/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getValue() != null) sb.append("Value: ").append(getValue()).append(","); if (getExists() != null) sb.append("Exists: ").append(getExists()).append(","); if (getComparisonOperator() != null) sb.append("ComparisonOperator: ").append(getComparisonOperator()).append(","); if (getAttributeValueList() != null) sb.append("AttributeValueList: ").append(getAttributeValueList()); sb.append("}"); return sb.toString(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getValue() == null) ? 0 : getValue().hashCode()); hashCode = prime * hashCode + ((getExists() == null) ? 0 : getExists().hashCode()); hashCode = prime * hashCode + ((getComparisonOperator() == null) ? 0 : getComparisonOperator().hashCode()); hashCode = prime * hashCode + ((getAttributeValueList() == null) ? 0 : getAttributeValueList().hashCode()); return hashCode; }
/** * Marshall the given parameter object. */ public void marshall(ExpectedAttributeValue expectedAttributeValue, ProtocolMarshaller protocolMarshaller) { if (expectedAttributeValue == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(expectedAttributeValue.getValue(), VALUE_BINDING); protocolMarshaller.marshall(expectedAttributeValue.getExists(), EXISTS_BINDING); protocolMarshaller.marshall(expectedAttributeValue.getComparisonOperator(), COMPARISONOPERATOR_BINDING); protocolMarshaller.marshall(expectedAttributeValue.getAttributeValueList(), ATTRIBUTEVALUELIST_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof ExpectedAttributeValue == false) return false; ExpectedAttributeValue other = (ExpectedAttributeValue) obj; if (other.getValue() == null ^ this.getValue() == null) return false; if (other.getValue() != null && other.getValue().equals(this.getValue()) == false) return false; if (other.getExists() == null ^ this.getExists() == null) return false; if (other.getExists() != null && other.getExists().equals(this.getExists()) == false) return false; if (other.getComparisonOperator() == null ^ this.getComparisonOperator() == null) return false; if (other.getComparisonOperator() != null && other.getComparisonOperator().equals(this.getComparisonOperator()) == false) return false; if (other.getAttributeValueList() == null ^ this.getAttributeValueList() == null) return false; if (other.getAttributeValueList() != null && other.getAttributeValueList().equals(this.getAttributeValueList()) == false) return false; return true; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getValue() == null) ? 0 : getValue().hashCode()); hashCode = prime * hashCode + ((getExists() == null) ? 0 : getExists().hashCode()); hashCode = prime * hashCode + ((getComparisonOperator() == null) ? 0 : getComparisonOperator().hashCode()); hashCode = prime * hashCode + ((getAttributeValueList() == null) ? 0 : getAttributeValueList().hashCode()); return hashCode; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getValue() != null) sb.append("Value: " + getValue() + ","); if (getExists() != null) sb.append("Exists: " + getExists() + ","); if (getComparisonOperator() != null) sb.append("ComparisonOperator: " + getComparisonOperator() + ","); if (getAttributeValueList() != null) sb.append("AttributeValueList: " + getAttributeValueList()); sb.append("}"); return sb.toString(); }
@Test public void testMergeExpectedAttributeValueConditionsNoInternalAssertions() { Map<String, ExpectedAttributeValue> userProvidedConditions = new HashMap<String, ExpectedAttributeValue>(); ExpectedAttributeValue user = new ExpectedAttributeValue().withValue(new AttributeValue() .withS("user")); userProvidedConditions.put("user", user); Map<String, ExpectedAttributeValue> merged = DynamoDBMapper .mergeExpectedAttributeValueConditions( null, userProvidedConditions, "AND"); assertEquals(merged.get("user").getValue().getS(), "user"); assertEquals(merged.size(), 1); }
@Test public void testMergeExpectedAttributeValueConditionsNoUserProvidedConditions() { Map<String, ExpectedAttributeValue> internalAssertions = new HashMap<String, ExpectedAttributeValue>(); ExpectedAttributeValue internal = new ExpectedAttributeValue() .withValue(new AttributeValue().withS("internal")); internalAssertions.put("internal", internal); Map<String, ExpectedAttributeValue> merged = DynamoDBMapper .mergeExpectedAttributeValueConditions( internalAssertions, null, "AND"); assertEquals(merged.get("internal").getValue().getS(), "internal"); assertEquals(merged.size(), 1); }
@Test public void testMergeExpectedAttributeValueConditions() { Map<String, ExpectedAttributeValue> internalAssertions = new HashMap<String, ExpectedAttributeValue>(); Map<String, ExpectedAttributeValue> userProvidedConditions = new HashMap<String, ExpectedAttributeValue>(); ExpectedAttributeValue internal = new ExpectedAttributeValue() .withValue(new AttributeValue().withS("internal")); ExpectedAttributeValue user = new ExpectedAttributeValue().withValue(new AttributeValue() .withS("user")); ExpectedAttributeValue bothInterlan = new ExpectedAttributeValue() .withValue(new AttributeValue().withS("bothInterlan")); ExpectedAttributeValue bothUser = new ExpectedAttributeValue() .withValue(new AttributeValue().withS("bothUser")); internalAssertions.put("internal", internal); userProvidedConditions.put("user", user); internalAssertions.put("both", bothInterlan); userProvidedConditions.put("both", bothUser); Map<String, ExpectedAttributeValue> merged = DynamoDBMapper .mergeExpectedAttributeValueConditions( internalAssertions, userProvidedConditions, "AND"); assertEquals(merged.get("internal").getValue().getS(), "internal"); assertEquals(merged.get("user").getValue().getS(), "user"); assertEquals(merged.get("both").getValue().getS(), "bothUser"); }
public void marshall(ExpectedAttributeValue expectedAttributeValue, AwsJsonWriter jsonWriter) throws Exception { jsonWriter.beginObject(); if (expectedAttributeValue.getValue() != null) { AttributeValue value = expectedAttributeValue.getValue(); jsonWriter.name("Value"); AttributeValueJsonMarshaller.getInstance().marshall(value, jsonWriter);
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getValue() != null) sb.append("Value: ").append(getValue()).append(","); if (getExists() != null) sb.append("Exists: ").append(getExists()).append(","); if (getComparisonOperator() != null) sb.append("ComparisonOperator: ").append(getComparisonOperator()).append(","); if (getAttributeValueList() != null) sb.append("AttributeValueList: ").append(getAttributeValueList()); sb.append("}"); return sb.toString(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getValue() == null) ? 0 : getValue().hashCode()); hashCode = prime * hashCode + ((getExists() == null) ? 0 : getExists().hashCode()); hashCode = prime * hashCode + ((getComparisonOperator() == null) ? 0 : getComparisonOperator().hashCode()); hashCode = prime * hashCode + ((getAttributeValueList() == null) ? 0 : getAttributeValueList().hashCode()); return hashCode; }
|| !expectedValueMatches(entry.getValue().getValue(), item.get(entry.getKey())))) { throw new ConditionalCheckFailedException( "expected attribute(s) " + expectedValues
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof ExpectedAttributeValue == false) return false; ExpectedAttributeValue other = (ExpectedAttributeValue) obj; if (other.getValue() == null ^ this.getValue() == null) return false; if (other.getValue() != null && other.getValue().equals(this.getValue()) == false) return false; if (other.getExists() == null ^ this.getExists() == null) return false; if (other.getExists() != null && other.getExists().equals(this.getExists()) == false) return false; if (other.getComparisonOperator() == null ^ this.getComparisonOperator() == null) return false; if (other.getComparisonOperator() != null && other.getComparisonOperator().equals(this.getComparisonOperator()) == false) return false; if (other.getAttributeValueList() == null ^ this.getAttributeValueList() == null) return false; if (other.getAttributeValueList() != null && other.getAttributeValueList().equals(this.getAttributeValueList()) == false) return false; return true; }
/** * Marshall the given parameter object. */ public void marshall(ExpectedAttributeValue expectedAttributeValue, ProtocolMarshaller protocolMarshaller) { if (expectedAttributeValue == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(expectedAttributeValue.getValue(), VALUE_BINDING); protocolMarshaller.marshall(expectedAttributeValue.getExists(), EXISTS_BINDING); protocolMarshaller.marshall(expectedAttributeValue.getComparisonOperator(), COMPARISONOPERATOR_BINDING); protocolMarshaller.marshall(expectedAttributeValue.getAttributeValueList(), ATTRIBUTEVALUELIST_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
private void checkExpectedValues(String tableName, Map<String, AttributeValue> itemKey, Map<String, ExpectedAttributeValue> expectedValues) { if (expectedValues != null && !expectedValues.isEmpty()) { for (Map.Entry<String, ExpectedAttributeValue> entry : expectedValues.entrySet()) { if ((entry.getValue().isExists() == null || entry.getValue().isExists() == true) && entry.getValue().getValue() == null) { throw new IllegalArgumentException("An explicit value is required when Exists is null or true, " + "but none was found in expected values for item with key " + itemKey + ": " + expectedValues); } } // simulate by loading the item and checking the values; // this also has the effect of locking the item, which gives the // same behavior GetItemResult result = getItem(new GetItemRequest() .withAttributesToGet(expectedValues.keySet()) .withKey(itemKey) .withTableName(tableName)); Map<String, AttributeValue> item = result.getItem(); try { checkExpectedValues(expectedValues, item); } catch (ConditionalCheckFailedException e) { throw new ConditionalCheckFailedException("Item " + itemKey + " had unexpected attributes: " + e.getMessage()); } } }