Package com.mongodb

Examples of com.mongodb.QueryBuilder$QueryBuilderException


                                              String indexedProperty,
                                              long startValue,
                                              int limit) {
        log("query", fromKey, toKey, limit);
        DBCollection dbCollection = getDBCollection(collection);
        QueryBuilder queryBuilder = QueryBuilder.start(Document.ID);
        queryBuilder.greaterThan(fromKey);
        queryBuilder.lessThan(toKey);
        if (indexedProperty != null) {
            queryBuilder.and(indexedProperty);
            queryBuilder.greaterThanEquals(startValue);
        }
        DBObject query = queryBuilder.get();
        long start = start();
        try {
            DBCursor cursor = dbCollection.find(query);
            List<T> list = new ArrayList<T>();
            for (int i = 0; i < limit && cursor.hasNext(); i++) {
View Full Code Here


        long start = start();
        try {
            // perform a conditional update with limited result
            // if we have a matching modCount
            if (modCount != null) {
                QueryBuilder query = createQueryForUpdate(updateOp, checkConditions);
                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);
                    // return previously cached document
                    return cachedDoc;
                }
            }

            // 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

    @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 {
            try {

                WriteResult writeResult = dbCollection.updateMulti(query.get(), update);
                if (writeResult.getError() != null) {
                    throw new MicroKernelException("Update failed: " + writeResult.getError());
                }
                if (collection == Collection.NODES) {
                    // update cache
View Full Code Here

    }

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

        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

                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

        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

                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

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

                                              String indexedProperty,
                                              long startValue,
                                              int limit) {
        log("query", fromKey, toKey, limit);
        DBCollection dbCollection = getDBCollection(collection);
        QueryBuilder queryBuilder = QueryBuilder.start(Document.ID);
        queryBuilder.greaterThan(fromKey);
        queryBuilder.lessThan(toKey);
        if (indexedProperty != null) {
            queryBuilder.and(indexedProperty);
            queryBuilder.greaterThanEquals(startValue);
        }
        DBObject query = queryBuilder.get();
        long start = start();
        try {
            DBCursor cursor = dbCollection.find(query).sort(BY_ID_ASC);
            List<T> list = new ArrayList<T>();
            for (int i = 0; i < limit && cursor.hasNext(); i++) {
View Full Code Here

            }

            // perform a conditional update with limited result
            // if we have a matching modCount
            if (modCount != null) {
                QueryBuilder query = createQueryForUpdate(updateOp, checkConditions);
                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);
                    // return previously cached document
                    return cachedDoc;
                }
            }

            // 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

TOP

Related Classes of com.mongodb.QueryBuilder$QueryBuilderException

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.