/** * Creates a Query for the given type and collection * * @param clazz the type to return * @param coll the collection to query * @param ds the Datastore to use */ public QueryImpl(final Class<T> clazz, final DBCollection coll, final Datastore ds) { super(CriteriaJoin.AND); setQuery(this); this.clazz = clazz; this.ds = ((org.mongodb.morphia.DatastoreImpl) ds); dbColl = coll; cache = this.ds.getMapper().createEntityCache(); final MappedClass mc = this.ds.getMapper().getMappedClass(clazz); final Entity entAn = mc == null ? null : mc.getEntityAnnotation(); if (entAn != null) { getOptions() .readPreference( this.ds.getMapper().getMappedClass(clazz).getEntityAnnotation().queryNonPrimary() ? ReadPreference.secondaryPreferred() : null); } }
@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; }