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);
}
});
}
Aggregations