Package com.mongodb

Examples of com.mongodb.QueryBuilder$QueryBuilderException


                if (!sameLevelNodes.isEmpty() &&
                        ((hasMore && tn.level() != pitr.peek().level()) || !hasMore)) {
                    List<String> sameLevelNodeIds = new ArrayList<String>(sameLevelNodes.keySet());
                    for(List<String> idBatch : Lists.partition(sameLevelNodeIds, IN_QUERY_BATCH_SIZE)) {

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

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


   * @see DATAMONGO-373
   */
  @Test
  public void handlesNativelyBuiltQueryCorrectly() {

    DBObject query = new QueryBuilder().or(new BasicDBObject("foo", "bar")).get();
    mapper.getMappedObject(query, null);
  }
View Full Code Here

    return list;
  }
 
  @Override
  public void write(DocumentFile<MongoType> df) throws IOException {
    QueryBuilder qb = QueryBuilder.start()
        .put(DOCUMENT_KEY)
        .is(df.getDocumentId().getID())
        .and(FILENAME_KEY)
        .is(df.getFileName());
    documentfs.remove(qb.get());
   
    GridFSInputFile input = documentfs.createFile(df.getStream(), df.getFileName());
    input.put(DOCUMENT_KEY, df.getDocumentId().getID());
    input.put(ENCODING_KEY, df.getEncoding());
    input.put(MIMETYPE_KEY, df.getMimetype());
   
    input.save();
   
    /**
     * This is here because of random failures when trying to do this query from another thread.
     *
     * RemotePipelineTest.testSaveFile() failed 2 or 3 times out of 100.
     */
    long start = System.currentTimeMillis();
    while (documentfs.findOne(qb.get()) == null) {
      try {
        if(start+1000>System.currentTimeMillis()) {
          throw new IOException("Failed to save the file");
        }
        Thread.sleep(10);
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

        }
        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

    }

    @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, indexedProperty, startValue, limit);
        DBCollection dbCollection = getDBCollection(collection);
        QueryBuilder queryBuilder = QueryBuilder.start(Document.ID);
        queryBuilder.greaterThan(fromKey);
        queryBuilder.lessThan(toKey);

        DBObject hint = new BasicDBObject(NodeDocument.ID, 1);

        if (indexedProperty != null) {
            queryBuilder.and(indexedProperty);
            queryBuilder.greaterThanEquals(startValue);

            if (NodeDocument.MODIFIED_IN_SECS.equals(indexedProperty)
                    && canUseModifiedTimeIdx(startValue)) {
                hint = new BasicDBObject(NodeDocument.MODIFIED_IN_SECS, -1);
            }
        }
        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).hint(hint);
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.