Skip to content

Make builders and static ctors consistent #1596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ default CompletableFuture<ResultT> executeAsync(TableSchema<ItemT> tableSchema,
CompletableFuture<ResponseT> response = asyncServiceCall(dynamoDbAsyncClient).apply(request);
return response.thenApply(r -> transformResponse(r, tableSchema, context, mapperExtension));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ default ResultT executeOnSecondaryIndex(TableSchema<ItemT> tableSchema,
String indexName,
MapperExtension mapperExtension,
DynamoDbClient dynamoDbClient) {
OperationContext context = OperationContext.of(tableName, indexName);
OperationContext context = OperationContext.create(tableName, indexName);
return execute(tableSchema, context, mapperExtension, dynamoDbClient);
}

Expand All @@ -78,7 +78,7 @@ default CompletableFuture<ResultT> executeOnSecondaryIndexAsync(TableSchema<Item
String indexName,
MapperExtension mapperExtension,
DynamoDbAsyncClient dynamoDbAsyncClient) {
OperationContext context = OperationContext.of(tableName, indexName);
OperationContext context = OperationContext.create(tableName, indexName);
return executeAsync(tableSchema, context, mapperExtension, dynamoDbAsyncClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private Key(AttributeValue partitionKeyValue, AttributeValue sortKeyValue) {
* @param partitionKeyValue A DynamoDb {@link AttributeValue} that is the literal value of the partition key.
* @return A key.
*/
public static Key of(AttributeValue partitionKeyValue) {
public static Key create(AttributeValue partitionKeyValue) {
return new Key(partitionKeyValue, null);
}

Expand All @@ -56,7 +56,7 @@ public static Key of(AttributeValue partitionKeyValue) {
* @param sortKeyValue A DynamoDb {@link AttributeValue} that is the literal value of the sort key.
* @return A key.
*/
public static Key of(AttributeValue partitionKeyValue, AttributeValue sortKeyValue) {
public static Key create(AttributeValue partitionKeyValue, AttributeValue sortKeyValue) {
return new Key(partitionKeyValue, sortKeyValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package software.amazon.awssdk.extensions.dynamodb.mappingclient;

import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.extensions.dynamodb.mappingclient.core.DynamoDbMappedDatabase;

/**
* Synchronous interface for running commands against a DynamoDb database. See {@link DynamoDbMappedDatabase} for an
Expand All @@ -43,12 +42,4 @@ public interface MappedDatabase {
* @param <T> THe modelled object type being mapped to this table.
*/
<T> MappedTable<T> table(String tableName, TableSchema<T> tableSchema);

/**
* Constructs a builder for the default approved implementation of this interface.
* @return A builder for a {@link DynamoDbMappedDatabase}.
*/
static DynamoDbMappedDatabase.Builder builder() {
return DynamoDbMappedDatabase.builder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ private OperationContext(String tableName, String indexName) {
this.indexName = indexName;
}

public static OperationContext of(String tableName, String indexName) {
public static OperationContext create(String tableName, String indexName) {
return new OperationContext(tableName, indexName);
}

public static OperationContext of(String tableName) {
public static OperationContext create(String tableName) {
return new OperationContext(tableName, TableMetadata.primaryIndexName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private Page(List<T> items, Map<String, AttributeValue> lastEvaluatedKey) {
* @param <T> The modelled type of the object that has been read.
* @return A newly constructed {@link Page} object.
*/
public static <T> Page<T> of(List<T> items, Map<String, AttributeValue> lastEvaluatedKey) {
public static <T> Page<T> create(List<T> items, Map<String, AttributeValue> lastEvaluatedKey) {
return new Page<>(items, lastEvaluatedKey);
}

Expand All @@ -53,7 +53,7 @@ public static <T> Page<T> of(List<T> items, Map<String, AttributeValue> lastEval
* @param <T> The modelled type of the object that has been read.
* @return A newly constructed {@link Page} object.
*/
public static <T> Page<T> of(List<T> items) {
public static <T> Page<T> create(List<T> items) {
return new Page<>(items, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default SdkIterable<ResultT> executeOnSecondaryIndex(TableSchema<ItemT> tableSch
String indexName,
MapperExtension mapperExtension,
DynamoDbClient dynamoDbClient) {
OperationContext context = OperationContext.of(tableName, indexName);
OperationContext context = OperationContext.create(tableName, indexName);
return execute(tableSchema, context, mapperExtension, dynamoDbClient);
}

Expand All @@ -79,7 +79,7 @@ default SdkPublisher<ResultT> executeOnSecondaryIndexAsync(TableSchema<ItemT> ta
String indexName,
MapperExtension mapperExtension,
DynamoDbAsyncClient dynamoDbAsyncClient) {
OperationContext context = OperationContext.of(tableName, indexName);
OperationContext context = OperationContext.create(tableName, indexName);
return executeAsync(tableSchema, context, mapperExtension, dynamoDbAsyncClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ default SdkPublisher<ResultT> executeAsync(TableSchema<ItemT> tableSchema,

return TransformPublisher.of(response, r -> transformResponse(r, tableSchema, context, mapperExtension));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ default SdkIterable<ResultT> executeOnPrimaryIndex(TableSchema<ItemT> tableSchem
MapperExtension mapperExtension,
DynamoDbClient dynamoDbClient) {

OperationContext context = OperationContext.of(tableName, TableMetadata.primaryIndexName());
OperationContext context = OperationContext.create(tableName, TableMetadata.primaryIndexName());
return execute(tableSchema, context, mapperExtension, dynamoDbClient);
}

Expand All @@ -76,7 +76,7 @@ default SdkPublisher<ResultT> executeOnPrimaryIndexAsync(TableSchema<ItemT> tabl
MapperExtension mapperExtension,
DynamoDbAsyncClient dynamoDbAsyncClient) {

OperationContext context = OperationContext.of(tableName, TableMetadata.primaryIndexName());
OperationContext context = OperationContext.create(tableName, TableMetadata.primaryIndexName());
return executeAsync(tableSchema, context, mapperExtension, dynamoDbAsyncClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ default ResultT executeOnPrimaryIndex(TableSchema<ItemT> tableSchema,
String tableName,
MapperExtension mapperExtension,
DynamoDbClient dynamoDbClient) {
OperationContext context = OperationContext.of(tableName, TableMetadata.primaryIndexName());
OperationContext context = OperationContext.create(tableName, TableMetadata.primaryIndexName());
return execute(tableSchema, context, mapperExtension, dynamoDbClient);
}

Expand All @@ -74,7 +74,7 @@ default CompletableFuture<ResultT> executeOnPrimaryIndexAsync(TableSchema<ItemT>
MapperExtension mapperExtension,
DynamoDbAsyncClient dynamoDbAsyncClient) {

OperationContext context = OperationContext.of(tableName, TableMetadata.primaryIndexName());
OperationContext context = OperationContext.create(tableName, TableMetadata.primaryIndexName());
return executeAsync(tableSchema, context, mapperExtension, dynamoDbAsyncClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Map;

import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.extensions.dynamodb.mappingclient.staticmapper.StaticTableSchema;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

/**
Expand Down Expand Up @@ -84,14 +83,4 @@ public interface TableSchema<T> {
* @return A {@link TableMetadata} object that contains structural information about the table being modelled.
*/
TableMetadata tableMetadata();

/**
* Returns a builder for the default implementation of this interface which is an immutable, declarative, type-safe
* mapper.
* See {@link StaticTableSchema} for more information.
* @return A default builder for a {@link StaticTableSchema}.
*/
static StaticTableSchema.GenericBuilder builder() {
return StaticTableSchema.builder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public static <T, R> TransformIterable<T, R> of(SdkIterable<T> iterable, Functio

@Override
public Iterator<R> iterator() {
return TransformIterator.of(wrappedIterable.iterator(), transformFunction);
return TransformIterator.create(wrappedIterable.iterator(), transformFunction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private TransformIterator(Iterator<T> wrappedIterator, Function<T, R> transformF
this.transformFunction = transformFunction;
}

public static <T, R> TransformIterator<T, R> of(Iterator<T> iterator, Function<T, R> transformFunction) {
public static <T, R> TransformIterator<T, R> create(Iterator<T> iterator, Function<T, R> transformFunction) {
return new TransformIterator<>(iterator, transformFunction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static <ResponseT, ItemT> Page<ItemT> readAndTransformPaginatedItems(

if (getLastEvaluatedKey.apply(response) == null || getLastEvaluatedKey.apply(response).isEmpty()) {
// Last page
return Page.of(getItems.apply(response)
return Page.create(getItems.apply(response)
.stream()
.map(itemMap -> readAndTransformSingleItem(itemMap,
tableSchema,
Expand All @@ -97,7 +97,7 @@ public static <ResponseT, ItemT> Page<ItemT> readAndTransformPaginatedItems(
.collect(Collectors.toList()));
} else {
// More pages to come; add the lastEvaluatedKey
return Page.of(getItems.apply(response)
return Page.create(getItems.apply(response)
.stream()
.map(itemMap -> readAndTransformSingleItem(itemMap,
tableSchema,
Expand All @@ -114,7 +114,7 @@ public static <T> Key createKeyFromItem(T item, TableSchema<T> tableSchema, Stri
AttributeValue partitionKeyValue = tableSchema.attributeValue(item, partitionKeyName);
Optional<AttributeValue> sortKeyValue = sortKeyName.map(key -> tableSchema.attributeValue(item, key));

return sortKeyValue.map(attributeValue -> Key.of(partitionKeyValue, attributeValue))
.orElseGet(() -> Key.of(partitionKeyValue));
return sortKeyValue.map(attributeValue -> Key.create(partitionKeyValue, attributeValue))
.orElseGet(() -> Key.create(partitionKeyValue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private ChainMapperExtension(List<MapperExtension> mapperExtensions) {
* @param mapperExtensions A list of {@link MapperExtension} to chain together.
* @return A constructed {@link ChainMapperExtension} object.
*/
public static ChainMapperExtension of(MapperExtension... mapperExtensions) {
public static ChainMapperExtension create(MapperExtension... mapperExtensions) {
return new ChainMapperExtension(Arrays.asList(mapperExtensions));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ private BatchGetItem(Collection<ReadBatch> readBatches) {
this.readBatches = readBatches;
}

public static BatchGetItem of(Collection<ReadBatch> readBatches) {
public static BatchGetItem create(Collection<ReadBatch> readBatches) {
return new BatchGetItem(readBatches);
}

public static BatchGetItem of(ReadBatch... readBatches) {
public static BatchGetItem create(ReadBatch... readBatches) {
return new BatchGetItem(Arrays.asList(readBatches));
}

Expand Down Expand Up @@ -150,7 +150,7 @@ public <T> List<T> getResultsForTable(MappedTable<T> mappedTable) {
return results.stream()
.map(itemMap -> readAndTransformSingleItem(itemMap,
mappedTable.tableSchema(),
OperationContext.of(mappedTable.tableName()),
OperationContext.create(mappedTable.tableName()),
mapperExtension))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ private BatchWriteItem(Collection<WriteBatch> writeBatches) {
this.writeBatches = writeBatches;
}

public static BatchWriteItem of(Collection<WriteBatch> writeBatches) {
public static BatchWriteItem create(Collection<WriteBatch> writeBatches) {
return new BatchWriteItem(writeBatches);
}

public static BatchWriteItem of(WriteBatch... writeBatches) {
public static BatchWriteItem create(WriteBatch... writeBatches) {
return new BatchWriteItem(Arrays.asList(writeBatches));
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public <T> List<T> unprocessedPutItemsForTable(MappedTable<T> mappedTable) {
.map(PutRequest::item)
.map(item -> readAndTransformSingleItem(item,
mappedTable.tableSchema(),
OperationContext.of(mappedTable.tableName()),
OperationContext.create(mappedTable.tableName()),
mappedTable.mapperExtension()))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private ConditionCheck(Key key, Expression conditionExpression) {
this.conditionExpression = conditionExpression;
}

public static <T> ConditionCheck<T> of(Key key, Expression conditionExpression) {
public static <T> ConditionCheck<T> create(Key key, Expression conditionExpression) {
return new ConditionCheck<>(key, conditionExpression);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private CreateTable(ProvisionedThroughput provisionedThroughput,
this.globalSecondaryIndices = globalSecondaryIndices;
}

public static <T> CreateTable<T> of(ProvisionedThroughput provisionedThroughput) {
public static <T> CreateTable<T> create(ProvisionedThroughput provisionedThroughput) {
return new CreateTable<>(provisionedThroughput, null, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private DeleteItem(Builder b) {
this.conditionExpression = b.conditionExpression;
}

public static <T> DeleteItem<T> of(Key key) {
public static <T> DeleteItem<T> create(Key key) {
return DeleteItem.builder().key(key).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private GetItem(Key key, Boolean consistentRead) {
this.consistentRead = consistentRead;
}

public static <T> GetItem<T> of(Key key) {
public static <T> GetItem<T> create(Key key) {
return new GetItem<>(key, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ private GlobalSecondaryIndex(String indexName, Projection projection, Provisione
this.provisionedThroughput = provisionedThroughput;
}

public static GlobalSecondaryIndex of(String indexName,
Projection projection,
ProvisionedThroughput provisionedThroughput) {
public static GlobalSecondaryIndex create(String indexName,
Projection projection,
ProvisionedThroughput provisionedThroughput) {

return new GlobalSecondaryIndex(indexName, projection, provisionedThroughput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private LocalSecondaryIndex(String indexName, Projection projection) {
this.projection = projection;
}

public static LocalSecondaryIndex of(String indexName,
Projection projection) {
public static LocalSecondaryIndex create(String indexName,
Projection projection) {

return new LocalSecondaryIndex(indexName, projection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private PutItem(Builder<T> b) {
this.conditionExpression = b.conditionExpression;
}

public static <T> PutItem<T> of(T item) {
public static <T> PutItem<T> create(T item) {
return PutItem.builder().item(item).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private Query(QueryConditional queryConditional,
this.filterExpression = filterExpression;
}

public static <T> Query<T> of(QueryConditional queryConditional) {
public static <T> Query<T> create(QueryConditional queryConditional) {
return new Query<>(queryConditional, null, null, null, null, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ private ReadBatch(MappedTableResource<T> mappedTableResource, Collection<Batchab
this.readOperations = readOperations;
}

public static <T> ReadBatch<T> of(MappedTableResource<T> mappedTableResource,
public static <T> ReadBatch<T> create(MappedTableResource<T> mappedTableResource,
Collection<BatchableReadOperation> readOperations) {
return new ReadBatch<>(mappedTableResource, readOperations);
}

public static <T> ReadBatch<T> of(MappedTableResource<T> mappedTableResource,
public static <T> ReadBatch<T> create(MappedTableResource<T> mappedTableResource,
BatchableReadOperation... readOperations) {
return new ReadBatch<>(mappedTableResource, Arrays.asList(readOperations));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private ReadTransaction(MappedTableResource<T> mappedTableResource, Transactable
this.readOperation = readOperation;
}

public static <T> ReadTransaction<T> of(MappedTableResource<T> mappedTableResource,
public static <T> ReadTransaction<T> create(MappedTableResource<T> mappedTableResource,
TransactableReadOperation<T> readOperation) {

return new ReadTransaction<>(mappedTableResource, readOperation);
Expand All @@ -47,7 +47,7 @@ public TransactableReadOperation<T> readOperation() {

TransactGetItem generateTransactGetItem() {
return readOperation.generateTransactGetItem(mappedTableResource.tableSchema(),
OperationContext.of(mappedTableResource.tableName()),
OperationContext.create(mappedTableResource.tableName()),
mappedTableResource.mapperExtension());
}

Expand Down
Loading