Search in sources :

Example 1 with BuildInfo

use of de.fhg.igd.mongomvcc.impl.internal.BuildInfo 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)1 DB (com.mongodb.DB)1 BuildInfo (de.fhg.igd.mongomvcc.impl.internal.BuildInfo)1