List of usage examples for org.springframework.data.mongodb.core CursorPreparer prepare
FindIterable<Document> prepare(FindIterable<Document> cursor);
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
/** * Internal method using callback to do queries against the datastore that requires reading a collection of objects. * It will take the following steps/*from w ww . j a v a 2 s . c o m*/ * <ol> * <li>Execute the given {@link ConnectionCallback} for a {@link DBCursor}.</li> * <li>Prepare that {@link DBCursor} with the given {@link CursorPreparer} (will be skipped if {@link CursorPreparer} * is {@literal null}</li> * <li>Iterate over the {@link DBCursor} and applies the given {@link DbObjectCallback} to each of the * {@link DBObject}s collecting the actual result {@link List}.</li> * <ol> * * @param <T> * @param collectionCallback the callback to retrieve the {@link DBCursor} with * @param preparer the {@link CursorPreparer} to potentially modify the {@link DBCursor} before ireating over it * @param objectCallback the {@link DbObjectCallback} to transform {@link DBObject}s into the actual domain type * @param collectionName the collection to be queried * @return */ private <T> List<T> executeFindMultiInternal(CollectionCallback<DBCursor> collectionCallback, CursorPreparer preparer, DbObjectCallback<T> objectCallback, String collectionName) { try { DBCursor cursor = collectionCallback.doInCollection(getAndPrepareCollection(getDb(), collectionName)); if (preparer != null) { cursor = preparer.prepare(cursor); } List<T> result = new ArrayList<T>(); for (DBObject object : cursor) { result.add(objectCallback.doWith(object)); } return result; } catch (RuntimeException e) { throw potentiallyConvertRuntimeException(e); } }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
private void executeQueryInternal(CollectionCallback<DBCursor> collectionCallback, CursorPreparer preparer, DocumentCallbackHandler callbackHandler, String collectionName) { try {// ww w. jav a 2 s. c o m DBCursor cursor = collectionCallback.doInCollection(getAndPrepareCollection(getDb(), collectionName)); if (preparer != null) { cursor = preparer.prepare(cursor); } for (DBObject dbobject : cursor) { callbackHandler.processDocument(dbobject); } } catch (RuntimeException e) { throw potentiallyConvertRuntimeException(e); } }