/** * Creates and returns a condition of the range key that has a value between * the given values. */ public Expected between(Object low, Object hi) { return _withComparisonOperator(ComparisonOperator.BETWEEN)._withValues(low, hi); }
public PutItemSpec withExpected(Collection<Expected> expected) { if (expected == null) { this.expected = null; return this; } Set<String> names = new LinkedHashSet<String>(); for (Expected e: expected) names.add(e.getAttribute()); if (names.size() != expected.size()) { throw new IllegalArgumentException( "attribute names must not duplicate in the list of expected"); } this.expected = Collections.unmodifiableCollection(expected); return this; }
@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 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; } }
new LinkedHashMap<String, ExpectedAttributeValue>(); for (Expected expected : expectedSet) { final String attr = expected.getAttribute(); final Object[] values = expected.getValues(); ExpectedAttributeValue eav = new ExpectedAttributeValue(); if (values != null) { ComparisonOperator op = expected.getComparisonOperator(); if (op == null) { throw new IllegalArgumentException( "Comparison operator for attribute " + expected.getAttribute() + " must be specified");
/** * Expects the attribute be an existing attribute. */ public Expected exists() { return _withComparisonOperator(ComparisonOperator.NOT_NULL); }
@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 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; } }
new LinkedHashMap<String, ExpectedAttributeValue>(); for (Expected expected : expectedSet) { final String attr = expected.getAttribute(); final Object[] values = expected.getValues(); ExpectedAttributeValue eav = new ExpectedAttributeValue(); if (values != null) { ComparisonOperator op = expected.getComparisonOperator(); if (op == null) { throw new IllegalArgumentException( "Comparison operator for attribute " + expected.getAttribute() + " must be specified");
/** * Expects the attribute be non-existing. */ public Expected notExist() { return _withComparisonOperator(ComparisonOperator.NULL); }
/** * Creates and returns a condition of the range key being less than the * given value. */ public Expected lt(Object val) { return _withComparisonOperator(ComparisonOperator.LT)._withValues(val); } }
public DeleteItemSpec withExpected(Collection<Expected> expected) { if (expected == null) { this.expected = null; return this; } Set<String> names = new LinkedHashSet<String>(); for (Expected e: expected) names.add(e.getAttribute()); if (names.size() != expected.size()) { throw new IllegalArgumentException( "attribute names must not duplicate in the list of expected"); } this.expected = Collections.unmodifiableCollection(expected); return this; }
/** * Expects the attribute be non-existing. */ public Expected notExist() { return _withComparisonOperator(ComparisonOperator.NULL); }
/** * Creates and returns a condition of the range key with a value that begins * with the given value. */ public Expected beginsWith(String val) { return _withComparisonOperator(ComparisonOperator.BEGINS_WITH)._withValues(val); }
public UpdateItemSpec withExpected(Collection<Expected> expected) { if (expected == null) { this.expected = null; return this; } Set<String> names = new LinkedHashSet<String>(); for (Expected e: expected) names.add(e.getAttribute()); if (names.size() != expected.size()) { throw new IllegalArgumentException( "attribute names must not duplicate in the list of expected"); } this.expected = Collections.unmodifiableCollection(expected); return this; }
/** * Expects the attribute be an existing attribute. */ public Expected exists() { return _withComparisonOperator(ComparisonOperator.NOT_NULL); }
/** * Creates and returns a condition of the range key being equal to the given * value. */ public Expected eq(Object val) { return _withComparisonOperator(ComparisonOperator.EQ)._withValues(val); }
public PutItemSpec withExpected(Collection<Expected> expected) { if (expected == null) { this.expected = null; return this; } Set<String> names = new LinkedHashSet<String>(); for (Expected e: expected) names.add(e.getAttribute()); if (names.size() != expected.size()) { throw new IllegalArgumentException( "attribute names must not duplicate in the list of expected"); } this.expected = Collections.unmodifiableCollection(expected); return this; }
public Expected notContains(Object val) { return _withComparisonOperator(ComparisonOperator.NOT_CONTAINS)._withValues(val); } /**
public DeleteItemSpec withExpected(Collection<Expected> expected) { if (expected == null) { this.expected = null; return this; } Set<String> names = new LinkedHashSet<String>(); for (Expected e: expected) names.add(e.getAttribute()); if (names.size() != expected.size()) { throw new IllegalArgumentException( "attribute names must not duplicate in the list of expected"); } this.expected = Collections.unmodifiableCollection(expected); return this; }