[jOOQ/jOOQ#13925] Show deprecation warning for javax.persistence annotations also for method and field annotations

This commit is contained in:
Lukas Eder 2022-08-29 10:54:45 +02:00
parent 20665c1d4c
commit d558c4ba9f

View File

@ -192,6 +192,7 @@ import static org.jooq.impl.SubqueryCharacteristics.SET_OPERATION;
import static org.jooq.impl.Tools.SimpleDataKey.DATA_BLOCK_NESTING;
import static org.jooq.tools.StringUtils.defaultIfNull;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@ -3989,9 +3990,21 @@ final class Tools {
return Cache.run(configuration, () -> {
switch (Tools.jpaNamespace()) {
case JAVAX:
if (anyMatch(type.getAnnotations(), a -> a.annotationType().getName().startsWith("javax.persistence.")))
if (anyMatch(type.getAnnotations(), isJavaxPersistenceAnnotation()))
JooqLogger.getLogger(Tools.class, "hasColumnAnnotations", 1).warn("Type " + type + " is annotated with javax.persistence annotation for usage in DefaultRecordMapper, but starting from jOOQ 3.16, only JakartaEE annotations are supported.");
if (anyMatch(map(type.getMethods(), m -> anyMatch(m.getAnnotations(), isJavaxPersistenceAnnotation())), b -> b))
JooqLogger.getLogger(Tools.class, "hasColumnAnnotations", 1).warn("Type " + type + " has methods annotated with javax.persistence annotation for usage in DefaultRecordMapper, but starting from jOOQ 3.16, only JakartaEE annotations are supported.");
if (anyMatch(map(type.getDeclaredMethods(), m -> anyMatch(m.getAnnotations(), isJavaxPersistenceAnnotation())), b -> b))
JooqLogger.getLogger(Tools.class, "hasColumnAnnotations", 1).warn("Type " + type + " has methods annotated with javax.persistence annotation for usage in DefaultRecordMapper, but starting from jOOQ 3.16, only JakartaEE annotations are supported.");
if (anyMatch(map(type.getFields(), f -> anyMatch(f.getAnnotations(), isJavaxPersistenceAnnotation())), b -> b))
JooqLogger.getLogger(Tools.class, "hasColumnAnnotations", 1).warn("Type " + type + " has fields annotated with javax.persistence annotation for usage in DefaultRecordMapper, but starting from jOOQ 3.16, only JakartaEE annotations are supported.");
if (anyMatch(map(type.getDeclaredFields(), f -> anyMatch(f.getAnnotations(), isJavaxPersistenceAnnotation())), b -> b))
JooqLogger.getLogger(Tools.class, "hasColumnAnnotations", 1).warn("Type " + type + " has fields annotated with javax.persistence annotation for usage in DefaultRecordMapper, but starting from jOOQ 3.16, only JakartaEE annotations are supported.");
return false;
case JAKARTA:
@ -4018,6 +4031,10 @@ final class Tools {
}, REFLECTION_CACHE_HAS_COLUMN_ANNOTATIONS, () -> type);
}
private static final ThrowingPredicate<? super Annotation, RuntimeException> isJavaxPersistenceAnnotation() {
return a -> a.annotationType().getName().startsWith("javax.persistence.");
}
static final <T extends AccessibleObject> T accessible(T object, boolean makeAccessible) {
return makeAccessible ? Reflect.accessible(object) : object;
}