Package com.mongodb

Examples of com.mongodb.QueryBuilder$NullObject


    @Override
    public <T extends Document> void update(Collection<T> collection,
                                            List<String> keys,
                                            UpdateOp updateOp) {
        DBCollection dbCollection = getDBCollection(collection);
        QueryBuilder query = QueryBuilder.start(Document.ID).in(keys);
        DBObject update = createUpdate(updateOp);
        long start = start();
        try {
            Map<String, NodeDocument> cachedDocs = Collections.emptyMap();
            if (collection == Collection.NODES) {
                cachedDocs = Maps.newHashMap();
                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()) {
View Full Code Here


    }

    @Nonnull
    private static QueryBuilder createQueryForUpdate(UpdateOp updateOp,
                                              boolean checkConditions) {
        QueryBuilder query = getByKeyQuery(updateOp.getId());

        for (Entry<Key, Operation> entry : updateOp.getChanges().entrySet()) {
            Key k = entry.getKey();
            Operation op = entry.getValue();
            switch (op.type) {
                case CONTAINS_MAP_ENTRY: {
                    if (checkConditions) {
                        query.and(k.toString()).exists(op.value);
                    }
                    break;
                }
            }
        }
View Full Code Here

                size++;
                cachedKeys.add(e.getKey().toString());
            }
            result.cacheSize = size;

            QueryBuilder query = QueryBuilder.start(Document.ID)
                    .in(cachedKeys);

            // Fetch only the lastRev map and id
            final BasicDBObject keys = new BasicDBObject(Document.ID, 1);
            keys.put(Document.MOD_COUNT, 1);

            // Fetch lastRev for each such node
            DBCursor cursor = nodes.find(query.get(), keys);
            result.queryCount++;

            for (DBObject obj : cursor) {
                result.cacheEntriesProcessedCount++;
                String id = (String) obj.get(Document.ID);
View Full Code Here

                // Change in level or last element
                if (!sameLevelNodes.isEmpty() &&
                        ((hasMore && tn.level() != pitr.peek().level()) || !hasMore)) {

                    QueryBuilder query = QueryBuilder.start(Document.ID)
                            .in(sameLevelNodes.keySet());

                    // Fetch lastRev and modCount for each such nodes
                    DBCursor cursor = nodes.find(query.get(), keys);
                    LOG.debug(
                            "Checking for changed nodes at level {} with {} paths",
                            tn.level(), sameLevelNodes.size());
                    result.queryCount++;
                    for (DBObject obj : cursor) {
View Full Code Here

        }
        return blob;
    }

    private static DBObject getBlobQuery(String id, long lastMod) {
        QueryBuilder queryBuilder = new QueryBuilder();
        if (id != null) {
            queryBuilder = queryBuilder.and(MongoBlob.KEY_ID).is(id);
        }
        if (lastMod > 0) {
            queryBuilder = queryBuilder.and(MongoBlob.KEY_LAST_MOD).lessThan(lastMod);
        }
        return queryBuilder.get();
    }
View Full Code Here

        DBCollection collection = getBlobCollection();

        DBObject fields = new BasicDBObject();
        fields.put(MongoBlob.KEY_ID, 1);

        QueryBuilder builder = new QueryBuilder();
        if (maxLastModifiedTime != 0 && maxLastModifiedTime != -1) {
            builder.and(MongoBlob.KEY_LAST_MOD).lessThanEquals(maxLastModifiedTime);
        }

        final DBCursor cur =
                collection.find(builder.get(), fields).hint(fields)
                        .addOption(Bytes.QUERYOPTION_SLAVEOK);

        return new AbstractIterator<String>() {
            protected String computeNext() {
                if (cur.hasNext()) {
View Full Code Here

                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());
View Full Code Here

    @Override
    public List<Map<String, Object>> query(Collection collection,
            String fromKey, String toKey, int limit) {
        log("query", fromKey, toKey, limit);
        DBCollection dbCollection = getDBCollection(collection);
        QueryBuilder queryBuilder = QueryBuilder.start(UpdateOp.ID);
        queryBuilder.greaterThanEquals(fromKey);
        queryBuilder.lessThan(toKey);
        DBObject query = queryBuilder.get();
        long start = start();
        try {
            DBCursor cursor = dbCollection.find(query);
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            for (int i = 0; i < limit && cursor.hasNext(); i++) {
View Full Code Here

    private Map<String, Object> findAndModify(Collection collection,
                                               UpdateOp updateOp,
                                               boolean upsert,
                                               boolean checkConditions) {
        DBCollection dbCollection = getDBCollection(collection);
        QueryBuilder query = getByKeyQuery(updateOp.key);

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

        for (Entry<String, Operation> entry : updateOp.changes.entrySet()) {
            String k = entry.getKey();
            if (k.equals(UpdateOp.ID)) {
                // avoid exception "Mod on _id not allowed"
                continue;
            }
            Operation op = entry.getValue();
            switch (op.type) {
                case SET: {
                    setUpdates.append(k, op.value);
                    break;
                }
                case INCREMENT: {
                    incUpdates.append(k, op.value);
                    break;
                }
                case SET_MAP_ENTRY: {
                    setUpdates.append(k, op.value);
                    break;
                }
                case REMOVE_MAP_ENTRY: {
                    unsetUpdates.append(k, "1");
                    break;
                }
                case SET_MAP: {
                    String[] kv = k.split("\\.");
                    BasicDBObject sub = new BasicDBObject();
                    sub.put(kv[1], op.value);
                    setUpdates.append(kv[0], sub);
                    break;
                }
                case CONTAINS_MAP_ENTRY: {
                    if (checkConditions) {
                        query.and(k).exists(op.value);
                    }
                    break;
                }
            }
        }

        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);
        }

        // dbCollection.update(query, update, true /*upsert*/, false /*multi*/,
        //         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

        DBObject query = getBlobQuery(id, lastMod);
        return (MongoBlob) getBlobCollection().findOne(query);
    }

    private static DBObject getBlobQuery(String id, long lastMod) {
        QueryBuilder queryBuilder = new QueryBuilder();
        if (id != null) {
            queryBuilder = queryBuilder.and(MongoBlob.KEY_ID).is(id);
        }
        if (lastMod > 0) {
            queryBuilder = queryBuilder.and(MongoBlob.KEY_LAST_MOD).lessThan(lastMod);
        }
        return queryBuilder.get();
    }
View Full Code Here

TOP

Related Classes of com.mongodb.QueryBuilder$NullObject

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.