@Test public void testReadPreference() { template.setReadPreference(ReadPreference.secondary()); Query query = new Query(); template.findEach(query, Entity.class, "student"); Assert.assertEquals(ReadPreference.secondary(), template.getCollection("student").getReadPreference()); }
public <T> Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName) { MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass); DBCollection collection = getDb().getCollection(collectionName); prepareCollection(collection); DBObject dbQuery = mapper.getMappedObject(query.getQueryObject(), entity); final DBCursor cursor; if (query.getFieldsObject() == null) { cursor = collection.find(dbQuery); } else { cursor = collection.find(dbQuery, query.getFieldsObject()); } return new Iterator<T>() { @Override public boolean hasNext() { return cursor.hasNext(); } @Override public T next() { return getConverter().read(entityClass, cursor.next()); } @Override public void remove() { cursor.remove(); } }; }
MongoEntityTemplate extends MongoTemplate { public <T> Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName) { MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass); DBCollection collection = getDb().getCollection(collectionName); prepareCollection(collection); DBObject dbQuery = mapper.getMappedObject(query.getQueryObject(), entity); final DBCursor cursor; if (query.getFieldsObject() == null) { cursor = collection.find(dbQuery); } else { cursor = collection.find(dbQuery, query.getFieldsObject()); } return new Iterator<T>() { @Override public boolean hasNext() { return cursor.hasNext(); } @Override public T next() { return getConverter().read(entityClass, cursor.next()); } @Override public void remove() { cursor.remove(); } }; } }
MongoEntityTemplate extends MongoTemplate { public <T> Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName) { MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass); DBCollection collection = getDb().getCollection(collectionName); prepareCollection(collection); DBObject dbQuery = mapper.getMappedObject(query.getQueryObject(), entity); final DBCursor cursor; if (query.getFieldsObject() == null) { cursor = collection.find(dbQuery); } else { cursor = collection.find(dbQuery, query.getFieldsObject()); } return new Iterator<T>() { @Override public boolean hasNext() { return cursor.hasNext(); } @Override public T next() { return getConverter().read(entityClass, cursor.next()); } @Override public void remove() { cursor.remove(); } }; } MongoEntityTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter); }
MongoEntityTemplate extends MongoTemplate { public <T> Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName) { MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass); DBCollection collection = getDb().getCollection(collectionName); prepareCollection(collection); DBObject dbQuery = mapper.getMappedObject(query.getQueryObject(), entity); final DBCursor cursor; if (query.getFieldsObject() == null) { cursor = collection.find(dbQuery); } else { cursor = collection.find(dbQuery, query.getFieldsObject()); } return new Iterator<T>() { @Override public boolean hasNext() { return cursor.hasNext(); } @Override public T next() { return getConverter().read(entityClass, cursor.next()); } @Override public void remove() { cursor.remove(); } }; } MongoEntityTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter); Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName); }
MongoEntityTemplate extends MongoTemplate { public <T> Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName) { MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass); DBCollection collection = getDb().getCollection(collectionName); prepareCollection(collection); DBObject dbQuery = mapper.getMappedObject(query.getQueryObject(), entity); final DBCursor cursor; if (query.getFieldsObject() == null) { cursor = collection.find(dbQuery); } else { cursor = collection.find(dbQuery, query.getFieldsObject()); } return new Iterator<T>() { @Override public boolean hasNext() { return cursor.hasNext(); } @Override public T next() { return getConverter().read(entityClass, cursor.next()); } @Override public void remove() { cursor.remove(); } }; } MongoEntityTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter); Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName);  }