Examples of MongoException


Examples of com.mongodb.MongoException

                    dbfile = getGridFS().findOne(query);
                } else {
                    dbfile = getGridFS().findOne(fname);
                }
                if (dbfile == null) {
                    throw new MongoException("GridFS cannot find file " + fname);
                }
                dbfile.writeTo(dfile);
                return dbfile;
            }
View Full Code Here

Examples of com.mongodb.MongoException

    public void open() {
        try {
            mongo = new MongoClient(uri);
        } catch (final Exception e) {
            LOG.error("Connecting to MongoDB failed.", e);
            throw new MongoException("Failed to connect to MongoDB. ", e);
        }
        try {
            collection = mongo.getDB(uri.getDatabase()).getCollection(uri.getCollection());
        } catch (final Exception e) {
            LOG.error("Connected to MongoDB but failed in acquiring collection.", e);
            throw new MongoException("Could not acquire specified collection.", e);
        }
    }
View Full Code Here

Examples of com.mongodb.MongoException

  }

  @Test
  public void translateToUncategorizedMongoDbException() {

    MongoException exception = new MongoException(0, "");
    DataAccessException translatedException = translator.translateExceptionIfPossible(exception);

    expectExceptionWithCauseMessage(translatedException, UncategorizedMongoDbException.class);
  }
View Full Code Here

Examples of com.mongodb.MongoException

  }

  private void checkTranslatedMongoException(Class<? extends Exception> clazz, int code) {

    try {
      translator.translateExceptionIfPossible(new MongoException(code, ""));
      fail("Expected exception of type " + clazz.getName() + "!");
    } catch (NestedRuntimeException e) {
      Throwable cause = e.getRootCause();
      assertThat(cause, is(instanceOf(MongoException.class)));
      assertThat(((MongoException) cause).getCode(), is(code));
View Full Code Here

Examples of com.mongodb.MongoException

  public CommandResult getServerStatus() {
    CommandResult result = getDb("admin").command("serverStatus");
    if (!result.ok()) {
      logger.error("Could not query for server status.  Command Result = " + result);
      throw new MongoException("could not query for server status.  Command Result = " + result);
    }
    return result;
  }
View Full Code Here

Examples of com.mongodb.MongoException

  }

  @Test(expected = DataAccessException.class)
  public void removeHandlesMongoExceptionProperly() throws Exception {
    MongoTemplate template = mockOutGetDb();
    when(db.getCollection("collection")).thenThrow(new MongoException("Exception!"));

    template.remove(null, "collection");
  }
View Full Code Here

Examples of com.mongodb.MongoException

    * @see org.springframework.data.mongodb.core.core.MongoOperationsUnitTests#getOperations()
    */
  @Override
  protected MongoOperations getOperationsForExceptionHandling() {
    MongoTemplate template = spy(this.template);
    stub(template.getDb()).toThrow(new MongoException("Error!"));
    return template;
  }
View Full Code Here

Examples of com.mongodb.MongoException

    db = mongo.getDB(conf.getNamespace());

    if (requiresAuthentication(mongo)) {
      if (!mongo.getDB("admin").authenticate(conf.getDatabaseUser(),
          conf.getDatabasePassword().toCharArray())) {
        throw new ConnectionException(new MongoException(
            "Failed to authenticate to MongoDB with username="
                + conf.getDatabaseUser()));
      }
    }
View Full Code Here

Examples of com.mongodb.MongoException

            Collection<T> collection, String key,
            DocumentReadPreference docReadPref,
            int retries) {
        checkArgument(retries >= 0, "retries must not be negative");
        int numAttempts = retries + 1;
        MongoException ex = null;
        for (int i = 0; i < numAttempts; i++) {
            if (i > 0) {
                LOG.warn("Retrying read of " + key);
            }
            try {
View Full Code Here

Examples of com.mongodb.MongoException

        protected <T extends Document> T findUncached(Collection<T> collection,
                                                      String key,
                                                      DocumentReadPreference docReadPref) {
            if (failRead > 0) {
                failRead--;
                throw new MongoException("read failed");
            }
            return super.findUncached(collection, key, docReadPref);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.