Search in sources :

Example 16 with CommandResult

use of com.mongodb.CommandResult in project mongomvcc by igd-geo.

the class MongoDBVDatabase method initBuildInfo.

/**
 * Obtains build information from the database instance. If any value is
 * not available, this method will return <code>null</code>.
 * @param mongo the database
 * @return the build information or <code>null</code>
 */
private static BuildInfo initBuildInfo(Mongo mongo) {
    DB db = mongo.getDB("admin");
    if (db == null) {
        return null;
    }
    CommandResult cr = db.command("buildInfo");
    String version = (String) cr.get("version");
    if (version == null) {
        return null;
    }
    String[] vss = version.split("\\.");
    if (vss.length <= 2) {
        return null;
    }
    Integer maxBsonObjectSize = (Integer) cr.get("maxBsonObjectSize");
    if (maxBsonObjectSize == null) {
        maxBsonObjectSize = Integer.valueOf(0);
    }
    try {
        return new BuildInfo(Integer.parseInt(vss[0]), Integer.parseInt(vss[1]), Integer.parseInt(vss[2]), maxBsonObjectSize);
    } catch (NumberFormatException e) {
        return null;
    }
}
Also used : BuildInfo(de.fhg.igd.mongomvcc.impl.internal.BuildInfo) DB(com.mongodb.DB) CommandResult(com.mongodb.CommandResult)

Aggregations

CommandResult (com.mongodb.CommandResult)16 BasicDBObject (com.mongodb.BasicDBObject)7 DB (com.mongodb.DB)5 DBCollection (com.mongodb.DBCollection)4 DBObject (com.mongodb.DBObject)3 MongoException (com.mongodb.MongoException)3 AggregationOutput (com.mongodb.AggregationOutput)2 BasicDBList (com.mongodb.BasicDBList)2 MongoClientURI (com.mongodb.MongoClientURI)2 File (java.io.File)2 List (java.util.List)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 DateTime (org.joda.time.DateTime)2 HostAndPort (com.google.common.net.HostAndPort)1 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 DBCursor (com.mongodb.DBCursor)1 EmbedMongoDB (com.mongodb.EmbedMongoDB)1 Mongo (com.mongodb.Mongo)1 MongoClient (com.mongodb.MongoClient)1 ServerAddress (com.mongodb.ServerAddress)1