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); } }
private void doUpdate(MongoCollection collection, String opQuery, Object[] parameters, String modifier, boolean upsert, boolean multi) throws DataServiceFault { if (opQuery != null) { if (parameters.length > 0) { Update update = collection.update(opQuery); if (upsert) { update = update.upsert(); } if (multi) { update = update.multi(); } update.with(modifier, parameters); } else { Update update = collection.update(opQuery); if (upsert) { update = update.upsert(); } if (multi) { update = update.multi(); } update.with(modifier); } } else { throw new DataServiceFault("Mongo update statements must contain a query"); } }
@Override public void update(final String id, final Object updateObject, 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(updateObject); } catch (com.mongodb.DuplicateKeyException ex) { String msg = "Duplicate key for update with id='" + id + "', updatedObject=" + updateObject + ", 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 + "', updatedObject=" + updateObject + ", multi=" + multi + ", upsert=" + upsert; log.error(msg, ex); throw new MongoDataException(msg, ex); } }
@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); } }