/** * <p> * This is a legacy parameter. Use <code>ConditionExpression</code> instead. For more information, see <a href= * "http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.Expected.html" * >Expected</a> in the <i>Amazon DynamoDB Developer Guide</i>. * </p> * * @param expected * This is a legacy parameter. Use <code>ConditionExpression</code> instead. For more information, see <a * href= * "http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.Expected.html" * >Expected</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 PutItemRequest withExpected(java.util.Map<String, ExpectedAttributeValue> expected) { setExpected(expected); return this; }
/** * <p> * This is a legacy parameter. Use <code>ConditionExpression</code> instead. For more information, see <a href= * "http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.Expected.html" * >Expected</a> in the <i>Amazon DynamoDB Developer Guide</i>. * </p> * * @param expected * This is a legacy parameter. Use <code>ConditionExpression</code> instead. For more information, see <a * href= * "http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.Expected.html" * >Expected</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 PutItemRequest withExpected(java.util.Map<String, ExpectedAttributeValue> expected) { setExpected(expected); return this; }
/** * {@inheritDoc} */ @Override public boolean createLeaseIfNotExists(T lease) throws DependencyException, InvalidStateException, ProvisionedThroughputException { verifyNotNull(lease, "lease cannot be null"); if (LOG.isDebugEnabled()) { LOG.debug("Creating lease " + lease); } PutItemRequest request = new PutItemRequest(); request.setTableName(table); request.setItem(serializer.toDynamoRecord(lease)); request.setExpected(serializer.getDynamoNonexistantExpectation()); try { dynamoDBClient.putItem(request); } catch (ConditionalCheckFailedException e) { if (LOG.isDebugEnabled()) { LOG.debug("Did not create lease " + lease + " because it already existed"); } return false; } catch (AmazonClientException e) { throw convertAndRethrowExceptions("create", lease.getLeaseKey(), e); } return true; }
@Override public PutItemResult putItem(PutItemRequest request) throws AmazonServiceException, AmazonClientException { Map<String, ExpectedAttributeValue> expectedValues = request.getExpected(); checkExpectedValues(request.getTableName(), Request.getKeyFromItem(request.getTableName(), request.getItem(), txManager), expectedValues); // conditional checks are handled by the above call request.setExpected(null); return txn.putItem(request); }
@Override public String lock(final String name, final String label) throws IOException { final AmazonDynamoDB aws = this.table.region().aws(); String msg = ""; try { final PutItemRequest request = new PutItemRequest(); request.setTableName(this.table.name()); request.setItem( new Attributes() .with(DyLocks.HASH, this.owner) .with(DyLocks.RANGE, name) .with(DyLocks.ATTR_LABEL, label) ); request.setExpected( new ImmutableMap.Builder<String, ExpectedAttributeValue>().put( DyLocks.ATTR_LABEL, new ExpectedAttributeValue().withExists(false) ).build() ); aws.putItem(request); } catch (final ConditionalCheckFailedException ex) { msg = ex.getLocalizedMessage(); } catch (final AmazonClientException ex) { throw new IOException(ex); } finally { aws.shutdown(); } return msg; }
put.setExpected(expected); put.setReturnValues(returnValues); returnItem = txManager.getClient().putItem(put).getAttributes();