Search in sources :

Example 1 with Update

use of org.jongo.Update in project commons by craftercms.

the class AbstractJongoRepository method update.

@Override
public void update(final String id, final String modifier, final boolean multi, final boolean upsert) throws MongoDataException {
    try {
        Update update = getCollection().update(new ObjectId(id));
        if (multi) {
            update.multi();
        }
        if (upsert) {
            update.upsert();
        }
        update.with(modifier);
    } catch (com.mongodb.DuplicateKeyException ex) {
        String msg = "Duplicate key for update with id='" + id + "', modifier=" + modifier + ", multi=" + multi + ", upsert=" + upsert;
        log.error(msg, ex);
        throw new MongoDataException(msg, ex);
    } catch (MongoException ex) {
        String msg = "Unable to do update with id='" + id + "', modifier=" + modifier + ", multi=" + multi + ", upsert=" + upsert;
        log.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) ObjectId(org.bson.types.ObjectId) Update(org.jongo.Update)

Example 2 with Update

use of org.jongo.Update in project profile by craftercms.

the class ProfileRepositoryImpl method updateAllWithDefaultValue.

@Override
public void updateAllWithDefaultValue(String tenantName, String attributeName, Object defaultValue) throws MongoDataException {
    try {
        String query = getQueryFor(KEY_FIND_BY_TENANT_AND_NON_EXISTING_ATTRIB_QUERY);
        Update update = getCollection().update(query, tenantName, attributeName).multi();
        update.with(MODIFIER_UPDATE_ATTRIBUTE, attributeName, defaultValue);
    } catch (MongoException ex) {
        String msg = "Unable to add attribute with name '" + attributeName + "' to profiles of tenant '" + tenantName + "'";
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Update(org.jongo.Update)

Example 3 with Update

use of org.jongo.Update in project profile by craftercms.

the class ProfileRepositoryImpl method removeAttributeFromAll.

@Override
public void removeAttributeFromAll(String tenantName, String attributeName) throws MongoDataException {
    try {
        String query = getQueryFor(KEY_FIND_BY_TENANT_AND_EXISTING_ATTRIB_QUERY);
        Update update = getCollection().update(query, tenantName, attributeName).multi();
        update.with(MODIFIER_REMOVE_ATTRIBUTE, attributeName);
    } catch (MongoException ex) {
        String msg = "Unable to remove attribute with name '" + attributeName + "' from profiles of tenant '" + tenantName + "'";
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Update(org.jongo.Update)

Example 4 with Update

use of org.jongo.Update in project profile by craftercms.

the class ProfileRepositoryImpl method removeRoleFromAll.

@Override
public void removeRoleFromAll(String tenantName, String role) throws MongoDataException {
    try {
        String query = getQueryFor(KEY_FIND_BY_TENANT_AND_ROLE_QUERY);
        Update update = getCollection().update(query, tenantName, role).multi();
        update.with(MODIFIER_REMOVE_ROLE, role);
    } catch (MongoException ex) {
        String msg = "Unable to remove role '" + role + "' from profiles of tenant '" + tenantName + "'";
        logger.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) MongoDataException(org.craftercms.commons.mongo.MongoDataException) Update(org.jongo.Update)

Example 5 with Update

use of org.jongo.Update in project commons by craftercms.

the class AbstractJongoRepository method update.

public void update(final String id, final String modifier, final boolean multi, final boolean upsert, final Object... params) throws MongoDataException {
    try {
        Update update = getCollection().update(new ObjectId(id));
        if (multi) {
            update.multi();
        }
        if (upsert) {
            update.upsert();
        }
        update.with(modifier, params);
    } catch (com.mongodb.DuplicateKeyException ex) {
        String msg = "Duplicate key for update with id='" + id + "', modifier=" + modifier + ", multi=" + multi + ", upsert=" + upsert + ", params" + Arrays.toString(params);
        log.error(msg, ex);
        throw new MongoDataException(msg, ex);
    } catch (MongoException ex) {
        String msg = "Unable to do update with id='" + id + "', modifier=" + modifier + ", multi=" + multi + ", upsert=" + upsert + ", params" + Arrays.toString(params);
        log.error(msg, ex);
        throw new MongoDataException(msg, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) ObjectId(org.bson.types.ObjectId) Update(org.jongo.Update)

Aggregations

MongoException (com.mongodb.MongoException)5 Update (org.jongo.Update)5 MongoDataException (org.craftercms.commons.mongo.MongoDataException)3 ObjectId (org.bson.types.ObjectId)2