Optional Configuration Settings for DynamoDBMapper
When you create an instance of
DynamoDBMapper, it has
certain default behaviors; you can override these defaults by using the
The following code snippet creates a
DynamoDBMapper with custom
ClasspathPropertiesFileCredentialsProvider cp = new ClasspathPropertiesFileCredentialsProvider(); AmazonDynamoDBClient client = new AmazonDynamoDBClient(cp); DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig( DynamoDBMapperConfig.SaveBehavior.CLOBBER, DynamoDBMapperConfig.ConsistentReads.CONSISTENT, null, //TableNameOverride - leaving this at default setting DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING ); DynamoDBMapper mapper = new DynamoDBMapper(client, mapperConfig, cp);
You can use the following arguments for an instance of
EVENTUAL—the mapper instance uses an eventually consistent read request.
CONSISTENT—the mapper instance uses a strongly consistent read request. You can use this optional setting with
scanoperations. Strongly consistent reads have implications for performance and billing; see the DynamoDB product detail page for more information.
If you do not specify a read consistency setting for your mapper instance, the default is
DynamoDBMapperConfig.PaginationLoadingStrategyenumeration value—Controls how the mapper instance processes a paginated list of data, such as the results from a
LAZY_LOADING— the mapper instance loads data when possible, and keep all loaded results in memory.
EAGER_LOADING—the mapper instance loads the data as soon as the list is initialized.
ITERATION_ONLY—you can only use an Iterator to read from the list. During the iteration, the list will clear all the previous results before loading the next page, so that the list will keep at most one page of the loaded results in memory. This also means the list can only be iterated once. This strategy is recommended when handling large items, in order to reduce memory overhead.
If you do not specify a pagination loading strategy for your mapper instance, the default is
DynamoDBMapperConfig.SaveBehaviorenumeration value - Specifies how the mapper instance should deal with attributes during save operations:
UPDATE—during a save operation, all modeled attributes are updated, and unmodeled attributes are unaffected. Primitive number types (byte, int, long) are set to 0. Object types are set to null.
CLOBBER—clears and replaces all attributes, included unmodeled ones, during a save operation. This is done be deleting the item and re-creating it. Versioned field constraints are also disregarded.
If you do not specify the save behavior for your mapper instance, the default is
DynamoDBMapperConfig.TableNameOverrideobject—Instructs the mapper instance to ignore the table name specified by a class's
DynamoDBTableannotation, and instead use a different table name that you supply. This is useful when partitioning your data into multiple tables at run time.
You can override the default configuration object for
per operation, as needed.