Package com.mongodb

Examples of com.mongodb.CommandResult


        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(WriteConcern.NORMAL);

        if (!cmdResult.ok() || cmdResult.getException() != null || 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


          clientURI.getOptions());
      DB db = client.getDB(scanSpec.getDbName());
      db.setReadPreference(ReadPreference.nearest());
      DBCollection collection = db.getCollectionFromString(scanSpec
          .getCollectionName());
      CommandResult stats = collection.getStats();
      return new ScanStats(GroupScanProperty.EXACT_ROW_COUNT,
          stats.getLong(COUNT), 1, (float) stats.getDouble(SIZE));
    } catch (Exception e) {
      throw new DrillRuntimeException(e.getMessage(), e);
    }
  }
View Full Code Here

    if (command == null) {
        throw new MissingCellsFailureException(cells.text()
        + " requires an argument");
    }
    String cmdString = command.text();
    CommandResult result = db.doEval(cmdString);
    if (result.ok()) {
      right(command);
    } else {
      wrong(command, result.getErrorMessage());
    }
  }
View Full Code Here

    if (command == null) {
      throw new MissingCellsFailureException(cells.text()
          + " requires an argument");
    }
    String cmdString = command.text();
    CommandResult result = db.doEval(cmdString);
    if (result.ok()) {
      right(command);
    } else {
      wrong(command, result.getErrorMessage());
    }
  }
View Full Code Here

        return Boolean.valueOf(System.getProperty("authEnabled", "false"))
               || "auth".equals(System.getProperty("mongodb_option"));
    }

    protected boolean isSharded(final MongoClientURI uri) {
        CommandResult isMasterResult = runIsMaster(uri);
        Object msg = isMasterResult.get("msg");
        return msg != null && msg.equals("isdbgrid");
    }
View Full Code Here

                                      // force:True is misbehaving it seems
                                 .add("force", false)
                                 .add("maxChunkSize", splitSize)
                                 .get();

        CommandResult data;
        boolean ok = true;
        if (authDB == null) {
            try {
                data = inputCollection.getDB().getSisterDB("admin").command(cmd);
            } catch (MongoException e) {  // 2.0 servers throw exceptions rather than info in a CommandResult
                data = null;
                LOG.info(e.getMessage(), e);
                if (e.getMessage().contains("unrecognized command: splitVector")) {
                    ok = false;
                } else {
                    throw e;
                }
            }
        } else {
            data = authDB.command(cmd);
        }

        if (data != null) {
            if (data.containsField("$err")) {
                throw new SplitFailedException("Error calculating splits: " + data);
            } else if (!data.get("ok").equals(1.0)) {
                ok = false;
            }
        }

        if (!ok) {
            CommandResult stats = inputCollection.getStats();
            if (stats.containsField("primary")) {
                DBCursor shards = inputCollection.getDB().getSisterDB("config")
                                                 .getCollection("shards")
                                                 .find(new BasicDBObject("_id", stats.getString("primary")));
                try {
                    if (shards.hasNext()) {
                        DBObject shard = shards.next();
                        String host = ((String) shard.get("host")).replace(shard.get("_id") + "/", "");
                        MongoClientURI shardHost = new MongoClientURIBuilder(inputURI)
View Full Code Here

        // big split for the whole collection.
        if (!MongoConfigUtil.createInputSplits(config)) {
            returnVal = new SingleMongoSplitter(config);
        } else {
            MongoClientURI authURI = MongoConfigUtil.getAuthURI(config);
            CommandResult stats;
            DBCollection coll;
            if (authURI != null) {
                coll = MongoConfigUtil.getCollectionWithAuth(uri, authURI);
                stats = coll.getStats();
                LOG.info("Retrieved Collection stats:" + stats);
            } else {
                coll = MongoConfigUtil.getCollection(uri);
                stats = coll.getStats();
            }

            if (!stats.getBoolean("ok", false)) {
                throw new RuntimeException("Unable to calculate input splits from collection stats: " + stats.getString("errmsg"));
            }

            if (!stats.getBoolean("sharded", false)) {
                returnVal = new StandaloneMongoSplitter(config);
            } else {
                // Collection is sharded
                if (MongoConfigUtil.isShardChunkedSplittingEnabled(config)) {
                    // Creates one split per chunk.
View Full Code Here

    assertEquals("localhost", servers.get(1).getHost());
    assertEquals(10001, servers.get(0).getPort());
    assertEquals(10002, servers.get(1).getPort());

    MongoTemplate template = new MongoTemplate(mongo, "admin");
    CommandResult result = template.executeCommand("{replSetGetStatus : 1}");
    assertEquals("blort", result.getString("set"));
  }
View Full Code Here

    return executeCommand((DBObject) JSON.parse(jsonCommand));
  }

  public CommandResult executeCommand(final DBObject command) {

    CommandResult result = execute(new DbCallback<CommandResult>() {
      public CommandResult doInDB(DB db) throws MongoException, DataAccessException {
        return db.command(command);
      }
    });
View Full Code Here

    return result;
  }

  public CommandResult executeCommand(final DBObject command, final int options) {

    CommandResult result = execute(new DbCallback<CommandResult>() {
      public CommandResult doInDB(DB db) throws MongoException, DataAccessException {
        return db.command(command, options);
      }
    });
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.