Skip to content
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

Add support for declaring DynamoDB table names using @TableName annotation #1152

Closed
hardikSinghBehl opened this issue May 14, 2024 · 5 comments

Comments

@hardikSinghBehl
Copy link
Contributor

hardikSinghBehl commented May 14, 2024

Type: Feature

Describe the solution you'd like
Similar to JPA's @Table annotation that provides the ability to declare table names in the entity class itself. I propose a similar solution of creating a custom annotation @TableName with a single attribute name:

@Target(TYPE)
@Retention(RUNTIME)
public @interface TableName {
    String name() default "";
}

This optional annotation when present in the class, takes precedence over the default snake_case name resolver in the DefaultDynamoDbTableNameResolver class.

@DynamoDbBean
@TableName(name = "MedicalRecords") // plural or whatever is needed
public class MedicalRecord {
    // class implementation
}
public class DefaultDynamoDbTableNameResolver implements DynamoDbTableNameResolver {

        // existing class implementation
        
	@Override
	public String resolve(Class clazz) {
                // existing method implementation
                 
                TableName tableName = clazz.getAnnotation(TableName.class);
                if (tableName != null && StringUtils.hasText(tableName.name())) {
                    String name = tableName.name();
                    return prefix.concat(name).concat(suffix);
                }
		
		// existing method implementation
	}

}

This feature would provide flexibility for developers to use custom table names when needed while still maintaining the default snake case behaviour for classes without the annotation. Also, no need to create a custom implementation of DynamoDbTableNameResolver when using this approach.

Additional context
Can submit PR if the feature is approved.

@hardikSinghBehl
Copy link
Contributor Author

Hi @MatejNedic, @maciejwalkowiak, @tomazfernandes. Submitting this feature request for evaluation.

@MatejNedic
Copy link
Member

Hey @hardikSinghBehl ,

Since this is simple wrapper I wouldn't go with personally. Let's see what community thinks. If there is support and need for this lets add it ;)

@MatejNedic
Copy link
Member

Closing as it this feature is going to be part of Spring Data DynamoDB based on AWS sdkv2

@Ghilga
Copy link

Ghilga commented Oct 17, 2024

Closing as it this feature is going to be part of Spring Data DynamoDB based on AWS sdkv2

Hey @MatejNedic, could you provide some links to this project, or how is it related to spring-cloud-aws? Only info I found about it is on some 4 year old repos.
I'm also in need of a solution like the one proposed here, but I'm having trouble finding it.

@MatejNedic
Copy link
Member

Hey @Ghilga ,

Current development is still in Private repo. I have not really done much work in last month have to go back to it.
It will feature Spring Data looking like project for DynamoDB. Although project will only support single table design.

It is too early to give samples since it is still under development it is not a small project. I have to go do the polish, add more tests and finally write the docs so it won't be that soon, since I do this when I get the time in my life after work 😅.

But to give you some idea it will allow you to annotate entity and automatically using custom dynamoDbTemplate to get all data you need via 1 query as single table design intends to. Serialisation here is a problem since modelling in Java for DynamoDB is really awkward for single table design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants