@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; }
/** * 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); } }