Search in sources :

Example 1 with EnhancedLocalSecondaryIndex

use of software.amazon.awssdk.enhanced.dynamodb.model.EnhancedLocalSecondaryIndex in project micronaut-aws-sdk by agorapulse.

the class DefaultDynamoDbService method createTable.

@Override
public void createTable() {
    Map<String, ProjectionType> types = getProjectionTypes();
    TableMetadata tableMetadata = table.tableSchema().tableMetadata();
    table.createTable(b -> {
        List<EnhancedLocalSecondaryIndex> localSecondaryIndices = new ArrayList<>();
        List<EnhancedGlobalSecondaryIndex> globalSecondaryIndices = new ArrayList<>();
        tableMetadata.indices().forEach(i -> {
            if (TableMetadata.primaryIndexName().equals(i.name())) {
                return;
            }
            ProjectionType type = types.getOrDefault(i.name(), ProjectionType.KEYS_ONLY);
            if (tableMetadata.primaryPartitionKey().equals(tableMetadata.indexPartitionKey(i.name()))) {
                localSecondaryIndices.add(EnhancedLocalSecondaryIndex.create(i.name(), Projection.builder().projectionType(type).build()));
            } else {
                globalSecondaryIndices.add(EnhancedGlobalSecondaryIndex.builder().indexName(i.name()).projection(Projection.builder().projectionType(type).build()).build());
            }
        });
        if (!localSecondaryIndices.isEmpty()) {
            b.localSecondaryIndices(localSecondaryIndices);
        }
        if (!globalSecondaryIndices.isEmpty()) {
            b.globalSecondaryIndices(globalSecondaryIndices);
        }
    });
}
Also used : TableMetadata(software.amazon.awssdk.enhanced.dynamodb.TableMetadata) EnhancedLocalSecondaryIndex(software.amazon.awssdk.enhanced.dynamodb.model.EnhancedLocalSecondaryIndex) ArrayList(java.util.ArrayList) EnhancedGlobalSecondaryIndex(software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex) ProjectionType(software.amazon.awssdk.services.dynamodb.model.ProjectionType)

Aggregations

ArrayList (java.util.ArrayList)1 TableMetadata (software.amazon.awssdk.enhanced.dynamodb.TableMetadata)1 EnhancedGlobalSecondaryIndex (software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex)1 EnhancedLocalSecondaryIndex (software.amazon.awssdk.enhanced.dynamodb.model.EnhancedLocalSecondaryIndex)1 ProjectionType (software.amazon.awssdk.services.dynamodb.model.ProjectionType)1