Package com.mongodb

Examples of com.mongodb.DB$CommandResultPair


        try
        {
            service.updated(null);

            Mongo mongo = new Mongo();
            DB db = mongo.getDB("ua_repo");
            DBCollection collection = db.getCollection("useradmin");
            // we always get a collection back, regardless if there is an actual MongoDB listening, hence we should do
            // some actual calls that cause a connection to MongoDB to be created...
            collection.remove(new BasicDBObject(), WriteConcern.SAFE);

            CommandResult lastError = db.getLastError();

            return (lastError.getException() == null && collection.getCount() == 0L);
        }
        catch (Exception e)
        {
View Full Code Here


    @Override
    public void start() {
        try {
            _mongo = new Mongo(_dbHost, _dbPort);
            DB db = _mongo.getDB(_dbName);
            _collection = db.getCollection(super.getName());
        } catch (Exception e) {
            addStatus(new ErrorStatus("Failed to initialize MondoDB", this, e));
            return;
        }
        super.start();
View Full Code Here

        DBCollection dbCol = null;
       
        if (dynamicDB == null && dynamicCollection == null) {
            dbCol = endpoint.getDbCollection();
        } else {
            DB db = null;

            if (dynamicDB == null) {
                db = endpoint.getDb();
            } else {
                db = endpoint.getMongoConnection().getDB(dynamicDB);
            }

            if (dynamicCollection == null) {
                dbCol = db.getCollection(endpoint.getCollection());
            } else {
                dbCol = db.getCollection(dynamicCollection);

                // on the fly add index
                if (dynamicIndex == null) {
                    endpoint.ensureIndex(dbCol, endpoint.createIndex());
                } else {
View Full Code Here

        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        Connection connection = DriverManager.getConnection("jdbc:derby:jar:(" + dbFile.getAbsolutePath()
                + ")derby_testdb;territory=en");
        connection.setReadOnly(true);

        DB db = new Mongo().getDB("orderdb_copy");

        DataContext sourceDataContext = new JdbcDataContext(connection);

        new MongoDbDataCopyer(db, "orders", sourceDataContext, "APP", "orders").copy();
        new MongoDbDataCopyer(db, "offices", sourceDataContext, "APP", "offices").copy();
View Full Code Here

                    new Object[] {type,mongoURI.getHosts(), db});
            logger.info("Mongo Connection details {}",MongoConnection.toString(mongoURI.getOptions()));
        }

        MongoClient client = new MongoClient(mongoURI);
        DB mongoDB = client.getDB(db);

        mk = new MongoMK.Builder()
                .memoryCacheSize(cacheSize * MB)
                .setMongoDB(mongoDB)
                .open();
View Full Code Here

    private static MongoMK createMK(boolean useSimpleRevision) {
        MongoMK.Builder builder = new MongoMK.Builder();

        if (MONGO_DB) {
            DB db = MongoUtils.getConnection().getDB();
            MongoUtils.dropCollections(db);
            builder.setMongoDB(db);
        }

        builder.setUseSimpleRevision(useSimpleRevision);
View Full Code Here

    private List<MongoConnection> connections = new ArrayList<MongoConnection>();

    private MicroKernel createMicroKernel() throws Exception {
        MongoConnection connection = MongoUtils.getConnection();
        connections.add(connection);
        DB mongoDB = connection.getDB();
        return new MongoMK.Builder().setMongoDB(mongoDB).open();
    }
View Full Code Here

    @Before
    @Override
    public void setUpConnection() throws Exception {
        super.setUpConnection();
        DB db = mongoConnection.getDB();
        mk2 = new MongoMK.Builder().setMongoDB(db).open();
    }
View Full Code Here

public class MongoDbTest {
   
    @Test
    @Ignore
    public void manyChildNodes() {
        DB db = MongoUtils.getConnection().getDB();
        MongoUtils.dropCollections(db);
        DBCollection nodes = db.getCollection(Collection.NODES.toString());
        DBObject index = new BasicDBObject();
        // modification time (descending)
        index.put("_mod", -1L);
        // and then id (ascending)
        index.put("_id", 1L);
        DBObject options = new BasicDBObject();
        // options.put("unique", Boolean.TRUE);
        nodes.ensureIndex(index, options)
       
        // index on (_id, _mod):
        // Query plan: { "cursor" : "BtreeCursor _id_1__mod_-1" ,
        // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
        // "nscanned" : 954647 , "nscannedObjectsAllPlans" : 1907080 ,
        // "nscannedAllPlans" : 2859727 , "scanAndOrder" : false ,
        // "indexOnly" : true , "nYields" : 5 , "nChunkSkips" : 0 ,
        // "millis" : 5112 ,...
        // Time: 2229 ms
        // Count: 2000
       
        // index on (_mod, _id)
        // Query plan: { "cursor" : "BtreeCursor _mod_-1__id_1" ,
        // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
        // "nscanned" : 2000 , "nscannedObjectsAllPlans" : 2203 ,
        // "nscannedAllPlans" : 2203 , "scanAndOrder" : false ,
        // "indexOnly" : true , "nYields" : 0 , "nChunkSkips" : 0 ,
        // "millis" : 3 ,...
        // Time: 43 ms
        // Count: 2000
       
        int children = 1000000;
        int perInsert = 1000;
        int group = 0;
        String parent = "/parent/node/abc";
        for (int i = 0; i < children;) {
            DBObject[] inserts = new DBObject[perInsert];
            group++;
            for (int j = 0; j < perInsert; j++, i++) {
                BasicDBObject doc = new BasicDBObject();
                inserts[j] = doc;
                doc.put("_id", parent + "/node" + i);
                doc.put("_mod", group);
            }
            nodes.insert(inserts, WriteConcern.SAFE);
            log("inserted " + i + "/" + children);
        }
        QueryBuilder queryBuilder = QueryBuilder.start("_mod");
        queryBuilder.greaterThanEquals(group - 1);
        queryBuilder.and("_id").greaterThan(parent + "/");
        queryBuilder.and("_id").lessThanEquals(parent + "0");
        DBObject query = queryBuilder.get();
        BasicDBObject keys = new BasicDBObject();
        keys.put("_id", 1);
        DBCursor cursor = nodes.find(query, keys);
        int count = 0;
        log("Query plan: " + cursor.explain());
        long time = System.currentTimeMillis();
        while (cursor.hasNext()) {
            DBObject obj = cursor.next();
            // dummy read operation (to ensure we did get the data)
            obj.get("_id");
            count++;
            // log(" read " + obj);
        }
        time = System.currentTimeMillis() - time;
        log("Time: " + time + " ms");
        log("Count: " + count);
        db.getMongo().close();
    }
View Full Code Here

    }
       
    @Test
    @Ignore
    public void updateDocument() {
        DB db = MongoUtils.getConnection().getDB();
        MongoUtils.dropCollections(db);
        DBCollection nodes = db.getCollection(Collection.NODES.toString());
        DBObject index = new BasicDBObject();
        // modification time (descending)
        index.put("_mod", -1L);
        // and then id (ascending)
        index.put("_id", 1L);
        DBObject options = new BasicDBObject();
        // options.put("unique", Boolean.TRUE);
        nodes.ensureIndex(index, options)
       
        long time;
        time = System.currentTimeMillis();
       
        int nodeCount = 4500;
        String parent = "/parent/node/abc";
        DBObject[] inserts = new DBObject[nodeCount];
        for (int i = 0; i < nodeCount; i++) {
            BasicDBObject doc = new BasicDBObject();
            inserts[i] = doc;
            doc.put("_id", parent + "/node" + i);
            doc.put("_mod", 0);
            doc.put("_counter", 0);
            doc.put("x", 10);
        }
        nodes.insert(inserts, WriteConcern.SAFE);
       
        time = System.currentTimeMillis() - time;
        System.out.println("insert: " + time);
        time = System.currentTimeMillis();
       
        for (int i = 0; i < nodeCount; i++) {
            QueryBuilder queryBuilder = QueryBuilder.start(Document.ID).is(parent + "/node" + i);
            DBObject fields = new BasicDBObject();
            // return _id only
            fields.put("_id", 1);
            DBObject query = queryBuilder.get();

            BasicDBObject setUpdates = new BasicDBObject();
            BasicDBObject incUpdates = new BasicDBObject();
            BasicDBObject unsetUpdates = new BasicDBObject();

            setUpdates.append("_mod", i);
            incUpdates.append("_counter", 1);
            unsetUpdates.append("x", "1");
           
            BasicDBObject update = new BasicDBObject();
            if (!setUpdates.isEmpty()) {
                update.append("$set", setUpdates);
            }
            if (!incUpdates.isEmpty()) {
                update.append("$inc", incUpdates);
            }
            if (!unsetUpdates.isEmpty()) {
                update.append("$unset", unsetUpdates);
            }

            // 1087 ms (upsert true+false, returnNew = false)
            // 1100 ms (returnNew = true)
//            DBObject oldNode =
            nodes.findAndModify(query, fields,
                    null /*sort*/, false /*remove*/, update, false /*returnNew*/,
                    true /*upsert*/);

            // 250 ms WriteConcern.NORMAL, NONE
            // 891 ms WriteConvern.SAFE
            // > 10 s WriteConcern.JOURNAL_SAFE, FSYNC_SAFE
           
//            WriteResult result =
//            nodes.update(query, update, /* upsert */ true, /* multi */ false,
//                    WriteConcern.NORMAL);

           
        }
       
        time = System.currentTimeMillis() - time;
        System.out.println("update: " + time);
        time = System.currentTimeMillis();

        db.getMongo().close();
    }
View Full Code Here

TOP

Related Classes of com.mongodb.DB$CommandResultPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.