use of com.amazonaws.services.dynamodbv2.document.Item in project aws-doc-sdk-examples by awsdocs.
the class LowLevelQuery method findRepliesInLast15DaysWithConfig.
private static void findRepliesInLast15DaysWithConfig(String forumName, String threadSubject) {
long twoWeeksAgoMilli = (new Date()).getTime() - (15L * 24L * 60L * 60L * 1000L);
Date twoWeeksAgo = new Date();
twoWeeksAgo.setTime(twoWeeksAgoMilli);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String twoWeeksAgoStr = df.format(twoWeeksAgo);
Condition sortKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withS(twoWeeksAgoStr));
Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);
keyConditions.put("ReplyDateTime", sortKeyCondition);
QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withKeyConditions(keyConditions).withProjectionExpression("Message, ReplyDateTime, PostedBy");
QueryResult result = client.query(queryRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
printItem(item);
}
}
use of com.amazonaws.services.dynamodbv2.document.Item in project aws-doc-sdk-examples by awsdocs.
the class LowLevelQuery method findRepliesUsingAFilterExpression.
private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) {
Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":val", new AttributeValue().withS("User B"));
QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withKeyConditions(keyConditions).withFilterExpression("PostedBy = :val").withExpressionAttributeValues(expressionAttributeValues).withProjectionExpression("Message, ReplyDateTime, PostedBy");
QueryResult result = client.query(queryRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
printItem(item);
}
}
use of com.amazonaws.services.dynamodbv2.document.Item in project aws-doc-sdk-examples by awsdocs.
the class FaultInjectionRequestHandler method afterResponse.
@Override
public void afterResponse(Request<?> request, Response<?> response) {
/*
* The following is a hit and miss for multi-threaded clients as the
* cache size is only 50 entries
*/
String awsRequestId = dynamoDBClient.getCachedResponseMetadata(request.getOriginalRequest()).getRequestId();
logger.info("AWS RequestID: " + awsRequestId);
/*
* Here you could inspect and alter the response object to see how your
* application behaves for specific data
*/
if (request.getOriginalRequest() instanceof GetItemRequest) {
GetItemResult result = (GetItemResult) response.getAwsResponse();
Map<String, AttributeValue> item = result.getItem();
if (item.get("name").getS().equals("Airplane")) {
// Alter the item
item.put("name", new AttributeValue("newAirplane"));
item.put("new attr", new AttributeValue("new attr"));
// Add some delay
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
logger.info(ie);
throw new RuntimeException(ie);
}
}
}
}
use of com.amazonaws.services.dynamodbv2.document.Item in project aws-doc-sdk-examples by awsdocs.
the class MoviesItemOps02 method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
int year = 2015;
String title = "The Big New Movie";
GetItemSpec spec = new GetItemSpec().withPrimaryKey("year", year, "title", title);
try {
System.out.println("Attempting to read the item...");
Item outcome = table.getItem(spec);
System.out.println("GetItem succeeded: " + outcome);
} catch (Exception e) {
System.err.println("Unable to read item: " + year + " " + title);
System.err.println(e.getMessage());
}
}
use of com.amazonaws.services.dynamodbv2.document.Item in project aws-doc-sdk-examples by awsdocs.
the class MoviesItemOps06 method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
int year = 2015;
String title = "The Big New Movie";
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(new PrimaryKey("year", year, "title", title)).withConditionExpression("info.rating <= :val").withValueMap(new ValueMap().withNumber(":val", 5.0));
try {
System.out.println("Attempting a conditional delete...");
table.deleteItem(deleteItemSpec);
System.out.println("DeleteItem succeeded");
} catch (Exception e) {
System.err.println("Unable to delete item: " + year + " " + title);
System.err.println(e.getMessage());
}
}
Aggregations