Package com.mongodb

Examples of com.mongodb.DBCollection.findAndModify()


                query.and(Document.MOD_COUNT).is(modCount);
                DBObject fields = new BasicDBObject();
                // return _id only
                fields.put("_id", 1);

                DBObject oldNode = dbCollection.findAndModify(query.get(), fields,
                        null /*sort*/, false /*remove*/, update, false /*returnNew*/,
                        false /*upsert*/);
                if (oldNode != null) {
                    // success, update cached document
                    applyToCache(collection, cachedDoc, updateOp);
View Full Code Here


            }

            // conditional update failed or not possible
            // perform operation and get complete document
            QueryBuilder query = createQueryForUpdate(updateOp, checkConditions);
            DBObject oldNode = dbCollection.findAndModify(query.get(), null,
                    null /*sort*/, false /*remove*/, update, false /*returnNew*/,
                    upsert);
            if (checkConditions && oldNode == null) {
                return null;
            }
View Full Code Here

            }

            // 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
View Full Code Here

    BasicDBObject update = new BasicDBObject();
    //FIXME should "value" be hardcoded?
    //FIXME how to set the initialValue if the document is not present? It seems the inc value is used as initial new value
    Integer incrementObject = increment == 1 ? ONE : Integer.valueOf( increment );
    this.addSubQuery( "$inc", update, SEQUENCE_VALUE, incrementObject );
    DBObject result = currentCollection.findAndModify( query, null, null, false, update, false, true );
    Object idFromDB;
    idFromDB = result == null ? null : result.get( SEQUENCE_VALUE );
    if ( idFromDB == null ) {
      //not inserted yet so we need to add initial value to increment to have the right next value in the DB
      //FIXME that means there is a small hole as when there was not value in the DB, we do add initial value in a non atomic way
View Full Code Here

    if ( idFromDB == null ) {
      //not inserted yet so we need to add initial value to increment to have the right next value in the DB
      //FIXME that means there is a small hole as when there was not value in the DB, we do add initial value in a non atomic way
      BasicDBObject updateForInitial = new BasicDBObject();
      this.addSubQuery( "$inc", updateForInitial, SEQUENCE_VALUE, initialValue );
      currentCollection.findAndModify( query, null, null, false, updateForInitial, false, true );
      idFromDB = initialValue; //first time we ask this value
    }
    else {
      idFromDB = result.get( SEQUENCE_VALUE );
    }
View Full Code Here

                query.and(Document.MOD_COUNT).is(modCount);
                DBObject fields = new BasicDBObject();
                // return _id only
                fields.put("_id", 1);

                DBObject oldNode = dbCollection.findAndModify(query.get(), fields,
                        null /*sort*/, false /*remove*/, update, false /*returnNew*/,
                        false /*upsert*/);
                if (oldNode != null) {
                    // success, update cached document
                    applyToCache(collection, cachedDoc, updateOp);
View Full Code Here

            }

            // conditional update failed or not possible
            // perform operation and get complete document
            QueryBuilder query = createQueryForUpdate(updateOp, checkConditions);
            DBObject oldNode = dbCollection.findAndModify(query.get(), null,
                    null /*sort*/, false /*remove*/, update, false /*returnNew*/,
                    upsert);
            if (checkConditions && oldNode == null) {
                return null;
            }
View Full Code Here

        //         WriteConcern.SAFE);
        // return null;

        long start = start();
        try {
            DBObject oldNode = dbCollection.findAndModify(query.get(), null /*fields*/,
                    null /*sort*/, false /*remove*/, update, false /*returnNew*/,
                    upsert /*upsert*/);
            if (checkConditions && oldNode == null) {
                return null;
            }
View Full Code Here

    public MongoSync execute() throws Exception {
        DBObject query = QueryBuilder.start(MongoSync.KEY_HEAD_REVISION_ID).is(oldHeadRevision).get();
        DBObject update = new BasicDBObject("$set", new BasicDBObject(MongoSync.KEY_HEAD_REVISION_ID,
                newHeadRevision));
        DBCollection collection = nodeStore.getSyncCollection();
        DBObject dbObject = collection.findAndModify(query, null/*fields*/,
                null/*sort*/, false/*remove*/, update, true/*returnNew*/, false/*upsert*/);
        return MongoSync.fromDBObject(dbObject);
    }
}
View Full Code Here

        DBCollection collection = nodeStore.getSyncCollection();
        DBObject dbObject = null;
        // In high concurrency situations, increment does not work right away,
        // so we need to keep retrying until it succeeds.
        while (dbObject == null) {
            dbObject = collection.findAndModify(null, null/*fields*/, null/*sort*/, false/*remove*/,
                    update, true/*returnNew*/, false/*upsert*/);
        }
        return MongoSync.fromDBObject(dbObject);
    }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.