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); }
@Override @Deprecated public MorphiaIterator<T, T> tail(final boolean awaitData) { return fetch(getOptions() .copy() .cursorType(awaitData ? TailableAwait : Tailable)); }
private int hash(final FindOptions options) { if (options == null) { return 0; } int result = options.getBatchSize(); result = 31 * result + getLimit(); result = 31 * result + (options.getModifiers() != null ? options.getModifiers().hashCode() : 0); result = 31 * result + (options.getProjection() != null ? options.getProjection().hashCode() : 0); result = 31 * result + (int) (options.getMaxTime(MILLISECONDS) ^ options.getMaxTime(MILLISECONDS) >>> 32); result = 31 * result + (int) (options.getMaxAwaitTime(MILLISECONDS) ^ options.getMaxAwaitTime(MILLISECONDS) >>> 32); result = 31 * result + options.getSkip(); result = 31 * result + (options.getSortDBObject() != null ? options.getSortDBObject().hashCode() : 0); result = 31 * result + (options.getCursorType() != null ? options.getCursorType().hashCode() : 0); result = 31 * result + (options.isNoCursorTimeout() ? 1 : 0); result = 31 * result + (options.isOplogReplay() ? 1 : 0); result = 31 * result + (options.isPartial() ? 1 : 0); result = 31 * result + (options.getReadPreference() != null ? options.getReadPreference().hashCode() : 0); result = 31 * result + (options.getReadConcern() != null ? options.getReadConcern().hashCode() : 0); result = 31 * result + (options.getCollation() != null ? options.getCollation().hashCode() : 0); return result; }
@Override public boolean exists(final Query<T> query) { return query.get(new FindOptions().limit(1)) != null; }
FindOptions getOptions() { if (options == null) { options = new FindOptions(); } return options; }
@Override @Deprecated public Query<T> offset(final int value) { getOptions().skip(value); return this; }
@Override @Deprecated public Query<T> limit(final int value) { getOptions().limit(value); return this; }
@Override @Deprecated public int getBatchSize() { return getOptions().getBatchSize(); }
@Override @Deprecated public Query<T> batchSize(final int value) { getOptions().batchSize(value); return this; }
@Override public QueryImpl<T> cloneQuery() { final QueryImpl<T> n = new QueryImpl<T>(clazz, dbColl, ds); n.cache = ds.getMapper().createEntityCache(); // fresh cache n.includeFields = includeFields; n.setQuery(n); // feels weird, correct? n.validateName = validateName; n.validateType = validateType; n.baseQuery = copy(baseQuery); n.options = options != null ? options.copy() : null; // fields from superclass n.setAttachedTo(getAttachedTo()); n.setChildren(getChildren() == null ? null : new ArrayList<Criteria>(getChildren())); return n; }
/** * Makes a copy of these find options * @return the new copy */ public FindOptions copy() { return new FindOptions(options.copy()); }
@Override public <T> Page<T> find(Object criteria, Integer page, Integer limit) { Query<T> query = this.prepareQuery(criteria, this.datastore()); List<T> list; Long totalElements = query.count(); 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); }
@Override public <T> Page<T> find(Object criteria, Integer page, Integer limit) { Query<T> query = this.prepareQuery(criteria, this.datastore()); List<T> list; Long totalElements = query.count(); 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); }