@Override public MorphiaIterator<U, U> aggregate( final Class<U> target, final AggregationOptions options, final ReadPreference readPreference) { return aggregate(datastore.getCollection(target).getName(), target, options, readPreference); }
@Override public Query<T> project(final Meta meta) { final StringBuilder sb = new StringBuilder(meta.getField()); validateQuery(clazz, ds.getMapper(), sb, FilterOperator.EQUAL, null, false, false); String fieldName = sb.toString(); validateProjections(fieldName, true); project(meta.toDatabase()); return this; }
@Override public Query<T> project(final String field, final ArraySlice slice) { final StringBuilder sb = new StringBuilder(field); validateQuery(clazz, ds.getMapper(), sb, FilterOperator.EQUAL, null, validateName, false); String fieldName = sb.toString(); validateProjections(fieldName, true); project(fieldName, slice.toDatabase()); return this; }
@Override public Query<T> project(final String field, final boolean include) { final StringBuilder sb = new StringBuilder(field); validateQuery(clazz, ds.getMapper(), sb, FilterOperator.EQUAL, null, validateName, false); String fieldName = sb.toString(); validateProjections(fieldName, include); project(fieldName, include ? 1 : 0); return this; }
@Override public MorphiaKeyIterator<T> fetchKeys(final FindOptions options) { QueryImpl<T> cloned = cloneQuery(); cloned.getOptions().projection(new BasicDBObject(Mapper.ID_KEY, 1)); cloned.includeFields = true; return new MorphiaKeyIterator<T>( ds, cloned.prepareCursor(options), ds.getMapper(), clazz, dbColl.getName()); }
@Override public MorphiaIterator<T, T> fetch(final FindOptions options) { final DBCursor cursor = prepareCursor(options); if (LOG.isTraceEnabled()) { LOG.trace("Getting cursor(" + dbColl.getName() + ") for query:" + cursor.getQuery()); } return new MorphiaIterator<T, T>(ds, cursor, ds.getMapper(), clazz, dbColl.getName(), cache); }
@Override public Query<T> retrieveKnownFields() { final MappedClass mc = ds.getMapper().getMappedClass(clazz); final List<String> fields = new ArrayList<String>(mc.getPersistenceFields().size() + 1); for (final MappedField mf : mc.getPersistenceFields()) { fields.add(mf.getNameToStore()); } retrievedFields(true, fields.toArray(new String[fields.size()])); return this; }
@Override public Query<T> order(final Sort... sorts) { BasicDBObject sortList = new BasicDBObject(); for (Sort sort : sorts) { String s = sort.getField(); if (validateName) { final StringBuilder sb = new StringBuilder(s); validateQuery(clazz, ds.getMapper(), sb, FilterOperator.IN, "", true, false); s = sb.toString(); } sortList.put(s, sort.getOrder()); } getOptions().sort(sortList); return this; }
@Override public Query<T> order(final Meta sort) { validateQuery( clazz, ds.getMapper(), new StringBuilder(sort.getField()), FilterOperator.IN, "", false, false); getOptions().sort(sort.toDatabase()); 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; }
@Override @Deprecated public DBObject getFieldsObject() { DBObject projection = getOptions().getProjection(); if (projection == null || projection.keySet().size() == 0) { return null; } final MappedClass mc = ds.getMapper().getMappedClass(clazz); Entity entityAnnotation = mc.getEntityAnnotation(); final BasicDBObject fieldsFilter = copy(projection); if (includeFields && entityAnnotation != null && !entityAnnotation.noClassnameStored()) { fieldsFilter.put(Mapper.CLASS_NAME_FIELDNAME, 1); } return fieldsFilter; }
private DBCursor prepareCursor(final FindOptions findOptions) { final DBObject query = getQueryObject(); if (LOG.isTraceEnabled()) { LOG.trace( String.format( "Running query(%s) : %s, options: %s,", dbColl.getName(), query, findOptions)); } if (findOptions.isSnapshot() && (findOptions.getSortDBObject() != null || findOptions.hasHint())) { LOG.warning("Snapshotted query should not have hint/sort."); } if (findOptions.getCursorType() != NonTailable && (findOptions.getSortDBObject() != null)) { LOG.warning("Sorting on tail is not allowed."); } return dbColl .find( query, findOptions.getOptions().copy().sort(getSortObject()).projection(getFieldsObject())) .setDecoderFactory(ds.getDecoderFact()); }
@Override public Query<T> order(final String sort) { getOptions().sort(parseFieldsString(sort, clazz, ds.getMapper(), validateName)); return this; }
public AggregationPipelineImpl(final DatastoreImpl datastore, final Class<T> source) { this.datastore = datastore; this.collection = datastore.getCollection(source); mapper = datastore.getMapper(); this.source = source; }
@Override public MorphiaIterator<U, U> out(final Class<U> target, final AggregationOptions options) { return out(datastore.getCollection(target).getName(), target, options); }
@Override public MorphiaIterator<U, U> out(final Class<U> target) { return out(datastore.getCollection(target).getName(), target); }