HHH-17891 support toplevel interceptors for JD repositories

as required by the spec

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-03-26 19:59:47 +01:00
parent e37ca54981
commit c08b8f8c38
6 changed files with 34 additions and 0 deletions

View File

@ -14,10 +14,12 @@ import jakarta.data.repository.Query;
import jakarta.data.repository.Repository; import jakarta.data.repository.Repository;
import jakarta.data.repository.Save; import jakarta.data.repository.Save;
import jakarta.data.repository.Update; import jakarta.data.repository.Update;
import jakarta.transaction.Transactional;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
@Transactional
@Repository @Repository
public interface Library { public interface Library {

View File

@ -94,6 +94,7 @@ public final class ClassWriter {
if ( context.addSuppressWarningsAnnotation() ) { if ( context.addSuppressWarningsAnnotation() ) {
pw.println( writeSuppressWarnings() ); pw.println( writeSuppressWarnings() );
} }
entity.inheritedAnnotations().forEach(pw::println);
printClassDeclaration( entity, pw ); printClassDeclaration( entity, pw );

View File

@ -2698,4 +2698,17 @@ public class AnnotationMetaEntity extends AnnotationMeta {
+ "' of inherited member '" + element.getEnclosingElement().getSimpleName() + "'" + "' of inherited member '" + element.getEnclosingElement().getSimpleName() + "'"
: message + " for inherited member '" + element.getSimpleName() + "'"; : message + " for inherited member '" + element.getSimpleName() + "'";
} }
@Override
public List<AnnotationMirror> inheritedAnnotations() {
if ( jakartaDataRepository ) {
return element.getAnnotationMirrors().stream()
.filter(annotationMirror -> hasAnnotation(annotationMirror.getAnnotationType().asElement(),
"jakarta.interceptor.InterceptorBinding"))
.collect(toList());
}
else {
return emptyList();
}
}
} }

View File

@ -12,6 +12,7 @@ import org.hibernate.processor.ImportContextImpl;
import org.hibernate.processor.model.ImportContext; import org.hibernate.processor.model.ImportContext;
import org.hibernate.processor.model.MetaAttribute; import org.hibernate.processor.model.MetaAttribute;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.PackageElement; import javax.lang.model.element.PackageElement;
import javax.tools.Diagnostic; import javax.tools.Diagnostic;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,6 +20,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static java.util.Collections.emptyList;
/** /**
* Class used to collect meta information about an annotated package. * Class used to collect meta information about an annotated package.
* *
@ -164,4 +167,9 @@ public class AnnotationMetaPackage extends AnnotationMeta {
public boolean isJakartaDataStyle() { public boolean isJakartaDataStyle() {
return false; return false;
} }
@Override
public List<AnnotationMirror> inheritedAnnotations() {
return emptyList();
}
} }

View File

@ -10,6 +10,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.processor.Context; import org.hibernate.processor.Context;
import java.util.List; import java.util.List;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
/** /**
@ -45,4 +46,6 @@ public interface Metamodel extends ImportContext {
String scope(); String scope();
boolean isJakartaDataStyle(); boolean isJakartaDataStyle();
List<AnnotationMirror> inheritedAnnotations();
} }

View File

@ -8,6 +8,7 @@ package org.hibernate.processor.xml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind; import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
@ -46,6 +47,7 @@ import org.hibernate.processor.xml.jaxb.OneToOne;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import static java.util.Collections.emptyList;
import static org.hibernate.processor.util.StringUtil.determineFullyQualifiedClassName; import static org.hibernate.processor.util.StringUtil.determineFullyQualifiedClassName;
import static org.hibernate.processor.util.TypeUtils.extractClosestRealTypeAsString; import static org.hibernate.processor.util.TypeUtils.extractClosestRealTypeAsString;
import static org.hibernate.processor.util.TypeUtils.findMappedSuperClass; import static org.hibernate.processor.util.TypeUtils.findMappedSuperClass;
@ -644,4 +646,9 @@ public class XmlMetaEntity implements Metamodel {
public boolean isJakartaDataStyle() { public boolean isJakartaDataStyle() {
return false; return false;
} }
@Override
public List<AnnotationMirror> inheritedAnnotations() {
return emptyList();
}
} }