Skip to content

Commit

Permalink
feat: refactoring the repository type to have the annotation class
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Dec 27, 2023
1 parent 877f742 commit d6b1006
Showing 1 changed file with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

import jakarta.data.repository.BasicRepository;
import jakarta.data.repository.CrudRepository;
import jakarta.data.repository.Delete;
import jakarta.data.repository.Insert;
import jakarta.data.repository.OrderBy;
import jakarta.data.repository.PageableRepository;
import jakarta.data.repository.Query;
import jakarta.data.repository.Save;
import jakarta.data.repository.Update;
import jakarta.enterprise.inject.spi.CDI;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.EnumSet;
import java.util.Objects;
Expand Down Expand Up @@ -61,22 +66,38 @@ public enum RepositoryType {
* Methods from {@link Object}
*/
OBJECT_METHOD(""),
/**
* The method that belongs to the interface using a default method.
*/
DEFAULT_METHOD(""),
/**
* The method that belongs to the interface using a custom repository.
*/
CUSTOM_REPOSITORY(""),
/**
* Method that has {@link Query} annotation
*/
QUERY(""),
QUERY("", Query.class),
/**
* Method that has {@link jakarta.data.repository.OrderBy} annotation
*/
ORDER_BY(""),
ORDER_BY("", OrderBy.class),
/**
* The method that belongs to the interface using a default method.
* Method that has {@link jakarta.data.repository.Save} annotation
*/
DEFAULT_METHOD(""),
SAVE("", Save.class),
/**
* The method that belongs to the interface using a custom repository.
* Method that has {@link jakarta.data.repository.Insert} annotation
*/
INSERT("", Insert.class),
/**
* Method that has {@link jakarta.data.repository.Delete} annotation
*/
DELETE("", Delete.class),
/**
* Method that has {@link jakarta.data.repository.Update} annotation
*/
CUSTOM_REPOSITORY("");
UPDATE("", Update.class);

private static final Predicate<Class<?>> IS_REPOSITORY_METHOD = Predicate.<Class<?>>isEqual(CrudRepository.class)
.or(Predicate.isEqual(PageableRepository.class))
Expand All @@ -85,8 +106,16 @@ public enum RepositoryType {
private static final Set<RepositoryType> KEY_WORLD_METHODS = EnumSet.of(FIND_BY, DELETE_BY, COUNT_BY, EXISTS_BY);
private final String keyword;

private final Class<? extends Annotation> annotation;

RepositoryType(String keyword) {
this.keyword = keyword;
this.annotation = null;
}

RepositoryType(String keyword, Class<? extends Annotation> annotation) {
this.keyword = keyword;
this.annotation = annotation;
}


Expand Down

0 comments on commit d6b1006

Please sign in to comment.