Example usage for com.mongodb MongoException MongoException

List of usage examples for com.mongodb MongoException MongoException

Introduction

In this page you can find the example usage for com.mongodb MongoException MongoException.

Prototype

public MongoException(final String msg) 

Source Link

Usage

From source file:org.apache.felix.useradmin.mongodb.MongoSerializerHelper.java

License:Apache License

/**
 * Finds an existing member by its name.
 * // www  . j  a  v a  2  s  .com
 * @param name the name of the member to return, cannot be <code>null</code>.
 * @return a member instance, never <code>null</code>.
 * @throws MongoException in case the requested member was not found (or any other MongoDB exception).
 */
final Role findExistingMember(String name) {
    Role result = m_roleProvider.getRole(name);
    if (result == null) {
        throw new MongoException("No such role: " + name);
    }
    return result;
}

From source file:org.craftercms.studio.impl.repository.mongodb.data.JongoCollectionFactory.java

License:Open Source License

public void init() {
    db = mongo.getDB(dbName);/*from   w w  w . j ava2 s . c o m*/
    if (!StringUtils.isBlank(password)) {
        boolean authenticated = db.authenticate(userName, password.toCharArray());
        if (!authenticated) {
            throw new MongoException("Authentication fail for database " + dbName);
        }
    }
    jongo = new Jongo(db);
}

From source file:org.fiware.apps.repository.dao.MongoDAOFactory.java

License:BSD License

public synchronized static DB createConnection() {
    Mongo m;//from w w  w. j a  va  2  s.c o m
    DB db;

    try {
        m = new Mongo(RepositorySettings.getProperty("mongodb.host"),
                Integer.parseInt(RepositorySettings.getProperty("mongodb.port")));
        db = m.getDB(RepositorySettings.getProperty("mongodb.db"));
    } catch (UnknownHostException | MongoException ex) {
        throw new MongoException(ex.getLocalizedMessage());
    }
    return db;
}

From source file:org.flywaydb.core.internal.dbsupport.MongoScript.java

License:Apache License

/**
 * Executes the MongoStatements found in this MongoScript against the database.
 *
 * @param mongoClient The MongoClient to use to execute this script.
 *///from  ww w  .  j a  v  a2s  .com
public void execute(final MongoClient mongoClient) {
    MongoDatabase mongoDatabase = mongoClient.getDatabase(databaseName);
    for (MongoStatement mongoStatement : mongoStatements) {
        LOG.debug("Executing MONGO: " + mongoStatement);
        try {
            mongoDatabase.runCommand(Document.parse(mongoStatement.getJson()));
        } catch (JsonParseException jpe) {
            MongoException e = new MongoException("Cannot parse mongo command. " + jpe.getMessage());
            throw new FlywayMongoScriptException(resource, mongoStatement, e);
        } catch (MongoException e) {
            throw new FlywayMongoScriptException(resource, mongoStatement, e);
        }
    }
}

From source file:org.flywaydb.core.internal.resolver.mongodb.MongoMigrationExecutor.java

License:Apache License

@Override
public void execute(MongoClient client) throws MongoException {
    try {/*  w  ww .  jav a 2  s . co  m*/
        mongoMigration.migrate(client);
    } catch (Exception e) {
        throw new MongoException("MongoDB migrate failed: " + e.getLocalizedMessage());
    }
}

From source file:org.mongojack.DBCursor.java

License:Apache License

private void checkExecuted() {
    if (executed) {
        throw new MongoException("Cannot modify query after it's been executed");
    }//from  ww  w. j  a  v a  2  s  .  c  om
}

From source file:org.mongojack.WriteResult.java

License:Apache License

/**
 * Get the object that was saved.  This will contain the updated ID if the ID was generated.
 * <p/>/*from  ww w. j  a va  2s  . c o  m*/
 * Note, this operation is a little expensive because it has to deserialise the object.  If you just want the ID,
 * call getSavedId() instead.
 *
 * @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);
}

From source file:org.mongojack.WriteResult.java

License:Apache License

/**
 * Get the saved ID.  This may be useful for finding out the ID that was generated by MongoDB if no ID was supplied.
 *
 * @return The saved ID//from ww  w. j  a  va 2  s  . c o  m
 * @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"));
}

From source file:org.mule.module.mongo.api.MongoClientImpl.java

License:Open Source License

public WriteResult addUser(final String username, final String password) {
    Validate.notNull(username);/*from  w  ww .  j a v a2s  .  co  m*/
    Validate.notNull(password);
    final WriteResult writeResult = db.addUser(username, password.toCharArray());
    if (!writeResult.getLastError().ok()) {
        throw new MongoException(writeResult.getLastError().getErrorMessage());
    }
    return writeResult;
}

From source file:org.mule.module.mongo.api.MongoClientImpl.java

License:Open Source License

public DBObject findOneObject(@NotNull final String collection, final DBObject query, final List<String> fields,
        boolean failOnNotFound) {
    Validate.notNull(collection);//from  ww w .ja v a 2  s . c o m
    final DBObject element = db.getCollection(collection).findOne(query, FieldsSet.from(fields));

    if (element == null && failOnNotFound) {
        throw new MongoException("No object found for query " + query);
    }
    return element;
}