DRY up creation of the CreateTable Request builder
This commit is contained in:
parent
cca20eb2a2
commit
890a5c8bd3
1 changed files with 16 additions and 20 deletions
|
|
@ -186,23 +186,13 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
@Override
|
@Override
|
||||||
public boolean createLeaseTableIfNotExists(@NonNull final Long readCapacity, @NonNull final Long writeCapacity)
|
public boolean createLeaseTableIfNotExists(@NonNull final Long readCapacity, @NonNull final Long writeCapacity)
|
||||||
throws ProvisionedThroughputException, DependencyException {
|
throws ProvisionedThroughputException, DependencyException {
|
||||||
ProvisionedThroughput throughput = ProvisionedThroughput.builder().readCapacityUnits(readCapacity)
|
final CreateTableRequest.Builder builder = createTableRequestBuilder();
|
||||||
|
if(BillingMode.PROVISIONED.equals(billingMode)) {
|
||||||
|
ProvisionedThroughput throughput = ProvisionedThroughput.builder().readCapacityUnits(readCapacity)
|
||||||
.writeCapacityUnits(writeCapacity).build();
|
.writeCapacityUnits(writeCapacity).build();
|
||||||
final CreateTableRequest request;
|
builder.provisionedThroughput(throughput);
|
||||||
if(BillingMode.PAY_PER_REQUEST.equals(billingMode)){
|
|
||||||
request = CreateTableRequest.builder().tableName(table).keySchema(serializer.getKeySchema())
|
|
||||||
.attributeDefinitions(serializer.getAttributeDefinitions())
|
|
||||||
.billingMode(billingMode)
|
|
||||||
.tags(tags)
|
|
||||||
.build();
|
|
||||||
} else {
|
|
||||||
request = CreateTableRequest.builder().tableName(table).keySchema(serializer.getKeySchema())
|
|
||||||
.attributeDefinitions(serializer.getAttributeDefinitions()).provisionedThroughput(throughput)
|
|
||||||
.tags(tags)
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
return createTableIfNotExists(builder.build());
|
||||||
return createTableIfNotExists(request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -211,11 +201,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
@Override
|
@Override
|
||||||
public boolean createLeaseTableIfNotExists()
|
public boolean createLeaseTableIfNotExists()
|
||||||
throws ProvisionedThroughputException, DependencyException {
|
throws ProvisionedThroughputException, DependencyException {
|
||||||
final CreateTableRequest request = CreateTableRequest.builder().tableName(table).keySchema(serializer.getKeySchema())
|
final CreateTableRequest request = createTableRequestBuilder().build();
|
||||||
.attributeDefinitions(serializer.getAttributeDefinitions())
|
|
||||||
.billingMode(billingMode)
|
|
||||||
.tags(tags)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return createTableIfNotExists(request);
|
return createTableIfNotExists(request);
|
||||||
}
|
}
|
||||||
|
|
@ -816,6 +802,16 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CreateTableRequest.Builder createTableRequestBuilder() {
|
||||||
|
final CreateTableRequest.Builder builder = CreateTableRequest.builder().tableName(table).keySchema(serializer.getKeySchema())
|
||||||
|
.attributeDefinitions(serializer.getAttributeDefinitions())
|
||||||
|
.tags(tags);
|
||||||
|
if (BillingMode.PAY_PER_REQUEST.equals(billingMode)) {
|
||||||
|
builder.billingMode(billingMode);
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
private AWSExceptionManager createExceptionManager() {
|
private AWSExceptionManager createExceptionManager() {
|
||||||
final AWSExceptionManager exceptionManager = new AWSExceptionManager();
|
final AWSExceptionManager exceptionManager = new AWSExceptionManager();
|
||||||
exceptionManager.add(DynamoDbException.class, t -> t);
|
exceptionManager.add(DynamoDbException.class, t -> t);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue