Example usage for org.springframework.data.mongodb.core MongoActionOperation REMOVE

List of usage examples for org.springframework.data.mongodb.core MongoActionOperation REMOVE

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core MongoActionOperation REMOVE.

Prototype

MongoActionOperation REMOVE

To view the source code for org.springframework.data.mongodb.core MongoActionOperation REMOVE.

Click Source Link

Usage

From source file:org.springframework.data.mongodb.core.MongoTemplate.java

protected <T> void doRemove(final String collectionName, final Query query, final Class<T> entityClass) {
    if (query == null) {
        throw new InvalidDataAccessApiUsageException("Query passed in to remove can't be null");
    }//from www. ja va2s  . c  om
    final DBObject queryObject = query.getQueryObject();
    final MongoPersistentEntity<?> entity = getPersistentEntity(entityClass);
    execute(collectionName, new CollectionCallback<Void>() {
        public Void doInCollection(DBCollection collection) throws MongoException, DataAccessException {
            DBObject dboq = mapper.getMappedObject(queryObject, entity);
            WriteResult wr = null;
            MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.REMOVE, collectionName,
                    entityClass, null, queryObject);
            WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("remove using query: " + dboq + " in collection: " + collection.getName());
            }
            if (writeConcernToUse == null) {
                wr = collection.remove(dboq);
            } else {
                wr = collection.remove(dboq, writeConcernToUse);
            }
            handleAnyWriteResultErrors(wr, dboq, "remove");
            return null;
        }
    });
}