List of usage examples for com.amazonaws.services.dynamodbv2.document Item fromJSON
public static Item fromJSON(String json)
Item from the given JSON string. From source file:com.eho.dynamodb.DynamoDBConnection.java
public static PutItemOutcome upload_resource_old(String resource) throws Exception { String id;//from www . j a v a 2s. c o m JSONObject json_resource = new JSONObject(resource); //does the resource have a primary key? if (json_resource.has(PRIMARY_KEY))//if it does not have a primary key, create one using uuid id = json_resource.getString(PRIMARY_KEY); else id = UUID.randomUUID().toString(); DynamoDB dynamoDB = new DynamoDB(dynamoDBClient); Table table = dynamoDB.getTable(PATIENT_TABLE); //lets retreive based on the key. if key invalid (not assigned yet) nullis returned. Item retreived_item = table.getItem(PRIMARY_KEY, id); if (retreived_item == null)//if null instantiate it { retreived_item = new Item(); retreived_item.withPrimaryKey(PRIMARY_KEY, id); } Integer new_version = retreived_item.getInt("version") + 1; retreived_item.withInt("version", new_version); Item item_to_upload = Item.fromJSON(retreived_item.toJSONPretty()).withJSON("Document", resource); PutItemSpec putItemSpec = new PutItemSpec().withItem(item_to_upload).withReturnValues(ReturnValue.NONE); return table.putItem(putItemSpec); }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
/** * converts a Jackson annotated domain object to a DynamoDB document (item) * @param domain the object to convert//from ww w. j a v a2 s .c o m * @return a DynamoDB Document representation of the domain object */ <T> Item convertDomainToItem(T domain) { return Item.fromJSON(convertDomainToJSON(domain)); }
From source file:org.eluder.logback.ext.dynamodb.appender.DynamoDbAppender.java
License:Open Source License
@Override protected void handle(final ILoggingEvent event, final String encoded) throws Exception { Item item = Item.fromJSON(encoded).withPrimaryKey(createEventId(event)); Map<String, AttributeValue> attributes = InternalUtils.toAttributeValues(item); PutItemRequest request = new PutItemRequest(table, attributes); String errorMessage = format("Appender '%s' failed to send logging event '%s' to DynamoDB table '%s'", getName(), event, table);/*from w w w . ja v a 2s.com*/ CountDownLatch latch = new CountDownLatch(isAsyncParent() ? 0 : 1); dynamoDb.putItemAsync(request, new LoggingEventHandler<PutItemRequest, PutItemResult>(this, latch, errorMessage)); AppenderExecutors.awaitLatch(this, latch, getMaxFlushTime()); }