Java Code Examples for com.mongodb.DB.requestStart()

The following are Jave code examples for showing how to use requestStart() of the com.mongodb.DB class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cloud-meter   File: MongoScriptRunner.java   View Source Code Vote up 6 votes
/**
 * Evaluate a script on the database
 *
 * @param db
 *            database connection to use
 * @param script
 *            script to evaluate on the database
 * @return result of evaluation on the database
 * @throws Exception
 *             when evaluation on the database fails
 */
public Object evaluate(DB db, String script)
    throws Exception {

    if(log.isDebugEnabled()) {
        log.debug("database: " + db.getName()+", script: " + script);
    }

    db.requestStart();
    try {
        db.requestEnsureConnection();

        Object result = db.eval(script);

        if(log.isDebugEnabled()) {
            log.debug("Result : " + result);
        }
        return result;
    } finally {
        db.requestDone();
    }
}