@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 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, String returnValues) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues)); }
@Override public void createProject(String project) { try { dynamoDBClient.putItem(new PutItemRequest() .withTableName(tableConfig.getTableName()) .addExpectedEntry("id", new ExpectedAttributeValue().withExists(false)) .withItem(ImmutableMap.<String, AttributeValue>builder() .put("project", new AttributeValue(project)) .put("id", new AttributeValue("|")).build() )); } catch (ConditionalCheckFailedException e) { throw new AlreadyExistsException("Project", HttpResponseStatus.BAD_REQUEST); } }
@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 <T> T setConfigOnce(String project, String configName, @NotNull T value) { try { dynamoDBClient.putItem(new PutItemRequest() .withTableName(tableConfig.getTableName()) .withExpected(of("id", new ExpectedAttributeValue(false), "project", new ExpectedAttributeValue(false))) .withItem(of( "project", new AttributeValue(project), "id", new AttributeValue(configName), "value", new AttributeValue(JsonHelper.encode(value))))); return value; } catch (Exception e) { return getConfig(project, configName, (Class<T>) value.getClass()); } }
@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))))); }
dynamoDBClient.putItem(new PutItemRequest() .withTableName(tableConfig.getTableName()) .addExpectedEntry("id", new ExpectedAttributeValue().withExists(false)) dynamoDBClient.putItem(new PutItemRequest() .withTableName(tableConfig.getTableName()) .addExpectedEntry("id", new ExpectedAttributeValue().withExists(false))
putItemRequest.setTableName(tableName); putItemRequest.setItem(item); return putItem(putItemRequest);
putItemRequest.setItem(item); putItemRequest.setReturnValues(returnValues); return putItem(putItemRequest);
AWSCredentials creds = new BasicAWSCredentials("myacceskey","mysecretkey"); AmazonDynamoDBClient dyndbclient = new AmazonDynamoDBClient(creds); String tableName = "myDynamoDbTable" Map<String, AttributeValue> dbItem = new HashMap<String, AttributeValue>(); //TODO put key/values from request in dbItem dyndbclient.putItem(tableName, dbItem);
private static void putItem(Map<String, AttributeValue> item) { try { PutItemRequest putItemRequest = new PutItemRequest(TABLENAME, item); PutItemResult putItemResult = dynamoDBClient.putItem(putItemRequest); logger.info("Result: " + putItemResult); } catch (Exception e) { // TODO: handle exception } }
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 { setRowKey(key, row); PutItemRequest putItemRequest = new PutItemRequest(getTablNameForAppid(appid), row); client().putItem(putItemRequest); } catch (Exception e) { logger.error(null, e); } return key; }
@Override public PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item)); }
public static void putItem(AmazonDynamoDBClient client, String tableName, java.util.Map<String, AttributeValue> items) { PutItemRequest putItemRequest = new PutItemRequest() .withTableName(tableName) .withItem(items); client.putItem(putItemRequest); }
public static void putItem(AmazonDynamoDBClient client, String tableName, String id, String val) { java.util.Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put("Id", new AttributeValue().withN(id)); item.put("attribute-1", new AttributeValue().withS(val)); PutItemRequest putItemRequest = new PutItemRequest() .withTableName(tableName) .withItem(item); client.putItem(putItemRequest); }
@Override public PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item, String returnValues) { return putItem(new PutItemRequest().withTableName(tableName).withItem(item).withReturnValues(returnValues)); }
public static void createItem(String threadId, String replyDateTime) throws IOException { // Craft a long message String messageInput = "Long message to be compressed in a lengthy forum reply"; // Compress the long message ByteBuffer compressedMessage = compressString(messageInput.toString()); // Add a the reply Map<String, AttributeValue> replyInput = new HashMap<String, AttributeValue>(); replyInput.put("Id", new AttributeValue().withS(threadId)); replyInput.put("ReplyDateTime", new AttributeValue().withS(replyDateTime)); replyInput.put("Message", new AttributeValue().withS("Long message follows")); replyInput.put("ExtendedMessage", new AttributeValue().withB(compressedMessage)); replyInput.put("PostedBy", new AttributeValue().withS("User A")); PutItemRequest putReplyRequest = new PutItemRequest().withTableName(tableName).withItem(replyInput); client.putItem(putReplyRequest); }
public PutPointResult putPoint(PutPointRequest putPointRequest) { long geohash = S2Manager.generateGeohash(putPointRequest.getGeoPoint()); long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength()); String geoJson = GeoJsonMapper.stringFromGeoObject(putPointRequest.getGeoPoint()); PutItemRequest putItemRequest = putPointRequest.getPutItemRequest(); putItemRequest.setTableName(config.getTableName()); AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey)); putItemRequest.getItem().put(config.getHashKeyAttributeName(), hashKeyValue); putItemRequest.getItem().put(config.getRangeKeyAttributeName(), putPointRequest.getRangeKeyValue()); AttributeValue geohashValue = new AttributeValue().withN(Long.toString(geohash)); putItemRequest.getItem().put(config.getGeohashAttributeName(), geohashValue); AttributeValue geoJsonValue = new AttributeValue().withS(geoJson); putItemRequest.getItem().put(config.getGeoJsonAttributeName(), geoJsonValue); PutItemResult putItemResult = config.getDynamoDBClient().putItem(putItemRequest); PutPointResult putPointResult = new PutPointResult(putItemResult); return putPointResult; }