Class<?> clazz,
DynamoDBMapperConfig config,
DynamoDBReflector reflector,
ItemConverter converter) {
CreateTableRequest createTableRequest = new CreateTableRequest();
createTableRequest.setTableName(DynamoDBMapper.getTableName(clazz, config, reflector));
// Primary keys
Method pHashKeyGetter = reflector.getPrimaryHashKeyGetter(clazz);
AttributeDefinition pHashAttrDefinition = getKeyAttributeDefinition(pHashKeyGetter, converter);
createTableRequest.withKeySchema(new KeySchemaElement(pHashAttrDefinition.getAttributeName(), KeyType.HASH));
// Primary range
Method pRangeKeyGetter = reflector.getPrimaryRangeKeyGetter(clazz);
AttributeDefinition pRangeAttrDefinition = null;
if (pRangeKeyGetter != null) {
pRangeAttrDefinition = getKeyAttributeDefinition(pRangeKeyGetter, converter);
createTableRequest.withKeySchema(new KeySchemaElement(pRangeAttrDefinition.getAttributeName(), KeyType.RANGE));
}
// Parse the index schema
TableIndexesInfo indexesInfo = parseTableIndexes(clazz, reflector);
if ( indexesInfo.getGlobalSecondaryIndexes().isEmpty() == false ) {
createTableRequest.setGlobalSecondaryIndexes(indexesInfo.getGlobalSecondaryIndexes());
}
if ( indexesInfo.getLocalSecondaryIndexes().isEmpty() == false ) {
createTableRequest.setLocalSecondaryIndexes(indexesInfo.getLocalSecondaryIndexes());
}
// Aggregate all key attribute definitions
Map<String, AttributeDefinition> attrDefinitions = new HashMap<String, AttributeDefinition>();
// Hash key definition
putAfterCheckConflict(attrDefinitions, pHashAttrDefinition);
// Range key definition
if (pRangeKeyGetter != null) {
putAfterCheckConflict(attrDefinitions, pRangeAttrDefinition);
}
for (Method indexKeyGetter : indexesInfo.getIndexKeyGetters()) {
AttributeDefinition indexKeyAttrDefinition = getKeyAttributeDefinition(indexKeyGetter, converter);
putAfterCheckConflict(attrDefinitions, indexKeyAttrDefinition);
}
createTableRequest.setAttributeDefinitions(attrDefinitions.values());
return createTableRequest;
}