nitrite-java icon indicating copy to clipboard operation
nitrite-java copied to clipboard

@Indices is not neccessary to use, multiple @Index annotations on class are allowed

Open Dacesilian opened this issue 1 year ago • 1 comments

I think you can modify example in https://nitrite.dizitart.com/java-sdk/repository/entity/index.html#indices to not use wrapper @Indices. I've looked into code and I think you load @Index annotations with and without @Indices, so no code should is needed.

SonarLint:

Before Java 8, a container annotation was required as wrapper to use multiple instances of the same annotation. As of Java 8, this is no longer necessary. Instead, these annotations should be used directly without a wrapper, resulting in cleaner and more readable code.

This:

@Indices({
        @Index(fields = "id", type = IndexType.UNIQUE),
        @Index(fields = "partNumber", type = IndexType.UNIQUE),
})
public class MyClass implements Serializable

can be replaced with:

@Index(fields = "id", type = IndexType.UNIQUE)
@Index(fields = "partNumber", type = IndexType.UNIQUE)
public class MyClass implements Serializable

https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html

Dacesilian avatar Apr 02 '24 11:04 Dacesilian

Yes you are right. These are legacy code which was not cleaned up properly.

anidotnet avatar Apr 02 '24 16:04 anidotnet