Example usage for org.springframework.data.mongodb.core DbCallback doInDB

List of usage examples for org.springframework.data.mongodb.core DbCallback doInDB

Introduction

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

Prototype

@Nullable
T doInDB(MongoDatabase db) throws MongoException, DataAccessException;

Source Link

Usage

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

public <T> T execute(DbCallback<T> action) {

    Assert.notNull(action);/*from w ww  .ja v  a  2s.  c  om*/

    try {
        DB db = this.getDb();
        return action.doInDB(db);
    } catch (RuntimeException e) {
        throw potentiallyConvertRuntimeException(e);
    }
}

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

public <T> T executeInSession(final DbCallback<T> action) {
    return execute(new DbCallback<T>() {
        public T doInDB(DB db) throws MongoException, DataAccessException {
            try {
                db.requestStart();/*from w w w  . j  a  v a 2s  .c  o  m*/
                return action.doInDB(db);
            } finally {
                db.requestDone();
            }
        }
    });
}