-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Configure DynamoDb TableSchema as a bean #957
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not my turf, but left a few comments 🙂
private final List<TableSchema<?>> tableSchemas; | ||
private final Map<String, TableSchema> tableSchemaCache = new ConcurrentHashMap<>(); | ||
|
||
DefaultDynamoDbTableResolver() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious - what is this constructor for, with package private visibility?
spring-cloud-aws-dynamodb/src/main/java/io/awspring/cloud/dynamodb/DynamoDbTableResolver.java
Outdated
Show resolved
Hide resolved
this.tableSchemas = tableSchemas; | ||
} | ||
|
||
public <T> TableSchema<T> resolveTableSchema(Class<T> clazz) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this method was added to the interface, maybe add @Override
?
public <T> TableSchema<T> resolveTableSchema(Class<T> clazz) { | ||
String tableName = tableNameResolver.resolve(clazz); | ||
return tableSchemaCache.computeIfAbsent(tableName, | ||
entityClassName -> tableSchemas.stream().filter(it -> it.itemType().rawClass().equals(clazz)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're doing lookups by matching Class
, maybe a better way to store this would be in a Map<Class, TableSchema>? We'd iterate it only once and have O(1) lookups afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and it actually opened my mind for simpler design.
thanks @tomazfernandes! now i think it is much better and no breaking changes. @MatejNedic can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Only 1 change and we can merge
@@ -115,17 +117,23 @@ public DynamoDbEnhancedClient dynamoDbEnhancedClient(DynamoDbClient dynamoDbClie | |||
return DynamoDbEnhancedClient.builder().dynamoDbClient(dynamoDbClient).build(); | |||
} | |||
|
|||
@ConditionalOnMissingBean(DynamoDbTableNameResolver.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ConditionalOnMissingBean(DynamoDbTableNameResolver.class) | |
@ConditionalOnMissingBean(DynamoDbTableSchemaResolver.class) |
Kudos, SonarCloud Quality Gate passed! |
Fixes #674 Co-authored-by: Gladîș Vladlen <gladis.vladlen+github@gmail.com>
Fixes #674 Co-authored-by: Gladîș Vladlen <gladis.vladlen+github@gmail.com>
Fixes #674