public PutItemSpec() { super(new PutItemRequest()); }
@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; }
/** * 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); }
/** * Simplified method form for invoking the PutItem operation. * * @see #putItemAsync(PutItemRequest) */ @Override public java.util.concurrent.Future<PutItemResult> putItemAsync(String tableName, java.util.Map<String, AttributeValue> item) { return putItemAsync(new PutItemRequest().withTableName(tableName).withItem(item)); }
/** * 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); }
/** * Simplified method form for invoking the PutItem operation. * * @see #putItemAsync(PutItemRequest) */ @Override public java.util.concurrent.Future<PutItemResult> putItemAsync(String tableName, java.util.Map<String, AttributeValue> item) { return putItemAsync(new PutItemRequest().withTableName(tableName).withItem(item)); }
@Override public PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item)); }
@Override public PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item)); }
/** * 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, String returnValues, com.amazonaws.handlers.AsyncHandler<PutItemRequest, PutItemResult> asyncHandler) { return putItemAsync(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues), asyncHandler); }
/** * 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, String returnValues, com.amazonaws.handlers.AsyncHandler<PutItemRequest, PutItemResult> asyncHandler) { return putItemAsync(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues), asyncHandler); }
/** * Simplified method form for invoking the PutItem operation. * * @see #putItemAsync(PutItemRequest) */ @Override public java.util.concurrent.Future<PutItemResult> putItemAsync(String tableName, java.util.Map<String, AttributeValue> item, String returnValues) { return putItemAsync(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues)); }
/** * Simplified method form for invoking the PutItem operation. * * @see #putItemAsync(PutItemRequest) */ @Override public java.util.concurrent.Future<PutItemResult> putItemAsync(String tableName, java.util.Map<String, AttributeValue> item, String returnValues) { return putItemAsync(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues)); }
@Override public PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item, String returnValues) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues)); }
@Override public PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item, String returnValues) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues)); }
/** * 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)); }
@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); } }
@Override public <T> void setConfig(String project, String configName, @NotNull T value) { dynamoDBClient.putItem(new PutItemRequest() .withTableName(tableConfig.getTableName()) .withItem(of( "project", new AttributeValue(project), "id", new AttributeValue(configName), "value", new AttributeValue(JsonHelper.encode(value))))); }
@Override public Object create(String project, Object id, ObjectNode properties) { dynamoDBClient.putItem(new PutItemRequest().withTableName(tableConfig.getTableName()) .withItem(generatePutRequest(project, id, properties))); return id; }
@Override public void createMaterializedView(String project, MaterializedView materializedView) { dynamoDBClient.putItem(new PutItemRequest().withTableName(tableConfig.getTableName()) .withItem(of( "project", new AttributeValue(project), "type_table_name", new AttributeValue("materialized_" + materializedView.tableName), "value", new AttributeValue(JsonHelper.encode(materializedView))))); }
/** Test on IllegalArgumentException when providing duplicated keys. */ @Test(expected = IllegalArgumentException.class) public void testDuplicatedKeysException() { new PutItemRequest() .addItemEntry("hash-key", new AttributeValue().withS("1")) .addItemEntry("hash-key", new AttributeValue().withS("2")); }