NDesai
NDesai

Reputation: 2131

[DynamoDB]: Can I share single data model among multiple tables in DynamoDB using DynamoDBMapper?

I have more than 1 table which follows the same data modeling structure. Basically, I have a different type of orders and based on its type, I am saving and retrieving orders from the tables based on their type.

Example :

All table have same data model.

Structure:

OrderID,Date...

I am using DynamoDbMapper. As DynamoDbMapper needs

@DynamoDBTable(tablename=TABLE)

annotation on class. How can I share this same model among all Order Tables?

@DynamoDBTable(tablename=TABLE)    
public class Order{
        public String orderID; 
        public String date;

    }

Upvotes: 1

Views: 2317

Answers (1)

Matthew Pope
Matthew Pope

Reputation: 7669

DynamoDBMapper allows you to provide some optional config, including overriding the table name.

AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();

// In all cases, setting null tells DynamoDBMapper to use the default value 
DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig(
    null, // Save behavior
    null, //ConsistentReads
    “TableName”, //TableNameOverride
    null // PaginationLoadingStrategy
);

DynamoDBMapper mapper = new DynamoDBMapper(client, mapperConfig, cp);

You can also provide a DynamoDBMapperConfig on a per-operation basis.

See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.OptionalConfig.html

Upvotes: 2

Related Questions