Package com.mongodb

Examples of com.mongodb.WriteResult


            builder.add("base", state.get("base"));
        }
        builder.add("head", head.toString());
        DBObject nextState = builder.get();

        WriteResult result =
                journals.update(state, nextState, false, false, concern);
        if (result.getN() == 1) {
            state = nextState;
            stateLastUpdated = System.nanoTime();
            return true;
        } else {
            // force refresh when next accessed
View Full Code Here


        if (batch) {
            DBObject[] arr = new BasicDBObject[n];
            for (int i = 0; i < n; i++) {
                arr[i] = new BasicDBObject("_path", "/a" + i);
            }
            WriteResult result = collection.insert(arr);
            if (result.getError() != null) {
                log("Error: " + result.getError());
            }
        } else {
            for (int i = 0; i < n; i++) {
                WriteResult result = collection.insert(new BasicDBObject("_path", "/a" + i));
                if (result.getError() != null) {
                    log("Error: " + result.getError());
                }
            }

        }
View Full Code Here

        try {
            DBCollection collection = this.connection.getDB().getCollection(collectionName);
            DBObject object = buildDBObject(record);
            DBObject translation = buildDBObject(translationRecord);
            if (operation == MongoOperation.UPDATE) {
                WriteResult result = collection.update(translation, object, mongoSpec.isUpsert(), mongoSpec.isMulti());
                return result.getN() > 0;
            } else {
                throw new ResourceException("Invalid operation: " + operation);               
            }
        } catch (Exception exception) {
            ResourceException resourceException = new ResourceException(exception.toString());
View Full Code Here

    public <T extends Document> void remove(Collection<T> collection, String key) {
        log("remove", key);       
        DBCollection dbCollection = getDBCollection(collection);
        long start = start();
        try {
            WriteResult writeResult = dbCollection.remove(getByKeyQuery(key).get(), WriteConcern.SAFE);
            invalidateCache(collection, key);
            if (writeResult.getError() != null) {
                throw new MicroKernelException("Remove failed: " + writeResult.getError());
            }
        } finally {
            end("remove", start);
        }
    }
View Full Code Here

        DBCollection dbCollection = getDBCollection(collection);
        long start = start();
        try {
            try {
                WriteResult writeResult = dbCollection.insert(inserts, WriteConcern.SAFE);
                if (writeResult.getError() != null) {
                    return false;
                }
                if (collection == Collection.NODES) {
                    for (T doc : docs) {
                        Lock lock = getAndLock(doc.getId());
View Full Code Here

                for (String key : keys) {
                    cachedDocs.put(key, nodesCache.getIfPresent(new StringValue(key)));
                }
            }
            try {
                WriteResult writeResult = dbCollection.update(query.get(), update, false, true, WriteConcern.SAFE);
                if (writeResult.getError() != null) {
                    throw new MicroKernelException("Update failed: " + writeResult.getError());
                }
                // update cache
                for (Entry<String, NodeDocument> entry : cachedDocs.entrySet()) {
                    Lock lock = getAndLock(entry.getKey());
                    try {
View Full Code Here

        }
        String id = StringUtils.convertBytesToHex(blockId.getDigest());
        DBObject query = getBlobQuery(id, minLastModified);
        DBObject update = new BasicDBObject("$set",
                new BasicDBObject(MongoBlob.KEY_LAST_MOD, System.currentTimeMillis()));
        WriteResult writeResult = getBlobCollection().update(query, update);
        if (writeResult.getError() != null) {
            LOG.error("Mark failed for blob %s: %s", id, writeResult.getError());
        }
    }
View Full Code Here

    @Override
    public int sweep() throws IOException {
        DBObject query = getBlobQuery(null, minLastModified);
        long countBefore = getBlobCollection().count(query);
        WriteResult writeResult = getBlobCollection().remove(query);
        if (writeResult.getError() != null) {
            LOG.error("Sweep failed: %s", writeResult.getError());
        }

        long countAfter = getBlobCollection().count(query);
        minLastModified = 0;
        return (int) (countBefore - countAfter);
View Full Code Here

    public boolean deleteChunk(String chunkId) throws Exception {
        DBCollection collection = getBlobCollection();
        BasicDBObject removeObj = new BasicDBObject();
        removeObj.append(MongoBlob.KEY_ID, chunkId);

        WriteResult result = collection.remove(removeObj);
        if (result.getN() == 1) {
            return true;
        }

        return false;
    }
View Full Code Here

        if (batch) {
            DBObject[] arr = new BasicDBObject[n];
            for (int i = 0; i < n; i++) {
                arr[i] = new BasicDBObject("_path", "/a" + i);
            }
            WriteResult result = collection.insert(arr);
            if (result.getError() != null) {
                log("Error: " + result.getError());
            }
        } else {
            for (int i = 0; i < n; i++) {
                WriteResult result = collection.insert(new BasicDBObject("_path", "/a" + i));
                if (result.getError() != null) {
                    log("Error: " + result.getError());
                }
            }

        }
View Full Code Here

TOP

Related Classes of com.mongodb.WriteResult

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.