Package com.mongodb

Examples of com.mongodb.CommandResult


            DBCollection collection = db.getCollection("useradmin");
            // we always get a collection back, regardless if there is an actual MongoDB listening, hence we should do
            // some actual calls that cause a connection to MongoDB to be created...
            collection.remove(new BasicDBObject(), WriteConcern.SAFE);

            CommandResult lastError = db.getLastError();

            return (lastError.getException() == null && collection.getCount() == 0L);
        }
        catch (Exception e)
        {
            // Ignore; apparently, we failed to connect to MongoDB...
        }
View Full Code Here


        geoNearCommand.put("near", coord);
        geoNearCommand.put("maxDistance", miles / 69.17);
        geoNearCommand.put("num", limit);
        geoNearCommand.put("spherical", true);

        CommandResult geoNearResult = Model.datastore.getDB().command(geoNearCommand);
        BasicDBList geoNearResults = (BasicDBList) geoNearResult.get("results");

        return Lists.newArrayList(Iterables.transform(geoNearResults, new Function<Object, PostcodeUnit>() {
            @Override
            public PostcodeUnit apply(@Nullable Object input) {
                BasicDBObject pcuObject = (BasicDBObject) ((BasicDBObject) input).get("obj");
View Full Code Here

   
    private void processAndTransferWriteResult(WriteResult result, Exchange exchange) {
        // if invokeGetLastError is set, or a WriteConcern is set which implicitly calls getLastError, then we have the chance to populate
        // the MONGODB_LAST_ERROR header, as well as setting an exception on the Exchange if one occurred at the MongoDB server
        if (endpoint.isInvokeGetLastError() || (endpoint.getWriteConcern() != null ? endpoint.getWriteConcern().callGetLastError() : false)) {
            CommandResult cr = result.getCachedLastError() == null ? result.getLastError() : result.getCachedLastError();
            exchange.getOut().setHeader(MongoDbConstants.LAST_ERROR, cr);
            if (!cr.ok()) {
                exchange.setException(MongoDbComponent.wrapInCamelMongoDbException(cr.getException()));
            }
        }
       
        // determine where to set the WriteResult: as the OUT body or as an IN message header
        if (endpoint.isWriteResultAsHeader()) {
View Full Code Here

   
    private void processAndTransferWriteResult(WriteResult result, Exchange exchange) {
        // if invokeGetLastError is set, or a WriteConcern is set which implicitly calls getLastError, then we have the chance to populate
        // the MONGODB_LAST_ERROR header, as well as setting an exception on the Exchange if one occurred at the MongoDB server
        if (endpoint.isInvokeGetLastError() || (endpoint.getWriteConcern() != null ? endpoint.getWriteConcern().callGetLastError() : false)) {
            CommandResult cr = result.getCachedLastError() == null ? result.getLastError() : result.getCachedLastError();
            exchange.getOut().setHeader(MongoDbConstants.LAST_ERROR, cr);
            if (!cr.ok()) {
                exchange.setException(MongoDbComponent.wrapInCamelMongoDbException(cr.getException()));
            }
        }
       
        // determine where to set the WriteResult: as the OUT body or as an IN message header
        if (endpoint.isWriteResultAsHeader()) {
View Full Code Here

        reader.close();
        in.close();
       
        // execute last statement
        try {
          CommandResult result = db.doEval("(function() {"+data.toString()+"})();", new Object[0]);
          if (!result.ok()) {
              getLog().warn(
                "Error executing "+file.getName()+": "
                +result.getErrorMessage(), result.getException());
          } else {
            getLog().info(" "+file.getName()+" executed successfully");
          }
        } catch(Exception e) {
          getLog().error(" error executing "+file.getName(), e);
View Full Code Here

        if (wc.callGetLastError()) {
            assertNotNull(wr.getCachedLastError());
        } else {
            assertNull(wr.getCachedLastError());
        }
        CommandResult cr = wr.getLastError();
        assertTrue(cr.ok());
    }
View Full Code Here

        Object result = template.requestBodyAndHeader("direct:noWriteConcern", "{\"scientist\":\"newton\"}", MongoDbConstants.WRITECONCERN, WriteConcern.SAFE);
        assertTrue("Result is not of type WriteResult", result instanceof WriteResult);
        WriteResult wr = (WriteResult) result;
        // should not be null because with WriteConcern.SAFE, getLastError was called implicitly by the driver
        assertNotNull(wr.getCachedLastError());
        CommandResult cr = wr.getLastError();
        assertTrue(cr.ok());
       
        // same behaviour should be reproduced with String 'SAFE'
        result = template.requestBodyAndHeader("direct:noWriteConcern", "{\"scientist\":\"newton\"}", MongoDbConstants.WRITECONCERN, "SAFE");
        assertTrue("Result is not of type WriteResult", result instanceof WriteResult);
        wr = (WriteResult) result;
        // should not be null because with WriteConcern.SAFE, getLastError was called implicitly by the driver
        assertNotNull(wr.getCachedLastError());
        cr = wr.getLastError();
        assertTrue(cr.ok());
    }
View Full Code Here

   
    private void processAndTransferWriteResult(WriteResult result, Exchange exchange) {
        // if invokeGetLastError is set, or a WriteConcern is set which implicitly calls getLastError, then we have the chance to populate
        // the MONGODB_LAST_ERROR header, as well as setting an exception on the Exchange if one occurred at the MongoDB server
        if (endpoint.isInvokeGetLastError() || (endpoint.getWriteConcern() != null ? endpoint.getWriteConcern().callGetLastError() : false)) {
            CommandResult cr = result.getCachedLastError() == null ? result.getLastError() : result.getCachedLastError();
            exchange.getOut().setHeader(MongoDbConstants.LAST_ERROR, cr);
            if (!cr.ok()) {
                exchange.setException(MongoDbComponent.wrapInCamelMongoDbException(cr.getException()));
            }
        }
       
        // determine where to set the WriteResult: as the OUT body or as an IN message header
        if (endpoint.isWriteResultAsHeader()) {
View Full Code Here

        lockDoc.put(LockDef.LOCK_ATTEMPT_COUNT.field, 0);
        lockDoc.put(LockDef.INACTIVE_LOCK_TIMEOUT.field, pLockOptions.getInactiveLockTimeout());

        // Insert, if successful then get out of here.
        final WriteResult result = getDbCollection(pMongo, pSvcOptions).insert(lockDoc, WriteConcern.NORMAL);
        final CommandResult cmdResult = result.getLastError();

        if (cmdResult.getErrorMessage() != null) return null;

       if (pSvcOptions.getEnableHistory())
       { LockHistoryDao.insert( pMongo, pLockName, pSvcOptions, pLockOptions, serverTime, LockState.LOCKED, lockId, false); }

        return lockId;
View Full Code Here

        if (wc.callGetLastError()) {
            assertNotNull(wr.getCachedLastError());
        } else {
            assertNull(wr.getCachedLastError());
        }
        CommandResult cr = wr.getLastError();
        assertTrue(cr.ok());
    }
View Full Code Here

TOP

Related Classes of com.mongodb.CommandResult

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.