List of usage examples for com.mongodb CommandResult ok
public boolean ok()
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * coll stats// w ww . j a v a 2 s. co m * * @param userDB * @param colName * @return * @throws Exception */ public static String getCollStats(UserDBDAO userDB, String colName) throws Exception { DBCollection collection = findCollection(userDB, colName); CommandResult cr = collection.getStats(); if (cr.ok()) { return cr.toString(); } else { throw cr.getException(); } }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * collection validate/* w w w. j a v a 2 s . co m*/ * * @param userDB * @param collName * @param isFull * @return * @throws Exception */ public static BasicDBObject collValidate(UserDBDAO userDB, String collName, boolean isFull) throws Exception { DBObject queryObj = new BasicDBObject("validate", collName); queryObj.put("full", isFull); CommandResult cr = findDB(userDB).command(queryObj); if (!cr.ok()) throw cr.getException(); if (logger.isDebugEnabled()) logger.debug("[compact] complements" + cr.toString()); return (BasicDBObject) cr; }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * collection compact/*ww w.j a v a 2 s.c o m*/ * * @param userDB * @param colName * @param force * @param paddingFactor * @param paddingBytes * @return * @throws Exception */ public static String collCompact(UserDBDAO userDB, String colName, boolean isForct, int paddingFactor, int paddingBytes) throws Exception { DB mongoDB = findDB(userDB); DBObject queryObj = new BasicDBObject("compact", colName); if (paddingFactor > 0) queryObj.put("paddingFactor", paddingFactor); if (paddingBytes > 0) queryObj.put("paddingBytes", paddingBytes); CommandResult cr = mongoDB.command(queryObj); if (!cr.ok()) throw cr.getException(); if (logger.isDebugEnabled()) logger.debug("[compact] complements" + cr.toString()); return cr.toString(); }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * reIndex collection/*from www. jav a2s . c o m*/ * * @param userDB * @param colName * @throws Exception */ public static void reIndexCollection(UserDBDAO userDB, String colName) throws Exception { DB mongoDB = findDB(userDB); DBObject queryObj = new BasicDBObject("reIndex", colName); CommandResult cr = mongoDB.command(queryObj); if (!cr.ok()) throw cr.getException(); if (logger.isDebugEnabled()) logger.debug("[reIndex] complements" + colName); }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * Server status, return to String// ww w .jav a2 s . c o m * * @param userDB * @throws Exception */ public static String serverStatus(UserDBDAO userDB) throws Exception { DB mongoDB = findDB(userDB); DBObject queryObj = new BasicDBObject("serverStatus", 1); CommandResult cr = mongoDB.command(queryObj); if (cr.ok()) { return cr.toString(); } else { throw cr.getException(); } }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * top/*from w w w .java 2 s . c o m*/ * * @param userDB * @param top * @return * @throws Exception */ public static String top(UserDBDAO userDB, int top) throws Exception { UserDBDAO adminDB = new UserDBDAO(); adminDB.setHost(userDB.getHost()); adminDB.setPort(userDB.getPort()); adminDB.setUsers(userDB.getUsers()); adminDB.setPasswd(userDB.getPasswd()); adminDB.setUrl(userDB.getHost() + ":" + userDB.getPort() + "/admin"); adminDB.setDb("admin"); DB mongoDB = findDB(adminDB); DBObject queryObj = new BasicDBObject("top", top); CommandResult cr = mongoDB.command(queryObj); if (cr.ok()) { return cr.toString(); } else { logger.error("top command" + userDB, cr.getException()); throw new Exception(cr.getErrorMessage());//cr.getException(); } }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * db stats/*w ww.ja v a 2 s . co m*/ * * @param userDB * @throws Exception */ public static String dbStats(UserDBDAO userDB) throws Exception { DB mongoDB = findDB(userDB); CommandResult cr = mongoDB.getStats(); if (cr.ok()) { return cr.toString(); } else { throw cr.getException(); } }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * profiling start//from w ww. j av a 2 s . co m * @param userDB * @param level 0 : stop, 1 or 2 : start * @return * @throws Exception */ public static boolean commandProfiling(UserDBDAO userDB, int level) throws Exception { DB mongoDB = findDB(userDB); DBObject queryObj = new BasicDBObject("profile", level); CommandResult cr = mongoDB.command(queryObj); if (cr.ok()) { return true; } else { throw cr.getException(); } }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestDBStats.java
License:Open Source License
/** * @param args//from w ww . ja v a2 s .c o m */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("test"); CommandResult cr = db.getStats(); System.out.println("[ok]" + cr.ok()); if (!cr.ok()) System.out.println("[Exception ]" + cr.getException().toString()); System.out.println("[toString]" + JSONUtil.getPretty(cr.toString())); System.out.println("[size]" + cr.size()); mongo.close(); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestListCommand.java
License:Open Source License
/** * @param args/* w ww.ja va2 s.c o m*/ */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("test"); DBObject queryObj = new BasicDBObject("listCommands", 1); CommandResult cr = db.command(queryObj); System.out.println("[ok]" + cr.ok()); if (!cr.ok()) System.out.println("[Exception ]" + cr.getException().toString()); System.out.println("[toString]" + JSONUtil.getPretty(cr.toString())); System.out.println("[size]" + cr.size()); mongo.close(); }