Package com.imaginea.mongodb.exceptions

Examples of com.imaginea.mongodb.exceptions.DatabaseException


                Mongo mongoInstance = authService.getMongoInstance(connectionId);
                // Get Server Stats
                try {
                    return mongoInstance.getDB("admin").command("serverStatus");
                } catch (MongoException e) {
                    throw new DatabaseException(ErrorCodes.GET_DB_STATS_EXCEPTION, e.getMessage());
                }
            }
        });
        return response;
    }
View Full Code Here



    @Override
    public String addUser(String dbName, String username, String password, boolean readOnly) throws ApplicationException {
        if (dbName == null) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database name is null");
        }
        if (dbName.equals("")) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database Name Empty");
        }
        if (username == null) {
            throw new DatabaseException(ErrorCodes.USERNAME_IS_EMPTY, "Username is null");
        }
        if (username.equals("")) {
            throw new DatabaseException(ErrorCodes.USERNAME_IS_EMPTY, "Username is empty");
        }
        if (password == null) {
            throw new DatabaseException(ErrorCodes.PASSWORD_IS_EMPTY, "Password is null");
        }
        if (password.equals("")) {
            throw new DatabaseException(ErrorCodes.PASSWORD_IS_EMPTY, "Password is empty");
        }
        try {
            mongoInstance.getDB(dbName).addUser(username, password.toCharArray(), readOnly);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.USER_CREATION_EXCEPTION, e.getMessage());
View Full Code Here

     * @throws DatabaseException throwsuper type of UndefinedDatabaseException
     */
    @Override
    public String removeUser(String dbName, String username) throws ApplicationException {
        if (dbName == null) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database name is null");
        }
        if (dbName.equals("")) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database Name Empty");
        }
        if (username == null) {
            throw new DatabaseException(ErrorCodes.USERNAME_IS_EMPTY, "Username is null");
        }
        if (username.equals("")) {
            throw new DatabaseException(ErrorCodes.USERNAME_IS_EMPTY, "Username is empty");
        }
        try {
            mongoInstance.getDB(dbName).removeUser(username);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.USER_DELETION_EXCEPTION, e.getMessage());
View Full Code Here

     */

    @Override
    public String removeAllUsers(String dbName) throws ApplicationException {
        if (dbName == null) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database name is null");
        }
        if (dbName.equals("")) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database Name Empty");
        }
        DBCursor users = mongoInstance.getDB(dbName).getCollection("system.users").find();
        if (users.size() != 0) {
            for (DBObject user : users) {
                try {
View Full Code Here

     */

    @Override
    public String addIndex(String dbName, String collectionName, DBObject keys) throws ApplicationException {
        if (dbName == null) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database name is null");
        }
        if (dbName.equals("")) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database Name Empty");
        }

        if (collectionName == null) {
            throw new DatabaseException(ErrorCodes.COLLECTION_NAME_EMPTY, "Collection name is null");
        }
        if (collectionName.equals("")) {
            throw new DatabaseException(ErrorCodes.COLLECTION_NAME_EMPTY, "Collection name is Empty");
        }
        if (keys == null) {
            throw new DatabaseException(ErrorCodes.KEYS_EMPTY, "Index Keys are null");
        }
        if (keys.equals("")) {
            throw new DatabaseException(ErrorCodes.KEYS_EMPTY, "Index keys are Empty");
        }
        try {
            mongoInstance.getDB(dbName).getCollection(collectionName).ensureIndex(keys);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.INDEX_ADDITION_EXCEPTION, e.getMessage());
View Full Code Here

     */

    @Override
    public String removeIndexes(String dbName) throws ApplicationException {
        if (dbName == null) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database name is null");
        }
        if (dbName.equals("")) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database Name Empty");
        }

        Set<String> collectionNames = mongoInstance.getDB(dbName).getCollectionNames();
        for (String collection : collectionNames) {
            try {
View Full Code Here

     */

    @Override
    public String removeIndex(String dbName, String collectionName, String indexName) throws ApplicationException {
        if (dbName == null) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database name is null");
        }
        if (dbName.equals("")) {
            throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database Name Empty");
        }
        if (collectionName == null) {
            throw new DatabaseException(ErrorCodes.COLLECTION_NAME_EMPTY, "Collection name is null");
        }
        if (collectionName.equals("")) {
            throw new DatabaseException(ErrorCodes.COLLECTION_NAME_EMPTY, "Collection name is Empty");
        }
        if (indexName == null) {
            throw new DatabaseException(ErrorCodes.INDEX_EMPTY, "Index name is null");
        }
        if (indexName.equals("")) {
            throw new DatabaseException(ErrorCodes.INDEX_EMPTY, "Index name is Empty");
        }
        try {
            mongoInstance.getDB(dbName).getCollection(collectionName).dropIndexes(indexName);
        } catch (MongoException e) {
            throw new ApplicationException(ErrorCodes.INDEX_REMOVE_EXCEPTION, e.getMessage());
View Full Code Here

            while (resultIterator.hasNext()) {
                results.add(resultIterator.next());
            }
            return ApplicationUtils.constructResponse(false, results.size(), results);
        }
        throw new DatabaseException(ErrorCodes.INVALID_AGGREGATE_COMMAND, "Aggregate command is ill formed");
    }
View Full Code Here

    }

    private static JSONObject executeDropIndex(DBCollection dbCollection, String queryStr) throws JSONException, DatabaseException {
        DBObject indexInfo = (DBObject) JSON.parse(queryStr);
        if (indexInfo == null) {
            throw new DatabaseException(ErrorCodes.INDEX_EMPTY, "Index is null");
        }
        dbCollection.dropIndex(indexInfo);
        return executeGetIndexes(dbCollection);
    }
View Full Code Here

    private static JSONObject executeEnsureIndex(DBCollection dbCollection, String queryStr) throws JSONException, DatabaseException {
        DBObject queryObj = (DBObject) JSON.parse("[" + queryStr + "]");
        DBObject keys = (DBObject) queryObj.get("0");
        if (keys == null) {
            throw new DatabaseException(ErrorCodes.KEYS_EMPTY, "Index Keys are null");
        }
        if (keys.equals("")) {
            throw new DatabaseException(ErrorCodes.KEYS_EMPTY, "Index keys are Empty");
        }
        DBObject options = (DBObject) queryObj.get("1");
        if (options != null) {
            dbCollection.ensureIndex(keys, options);
        } else {
View Full Code Here

TOP

Related Classes of com.imaginea.mongodb.exceptions.DatabaseException

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.