Refine search
@Override public PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item, String returnValues) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues)); }
setTableName(tableName); setItem(item); setReturnValues(returnValues);
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getTableName() == null) ? 0 : getTableName().hashCode()); hashCode = prime * hashCode + ((getItem() == null) ? 0 : getItem().hashCode()); hashCode = prime * hashCode + ((getExpected() == null) ? 0 : getExpected().hashCode()); hashCode = prime * hashCode + ((getReturnValues() == null) ? 0 : getReturnValues().hashCode()); hashCode = prime * hashCode + ((getReturnConsumedCapacity() == null) ? 0 : getReturnConsumedCapacity().hashCode()); hashCode = prime * hashCode + ((getReturnItemCollectionMetrics() == null) ? 0 : getReturnItemCollectionMetrics().hashCode()); hashCode = prime * hashCode + ((getConditionalOperator() == null) ? 0 : getConditionalOperator().hashCode()); hashCode = prime * hashCode + ((getConditionExpression() == null) ? 0 : getConditionExpression().hashCode()); hashCode = prime * hashCode + ((getExpressionAttributeNames() == null) ? 0 : getExpressionAttributeNames().hashCode()); hashCode = prime * hashCode + ((getExpressionAttributeValues() == null) ? 0 : getExpressionAttributeValues().hashCode()); return hashCode; }
/** * Simplified method form for invoking the PutItem operation with an AsyncHandler. * * @see #putItemAsync(PutItemRequest, com.amazonaws.handlers.AsyncHandler) */ @Override public java.util.concurrent.Future<PutItemResult> putItemAsync(String tableName, java.util.Map<String, AttributeValue> item, com.amazonaws.handlers.AsyncHandler<PutItemRequest, PutItemResult> asyncHandler) { return putItemAsync(new PutItemRequest().withTableName(tableName).withItem(item), asyncHandler); }
@Override public void saveAttributes(RequestEnvelope envelope, Map<String, Object> attributes) throws PersistenceException { String partitionKey = partitionKeyGenerator.apply(envelope); PutItemRequest request = new PutItemRequest() .withTableName(tableName) .withItem(getItem(partitionKey, attributes)); try { dynamoDb.putItem(request); } catch (ResourceNotFoundException e) { throw new PersistenceException(String.format("Table %s does not exist or is in the process of being created", tableName), e); } catch (AmazonDynamoDBException e) { throw new PersistenceException("Failed to save attributes to DynamoDB", e); } }
/** * Save the item using a PutItem request. The handler will call this * method if * <ul> * <li> CLOBBER configuration is being used; * <li> OR the item contains auto-generated key value; * <li> OR an UpdateItem request has silently failed (200 response with * no affected attribute), which indicates the key-only-put scenario * that we used to handle by the keyOnlyPut(...) hack. * </ul> */ protected PutItemResult doPutItem() { Map<String, AttributeValue> attributeValues = convertToItem(getAttributeValueUpdates()); attributeValues = transformAttributes( toParameters(attributeValues, this.clazz, getTableName(), saveConfig)); PutItemRequest req = new PutItemRequest() .withTableName(getTableName()) .withItem(attributeValues) .withExpected(mergeExpectedAttributeValueConditions()) .withConditionalOperator(userProvidedConditionOperator) .withRequestMetricCollector(saveConfig.getRequestMetricCollector()); return db.putItem(applyUserAgent(req)); }
final AmazonDynamoDB aws = this.credentials.aws(); try { final PutItemRequest request = new PutItemRequest(); request.setTableName(this.self); request.setItem(attributes); request.setReturnValues(ReturnValue.NONE); request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); final PutItemResult result = aws.putItem(request); final long start = System.currentTimeMillis(); Logger.info( ); } finally { aws.shutdown();
/** * {@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; }
String returnValues) throws AmazonServiceException, AmazonClientException { PutItemRequest putItemRequest = new PutItemRequest(); putItemRequest.setTableName(tableName); putItemRequest.setItem(item); putItemRequest.setReturnValues(returnValues); return putItem(putItemRequest);
/** * Puts a document into DynamoDB. * * @param document the {@link Document}. * @param config {@link PutItemOperationConfig}. * @return the dynamodb {@link Document}. */ public Document putItem(Document document, PutItemOperationConfig config) { final PutItemRequest request = new PutItemRequest(); request.setTableName(this.tableName); request.setItem(toAttributeMap(document)); if (config != null && config.getReturnValue().compareTo(ReturnValue.ALL_OLD) == 0) { request.setReturnValues(ReturnValue.ALL_OLD); } Table.appendDynamoDBDocumentUserAgentString(request); final PutItemResult result = client.putItem(request); Document ret = null; if (config != null && config.getReturnValue().compareTo(ReturnValue.ALL_OLD) == 0) { final Map<String, AttributeValue> values = result.getAttributes(); ret = this.fromAttributeMap(values); ret.commit(); } return ret; }
private PutItemOutcome doPutItem(PutItemSpec spec) { // set the table name String tableName = getTable().getTableName(); PutItemRequest req = spec.getRequest().withTableName(tableName); // set up the item Item item = spec.getItem(); final Map<String,AttributeValue> attributes = InternalUtils.toAttributeValues(item); // set up the expected attribute map, if any final Map<String, ExpectedAttributeValue> expectedMap = InternalUtils.toExpectedAttributeValueMap(spec.getExpected()); // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up the request req.withItem(attributes) .withExpected(expectedMap) .withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; PutItemResult result = getClient().putItem(req); return new PutItemOutcome(result); } }
private String createRow(String key, String appid, Map<String, AttributeValue> row) { if (StringUtils.isBlank(key) || StringUtils.isBlank(appid) || row == null || row.isEmpty()) { return null; } try { key = getKeyForAppid(key, appid); setRowKey(key, row); PutItemRequest putItemRequest = new PutItemRequest(getTableNameForAppid(appid), row); client().putItem(putItemRequest); } catch (Exception e) { logger.error("Could not write row to DB - appid={}, key={}", appid, key, e); throwIfNecessary(e); } return key; }
@Override public Status insert(String table, String key, Map<String, ByteIterator> values) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("insertkey: " + primaryKeyName + "-" + key + " from table: " + table); } Map<String, AttributeValue> attributes = createAttributes(values); // adding primary key attributes.put(primaryKeyName, new AttributeValue(key)); if (primaryKeyType == PrimaryKeyType.HASH_AND_RANGE) { // If the primary key type is HASH_AND_RANGE, then what has been put // into the attributes map above is the range key part of the primary // key, we still need to put in the hash key part here. attributes.put(hashKeyName, new AttributeValue(hashKeyValue)); } PutItemRequest putItemRequest = new PutItemRequest(table, attributes); try { dynamoDB.putItem(putItemRequest); } catch (AmazonServiceException ex) { LOGGER.error(ex); return Status.ERROR; } catch (AmazonClientException ex) { LOGGER.error(ex); return CLIENT_ERROR; } return Status.OK; }
@Override public String apply(String key) { PutItemRequest request = new PutItemRequest() .withTableName(tableName) .withReturnConsumedCapacity(returnConsumedCapacity) .addItemEntry(partitionKeyName, new AttributeValue().withS(key)) .addItemEntry(ATTRIBUTE_NAME, new AttributeValue().withS(dataGenerator.getRandomValue())); try { // Write the item to the table return Optional.ofNullable(dynamoDB.putItem(request)) .map(this::measureConsumedCapacity) .map(PutItemResult::toString) .orElse(null); } catch (AmazonServiceException ase) { throw amazonServiceException(ase); } catch (AmazonClientException ace) { throw amazonClientException(ace); } }
PutItemRequest put = ((PutItem)request).getRequest(); put.getItem().put(AttributeName.TXID.toString(), new AttributeValue(txId)); put.getItem().put(AttributeName.APPLIED.toString(), new AttributeValue(BOOLEAN_TRUE_ATTR_VAL)); if(lockedItem.containsKey(AttributeName.TRANSIENT.toString())) { put.getItem().put(AttributeName.TRANSIENT.toString(), lockedItem.get(AttributeName.TRANSIENT.toString())); put.getItem().put(AttributeName.DATE.toString(), lockedItem.get(AttributeName.DATE.toString())); put.setExpected(expected); put.setReturnValues(returnValues); returnItem = txManager.getClient().putItem(put).getAttributes(); } else if(request instanceof UpdateItem) { UpdateItemRequest update = ((UpdateItem)request).getRequest(); .withValue(new AttributeValue(BOOLEAN_TRUE_ATTR_VAL))); returnItem = txManager.getClient().updateItem(update).getAttributes(); } else if(request instanceof DeleteItem) {
if (eventName.equalsIgnoreCase(OperationType.INSERT.toString()) || eventName.equalsIgnoreCase(OperationType.MODIFY.toString())) { PutItemRequest putItemRequest = new PutItemRequest(); putItemRequest.setItem(record.getDynamodb().getNewImage()); putItemRequest.setTableName(getTableName()); request = putItemRequest; } else if (eventName.equalsIgnoreCase(OperationType.REMOVE.toString())) {
/** Test on using map entry adder method. */ @Test public void testMapEntryAdderMethod() { PutItemRequest putItemRequest = new PutItemRequest() .addItemEntry("hash-key", new AttributeValue().withS("1")) .addItemEntry("range-key", new AttributeValue().withS("2")) .addItemEntry("attribute", new AttributeValue().withS("3")); Map<String, AttributeValue> item = putItemRequest.getItem(); assertEquals(3, item.size()); assertEquals("1", item.get("hash-key").getS()); assertEquals("2", item.get("range-key").getS()); assertEquals("3", item.get("attribute").getS()); putItemRequest.clearItemEntries(); assertEquals(null, putItemRequest.getItem()); }
public PutItemSpec() { super(new PutItemRequest()); }
public PutPointRequest(GeoPoint geoPoint, AttributeValue rangeKeyValue) { putItemRequest = new PutItemRequest(); putItemRequest.setItem(new HashMap<String, AttributeValue>()); putRequest = new PutRequest(); putRequest.setItem(new HashMap<String, AttributeValue>()); this.geoPoint = geoPoint; this.rangeKeyValue = rangeKeyValue; }
/** * Constructs a new PutItemRequest object. Callers should use the setter or fluent setter (with...) methods to * initialize any additional object members. * * @param tableName * The name of the table to contain the item. * @param item * A map of attribute name/value pairs, one for each attribute. Only the primary key attributes are required; * you can optionally provide other attribute name-value pairs for the item.</p> * <p> * You must provide all of the attributes for the primary key. For example, with a simple primary key, you * only need to provide a value for the partition key. For a composite primary key, you must provide both * values for both the partition key and the sort key. * </p> * <p> * If you specify any attributes that are part of an index key, then the data types for those attributes must * match those of the schema in the table's attribute definition. * </p> * <p> * For more information about primary keys, see <a href= * "http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModelPrimaryKey" * >Primary Key</a> in the <i>Amazon DynamoDB Developer Guide</i>. * </p> * <p> * Each element in the <code>Item</code> map is an <code>AttributeValue</code> object. */ public PutItemRequest(String tableName, java.util.Map<String, AttributeValue> item) { setTableName(tableName); setItem(item); }