@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAttributes() == null) ? 0 : getAttributes().hashCode()); hashCode = prime * hashCode + ((getConsumedCapacity() == null) ? 0 : getConsumedCapacity().hashCode()); hashCode = prime * hashCode + ((getItemCollectionMetrics() == null) ? 0 : getItemCollectionMetrics().hashCode()); return hashCode; }
/** * <p> * A map of attribute values as they appear before or after the <code>UpdateItem</code> operation, as determined by * the <code>ReturnValues</code> parameter. * </p> * <p> * The <code>Attributes</code> map is only present if <code>ReturnValues</code> was specified as something other * than <code>NONE</code> in the request. Each element represents one attribute. * </p> * * @param attributes * A map of attribute values as they appear before or after the <code>UpdateItem</code> operation, as * determined by the <code>ReturnValues</code> parameter.</p> * <p> * The <code>Attributes</code> map is only present if <code>ReturnValues</code> was specified as something * other than <code>NONE</code> in the request. Each element represents one attribute. * @return Returns a reference to this object so that method calls can be chained together. */ public UpdateItemResult withAttributes(java.util.Map<String, AttributeValue> attributes) { setAttributes(attributes); return this; }
/** * <p> * The capacity units consumed by the <code>UpdateItem</code> operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the operation. * <code>ConsumedCapacity</code> is only returned if the <code>ReturnConsumedCapacity</code> parameter was * specified. For more information, see <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html" * >Provisioned Throughput</a> in the <i>Amazon DynamoDB Developer Guide</i>. * </p> * * @param consumedCapacity * The capacity units consumed by the <code>UpdateItem</code> operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the * operation. <code>ConsumedCapacity</code> is only returned if the <code>ReturnConsumedCapacity</code> * parameter was specified. For more information, see <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html" * >Provisioned Throughput</a> in the <i>Amazon DynamoDB Developer Guide</i>. * @return Returns a reference to this object so that method calls can be chained together. */ public UpdateItemResult withConsumedCapacity(ConsumedCapacity consumedCapacity) { setConsumedCapacity(consumedCapacity); return this; }
/** * Returns all the returned attributes as a (non-null) {@link Item}. */ public Item getItem() { Map<String, Object> attributes = InternalUtils.toSimpleMapValue(result.getAttributes()); Item item = Item.fromMap(attributes); return item; }
attrs, new PrintableConsumedCapacity( result.getConsumedCapacity() ).print(), System.currentTimeMillis() - start ); return result.getAttributes(); } catch (final AmazonClientException ex) { throw new IOException(
public UpdateItemResult unmarshall(JsonUnmarshallerContext context) throws Exception { UpdateItemResult updateItemResult = new UpdateItemResult(); if (context.testExpression("Attributes", targetDepth)) { context.nextToken(); updateItemResult.setAttributes(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller.getInstance()).unmarshall(context)); updateItemResult.setConsumedCapacity(ConsumedCapacityJsonUnmarshaller.getInstance().unmarshall(context)); updateItemResult.setItemCollectionMetrics(ItemCollectionMetricsJsonUnmarshaller.getInstance().unmarshall(context));
/** * Adds an UpdateItem request to the transaction * * @param request * @throws DuplicateRequestException if the item in the request is already involved in this transaction * @throws ItemNotLockedException when another transaction is confirmed to have the lock on the item in the request * @throws TransactionCompletedException when the transaction has already completed * @throws TransactionNotFoundException if the transaction does not exist * @throws TransactionException on unexpected errors or unresolvable OCC contention */ public UpdateItemResult updateItem(UpdateItemRequest request) throws DuplicateRequestException, ItemNotLockedException, TransactionCompletedException, TransactionNotFoundException, TransactionException { UpdateItem wrappedRequest = new UpdateItem(); wrappedRequest.setRequest(request); Map<String, AttributeValue> item = driveRequest(wrappedRequest); stripSpecialAttributes(item); return new UpdateItemResult().withAttributes(item); }
UpdateItemResult updateItem(final UpdateItemRequest request) throws BackendException { setUserAgent(request); UpdateItemResult result; final int bytes; if (request.getUpdateExpression() != null) { bytes = calculateExpressionBasedUpdateSize(request); } else { bytes = calculateItemUpdateSizeInBytes(request.getAttributeUpdates()); } getBytesHistogram(UPDATE_ITEM, request.getTableName()).update(bytes); final int wcu = computeWcu(bytes); timedWriteThrottle(UPDATE_ITEM, request.getTableName(), wcu); final Timer.Context apiTimerContext = getTimerContext(UPDATE_ITEM, request.getTableName()); try { result = client.updateItem(request); } catch (Exception e) { throw processDynamoDbApiException(e, UPDATE_ITEM, request.getTableName()); } finally { apiTimerContext.stop(); } meterConsumedCapacity(UPDATE_ITEM, result.getConsumedCapacity()); return result; }
@Override protected void executeLowLevelRequest() { UpdateItemResult updateItemResult = doUpdateItem(); // The UpdateItem request is specified to return ALL_NEW // attributes of the affected item. So if the returned // UpdateItemResult does not include any ReturnedAttributes, // it indicates the UpdateItem failed silently (e.g. the // key-only-put nightmare - // https://forums.aws.amazon.com/thread.jspa?threadID=86798&tstart=25), // in which case we should re-send a PutItem // request instead. if (updateItemResult.getAttributes() == null || updateItemResult.getAttributes().isEmpty()) { // Before we proceed with PutItem, we need to put all // the key attributes (prepared for the // UpdateItemRequest) into the AttributeValueUpdates // collection. for (String keyAttributeName : getPrimaryKeyAttributeValues().keySet()) { getAttributeValueUpdates().put(keyAttributeName, new AttributeValueUpdate() .withValue(getPrimaryKeyAttributeValues().get(keyAttributeName)) .withAction("PUT")); } doPutItem(); } } };
attrs, new PrintableConsumedCapacity( result.getConsumedCapacity() ).print(), System.currentTimeMillis() - start ); return result.getAttributes(); } catch (final AmazonClientException ex) { throw new IOException(
public UpdateItemResult unmarshall(JsonUnmarshallerContext context) throws Exception { UpdateItemResult updateItemResult = new UpdateItemResult(); AwsJsonReader reader = context.getReader(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("Attributes")) { updateItemResult.setAttributes(new MapUnmarshaller<AttributeValue>( AttributeValueJsonUnmarshaller.getInstance() ) .unmarshall(context)); } else if (name.equals("ConsumedCapacity")) { updateItemResult.setConsumedCapacity(ConsumedCapacityJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("ItemCollectionMetrics")) { updateItemResult.setItemCollectionMetrics(ItemCollectionMetricsJsonUnmarshaller .getInstance() .unmarshall(context)); } else { reader.skipValue(); } } reader.endObject(); return updateItemResult; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof UpdateItemResult == false) return false; UpdateItemResult other = (UpdateItemResult) obj; if (other.getAttributes() == null ^ this.getAttributes() == null) return false; if (other.getAttributes() != null && other.getAttributes().equals(this.getAttributes()) == false) return false; if (other.getConsumedCapacity() == null ^ this.getConsumedCapacity() == null) return false; if (other.getConsumedCapacity() != null && other.getConsumedCapacity().equals(this.getConsumedCapacity()) == false) return false; if (other.getItemCollectionMetrics() == null ^ this.getItemCollectionMetrics() == null) return false; if (other.getItemCollectionMetrics() != null && other.getItemCollectionMetrics().equals(this.getItemCollectionMetrics()) == false) return false; return true; }
@Override protected void executeLowLevelRequest() { final UpdateItemResult updateItemResult = doUpdateItem(); // The UpdateItem request is specified to return ALL_NEW // attributes of the affected item. So if the returned // UpdateItemResult does not include any ReturnedAttributes, // it indicates the UpdateItem failed silently (e.g. the // key-only-put nightmare - // https://forums.aws.amazon.com/thread.jspa?threadID=86798&tstart=25), // in which case we should re-send a PutItem // request instead. if (updateItemResult.getAttributes() == null || updateItemResult.getAttributes().isEmpty()) { // Before we proceed with PutItem, we need to put all // the key attributes (prepared for the // UpdateItemRequest) into the AttributeValueUpdates // collection. for (final String keyAttributeName : getKeyAttributeValues().keySet()) { getAttributeValueUpdates().put( keyAttributeName, new AttributeValueUpdate() .withValue( getKeyAttributeValues().get(keyAttributeName)) .withAction("PUT")); } doPutItem(); } } };
public UpdateItemResult unmarshall(JsonUnmarshallerContext context) throws Exception { UpdateItemResult updateItemResult = new UpdateItemResult(); if (context.testExpression("Attributes", targetDepth)) { context.nextToken(); updateItemResult.setAttributes(new MapUnmarshaller<String, AttributeValue>(context.getUnmarshaller(String.class), AttributeValueJsonUnmarshaller.getInstance()).unmarshall(context)); updateItemResult.setConsumedCapacity(ConsumedCapacityJsonUnmarshaller.getInstance().unmarshall(context)); updateItemResult.setItemCollectionMetrics(ItemCollectionMetricsJsonUnmarshaller.getInstance().unmarshall(context));
/** * <p> * A map of attribute values as they appear before or after the <code>UpdateItem</code> operation, as determined by * the <code>ReturnValues</code> parameter. * </p> * <p> * The <code>Attributes</code> map is only present if <code>ReturnValues</code> was specified as something other * than <code>NONE</code> in the request. Each element represents one attribute. * </p> * * @param attributes * A map of attribute values as they appear before or after the <code>UpdateItem</code> operation, as * determined by the <code>ReturnValues</code> parameter.</p> * <p> * The <code>Attributes</code> map is only present if <code>ReturnValues</code> was specified as something * other than <code>NONE</code> in the request. Each element represents one attribute. * @return Returns a reference to this object so that method calls can be chained together. */ public UpdateItemResult withAttributes(java.util.Map<String, AttributeValue> attributes) { setAttributes(attributes); return this; }
/** * <p> * The capacity units consumed by the <code>UpdateItem</code> operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the operation. * <code>ConsumedCapacity</code> is only returned if the <code>ReturnConsumedCapacity</code> parameter was * specified. For more information, see <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html" * >Provisioned Throughput</a> in the <i>Amazon DynamoDB Developer Guide</i>. * </p> * * @param consumedCapacity * The capacity units consumed by the <code>UpdateItem</code> operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the * operation. <code>ConsumedCapacity</code> is only returned if the <code>ReturnConsumedCapacity</code> * parameter was specified. For more information, see <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html" * >Provisioned Throughput</a> in the <i>Amazon DynamoDB Developer Guide</i>. * @return Returns a reference to this object so that method calls can be chained together. */ public UpdateItemResult withConsumedCapacity(ConsumedCapacity consumedCapacity) { setConsumedCapacity(consumedCapacity); return this; }
/** * 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 (getAttributes() != null) sb.append("Attributes: ").append(getAttributes()).append(","); if (getConsumedCapacity() != null) sb.append("ConsumedCapacity: ").append(getConsumedCapacity()).append(","); if (getItemCollectionMetrics() != null) sb.append("ItemCollectionMetrics: ").append(getItemCollectionMetrics()); sb.append("}"); return sb.toString(); }
private Document updateItem(Document doc, Key key, UpdateItemOperationConfig config) { final boolean updateChangedAttributes = !this.haveKeysChanged(doc); final Map<String, AttributeValueUpdate> attributeUpdateValues = this.toAttributeUpdateMap( doc, updateChangedAttributes); for (final String keyName : this.keys.keySet()) { attributeUpdateValues.remove(keyName); } final UpdateItemRequest updateRequest = new UpdateItemRequest(); updateRequest.setTableName(this.tableName); updateRequest.setKey(key); updateRequest.setAttributeUpdates( attributeUpdateValues.size() == 0 ? null : attributeUpdateValues); updateRequest.setReturnValues(config.getReturnValue()); Table.appendDynamoDBDocumentUserAgentString(updateRequest); final UpdateItemResult result = this.client.updateItem(updateRequest); doc.commit(); if (config.getReturnValue() != ReturnValue.NONE) { return this.fromAttributeMap(result.getAttributes()); } return null; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAttributes() == null) ? 0 : getAttributes().hashCode()); hashCode = prime * hashCode + ((getConsumedCapacity() == null) ? 0 : getConsumedCapacity().hashCode()); hashCode = prime * hashCode + ((getItemCollectionMetrics() == null) ? 0 : getItemCollectionMetrics().hashCode()); return hashCode; }
/** * Returns all the returned attributes as a (non-null) {@link Item}. */ public Item getItem() { Map<String, Object> attributes = InternalUtils.toSimpleMapValue(result.getAttributes()); Item item = Item.fromMap(attributes); return item; }