Java Code Examples for org.mongodb.morphia.query.Query#order()
The following examples show how to use
org.mongodb.morphia.query.Query#order() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoLogConnector.java From heimdall with Apache License 2.0 | 6 votes |
private Page<LogTrace> preparePage(Query<LogTrace> query, Integer page, Integer limit) { List<LogTrace> list; Long totalElements = query.count(); query = query.order("-ts"); page = page == null ? PAGE : page; limit = limit == null || limit > LIMIT ? LIMIT : limit; if (page >= 1 && limit > 0) { list = query.asList(new FindOptions().limit(limit).skip(page * limit)); } else { list = query.asList(new FindOptions().limit(limit)); } return buildPage(list, page, limit, totalElements); }
Example 2
Source File: AbstractMongoJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public PaginationRsp<JobPo> pageSelect(JobQueueReq request) { Query<JobPo> query = template.createQuery(getTargetTable(request.getTaskTrackerNodeGroup()), JobPo.class); addCondition(query, "jobId", request.getJobId()); addCondition(query, "taskId", request.getTaskId()); addCondition(query, "realTaskId", request.getRealTaskId()); addCondition(query, "taskTrackerNodeGroup", request.getTaskTrackerNodeGroup()); addCondition(query, "jobType", request.getJobType()); addCondition(query, "submitNodeGroup", request.getSubmitNodeGroup()); addCondition(query, "needFeedback", request.getNeedFeedback()); if (request.getStartGmtCreated() != null) { query.filter("gmtCreated >= ", request.getStartGmtCreated().getTime()); } if (request.getEndGmtCreated() != null) { query.filter("gmtCreated <= ", request.getEndGmtCreated().getTime()); } if (request.getStartGmtModified() != null) { query.filter("gmtModified <= ", request.getStartGmtModified().getTime()); } if (request.getEndGmtModified() != null) { query.filter("gmtModified >= ", request.getEndGmtModified().getTime()); } PaginationRsp<JobPo> response = new PaginationRsp<JobPo>(); Long results = template.getCount(query); response.setResults(results.intValue()); if (results == 0) { return response; } if (StringUtils.isNotEmpty(request.getField()) && StringUtils.isNotEmpty(request.getDirection())) { query.order(("ASC".equalsIgnoreCase(request.getDirection()) ? "" : "-") + request.getField()); } query.offset(request.getStart()).limit(request.getLimit()); response.setRows(query.asList()); return response; }
Example 3
Source File: MongodbRepository.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param q * @param order */ private void configureQueryOrder(Query<T> q, QueryOrder order) { if (order == null) return; if (order.isSorted()) { final StringBuilder sb = new StringBuilder(); order.iterate(new OrderCallback() { boolean isFirst = true; @Override public void orderBy(OrderComponent component) { if (!isFirst) { sb.append(','); } if (component.isDescending()) { sb.append('-'); } sb.append(component.getFieldName()); isFirst = false; } }); q.order(sb.toString()); } }
Example 4
Source File: MongoExperimentsStore.java From alchemy with MIT License | 4 votes |
@Override public Iterable<Experiment> find(Filter filter, Experiment.BuilderFactory factory) { final Query<ExperimentEntity> query = ds.find(ExperimentEntity.class); if (filter.getFilter() != null) { query.or( query.criteria("name").containsIgnoreCase(filter.getFilter()), query.criteria("description").containsIgnoreCase(filter.getFilter()) ); } final Ordering ordering = filter.getOrdering(); if (ordering != null && !ordering.isEmpty()) { final StringBuilder orderingString = new StringBuilder(); for (Entry<Field, Direction> entry : ordering.getFields().entrySet()) { final String field = ExperimentEntity.getFieldName(entry.getKey()); if (orderingString.length() > 0) { orderingString.append(','); } if (entry.getValue() == Direction.DESCENDING) { orderingString.append('-'); } orderingString.append(field); } query.order(orderingString.toString()); } if (filter.getOffset() != null) { query.offset(filter.getOffset()); } if (filter.getLimit() != null) { query.limit(filter.getLimit()); } return new ExperimentIterable(query.iterator(), factory); }
Example 5
Source File: JobMetric.java From DotCi with MIT License | 4 votes |
private Query<DynamicBuild> applyQueryFilters(Query<DynamicBuild> query) { query = filterBranch(query); query = query.limit(getBuildCount()); return query.order("number"); }