List of usage examples for com.mongodb DBCursor remove
@Override public void remove()
From source file:org.iternine.jeppetto.dao.mongodb.MongoDBQueryModelDAO.java
License:Apache License
public Iterable<T> findUsingQueryModel(QueryModel queryModel) { MongoDBCommand command = buildCommand(queryModel); DBCursor dbCursor = command.cursor(dbCollection); if (queryModel.getSorts() != null) { dbCursor.sort(processSorts(queryModel.getSorts())); }/*from w ww .java 2s . co m*/ if (queryModel.getFirstResult() > 0) { dbCursor = dbCursor.skip(queryModel.getFirstResult()); // dbCursor is zero-indexed, firstResult is one-indexed } if (queryModel.getMaxResults() > 0) { dbCursor = dbCursor.limit(queryModel.getMaxResults()); } final DBCursor finalDbCursor = dbCursor; return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return finalDbCursor.hasNext(); } @Override @SuppressWarnings({ "unchecked" }) public T next() { DBObject result = finalDbCursor.next(); ((DirtyableDBObject) result).markPersisted(); if (MongoDBSession.isActive()) { MongoDBSession.trackForSave(MongoDBQueryModelDAO.this, buildIdentifyingQuery(result), (T) result, createIdentifyingQueries(result)); } return (T) result; } @Override public void remove() { finalDbCursor.remove(); } }; } }; }
From source file:org.slc.sli.dal.template.MongoEntityTemplate.java
License:Apache License
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);//www .ja va 2s. co m 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() { // TODO Auto-generated method stub return cursor.hasNext(); } @Override public T next() { return getConverter().read(entityClass, cursor.next()); } @Override public void remove() { cursor.remove(); } }; }