CAST supports DynamoDB via
its com.castsoftware.nosqljava
extension. Details about how this support is provided for Java source
code is discussed below.
Note: batchWriteItems, transactWriteItems may result in useInsertLink,
useUpdateLink or useDeleteLink depnding on the usage.
Objects
Icon
Description
Java AWS DynamoDB Client
Java AWS DynamoDB Table
Java AWS Unknown DynamoDB Client
Java AWS Unknown DynamoDB Table
Links
Link type
Source and
destination of link
Methods Supported in AWS SDK Java v1
Methods Supported in AWS SDK Java v1 DynamoDB
Mapper
Methods Supported in AWS SDK Java v2
Methods Supported in v2 Enhanced
Remarks
belongsTo
From Java
AWS DynamoDB Table object to Java AWS DynamoDB Client object
-
-
-
-
-
useLink
Between the caller
Java Method objects and Java AWS DynamoDB table object
createTable
createTableAsync
-
createTable
-
-
useInsertLink
Between the caller
Java Method objects and Java AWS DynamoDB table object
putItem
putItemAsync
save
batchSave
putItem
putItem
putItemWithResponse
batchWriteItems, transactWriteItems may result
in useInsertLink, useUpdateLink or useDeleteLink depnding on the
usage.
useUpdateLink
Between the caller
Java Method objects and Java AWS DynamoDB table object
updateTable
updateItem
updateTableAsync
updateItemAsync
-
updateTable
updateItem
updateItem
updateItemWithReponse
As above
useSelectLink
Between the caller
Java Method objects and Java AWS DynamoDB table object
query
queryAsync
describeTable
describeTableAsync
getItem
getItemAsync
batchGetItem
batchGetItemAsync
transactGetItems
transactGetItemsAsync
load
query
count
scan
scanPage
queryPage
parallelScan
getTableModel
batchLoad
transasctionLoad
describeTable
getItem
query
scan
getItem
query
scan
readBatches
batchGetItem
transactGetItems
As above
useDeleteLink
Between the caller
Java Method objects and Java AWS DynamoDB table object
DeleteTable
DeleteItem
delete
batchDelete
deleteTable
deleteItem
deleteItem
deleteItemWithResponse
As above
What results can you expect?
Some example scenarios are shown below:
AWS SDK JAVA v1
DynamoDB Client Configuration
publicstaticvoidmain(String[]args){finalStringUSAGE="\n"+"Usage:\n"+" CreateTable <table>\n\n"+"Where:\n"+" table - the table to create.\n\n"+"Example:\n"+" CreateTable HelloTable\n";if(args.length<1){System.out.println(USAGE);System.exit(1);}/* Read the name from command args */Stringtable_name="Customer Table";System.out.format("Creating table \"%s\" with a simple primary key: \"Name\".\n",table_name);CreateTableRequestrequest=newCreateTableRequest().withAttributeDefinitions(newAttributeDefinition("Name",ScalarAttributeType.S)).withKeySchema(newKeySchemaElement("Name",KeyType.HASH)).withProvisionedThroughput(newProvisionedThroughput(newLong(10),newLong(10))).withTableName(table_name);finalAmazonDynamoDBddb=AmazonDynamoDBClientBuilder.defaultClient();try{CreateTableResultresult=ddb.createTable(request);System.out.println(result.getTableDescription().getTableName());}catch(AmazonServiceExceptione){System.err.println(e.getErrorMessage());System.exit(1);}System.out.println("Done!");}
Insert Operation
publicstaticvoidmain(Stringargs[])throwsInterruptedException{AmazonDynamoDBdynamoDBClient=AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_EAST_2).withCredentials(newDefaultAWSCredentialsProviderChain()).build();intmaxItemCount=100;for(Integeri=1;i<=maxItemCount;i++){System.out.println("Processing item "+i+" of "+maxItemCount);// Write a new itemMap<String,AttributeValue>item=newHashMap<>();item.put("Id",newAttributeValue().withN(i.toString()));item.put("Message",newAttributeValue().withS("New item!"));dynamoDBClient.putItem(tableName,item);}}
publicstaticvoidmain(Stringargs[])throwsInterruptedException{AmazonDynamoDBdynamoDBClient=AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_EAST_2).withCredentials(newDefaultAWSCredentialsProviderChain()).build();Map<String,AttributeValue>key=newHashMap<>();key.put("Id",newAttributeValue().withN(i.toString()));Map<String,AttributeValueUpdate>attributeUpdates=newHashMap<>();attributeUpdates.put("Message",newAttributeValueUpdate().withAction(AttributeAction.PUT).withValue(newAttributeValue().withS("This item has changed")));dynamoDBClient.updateItem(tableName,key,attributeUpdates);
Select Operation
publicstaticvoidmain(Stringargs[])throwsInterruptedException{AmazonDynamoDBdynamoDBClient=AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_EAST_2).withCredentials(newDefaultAWSCredentialsProviderChain()).build();StringtableName="TestTableForStreams";// Print the stream settings for the tableDescribeTableResultdescribeTableResult=dynamoDBClient.describeTable(tableName);StringstreamArn=describeTableResult.getTable().getLatestStreamArn();System.out.println("Current stream ARN for "+tableName+": "+describeTableResult.getTable().getLatestStreamArn());
publicstaticvoidputItemInTable(DynamoDbClientddb,StringtableName,Stringkey,StringkeyVal,StringalbumTitle,StringalbumTitleValue,Stringawards,StringawardVal,StringsongTitle,StringsongTitleVal){HashMap<String,AttributeValue>itemValues=newHashMap<String,AttributeValue>();// Add all content to the tableitemValues.put(key,AttributeValue.builder().s(keyVal).build());itemValues.put(songTitle,AttributeValue.builder().s(songTitleVal).build());itemValues.put(albumTitle,AttributeValue.builder().s(albumTitleValue).build());itemValues.put(awards,AttributeValue.builder().s(awardVal).build());PutItemRequestrequest=PutItemRequest.builder().tableName(tableName).item(itemValues).build();try{ddb.putItem(request);System.out.println(tableName+" was successfully updated");}catch(ResourceNotFoundExceptione){System.err.format("Error: The Amazon DynamoDB table \"%s\" can't be found.\n",tableName);System.err.println("Be sure that it exists and that you've typed its name correctly!");System.exit(1);}
Delete Operation
publicstaticvoiddeleteDynamoDBTable(DynamoDbClientddb,StringtableName){DeleteTableRequestrequest=DeleteTableRequest.builder().tableName(tableName).build();try{ddb.deleteTable(request);}catch(DynamoDbExceptione){System.err.println(e.getMessage());System.exit(1);}System.out.println(tableName+" was successfully deleted!");}
Update Operation
publicstaticvoidupdateDynamoDBTable(DynamoDbClientddb,StringtableName,LongreadCapacity,LongwriteCapacity){System.out.format("Updating %s with new provisioned throughput values\n",tableName);System.out.format("Read capacity : %d\n",readCapacity);System.out.format("Write capacity : %d\n",writeCapacity);ProvisionedThroughputtableThroughput=ProvisionedThroughput.builder().readCapacityUnits(readCapacity).writeCapacityUnits(writeCapacity).build();UpdateTableRequestrequest=UpdateTableRequest.builder().provisionedThroughput(tableThroughput).tableName(tableName).build();try{ddb.updateTable(request);}catch(DynamoDbExceptione){System.err.println(e.getMessage());System.exit(1);}System.out.println("Done!");}
publicstaticvoidupdateDynamoDBTable(DynamoDbClientddb,StringtableName,LongreadCapacity,LongwriteCapacity){System.out.format("Updating %s with new provisioned throughput values\n",tableName);System.out.format("Read capacity : %d\n",readCapacity);System.out.format("Write capacity : %d\n",writeCapacity);ProvisionedThroughputtableThroughput=ProvisionedThroughput.builder().readCapacityUnits(readCapacity).writeCapacityUnits(writeCapacity).build();UpdateTableRequestrequest=UpdateTableRequest.builder().provisionedThroughput(tableThroughput).tableName(tableName).build();try{ddb.updateTable(request);}catch(DynamoDbExceptione){System.err.println(e.getMessage());System.exit(1);}System.out.println("Done!");}
Select Operation
publicstaticintqueryTable(DynamoDbClientddb,StringtableName,StringpartitionKeyName,StringpartitionKeyVal,StringpartitionAlias){HashMap<String,String>attrNameAlias=newHashMap<String,String>();attrNameAlias.put(partitionAlias,partitionKeyName);// Set up mapping of the partition name with the valueHashMap<String,AttributeValue>attrValues=newHashMap<String,AttributeValue>();attrValues.put(":"+partitionKeyName,AttributeValue.builder().s(partitionKeyVal).build());QueryRequestqueryReq=QueryRequest.builder().tableName(tableName).keyConditionExpression(partitionAlias+" = :"+partitionKeyName).expressionAttributeNames(attrNameAlias).expressionAttributeValues(attrValues).build();try{QueryResponseresponse=ddb.query(queryReq);returnresponse.count();}catch(DynamoDbExceptione){System.err.println(e.getMessage());System.exit(1);}return-1;}
AWS JAVA SDK v2 - Enhanced
Insert Operation
publicstaticvoidputRecord(DynamoDbEnhancedClientenhancedClient){try{DynamoDbTable<Customer>custTable=enhancedClient.table("Customer",TableSchema.fromBean(Customer.class));// Create an InstantLocalDatelocalDate=LocalDate.parse("2021-08-16");LocalDateTimelocalDateTime=localDate.atStartOfDay();Instantinstant=localDateTime.toInstant(ZoneOffset.UTC);// Populate the TableCustomercustRecord=newCustomer();custRecord.setCustName("Susan red");custRecord.setId("id66");custRecord.setEmail("abc@xyz.com");custRecord.setRegistrationDate(instant);// Put the customer data into a DynamoDB tablecustTable.putItem(custRecord);}catch(DynamoDbExceptione){System.err.println(e.getMessage());System.exit(1);}System.out.println("done");}
Update Operation
publicstaticStringmodifyItem(DynamoDbEnhancedClientenhancedClient,StringkeyVal,Stringemail){try{//Create a DynamoDbTable objectDynamoDbTable<Customer>mappedTable=enhancedClient.table("Customer",TableSchema.fromBean(Customer.class));//Create a KEY objectKeykey=Key.builder().partitionValue(keyVal).build();// Get the item by using the key and update the email value.CustomercustomerRec=mappedTable.getItem(r->r.key(key));customerRec.setEmail(email);mappedTable.updateItem(customerRec);returncustomerRec.getEmail();}catch(DynamoDbExceptione){System.err.println(e.getMessage());System.exit(1);}return"";}
Select Operation
publicstaticStringgetItem(DynamoDbEnhancedClientenhancedClient){try{//Create a DynamoDbTable objectDynamoDbTable<Customer>mappedTable=enhancedClient.table("Customer",TableSchema.fromBean(Customer.class));//Create a KEY objectKeykey=Key.builder().partitionValue("id120").build();// Get the item by using the keyCustomerresult=mappedTable.getItem(r->r.key(key));return"The email valie is "+result.getEmail();}catch(DynamoDbExceptione){System.err.println(e.getMessage());System.exit(1);}}
Region_property
publicstaticvoidmain(String[]args){finalStringusage="\n"+"Usage:\n"+" <tableName>\n\n"+"Where:\n"+" tableName - The Amazon DynamoDB table to get information about (for example, Music3).\n\n";if(args.length!=1){System.out.println(usage);System.exit(1);}StringtableName="Test";System.out.format("Getting description for %s\n\n",tableName);Regionsregion=Regions.US_WEST_2;AmazonDynamoDBddb1=AmazonDynamoDBClientBuilder.standard().withRegion(region).build();CreateTableRequestrequest=newCreateTableRequest().withAttributeDefinitions(newAttributeDefinition("Name",ScalarAttributeType.S)).withKeySchema(newKeySchemaElement("Name",KeyType.HASH)).withProvisionedThroughput(newProvisionedThroughput(newLong(10),newLong(10))).withTableName(Table1);TestDescribeTable(ddb1,tableName);ddb1.close();System.out.println("Done!");}publicstaticvoidTestDescribeTable(AmazonDynamoDBddb1,StringtableName){System.out.format("Getting description for %s\n\n",table_name);try{DescribeTableResulttable_info1=ddb1.describeTable(tableName);// ddb4.describeTable(table_name).getTable();TableDescriptiontable_info=table_info1.getTable();if(table_info!=null){System.out.format("Table name : %s\n",table_info.getTableName());System.out.format("Table ARN : %s\n",table_info.getTableArn());System.out.format("Status : %s\n",table_info.getTableStatus());System.out.format("Item count : %d\n",table_info.getItemCount().longValue());System.out.format("Size (bytes): %d\n",table_info.getTableSizeBytes().longValue());ProvisionedThroughputDescriptionthroughput_info=table_info.getProvisionedThroughput();System.out.println("Throughput");System.out.format(" Read Capacity : %d\n",throughput_info.getReadCapacityUnits().longValue());System.out.format(" Write Capacity: %d\n",throughput_info.getWriteCapacityUnits().longValue());List<AttributeDefinition>attributes=table_info.getAttributeDefinitions();System.out.println("Attributes");for(AttributeDefinitiona:attributes){System.out.format(" %s (%s)\n",a.getAttributeName(),a.getAttributeType());}}}catch(AmazonServiceExceptione){System.err.println(e.getErrorMessage());System.exit(1);}System.out.println("\nDone!");}}
Known Limitations
If the table name is not resolved in the CRUD API, then the link is
created with an unknown Table object