private static void ManualPagination() { System.out.println("running ManualPagination...\n"); final DynamoDbClient client = DynamoDbClient.create(); ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build(); boolean done = false; while (!done) { ListTablesResponse listTablesResponse = client.listTables(listTablesRequest); System.out.println(listTablesResponse.tableNames()); if (listTablesResponse.lastEvaluatedTableName() == null) { done = true; } listTablesRequest = listTablesRequest.toBuilder() .exclusiveStartTableName(listTablesResponse.lastEvaluatedTableName()) .build(); } }
table_name); CreateTableRequest request = CreateTableRequest.builder() .attributeDefinitions(AttributeDefinition.builder() .attributeName("Name") .attributeType(ScalarAttributeType.S) .build()) .keySchema(KeySchemaElement.builder() .attributeName("Name") .keyType(KeyType.HASH) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(new Long(10)) .writeCapacityUnits(new Long(10)) .build()) .tableName(table_name) .build(); System.out.println(response.tableDescription().tableName()); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1);
private static void AutoPaginationWithResume() { System.out.println("running AutoPagination with resume in case of errors...\n"); final DynamoDbClient client = DynamoDbClient.create(); ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build(); ListTablesIterable responses = client.listTablesPaginator(listTablesRequest); ListTablesResponse lastSuccessfulPage = null; try { for (ListTablesResponse response : responses) { response.tableNames().forEach(System.out::println); lastSuccessfulPage = response; } } catch (Exception exception) { if (lastSuccessfulPage != null) { System.out.println(exception.getMessage()); } } } }
new HashMap<String,AttributeValue>(); item_key.put("Name", AttributeValue.builder().s(name).build()); updated_values.put(field[0], AttributeValueUpdate.builder() .value(AttributeValue.builder().s(field[1]).build()) .action(AttributeAction.PUT) .build()); UpdateItemRequest request = UpdateItemRequest.builder() .tableName(table_name) .key(item_key) .attributeUpdates(updated_values) .build(); ddb.updateItem(request); } catch (ResourceNotFoundException e) { System.err.println(e.getMessage()); System.exit(1); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1);
new HashMap<String,AttributeValue>(); key_to_get.put("Name", AttributeValue.builder() .s(name).build()); request = GetItemRequest.builder() .key(key_to_get) .tableName(table_name) .projectionExpression(projection_expression) .build(); } else { request = GetItemRequest.builder() .key(key_to_get) .tableName(table_name) .build(); ddb.getItem(request).item(); if (returned_item != null) { Set<String> keys = returned_item.keySet(); for (String key : keys) { System.out.format("%s: %s\n", key, returned_item.get(key).toString()); System.err.println(e.getMessage()); System.exit(1);
DescribeTableRequest request = DescribeTableRequest.builder() .tableName(table_name) .build(); ddb.describeTable(request).table(); table_info.tableName()); System.out.format("Table ARN : %s\n", table_info.tableArn()); System.out.format("Status : %s\n", table_info.tableStatus()); System.out.format("Item count : %d\n", table_info.itemCount().longValue()); System.out.format("Size (bytes): %d\n", table_info.tableSizeBytes().longValue()); table_info.provisionedThroughput(); System.out.println("Throughput"); System.out.format(" Read Capacity : %d\n", throughput_info.readCapacityUnits().longValue()); System.out.format(" Write Capacity: %d\n", throughput_info.writeCapacityUnits().longValue()); table_info.attributeDefinitions(); System.out.println("Attributes"); for (AttributeDefinition a : attributes) { System.out.format(" %s (%s)\n", a.attributeName(), a.attributeType());
new HashMap<String,AttributeValue>(); item_values.put("Name", AttributeValue.builder().s(name).build()); item_values.put(field[0], AttributeValue.builder().s(field[1]).build()); PutItemRequest request = PutItemRequest.builder() .tableName(table_name) .item(item_values) .build(); System.exit(1); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1);
new HashMap<String,AttributeValue>(); key_to_get.put("Name", AttributeValue.builder() .s(name) .build()); DeleteItemRequest deleteReq = DeleteItemRequest.builder() .tableName(table_name) .key(key_to_get) .build(); ddb.deleteItem(deleteReq); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1);
attrValues.put(":"+partition_key_name, AttributeValue.builder().s(partition_key_val).build()); QueryRequest queryReq = QueryRequest.builder() .tableName(table_name) .keyConditionExpression(partition_alias + " = :" + partition_key_name) .expressionAttributeNames(attrNameAlias) .expressionAttributeValues(attrValues) .build(); System.out.println(response.count()); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1);
System.out.format("Write capacity : %d\n", write_capacity); ProvisionedThroughput table_throughput = ProvisionedThroughput.builder() .readCapacityUnits(read_capacity) .writeCapacityUnits(write_capacity) .build(); UpdateTableRequest request = UpdateTableRequest.builder() .provisionedThroughput(table_throughput) .tableName(table_name) .build(); System.err.println(e.getMessage()); System.exit(1);
ListTablesResponse response = null; if (last_name == null) { ListTablesRequest request = ListTablesRequest.builder().build(); response = ddb.listTables(request); ListTablesRequest request = ListTablesRequest.builder() .exclusiveStartTableName(last_name).build(); response = ddb.listTables(request); List<String> table_names = response.tableNames(); last_name = response.lastEvaluatedTableName(); if (last_name == null) { more_tables = false; System.err.println(e.getMessage()); System.exit(1);
DeleteTableRequest request = DeleteTableRequest.builder() .tableName(table_name) .build(); System.err.println(e.getMessage()); System.exit(1);
@Override public final Builder streamViewType(StreamViewType streamViewType) { this.streamViewType(streamViewType.toString()); return this; }
@Override public final Builder backupStatus(BackupStatus backupStatus) { this.backupStatus(backupStatus.toString()); return this; }
@Override public final Builder billingMode(BillingMode billingMode) { this.billingMode(billingMode.toString()); return this; }
@Override public final Builder returnValuesOnConditionCheckFailure( ReturnValuesOnConditionCheckFailure returnValuesOnConditionCheckFailure) { this.returnValuesOnConditionCheckFailure(returnValuesOnConditionCheckFailure.toString()); return this; }
@Override public final Builder continuousBackupsStatus(ContinuousBackupsStatus continuousBackupsStatus) { this.continuousBackupsStatus(continuousBackupsStatus.toString()); return this; }
@Override public final Builder returnConsumedCapacity(ReturnConsumedCapacity returnConsumedCapacity) { this.returnConsumedCapacity(returnConsumedCapacity.toString()); return this; }
CreateTableRequest request = CreateTableRequest.builder() .attributeDefinitions( AttributeDefinition.builder() .attributeName("Language") .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName("Greeting") .attributeType(ScalarAttributeType.S) .build()) .keySchema( KeySchemaElement.builder() .attributeName("Language") .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName("Greeting") .keyType(KeyType.RANGE) .build()) .provisionedThroughput( ProvisionedThroughput.builder() .readCapacityUnits(new Long(10)) .writeCapacityUnits(new Long(10)).build()) .tableName(table_name) .build(); CreateTableResponse result = ddb.createTable(request); } catch (DynamoDbException e) { System.err.println(e.getMessage());
private static void AutoPagination() { System.out.println("running AutoPagination...\n"); final DynamoDbClient client = DynamoDbClient.create(); ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build(); ListTablesIterable responses = client.listTablesPaginator(listTablesRequest); System.out.println("AutoPagination: using for loop"); for (final ListTablesResponse response : responses) { System.out.println(response.tableNames()); } // Print the table names using the responses stream System.out.println("AutoPagination: using stream"); responses.stream().forEach(response -> System.out.println(response.tableNames())); // Convert the stream of responses to stream of table names, then print the table names System.out.println("AutoPagination: using flatmap to get stream of table names"); responses.stream() .flatMap(response -> response.tableNames().stream()) .forEach(System.out::println); System.out.println("AutoPagination: iterating directly on the table names"); Iterable<String> tableNames = responses.tableNames(); tableNames.forEach(System.out::println); }