Package com.mongodb

Examples of com.mongodb.DB$CommandResultPair


    }
       
    @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


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

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

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

        // Check if any valid external BlobStore is defined.
        // If not then use the default which is MongoBlobStore
        BlobStore blobStore = null;
        if (Strings.isNullOrEmpty(blobStoreType)) {
View Full Code Here

    @Before
    @After
    public void clear() {
        if (MONGO_DB) {
            DB db = MongoUtils.getConnection().getDB();
            MongoUtils.dropCollections(db);
        }
    }
View Full Code Here

        return createMK(clusterId, 10);
    }

    private DocumentMK createMK(int clusterId, int asyncDelay) {
        if (MONGO_DB) {
            DB db = MongoUtils.getConnection().getDB();
            return new DocumentMK.Builder().setMongoDB(db)
                    .setClusterId(clusterId).setAsyncDelay(asyncDelay).open();
        } else {
            if (ds == null) {
                ds = new MemoryDocumentStore();
View Full Code Here

   
    private DocumentMK createMK(int clusterId) {
        DocumentMK.Builder builder = new DocumentMK.Builder();
        builder.setAsyncDelay(0);
        if (MONGO_DB) {
            DB db = MongoUtils.getConnection().getDB();
            MongoUtils.dropCollections(db);
            builder.setMongoDB(db);
        } else {
            if (ds == null) {
                ds = new MemoryDocumentStore();
View Full Code Here

    @Before
    public void setupMicroKernels() throws Exception {
        mongoConnection2.getDB().dropDatabase();
        // DB1 handled by the AbstractMongoConnectionTest

        DB db = mongoConnection.getDB();
        mk1 = new DocumentMK.Builder().setMongoDB(db).open();

        DB db2 = mongoConnection2.getDB();
        mk2 = new DocumentMK.Builder().setMongoDB(db2).open();

        DB db3 = mongoConnection3.getDB();
        mk3 = new DocumentMK.Builder().setMongoDB(db3).open();
    }
View Full Code Here

    private List<DocumentMK> mks = new ArrayList<DocumentMK>();

    private DocumentMK createMicroKernel() throws Exception {
        MongoConnection connection = MongoUtils.getConnection();
        DB mongoDB = connection.getDB();
        return new DocumentMK.Builder().memoryCacheSize(CACHE_SIZE).setMongoDB(mongoDB).open();
    }
View Full Code Here

        private static NodeStore createNodeStore(String uri) {
            MongoConnection connection;
            try {
                connection = new MongoConnection(uri);
                DB mongoDB = connection.getDB();
                return new DocumentMK.Builder()
                        .setMongoDB(mongoDB).getNodeStore();
            } catch (Exception e) {
                return null;
            }
View Full Code Here

    @Override
    public void setUpCluster(MicroKernel[] cluster) throws Exception {
        MongoConnection connection = getMongoConnection();
        openConnection();
        DB db = connection.getDB();
        dropCollections(db);

        for (int i = 0; i < cluster.length; i++) {
            cluster[i] = new DocumentMK.Builder().
                    setMongoDB(db).setBlobStore(blobStore).setClusterId(i).open();
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.