Package com.mongodb

Examples of com.mongodb.MongoException$Network


            } else {
                if (mongo.getDB("admin").authenticate(user, password.toCharArray())) {
                    logger.debug("Successfully authenticated to MongoDB database (" + dbName +
                            ") as admin " + user);
                } else {
                    throw new MongoException("Unable to authenticate to MongoDB using " +
                            user + "@" + dbName + " or " + user + "@admin.");
                }
            }
        } else {
            logger.debug("Create the morphia datastore WITHOUT credentials");
View Full Code Here


     * @return The saved object
     * @throws MongoException If no objects were saved
     */
    public T getSavedObject() {
        if (dbObjects.length == 0) {
            throw new MongoException("No objects to return");
        }
        return getSavedObjects().get(0);
    }
View Full Code Here

     * @return The saved ID
     * @throws MongoException If no objects were saved
     */
    public K getSavedId() {
        if (dbObjects.length == 0) {
            throw new MongoException("No objects to return");
        }
        if (dbObjects[0] instanceof JacksonDBObject) {
            throw new UnsupportedOperationException("Generated _id retrieval not supported when using stream serialization");
        }
        return jacksonDBCollection.convertFromDbId(dbObjects[0].get("_id"));
View Full Code Here

     * @return The underlying DBObject
     * @throws MongoException If no objects were saved
     */
    public DBObject getDbObject() {
        if (dbObjects.length == 0) {
            throw new MongoException("No objects to return");
        }
        return dbObjects[0];
    }
View Full Code Here

        label = in;
        setStringFieldValue(Item.errorIn, in);
        setStringFieldValue(Item.errorMsg, exception.getMessage());
        String code = "?";
        if (exception instanceof MongoException) {
            MongoException me = (MongoException) exception;
            code = String.valueOf(me.getCode());
        }

        setStringFieldValue(Item.errorCode, code);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintWriter pw = new PrintWriter(baos);
View Full Code Here

                // The generator buffers everything so that it can write the number of bytes to the stream
                generator.close();
            } catch (JsonMappingException e) {
                throw new MongoJsonMappingException(e);
            } catch (IOException e) {
                throw new MongoException("Error writing object out", e);
            }
            return stream.getCount();
        } else {
            return defaultDBEncoder.writeObject(buf, object);
        }
View Full Code Here

                    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

    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

  }

  @Test
  public void translateToUncategorizedMongoDbException() {

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

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

  }

  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

TOP

Related Classes of com.mongodb.MongoException$Network

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.