@Override public <T> T update(Object id, T objectToUpdate) { Assert.notNull(id, "Id for object to be inserted must not be null!"); Assert.notNull(objectToUpdate, "Object to be updated must not be null!"); String keyspace = resolveKeySpace(objectToUpdate.getClass()); potentiallyPublishEvent(KeyValueEvent.beforeUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate)); Object existing = execute(adapter -> adapter.put(id, objectToUpdate, keyspace)); potentiallyPublishEvent( KeyValueEvent.afterUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate, existing)); return objectToUpdate; }
@Override public <T> T update(Object id, T objectToUpdate) { Assert.notNull(id, "Id for object to be inserted must not be null!"); Assert.notNull(objectToUpdate, "Object to be updated must not be null!"); String keyspace = resolveKeySpace(objectToUpdate.getClass()); potentiallyPublishEvent(KeyValueEvent.beforeUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate)); Object existing = execute(adapter -> adapter.put(id, objectToUpdate, keyspace)); potentiallyPublishEvent( KeyValueEvent.afterUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate, existing)); return objectToUpdate; }
@Override public <T> T update(Object id, T objectToUpdate) { Assert.notNull(id, "Id for object to be inserted must not be null!"); Assert.notNull(objectToUpdate, "Object to be updated must not be null!"); String keyspace = resolveKeySpace(objectToUpdate.getClass()); potentiallyPublishEvent(KeyValueEvent.beforeUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate)); Object existing = execute(adapter -> adapter.put(id, objectToUpdate, keyspace)); potentiallyPublishEvent( KeyValueEvent.afterUpdate(id, keyspace, objectToUpdate.getClass(), objectToUpdate, existing)); return objectToUpdate; }
@Override public <T> T insert(Object id, T objectToInsert) { Assert.notNull(id, "Id for object to be inserted must not be null!"); Assert.notNull(objectToInsert, "Object to be inserted must not be null!"); String keyspace = resolveKeySpace(objectToInsert.getClass()); potentiallyPublishEvent(KeyValueEvent.beforeInsert(id, keyspace, objectToInsert.getClass(), objectToInsert)); execute((KeyValueCallback<Void>) adapter -> { if (adapter.contains(id, keyspace)) { throw new DuplicateKeyException( String.format("Cannot insert existing object with id %s!. Please use update.", id)); } adapter.put(id, objectToInsert, keyspace); return null; }); potentiallyPublishEvent(KeyValueEvent.afterInsert(id, keyspace, objectToInsert.getClass(), objectToInsert)); return objectToInsert; }
@Override public <T> T insert(Object id, T objectToInsert) { Assert.notNull(id, "Id for object to be inserted must not be null!"); Assert.notNull(objectToInsert, "Object to be inserted must not be null!"); String keyspace = resolveKeySpace(objectToInsert.getClass()); potentiallyPublishEvent(KeyValueEvent.beforeInsert(id, keyspace, objectToInsert.getClass(), objectToInsert)); execute((KeyValueCallback<Void>) adapter -> { if (adapter.contains(id, keyspace)) { throw new DuplicateKeyException( String.format("Cannot insert existing object with id %s!. Please use update.", id)); } adapter.put(id, objectToInsert, keyspace); return null; }); potentiallyPublishEvent(KeyValueEvent.afterInsert(id, keyspace, objectToInsert.getClass(), objectToInsert)); return objectToInsert; }
@Override public <T> T insert(Object id, T objectToInsert) { Assert.notNull(id, "Id for object to be inserted must not be null!"); Assert.notNull(objectToInsert, "Object to be inserted must not be null!"); String keyspace = resolveKeySpace(objectToInsert.getClass()); potentiallyPublishEvent(KeyValueEvent.beforeInsert(id, keyspace, objectToInsert.getClass(), objectToInsert)); execute((KeyValueCallback<Void>) adapter -> { if (adapter.contains(id, keyspace)) { throw new DuplicateKeyException( String.format("Cannot insert existing object with id %s!. Please use update.", id)); } adapter.put(id, objectToInsert, keyspace); return null; }); potentiallyPublishEvent(KeyValueEvent.afterInsert(id, keyspace, objectToInsert.getClass(), objectToInsert)); return objectToInsert; }