Refine search
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("updatekey: " + key + " from table: " + table); } Map<String, AttributeValueUpdate> attributes = new HashMap<>(values.size()); for (Entry<String, ByteIterator> val : values.entrySet()) { AttributeValue v = new AttributeValue(val.getValue().toString()); attributes.put(val.getKey(), new AttributeValueUpdate().withValue(v).withAction("PUT")); } UpdateItemRequest req = new UpdateItemRequest(table, createPrimaryKey(key), attributes); try { dynamoDB.updateItem(req); } catch (AmazonServiceException ex) { LOGGER.error(ex); return Status.ERROR; } catch (AmazonClientException ex) { LOGGER.error(ex); return CLIENT_ERROR; } return Status.OK; }
public AttributeValueUpdate unmarshall(JsonUnmarshallerContext context) throws Exception { AttributeValueUpdate attributeValueUpdate = new AttributeValueUpdate(); if (context.testExpression("Value", targetDepth)) { context.nextToken(); attributeValueUpdate.setValue(AttributeValueJsonUnmarshaller.getInstance().unmarshall(context)); attributeValueUpdate.setAction(context.getUnmarshaller(String.class).unmarshall(context));
/** * Implement this method for necessary operations when a non-key * attribute is set a non-null value in the object. * The default implementation simply adds a "PUT" update for the given attribute. * * @param attributeName * The name of the non-key attribute. * @param currentValue * The updated value of the given attribute. */ protected void onNonKeyAttribute(String attributeName, AttributeValue currentValue) { updateValues.put(attributeName, new AttributeValueUpdate() .withValue(currentValue).withAction("PUT")); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof AttributeValueUpdate == false) return false; AttributeValueUpdate other = (AttributeValueUpdate) obj; if (other.getValue() == null ^ this.getValue() == null) return false; if (other.getValue() != null && other.getValue().equals(this.getValue()) == false) return false; if (other.getAction() == null ^ this.getAction() == null) return false; if (other.getAction() != null && other.getAction().equals(this.getAction()) == false) return false; return true; }
keys.put("id", new AttributeValue().withS("hashKey")); Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>(); AttributeValueUpdate update = new AttributeValueUpdate().withValue(new AttributeValue() .withS("newValue1")); updates.put("firstValue", update); MockTwoValuePlusVersionClass.class, "aws-android-sdk-dynamodbmapper-test", keys, updates, config); assertEquals(transformed.get("firstValue").getValue().getS(), "NEWVALUE1"); assertNull(transformed.get("id"));
public static void updItem(CamelContext camelctx, String title) { HashMap<String, AttributeValue> key = new HashMap<>(); key.put("Id", new AttributeValue().withN("103")); HashMap<String, AttributeValueUpdate> updItem = new HashMap<>(); AttributeValueUpdate updValue = new AttributeValueUpdate(); updValue.setValue(new AttributeValue().withS(title)); updItem.put("Title", updValue); Exchange exchange = new ExchangeBuilder(camelctx) .withHeader(DdbConstants.OPERATION, DdbOperations.UpdateItem) .withHeader(DdbConstants.KEY, key) .withHeader(DdbConstants.UPDATE_VALUES, updItem).build(); ProducerTemplate producer = camelctx.createProducerTemplate(); producer.send("direct:start", exchange); Assert.assertNull(exchange.getException()); }
@Override protected void onNonKeyAttribute(String attributeName, AttributeValue currentValue) { /* If it's a set attribute and the mapper is configured with APPEND_SET, * we do an "ADD" update instead of the default "PUT". */ if (getLocalSaveBehavior() == SaveBehavior.APPEND_SET) { if (currentValue.getBS() != null || currentValue.getNS() != null || currentValue.getSS() != null) { getAttributeValueUpdates().put( attributeName, new AttributeValueUpdate().withValue( currentValue).withAction("ADD")); return; } } /* Otherwise, we do the default "PUT" update. */ super.onNonKeyAttribute(attributeName, currentValue); }
@Override public BigDecimal increment(final BigDecimal delta) throws IOException { return new BigDecimal( this.item.put( DyCounters.ATTR_VALUE, new AttributeValueUpdate( new AttributeValue().withN(delta.toString()), AttributeAction.ADD ) ).get(DyCounters.ATTR_VALUE).getN() ); } }
try { Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>(); expected.put(AttributeName.TXID.toString(), new ExpectedAttributeValue().withValue(new AttributeValue(txId))); updates.put(AttributeName.TXID.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); updates.put(AttributeName.TRANSIENT.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); updates.put(AttributeName.APPLIED.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE)); updates.put(AttributeName.DATE.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE));
@Override public void set(final BigDecimal value) throws IOException { this.item.put( DyCounters.ATTR_VALUE, new AttributeValueUpdate( new AttributeValue().withN(value.toString()), AttributeAction.PUT ) ); }
Key pk = new Key(new AttributeValue().withN(Long.toString(123))); AttributeValueUpdate avu = new AttributeValueUpdate(null, "DELETE"); Map<String, AttributeValueUpdate> m = new HashMap<String, AttributeValueUpdate>(); m.put(String.valueOf(555), avu); UpdateItemRequest uir = new UpdateItemRequest("users", pk, m); dynamoDB.updateItem(uir);
@Override protected void onNullNonKeyAttribute(String attributeName) { /* * If UPDATE_SKIP_NULL_ATTRIBUTES or APPEND_SET is * configured, we don't delete null value attributes. */ if (getLocalSaveBehavior() == SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES || getLocalSaveBehavior() == SaveBehavior.APPEND_SET) { return; } else { /* Delete attributes that are set as null in the object. */ getAttributeValueUpdates() .put(attributeName, new AttributeValueUpdate() .withAction("DELETE")); } }
new AttributeValueUpdate().withValue(keyAttributeValue) .withAction("PUT")); getAttributeValueUpdates().put( attributeName, new AttributeValueUpdate().withValue( currentValue).withAction("ADD")); return; new AttributeValueUpdate() .withAction("DELETE")); getAttributeValueUpdates().put( keyAttributeName, new AttributeValueUpdate() .withValue( getKeyAttributeValues().get(keyAttributeName))
/** * 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 (getAction() != null) sb.append("Action: ").append(getAction()); sb.append("}"); return sb.toString(); }
withAction(action);
@Override public AttributeValue apply(final AttributeValueUpdate update) { return update.getValue(); } }