@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; }