/** * Gets the last result from getLastError() * * @return The last error */ public CommandResult getCachedLastError() { return writeResult.getCachedLastError(); }
/** * Gets the last result from getLastError() * * @return The last error */ public CommandResult getCachedLastError() { return writeResult.getCachedLastError(); }
public static boolean wrapperUpdate(DBCollection collection, DBObject query, DBObject update) { WriteResult wr = collection.update(query, update, false, true); Boolean updated = (Boolean)wr.getCachedLastError().get("updatedExisting"); if (updated == null || !updated) { return false; } return true; } }
public <T> UpdateResults<T> updateFirst(Query<T> query, T entity, boolean createIfMissing) { LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>(); DBObject dbObj = mapr.toDBObject(entity, involvedObjects); UpdateResults<T> res = update(query, dbObj, createIfMissing, false, getWriteConcern(entity)); //update _id field CommandResult gle = res.getWriteResult().getCachedLastError(); if(gle != null && res.getInsertedCount() > 0) dbObj.put(Mapper.ID_KEY, res.getNewId()); postSaveOperations(entity, dbObj, involvedObjects); return res; }
public <T> Key<T> merge(T entity, WriteConcern wc) { LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>(); DBObject dbObj = mapr.toDBObject(entity, involvedObjects); Key<T> key = getKey(entity); entity = ProxyHelper.unwrap(entity); Object id = getId(entity); if (id == null) throw new MappingException("Could not get id for " + entity.getClass().getName()); Query<T> query = (Query<T>) createQuery(entity.getClass()).filter(Mapper.ID_KEY, id); //remove (immutable) _id field for update. dbObj.removeField(Mapper.ID_KEY); UpdateResults<T> res = update(query, new BasicDBObject("$set", dbObj), false, false, wc); //check for updated count if we have a gle CommandResult gle = res.getWriteResult().getCachedLastError(); if(gle != null && res.getUpdatedCount() == 0) throw new UpdateException("Not updated: " + gle); postSaveOperations(entity, dbObj, involvedObjects); return key; }
public <T> UpdateResults<T> updateFirst(final Query<T> query, final T entity, final boolean createIfMissing) { final LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>(); final DBObject dbObj = mapper.toDBObject(entity, involvedObjects); final UpdateResults<T> res = update(query, dbObj, createIfMissing, false, getWriteConcern(entity)); //update _id field final CommandResult gle = res.getWriteResult().getCachedLastError(); if (gle != null && res.getInsertedCount() > 0) { dbObj.put(Mapper.ID_KEY, res.getNewId()); } postSaveOperations(entity, dbObj, involvedObjects); return res; }
/** * @param query * @param entity * @param createIfMissing * @param <T> * @return */ public <T> UpdateResults<T> updateFirst(Query<T> query, T entity, boolean createIfMissing) { LinkedHashMap<Object, DBObject> involvedObjects = new LinkedHashMap<Object, DBObject>(); DBObject dbObj = mapr.toDBObject(entity, involvedObjects); UpdateResults<T> res = update(query, dbObj, createIfMissing, false, getWriteConcern(entity)); //update _id field CommandResult gle = res.getWriteResult().getCachedLastError(); if (gle != null && res.getInsertedCount() > 0) dbObj.put(Mapper.ID_KEY, res.getNewId()); postSaveOperations(entity, dbObj, involvedObjects); return res; }
final CommandResult gle = wr.getCachedLastError(); if (gle != null && res.getUpdatedCount() == 0) { throw new UpdateException("Not updated: " + gle);
CommandResult gle = wr.getCachedLastError(); if (gle != null && res.getUpdatedCount() == 0) throw new UpdateException("Not updated: " + gle);