public UpdateItemSpec withExpected(Expected ... expected) { if (expected == null) { this.expected = null; return this; } return withExpected(Arrays.asList(expected)); }
@Override public UpdateItemOutcome updateItem(PrimaryKey primaryKey, Collection<Expected> expected, AttributeUpdate... attributeUpdates) { return updateItem(new UpdateItemSpec() .withPrimaryKey(primaryKey) .withExpected(expected) .withAttributeUpdate(attributeUpdates)); }
public UpdateItemSpec withExpected(Expected ... expected) { if (expected == null) { this.expected = null; return this; } return withExpected(Arrays.asList(expected)); }
@Override public UpdateItemOutcome updateItem(PrimaryKey primaryKey, Collection<Expected> expected, AttributeUpdate... attributeUpdates) { return updateItem(new UpdateItemSpec() .withPrimaryKey(primaryKey) .withExpected(expected) .withAttributeUpdate(attributeUpdates)); }
@Override public boolean replace(String key, String oldValue, String newValue) { Assert.hasText(key, "'key' must not be empty."); Assert.hasText(oldValue, "'value' must not be empty."); Assert.hasText(newValue, "'newValue' must not be empty."); awaitForActive(); UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey(KEY, key) .withAttributeUpdate( new AttributeUpdate(VALUE) .put(newValue)) .withExpected( new Expected(VALUE) .eq(oldValue)) .withReturnValues(ReturnValue.UPDATED_NEW); if (this.timeToLive != null && this.timeToLive > 0) { updateItemSpec = updateItemSpec.addAttributeUpdate( new AttributeUpdate(TTL) .put((System.currentTimeMillis() + this.timeToLive) / 1000)); } try { return this.table.updateItem(updateItemSpec) .getItem() != null; } catch (ConditionalCheckFailedException e) { return false; } }
@Override public boolean replace(String key, String oldValue, String newValue) { Assert.hasText(key, "'key' must not be empty."); Assert.hasText(oldValue, "'value' must not be empty."); Assert.hasText(newValue, "'newValue' must not be empty."); awaitForActive(); UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey(KEY, key) .withAttributeUpdate( new AttributeUpdate(VALUE) .put(newValue)) .withExpected( new Expected(VALUE) .eq(oldValue)) .withReturnValues(ReturnValue.UPDATED_NEW); if (this.timeToLive != null && this.timeToLive > 0) { updateItemSpec = updateItemSpec.addAttributeUpdate( new AttributeUpdate(TTL) .put((System.currentTimeMillis() + this.timeToLive) / 1000)); } try { return this.table.updateItem(updateItemSpec) .getItem() != null; } catch (ConditionalCheckFailedException e) { return false; } }
@Override public String putIfAbsent(String key, String value) { Assert.hasText(key, "'key' must not be empty."); Assert.hasText(value, "'value' must not be empty."); awaitForActive(); UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey(KEY, key) .withAttributeUpdate( new AttributeUpdate(VALUE) .put(value)) .withExpected( new Expected(KEY) .notExist()); if (this.timeToLive != null && this.timeToLive > 0) { updateItemSpec = updateItemSpec.addAttributeUpdate( new AttributeUpdate(TTL) .put((System.currentTimeMillis() + this.timeToLive) / 1000)); } try { this.table.updateItem(updateItemSpec); return null; } catch (ConditionalCheckFailedException e) { return get(key); } }
@Override public String putIfAbsent(String key, String value) { Assert.hasText(key, "'key' must not be empty."); Assert.hasText(value, "'value' must not be empty."); awaitForActive(); UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey(KEY, key) .withAttributeUpdate( new AttributeUpdate(VALUE) .put(value)) .withExpected( new Expected(KEY) .notExist()); if (this.timeToLive != null && this.timeToLive > 0) { updateItemSpec = updateItemSpec.addAttributeUpdate( new AttributeUpdate(TTL) .put((System.currentTimeMillis() + this.timeToLive) / 1000)); } try { this.table.updateItem(updateItemSpec); return null; } catch (ConditionalCheckFailedException e) { return get(key); } }