use of com.amazonaws.services.dynamodbv2.document.Table in project aws-doc-sdk-examples by awsdocs.
the class TryDaxTests method scanTest.
void scanTest(String tableName, DynamoDB client, int iterations) {
long startTime, endTime;
System.out.println("Scan test - all items in the table");
Table table = client.getTable(tableName);
for (int i = 0; i < iterations; i++) {
startTime = System.nanoTime();
ItemCollection<ScanOutcome> items = table.scan();
try {
Iterator<Item> iter = items.iterator();
while (iter.hasNext()) {
iter.next();
}
} catch (Exception e) {
System.err.println("Unable to scan table:");
e.printStackTrace();
}
endTime = System.nanoTime();
printTime(startTime, endTime, iterations);
}
}
use of com.amazonaws.services.dynamodbv2.document.Table in project aws-doc-sdk-examples by awsdocs.
the class DeleteTable method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " DeleteTable <table>\n\n" + "Where:\n" + " table - the table to delete.\n\n" + "Example:\n" + " DeleteTable Greetings\n\n" + "**Warning** This program will actually delete the table\n" + " that you specify!\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String table_name = args[0];
System.out.format("Deleting table %s...\n", table_name);
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
ddb.deleteTable(table_name);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.services.dynamodbv2.document.Table in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBScanItems method main.
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Please specify a table name");
System.exit(1);
}
// snippet-start:[dynamodb.java.dynamoDB_scan.main]
String tableName = args[0];
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
try {
ScanRequest scanRequest = new ScanRequest().withTableName(tableName);
ScanResult result = client.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
Set<String> keys = item.keySet();
for (String key : keys) {
System.out.println("The key name is " + key + "\n");
System.out.println("The value is " + item.get(key).getS());
}
}
} catch (AmazonDynamoDBException e) {
e.getStackTrace();
}
// snippet-end:[dynamodb.java.dynamoDB_scan.main]
}
use of com.amazonaws.services.dynamodbv2.document.Table in project aws-doc-sdk-examples by awsdocs.
the class TryDaxHelper method createTable.
void createTable(String tableName, DynamoDB client) {
Table table = client.getTable(tableName);
try {
System.out.println("Attempting to create table; please wait...");
table = client.createTable(tableName, Arrays.asList(// Partition key
new KeySchemaElement("pk", KeyType.HASH), // Sort key
new KeySchemaElement("sk", KeyType.RANGE)), Arrays.asList(new AttributeDefinition("pk", ScalarAttributeType.N), new AttributeDefinition("sk", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L));
table.waitForActive();
System.out.println("Successfully created table. Table status: " + table.getDescription().getTableStatus());
} catch (Exception e) {
System.err.println("Unable to create table: ");
e.printStackTrace();
}
}
use of com.amazonaws.services.dynamodbv2.document.Table in project aws-doc-sdk-examples by awsdocs.
the class TryDaxHelper method writeData.
void writeData(String tableName, DynamoDB client, int pkmax, int skmax) {
Table table = client.getTable(tableName);
System.out.println("Writing data to the table...");
int stringSize = 1000;
StringBuilder sb = new StringBuilder(stringSize);
for (int i = 0; i < stringSize; i++) {
sb.append('X');
}
String someData = sb.toString();
try {
for (Integer ipk = 1; ipk <= pkmax; ipk++) {
System.out.println(("Writing " + skmax + " items for partition key: " + ipk));
for (Integer isk = 1; isk <= skmax; isk++) {
table.putItem(new Item().withPrimaryKey("pk", ipk, "sk", isk).withString("someData", someData));
}
}
} catch (Exception e) {
System.err.println("Unable to write item:");
e.printStackTrace();
}
}
Aggregations