Package com.mongodb

Examples of com.mongodb.QueryBuilder$NullObject


    }

    @Override
    public boolean deleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception {
        DBCollection collection = getBlobCollection();
        QueryBuilder queryBuilder = new QueryBuilder();
        if (chunkIds != null) {
            queryBuilder = queryBuilder.and(MongoBlob.KEY_ID).in(chunkIds.toArray(new String[0]));
            if (maxLastModifiedTime > 0) {
                queryBuilder = queryBuilder.and(MongoBlob.KEY_LAST_MOD)
                                    .lessThan(maxLastModifiedTime);
            }
        }

        WriteResult result = collection.remove(queryBuilder.get());
        if (result.getN() == chunkIds.size()) {
            return true;
        }

        return false;
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);

        //TODO The cursor needs to be closed
        return new AbstractIterator<String>() {
            @Override
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();
        String parentId = Utils.getParentIdFromLowerLimit(fromKey);
        TreeLock lock = acquireExclusive(parentId != null ? parentId : "");
        long start = start();
        try {
            DBCursor cursor = dbCollection.find(query).sort(BY_ID_ASC);
View Full Code Here

        }), cursor);
    }

    @Override
    public boolean acquireRecoveryLock(int clusterId) {
        QueryBuilder query =
                start().and(
                        start(Document.ID).is(Integer.toString(clusterId)).get(),
                        start(ClusterNodeInfo.REV_RECOVERY_LOCK).notEquals(RecoverLockState.ACQUIRED.name()).get()
                );

        DBObject returnFields = new BasicDBObject();
        returnFields.put("_id", 1);

        BasicDBObject setUpdates = new BasicDBObject();
        setUpdates.append(ClusterNodeInfo.REV_RECOVERY_LOCK, RecoverLockState.ACQUIRED.name());

        BasicDBObject update = new BasicDBObject();
        update.append("$set", setUpdates);

        DBObject oldNode = getClusterNodeCollection().findAndModify(query.get(), returnFields,
                null /*sort*/, false /*remove*/, update, false /*returnNew*/,
                false /*upsert*/);

        return oldNode != null;
    }
View Full Code Here

        return oldNode != null;
    }

    @Override
    public boolean isRecoveryNeeded(long currentTime) {
        QueryBuilder query =
                start(ClusterNodeInfo.STATE).is(ClusterNodeInfo.ClusterNodeState.ACTIVE.name())
                .put(ClusterNodeInfo.LEASE_END_KEY).lessThan(currentTime)
                .put(ClusterNodeInfo.REV_RECOVERY_LOCK).notEquals(RecoverLockState.ACQUIRED.name());

        return getClusterNodeCollection().findOne(query.get()) != null;
    }
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

    @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);
        // make sure we don't modify the original updateOp
        updateOp = updateOp.copy();
        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());
                }
                if (collection == Collection.NODES) {
                    // update cache
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

    @Override
    public int deleteSplitDocuments(Set<SplitDocType> gcTypes, long oldestRevTimeStamp) {
        //OR condition has to be first as we have a index for that
        //((type == DEFAULT_NO_CHILD || type == PROP_COMMIT_ONLY ..) && _sdMaxRevTime < oldestRevTimeStamp(in secs)
        QueryBuilder orClause = start();
        for(SplitDocType type : gcTypes){
            orClause.or(start(NodeDocument.SD_TYPE).is(type.typeCode()).get());
        }
        DBObject query = start()
                .and(
                    orClause.get(),
                    start(NodeDocument.SD_MAX_REV_TIME_IN_SECS)
                        .lessThan(NodeDocument.getModifiedInSecs(oldestRevTimeStamp))
                        .get()
                ).get();
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);
            cursor.setReadPreference(ReadPreference.primary());
            result.queryCount++;

            for (DBObject obj : cursor) {
                result.cacheEntriesProcessedCount++;
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.