diff --git a/annotation-descriptor-generator/annotation-descriptor-generator.gradle b/annotation-descriptor-generator/annotation-descriptor-generator.gradle new file mode 100644 index 0000000000..e18e5f3c7e --- /dev/null +++ b/annotation-descriptor-generator/annotation-descriptor-generator.gradle @@ -0,0 +1,3 @@ +apply from: rootProject.file( 'gradle/java-module.gradle' ) +apply plugin: 'version-injection' + diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/AbstractClassWriter.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/AbstractClassWriter.java new file mode 100644 index 0000000000..ad38095ad0 --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/AbstractClassWriter.java @@ -0,0 +1,36 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations; + +import java.io.IOException; +import java.io.Writer; +import java.util.Locale; + +/** + * @author Steve Ebersole + */ +public abstract class AbstractClassWriter { + protected final Writer writer; + + protected AbstractClassWriter(Writer writer) { + this.writer = writer; + } + + protected void writeLine() throws IOException { + writer.write( '\n' ); + } + + protected void writeLine(String line, Object... args) throws IOException { + writer.write( String.format( Locale.ROOT, line, args ) ); + writeLine(); + } + + protected void writeLine(int indentation, String line, Object... args) throws IOException { + writer.write( " " .repeat( indentation * 4 ) ); + writeLine( line, args ); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ClassFileHelper.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ClassFileHelper.java new file mode 100644 index 0000000000..3582f2959f --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ClassFileHelper.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations; + +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.lang.model.element.TypeElement; + +/** + * @author Steve Ebersole + */ +public class ClassFileHelper { + public static final String GENERATION_PACKAGE = "org.hibernate.boot.models.annotations.spi"; + static final Pattern CAMEL_CASE_SPLITTER = Pattern.compile( "(([A-Z]?[a-z]+)|([A-Z]))" ); + + static String determineConstantName(TypeElement annotationClass) { + final StringBuilder nameBuffer = new StringBuilder(); + final Matcher matcher = CAMEL_CASE_SPLITTER.matcher( annotationClass.getSimpleName().toString() ); + boolean firstPass = true; + while ( matcher.find() ) { + if ( !firstPass ) { + nameBuffer.append( '_' ); + } + else { + firstPass = false; + } + nameBuffer.append( matcher.group(0).toUpperCase( Locale.ROOT ) ); + } + return nameBuffer.toString(); + } + + public static Object defaultValueValue(Method declaredMethod) { + // should not get in here if there is no default + assert declaredMethod.getDefaultValue() != null; + + if ( declaredMethod.getReturnType().isAnnotation() ) { + return String.format( + Locale.ROOT, + "modelContext.getAnnotationDescriptorRegistry().getDescriptor(%s.class).createUsage(modelContext)", + declaredMethod.getReturnType().getName() + ); + } + + if ( String.class.equals( declaredMethod.getReturnType() ) ) { + return "\"" + declaredMethod.getDefaultValue() + "\""; + } + + if ( long.class.equals( declaredMethod.getReturnType() ) ) { + return declaredMethod.getDefaultValue() + "L"; + } + + if ( declaredMethod.getReturnType().isArray() ) { + final Class componentType = declaredMethod.getReturnType().getComponentType(); + return "new " + componentType.getName() + "[0]"; + } + + return declaredMethod.getDefaultValue(); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ClassGeneratorProcessor.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ClassGeneratorProcessor.java new file mode 100644 index 0000000000..a6d9dbc1bd --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ClassGeneratorProcessor.java @@ -0,0 +1,232 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.ArrayType; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.ExecutableType; +import javax.lang.model.type.TypeMirror; + +import org.hibernate.orm.build.annotations.structure.AnnotationDescriptor; +import org.hibernate.orm.build.annotations.structure.AnnotationType; +import org.hibernate.orm.build.annotations.structure.AttributeDescriptor; +import org.hibernate.orm.build.annotations.structure.BooleanType; +import org.hibernate.orm.build.annotations.structure.EnumType; +import org.hibernate.orm.build.annotations.structure.IntType; +import org.hibernate.orm.build.annotations.structure.LongType; +import org.hibernate.orm.build.annotations.structure.ShortType; +import org.hibernate.orm.build.annotations.structure.Type; + +import static org.hibernate.orm.build.annotations.structure.StringType.STRING_TYPE; + +/** + * @author Steve Ebersole + */ +@SupportedAnnotationTypes( "java.lang.annotation.Retention" ) +public class ClassGeneratorProcessor extends AbstractProcessor { + public static final String JPA_PACKAGE = "jakarta.persistence"; + public static final String HIBERNATE_PACKAGE = "org.hibernate.annotations"; + public static final String HIBERNATE_PACKAGE2 = "org.hibernate.boot.internal"; + public static final String DIALECT_OVERRIDES = "org.hibernate.annotations.DialectOverride"; + + private final Map annotationDescriptorMap = new TreeMap<>( Comparator.comparing( typeElement -> typeElement.getSimpleName().toString() ) ); + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if ( roundEnv.processingOver() ) { + finishUp(); + } + else { + processAnnotations( roundEnv ); + } + + return false; + } + + private void processAnnotations(RoundEnvironment roundEnv) { + processAnnotations( + processingEnv.getElementUtils().getPackageElement( JPA_PACKAGE ), + "%sJpaAnnotation", + "org.hibernate.boot.models.JpaAnnotations" + ); + + processAnnotations( + processingEnv.getElementUtils().getPackageElement( HIBERNATE_PACKAGE ), + "%sAnnotation", + "org.hibernate.boot.models.HibernateAnnotations" + ); + + processAnnotations( + processingEnv.getElementUtils().getPackageElement( HIBERNATE_PACKAGE2 ), + "%sXmlAnnotation", + "org.hibernate.boot.models.XmlAnnotations" + ); + + processAnnotations( + processingEnv.getElementUtils().getTypeElement( DIALECT_OVERRIDES ), + "%sAnnotation", + "org.hibernate.boot.models.DialectOverrideAnnotations" + ); + } + + private void processAnnotations(PackageElement packageElement, String concreteNamePattern, String constantsClassName) { + for ( Element enclosedElement : packageElement.getEnclosedElements() ) { + if ( enclosedElement instanceof TypeElement typeElement ) { + if ( typeElement.getKind() == ElementKind.ANNOTATION_TYPE ) { + processAnnotation( typeElement, concreteNamePattern, constantsClassName, annotationDescriptorMap ); + } + } + } + } + + private void processAnnotations(TypeElement typeElement, String concreteNamePattern, String constantsClassName) { + for ( Element enclosedElement : typeElement.getEnclosedElements() ) { + if ( enclosedElement instanceof TypeElement nestedTypeElement ) { + if ( nestedTypeElement.getKind() == ElementKind.ANNOTATION_TYPE ) { + processAnnotation( nestedTypeElement, concreteNamePattern, constantsClassName, annotationDescriptorMap ); + } + } + } + } + + private void processAnnotation( + TypeElement annotationClass, + String concreteNamePattern, + String constantsClassName, + Map descriptorMap) { + if ( descriptorMap.containsKey( annotationClass ) ) { + // we've already processed it + return; + } + + final String concreteClassName = String.format( concreteNamePattern, annotationClass.getSimpleName().toString() ); + final String constantName = ClassFileHelper.determineConstantName( annotationClass ); + final String repeatableContainerConstantName = resolveRepeatableContainer( annotationClass ); + + final AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor( + annotationClass, + concreteClassName, + constantsClassName, + constantName, + repeatableContainerConstantName, + extractAttributes( annotationClass ) + ); + descriptorMap.put( annotationClass, annotationDescriptor ); + + ConcreteClassWriter.writeClass( annotationDescriptor, processingEnv ); + } + + private List extractAttributes(TypeElement annotationType) { + final List allMembers = processingEnv.getElementUtils().getAllMembers( annotationType ); + final List attributeDescriptors = new ArrayList<>( allMembers.size() ); + + for ( Element member : allMembers ) { + if ( member.getKind() != ElementKind.METHOD ) { + // should only ever be methods anyway, but... + continue; + } + + if ( !member.getEnclosingElement().equals( annotationType ) ) { + // we only want members declared on the annotation (as opposed to Object e.g.) + continue; + } + + ExecutableElement memberAsExecutableElement = (ExecutableElement) member; + + attributeDescriptors.add( new AttributeDescriptor( + member.getSimpleName().toString(), + determineType( member ), + memberAsExecutableElement.getDefaultValue() + ) ); + } + + return attributeDescriptors; + } + + private Type determineType(Element member) { + // member should be an ExecutableElement... + + final ExecutableType memberAsExecutableType = (ExecutableType) member.asType(); + + return interpretType( memberAsExecutableType.getReturnType() ); + } + + private Type interpretType(TypeMirror type) { + return switch ( type.getKind() ) { + case BOOLEAN -> BooleanType.BOOLEAN_TYPE; + case SHORT -> ShortType.SHORT_TYPE; + case INT -> IntType.INT_TYPE; + case LONG -> LongType.LONG_TYPE; + case DECLARED -> interpretDeclaredType( type ); + case ARRAY -> interpretArrayType( type ); + default -> throw new IllegalStateException(); + }; + } + + private Type interpretDeclaredType(TypeMirror type) { + final DeclaredType declaredType = (DeclaredType) type; + final Element declaredTypeAsElement = declaredType.asElement(); + + if ( String.class.getName().equals( declaredTypeAsElement.toString() ) ) { + return STRING_TYPE; + } + + if ( declaredTypeAsElement.getKind() == ElementKind.ANNOTATION_TYPE ) { + return new AnnotationType( declaredType ); + } + + if ( declaredTypeAsElement.getKind() == ElementKind.ENUM ) { + return new EnumType( declaredType ); + } + return new org.hibernate.orm.build.annotations.structure.DeclaredType( declaredType ); + } + + private Type interpretArrayType(TypeMirror type) { + final ArrayType arrayType = (ArrayType) type; + final TypeMirror componentType = arrayType.getComponentType(); + return new org.hibernate.orm.build.annotations.structure.ArrayType( interpretType( componentType ) ); + } + + private String resolveRepeatableContainer(TypeElement annotationClass) { + // todo : need to resolve this... + return null; + } + + private void finishUp() { +// jpaAnnotationDescriptorMap.forEach( (typeElement, annotationDescriptor) -> { +// ConcreteClassWriter.writeClass( annotationDescriptor, JPA_CONSTANTS_CLASS, processingEnv ); +// } ); +// ConstantsClassWriter.writeClass( +// JPA_CONSTANTS_CLASS, +// jpaAnnotationDescriptorMap, +// processingEnv +// ); +// +// hibernateAnnotationDescriptorMap.forEach( (typeElement, annotationDescriptor) -> { +// ConcreteClassWriter.writeClass( annotationDescriptor, HIBERNATE_CONSTANTS_CLASS, processingEnv ); +// } ); +// ConstantsClassWriter.writeClass( +// HIBERNATE_CONSTANTS_CLASS, +// hibernateAnnotationDescriptorMap, +// processingEnv +// ); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ConcreteClassWriter.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ConcreteClassWriter.java new file mode 100644 index 0000000000..5358a7c22e --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/ConcreteClassWriter.java @@ -0,0 +1,261 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations; + +import java.io.IOException; +import java.io.Writer; +import java.lang.reflect.Method; +import javax.annotation.processing.Filer; +import javax.annotation.processing.ProcessingEnvironment; +import javax.tools.JavaFileObject; + +import org.hibernate.orm.build.annotations.structure.AnnotationDescriptor; +import org.hibernate.orm.build.annotations.structure.AttributeDescriptor; + +import static org.hibernate.orm.build.annotations.ClassFileHelper.GENERATION_PACKAGE; + +/** + * Writes the concrete annotation class to file + * + * @author Steve Ebersole + */ +public class ConcreteClassWriter extends AbstractClassWriter { + + public static void writeClass( + AnnotationDescriptor annotationDescriptor, + ProcessingEnvironment processingEnv) { + final String sourceFileName = GENERATION_PACKAGE + "." + annotationDescriptor.concreteTypeName(); + + final Filer filer = processingEnv.getFiler(); + try { + final JavaFileObject sourceFile = filer.createSourceFile( sourceFileName, annotationDescriptor.annotationType() ); + try (Writer writer = sourceFile.openWriter()) { + final ConcreteClassWriter classWriter = new ConcreteClassWriter( annotationDescriptor, writer, processingEnv ); + classWriter.write(); + } + } + catch (IOException e) { + throw new RuntimeException( "Unable to create concrete Annotation class source file : " + sourceFileName, e ); + } + } + + private final AnnotationDescriptor annotationDescriptor; + private final ProcessingEnvironment processingEnv; + + public ConcreteClassWriter( + AnnotationDescriptor annotationDescriptor, + Writer writer, + ProcessingEnvironment processingEnv) { + super( writer ); + this.annotationDescriptor = annotationDescriptor; + this.processingEnv = processingEnv; + } + + private void write() throws IOException { + writeLine( "package %s;", GENERATION_PACKAGE ); + + writer.write( '\n' ); + + writeLine( "import java.lang.annotation.Annotation;" ); + writeLine(); + writeLine( "import org.hibernate.models.spi.SourceModelBuildingContext;" ); + writeLine(); + writeLine( "import org.jboss.jandex.AnnotationInstance;" ); + writeLine(); + writeLine( "import %s;", annotationDescriptor.annotationType().getQualifiedName().toString() ); + writeLine(); + writeLine( "import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue;" ); + writeLine( "import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue;" ); + + writer.write( '\n' ); + + writeLine( "@SuppressWarnings({ \"ClassExplicitlyAnnotation\", \"unused\" })" ); + writeLine( "@jakarta.annotation.Generated(\"org.hibernate.orm.build.annotations.ClassGeneratorProcessor\")" ); + writeLine( "public class %s implements %s {", annotationDescriptor.concreteTypeName(), annotationDescriptor.annotationType().getSimpleName().toString() ); + + writeDescriptorConstant(); + writeFields(); + writeConstructors(); + writeMethods(); + + writeLine( "}" ); + } + + private void writeDescriptorConstant() throws IOException { +// writeLine( +// 1, +// "public static final %s<%s,%> %s = new %s(%s.class, %s.class, %s);", +// "OrmAnnotationDescriptor", +// annotationDescriptor.annotationType().getSimpleName(), +// annotationDescriptor.concreteTypeName(), +// annotationDescriptor.constantName(), +// "OrmAnnotationDescriptor", +// annotationDescriptor.annotationType().getSimpleName(), +// annotationDescriptor.concreteTypeName(), +// annotationDescriptor.repeatableContainerConstantName() +// ); + writeLine( + 1, + "public static final %s<%s,%s> %s = null;", + "OrmAnnotationDescriptor", + annotationDescriptor.annotationType().getSimpleName(), + annotationDescriptor.concreteTypeName(), + annotationDescriptor.constantName() + ); + writeLine(); + } + + private void writeFields() throws IOException { + for ( AttributeDescriptor attribute : annotationDescriptor.attributes() ) { + writeLine( 1, "private %s %s;", attribute.getType().getTypeDeclarationString(), attribute.getName() ); + } + writeLine(); + } + + private void writeConstructors() throws IOException { + writeDefaultInitialization(); + writeJdkInitialization(); + writeJandexInitialization(); + } + + private void writeDefaultInitialization() throws IOException { + writeLine( 1, "/**" ); + writeLine( 1, " * Used in creating dynamic annotation instances (e.g. from XML)" ); + writeLine( 1, " */" ); + writeLine( 1, "public %s(SourceModelBuildingContext modelContext) {", annotationDescriptor.concreteTypeName() ); + + for ( AttributeDescriptor attribute : annotationDescriptor.attributes() ) { + writeDefaultValueInitialization( attribute ); + } + + writeLine( 1, "}" ); + writeLine(); + } + + private void writeDefaultValueInitialization(AttributeDescriptor attribute) throws IOException { + if ( attribute.getDefaultValue() == null || attribute.getDefaultValue().getValue() == null ) { + return; + } + + writeLine( 2, "this.%s = %s;", attribute.getName(),attribute.getType().getInitializerValue( attribute.getDefaultValue() ) ); + } + + private void writeJdkInitialization() throws IOException { + writeLine( 1, "/**" ); + writeLine( 1, " * Used in creating annotation instances from JDK variant" ); + writeLine( 1, " */" ); + writeLine( 1, "public %s(%s annotation, SourceModelBuildingContext modelContext) {", annotationDescriptor.concreteTypeName(), annotationDescriptor.annotationType().getSimpleName().toString() ); + + for ( AttributeDescriptor attributeDescriptor : annotationDescriptor.attributes() ) { + writeJdkValueInitialization( attributeDescriptor ); + } + + writeLine( 1, "}" ); + writeLine(); + } + + private void writeJdkValueInitialization(AttributeDescriptor attribute) throws IOException { + writeLine( + 2, + "this.%s = extractJdkValue( annotation, %s, \"%s\", modelContext );", + attribute.getName(), + annotationDescriptor.getConstantFqn(), + attribute.getName() + ); + } + + private void writeJandexInitialization() throws IOException { + writeLine( 1, "/**" ); + writeLine( 1, " * Used in creating annotation instances from Jandex variant" ); + writeLine( 1, " */" ); + writeLine( 1, "public %s(AnnotationInstance annotation, SourceModelBuildingContext modelContext) {", annotationDescriptor.concreteTypeName() ); + + for ( AttributeDescriptor attributeDescriptor : annotationDescriptor.attributes() ) { + writeJandexValueInitialization( attributeDescriptor ); + } + + writeLine( 1, "}" ); + writeLine(); + } + + private void writeJandexValueInitialization(AttributeDescriptor attributeDescriptor) throws IOException { + final String attrName = attributeDescriptor.getName(); + + writeLine( + 2, + "this.%s = extractJandexValue( annotation, %s, \"%s\", modelContext );", + attrName, + annotationDescriptor.getConstantFqn(), + attrName + ); + } + + private void writeMethods() throws IOException { + writeAnnotationTypeMethod(); + writeGettersAndSetters(); + writeHelperMethods(); + } + + private void writeAnnotationTypeMethod() throws IOException { + writeLine( 1, "@Override" ); + writeLine( 1, "public Class annotationType() {" ); + writeLine( 2, "return %s.class;", annotationDescriptor.annotationType().getSimpleName() ); + writeLine( 1, "}" ); + writeLine(); + } + + private void writeGettersAndSetters() throws IOException { + for ( AttributeDescriptor attribute : annotationDescriptor.attributes() ) { + writeGetterAndSetter( attribute ); + writeLine(); + } + } + + private void writeGetterAndSetter(AttributeDescriptor attribute) throws IOException { + // "getter" + writeLine( + 1, + "@Override public %s %s() { return %s; }", + attribute.getType().getTypeDeclarationString(), + attribute.getName(), + attribute.getName() + ); + + // "setter" + writeLine( + 1, + "public void %s(%s value) { this.%s = value; }", + attribute.getName(), + attribute.getType().getTypeDeclarationString(), + attribute.getName() + ); + + writeLine(); + } + + private void writeHelperMethods() throws IOException { +// writeLine( 1, "public static V extractJdkValue(A jdkAnnotation, AttributeDescriptor attributeDescriptor, SourceModelBuildingContext modelContext) {" ); +// writeLine( 2, "return attributeDescriptor.getTypeDescriptor().createJdkValueExtractor( modelContext ).extractValue( jdkAnnotation, attributeDescriptor, modelContext );" ); +// writeLine( 1, "}" ); +// writeLine(); +// writeLine( 1, "public static V extractJdkValue(A jdkAnnotation, AnnotationDescriptor annotationDescriptor, String attributeName, SourceModelBuildingContext modelContext) {" ); +// writeLine( 2, "final AttributeDescriptor attributeDescriptor = annotationDescriptor.getAttribute( attributeName );" ); +// writeLine( 2, "return extractJdkValue( jdkAnnotation, attributeDescriptor, modelContext );" ); +// writeLine( 1, "}" ); +// writeLine(); +// writeLine( 1, "public static V extractJandexValue(AnnotationInstance jandexAnnotation, AttributeDescriptor attributeDescriptor, SourceModelBuildingContext modelContext) {" ); +// writeLine( 2, "final AnnotationValue value = jandexAnnotation.value( attributeDescriptor.getName() );" ); +// writeLine( 2, "return attributeDescriptor.getTypeDescriptor().createJandexValueConverter( modelContext ).convert( value, modelContext );" ); +// writeLine( 1, "}" ); +// writeLine(); +// writeLine( 1, "public static V extractJandexValue(AnnotationInstance jandexAnnotation, AnnotationDescriptor annotationDescriptor, String attributeName, SourceModelBuildingContext modelContext) {" ); +// writeLine( 2, "final AttributeDescriptor attributeDescriptor = %s.getAttribute( attributeName );" ); +// writeLine( 2, "return extractJandexValue( jandexAnnotation, attributeDescriptor, modelContext );" ); +// writeLine( 1, "}" ); + } + +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AnnotationDescriptor.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AnnotationDescriptor.java new file mode 100644 index 0000000000..f55dc441d7 --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AnnotationDescriptor.java @@ -0,0 +1,25 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import java.util.List; +import javax.lang.model.element.TypeElement; + +/** + * @author Steve Ebersole + */ +public record AnnotationDescriptor( + TypeElement annotationType, + String concreteTypeName, + String constantsClassName, + String constantName, + String repeatableContainerConstantName, + List attributes) { + public String getConstantFqn() { + return constantsClassName() + "." + constantName(); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AnnotationType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AnnotationType.java new file mode 100644 index 0000000000..ed0d4e0653 --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AnnotationType.java @@ -0,0 +1,36 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import java.util.Locale; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.type.DeclaredType; + +/** + * @author Steve Ebersole + */ +public class AnnotationType implements Type { + private final javax.lang.model.type.DeclaredType underlyingType; + + public AnnotationType(DeclaredType underlyingType) { + this.underlyingType = underlyingType; + } + + @Override + public String getTypeDeclarationString() { + return underlyingType.toString(); + } + + @Override + public String getInitializerValue(AnnotationValue defaultValue) { + return String.format( + Locale.ROOT, + "modelContext.getAnnotationDescriptorRegistry().getDescriptor(%s.class).createUsage(modelContext)", + underlyingType.toString() + ); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/ArrayType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/ArrayType.java new file mode 100644 index 0000000000..d92e81286a --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/ArrayType.java @@ -0,0 +1,31 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import java.util.Locale; +import javax.lang.model.element.AnnotationValue; + +/** + * @author Steve Ebersole + */ +public class ArrayType implements Type { + private final Type componentType; + + public ArrayType(Type componentType) { + this.componentType = componentType; + } + + @Override + public String getTypeDeclarationString() { + return componentType.getTypeDeclarationString() + "[]"; + } + + @Override + public String getInitializerValue(AnnotationValue defaultValue) { + return String.format( Locale.ROOT, "new %s[0]", componentType.getTypeDeclarationString() ); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AttributeDescriptor.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AttributeDescriptor.java new file mode 100644 index 0000000000..546b36f0a6 --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/AttributeDescriptor.java @@ -0,0 +1,36 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import javax.lang.model.element.AnnotationValue; + +/** + * @author Steve Ebersole + */ +public class AttributeDescriptor { + private final String name; + private final Type type; + private final AnnotationValue defaultValue; + + public AttributeDescriptor(String name, Type type, AnnotationValue defaultValue) { + this.name = name; + this.type = type; + this.defaultValue = defaultValue; + } + + public String getName() { + return name; + } + + public Type getType() { + return type; + } + + public AnnotationValue getDefaultValue() { + return defaultValue; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/PhysicalTableReference.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/BooleanType.java similarity index 52% rename from hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/PhysicalTableReference.java rename to annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/BooleanType.java index 2022cec1dd..8771d86c56 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/PhysicalTableReference.java +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/BooleanType.java @@ -4,13 +4,16 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.bind.spi; - -import org.hibernate.boot.model.naming.Identifier; +package org.hibernate.orm.build.annotations.structure; /** * @author Steve Ebersole */ -public interface PhysicalTableReference extends PersistentTableReference { - Identifier getPhysicalTableName(); +public class BooleanType implements Type { + public static final BooleanType BOOLEAN_TYPE = new BooleanType(); + + @Override + public String getTypeDeclarationString() { + return "boolean"; + } } diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/DeclaredType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/DeclaredType.java new file mode 100644 index 0000000000..a86b17eb9e --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/DeclaredType.java @@ -0,0 +1,23 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +/** + * @author Steve Ebersole + */ +public class DeclaredType implements Type { + private final javax.lang.model.type.DeclaredType underlyingType; + + public DeclaredType(javax.lang.model.type.DeclaredType underlyingType) { + this.underlyingType = underlyingType; + } + + @Override + public String getTypeDeclarationString() { + return underlyingType.toString(); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/EnumType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/EnumType.java new file mode 100644 index 0000000000..e9443d943d --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/EnumType.java @@ -0,0 +1,31 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.type.DeclaredType; + +/** + * @author Steve Ebersole + */ +public class EnumType implements Type { + private final DeclaredType underlyingType; + + public EnumType(DeclaredType underlyingType) { + this.underlyingType = underlyingType; + } + + @Override + public String getTypeDeclarationString() { + return underlyingType.toString(); + } + + @Override + public String getInitializerValue(AnnotationValue defaultValue) { + return underlyingType.toString() + "." + defaultValue.toString(); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/IntType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/IntType.java new file mode 100644 index 0000000000..c872d741b5 --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/IntType.java @@ -0,0 +1,26 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import javax.lang.model.element.AnnotationValue; + +/** + * @author Steve Ebersole + */ +public class IntType implements Type { + public static final IntType INT_TYPE = new IntType(); + + @Override + public String getTypeDeclarationString() { + return "int"; + } + + @Override + public String getInitializerValue(AnnotationValue defaultValue) { + return defaultValue.toString(); + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/LongType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/LongType.java new file mode 100644 index 0000000000..4aaa7b46f9 --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/LongType.java @@ -0,0 +1,26 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import javax.lang.model.element.AnnotationValue; + +/** + * @author Steve Ebersole + */ +public class LongType implements Type { + public static final LongType LONG_TYPE = new LongType(); + + @Override + public String getTypeDeclarationString() { + return "long"; + } + + @Override + public String getInitializerValue(AnnotationValue defaultValue) { + return Type.super.getInitializerValue( defaultValue ) + "L"; + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/ShortType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/ShortType.java new file mode 100644 index 0000000000..8d47e7a40c --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/ShortType.java @@ -0,0 +1,21 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import javax.lang.model.element.AnnotationValue; + +/** + * @author Steve Ebersole + */ +public class ShortType implements Type { + public static final ShortType SHORT_TYPE = new ShortType(); + + @Override + public String getTypeDeclarationString() { + return "short"; + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/StringType.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/StringType.java new file mode 100644 index 0000000000..a49b9240fc --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/StringType.java @@ -0,0 +1,26 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import javax.lang.model.element.AnnotationValue; + +/** + * Type implementation Strings + * + * @author Steve Ebersole + */ +public class StringType implements Type { + public static final StringType STRING_TYPE = new StringType(); + + public StringType() { + } + + @Override + public String getTypeDeclarationString() { + return "String"; + } +} diff --git a/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/Type.java b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/Type.java new file mode 100644 index 0000000000..7d900ce402 --- /dev/null +++ b/annotation-descriptor-generator/src/main/java/org/hibernate/orm/build/annotations/structure/Type.java @@ -0,0 +1,20 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.build.annotations.structure; + +import javax.lang.model.element.AnnotationValue; + +/** + * @author Steve Ebersole + */ +public interface Type { + String getTypeDeclarationString(); + + default String getInitializerValue(AnnotationValue defaultValue) { + return defaultValue.toString(); + } +} diff --git a/annotation-descriptor-generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/annotation-descriptor-generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000000..e71374d7d0 --- /dev/null +++ b/annotation-descriptor-generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +org.hibernate.orm.build.annotations.ClassGeneratorProcessor \ No newline at end of file diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 1d1d18f1f6..3837904c3b 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -46,6 +46,9 @@ dependencies { compileOnly libs.jacksonXml compileOnly dbLibs.postgresql +// annotationProcessor project( ":annotation-descriptor-generator" ) + compileOnly project( ":annotation-descriptor-generator" ) + testImplementation project(':hibernate-testing') testImplementation project(':hibernate-ant') testImplementation testLibs.shrinkwrapApi @@ -206,6 +209,22 @@ artifacts { tests testJar } +tasks.register( "generateAnnotationClasses", JavaCompile ) { + description = "Generate concrete classes for Hibernate and JPA annotations" + + source = sourceSets.main.allJava + include "org/hibernate/annotations/*" + classpath = sourceSets.main.runtimeClasspath + sourceSets.main.compileClasspath + options.annotationProcessorPath = sourceSets.main.compileClasspath + options.compilerArgs = [ + "-proc:only", + "-processor", + "org.hibernate.orm.build.annotations.ClassGeneratorProcessor" + ] + + destinationDirectory.set( project.layout.buildDirectory.dir( "generated/sources/annotations/" ) ) +} + task generateEnversStaticMetamodel( type: JavaCompile, description: "Generate the Hibernate Envers revision entity static metamodel classes." ) { diff --git a/hibernate-core/src/main/java/org/hibernate/Remove.java b/hibernate-core/src/main/java/org/hibernate/Remove.java index 64a2d206c7..6f80784382 100644 --- a/hibernate-core/src/main/java/org/hibernate/Remove.java +++ b/hibernate-core/src/main/java/org/hibernate/Remove.java @@ -16,7 +16,6 @@ import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PACKAGE; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.ElementType.TYPE_PARAMETER; -import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.RetentionPolicy.RUNTIME; /** @@ -32,7 +31,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; * * @author Steve Ebersole */ -@Target({METHOD, FIELD, TYPE, PACKAGE, CONSTRUCTOR, TYPE_PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, TYPE, PACKAGE, CONSTRUCTOR, TYPE_PARAMETER}) @Retention(RUNTIME) @Documented public @interface Remove { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/GenerationStrategyInterpreter.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/GenerationStrategyInterpreter.java index 3abfa9d727..7ff5d8dd99 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/GenerationStrategyInterpreter.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/GenerationStrategyInterpreter.java @@ -6,7 +6,6 @@ */ package org.hibernate.boot.internal; -import java.util.List; import java.util.UUID; import org.hibernate.boot.model.IdentifierGeneratorDefinition; @@ -18,7 +17,6 @@ import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -86,28 +84,28 @@ public class GenerationStrategyInterpreter { } public void interpretTableGenerator( - AnnotationUsage tableGeneratorAnnotation, + TableGenerator tableGeneratorAnnotation, IdentifierGeneratorDefinition.Builder definitionBuilder) { - definitionBuilder.setName( tableGeneratorAnnotation.getString( "name" ) ); + definitionBuilder.setName( tableGeneratorAnnotation.name() ); definitionBuilder.setStrategy( org.hibernate.id.enhanced.TableGenerator.class.getName() ); definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" ); - final String catalog = tableGeneratorAnnotation.getString( "catalog" ); + final String catalog = tableGeneratorAnnotation.catalog(); if ( StringHelper.isNotEmpty( catalog ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.CATALOG, catalog ); } - final String schema = tableGeneratorAnnotation.getString( "schema" ); + final String schema = tableGeneratorAnnotation.schema(); if ( StringHelper.isNotEmpty( schema ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.SCHEMA, schema ); } - final String table = tableGeneratorAnnotation.getString( "table" ); + final String table = tableGeneratorAnnotation.table(); if ( StringHelper.isNotEmpty( table ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM, table ); } - final String pkColumnName = tableGeneratorAnnotation.getString( "pkColumnName" ); + final String pkColumnName = tableGeneratorAnnotation.pkColumnName(); if ( StringHelper.isNotEmpty( pkColumnName ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM, @@ -115,7 +113,7 @@ public class GenerationStrategyInterpreter { ); } - final String pkColumnValue = tableGeneratorAnnotation.getString( "pkColumnValue" ); + final String pkColumnValue = tableGeneratorAnnotation.pkColumnValue(); if ( StringHelper.isNotEmpty( pkColumnValue ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, @@ -123,7 +121,7 @@ public class GenerationStrategyInterpreter { ); } - final String valueColumnName = tableGeneratorAnnotation.getString( "valueColumnName" ); + final String valueColumnName = tableGeneratorAnnotation.valueColumnName(); if ( StringHelper.isNotEmpty( valueColumnName ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, @@ -131,7 +129,7 @@ public class GenerationStrategyInterpreter { ); } - final String options = tableGeneratorAnnotation.getString( "options" ); + final String options = tableGeneratorAnnotation.options(); if ( StringHelper.isNotEmpty( options ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.OPTIONS, @@ -141,53 +139,53 @@ public class GenerationStrategyInterpreter { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM, - String.valueOf( tableGeneratorAnnotation.getInteger( "allocationSize" ) ) + String.valueOf( tableGeneratorAnnotation.allocationSize() ) ); // See comment on HHH-4884 wrt initialValue. Basically initialValue is really the stated value + 1 definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM, - String.valueOf( tableGeneratorAnnotation.getInteger( "initialValue" ) + 1 ) + String.valueOf( tableGeneratorAnnotation.initialValue() + 1 ) ); // TODO : implement unique-constraint support - final List> uniqueConstraints = tableGeneratorAnnotation.getList( "uniqueConstraints" ); + final UniqueConstraint[] uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); if ( CollectionHelper.isNotEmpty( uniqueConstraints ) ) { - LOG.ignoringTableGeneratorConstraints( tableGeneratorAnnotation.getString( "name" ) ); + LOG.ignoringTableGeneratorConstraints( tableGeneratorAnnotation.name() ); } } public void interpretSequenceGenerator( - AnnotationUsage sequenceGeneratorAnnotation, + SequenceGenerator sequenceGeneratorAnnotation, IdentifierGeneratorDefinition.Builder definitionBuilder) { - definitionBuilder.setName( sequenceGeneratorAnnotation.getString( "name" ) ); + definitionBuilder.setName( sequenceGeneratorAnnotation.name() ); definitionBuilder.setStrategy( SequenceStyleGenerator.class.getName() ); - final String catalog = sequenceGeneratorAnnotation.getString( "catalog" ); + final String catalog = sequenceGeneratorAnnotation.catalog(); if ( StringHelper.isNotEmpty( catalog ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.CATALOG, catalog ); } - final String schema = sequenceGeneratorAnnotation.getString( "schema" ); + final String schema = sequenceGeneratorAnnotation.schema(); if ( StringHelper.isNotEmpty( schema ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.SCHEMA, schema ); } - final String sequenceName = sequenceGeneratorAnnotation.getString( "sequenceName" ); + final String sequenceName = sequenceGeneratorAnnotation.sequenceName(); if ( StringHelper.isNotEmpty( sequenceName ) ) { definitionBuilder.addParam( SequenceStyleGenerator.SEQUENCE_PARAM, sequenceName ); } definitionBuilder.addParam( SequenceStyleGenerator.INCREMENT_PARAM, - String.valueOf( sequenceGeneratorAnnotation.getInteger( "allocationSize" ) ) + String.valueOf( sequenceGeneratorAnnotation.allocationSize() ) ); definitionBuilder.addParam( SequenceStyleGenerator.INITIAL_PARAM, - String.valueOf( sequenceGeneratorAnnotation.getInteger( "initialValue" ) ) + String.valueOf( sequenceGeneratorAnnotation.initialValue() ) ); - final String options = sequenceGeneratorAnnotation.getString( "options" ); + final String options = sequenceGeneratorAnnotation.options(); if ( StringHelper.isNotEmpty( options ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.OPTIONS, options ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index dd510bb376..b49acbfacf 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -62,9 +62,9 @@ import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.model.source.internal.ImplicitColumnNamingSecondPass; import org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext; import org.hibernate.boot.models.categorize.internal.ClassLoaderServiceLoading; -import org.hibernate.boot.models.categorize.internal.GlobalRegistrationsImpl; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor; +import org.hibernate.boot.models.internal.GlobalRegistrationsImpl; +import org.hibernate.boot.models.internal.ModelsHelper; +import org.hibernate.boot.models.spi.GlobalRegistrations; import org.hibernate.boot.models.xml.internal.PersistenceUnitMetadataImpl; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; import org.hibernate.boot.query.NamedHqlQueryDefinition; @@ -107,7 +107,6 @@ import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.mapping.DiscriminatorType; import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.models.internal.SourceModelBuildingContextImpl; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.query.named.NamedObjectRepository; @@ -233,7 +232,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, return new SourceModelBuildingContextImpl( classLoading, bootstrapContext.getJandexView(), - ManagedResourcesProcessor::preFillRegistries + ModelsHelper::preFillRegistries ); } @@ -548,9 +547,9 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, private Map collectionTypeRegistrations; @Override - public void addCollectionTypeRegistration(AnnotationUsage registrationAnnotation) { + public void addCollectionTypeRegistration(CollectionTypeRegistration registrationAnnotation) { addCollectionTypeRegistration( - registrationAnnotation.getEnum( "classification" ), + registrationAnnotation.classification(), toDescriptor( registrationAnnotation ) ); } @@ -572,21 +571,21 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, return collectionTypeRegistrations.get( classification ); } - private CollectionTypeRegistrationDescriptor toDescriptor(AnnotationUsage registrationAnnotation) { + private CollectionTypeRegistrationDescriptor toDescriptor(CollectionTypeRegistration registrationAnnotation) { return new CollectionTypeRegistrationDescriptor( - registrationAnnotation.getClassDetails( "type" ).toJavaClass(), - extractParameters( registrationAnnotation.getList( "parameters" ) ) + registrationAnnotation.type(), + extractParameters( registrationAnnotation.parameters() ) ); } - private Map extractParameters(List> annotationUsages) { + private Map extractParameters(Parameter[] annotationUsages) { if ( CollectionHelper.isEmpty( annotationUsages ) ) { return null; } - final Map result = mapOfSize( annotationUsages.size() ); - for ( AnnotationUsage parameter : annotationUsages ) { - result.put( parameter.getString( "name" ), parameter.getString( "value" ) ); + final Map result = mapOfSize( annotationUsages.length ); + for ( Parameter parameter : annotationUsages ) { + result.put( parameter.name(), parameter.value() ); } return result; } @@ -1369,16 +1368,16 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, } private static AnnotatedClassType getAnnotatedClassType2(ClassDetails classDetails) { - if ( classDetails.hasAnnotationUsage( Entity.class ) ) { + if ( classDetails.hasDirectAnnotationUsage( Entity.class ) ) { return AnnotatedClassType.ENTITY; } - else if ( classDetails.hasAnnotationUsage( Embeddable.class ) ) { + else if ( classDetails.hasDirectAnnotationUsage( Embeddable.class ) ) { return AnnotatedClassType.EMBEDDABLE; } - else if ( classDetails.hasAnnotationUsage( jakarta.persistence.MappedSuperclass.class ) ) { + else if ( classDetails.hasDirectAnnotationUsage( jakarta.persistence.MappedSuperclass.class ) ) { return AnnotatedClassType.MAPPED_SUPERCLASS; } - else if ( classDetails.hasAnnotationUsage( Imported.class ) ) { + else if ( classDetails.hasDirectAnnotationUsage( Imported.class ) ) { return AnnotatedClassType.IMPORTED; } else { @@ -1435,7 +1434,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector, k -> new HashMap<>() ); map.put( - property.getAttributeMember().getAnnotationUsage( MapsId.class ).getString( "value" ), + property.getAttributeMember().getDirectAnnotationUsage( MapsId.class ).value(), property ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedProcedureCallDefinitionImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedProcedureCallDefinitionImpl.java index 6e89ee41a6..21ab2aceab 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedProcedureCallDefinitionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedProcedureCallDefinitionImpl.java @@ -20,8 +20,6 @@ import org.hibernate.boot.query.NamedProcedureCallDefinition; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.procedure.internal.NamedCallableQueryMementoImpl; import org.hibernate.procedure.internal.Util; import org.hibernate.procedure.spi.NamedCallableQueryMemento; @@ -50,15 +48,15 @@ public class NamedProcedureCallDefinitionImpl implements NamedProcedureCallDefin private final ParameterDefinitions parameterDefinitions; private final Map hints; - public NamedProcedureCallDefinitionImpl(AnnotationUsage annotation) { - this.registeredName = annotation.getString( "name" ); - this.procedureName = annotation.getString( "procedureName" ); - this.hints = new QueryHintDefinition( registeredName, annotation.getList( "hints" ) ).getHintsMap(); + public NamedProcedureCallDefinitionImpl(NamedStoredProcedureQuery annotation) { + this.registeredName = annotation.name(); + this.procedureName = annotation.procedureName(); + this.hints = new QueryHintDefinition( registeredName, annotation.hints() ).getHintsMap(); - this.resultClasses = interpretResultClasses( annotation ); - this.resultSetMappings = interpretResultMappings( annotation ); + this.resultClasses = annotation.resultClasses(); + this.resultSetMappings = annotation.resultSetMappings(); - this.parameterDefinitions = new ParameterDefinitions( annotation.getList( "parameters" ) ); + this.parameterDefinitions = new ParameterDefinitions( annotation.parameters() ); final boolean specifiesResultClasses = resultClasses != null && resultClasses.length > 0; final boolean specifiesResultSetMappings = resultSetMappings != null && resultSetMappings.length > 0; @@ -73,30 +71,6 @@ public class NamedProcedureCallDefinitionImpl implements NamedProcedureCallDefin } } - private Class[] interpretResultClasses(AnnotationUsage annotation) { - final List resultClassDetails = annotation.getList( "resultClasses" ); - if ( resultClassDetails == null ) { - return null; - } - final Class[] resultClasses = new Class[resultClassDetails.size()]; - for ( int i = 0; i < resultClassDetails.size(); i++ ) { - resultClasses[i] = resultClassDetails.get( i ).toJavaClass(); - } - return resultClasses; - } - - private String[] interpretResultMappings(AnnotationUsage annotation) { - final List list = annotation.getList( "resultSetMappings" ); - if ( list == null ) { - return null; - } - final String[] strings = new String[list.size()]; - for ( int i = 0; i < list.size(); i++ ) { - strings[i] = list.get( i ); - } - return strings; - } - @Override public String getRegistrationName() { return registeredName; @@ -164,22 +138,22 @@ public class NamedProcedureCallDefinitionImpl implements NamedProcedureCallDefin private final ParameterStrategy parameterStrategy; private final ParameterDefinition[] parameterDefinitions; - ParameterDefinitions(List> parameters) { + ParameterDefinitions(StoredProcedureParameter[] parameters) { if ( CollectionHelper.isEmpty( parameters ) ) { parameterStrategy = ParameterStrategy.POSITIONAL; parameterDefinitions = new ParameterDefinition[0]; } else { - final AnnotationUsage parameterAnn = parameters.get( 0 ); - final boolean firstParameterHasName = StringHelper.isNotEmpty( parameterAnn.findAttributeValue( "name" ) ); + final StoredProcedureParameter parameterAnn = parameters[0]; + final boolean firstParameterHasName = StringHelper.isNotEmpty( parameterAnn.name() ); parameterStrategy = firstParameterHasName ? ParameterStrategy.NAMED : ParameterStrategy.POSITIONAL; - parameterDefinitions = new ParameterDefinition[ parameters.size() ]; + parameterDefinitions = new ParameterDefinition[ parameters.length ]; - for ( int i = 0; i < parameters.size(); i++ ) { + for ( int i = 0; i < parameters.length; i++ ) { // i+1 for the position because the apis say the numbers are 1-based, not zero - parameterDefinitions[i] = new ParameterDefinition<>(i + 1, parameters.get( i )); + parameterDefinitions[i] = new ParameterDefinition<>(i + 1, parameters[i]); } } } @@ -203,11 +177,12 @@ public class NamedProcedureCallDefinitionImpl implements NamedProcedureCallDefin private final ParameterMode parameterMode; private final Class type; - ParameterDefinition(int position, AnnotationUsage annotation) { + ParameterDefinition(int position, StoredProcedureParameter annotation) { this.position = position; - this.name = normalize( annotation.getString( "name" ) ); - this.parameterMode = annotation.getEnum( "mode" ); - this.type = annotation.getClassDetails( "type" ).toJavaClass(); + this.name = normalize( annotation.name() ); + this.parameterMode = annotation.mode(); + //noinspection unchecked + this.type = (Class) annotation.type(); } public ParameterMemento toMemento(SessionFactoryImplementor sessionFactory) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java b/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java index d6f6eb27fe..495ac7d6ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java @@ -16,20 +16,18 @@ import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.Internal; import org.hibernate.boot.internal.GenerationStrategyInterpreter; -import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.SequenceGeneratorJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TableGeneratorJpaAnnotation; import org.hibernate.id.IdentifierGenerator; -import org.hibernate.models.spi.MutableAnnotationUsage; +import org.hibernate.internal.util.StringHelper; import jakarta.persistence.GenerationType; -import jakarta.persistence.SequenceGenerator; -import jakarta.persistence.TableGenerator; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; import static org.hibernate.boot.internal.GenerationStrategyInterpreter.STRATEGY_INTERPRETER; import static org.hibernate.boot.models.JpaAnnotations.SEQUENCE_GENERATOR; import static org.hibernate.boot.models.JpaAnnotations.TABLE_GENERATOR; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified; import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; /** @@ -153,16 +151,20 @@ public class IdentifierGeneratorDefinition implements Serializable { private static IdentifierGeneratorDefinition buildTableGeneratorDefinition(String name) { final Builder builder = new Builder(); - final MutableAnnotationUsage tableGeneratorUsage = TABLE_GENERATOR.createUsage( null ); - tableGeneratorUsage.setAttributeValue( "name", name ); + final TableGeneratorJpaAnnotation tableGeneratorUsage = TABLE_GENERATOR.createUsage( null ); + if ( StringHelper.isNotEmpty( name ) ) { + tableGeneratorUsage.name( name ); + } STRATEGY_INTERPRETER.interpretTableGenerator( tableGeneratorUsage, builder ); return builder.build(); } private static IdentifierGeneratorDefinition buildSequenceGeneratorDefinition(String name) { final Builder builder = new Builder(); - final MutableAnnotationUsage sequenceGeneratorUsage = SEQUENCE_GENERATOR.createUsage( null ); - applyStringAttributeIfSpecified( "name", name, sequenceGeneratorUsage ); + final SequenceGeneratorJpaAnnotation sequenceGeneratorUsage = SEQUENCE_GENERATOR.createUsage( null ); + if ( StringHelper.isNotEmpty( name ) ) { + sequenceGeneratorUsage.name( name ); + } STRATEGY_INTERPRETER.interpretSequenceGenerator( sequenceGeneratorUsage, builder ); return builder.build(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java index 4ff8756b41..489384836c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java @@ -22,16 +22,15 @@ import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource; import org.hibernate.boot.model.source.spi.AttributePath; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.internal.AnnotationUsageHelper; +import org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType; import org.hibernate.usertype.internal.OffsetTimeCompositeUserType; @@ -64,16 +63,16 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { private Boolean isInIdClass; - private Map>> holderColumnOverride; - private Map>> currentPropertyColumnOverride; - private Map> holderColumnTransformerOverride; - private Map> currentPropertyColumnTransformerOverride; - private Map>> holderJoinColumnOverride; - private Map>> currentPropertyJoinColumnOverride; - private Map> holderJoinTableOverride; - private Map> currentPropertyJoinTableOverride; - private Map> holderForeignKeyOverride; - private Map> currentPropertyForeignKeyOverride; + private Map holderColumnOverride; + private Map currentPropertyColumnOverride; + private Map holderColumnTransformerOverride; + private Map currentPropertyColumnTransformerOverride; + private Map holderJoinColumnOverride; + private Map currentPropertyJoinColumnOverride; + private Map holderJoinTableOverride; + private Map currentPropertyJoinTableOverride; + private Map holderForeignKeyOverride; + private Map currentPropertyForeignKeyOverride; AbstractPropertyHolder( String path, @@ -181,6 +180,10 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { return context; } + protected SourceModelBuildingContext getSourceModelContext() { + return getContext().getMetadataCollector().getSourceModelBuildingContext(); + } + /** * Set the property to be processed. property can be null * @@ -202,22 +205,22 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { this.currentPropertyColumnOverride = null; } - this.currentPropertyColumnTransformerOverride = buildColumnTransformerOverride( attributeMember ); + this.currentPropertyColumnTransformerOverride = buildColumnTransformerOverride( attributeMember, context ); if ( this.currentPropertyColumnTransformerOverride.isEmpty() ) { this.currentPropertyColumnTransformerOverride = null; } - this.currentPropertyJoinColumnOverride = buildJoinColumnOverride( attributeMember, getPath() ); + this.currentPropertyJoinColumnOverride = buildJoinColumnOverride( attributeMember, getPath(), context ); if ( this.currentPropertyJoinColumnOverride.isEmpty() ) { this.currentPropertyJoinColumnOverride = null; } - this.currentPropertyJoinTableOverride = buildJoinTableOverride( attributeMember, getPath() ); + this.currentPropertyJoinTableOverride = buildJoinTableOverride( attributeMember, getPath(), context ); if ( this.currentPropertyJoinTableOverride.isEmpty() ) { this.currentPropertyJoinTableOverride = null; } - this.currentPropertyForeignKeyOverride = buildForeignKeyOverride( attributeMember, getPath() ); + this.currentPropertyForeignKeyOverride = buildForeignKeyOverride( attributeMember, getPath(), context ); if ( this.currentPropertyForeignKeyOverride.isEmpty() ) { this.currentPropertyForeignKeyOverride = null; } @@ -231,8 +234,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { * These rules are here to support both JPA 2 and legacy overriding rules. */ @Override - public List> getOverriddenColumn(String propertyName) { - final List> result = getExactOverriddenColumn( propertyName ); + public Column[] getOverriddenColumn(String propertyName) { + final Column[] result = getExactOverriddenColumn( propertyName ); if ( result == null ) { if ( propertyName.contains( ".collection&&element." ) ) { //support for non map collections where no prefix is needed @@ -244,8 +247,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { } @Override - public AnnotationUsage getOverriddenColumnTransformer(String logicalColumnName) { - AnnotationUsage result = null; + public ColumnTransformer getOverriddenColumnTransformer(String logicalColumnName) { + ColumnTransformer result = null; if ( parent != null ) { result = parent.getOverriddenColumnTransformer( logicalColumnName ); } @@ -265,8 +268,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { * Get column overriding, property first, then parent, then holder * find the overridden rules from the exact property name. */ - private List> getExactOverriddenColumn(String propertyName) { - List> result = null; + private Column[] getExactOverriddenColumn(String propertyName) { + Column[] result = null; if ( parent != null ) { result = parent.getExactOverriddenColumn( propertyName ); } @@ -289,8 +292,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { * These rules are here to support both JPA 2 and legacy overriding rules. */ @Override - public List> getOverriddenJoinColumn(String propertyName) { - final List> result = getExactOverriddenJoinColumn( propertyName ); + public JoinColumn[] getOverriddenJoinColumn(String propertyName) { + final JoinColumn[] result = getExactOverriddenJoinColumn( propertyName ); if ( result == null && propertyName.contains( ".collection&&element." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp @@ -302,8 +305,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { /** * Get column overriding, property first, then parent, then holder */ - private List> getExactOverriddenJoinColumn(String propertyName) { - List> result = null; + private JoinColumn[] getExactOverriddenJoinColumn(String propertyName) { + JoinColumn[] result = null; if ( parent != null ) { result = parent.getExactOverriddenJoinColumn( propertyName ); } @@ -320,8 +323,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { } @Override - public AnnotationUsage getOverriddenForeignKey(String propertyName) { - final AnnotationUsage result = getExactOverriddenForeignKey( propertyName ); + public ForeignKey getOverriddenForeignKey(String propertyName) { + final ForeignKey result = getExactOverriddenForeignKey( propertyName ); if ( result == null && propertyName.contains( ".collection&&element." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp @@ -330,8 +333,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { return result; } - private AnnotationUsage getExactOverriddenForeignKey(String propertyName) { - AnnotationUsage result = null; + private ForeignKey getExactOverriddenForeignKey(String propertyName) { + ForeignKey result = null; if ( parent != null ) { result = parent.getExactOverriddenForeignKey( propertyName ); } @@ -351,11 +354,11 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { * These rules are here to support both JPA 2 and legacy overriding rules. */ @Override - public AnnotationUsage getJoinTable(MemberDetails attributeMember) { + public JoinTable getJoinTable(MemberDetails attributeMember) { final String propertyName = qualify( getPath(), attributeMember.getName() ); - final AnnotationUsage result = getOverriddenJoinTable( propertyName ); + final JoinTable result = getOverriddenJoinTable( propertyName ); if ( result == null ) { - return attributeMember.getAnnotationUsage( JoinTable.class ); + return attributeMember.getDirectAnnotationUsage( JoinTable.class ); } return result; } @@ -366,8 +369,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { * * These rules are here to support both JPA 2 and legacy overriding rules. */ - public AnnotationUsage getOverriddenJoinTable(String propertyName) { - final AnnotationUsage result = getExactOverriddenJoinTable( propertyName ); + public JoinTable getOverriddenJoinTable(String propertyName) { + final JoinTable result = getExactOverriddenJoinTable( propertyName ); if ( result == null && propertyName.contains( ".collection&&element." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp @@ -379,8 +382,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { /** * Get column overriding, property first, then parent, then holder */ - private AnnotationUsage getExactOverriddenJoinTable(String propertyName) { - AnnotationUsage override = null; + private JoinTable getExactOverriddenJoinTable(String propertyName) { + JoinTable override = null; if ( parent != null ) { override = parent.getExactOverriddenJoinTable( propertyName ); } @@ -395,21 +398,21 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { private void buildHierarchyColumnOverride(ClassDetails element) { ClassDetails current = element; - Map>> columnOverride = new HashMap<>(); - Map> columnTransformerOverride = new HashMap<>(); - Map>> joinColumnOverride = new HashMap<>(); - Map> joinTableOverride = new HashMap<>(); - Map> foreignKeyOverride = new HashMap<>(); + Map columnOverride = new HashMap<>(); + Map columnTransformerOverride = new HashMap<>(); + Map joinColumnOverride = new HashMap<>(); + Map joinTableOverride = new HashMap<>(); + Map foreignKeyOverride = new HashMap<>(); while ( current != null && !ClassDetails.OBJECT_CLASS_DETAILS.equals( current ) ) { - if ( current.hasAnnotationUsage( Entity.class ) - || current.hasAnnotationUsage( MappedSuperclass.class ) - || current.hasAnnotationUsage( Embeddable.class ) ) { + if ( current.hasDirectAnnotationUsage( Entity.class ) + || current.hasDirectAnnotationUsage( MappedSuperclass.class ) + || current.hasDirectAnnotationUsage( Embeddable.class ) ) { //FIXME is embeddable override? - Map>> currentOverride = buildColumnOverride( current, getPath(), context ); - Map> currentTransformerOverride = buildColumnTransformerOverride( current ); - Map>> currentJoinOverride = buildJoinColumnOverride( current, getPath() ); - Map> currentJoinTableOverride = buildJoinTableOverride( current, getPath() ); - Map> currentForeignKeyOverride = buildForeignKeyOverride( current, getPath() ); + Map currentOverride = buildColumnOverride( current, getPath(), context ); + Map currentTransformerOverride = buildColumnTransformerOverride( current, context ); + Map currentJoinOverride = buildJoinColumnOverride( current, getPath(), context ); + Map currentJoinTableOverride = buildJoinTableOverride( current, getPath(), context ); + Map currentForeignKeyOverride = buildForeignKeyOverride( current, getPath(), context ); currentOverride.putAll( columnOverride ); //subclasses have precedence over superclasses currentTransformerOverride.putAll( columnTransformerOverride ); //subclasses have precedence over superclasses currentJoinOverride.putAll( joinColumnOverride ); //subclasses have precedence over superclasses @@ -431,20 +434,23 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { holderForeignKeyOverride = !foreignKeyOverride.isEmpty() ? foreignKeyOverride : null; } - private static Map>> buildColumnOverride( + private static Map buildColumnOverride( AnnotationTarget element, String path, MetadataBuildingContext context) { - final Map>> columnOverrideMap = new HashMap<>(); + final Map result = new HashMap<>(); if ( element == null ) { - return columnOverrideMap; + return result; } - final List> overrides = element.getRepeatedAnnotationUsages( AttributeOverride.class ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + final Map> columnOverrideMap = new HashMap<>(); + + final AttributeOverride[] overrides = element.getRepeatedAnnotationUsages( AttributeOverride.class, sourceModelContext ); if ( CollectionHelper.isNotEmpty( overrides ) ) { - for ( AnnotationUsage depAttr : overrides ) { - final String qualifiedName = StringHelper.qualify( path, depAttr.getString( "name" ) ); - final AnnotationUsage column = depAttr.getNestedUsage( "column" ); + for ( AttributeOverride depAttr : overrides ) { + final String qualifiedName = StringHelper.qualify( path, depAttr.name() ); + final Column column = depAttr.column(); if ( columnOverrideMap.containsKey( qualifiedName ) ) { // already an entry, just add to that List @@ -452,14 +458,14 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { } else { // not yet an entry, create the list and add - final List> list = new ArrayList<>(); + final List list = new ArrayList<>(); list.add( column ); columnOverrideMap.put( qualifiedName, list ); } } } else if ( useColumnForTimeZoneStorage( element, context ) ) { - final AnnotationUsage column = createTemporalColumn( element, path, context ); + final Column column = createTemporalColumn( element, path, context ); if ( isOffsetTimeClass( element ) ) { columnOverrideMap.put( path + "." + OffsetTimeCompositeUserType.LOCAL_TIME_NAME, @@ -472,55 +478,60 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { List.of( column ) ); } - final AnnotationUsage offsetColumn = createTimeZoneColumn( element, column, context ); + final Column offsetColumn = createTimeZoneColumn( element, column, context ); columnOverrideMap.put( path + "." + AbstractTimeZoneStorageCompositeUserType.ZONE_OFFSET_NAME, List.of( offsetColumn ) ); } - return columnOverrideMap; + + columnOverrideMap.forEach( (name, columns) -> { + result.put( name, columns.toArray(new Column[0]) ); + } ); + return result; } - private static AnnotationUsage createTimeZoneColumn( + private static Column createTimeZoneColumn( AnnotationTarget element, - AnnotationUsage column, + Column column, MetadataBuildingContext context) { - final AnnotationUsage timeZoneColumn = element.getAnnotationUsage( TimeZoneColumn.class ); - final MutableAnnotationUsage created = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); + final TimeZoneColumn timeZoneColumn = element.getDirectAnnotationUsage( TimeZoneColumn.class ); + final ColumnJpaAnnotation created = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); final String columnName = timeZoneColumn != null - ? timeZoneColumn.getString( "name" ) - : column.getString( "name" ) + "_tz"; - created.setAttributeValue( "name", columnName ); - - AnnotationUsageHelper.applyAttributeIfSpecified( "nullable", column.getBoolean( "nullable" ), created ); - - final AnnotationUsage source = timeZoneColumn != null - ? timeZoneColumn - : column; - AnnotationUsageHelper.applyAttributeIfSpecified( "table", source.getString( "table" ), created ); - AnnotationUsageHelper.applyAttributeIfSpecified( "insertable", source.getAttributeValue( "insertable" ), created ); - AnnotationUsageHelper.applyAttributeIfSpecified( "updatable", source.getAttributeValue( "updatable" ), created ); + ? timeZoneColumn.name() + : column.name() + "_tz"; + created.name( columnName ); + created.nullable( column.nullable() ); if ( timeZoneColumn != null ) { - AnnotationUsageHelper.applyStringAttributeIfSpecified( "columnDefinition", timeZoneColumn.getAttributeValue( "columnDefinition" ), created ); + created.table( timeZoneColumn.table() ); + created.insertable( timeZoneColumn.insertable() ); + created.updatable( timeZoneColumn.updatable() ); + created.columnDefinition( timeZoneColumn.columnDefinition() ); + } + else { + created.table( column.table() ); + created.insertable( column.insertable() ); + created.updatable( column.updatable() ); + created.columnDefinition( column.columnDefinition() ); } return created; } - private static AnnotationUsage createTemporalColumn( + private static Column createTemporalColumn( AnnotationTarget element, String path, MetadataBuildingContext context) { int precision; int secondPrecision; - final AnnotationUsage annotatedColumn = element.getAnnotationUsage( Column.class ); + final Column annotatedColumn = element.getDirectAnnotationUsage( Column.class ); if ( annotatedColumn != null ) { - if ( StringHelper.isNotEmpty( annotatedColumn.getString( "name" ) ) ) { + if ( StringHelper.isNotEmpty( annotatedColumn.name() ) ) { return annotatedColumn; } - precision = annotatedColumn.getInteger( "precision" ); - secondPrecision = annotatedColumn.getInteger( "secondPrecision" ); + precision = annotatedColumn.precision(); + secondPrecision = annotatedColumn.secondPrecision(); } else { precision = 0; @@ -551,67 +562,68 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { ) ); - final MutableAnnotationUsage usage = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); - AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", implicitName.getText(), usage ); - usage.setAttributeValue( "precision", precision ); - usage.setAttributeValue( "secondPrecision", secondPrecision ); - return usage; + final ColumnJpaAnnotation created = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); + if ( StringHelper.isNotEmpty( implicitName.getText() ) ) { + created.name( implicitName.getText() ); + } + created.precision( precision ); + created.secondPrecision( secondPrecision ); + return created; } - private static Map> buildColumnTransformerOverride(AnnotationTarget element) { - final Map> columnOverride = new HashMap<>(); + private static Map buildColumnTransformerOverride(AnnotationTarget element, MetadataBuildingContext context) { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + final Map columnOverride = new HashMap<>(); if ( element != null ) { - element.forEachAnnotationUsage( ColumnTransformer.class, (usage) -> { - columnOverride.put( usage.getString( "forColumn" ), usage ); + element.forEachAnnotationUsage( ColumnTransformer.class, sourceModelContext, (usage) -> { + columnOverride.put( usage.forColumn(), usage ); } ); } return columnOverride; } - private static Map>> buildJoinColumnOverride(AnnotationTarget element, String path) { - final Map>> columnOverride = new HashMap<>(); + private static Map buildJoinColumnOverride(AnnotationTarget element, String path, MetadataBuildingContext context) { + final Map columnOverride = new HashMap<>(); if ( element != null ) { - final List> overrides = buildAssociationOverrides( element, path ); - for ( AnnotationUsage override : overrides ) { + final AssociationOverride[] overrides = buildAssociationOverrides( element, path, context ); + for ( AssociationOverride override : overrides ) { columnOverride.put( - qualify( path, override.getString( "name" ) ), - override.getList( "joinColumns" ) + qualify( path, override.name() ), + override.joinColumns() ); } } return columnOverride; } - private static Map> buildForeignKeyOverride(AnnotationTarget element, String path) { - final Map> foreignKeyOverride = new HashMap<>(); + private static Map buildForeignKeyOverride(AnnotationTarget element, String path, MetadataBuildingContext context) { + final Map foreignKeyOverride = new HashMap<>(); if ( element != null ) { - final List> overrides = buildAssociationOverrides( element, path ); - for ( AnnotationUsage override : overrides ) { + final AssociationOverride[] overrides = buildAssociationOverrides( element, path, context ); + for ( AssociationOverride override : overrides ) { foreignKeyOverride.put( - qualify( path, override.getString( "name" ) ), - override.getNestedUsage( "foreignKey" ) + qualify( path, override.name() ), + override.foreignKey() ); } } return foreignKeyOverride; } - private static List> buildAssociationOverrides(AnnotationTarget element, String path) { - final List> overrides = new ArrayList<>(); - element.forEachAnnotationUsage( AssociationOverride.class, overrides::add ); - return overrides; + private static AssociationOverride[] buildAssociationOverrides(AnnotationTarget element, String path, MetadataBuildingContext context) { + return element.getRepeatedAnnotationUsages( AssociationOverride.class, context.getMetadataCollector().getSourceModelBuildingContext() ); } - private static Map> buildJoinTableOverride(AnnotationTarget element, String path) { - final Map> result = new HashMap<>(); + private static Map buildJoinTableOverride(AnnotationTarget element, String path, MetadataBuildingContext context) { + final Map result = new HashMap<>(); if ( element != null ) { - final List> overrides = buildAssociationOverrides( element, path ); - for ( AnnotationUsage override : overrides ) { - final List> joinColumns = override.getList( "joinColumns" ); + final AssociationOverride[] overrides = buildAssociationOverrides( element, path, context ); + for ( AssociationOverride override : overrides ) { + final JoinColumn[] joinColumns = override.joinColumns(); if ( CollectionHelper.isEmpty( joinColumns ) ) { result.put( - qualify( path, override.getString( "name" ) ), - override.getNestedUsage( "joinTable" ) + qualify( path, override.name() ), + override.joinTable() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentBinder.java index 43e384fb49..a9b2ba7822 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentBinder.java @@ -20,7 +20,8 @@ import org.hibernate.boot.spi.PropertyData; import org.hibernate.mapping.AggregateColumn; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Component; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.mapping.Property; +import org.hibernate.mapping.Value; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.TypeDetails; @@ -128,15 +129,16 @@ public final class AggregateComponentBinder { MetadataBuildingContext context) { final MemberDetails property = inferredData.getAttributeMember(); if ( property != null ) { - final AnnotationUsage struct = property.getAnnotationUsage( Struct.class ); + final Struct struct = property.getDirectAnnotationUsage( Struct.class ); if ( struct != null ) { return toQualifiedName( struct, context ); } - final AnnotationUsage jdbcTypeCode = property.getAnnotationUsage( JdbcTypeCode.class ); - if ( jdbcTypeCode != null - && ( jdbcTypeCode.getInteger( "value" ) == SqlTypes.STRUCT - || jdbcTypeCode.getInteger( "value" ) == SqlTypes.STRUCT_ARRAY - || jdbcTypeCode.getInteger( "value" ) == SqlTypes.STRUCT_TABLE ) + + final JdbcTypeCode jdbcTypeCodeAnn = property.getDirectAnnotationUsage( JdbcTypeCode.class ); + if ( jdbcTypeCodeAnn != null + && ( jdbcTypeCodeAnn.value() == SqlTypes.STRUCT + || jdbcTypeCodeAnn.value() == SqlTypes.STRUCT_ARRAY + || jdbcTypeCodeAnn.value() == SqlTypes.STRUCT_TABLE ) && columns != null ) { final List columnList = columns.getColumns(); final String sqlType; @@ -149,11 +151,10 @@ public final class AggregateComponentBinder { null, context.getMetadataCollector().getDatabase().toIdentifier( sqlType ) ); - } - } + } } } - final AnnotationUsage struct = returnedClassOrElement.getAnnotationUsage( Struct.class ); + final Struct struct = returnedClassOrElement.getDirectAnnotationUsage( Struct.class ); if ( struct != null ) { return toQualifiedName( struct, context ); } @@ -161,29 +162,27 @@ public final class AggregateComponentBinder { return null; } - private static QualifiedName toQualifiedName(AnnotationUsage struct, MetadataBuildingContext context) { + private static QualifiedName toQualifiedName(Struct struct, MetadataBuildingContext context) { final Database database = context.getMetadataCollector().getDatabase(); return new QualifiedNameImpl( - database.toIdentifier( struct.getString( "catalog" ) ), - database.toIdentifier( struct.getString( "schema" ) ), - database.toIdentifier( struct.getString( "name" ) ) + database.toIdentifier( struct.catalog() ), + database.toIdentifier( struct.schema() ), + database.toIdentifier( struct.name() ) ); } private static String[] determineStructAttributeNames(PropertyData inferredData, ClassDetails returnedClassOrElement) { final MemberDetails property = inferredData.getAttributeMember(); if ( property != null ) { - final AnnotationUsage struct = property.getAnnotationUsage( Struct.class ); + final Struct struct = property.getDirectAnnotationUsage( Struct.class ); if ( struct != null ) { - final List attributes = struct.getList( "attributes" ); - return attributes.toArray( new String[0] ); + return struct.attributes(); } } - final AnnotationUsage struct = returnedClassOrElement.getAnnotationUsage( Struct.class ); + final Struct struct = returnedClassOrElement.getDirectAnnotationUsage( Struct.class ); if ( struct != null ) { - final List attributes = struct.getList( "attributes" ); - return attributes.toArray( new String[0] ); + return struct.attributes(); } return null; @@ -194,13 +193,13 @@ public final class AggregateComponentBinder { TypeDetails returnedClass, MetadataBuildingContext context) { if ( property != null ) { - if ( property.hasAnnotationUsage( Struct.class ) ) { + if ( property.hasDirectAnnotationUsage( Struct.class ) ) { return true; } - final AnnotationUsage jdbcTypeCode = property.getAnnotationUsage( JdbcTypeCode.class ); + final JdbcTypeCode jdbcTypeCode = property.getDirectAnnotationUsage( JdbcTypeCode.class ); if ( jdbcTypeCode != null ) { - switch ( jdbcTypeCode.getInteger( "value" ) ) { + switch ( jdbcTypeCode.value() ) { case SqlTypes.STRUCT: case SqlTypes.JSON: case SqlTypes.SQLXML: @@ -215,7 +214,7 @@ public final class AggregateComponentBinder { } if ( returnedClass != null ) { - return returnedClass.determineRawClass().hasAnnotationUsage( Struct.class ); + return returnedClass.determineRawClass().hasDirectAnnotationUsage( Struct.class ); } return false; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentSecondPass.java index 40e397c823..f0d7cab2e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AggregateComponentSecondPass.java @@ -35,7 +35,6 @@ import org.hibernate.mapping.ToOne; import org.hibernate.mapping.UserDefinedObjectType; import org.hibernate.mapping.Value; import org.hibernate.metamodel.internal.EmbeddableHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.sql.Template; import org.hibernate.type.SqlTypes; @@ -95,9 +94,9 @@ public class AggregateComponentSecondPass implements SecondPass { structName.getSchemaName() ); final UserDefinedObjectType udt = new UserDefinedObjectType( "orm", namespace, structName.getObjectName() ); - final AnnotationUsage comment = returnedClassOrElement.getAnnotationUsage( Comment.class ); + final Comment comment = returnedClassOrElement.getDirectAnnotationUsage( Comment.class ); if ( comment != null ) { - udt.setComment( comment.getString( "value" ) ); + udt.setComment( comment.value() ); } for ( org.hibernate.mapping.Column aggregatedColumn : aggregatedColumns ) { udt.addColumn( aggregatedColumn ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java index 446fc52a45..d3cb00ba3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java @@ -30,6 +30,7 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.AggregateColumn; import org.hibernate.mapping.CheckConstraint; @@ -39,14 +40,14 @@ import org.hibernate.mapping.Formula; import org.hibernate.mapping.Join; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.MemberDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.jboss.logging.Logger; -import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; import static org.hibernate.boot.model.internal.BinderHelper.getPath; import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath; +import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; import static org.hibernate.internal.util.StringHelper.isEmpty; import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; @@ -501,7 +502,7 @@ public class AnnotatedColumn { } public static AnnotatedColumns buildFormulaFromAnnotation( - AnnotationUsage formulaAnn, + org.hibernate.annotations.Formula formulaAnn, // Comment commentAnn, Nullability nullability, PropertyHolder propertyHolder, @@ -522,7 +523,7 @@ public class AnnotatedColumn { } public static AnnotatedColumns buildColumnFromNoAnnotation( - AnnotationUsage fractionalSeconds, + FractionalSeconds fractionalSeconds, // Comment commentAnn, Nullability nullability, PropertyHolder propertyHolder, @@ -542,8 +543,8 @@ public class AnnotatedColumn { } public static AnnotatedColumns buildColumnFromAnnotation( - AnnotationUsage column, - AnnotationUsage fractionalSeconds, + jakarta.persistence.Column column, + FractionalSeconds fractionalSeconds, // Comment commentAnn, Nullability nullability, PropertyHolder propertyHolder, @@ -564,8 +565,8 @@ public class AnnotatedColumn { } public static AnnotatedColumns buildColumnsFromAnnotations( - List> columns, - AnnotationUsage fractionalSeconds, + jakarta.persistence.Column[] columns, + FractionalSeconds fractionalSeconds, // Comment commentAnn, Nullability nullability, PropertyHolder propertyHolder, @@ -587,7 +588,7 @@ public class AnnotatedColumn { } public static AnnotatedColumns buildColumnsFromAnnotations( - List> columns, + jakarta.persistence.Column[] columns, // Comment commentAnn, Nullability nullability, PropertyHolder propertyHolder, @@ -610,9 +611,9 @@ public class AnnotatedColumn { } public static AnnotatedColumns buildColumnOrFormulaFromAnnotation( - AnnotationUsage column, - AnnotationUsage formulaAnn, - AnnotationUsage fractionalSeconds, + jakarta.persistence.Column column, + org.hibernate.annotations.Formula formulaAnn, + FractionalSeconds fractionalSeconds, // Comment commentAnn, Nullability nullability, PropertyHolder propertyHolder, @@ -620,7 +621,7 @@ public class AnnotatedColumn { Map secondaryTables, MetadataBuildingContext context) { return buildColumnsOrFormulaFromAnnotation( - column==null ? null : List.of( column ), + column==null ? null : new jakarta.persistence.Column[] {column}, formulaAnn, fractionalSeconds, // commentAnn, @@ -634,9 +635,9 @@ public class AnnotatedColumn { } public static AnnotatedColumns buildColumnsOrFormulaFromAnnotation( - List> columns, - AnnotationUsage formulaAnn, - AnnotationUsage fractionalSeconds, + jakarta.persistence.Column[] columns, + org.hibernate.annotations.Formula formulaAnn, + FractionalSeconds fractionalSeconds, // Comment comment, Nullability nullability, PropertyHolder propertyHolder, @@ -652,7 +653,7 @@ public class AnnotatedColumn { parent.setBuildingContext( context ); parent.setJoins( secondaryTables ); //unnecessary final AnnotatedColumn formulaColumn = new AnnotatedColumn(); - formulaColumn.setFormula( formulaAnn.getString( "value" ) ); + formulaColumn.setFormula( formulaAnn.value() ); formulaColumn.setImplicit( false ); // formulaColumn.setBuildingContext( context ); // formulaColumn.setPropertyHolder( propertyHolder ); @@ -661,8 +662,8 @@ public class AnnotatedColumn { return parent; } else { - final List> actualColumns = overrideColumns( columns, propertyHolder, inferredData ); - if ( actualColumns == null ) { + final jakarta.persistence.Column[] actualColumns = overrideColumns( columns, propertyHolder, inferredData ); + if ( ArrayHelper.isEmpty( actualColumns ) ) { return buildImplicitColumn( fractionalSeconds, inferredData, @@ -689,24 +690,24 @@ public class AnnotatedColumn { } } - private static List> overrideColumns( - List> columns, + private static jakarta.persistence.Column[] overrideColumns( + jakarta.persistence.Column[] columns, PropertyHolder propertyHolder, PropertyData inferredData ) { final String path = getPath( propertyHolder, inferredData ); - final List> overriddenCols = propertyHolder.getOverriddenColumn( path ); + final jakarta.persistence.Column[] overriddenCols = propertyHolder.getOverriddenColumn( path ); if ( overriddenCols != null ) { //check for overridden first - if ( columns != null && overriddenCols.size() != columns.size() ) { + if ( columns != null && overriddenCols.length != columns.length ) { //TODO: unfortunately, we never actually see this nice error message, since // PersistentClass.validate() gets called first and produces a worse message throw new AnnotationException( "Property '" + path - + "' specifies " + columns.size() - + " '@AttributeOverride's but the overridden property has " + overriddenCols.size() + + "' specifies " + columns.length + + " '@AttributeOverride's but the overridden property has " + overriddenCols.length + " columns (every column must have exactly one '@AttributeOverride')" ); } LOG.debugf( "Column(s) overridden for property %s", inferredData.getPropertyName() ); - return overriddenCols.isEmpty() ? null : overriddenCols; + return ArrayHelper.isEmpty( overriddenCols ) ? null : overriddenCols; } else { return columns; @@ -720,14 +721,14 @@ public class AnnotatedColumn { String suffixForDefaultColumnName, Map secondaryTables, MetadataBuildingContext context, - List> actualCols, - AnnotationUsage fractionalSeconds) { + jakarta.persistence.Column[] actualCols, + FractionalSeconds fractionalSeconds) { final AnnotatedColumns parent = new AnnotatedColumns(); parent.setPropertyHolder( propertyHolder ); parent.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) ); parent.setJoins( secondaryTables ); parent.setBuildingContext( context ); - for ( AnnotationUsage column : actualCols ) { + for ( jakarta.persistence.Column column : actualCols ) { final Database database = context.getMetadataCollector().getDatabase(); final String sqlType = getSqlType( context, column ); final String tableName = getTableName( column, database ); @@ -742,21 +743,22 @@ public class AnnotatedColumn { inferredData, suffixForDefaultColumnName, parent, - actualCols.size(), + actualCols.length, database, column, fractionalSeconds, sqlType, - tableName + tableName, + context.getMetadataCollector().getSourceModelBuildingContext() ); } return parent; } private static String getTableName( - AnnotationUsage column, + jakarta.persistence.Column column, Database database) { - final String table = column.getString( "table" ); + final String table = column.table(); return table.isEmpty() ? "" : database.getJdbcEnvironment().getIdentifierHelper().toIdentifier( table ).render(); @@ -764,8 +766,8 @@ public class AnnotatedColumn { private static String getSqlType( MetadataBuildingContext context, - AnnotationUsage column) { - final String columnDefinition = column.getString( "columnDefinition" ); + jakarta.persistence.Column column) { + final String columnDefinition = column.columnDefinition(); return columnDefinition.isEmpty() ? null : context.getObjectNameNormalizer().applyGlobalQuoting( columnDefinition ); @@ -779,33 +781,34 @@ public class AnnotatedColumn { AnnotatedColumns parent, int numberOfColumns, Database database, - AnnotationUsage column, - AnnotationUsage fractionalSeconds, + jakarta.persistence.Column column, + FractionalSeconds fractionalSeconds, String sqlType, - String tableName) { + String tableName, + SourceModelBuildingContext sourceModelContext) { final String columnName = logicalColumnName( inferredData, suffixForDefaultColumnName, database, column ); final AnnotatedColumn annotatedColumn = new AnnotatedColumn(); annotatedColumn.setLogicalColumnName( columnName ); annotatedColumn.setImplicit( false ); annotatedColumn.setSqlType( sqlType ); - annotatedColumn.setLength( (long) column.getInteger( "length" ) ); + annotatedColumn.setLength( (long) column.length() ); if ( fractionalSeconds != null ) { - annotatedColumn.setTemporalPrecision( fractionalSeconds.getInteger( "value" ) ); + annotatedColumn.setTemporalPrecision( fractionalSeconds.value() ); } else { - annotatedColumn.setPrecision( column.getInteger( "precision" ) ); + annotatedColumn.setPrecision( column.precision() ); // The passed annotation could also be a MapKeyColumn - Integer secondPrecision = column.getAnnotationType() == jakarta.persistence.Column.class - ? column.getInteger( "secondPrecision" ) + Integer secondPrecision = column.annotationType() == jakarta.persistence.Column.class + ? column.secondPrecision() : null; annotatedColumn.setTemporalPrecision( secondPrecision == null || secondPrecision == -1 ? null : secondPrecision ); } - annotatedColumn.setScale( column.getInteger( "scale" ) ); + annotatedColumn.setScale( column.scale() ); annotatedColumn.handleArrayLength( inferredData ); - annotatedColumn.setNullable( column.getBoolean( "nullable" ) ); - annotatedColumn.setUnique( column.getBoolean( "unique" ) ); - annotatedColumn.setInsertable( column.getBoolean( "insertable" ) ); - annotatedColumn.setUpdatable( column.getBoolean( "updatable" ) ); + annotatedColumn.setNullable( column.nullable() ); + annotatedColumn.setUnique( column.unique() ); + annotatedColumn.setInsertable( column.insertable() ); + annotatedColumn.setUpdatable( column.updatable() ); annotatedColumn.setExplicitTableName( tableName ); annotatedColumn.setParent( parent ); annotatedColumn.applyColumnDefault( inferredData, numberOfColumns ); @@ -813,14 +816,15 @@ public class AnnotatedColumn { annotatedColumn.applyColumnCheckConstraint( column ); annotatedColumn.applyColumnOptions( column ); annotatedColumn.applyCheckConstraint( inferredData, numberOfColumns ); - annotatedColumn.extractDataFromPropertyData( propertyHolder, inferredData ); + annotatedColumn.extractDataFromPropertyData( propertyHolder, inferredData, sourceModelContext ); annotatedColumn.bind(); return annotatedColumn; } private void handleArrayLength(PropertyData inferredData) { - if ( inferredData.getAttributeMember().hasAnnotationUsage( Array.class) ) { - setArrayLength( inferredData.getAttributeMember().getAnnotationUsage( Array.class).getInteger( "length" ) ); + final Array arrayAnn = inferredData.getAttributeMember().getDirectAnnotationUsage( Array.class ); + if ( arrayAnn != null ) { + setArrayLength( arrayAnn.length() ); } } @@ -828,7 +832,7 @@ public class AnnotatedColumn { PropertyData inferredData, String suffixForDefaultColumnName, Database database, - AnnotationUsage column) { + jakarta.persistence.Column column) { final String columnName = getColumnName( database, column ); // NOTE : this is the logical column name, not the physical! return isEmpty( columnName ) && isNotEmpty( suffixForDefaultColumnName ) @@ -836,8 +840,8 @@ public class AnnotatedColumn { : columnName; } - private static String getColumnName(Database database, AnnotationUsage column) { - final String name = column.getString( "name" ); + private static String getColumnName(Database database, jakarta.persistence.Column column) { + final String name = column.name(); return name.isEmpty() ? null : database.getJdbcEnvironment().getIdentifierHelper().toIdentifier( name ).render(); @@ -846,7 +850,7 @@ public class AnnotatedColumn { void applyColumnDefault(PropertyData inferredData, int length) { final MemberDetails attributeMember = inferredData.getAttributeMember(); if ( attributeMember != null ) { - final AnnotationUsage columnDefault = getOverridableAnnotation( + final ColumnDefault columnDefault = getOverridableAnnotation( attributeMember, ColumnDefault.class, getBuildingContext() @@ -856,7 +860,7 @@ public class AnnotatedColumn { throw new AnnotationException( "'@ColumnDefault' may only be applied to single-column mappings but '" + attributeMember.getName() + "' maps to " + length + " columns" ); } - setDefaultValue( columnDefault.getString( "value" ) ); + setDefaultValue( columnDefault.value() ); } } else { @@ -867,7 +871,7 @@ public class AnnotatedColumn { void applyGeneratedAs(PropertyData inferredData, int length) { final MemberDetails attributeMember = inferredData.getAttributeMember(); if ( attributeMember != null ) { - final AnnotationUsage generatedColumn = getOverridableAnnotation( + final GeneratedColumn generatedColumn = getOverridableAnnotation( attributeMember, GeneratedColumn.class, getBuildingContext() @@ -877,7 +881,7 @@ public class AnnotatedColumn { throw new AnnotationException("'@GeneratedColumn' may only be applied to single-column mappings but '" + attributeMember.getName() + "' maps to " + length + " columns" ); } - setGeneratedAs( generatedColumn.getString( "value" ) ); + setGeneratedAs( generatedColumn.value() ); } } else { @@ -885,17 +889,17 @@ public class AnnotatedColumn { } } - private void applyColumnCheckConstraint(AnnotationUsage column) { - applyCheckConstraints( column.findAttributeValue( "check" ) ); + private void applyColumnCheckConstraint(jakarta.persistence.Column column) { + applyCheckConstraints( column.check() ); } - void applyCheckConstraints(List> checkConstraintAnnotationUsages) { + void applyCheckConstraints(jakarta.persistence.CheckConstraint[] checkConstraintAnnotationUsages) { if ( CollectionHelper.isNotEmpty( checkConstraintAnnotationUsages ) ) { - for ( AnnotationUsage checkConstraintAnnotationUsage : checkConstraintAnnotationUsages ) { + for ( jakarta.persistence.CheckConstraint checkConstraintAnnotationUsage : checkConstraintAnnotationUsages ) { addCheckConstraint( - checkConstraintAnnotationUsage.getString( "name" ), - checkConstraintAnnotationUsage.getString( "constraint" ), - checkConstraintAnnotationUsage.getString( "options" ) + checkConstraintAnnotationUsage.name(), + checkConstraintAnnotationUsage.constraint(), + checkConstraintAnnotationUsage.options() ); } } @@ -905,27 +909,21 @@ public class AnnotatedColumn { final MemberDetails attributeMember = inferredData.getAttributeMember(); if ( attributeMember != null ) { // if there are multiple annotations, they're not overrideable - final AnnotationUsage checksAnn = attributeMember.getAnnotationUsage( Checks.class ); + final Checks checksAnn = attributeMember.getDirectAnnotationUsage( Checks.class ); if ( checksAnn != null ) { - final List> checkAnns = checksAnn.getList( "value" ); - for ( AnnotationUsage checkAnn : checkAnns ) { - addCheckConstraint( - checkAnn.getString( "name" ), - checkAnn.getString( "constraints" ) - ); + final Check[] checkAnns = checksAnn.value(); + for ( Check checkAnn : checkAnns ) { + addCheckConstraint( checkAnn.name(), checkAnn.constraints() ); } } else { - final AnnotationUsage checkAnn = getOverridableAnnotation( attributeMember, Check.class, getBuildingContext() ); + final Check checkAnn = getOverridableAnnotation( attributeMember, Check.class, getBuildingContext() ); if ( checkAnn != null ) { if ( length != 1 ) { throw new AnnotationException("'@Check' may only be applied to single-column mappings but '" + attributeMember.getName() + "' maps to " + length + " columns (use a table-level '@Check')" ); } - addCheckConstraint( - nullIfEmpty( checkAnn.getString( "name" ) ), - checkAnn.getString( "constraints" ) - ); + addCheckConstraint( nullIfEmpty( checkAnn.name() ), checkAnn.constraints() ); } } } @@ -935,7 +933,10 @@ public class AnnotatedColumn { } //must only be called after all setters are defined and before binding - private void extractDataFromPropertyData(PropertyHolder propertyHolder, PropertyData inferredData) { + private void extractDataFromPropertyData( + PropertyHolder propertyHolder, + PropertyData inferredData, + SourceModelBuildingContext context) { if ( inferredData != null ) { final MemberDetails attributeMember = inferredData.getAttributeMember(); if ( attributeMember != null ) { @@ -943,27 +944,28 @@ public class AnnotatedColumn { processColumnTransformerExpressions( propertyHolder.getOverriddenColumnTransformer( logicalColumnName ) ); } - attributeMember.forEachAnnotationUsage( ColumnTransformer.class, this::processColumnTransformerExpressions ); + + attributeMember.forEachAnnotationUsage( ColumnTransformer.class, context, this::processColumnTransformerExpressions ); } } } - private void processColumnTransformerExpressions(AnnotationUsage annotation) { + private void processColumnTransformerExpressions(ColumnTransformer annotation) { if ( annotation == null ) { // nothing to process return; } - final String targetColumnName = annotation.getString( "forColumn" ); + final String targetColumnName = annotation.forColumn(); if ( isEmpty( targetColumnName ) || targetColumnName.equals( logicalColumnName != null ? logicalColumnName : "" ) ) { - readExpression = nullIfEmpty( annotation.getString( "read" ) ); - writeExpression = nullIfEmpty( annotation.getString( "write" ) ); + readExpression = nullIfEmpty( annotation.read() ); + writeExpression = nullIfEmpty( annotation.write() ); } } private static AnnotatedColumns buildImplicitColumn( - AnnotationUsage fractionalSeconds, + FractionalSeconds fractionalSeconds, PropertyData inferredData, String suffixForDefaultColumnName, Map secondaryTables, @@ -1001,18 +1003,18 @@ public class AnnotatedColumn { column.applyColumnDefault( inferredData, 1 ); column.applyGeneratedAs( inferredData, 1 ); column.applyCheckConstraint( inferredData, 1 ); - column.extractDataFromPropertyData( propertyHolder, inferredData ); + column.extractDataFromPropertyData( propertyHolder, inferredData, context.getMetadataCollector().getSourceModelBuildingContext() ); column.handleArrayLength( inferredData ); if ( fractionalSeconds != null ) { - column.setTemporalPrecision( fractionalSeconds.getInteger( "value" ) ); + column.setTemporalPrecision( fractionalSeconds.value() ); } column.bind(); return columns; } - public void addIndex(AnnotationUsage index, boolean inSecondPass) { + public void addIndex(Index index, boolean inSecondPass) { if ( index != null ) { - addIndex( index.getString( "name" ), inSecondPass ); + addIndex( index.name(), inSecondPass ); } } @@ -1059,8 +1061,8 @@ public class AnnotatedColumn { return getParent().getBuildingContext(); } - private void applyColumnOptions(AnnotationUsage column) { - options = column.findAttributeValue( "options" ); + private void applyColumnOptions(jakarta.persistence.Column column) { + options = column.options(); } void setOptions(String options){ diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java index e04c76f07e..3a722860c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java @@ -9,7 +9,6 @@ package org.hibernate.boot.model.internal; import org.hibernate.AssertionFailure; import org.hibernate.annotations.DiscriminatorFormula; import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorColumn; @@ -45,9 +44,9 @@ public class AnnotatedDiscriminatorColumn extends AnnotatedColumn { } public static AnnotatedDiscriminatorColumn buildDiscriminatorColumn( - AnnotationUsage discriminatorColumn, - AnnotationUsage discriminatorFormula, - AnnotationUsage columnOverride, + DiscriminatorColumn discriminatorColumn, + DiscriminatorFormula discriminatorFormula, + Column columnOverride, String defaultColumnName, MetadataBuildingContext context) { final AnnotatedColumns parent = new AnnotatedColumns(); @@ -55,36 +54,36 @@ public class AnnotatedDiscriminatorColumn extends AnnotatedColumn { final AnnotatedDiscriminatorColumn column = new AnnotatedDiscriminatorColumn( defaultColumnName ); final DiscriminatorType discriminatorType; if ( discriminatorFormula != null ) { - final DiscriminatorType type = discriminatorFormula.getEnum( "discriminatorType" ); + final DiscriminatorType type = discriminatorFormula.discriminatorType(); if ( type == DiscriminatorType.STRING ) { - discriminatorType = discriminatorColumn == null ? type : discriminatorColumn.getEnum( "discriminatorType" ); + discriminatorType = discriminatorColumn == null ? type : discriminatorColumn.discriminatorType(); } else { discriminatorType = type; } column.setImplicit( false ); - column.setFormula( discriminatorFormula.getString( "value" ) ); + column.setFormula( discriminatorFormula.value() ); } else if ( discriminatorColumn != null ) { - discriminatorType = discriminatorColumn.getEnum( "discriminatorType" ); + discriminatorType = discriminatorColumn.discriminatorType(); column.setImplicit( false ); - if ( !discriminatorColumn.getString( "columnDefinition" ).isEmpty() ) { - column.setSqlType( discriminatorColumn.getString( "columnDefinition" ) ); + if ( !discriminatorColumn.columnDefinition().isEmpty() ) { + column.setSqlType( discriminatorColumn.columnDefinition() ); } - if ( !discriminatorColumn.getString( "name" ).isEmpty() ) { - column.setLogicalColumnName( discriminatorColumn.getString( "name" ) ); + if ( !discriminatorColumn.name().isEmpty() ) { + column.setLogicalColumnName( discriminatorColumn.name() ); } column.setNullable( false ); - column.setOptions( discriminatorColumn.getString( "options" ) ); + column.setOptions( discriminatorColumn.options() ); } else { discriminatorType = DiscriminatorType.STRING; column.setImplicit( true ); } if ( columnOverride != null ) { - column.setLogicalColumnName( columnOverride.getString( "name" ) ); + column.setLogicalColumnName( columnOverride.name() ); - final String columnDefinition = columnOverride.getString( "columnDefinition" ); + final String columnDefinition = columnOverride.columnDefinition(); if ( !columnDefinition.isEmpty() ) { column.setSqlType( columnDefinition ); } @@ -97,8 +96,8 @@ public class AnnotatedDiscriminatorColumn extends AnnotatedColumn { private static void setDiscriminatorType( DiscriminatorType type, - AnnotationUsage discriminatorColumn, - AnnotationUsage columnOverride, + DiscriminatorColumn discriminatorColumn, + Column columnOverride, AnnotatedDiscriminatorColumn column) { if ( type == null ) { column.setDiscriminatorTypeName( "string" ); @@ -117,10 +116,10 @@ public class AnnotatedDiscriminatorColumn extends AnnotatedColumn { case STRING: column.setDiscriminatorTypeName( "string" ); if ( columnOverride != null ) { - column.setLength( (long) columnOverride.getInteger( "length" ) ); + column.setLength( (long) columnOverride.length() ); } else if ( discriminatorColumn != null ) { - column.setLength( (long) discriminatorColumn.getInteger( "length" ) ); + column.setLength( (long) discriminatorColumn.length() ); } break; default: diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java index c06673aeaf..e5dc8fbe19 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java @@ -6,8 +6,6 @@ */ package org.hibernate.boot.model.internal; -import java.util.List; - import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.annotations.JoinFormula; @@ -21,7 +19,6 @@ import org.hibernate.mapping.Column; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Value; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.JoinColumn; import jakarta.persistence.PrimaryKeyJoinColumn; @@ -74,13 +71,13 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { } static AnnotatedJoinColumn buildJoinColumn( - AnnotationUsage joinColumn, + JoinColumn joinColumn, String mappedBy, AnnotatedJoinColumns parent, PropertyHolder propertyHolder, PropertyData inferredData) { final String path = qualify( propertyHolder.getPath(), inferredData.getPropertyName() ); - final List> overrides = propertyHolder.getOverriddenJoinColumn( path ); + final JoinColumn[] overrides = propertyHolder.getOverriddenJoinColumn( path ); if ( overrides != null ) { //TODO: relax this restriction throw new AnnotationException( "Property '" + path @@ -90,11 +87,11 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { } public static AnnotatedJoinColumn buildJoinFormula( - AnnotationUsage joinFormula, + JoinFormula joinFormula, AnnotatedJoinColumns parent) { final AnnotatedJoinColumn formulaColumn = new AnnotatedJoinColumn(); - formulaColumn.setFormula( joinFormula.getString( "value" ) ); - formulaColumn.setReferencedColumn( joinFormula.getString( "referencedColumnName" ) ); + formulaColumn.setFormula( joinFormula.value() ); + formulaColumn.setReferencedColumn( joinFormula.referencedColumnName() ); // formulaColumn.setContext( buildingContext ); // formulaColumn.setPropertyHolder( propertyHolder ); // formulaColumn.setPropertyName( getRelativePath( propertyHolder, propertyName ) ); @@ -105,7 +102,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { } static AnnotatedJoinColumn buildJoinColumn( - AnnotationUsage joinColumn, + JoinColumn joinColumn, // Comment comment, String mappedBy, AnnotatedJoinColumns parent, @@ -126,7 +123,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { } private static AnnotatedJoinColumn explicitJoinColumn( - AnnotationUsage joinColumn, + JoinColumn joinColumn, // Comment comment, AnnotatedJoinColumns parent, PropertyData inferredData, @@ -173,32 +170,32 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { // TODO default name still useful in association table - public void applyJoinAnnotation(AnnotationUsage joinColumn, String defaultName) { + public void applyJoinAnnotation(JoinColumn joinColumn, String defaultName) { if ( joinColumn == null ) { setImplicit( true ); } else { setImplicit( false ); - final String name = joinColumn.getString( "name" ); + final String name = joinColumn.name(); if ( !name.isEmpty() ) { setLogicalColumnName( name ); } - final String columnDefinition = joinColumn.getString( "columnDefinition" ); + final String columnDefinition = joinColumn.columnDefinition(); if ( !columnDefinition.isEmpty() ) { setSqlType( getBuildingContext().getObjectNameNormalizer().applyGlobalQuoting( columnDefinition ) ); } - setNullable( joinColumn.getBoolean( "nullable" ) ); - setUnique( joinColumn.getBoolean( "unique" ) ); - setInsertable( joinColumn.getBoolean( "insertable" ) ); - setUpdatable( joinColumn.getBoolean( "updatable" ) ); - setReferencedColumn( joinColumn.getString( "referencedColumnName" ) ); + setNullable( joinColumn.nullable() ); + setUnique( joinColumn.unique() ); + setInsertable( joinColumn.insertable() ); + setUpdatable( joinColumn.updatable() ); + setReferencedColumn( joinColumn.referencedColumnName() ); applyColumnCheckConstraint( joinColumn ); - setOptions( joinColumn.getString( "options" ) ); + setOptions( joinColumn.options() ); - final String table = joinColumn.getString( "table" ); + final String table = joinColumn.table(); if ( table.isEmpty() ) { setExplicitTableName( "" ); } @@ -217,8 +214,8 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { * Called for {@link jakarta.persistence.InheritanceType#JOINED} entities. */ public static AnnotatedJoinColumn buildInheritanceJoinColumn( - AnnotationUsage primaryKeyJoinColumn, - AnnotationUsage joinColumn, + PrimaryKeyJoinColumn primaryKeyJoinColumn, + JoinColumn joinColumn, Value identifier, AnnotatedJoinColumns parent, MetadataBuildingContext context) { @@ -230,8 +227,8 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { } private static AnnotatedJoinColumn buildExplicitInheritanceJoinColumn( - AnnotationUsage primaryKeyJoinColumn, - AnnotationUsage joinColumn, + PrimaryKeyJoinColumn primaryKeyJoinColumn, + JoinColumn joinColumn, AnnotatedJoinColumns parent, MetadataBuildingContext context, String defaultColumnName) { @@ -240,16 +237,16 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { final String referencedColumnName; final String options; if ( primaryKeyJoinColumn != null ) { - columnName = primaryKeyJoinColumn.getString( "name" ); - columnDefinition = primaryKeyJoinColumn.getString( "columnDefinition" ); - referencedColumnName = primaryKeyJoinColumn.getString( "referencedColumnName" ); - options = primaryKeyJoinColumn.getString( "options" ); + columnName = primaryKeyJoinColumn.name(); + columnDefinition = primaryKeyJoinColumn.columnDefinition(); + referencedColumnName = primaryKeyJoinColumn.referencedColumnName(); + options = primaryKeyJoinColumn.options(); } else { - columnName = joinColumn.getString( "name" ); - columnDefinition = joinColumn.getString( "columnDefinition" ); - referencedColumnName = joinColumn.getString( "referencedColumnName" ); - options = joinColumn.getString( "options" ); + columnName = joinColumn.name(); + columnDefinition = joinColumn.columnDefinition(); + referencedColumnName = joinColumn.referencedColumnName(); + options = joinColumn.options(); } final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer(); @@ -474,7 +471,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { AnnotatedJoinColumns parent, PropertyHolder propertyHolder, PropertyData inferredData, - AnnotationUsage joinColumn) { + JoinColumn joinColumn) { final AnnotatedJoinColumn column = new AnnotatedJoinColumn(); column.setImplicit( true ); // column.setPropertyHolder( propertyHolder ); @@ -523,7 +520,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { super.setParent( parent ); } - private void applyColumnCheckConstraint(AnnotationUsage column) { - applyCheckConstraints( column.findAttributeValue( "check" ) ); + private void applyColumnCheckConstraint(jakarta.persistence.JoinColumn column) { + applyCheckConstraints( column.check() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java index 50d29b1f62..73b692f863 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java @@ -29,7 +29,7 @@ import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.PropertyData; import org.hibernate.cfg.RecoverableException; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Column; import org.hibernate.mapping.Component; import org.hibernate.mapping.Join; @@ -39,7 +39,6 @@ import org.hibernate.mapping.Property; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.JoinColumn; @@ -77,7 +76,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { private String manyToManyOwnerSideEntityName; public static AnnotatedJoinColumns buildJoinColumnsOrFormulas( - List> joinColumnOrFormulas, + JoinColumnOrFormula[] joinColumnOrFormulas, String mappedBy, Map joins, PropertyHolder propertyHolder, @@ -89,10 +88,10 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { parent.setPropertyHolder( propertyHolder ); parent.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) ); parent.setMappedBy( mappedBy ); - for ( AnnotationUsage columnOrFormula : joinColumnOrFormulas ) { - final AnnotationUsage formula = columnOrFormula.getNestedUsage( "formula" ); - final AnnotationUsage column = columnOrFormula.getNestedUsage( "column" ); - final String annotationString = formula.getString( "value" ); + for ( JoinColumnOrFormula columnOrFormula : joinColumnOrFormulas ) { + final JoinFormula formula = columnOrFormula.formula(); + final JoinColumn column = columnOrFormula.column(); + final String annotationString = formula.value(); if ( isNotEmpty( annotationString ) ) { AnnotatedJoinColumn.buildJoinFormula( formula, parent ); } @@ -104,7 +103,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { } static AnnotatedJoinColumns buildJoinColumnsWithFormula( - AnnotationUsage joinFormula, + JoinFormula joinFormula, Map secondaryTables, PropertyHolder propertyHolder, PropertyData inferredData, @@ -119,7 +118,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { } public static AnnotatedJoinColumns buildJoinColumns( - List> joinColumns, + JoinColumn[] joinColumns, // Comment comment, String mappedBy, Map joins, @@ -139,7 +138,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { } public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix( - List> joinColumns, + JoinColumn[] joinColumns, // Comment comment, String mappedBy, Map joins, @@ -150,15 +149,15 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { assert mappedBy == null || !mappedBy.isEmpty(); final String propertyName = inferredData.getPropertyName(); final String path = qualify( propertyHolder.getPath(), propertyName ); - final List> overrides = propertyHolder.getOverriddenJoinColumn( path ); - final List> actualColumns = overrides == null ? joinColumns : overrides; + final JoinColumn[] overrides = propertyHolder.getOverriddenJoinColumn( path ); + final JoinColumn[] actualColumns = overrides == null ? joinColumns : overrides; final AnnotatedJoinColumns parent = new AnnotatedJoinColumns(); parent.setBuildingContext( context ); parent.setJoins( joins ); parent.setPropertyHolder( propertyHolder ); parent.setPropertyName( getRelativePath( propertyHolder, propertyName ) ); parent.setMappedBy( mappedBy ); - if ( CollectionHelper.isEmpty( actualColumns ) ) { + if ( ArrayHelper.isEmpty( actualColumns ) ) { AnnotatedJoinColumn.buildJoinColumn( null, // comment, @@ -171,7 +170,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { } else { parent.setMappedBy( mappedBy ); - for ( AnnotationUsage actualColumn : actualColumns ) { + for ( JoinColumn actualColumn : actualColumns ) { AnnotatedJoinColumn.buildJoinColumn( actualColumn, // comment, @@ -190,7 +189,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { * Called for join tables in {@link jakarta.persistence.ManyToMany} associations. */ public static AnnotatedJoinColumns buildJoinTableJoinColumns( - List> joinColumns, + JoinColumn[] joinColumns, Map secondaryTables, PropertyHolder propertyHolder, PropertyData inferredData, @@ -206,7 +205,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { AnnotatedJoinColumn.buildImplicitJoinTableJoinColumn( parent, propertyHolder, inferredData ); } else { - for ( AnnotationUsage joinColumn : joinColumns ) { + for ( JoinColumn joinColumn : joinColumns ) { AnnotatedJoinColumn.buildExplicitJoinTableJoinColumn( parent, propertyHolder, inferredData, joinColumn ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java index 686dc57ede..d2374042a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java @@ -27,14 +27,15 @@ import org.hibernate.annotations.TypeRegistration; import org.hibernate.boot.internal.GenerationStrategyInterpreter; import org.hibernate.boot.model.IdentifierGeneratorDefinition; import org.hibernate.boot.model.convert.spi.RegisteredConversion; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.spi.GlobalRegistrations; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.type.descriptor.java.BasicJavaType; @@ -45,11 +46,7 @@ import jakarta.persistence.FetchType; import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.MappedSuperclass; -import jakarta.persistence.NamedNativeQuery; -import jakarta.persistence.NamedQuery; -import jakarta.persistence.NamedStoredProcedureQuery; import jakarta.persistence.SequenceGenerator; -import jakarta.persistence.SqlResultSetMapping; import jakarta.persistence.Table; import jakarta.persistence.TableGenerator; @@ -58,8 +55,6 @@ import static org.hibernate.boot.model.internal.AnnotatedClassType.ENTITY; import static org.hibernate.boot.model.internal.FilterDefBinder.bindFilterDefs; import static org.hibernate.boot.model.internal.GeneratorBinder.buildGenerators; import static org.hibernate.boot.model.internal.GeneratorBinder.buildIdGenerator; -import static org.hibernate.boot.model.internal.GeneratorBinder.buildSequenceIdGenerator; -import static org.hibernate.boot.model.internal.GeneratorBinder.buildTableIdGenerator; import static org.hibernate.boot.model.internal.InheritanceState.getInheritanceStateOfSuperEntity; import static org.hibernate.boot.model.internal.InheritanceState.getSuperclassInheritanceState; import static org.hibernate.internal.CoreLogging.messageLogger; @@ -157,16 +152,18 @@ public final class AnnotationBinder { } private static void handleIdGenerators(ClassDetails packageInfoClassDetails, MetadataBuildingContext context) { - packageInfoClassDetails.forEachAnnotationUsage( SequenceGenerator.class, usage -> { - IdentifierGeneratorDefinition idGen = buildSequenceIdGenerator( usage ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + + packageInfoClassDetails.forEachAnnotationUsage( SequenceGenerator.class, sourceModelContext, (usage) -> { + IdentifierGeneratorDefinition idGen = buildIdGenerator( usage, context ); context.getMetadataCollector().addIdentifierGenerator( idGen ); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Add sequence generator with name: {0}", idGen.getName() ); } } ); - packageInfoClassDetails.forEachAnnotationUsage( TableGenerator.class, usage -> { - IdentifierGeneratorDefinition idGen = buildTableIdGenerator( usage ); + packageInfoClassDetails.forEachAnnotationUsage( TableGenerator.class, sourceModelContext, (usage) -> { + IdentifierGeneratorDefinition idGen = buildIdGenerator( usage, context ); context.getMetadataCollector().addIdentifierGenerator( idGen ); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Add table generator with name: {0}", idGen.getName() ); @@ -175,13 +172,15 @@ public final class AnnotationBinder { } private static void bindGenericGenerators(AnnotationTarget annotatedElement, MetadataBuildingContext context) { - annotatedElement.forEachAnnotationUsage( GenericGenerator.class, usage -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + + annotatedElement.forEachAnnotationUsage( GenericGenerator.class, sourceModelContext, (usage) -> { bindGenericGenerator( usage, context ); } ); } - private static void bindGenericGenerator(AnnotationUsage def, MetadataBuildingContext context) { - context.getMetadataCollector().addIdentifierGenerator( buildIdGenerator( def ) ); + private static void bindGenericGenerator(GenericGenerator def, MetadataBuildingContext context) { + context.getMetadataCollector().addIdentifierGenerator( buildIdGenerator( def, context ) ); } public static void bindQueries(AnnotationTarget annotationTarget, MetadataBuildingContext context) { @@ -190,41 +189,47 @@ public final class AnnotationBinder { } private static void bindNamedHibernateQueries(AnnotationTarget annotationTarget, MetadataBuildingContext context) { - annotationTarget.forEachAnnotationUsage( org.hibernate.annotations.NamedQuery.class, (usage) -> QueryBinder.bindQuery( - usage, - context - ) ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); - annotationTarget.forEachAnnotationUsage( org.hibernate.annotations.NamedNativeQuery.class, (usage) -> QueryBinder.bindNativeQuery( - usage, - context - ) ); + annotationTarget.forEachRepeatedAnnotationUsages( + HibernateAnnotations.NAMED_QUERY, + sourceModelContext, + (usage) -> QueryBinder.bindQuery( usage, context ) + ); + + annotationTarget.forEachRepeatedAnnotationUsages( + HibernateAnnotations.NAMED_NATIVE_QUERY, + sourceModelContext, + (usage) -> QueryBinder.bindNativeQuery( usage, context ) + ); } private static void bindNamedJpaQueries(AnnotationTarget annotationTarget, MetadataBuildingContext context) { - annotationTarget.forEachAnnotationUsage( SqlResultSetMapping.class, (usage) -> QueryBinder.bindSqlResultSetMapping( - usage, - context, - false - ) ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); - annotationTarget.forEachAnnotationUsage( NamedQuery.class, (usage) -> QueryBinder.bindQuery( - usage, - context, - false - ) ); + annotationTarget.forEachRepeatedAnnotationUsages( + JpaAnnotations.SQL_RESULT_SET_MAPPING, + sourceModelContext, + (usage) -> QueryBinder.bindSqlResultSetMapping( usage, context,false ) + ); - annotationTarget.forEachAnnotationUsage( NamedNativeQuery.class, (usage) -> QueryBinder.bindNativeQuery( - usage, - context, - false - ) ); + annotationTarget.forEachRepeatedAnnotationUsages( + JpaAnnotations.NAMED_QUERY, + sourceModelContext, + (usage) -> QueryBinder.bindQuery( usage, context, false ) + ); - annotationTarget.forEachAnnotationUsage( NamedStoredProcedureQuery.class, (usage) -> QueryBinder.bindNamedStoredProcedureQuery( - usage, - context, - false - ) ); + annotationTarget.forEachRepeatedAnnotationUsages( + JpaAnnotations.NAMED_NATIVE_QUERY, + sourceModelContext, + (usage) -> QueryBinder.bindNativeQuery( usage, context, false ) + ); + + annotationTarget.forEachRepeatedAnnotationUsages( + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + sourceModelContext, + (usage) -> QueryBinder.bindNamedStoredProcedureQuery( usage, context, false ) + ); } /** @@ -259,26 +264,26 @@ public final class AnnotationBinder { } private static void handleImport(ClassDetails annotatedClass, MetadataBuildingContext context) { - if ( annotatedClass.hasAnnotationUsage( Imported.class ) ) { + if ( annotatedClass.hasDirectAnnotationUsage( Imported.class ) ) { final String qualifiedName = annotatedClass.getName(); final String name = unqualify( qualifiedName ); - final String rename = annotatedClass.getAnnotationUsage( Imported.class ).getString( "rename" ); + final String rename = annotatedClass.getDirectAnnotationUsage( Imported.class ).rename(); context.getMetadataCollector().addImport( rename.isEmpty() ? name : rename, qualifiedName ); } } private static void detectMappedSuperclassProblems(ClassDetails annotatedClass) { - if ( annotatedClass.hasAnnotationUsage( MappedSuperclass.class ) ) { + if ( annotatedClass.hasDirectAnnotationUsage( MappedSuperclass.class ) ) { //@Entity and @MappedSuperclass on the same class leads to a NPE down the road - if ( annotatedClass.hasAnnotationUsage( Entity.class ) ) { + if ( annotatedClass.hasDirectAnnotationUsage( Entity.class ) ) { throw new AnnotationException( "Type '" + annotatedClass.getName() + "' is annotated both '@Entity' and '@MappedSuperclass'" ); } - if ( annotatedClass.hasAnnotationUsage( Table.class ) ) { + if ( annotatedClass.hasDirectAnnotationUsage( Table.class ) ) { throw new AnnotationException( "Mapped superclass '" + annotatedClass.getName() + "' may not specify a '@Table'" ); } - if ( annotatedClass.hasAnnotationUsage( Inheritance.class ) ) { + if ( annotatedClass.hasDirectAnnotationUsage( Inheritance.class ) ) { throw new AnnotationException( "Mapped superclass '" + annotatedClass.getName() + "' may not specify an '@Inheritance' mapping strategy" ); } @@ -292,15 +297,16 @@ public final class AnnotationBinder { .getServiceRegistry() .getService( ManagedBeanRegistry.class ); - annotatedElement.forEachAnnotationUsage( JavaTypeRegistration.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + annotatedElement.forEachAnnotationUsage( JavaTypeRegistration.class, sourceModelContext, (usage) -> { handleJavaTypeRegistration( context, managedBeanRegistry, usage ); } ); - annotatedElement.forEachAnnotationUsage( JdbcTypeRegistration.class, (usage) -> { + annotatedElement.forEachAnnotationUsage( JdbcTypeRegistration.class, sourceModelContext, (usage) -> { handleJdbcTypeRegistration( context, managedBeanRegistry, usage ); } ); - annotatedElement.forEachAnnotationUsage( CollectionTypeRegistration.class, (usage) -> { + annotatedElement.forEachAnnotationUsage( CollectionTypeRegistration.class, sourceModelContext, (usage) -> { context.getMetadataCollector().addCollectionTypeRegistration( usage ); } ); } @@ -308,12 +314,12 @@ public final class AnnotationBinder { private static void handleJdbcTypeRegistration( MetadataBuildingContext context, ManagedBeanRegistry managedBeanRegistry, - AnnotationUsage annotation) { - final Class jdbcTypeClass = annotation.getClassDetails( "value" ).toJavaClass(); + JdbcTypeRegistration annotation) { + final Class jdbcTypeClass = annotation.value(); final JdbcType jdbcType = !context.getBuildingOptions().isAllowExtensionsInCdi() ? FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ) : managedBeanRegistry.getBean( jdbcTypeClass ).getBeanInstance(); - final Integer registrationCode = annotation.getInteger( "registrationCode" ); + final int registrationCode = annotation.registrationCode(); final int typeCode = registrationCode == Integer.MIN_VALUE ? jdbcType.getDefaultSqlTypeCode() : registrationCode; @@ -323,13 +329,13 @@ public final class AnnotationBinder { private static void handleJavaTypeRegistration( MetadataBuildingContext context, ManagedBeanRegistry managedBeanRegistry, - AnnotationUsage annotation) { - final Class> javaTypeClass = annotation.getClassDetails( "descriptorClass" ).toJavaClass(); + JavaTypeRegistration annotation) { + final Class> javaTypeClass = annotation.descriptorClass(); final BasicJavaType javaType = !context.getBuildingOptions().isAllowExtensionsInCdi() ? FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ) : managedBeanRegistry.getBean( javaTypeClass ).getBeanInstance(); context.getMetadataCollector().addJavaTypeRegistration( - annotation.getClassDetails( "javaType" ).toJavaClass(), + annotation.javaType(), javaType ); } @@ -337,24 +343,27 @@ public final class AnnotationBinder { private static void bindEmbeddableInstantiatorRegistrations( AnnotationTarget annotatedElement, MetadataBuildingContext context) { - annotatedElement.forEachAnnotationUsage( EmbeddableInstantiatorRegistration.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + annotatedElement.forEachAnnotationUsage( EmbeddableInstantiatorRegistration.class, sourceModelContext, (usage) -> { handleEmbeddableInstantiatorRegistration( context, usage ); } ); } private static void handleEmbeddableInstantiatorRegistration( MetadataBuildingContext context, - AnnotationUsage annotation) { + EmbeddableInstantiatorRegistration annotation) { context.getMetadataCollector().registerEmbeddableInstantiator( - annotation.getClassDetails( "embeddableClass" ).toJavaClass(), - annotation.getClassDetails( "instantiator" ).toJavaClass() + annotation.embeddableClass(), + annotation.instantiator() ); } private static void bindCompositeUserTypeRegistrations( AnnotationTarget annotatedElement, MetadataBuildingContext context) { - annotatedElement.forEachAnnotationUsage( CompositeTypeRegistration.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + + annotatedElement.forEachAnnotationUsage( CompositeTypeRegistration.class, sourceModelContext, (usage) -> { handleCompositeUserTypeRegistration( context, usage ); } ); } @@ -362,44 +371,46 @@ public final class AnnotationBinder { private static void bindUserTypeRegistrations( AnnotationTarget annotatedElement, MetadataBuildingContext context) { - annotatedElement.forEachAnnotationUsage( TypeRegistration.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + annotatedElement.forEachAnnotationUsage( TypeRegistration.class, sourceModelContext, (usage) -> { handleUserTypeRegistration( context, usage ); } ); } private static void handleUserTypeRegistration( MetadataBuildingContext context, - AnnotationUsage compositeTypeRegistration) { + TypeRegistration compositeTypeRegistration) { // TODO: check that the two classes agree, i.e. that // the user type knows how to handle the type context.getMetadataCollector().registerUserType( - compositeTypeRegistration.getClassDetails( "basicClass" ).toJavaClass(), - compositeTypeRegistration.getClassDetails( "userType" ).toJavaClass() + compositeTypeRegistration.basicClass(), + compositeTypeRegistration.userType() ); } private static void handleCompositeUserTypeRegistration( MetadataBuildingContext context, - AnnotationUsage compositeTypeRegistration) { + CompositeTypeRegistration compositeTypeRegistration) { // TODO: check that the two classes agree, i.e. that // the user type knows how to handle the type context.getMetadataCollector().registerCompositeUserType( - compositeTypeRegistration.getClassDetails( "embeddableClass" ).toJavaClass(), - compositeTypeRegistration.getClassDetails( "userType" ).toJavaClass() + compositeTypeRegistration.embeddableClass(), + compositeTypeRegistration.userType() ); } private static void bindConverterRegistrations(AnnotationTarget container, MetadataBuildingContext context) { - container.forEachAnnotationUsage( ConverterRegistration.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + container.forEachAnnotationUsage( ConverterRegistration.class, sourceModelContext, (usage) -> { handleConverterRegistration( usage, context ); } ); } - private static void handleConverterRegistration(AnnotationUsage registration, MetadataBuildingContext context) { + private static void handleConverterRegistration(ConverterRegistration registration, MetadataBuildingContext context) { context.getMetadataCollector().getConverterRegistry().addRegisteredConversion( new RegisteredConversion( - registration.getClassDetails( "domainType" ).toJavaClass(), - registration.getClassDetails( "converter" ).toJavaClass(), - registration.getBoolean( "autoApply" ), + registration.domainType(), + registration.converter(), + registration.autoApply(), context ) ); } @@ -419,18 +430,19 @@ public final class AnnotationBinder { } private static void bindFetchProfiles(AnnotationTarget annotatedElement, MetadataBuildingContext context) { - annotatedElement.forEachAnnotationUsage( FetchProfile.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + annotatedElement.forEachAnnotationUsage( FetchProfile.class, sourceModelContext, (usage) -> { bindFetchProfile( usage, context ); } ); } - private static void bindFetchProfile(AnnotationUsage fetchProfile, MetadataBuildingContext context) { - final String name = fetchProfile.getString( "name" ); + private static void bindFetchProfile(FetchProfile fetchProfile, MetadataBuildingContext context) { + final String name = fetchProfile.name(); if ( reuseOrCreateFetchProfile( context, name ) ) { - final List> fetchOverrides = fetchProfile.getList( "fetchOverrides" ); - for ( AnnotationUsage fetchOverride : fetchOverrides ) { - final FetchType type = fetchOverride.getEnum( "fetch" ); - final FetchMode mode = fetchOverride.getEnum( "mode" ); + final FetchOverride[] fetchOverrides = fetchProfile.fetchOverrides(); + for ( FetchOverride fetchOverride : fetchOverrides ) { + final FetchType type = fetchOverride.fetch(); + final FetchMode mode = fetchOverride.mode(); if ( type == FetchType.LAZY && mode == FetchMode.JOIN ) { throw new AnnotationException( "Fetch profile '" + name @@ -476,7 +488,7 @@ public final class AnnotationBinder { final InheritanceState superclassState = getSuperclassInheritanceState( clazz, inheritanceStatePerClass ); final InheritanceState state = new InheritanceState( clazz, inheritanceStatePerClass, buildingContext ); final AnnotatedClassType classType = buildingContext.getMetadataCollector().getClassType( clazz ); - if ( classType == EMBEDDABLE && !clazz.hasAnnotationUsage( Imported.class ) ) { + if ( classType == EMBEDDABLE && !clazz.hasDirectAnnotationUsage( Imported.class ) ) { final String className = clazz.getName(); buildingContext.getMetadataCollector().addImport( unqualify( className ), className ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationHelper.java index 5532539097..0b39af21e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationHelper.java @@ -8,7 +8,6 @@ package org.hibernate.boot.model.internal; import java.lang.reflect.ParameterizedType; import java.util.HashMap; -import java.util.List; import org.hibernate.annotations.Parameter; import org.hibernate.boot.model.convert.spi.ConverterDescriptor; @@ -16,7 +15,6 @@ import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.Dialect; import org.hibernate.metamodel.mapping.JdbcMapping; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; @@ -41,11 +39,11 @@ import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize * @author Steve Ebersole */ public class AnnotationHelper { - public static HashMap extractParameterMap(List> parameters) { - final HashMap paramMap = mapOfSize( parameters.size() ); - parameters.forEach( (usage) -> { - paramMap.put( usage.getString( "name" ), usage.getString( "value" ) ); - } ); + public static HashMap extractParameterMap(Parameter[] parameters) { + final HashMap paramMap = mapOfSize( parameters.length ); + for ( int i = 0; i < parameters.length; i++ ) { + paramMap.put( parameters[i].name(), parameters[i].value() ); + } return paramMap; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnyBinder.java index aa926788ed..70d3660b52 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnyBinder.java @@ -20,7 +20,6 @@ import org.hibernate.boot.spi.PropertyData; import org.hibernate.mapping.Any; import org.hibernate.mapping.Join; import org.hibernate.mapping.Property; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.MemberDetails; import jakarta.persistence.Column; @@ -44,7 +43,7 @@ public class AnyBinder { AnnotatedJoinColumns joinColumns) { //check validity - if ( property.hasAnnotationUsage( Columns.class ) ) { + if ( property.hasDirectAnnotationUsage( Columns.class ) ) { throw new AnnotationException( String.format( Locale.ROOT, @@ -55,9 +54,9 @@ public class AnyBinder { ); } - final AnnotationUsage hibernateCascade = property.getAnnotationUsage( Cascade.class ); - final AnnotationUsage onDeleteAnn = property.getAnnotationUsage( OnDelete.class ); - final AnnotationUsage assocTable = propertyHolder.getJoinTable( property ); + final Cascade hibernateCascade = property.getDirectAnnotationUsage( Cascade.class ); + final OnDelete onDeleteAnn = property.getDirectAnnotationUsage( OnDelete.class ); + final JoinTable assocTable = propertyHolder.getJoinTable( property ); if ( assocTable != null ) { final Join join = propertyHolder.addJoin( assocTable, false ); for ( AnnotatedJoinColumn joinColumn : joinColumns.getJoinColumns() ) { @@ -68,7 +67,7 @@ public class AnyBinder { getCascadeStrategy( null, hibernateCascade, false, context ), //@Any has no cascade attribute joinColumns, - onDeleteAnn == null ? null : onDeleteAnn.getEnum( "action" ), + onDeleteAnn == null ? null : onDeleteAnn.action(), nullability, propertyHolder, inferredData, @@ -89,15 +88,15 @@ public class AnyBinder { boolean isIdentifierMapper, MetadataBuildingContext context) { final MemberDetails property = inferredData.getAttributeMember(); - final AnnotationUsage any = property.getAnnotationUsage( org.hibernate.annotations.Any.class ); + final org.hibernate.annotations.Any any = property.getDirectAnnotationUsage( org.hibernate.annotations.Any.class ); if ( any == null ) { throw new AssertionFailure( "Missing @Any annotation: " + getPath( propertyHolder, inferredData ) ); } - final boolean lazy = any.getEnum( "fetch" ) == FetchType.LAZY; - final boolean optional = any.getBoolean( "optional" ); + final boolean lazy = any.fetch() == FetchType.LAZY; + final boolean optional = any.optional(); final Any value = BinderHelper.buildAnyValue( - property.getAnnotationUsage( Column.class ), + property.getDirectAnnotationUsage( Column.class ), getOverridableAnnotation( property, Formula.class, context ), columns, inferredData, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AttributeConversionInfo.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AttributeConversionInfo.java index f8d0c4364e..9c585bd0e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AttributeConversionInfo.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AttributeConversionInfo.java @@ -7,8 +7,6 @@ package org.hibernate.boot.model.internal; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.MemberDetails; import jakarta.persistence.AttributeConverter; import jakarta.persistence.Convert; @@ -40,11 +38,11 @@ public class AttributeConversionInfo { this.source = source; } - public AttributeConversionInfo(AnnotationUsage convertAnnotation, AnnotationTarget source) { + public AttributeConversionInfo(Convert convertAnnotation, AnnotationTarget source) { this( - convertAnnotation.getClassDetails( "converter" ).toJavaClass(), - convertAnnotation.getBoolean( "disableConversion" ), - convertAnnotation.getString( "attributeName" ), + convertAnnotation.converter(), + convertAnnotation.disableConversion(), + convertAnnotation.attributeName(), source ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java index 2f7d0432c0..22e9605e3d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java @@ -60,10 +60,10 @@ import org.hibernate.internal.util.ReflectHelper; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Component; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.ParameterizedTypeDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer; import org.hibernate.resource.beans.spi.ManagedBean; @@ -184,6 +184,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { this.buildingContext = buildingContext; } + protected SourceModelBuildingContext getSourceModelContext() { + return buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + } @Override public TypeConfiguration getTypeConfiguration() { @@ -348,19 +351,19 @@ public class BasicValueBinder implements JdbcTypeIndicators { : typeDetails; if ( kind != Kind.LIST_INDEX && kind != Kind.MAP_KEY ) { - isLob = valueMember.hasAnnotationUsage( Lob.class ); + isLob = valueMember.hasDirectAnnotationUsage( Lob.class ); } if ( getDialect().getNationalizationSupport() == NationalizationSupport.EXPLICIT ) { isNationalized = buildingContext.getBuildingOptions().useNationalizedCharacterData() - || valueMember.locateAnnotationUsage( Nationalized.class ) != null; + || valueMember.locateAnnotationUsage( Nationalized.class, getSourceModelContext() ) != null; } applyJpaConverter( valueMember, converterDescriptor ); - final Class> userTypeImpl = kind.mappingAccess.customType( valueMember ); + final Class> userTypeImpl = kind.mappingAccess.customType( valueMember, getSourceModelContext() ); if ( userTypeImpl != null ) { - applyExplicitType( userTypeImpl, kind.mappingAccess.customTypeParameters( valueMember ) ); + applyExplicitType( userTypeImpl, kind.mappingAccess.customTypeParameters( valueMember, getSourceModelContext() ) ); // An explicit custom UserType has top precedence when we get to BasicValue resolution. return; @@ -418,7 +421,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { } private void prepareCollectionId(MemberDetails attributeMember) { - final AnnotationUsage collectionIdAnn = attributeMember.getAnnotationUsage( CollectionId.class ); + final CollectionId collectionIdAnn = attributeMember.getDirectAnnotationUsage( CollectionId.class ); if ( collectionIdAnn == null ) { throw new MappingException( "idbag mapping missing @CollectionId" ); } @@ -430,10 +433,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { implicitJavaTypeAccess = (typeConfiguration) -> null; explicitJavaTypeAccess = (typeConfiguration) -> { - final AnnotationUsage javaTypeAnn = attributeMember.locateAnnotationUsage( CollectionIdJavaType.class ); + final CollectionIdJavaType javaTypeAnn = attributeMember.locateAnnotationUsage( CollectionIdJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { - final ClassDetails implDetails = javaTypeAnn.getClassDetails( "value" ); - final Class> javaTypeClass = normalizeJavaType( implDetails.toJavaClass() ); + final Class> javaTypeClass = javaTypeAnn.value(); if ( javaTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); @@ -447,10 +449,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitJdbcTypeAccess = (typeConfiguration) -> { - final AnnotationUsage jdbcTypeAnn = attributeMember.locateAnnotationUsage( CollectionIdJdbcType.class ); + final CollectionIdJdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( CollectionIdJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { - final ClassDetails implDetails = jdbcTypeAnn.getClassDetails( "value" ); - final Class jdbcTypeClass = normalizeJdbcType( implDetails.toJavaClass() ); + final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); @@ -460,9 +461,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - final AnnotationUsage jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( CollectionIdJdbcTypeCode.class ); + final CollectionIdJdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( CollectionIdJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { - final int code = jdbcTypeCodeAnn.getInteger( "value" ); + final int code = jdbcTypeCodeAnn.value(); if ( code != Integer.MIN_VALUE ) { return typeConfiguration.getJdbcTypeRegistry().getDescriptor( code ); } @@ -472,10 +473,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitMutabilityAccess = (typeConfiguration) -> { - final AnnotationUsage mutabilityAnn = attributeMember.locateAnnotationUsage( CollectionIdMutability.class ); + final CollectionIdMutability mutabilityAnn = attributeMember.locateAnnotationUsage( CollectionIdMutability.class, getSourceModelContext() ); if ( mutabilityAnn != null ) { - final ClassDetails implDetails = mutabilityAnn.getClassDetails( "value" ); - final Class> mutabilityClass = implDetails.toJavaClass(); + final Class> mutabilityClass = mutabilityAnn.value(); if ( mutabilityClass != null ) { return resolveMutability( mutabilityClass ); } @@ -509,7 +509,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { } // if there is a UserType, see if its Class is annotated with mutability-related annotations - final Class> customTypeImpl = Kind.ATTRIBUTE.mappingAccess.customType( attributeMember ); + final Class> customTypeImpl = Kind.ATTRIBUTE.mappingAccess.customType( attributeMember, getSourceModelContext() ); if ( customTypeImpl != null ) { final Mutability customTypeMutabilityAnn = customTypeImpl.getAnnotation( Mutability.class ); if ( customTypeMutabilityAnn != null ) { @@ -543,23 +543,22 @@ public class BasicValueBinder implements JdbcTypeIndicators { return rawKeyClassDetails.toJavaClass(); }; - final AnnotationUsage mapKeyEnumeratedAnn = attributeMember.getAnnotationUsage( MapKeyEnumerated.class ); + final MapKeyEnumerated mapKeyEnumeratedAnn = attributeMember.getDirectAnnotationUsage( MapKeyEnumerated.class ); if ( mapKeyEnumeratedAnn != null ) { - enumType = mapKeyEnumeratedAnn.getEnum( "value" ); + enumType = mapKeyEnumeratedAnn.value(); } - final AnnotationUsage mapKeyTemporalAnn = attributeMember.getAnnotationUsage( MapKeyTemporal.class ); + final MapKeyTemporal mapKeyTemporalAnn = attributeMember.getDirectAnnotationUsage( MapKeyTemporal.class ); if ( mapKeyTemporalAnn != null ) { - temporalPrecision = mapKeyTemporalAnn.getEnum( "value" ); + temporalPrecision = mapKeyTemporalAnn.value(); } final boolean useDeferredBeanContainerAccess = !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); explicitJdbcTypeAccess = typeConfiguration -> { - final AnnotationUsage jdbcTypeAnn = attributeMember.locateAnnotationUsage( MapKeyJdbcType.class ); + final MapKeyJdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( MapKeyJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { - final ClassDetails implDetails = jdbcTypeAnn.getClassDetails( "value" ); - final Class jdbcTypeClass = normalizeJdbcType( implDetails.toJavaClass() ); + final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); @@ -568,9 +567,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - final AnnotationUsage jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( MapKeyJdbcTypeCode.class ); + final MapKeyJdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( MapKeyJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { - final int jdbcTypeCode = jdbcTypeCodeAnn.getInteger( "value" ); + final int jdbcTypeCode = jdbcTypeCodeAnn.value(); if ( jdbcTypeCode != Integer.MIN_VALUE ) { return typeConfiguration.getJdbcTypeRegistry().getDescriptor( jdbcTypeCode ); } @@ -580,10 +579,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitJavaTypeAccess = typeConfiguration -> { - final AnnotationUsage javaTypeAnn = attributeMember.locateAnnotationUsage( MapKeyJavaType.class ); + final MapKeyJavaType javaTypeAnn = attributeMember.locateAnnotationUsage( MapKeyJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { - final ClassDetails implDetails = javaTypeAnn.getClassDetails( "value" ); - final Class> javaTypeClass = normalizeJavaType( implDetails.toJavaClass() ); + final Class> javaTypeClass = javaTypeAnn.value(); if ( javaTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); @@ -592,19 +590,18 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - final AnnotationUsage mapKeyClassAnn = attributeMember.getAnnotationUsage( MapKeyClass.class ); + final MapKeyClass mapKeyClassAnn = attributeMember.getDirectAnnotationUsage( MapKeyClass.class ); if ( mapKeyClassAnn != null ) { - final ClassDetails mapKeyClassDetails = mapKeyClassAnn.getClassDetails( "value" ); - return (BasicJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor( mapKeyClassDetails.toJavaClass() ); + return (BasicJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor( mapKeyClassAnn.value() ); } return null; }; explicitMutabilityAccess = typeConfiguration -> { - final AnnotationUsage mutabilityAnn = attributeMember.locateAnnotationUsage( MapKeyMutability.class ); + final MapKeyMutability mutabilityAnn = attributeMember.locateAnnotationUsage( MapKeyMutability.class, getSourceModelContext() ); if ( mutabilityAnn != null ) { - final Class> mutabilityClass = mutabilityAnn.getClassDetails( "value" ).toJavaClass(); + final Class> mutabilityClass = mutabilityAnn.value(); if ( mutabilityClass != null ) { return resolveMutability( mutabilityClass ); } @@ -638,7 +635,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { } // if there is a UserType, see if its Class is annotated with mutability-related annotations - final Class> customTypeImpl = Kind.MAP_KEY.mappingAccess.customType( attributeMember ); + final Class> customTypeImpl = Kind.MAP_KEY.mappingAccess.customType( attributeMember, getSourceModelContext() ); if ( customTypeImpl != null ) { final Mutability customTypeMutabilityAnn = customTypeImpl.getAnnotation( Mutability.class ); if ( customTypeMutabilityAnn != null ) { @@ -664,10 +661,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { .requireService( ManagedBeanRegistry.class ); explicitJavaTypeAccess = (typeConfiguration) -> { - final AnnotationUsage javaTypeAnn = attributeMember.locateAnnotationUsage( ListIndexJavaType.class ); + final ListIndexJavaType javaTypeAnn = attributeMember.locateAnnotationUsage( ListIndexJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { - final ClassDetails implDetails = javaTypeAnn.getClassDetails( "value" ); - final Class> javaTypeClass = normalizeJavaType( implDetails.toJavaClass() ); + final Class> javaTypeClass = javaTypeAnn.value(); if ( javaTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); @@ -681,10 +677,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitJdbcTypeAccess = (typeConfiguration) -> { - final AnnotationUsage jdbcTypeAnn = attributeMember.locateAnnotationUsage( ListIndexJdbcType.class ); + final ListIndexJdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( ListIndexJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { - final ClassDetails implDetails = jdbcTypeAnn.getClassDetails( "value" ); - final Class jdbcTypeClass = normalizeJdbcType( implDetails.toJavaClass() ); + final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); @@ -694,9 +689,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - final AnnotationUsage jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( ListIndexJdbcTypeCode.class ); + final ListIndexJdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( ListIndexJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { - return typeConfiguration.getJdbcTypeRegistry().getDescriptor( jdbcTypeCodeAnn.getInteger( "value" ) ); + return typeConfiguration.getJdbcTypeRegistry().getDescriptor( jdbcTypeCodeAnn.value() ); } return null; @@ -715,10 +710,10 @@ public class BasicValueBinder implements JdbcTypeIndicators { implicitJavaTypeAccess = typeConfiguration -> javaType; - final AnnotationUsage temporalAnn = attributeMember.getAnnotationUsage( Temporal.class ); + final Temporal temporalAnn = attributeMember.getDirectAnnotationUsage( Temporal.class ); if ( temporalAnn != null ) { DEPRECATION_LOGGER.deprecatedAnnotation( Temporal.class, attributeMember.getName() ); - temporalPrecision = temporalAnn.getEnum( "value" ); + temporalPrecision = temporalAnn.value(); if ( temporalPrecision == null ) { throw new IllegalStateException( "No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + @@ -731,9 +726,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { } if ( javaTypeClass.isEnum() ) { - final AnnotationUsage enumeratedAnn = attributeMember.getAnnotationUsage( Enumerated.class ); + final Enumerated enumeratedAnn = attributeMember.getDirectAnnotationUsage( Enumerated.class ); if ( enumeratedAnn != null ) { - enumType = enumeratedAnn.getEnum( "value" ); + enumType = enumeratedAnn.value(); if ( enumType == null ) { throw new IllegalStateException( "jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + @@ -749,10 +744,10 @@ public class BasicValueBinder implements JdbcTypeIndicators { normalSupplementalDetails( attributeMember); // layer in support for JPA's approach for specifying a specific Java type for the collection elements... - final AnnotationUsage elementCollectionAnn = attributeMember.getAnnotationUsage( ElementCollection.class ); + final ElementCollection elementCollectionAnn = attributeMember.getDirectAnnotationUsage( ElementCollection.class ); if ( elementCollectionAnn != null ) { - final ClassDetails targetClassDetails = elementCollectionAnn.getClassDetails( "targetClass" ); - if ( ClassDetails.VOID_CLASS_DETAILS != targetClassDetails ) { + final Class targetClassDetails = elementCollectionAnn.targetClass(); + if ( targetClassDetails != void.class) { //noinspection rawtypes final Function original = explicitJavaTypeAccess; explicitJavaTypeAccess = (typeConfiguration) -> { @@ -763,7 +758,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { return (BasicJavaType) typeConfiguration .getJavaTypeRegistry() - .getDescriptor( targetClassDetails.toJavaClass() ); + .getDescriptor( targetClassDetails ); }; } } @@ -782,11 +777,11 @@ public class BasicValueBinder implements JdbcTypeIndicators { } ); //noinspection deprecation - final var temporalAnn = attributeMember.getAnnotationUsage( Temporal.class ); + final var temporalAnn = attributeMember.getDirectAnnotationUsage( Temporal.class ); if ( temporalAnn != null ) { //noinspection deprecation DEPRECATION_LOGGER.deprecatedAnnotation( Temporal.class, declaringClassName + "." + attributeMember.getName() ); - this.temporalPrecision = temporalAnn.getEnum( "value" ); + this.temporalPrecision = temporalAnn.value(); if ( this.temporalPrecision == null ) { throw new IllegalStateException( "No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + @@ -798,9 +793,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { this.temporalPrecision = null; } - final AnnotationUsage enumeratedAnn = attributeMember.getAnnotationUsage( Enumerated.class ); + final Enumerated enumeratedAnn = attributeMember.getDirectAnnotationUsage( Enumerated.class ); if ( enumeratedAnn != null ) { - this.enumType = enumeratedAnn.getEnum( "value" ); + this.enumType = enumeratedAnn.value(); if ( canUseEnumerated( attributeType, javaTypeClass ) ) { if ( this.enumType == null ) { throw new IllegalStateException( @@ -842,12 +837,12 @@ public class BasicValueBinder implements JdbcTypeIndicators { } private void prepareAnyDiscriminator(MemberDetails memberDetails) { - final AnnotationUsage anyDiscriminatorAnn = memberDetails.locateAnnotationUsage( AnyDiscriminator.class ); + final AnyDiscriminator anyDiscriminatorAnn = memberDetails.locateAnnotationUsage( AnyDiscriminator.class, getSourceModelContext() ); implicitJavaTypeAccess = (typeConfiguration) -> { if ( anyDiscriminatorAnn != null ) { - final DiscriminatorType anyDiscriminatorType = anyDiscriminatorAnn.getEnum( "value" ); - return switch ( anyDiscriminatorAnn.getEnum( "value", DiscriminatorType.class ) ) { + final DiscriminatorType anyDiscriminatorType = anyDiscriminatorAnn.value(); + return switch ( anyDiscriminatorType ) { case CHAR -> Character.class; case INTEGER -> Integer.class; default -> String.class; @@ -882,10 +877,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { final boolean useDeferredBeanContainerAccess = !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); explicitJavaTypeAccess = (typeConfiguration) -> { - final AnnotationUsage javaTypeAnn = memberDetails.locateAnnotationUsage( AnyKeyJavaType.class ); + final AnyKeyJavaType javaTypeAnn = memberDetails.locateAnnotationUsage( AnyKeyJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { - final ClassDetails implDetails = javaTypeAnn.getClassDetails( "value" ); - final Class> implClass = normalizeJavaType( implDetails.toJavaClass() ); + final Class> implClass = javaTypeAnn.value(); if ( implClass != null ) { if ( useDeferredBeanContainerAccess ) { @@ -895,23 +889,22 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - final AnnotationUsage javaClassAnn = memberDetails.locateAnnotationUsage( AnyKeyJavaClass.class ); + final AnyKeyJavaClass javaClassAnn = memberDetails.locateAnnotationUsage( AnyKeyJavaClass.class, getSourceModelContext() ); if ( javaClassAnn != null ) { - final ClassDetails implDetails = javaClassAnn.getClassDetails( "value" ); + final Class impl = javaClassAnn.value(); //noinspection rawtypes return (BasicJavaType) typeConfiguration .getJavaTypeRegistry() - .getDescriptor( implDetails.toJavaClass() ); + .getDescriptor( impl ); } throw new MappingException("Could not determine key type for '@Any' mapping (specify '@AnyKeyJavaType' or '@AnyKeyJavaClass')"); }; explicitJdbcTypeAccess = (typeConfiguration) -> { - final AnnotationUsage jdbcTypeAnn = memberDetails.locateAnnotationUsage( AnyKeyJdbcType.class ); + final AnyKeyJdbcType jdbcTypeAnn = memberDetails.locateAnnotationUsage( AnyKeyJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { - final ClassDetails implDetails = jdbcTypeAnn.getClassDetails( "value" ); - final Class jdbcTypeClass = normalizeJdbcType( implDetails.toJavaClass() ); + final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); @@ -921,9 +914,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - final AnnotationUsage jdbcTypeCodeAnn = memberDetails.locateAnnotationUsage( AnyKeyJdbcTypeCode.class ); + final AnyKeyJdbcTypeCode jdbcTypeCodeAnn = memberDetails.locateAnnotationUsage( AnyKeyJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { - final int code = jdbcTypeCodeAnn.getInteger( "value" ); + final int code = jdbcTypeCodeAnn.value(); if ( code != Integer.MIN_VALUE ) { return typeConfiguration.getJdbcTypeRegistry().getDescriptor( code ); } @@ -935,9 +928,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { private void normalJdbcTypeDetails(MemberDetails attributeMember) { explicitJdbcTypeAccess = typeConfiguration -> { - final AnnotationUsage jdbcTypeAnn = attributeMember.locateAnnotationUsage( org.hibernate.annotations.JdbcType.class ); + final org.hibernate.annotations.JdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( org.hibernate.annotations.JdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { - final Class jdbcTypeClass = normalizeJdbcType( jdbcTypeAnn.getClassDetails( "value" ).toJavaClass() ); + final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( !buildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); @@ -946,9 +939,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - final AnnotationUsage jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( JdbcTypeCode.class ); + final JdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( JdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { - final int jdbcTypeCode = jdbcTypeCodeAnn.getInteger( "value" ); + final int jdbcTypeCode = jdbcTypeCodeAnn.value(); if ( jdbcTypeCode != Integer.MIN_VALUE ) { final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry(); if ( jdbcTypeRegistry.getConstructor( jdbcTypeCode ) != null ) { @@ -967,16 +960,16 @@ public class BasicValueBinder implements JdbcTypeIndicators { private void normalMutabilityDetails(MemberDetails attributeMember) { explicitMutabilityAccess = typeConfiguration -> { // Look for `@Mutability` on the attribute - final AnnotationUsage mutabilityAnn = attributeMember.locateAnnotationUsage( Mutability.class ); + final Mutability mutabilityAnn = attributeMember.locateAnnotationUsage( Mutability.class, getSourceModelContext() ); if ( mutabilityAnn != null ) { - final Class> mutability = mutabilityAnn.getClassDetails( "value" ).toJavaClass(); + final Class> mutability = mutabilityAnn.value(); if ( mutability != null ) { return resolveMutability( mutability ); } } // Look for `@Immutable` on the attribute - if ( attributeMember.hasAnnotationUsage( Immutable.class ) ) { + if ( attributeMember.hasDirectAnnotationUsage( Immutable.class ) ) { return ImmutableMutabilityPlan.instance(); } @@ -1028,7 +1021,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { } // if a custom UserType is specified, see if the UserType Class is annotated `@Mutability` - final Class> customTypeImpl = Kind.ATTRIBUTE.mappingAccess.customType( attributeMember ); + final Class> customTypeImpl = Kind.ATTRIBUTE.mappingAccess.customType( attributeMember, getSourceModelContext() ); if ( customTypeImpl != null ) { final Mutability customTypeMutabilityAnn = customTypeImpl.getAnnotation( Mutability.class ); if ( customTypeMutabilityAnn != null ) { @@ -1066,9 +1059,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { private void normalSupplementalDetails(MemberDetails attributeMember) { explicitJavaTypeAccess = typeConfiguration -> { - final AnnotationUsage javaType = attributeMember.locateAnnotationUsage( org.hibernate.annotations.JavaType.class ); + final org.hibernate.annotations.JavaType javaType = attributeMember.locateAnnotationUsage( org.hibernate.annotations.JavaType.class, getSourceModelContext() ); if ( javaType != null ) { - final Class> javaTypeClass = normalizeJavaType( javaType.getClassDetails( "value" ).toJavaClass() ); + final Class> javaTypeClass = normalizeJavaType( javaType.value() ); if ( javaTypeClass != null ) { if ( !buildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); @@ -1078,38 +1071,38 @@ public class BasicValueBinder implements JdbcTypeIndicators { } //noinspection deprecation - final var targetAnn = attributeMember.locateAnnotationUsage( Target.class ); + final var targetAnn = attributeMember.locateAnnotationUsage( Target.class, getSourceModelContext() ); if ( targetAnn != null ) { //noinspection deprecation DEPRECATION_LOGGER.deprecatedAnnotation( Target.class, attributeMember.getName() ); - return (BasicJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor( targetAnn.getClassDetails( "value" ).toJavaClass() ); + return (BasicJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor( targetAnn.value() ); } return null; }; - final AnnotationUsage jdbcType = attributeMember.locateAnnotationUsage( JdbcTypeCode.class ); + final JdbcTypeCode jdbcType = attributeMember.locateAnnotationUsage( JdbcTypeCode.class, getSourceModelContext() ); if ( jdbcType != null ) { - jdbcTypeCode = jdbcType.getInteger( "value" ); + jdbcTypeCode = jdbcType.value(); } normalJdbcTypeDetails( attributeMember); normalMutabilityDetails( attributeMember ); - final AnnotationUsage enumerated = attributeMember.getAnnotationUsage( Enumerated.class ); + final Enumerated enumerated = attributeMember.getDirectAnnotationUsage( Enumerated.class ); if ( enumerated != null ) { - enumType = enumerated.getEnum( "value" ); + enumType = enumerated.value(); } - final AnnotationUsage temporal = attributeMember.getAnnotationUsage( Temporal.class ); + final Temporal temporal = attributeMember.getDirectAnnotationUsage( Temporal.class ); if ( temporal != null ) { - temporalPrecision = temporal.getEnum( "value" ); + temporalPrecision = temporal.value(); } - final AnnotationUsage timeZoneStorage = attributeMember.getAnnotationUsage( TimeZoneStorage.class ); + final TimeZoneStorage timeZoneStorage = attributeMember.getDirectAnnotationUsage( TimeZoneStorage.class ); if ( timeZoneStorage != null ) { - timeZoneStorageType = timeZoneStorage.getEnum( "value" ); - final AnnotationUsage timeZoneColumnAnn = attributeMember.getAnnotationUsage( TimeZoneColumn.class ); + timeZoneStorageType = timeZoneStorage.value(); + final TimeZoneColumn timeZoneColumnAnn = attributeMember.getDirectAnnotationUsage( TimeZoneColumn.class ); if ( timeZoneColumnAnn != null ) { if ( timeZoneStorageType != TimeZoneStorageType.AUTO && timeZoneStorageType != TimeZoneStorageType.COLUMN ) { throw new IllegalStateException( @@ -1121,7 +1114,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } - this.partitionKey = attributeMember.hasAnnotationUsage( PartitionKey.class ); + this.partitionKey = attributeMember.hasDirectAnnotationUsage( PartitionKey.class ); } private static Class> normalizeUserType(Class> userType) { @@ -1148,34 +1141,34 @@ public class BasicValueBinder implements JdbcTypeIndicators { LOG.debugf( "Applying JPA converter [%s:%s]", persistentClassName, attributeMember.getName() ); - if ( attributeMember.hasAnnotationUsage( Id.class ) ) { + if ( attributeMember.hasDirectAnnotationUsage( Id.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for Id attribute [%s]", attributeMember.getName() ); return; } - if ( attributeMember.hasAnnotationUsage( Version.class ) ) { + if ( attributeMember.hasDirectAnnotationUsage( Version.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for version attribute [%s]", attributeMember.getName() ); return; } if ( kind == Kind.MAP_KEY ) { - if ( attributeMember.hasAnnotationUsage( MapKeyTemporal.class ) ) { + if ( attributeMember.hasDirectAnnotationUsage( MapKeyTemporal.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyTemporal [%s]", attributeMember.getName() ); return; } - if ( attributeMember.hasAnnotationUsage( MapKeyEnumerated.class ) ) { + if ( attributeMember.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyEnumerated [%s]", attributeMember.getName() ); return; } } else { - if ( attributeMember.hasAnnotationUsage( Temporal.class ) ) { + if ( attributeMember.hasDirectAnnotationUsage( Temporal.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for Temporal attribute [%s]", attributeMember.getName() ); return; } - if ( attributeMember.hasAnnotationUsage( Enumerated.class ) ) { + if ( attributeMember.hasDirectAnnotationUsage( Enumerated.class ) ) { LOG.debugf( "Skipping AttributeConverter checks for Enumerated attribute [%s]", attributeMember.getName() ); return; } @@ -1454,31 +1447,31 @@ public class BasicValueBinder implements JdbcTypeIndicators { * Access to detail of basic value mappings based on {@link Kind} */ private interface BasicMappingAccess { - Class> customType(MemberDetails attributeMember); - Map customTypeParameters(MemberDetails attributeMember); + Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext); + Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext); } private static class ValueMappingAccess implements BasicMappingAccess { public static final ValueMappingAccess INSTANCE = new ValueMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember) { - final AnnotationUsage customType = attributeMember.locateAnnotationUsage( Type.class ); + public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + final Type customType = attributeMember.locateAnnotationUsage( Type.class, sourceModelContext ); if ( customType == null ) { return null; } - return normalizeUserType( customType.getClassDetails( "value" ).toJavaClass() ); + return normalizeUserType( customType.value() ); } @Override - public Map customTypeParameters(MemberDetails attributeMember) { - final AnnotationUsage customType = attributeMember.locateAnnotationUsage( Type.class ); + public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + final Type customType = attributeMember.locateAnnotationUsage( Type.class, sourceModelContext ); if ( customType == null ) { return null; } - return AnnotationHelper.extractParameterMap( customType.getList( "parameters" ) ); + return AnnotationHelper.extractParameterMap( customType.parameters() ); } } @@ -1486,12 +1479,12 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final AnyDiscriminatorMappingAccess INSTANCE = new AnyDiscriminatorMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember) { + public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { return null; } @Override - public Map customTypeParameters(MemberDetails attributeMember) { + public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { return Collections.emptyMap(); } } @@ -1500,12 +1493,12 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final AnyKeyMappingAccess INSTANCE = new AnyKeyMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember) { + public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { return null; } @Override - public Map customTypeParameters(MemberDetails attributeMember) { + public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { return Collections.emptyMap(); } } @@ -1514,23 +1507,23 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final MapKeyMappingAccess INSTANCE = new MapKeyMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember) { - final AnnotationUsage customType = attributeMember.locateAnnotationUsage( MapKeyType.class ); + public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + final MapKeyType customType = attributeMember.locateAnnotationUsage( MapKeyType.class, sourceModelContext ); if ( customType == null ) { return null; } - return normalizeUserType( customType.getClassDetails( "value" ).toJavaClass() ); + return normalizeUserType( customType.value() ); } @Override - public Map customTypeParameters(MemberDetails attributeMember) { - final AnnotationUsage customType = attributeMember.locateAnnotationUsage( MapKeyType.class ); + public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + final MapKeyType customType = attributeMember.locateAnnotationUsage( MapKeyType.class, sourceModelContext ); if ( customType == null ) { return null; } - return AnnotationHelper.extractParameterMap( customType.getList( "parameters" ) ); + return AnnotationHelper.extractParameterMap( customType.parameters() ); } } @@ -1538,23 +1531,23 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final CollectionIdMappingAccess INSTANCE = new CollectionIdMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember) { - final AnnotationUsage customType = attributeMember.locateAnnotationUsage( CollectionIdType.class ); + public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelBuildingContext) { + final CollectionIdType customType = attributeMember.locateAnnotationUsage( CollectionIdType.class, sourceModelBuildingContext ); if ( customType == null ) { return null; } - return normalizeUserType( customType.getClassDetails( "value" ).toJavaClass() ); + return normalizeUserType( customType.value() ); } @Override - public Map customTypeParameters(MemberDetails attributeMember) { - final AnnotationUsage customType = attributeMember.locateAnnotationUsage( CollectionIdType.class ); + public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + final CollectionIdType customType = attributeMember.locateAnnotationUsage( CollectionIdType.class, sourceModelContext ); if ( customType == null ) { return null; } - return AnnotationHelper.extractParameterMap( customType.getList( "parameters" ) ); + return AnnotationHelper.extractParameterMap( customType.parameters() ); } } @@ -1562,12 +1555,12 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final ListIndexMappingAccess INSTANCE = new ListIndexMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember) { + public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { return null; } @Override - public Map customTypeParameters(MemberDetails attributeMember) { + public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { return Collections.emptyMap(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java index 7a1406ed1b..f4ef045326 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java @@ -8,6 +8,7 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedHashSet; @@ -35,6 +36,7 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Any; import org.hibernate.mapping.AttributeContainer; import org.hibernate.mapping.BasicValue; @@ -51,10 +53,10 @@ import org.hibernate.mapping.Table; import org.hibernate.mapping.ToOne; import org.hibernate.mapping.Value; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MemberDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.models.spi.TypeDetailsHelper; import org.hibernate.type.descriptor.java.JavaType; @@ -746,8 +748,8 @@ public class BinderHelper { } public static Any buildAnyValue( - AnnotationUsage discriminatorColumn, - AnnotationUsage discriminatorFormula, + jakarta.persistence.Column discriminatorColumn, + Formula discriminatorFormula, AnnotatedJoinColumns keyColumns, PropertyData inferredData, OnDeleteAction onDeleteAction, @@ -802,9 +804,10 @@ public class BinderHelper { processAnyDiscriminatorValues( inferredData.getAttributeMember(), valueMapping -> discriminatorValueMappings.put( - discriminatorJavaType.wrap( valueMapping.getString( "discriminator" ), null ), - valueMapping.getClassDetails( "entity" ).toJavaClass() - ) + discriminatorJavaType.wrap( valueMapping.discriminator(), null ), + valueMapping.entity() + ), + context.getMetadataCollector().getSourceModelBuildingContext() ); value.setDiscriminatorValueMappings( discriminatorValueMappings ); @@ -829,15 +832,16 @@ public class BinderHelper { private static void processAnyDiscriminatorValues( MemberDetails property, - Consumer> consumer) { - final AnnotationUsage valuesAnn = property.locateAnnotationUsage( AnyDiscriminatorValues.class ); + Consumer consumer, + SourceModelBuildingContext sourceModelContext) { + final AnyDiscriminatorValues valuesAnn = property.locateAnnotationUsage( AnyDiscriminatorValues.class, sourceModelContext ); if ( valuesAnn != null ) { - final List> nestedList = valuesAnn.getList( "value" ); - nestedList.forEach( consumer ); + final AnyDiscriminatorValue[] nestedList = valuesAnn.value(); + ArrayHelper.forEach( nestedList, consumer ); return; } - final AnnotationUsage valueAnn = property.locateAnnotationUsage( AnyDiscriminatorValue.class ); + final AnyDiscriminatorValue valueAnn = property.locateAnnotationUsage( AnyDiscriminatorValue.class, sourceModelContext ); if ( valueAnn != null ) { consumer.accept( valueAnn ); } @@ -898,31 +902,31 @@ public class BinderHelper { return metadataCollector.getPropertyAnnotatedWithMapsId( classDetails, isId ? "" : propertyName ); } - public static Map toAliasTableMap(List> aliases){ + public static Map toAliasTableMap(SqlFragmentAlias[] aliases){ final Map ret = new HashMap<>(); - for ( AnnotationUsage aliasAnnotation : aliases ) { - final String table = aliasAnnotation.getString( "table" ); + for ( SqlFragmentAlias aliasAnnotation : aliases ) { + final String table = aliasAnnotation.table(); if ( isNotEmpty( table ) ) { - ret.put( aliasAnnotation.getString( "alias" ), table ); + ret.put( aliasAnnotation.alias(), table ); } } return ret; } - public static Map toAliasEntityMap(List> aliases){ + public static Map toAliasEntityMap(SqlFragmentAlias[] aliases){ final Map result = new HashMap<>(); - for ( AnnotationUsage aliasAnnotation : aliases ) { - final ClassDetails entityClassDetails = aliasAnnotation.getClassDetails( "entity" ); - if ( entityClassDetails != ClassDetails.VOID_CLASS_DETAILS ) { - result.put( aliasAnnotation.getString( "alias" ), entityClassDetails.getName() ); + for ( SqlFragmentAlias aliasAnnotation : aliases ) { + final Class entityClass = aliasAnnotation.entity(); + if ( entityClass != void.class ) { + result.put( aliasAnnotation.alias(), entityClass.getName() ); } } return result; } public static boolean hasToOneAnnotation(AnnotationTarget property) { - return property.hasAnnotationUsage(ManyToOne.class) - || property.hasAnnotationUsage(OneToOne.class); + return property.hasDirectAnnotationUsage(ManyToOne.class) + || property.hasDirectAnnotationUsage(OneToOne.class); } @@ -934,16 +938,16 @@ public class BinderHelper { } public static String getCascadeStrategy( - List ejbCascades, - AnnotationUsage hibernateCascadeAnnotation, + jakarta.persistence.CascadeType[] ejbCascades, + Cascade hibernateCascadeAnnotation, boolean orphanRemoval, MetadataBuildingContext context) { final EnumSet cascadeTypes = convertToHibernateCascadeType( ejbCascades ); - final List hibernateCascades = hibernateCascadeAnnotation == null + final CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ? null - : hibernateCascadeAnnotation.getList( "value" ); - if ( hibernateCascades != null && !hibernateCascades.isEmpty() ) { - cascadeTypes.addAll( hibernateCascades ); + : hibernateCascadeAnnotation.value(); + if ( !ArrayHelper.isEmpty( hibernateCascades ) ) { + Collections.addAll( cascadeTypes, hibernateCascades ); } if ( orphanRemoval ) { cascadeTypes.add( CascadeType.DELETE_ORPHAN ); @@ -953,7 +957,7 @@ public class BinderHelper { return renderCascadeTypeList( cascadeTypes ); } - private static EnumSet convertToHibernateCascadeType(List ejbCascades) { + private static EnumSet convertToHibernateCascadeType(jakarta.persistence.CascadeType[] ejbCascades) { final EnumSet cascadeTypes = EnumSet.noneOf( CascadeType.class ); if ( ejbCascades != null ) { for ( jakarta.persistence.CascadeType cascade: ejbCascades ) { @@ -1050,8 +1054,8 @@ public class BinderHelper { } static boolean isCompositeId(ClassDetails entityClass, MemberDetails idProperty) { - return entityClass.hasAnnotationUsage( Embeddable.class ) - || idProperty.hasAnnotationUsage( EmbeddedId.class ); + return entityClass.hasDirectAnnotationUsage( Embeddable.class ) + || idProperty.hasDirectAnnotationUsage( EmbeddedId.class ); } public static boolean isDefault(ClassDetails clazz, MetadataBuildingContext context) { @@ -1110,12 +1114,12 @@ public class BinderHelper { return false; } - public static boolean noConstraint(AnnotationUsage foreignKey, boolean noConstraintByDefault) { + public static boolean noConstraint(ForeignKey foreignKey, boolean noConstraintByDefault) { if ( foreignKey == null ) { return false; } else { - final ConstraintMode mode = foreignKey.getEnum( "value" ); + final ConstraintMode mode = foreignKey.value(); return mode == NO_CONSTRAINT || mode == PROVIDER_DEFAULT && noConstraintByDefault; } @@ -1130,7 +1134,7 @@ public class BinderHelper { * * @return The annotation or {@code null} */ - public static AnnotationUsage extractFromPackage( + public static A extractFromPackage( Class annotationType, ClassDetails classDetails, MetadataBuildingContext context) { @@ -1148,14 +1152,13 @@ public class BinderHelper { if ( isEmpty( packageName ) ) { return null; } + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + final ClassDetailsRegistry classDetailsRegistry = sourceModelContext.getClassDetailsRegistry(); - final ClassDetailsRegistry classDetailsRegistry = context.getMetadataCollector() - .getSourceModelBuildingContext() - .getClassDetailsRegistry(); final String packageInfoName = packageName + ".package-info"; try { final ClassDetails packageInfoClassDetails = classDetailsRegistry.resolveClassDetails( packageInfoName ); - return packageInfoClassDetails.getAnnotationUsage( annotationType ); + return packageInfoClassDetails.getAnnotationUsage( annotationType, sourceModelContext ); } catch (ClassLoadingException ignore) { } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java index b96658c14d..4098087c9c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java @@ -6,13 +6,11 @@ */ package org.hibernate.boot.model.internal; -import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.function.Consumer; -import java.util.stream.Collectors; import org.hibernate.AssertionFailure; import org.hibernate.MappingException; @@ -32,10 +30,8 @@ import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; import org.hibernate.mapping.ToOne; import org.hibernate.mapping.Value; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; -import org.hibernate.models.spi.TypeDetails; import jakarta.persistence.Convert; import jakarta.persistence.JoinTable; @@ -104,14 +100,14 @@ public class ClassPropertyHolder extends AbstractPropertyHolder { // collect superclass info first collectAttributeConversionInfo( infoMap, entityClassDetails.getSuperClass() ); - final boolean canContainConvert = entityClassDetails.hasAnnotationUsage( jakarta.persistence.Entity.class ) - || entityClassDetails.hasAnnotationUsage( jakarta.persistence.MappedSuperclass.class ) - || entityClassDetails.hasAnnotationUsage( jakarta.persistence.Embeddable.class ); + final boolean canContainConvert = entityClassDetails.hasAnnotationUsage( jakarta.persistence.Entity.class, getSourceModelContext() ) + || entityClassDetails.hasAnnotationUsage( jakarta.persistence.MappedSuperclass.class, getSourceModelContext() ) + || entityClassDetails.hasAnnotationUsage( jakarta.persistence.Embeddable.class, getSourceModelContext() ); if ( ! canContainConvert ) { return; } - entityClassDetails.forEachAnnotationUsage( Convert.class, (usage) -> { + entityClassDetails.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { final AttributeConversionInfo info = new AttributeConversionInfo( usage, entityClassDetails ); if ( isEmpty( info.getAttributeName() ) ) { throw new IllegalStateException( "@Convert placed on @Entity/@MappedSuperclass must define attributeName" ); @@ -131,7 +127,7 @@ public class ClassPropertyHolder extends AbstractPropertyHolder { return; } - property.forEachAnnotationUsage( Convert.class, (usage) -> { + property.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { final AttributeConversionInfo info = new AttributeConversionInfo( usage, property ); if ( isEmpty( info.getAttributeName() ) ) { attributeConversionInfoMap.put( propertyName, info ); @@ -192,19 +188,19 @@ public class ClassPropertyHolder extends AbstractPropertyHolder { } @Override - public Join addJoin(AnnotationUsage joinTableAnn, boolean noDelayInPkColumnCreation) { + public Join addJoin(JoinTable joinTableAnn, boolean noDelayInPkColumnCreation) { final Join join = entityBinder.addJoinTable( joinTableAnn, this, noDelayInPkColumnCreation ); joins = entityBinder.getSecondaryTables(); return join; } @Override - public Join addJoin(AnnotationUsage joinTable, Table table, boolean noDelayInPkColumnCreation) { + public Join addJoin(JoinTable joinTable, Table table, boolean noDelayInPkColumnCreation) { final Join join = entityBinder.createJoin( this, noDelayInPkColumnCreation, false, - joinTable.getList( "joinColumns" ), + joinTable.joinColumns(), table.getQualifiedTableName(), table ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java index a0cfa334f2..09b835ecb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java @@ -78,6 +78,9 @@ import org.hibernate.annotations.WhereJoinTable; import org.hibernate.boot.BootLogging; import org.hibernate.boot.model.IdentifierGeneratorDefinition; import org.hibernate.boot.model.TypeDefinition; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyColumnJpaAnnotation; import org.hibernate.boot.spi.AccessType; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.InFlightMetadataCollector.CollectionTypeRegistrationDescriptor; @@ -88,6 +91,7 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jdbc.Expectation; import org.hibernate.mapping.Any; @@ -110,10 +114,10 @@ import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.models.internal.ClassTypeDetailsImpl; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; @@ -141,7 +145,6 @@ import jakarta.persistence.ManyToMany; import jakarta.persistence.MapKey; import jakarta.persistence.MapKeyColumn; import jakarta.persistence.MapKeyJoinColumn; -import jakarta.persistence.MapKeyJoinColumns; import jakarta.persistence.OneToMany; import jakarta.persistence.OrderBy; import jakarta.persistence.OrderColumn; @@ -240,11 +243,11 @@ public abstract class CollectionBinder { private AccessType accessType; private boolean hibernateExtensionMapping; - private AnnotationUsage jpaOrderBy; - private AnnotationUsage sqlOrderBy; - private AnnotationUsage sqlOrder; - private AnnotationUsage naturalSort; - private AnnotationUsage comparatorSort; + private jakarta.persistence.OrderBy jpaOrderBy; + private org.hibernate.annotations.OrderBy sqlOrderBy; + private SQLOrder sqlOrder; + private SortNatural naturalSort; + private SortComparator comparatorSort; private String explicitType; private final Map explicitTypeParameters = new HashMap<>(); @@ -272,35 +275,37 @@ public abstract class CollectionBinder { Map inheritanceStatePerClass, MemberDetails property, AnnotatedJoinColumns joinColumns) { - final AnnotationUsage oneToManyAnn = property.getAnnotationUsage( OneToMany.class ); - final AnnotationUsage manyToManyAnn = property.getAnnotationUsage( ManyToMany.class ); - final AnnotationUsage elementCollectionAnn = property.getAnnotationUsage( ElementCollection.class ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + + final OneToMany oneToManyAnn = property.getAnnotationUsage( OneToMany.class, sourceModelContext ); + final ManyToMany manyToManyAnn = property.getAnnotationUsage( ManyToMany.class, sourceModelContext ); + final ElementCollection elementCollectionAnn = property.getAnnotationUsage( ElementCollection.class, sourceModelContext ); checkAnnotations( propertyHolder, inferredData, property, oneToManyAnn, manyToManyAnn, elementCollectionAnn ); final CollectionBinder collectionBinder = getCollectionBinder( property, hasMapKeyAnnotation( property ), context ); collectionBinder.setIndexColumn( getIndexColumn( propertyHolder, inferredData, entityBinder, context, property ) ); - collectionBinder.setMapKey( property.getAnnotationUsage( MapKey.class ) ); + collectionBinder.setMapKey( property.getAnnotationUsage( MapKey.class, sourceModelContext ) ); collectionBinder.setPropertyName( inferredData.getPropertyName() ); - collectionBinder.setJpaOrderBy( property.getAnnotationUsage( OrderBy.class ) ); + collectionBinder.setJpaOrderBy( property.getAnnotationUsage( OrderBy.class, sourceModelContext ) ); collectionBinder.setSqlOrderBy( getOverridableAnnotation( property, org.hibernate.annotations.OrderBy.class, context ) ); collectionBinder.setSqlOrder( getOverridableAnnotation( property, SQLOrder.class, context ) ); - collectionBinder.setNaturalSort( property.getAnnotationUsage( SortNatural.class ) ); - collectionBinder.setComparatorSort( property.getAnnotationUsage( SortComparator.class ) ); - collectionBinder.setCache( property.getAnnotationUsage( Cache.class ) ); - collectionBinder.setQueryCacheLayout( property.getAnnotationUsage( QueryCacheLayout.class ) ); + collectionBinder.setNaturalSort( property.getAnnotationUsage( SortNatural.class, sourceModelContext ) ); + collectionBinder.setComparatorSort( property.getAnnotationUsage( SortComparator.class, sourceModelContext ) ); + collectionBinder.setCache( property.getAnnotationUsage( Cache.class, sourceModelContext ) ); + collectionBinder.setQueryCacheLayout( property.getAnnotationUsage( QueryCacheLayout.class, sourceModelContext ) ); collectionBinder.setPropertyHolder(propertyHolder); - collectionBinder.setNotFoundAction( notFoundAction( propertyHolder, inferredData, property, manyToManyAnn ) ); + collectionBinder.setNotFoundAction( notFoundAction( propertyHolder, inferredData, property, manyToManyAnn, sourceModelContext ) ); collectionBinder.setElementType( inferredData.getClassOrElementType() ); collectionBinder.setAccessType( inferredData.getDefaultAccess() ); - collectionBinder.setEmbedded( property.hasAnnotationUsage( Embedded.class ) ); + collectionBinder.setEmbedded( property.hasAnnotationUsage( Embedded.class, sourceModelContext ) ); collectionBinder.setProperty( property ); collectionBinder.setOnDeleteActionAction( onDeleteAction( property ) ); collectionBinder.setInheritanceStatePerClass( inheritanceStatePerClass ); collectionBinder.setDeclaringClass( inferredData.getDeclaringClass() ); // final Comment comment = property.getAnnotation( Comment.class ); - final AnnotationUsage hibernateCascade = property.getAnnotationUsage( Cascade.class ); + final Cascade hibernateCascade = property.getAnnotationUsage( Cascade.class, sourceModelContext ); collectionBinder.setElementColumns( elementColumns( propertyHolder, @@ -356,7 +361,7 @@ public abstract class CollectionBinder { collectionBinder.setUpdatable( false ); } - if ( property.hasAnnotationUsage( CollectionId.class ) ) { + if ( property.hasAnnotationUsage( CollectionId.class, sourceModelContext ) ) { //do not compute the generators unless necessary final HashMap localGenerators = new HashMap<>(classGenerators); localGenerators.putAll( buildGenerators( property, context ) ); @@ -370,14 +375,15 @@ public abstract class CollectionBinder { PropertyHolder propertyHolder, PropertyData inferredData, MemberDetails property, - AnnotationUsage manyToManyAnn) { - final AnnotationUsage notFound = property.getAnnotationUsage( NotFound.class ); + ManyToMany manyToManyAnn, + SourceModelBuildingContext sourceModelContext) { + final NotFound notFound = property.getAnnotationUsage( NotFound.class, sourceModelContext ); if ( notFound != null ) { if ( manyToManyAnn == null ) { throw new AnnotationException( "Collection '" + getPath(propertyHolder, inferredData) + "' annotated '@NotFound' is not a '@ManyToMany' association" ); } - return notFound.getEnum( "action" ); + return notFound.action(); } else { return null; @@ -404,13 +410,13 @@ public abstract class CollectionBinder { } private static OnDeleteAction onDeleteAction(MemberDetails property) { - final AnnotationUsage onDelete = property.getAnnotationUsage( OnDelete.class ); - return onDelete == null ? null : onDelete.getEnum( "action" ); + final OnDelete onDelete = property.getDirectAnnotationUsage( OnDelete.class ); + return onDelete == null ? null : onDelete.action(); } private static PropertyData virtualPropertyData(PropertyData inferredData, MemberDetails property) { //do not use "element" if you are a JPA 2 @ElementCollection, only for legacy Hibernate mappings - return property.hasAnnotationUsage( ElementCollection.class ) + return property.hasDirectAnnotationUsage( ElementCollection.class ) ? inferredData : new WrappedInferredData(inferredData, "element" ); } @@ -419,9 +425,9 @@ public abstract class CollectionBinder { PropertyHolder propertyHolder, PropertyData inferredData, MemberDetails property, - AnnotationUsage oneToMany, - AnnotationUsage manyToMany, - AnnotationUsage elementCollection) { + OneToMany oneToMany, + ManyToMany manyToMany, + ElementCollection elementCollection) { if ( ( oneToMany != null || manyToMany != null || elementCollection != null ) && isToManyAssociationWithinEmbeddableCollection( propertyHolder ) ) { throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData ) + @@ -429,22 +435,23 @@ public abstract class CollectionBinder { + annotationName( oneToMany, manyToMany, elementCollection )); } - if ( oneToMany != null && property.hasAnnotationUsage( SoftDelete.class ) ) { + if ( oneToMany != null && property.hasDirectAnnotationUsage( SoftDelete.class ) ) { throw new UnsupportedMappingException( "@SoftDelete cannot be applied to @OneToMany - " + property.getDeclaringType().getName() + "." + property.getName() ); } - if ( property.hasAnnotationUsage( OrderColumn.class ) + if ( property.hasDirectAnnotationUsage( OrderColumn.class ) && manyToMany != null - && StringHelper.isNotEmpty( manyToMany.getString( "mappedBy" ) ) ) { + && StringHelper.isNotEmpty( manyToMany.mappedBy() ) ) { throw new AnnotationException("Collection '" + getPath( propertyHolder, inferredData ) + "' is the unowned side of a bidirectional '@ManyToMany' and may not have an '@OrderColumn'"); } if ( manyToMany != null || elementCollection != null ) { - if ( property.hasAnnotationUsage( JoinColumn.class ) || property.hasAnnotationUsage( JoinColumns.class ) ) { + if ( property.hasDirectAnnotationUsage( JoinColumn.class ) + || property.hasDirectAnnotationUsage( JoinColumns.class ) ) { throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData ) + "' is a " + annotationName( oneToMany, manyToMany, elementCollection ) + " and is directly annotated '@JoinColumn'" @@ -454,9 +461,9 @@ public abstract class CollectionBinder { } private static String annotationName( - AnnotationUsage oneToMany, - AnnotationUsage manyToMany, - AnnotationUsage elementCollection) { + OneToMany oneToMany, + ManyToMany manyToMany, + ElementCollection elementCollection) { return oneToMany != null ? "'@OneToMany'" : manyToMany != null ? "'@ManyToMany'" : "'@ElementCollection'"; } @@ -467,9 +474,9 @@ public abstract class CollectionBinder { MetadataBuildingContext context, MemberDetails property) { return IndexColumn.fromAnnotations( - property.getAnnotationUsage( OrderColumn.class ), - property.getAnnotationUsage( org.hibernate.annotations.IndexColumn.class ), - property.getAnnotationUsage( ListIndexBase.class ), + property.getDirectAnnotationUsage( OrderColumn.class ), + property.getDirectAnnotationUsage( org.hibernate.annotations.IndexColumn.class ), + property.getDirectAnnotationUsage( ListIndexBase.class ), propertyHolder, inferredData, entityBinder.getSecondaryTables(), @@ -483,11 +490,11 @@ public abstract class CollectionBinder { MetadataBuildingContext context, MemberDetails property, AnnotatedJoinColumns joinColumns, - AnnotationUsage oneToManyAnn, - AnnotationUsage manyToManyAnn, - AnnotationUsage elementCollectionAnn, + OneToMany oneToManyAnn, + ManyToMany manyToManyAnn, + ElementCollection elementCollectionAnn, CollectionBinder collectionBinder, - AnnotationUsage hibernateCascade) { + Cascade hibernateCascade) { //TODO enhance exception with @ManyToAny and @CollectionOfElements if ( oneToManyAnn != null && manyToManyAnn != null ) { @@ -501,12 +508,12 @@ public abstract class CollectionBinder { + "' has foreign key in secondary table" ); } collectionBinder.setFkJoinColumns( joinColumns ); - mappedBy = nullIfEmpty( oneToManyAnn.getString( "mappedBy" ) ); - collectionBinder.setTargetEntity( oneToManyAnn.getClassDetails( "targetEntity" ) ); + mappedBy = nullIfEmpty( oneToManyAnn.mappedBy() ); + collectionBinder.setTargetEntity( oneToManyAnn.targetEntity() ); collectionBinder.setCascadeStrategy( getCascadeStrategy( - oneToManyAnn.getList( "cascade" ), + oneToManyAnn.cascade(), hibernateCascade, - oneToManyAnn.getBoolean( "orphanRemoval" ), + oneToManyAnn.orphanRemoval(), context ) ); collectionBinder.setOneToMany( true ); @@ -518,22 +525,21 @@ public abstract class CollectionBinder { } collectionBinder.setFkJoinColumns( joinColumns ); mappedBy = null; - final ClassDetails targetClassDetails = elementCollectionAnn.getClassDetails( "targetClass" ); - collectionBinder.setTargetEntity( targetClassDetails ); + collectionBinder.setTargetEntity( elementCollectionAnn.targetClass() ); collectionBinder.setOneToMany( false ); } else if ( manyToManyAnn != null ) { - mappedBy = nullIfEmpty( manyToManyAnn.getString( "mappedBy" ) ); - collectionBinder.setTargetEntity( manyToManyAnn.getClassDetails( "targetEntity" ) ); + mappedBy = nullIfEmpty( manyToManyAnn.mappedBy() ); + collectionBinder.setTargetEntity( manyToManyAnn.targetEntity() ); collectionBinder.setCascadeStrategy( getCascadeStrategy( - manyToManyAnn.getList( "cascade" ), + manyToManyAnn.cascade(), hibernateCascade, false, context ) ); collectionBinder.setOneToMany( false ); } - else if ( property.hasAnnotationUsage( ManyToAny.class ) ) { + else if ( property.hasDirectAnnotationUsage( ManyToAny.class ) ) { mappedBy = null; collectionBinder.setTargetEntity( ClassDetails.VOID_CLASS_DETAILS ); collectionBinder.setCascadeStrategy( getCascadeStrategy( @@ -552,12 +558,12 @@ public abstract class CollectionBinder { } private static boolean hasMapKeyAnnotation(MemberDetails property) { - return property.hasAnnotationUsage(MapKeyJavaType.class) - || property.hasAnnotationUsage(MapKeyJdbcType.class) - || property.hasAnnotationUsage(MapKeyJdbcTypeCode.class) - || property.hasAnnotationUsage(MapKeyMutability.class) - || property.hasAnnotationUsage(MapKey.class) - || property.hasAnnotationUsage(MapKeyType.class); + return property.hasDirectAnnotationUsage(MapKeyJavaType.class) + || property.hasDirectAnnotationUsage(MapKeyJdbcType.class) + || property.hasDirectAnnotationUsage(MapKeyJdbcTypeCode.class) + || property.hasDirectAnnotationUsage(MapKeyMutability.class) + || property.hasDirectAnnotationUsage(MapKey.class) + || property.hasDirectAnnotationUsage(MapKeyType.class); } private static boolean isToManyAssociationWithinEmbeddableCollection(PropertyHolder propertyHolder) { @@ -578,9 +584,9 @@ public abstract class CollectionBinder { MemberDetails property, PropertyData virtualProperty) { // Comment comment) { - if ( property.hasAnnotationUsage( jakarta.persistence.Column.class ) ) { + if ( property.hasDirectAnnotationUsage( jakarta.persistence.Column.class ) ) { return buildColumnFromAnnotation( - property.getAnnotationUsage( jakarta.persistence.Column.class ), + property.getDirectAnnotationUsage( jakarta.persistence.Column.class ), null, // comment, nullability, @@ -590,7 +596,7 @@ public abstract class CollectionBinder { context ); } - else if ( property.hasAnnotationUsage( Formula.class ) ) { + else if ( property.hasDirectAnnotationUsage( Formula.class ) ) { return buildFormulaFromAnnotation( getOverridableAnnotation(property, Formula.class, context), // comment, @@ -601,9 +607,9 @@ public abstract class CollectionBinder { context ); } - else if ( property.hasAnnotationUsage( Columns.class ) ) { + else if ( property.hasDirectAnnotationUsage( Columns.class ) ) { return buildColumnsFromAnnotations( - property.getAnnotationUsage( Columns.class ).getList( "columns" ), + property.getDirectAnnotationUsage( Columns.class ).columns(), null, // comment, nullability, @@ -626,38 +632,29 @@ public abstract class CollectionBinder { } } - private static List> mapKeyJoinColumnAnnotations( + private static JoinColumn[] mapKeyJoinColumnAnnotations( PropertyHolder propertyHolder, PropertyData inferredData, MemberDetails property, MetadataBuildingContext context) { - if ( property.hasAnnotationUsage( MapKeyJoinColumns.class ) ) { - if ( property.hasAnnotationUsage( MapKeyJoinColumn.class ) ) { - throw new AnnotationException( - "Property '" + getPath( propertyHolder, inferredData ) - + "' is annotated with both '@MapKeyJoinColumn' and '@MapKeyJoinColumns'" - ); - } - final List> mapKeyJoinColumns = property.getAnnotationUsage( MapKeyJoinColumns.class ).getList( "value" ); - final List> joinKeyColumns = CollectionHelper.arrayList( mapKeyJoinColumns.size() ); - for ( AnnotationUsage mapKeyJoinColumn : mapKeyJoinColumns ) { - final MutableAnnotationUsage joinColumn - = MapKeyJoinColumnDelegator.fromMapKeyJoinColumn( mapKeyJoinColumn, property, context ); - joinKeyColumns.add( joinColumn ); - } - return joinKeyColumns; - } - else if ( property.hasAnnotationUsage( MapKeyJoinColumn.class ) ) { - final MutableAnnotationUsage delegator = MapKeyJoinColumnDelegator.fromMapKeyJoinColumn( - property.getAnnotationUsage( MapKeyJoinColumn.class ), - property, - context - ); - return List.of( delegator ); - } - else { + final MapKeyJoinColumn[] mapKeyJoinColumns = property.getRepeatedAnnotationUsages( + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + context.getMetadataCollector().getSourceModelBuildingContext() + ); + + if ( CollectionHelper.isEmpty( mapKeyJoinColumns ) ) { return null; } + + final JoinColumn[] joinColumns = new JoinColumn[mapKeyJoinColumns.length]; + for ( int i = 0; i < mapKeyJoinColumns.length; i++ ) { + final JoinColumn joinColumn = JoinColumnJpaAnnotation.toJoinColumn( + mapKeyJoinColumns[i], + context.getMetadataCollector().getSourceModelBuildingContext() + ); + joinColumns[i] = joinColumn; + } + return joinColumns; } private static AnnotatedColumns mapKeyColumns( @@ -667,11 +664,18 @@ public abstract class CollectionBinder { MetadataBuildingContext context, MemberDetails property) { // Comment comment) { - //noinspection unchecked,rawtypes,RedundantCast + final jakarta.persistence.Column column; + if ( property.hasDirectAnnotationUsage( MapKeyColumn.class ) ) { + column = MapKeyColumnJpaAnnotation.toColumnAnnotation( + property.getDirectAnnotationUsage( MapKeyColumn.class ), + context.getMetadataCollector().getSourceModelBuildingContext() + ); + } + else { + column = null; + } return buildColumnsFromAnnotations( - property.hasAnnotationUsage( MapKeyColumn.class ) - ? (List) List.of( property.getAnnotationUsage( MapKeyColumn.class ) ) - : null, + column == null ? null : new jakarta.persistence.Column[] { column }, // comment, Nullability.FORCED_NOT_NULL, propertyHolder, @@ -691,41 +695,41 @@ public abstract class CollectionBinder { PropertyData inferredData, String mappedBy) { final TableBinder associationTableBinder = new TableBinder(); - final AnnotationUsage assocTable = propertyHolder.getJoinTable( property ); - final AnnotationUsage collectionTable = property.getAnnotationUsage( CollectionTable.class ); + final JoinTable assocTable = propertyHolder.getJoinTable( property ); + final CollectionTable collectionTable = property.getDirectAnnotationUsage( CollectionTable.class ); - final List> annJoins; - final List> annInverseJoins; + final JoinColumn[] annJoins; + final JoinColumn[] annInverseJoins; if ( assocTable != null || collectionTable != null ) { final String catalog; final String schema; final String tableName; - final List> uniqueConstraints; - final List> joins; - final List> inverseJoins; - final List> jpaIndexes; + final UniqueConstraint[] uniqueConstraints; + final JoinColumn[] joins; + final JoinColumn[] inverseJoins; + final Index[] jpaIndexes; final String options; //JPA 2 has priority if ( collectionTable != null ) { - catalog = collectionTable.getString( "catalog" ); - schema = collectionTable.getString( "schema" ); - tableName = collectionTable.getString( "name" ); - uniqueConstraints = collectionTable.getList( "uniqueConstraints" ); - joins = collectionTable.getList( "joinColumns" ); + catalog = collectionTable.catalog(); + schema = collectionTable.schema(); + tableName = collectionTable.name(); + uniqueConstraints = collectionTable.uniqueConstraints(); + joins = collectionTable.joinColumns(); inverseJoins = null; - jpaIndexes = collectionTable.getList( "indexes" ); - options = collectionTable.getString( "options" ); + jpaIndexes = collectionTable.indexes(); + options = collectionTable.options(); } else { - catalog = assocTable.getString( "catalog" ); - schema = assocTable.getString( "schema" ); - tableName = assocTable.getString( "name" ); - uniqueConstraints = assocTable.getList( "uniqueConstraints" ); - joins = assocTable.getList( "joinColumns" ); - inverseJoins = assocTable.getList( "inverseJoinColumns" ); - jpaIndexes = assocTable.getList( "indexes" ); - options = assocTable.getString( "options" ); + catalog = assocTable.catalog(); + schema = assocTable.schema(); + tableName = assocTable.name(); + uniqueConstraints = assocTable.uniqueConstraints(); + joins = assocTable.joinColumns(); + inverseJoins = assocTable.inverseJoinColumns(); + jpaIndexes = assocTable.indexes(); + options = assocTable.options(); } collectionBinder.setExplicitAssociationTable( true ); @@ -745,8 +749,8 @@ public abstract class CollectionBinder { associationTableBinder.setJpaIndex( jpaIndexes ); associationTableBinder.setOptions( options ); //set check constraint in the second pass - annJoins = joins.isEmpty() ? null : joins; - annInverseJoins = inverseJoins == null || inverseJoins.isEmpty() ? null : inverseJoins; + annJoins = ArrayHelper.isEmpty( joins ) ? null : joins; + annInverseJoins = inverseJoins == null || ArrayHelper.isEmpty( inverseJoins ) ? null : inverseJoins; } else { annJoins = null; @@ -824,24 +828,24 @@ public abstract class CollectionBinder { this.propertyHolder = propertyHolder; } - public void setJpaOrderBy(AnnotationUsage jpaOrderBy) { + public void setJpaOrderBy(jakarta.persistence.OrderBy jpaOrderBy) { this.jpaOrderBy = jpaOrderBy; } @SuppressWarnings("removal") - public void setSqlOrderBy(AnnotationUsage sqlOrderBy) { + public void setSqlOrderBy(org.hibernate.annotations.OrderBy sqlOrderBy) { this.sqlOrderBy = sqlOrderBy; } - public void setSqlOrder(AnnotationUsage sqlOrder) { + public void setSqlOrder(SQLOrder sqlOrder) { this.sqlOrder = sqlOrder; } - public void setNaturalSort(AnnotationUsage naturalSort) { + public void setNaturalSort(SortNatural naturalSort) { this.naturalSort = naturalSort; } - public void setComparatorSort(AnnotationUsage comparatorSort) { + public void setComparatorSort(SortComparator comparatorSort) { this.comparatorSort = comparatorSort; } @@ -854,13 +858,13 @@ public abstract class CollectionBinder { MetadataBuildingContext buildingContext) { final CollectionBinder binder; - final AnnotationUsage typeAnnotation = property.getAnnotationUsage( CollectionType.class ); + final CollectionType typeAnnotation = property.getAnnotationUsage( CollectionType.class, buildingContext.getMetadataCollector().getSourceModelBuildingContext() ); if ( typeAnnotation != null ) { binder = createBinderFromCustomTypeAnnotation( property, typeAnnotation, buildingContext ); // todo (6.0) - technically, these should no longer be needed - binder.explicitType = typeAnnotation.getClassDetails( "type" ).getClassName(); - for ( AnnotationUsage param : typeAnnotation.>getList( "parameters" ) ) { - binder.explicitTypeParameters.put( param.getString( "name" ), param.getString( "value" ) ); + binder.explicitType = typeAnnotation.type().getName(); + for ( Parameter param : typeAnnotation.parameters() ) { + binder.explicitTypeParameters.put( param.name(), param.value() ); } } else { @@ -946,7 +950,7 @@ public abstract class CollectionBinder { private static CollectionBinder createBinderFromCustomTypeAnnotation( MemberDetails property, - AnnotationUsage typeAnnotation, + CollectionType typeAnnotation, MetadataBuildingContext buildingContext) { determineSemanticJavaType( property, buildingContext ); final ManagedBean customTypeBean = resolveCustomType( @@ -964,24 +968,24 @@ public abstract class CollectionBinder { public static ManagedBean resolveCustomType( MemberDetails property, - AnnotationUsage typeAnnotation, + CollectionType typeAnnotation, MetadataBuildingContext context) { final Properties parameters = extractParameters( typeAnnotation ); //noinspection unchecked,rawtypes return createCustomType( property.getDeclaringType().getName() + "." + property.getName(), - typeAnnotation.getClassDetails( "type" ).toJavaClass(), + typeAnnotation.type(), (Map) parameters, context ); } - private static Properties extractParameters(AnnotationUsage typeAnnotation) { - final List> parameterAnnotations = typeAnnotation.getList( "parameters" ); - final Properties configParams = new Properties( parameterAnnotations.size() ); - for ( AnnotationUsage parameterAnnotation : parameterAnnotations ) { - configParams.put( parameterAnnotation.getString( "name" ), parameterAnnotation.getString( "value" ) ); + private static Properties extractParameters(CollectionType typeAnnotation) { + final Parameter[] parameterAnnotations = typeAnnotation.parameters(); + final Properties configParams = new Properties( parameterAnnotations.length ); + for ( Parameter parameterAnnotation : parameterAnnotations ) { + configParams.put( parameterAnnotation.name(), parameterAnnotation.value() ); } return configParams; } @@ -1014,17 +1018,19 @@ public abstract class CollectionBinder { return CollectionClassification.ARRAY; } - if ( !property.hasAnnotationUsage( Bag.class ) ) { + final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + + if ( !property.hasAnnotationUsage( Bag.class, sourceModelContext ) ) { return determineCollectionClassification( determineSemanticJavaType( property, buildingContext ), property, buildingContext ); } - if ( property.hasAnnotationUsage( OrderColumn.class ) ) { + if ( property.hasAnnotationUsage( OrderColumn.class, sourceModelContext ) ) { throw new AnnotationException( "Attribute '" + qualify( property.getDeclaringType().getName(), property.getName() ) + "' is annotated '@Bag' and may not also be annotated '@OrderColumn'" ); } - if ( property.hasAnnotationUsage( ListIndexBase.class ) ) { + if ( property.hasAnnotationUsage( ListIndexBase.class, sourceModelContext ) ) { throw new AnnotationException( "Attribute '" + qualify( property.getDeclaringType().getName(), property.getName() ) + "' is annotated '@Bag' and may not also be annotated '@ListIndexBase'" ); @@ -1059,38 +1065,39 @@ public abstract class CollectionBinder { return CollectionClassification.ARRAY; } - if ( property.hasAnnotationUsage( CollectionId.class ) - || property.hasAnnotationUsage( CollectionIdJdbcType.class ) - || property.hasAnnotationUsage( CollectionIdJdbcTypeCode.class ) - || property.hasAnnotationUsage( CollectionIdJavaType.class ) ) { + if ( property.hasDirectAnnotationUsage( CollectionId.class ) + || property.hasDirectAnnotationUsage( CollectionIdJdbcType.class ) + || property.hasDirectAnnotationUsage( CollectionIdJdbcTypeCode.class ) + || property.hasDirectAnnotationUsage( CollectionIdJavaType.class ) ) { // explicitly an ID_BAG return CollectionClassification.ID_BAG; } if ( java.util.List.class.isAssignableFrom( semanticJavaType ) ) { - if ( property.hasAnnotationUsage( OrderColumn.class ) - || property.hasAnnotationUsage( org.hibernate.annotations.IndexColumn.class ) - || property.hasAnnotationUsage( ListIndexBase.class ) - || property.hasAnnotationUsage( ListIndexJdbcType.class ) - || property.hasAnnotationUsage( ListIndexJdbcTypeCode.class ) - || property.hasAnnotationUsage( ListIndexJavaType.class ) ) { + if ( property.hasDirectAnnotationUsage( OrderColumn.class ) + || property.hasDirectAnnotationUsage( org.hibernate.annotations.IndexColumn.class ) + || property.hasDirectAnnotationUsage( ListIndexBase.class ) + || property.hasDirectAnnotationUsage( ListIndexJdbcType.class ) + || property.hasDirectAnnotationUsage( ListIndexJdbcTypeCode.class ) + || property.hasDirectAnnotationUsage( ListIndexJavaType.class ) ) { // it is implicitly a LIST because of presence of explicit List index config return CollectionClassification.LIST; } - if ( property.hasAnnotationUsage( jakarta.persistence.OrderBy.class ) - || property.hasAnnotationUsage( org.hibernate.annotations.OrderBy.class ) ) { + if ( property.hasDirectAnnotationUsage( jakarta.persistence.OrderBy.class ) + || property.hasDirectAnnotationUsage( org.hibernate.annotations.OrderBy.class ) ) { return CollectionClassification.BAG; } - final AnnotationUsage manyToMany = property.getAnnotationUsage( ManyToMany.class ); - if ( manyToMany != null && !manyToMany.getString( "mappedBy" ).isEmpty() ) { + final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + final ManyToMany manyToMany = property.getAnnotationUsage( ManyToMany.class, sourceModelContext ); + if ( manyToMany != null && !manyToMany.mappedBy().isEmpty() ) { // We don't support @OrderColumn on the non-owning side of a many-to-many association. return CollectionClassification.BAG; } - final AnnotationUsage oneToMany = property.getAnnotationUsage( OneToMany.class ); - if ( oneToMany != null && !oneToMany.getString( "mappedBy" ).isEmpty() ) { + final OneToMany oneToMany = property.getAnnotationUsage( OneToMany.class, sourceModelContext ); + if ( oneToMany != null && !oneToMany.mappedBy().isEmpty() ) { // Unowned to-many mappings are always considered BAG by default return CollectionClassification.BAG; } @@ -1116,7 +1123,7 @@ public abstract class CollectionBinder { } if ( java.util.Collection.class.isAssignableFrom( semanticJavaType ) ) { - if ( property.hasAnnotationUsage( CollectionId.class ) ) { + if ( property.hasDirectAnnotationUsage( CollectionId.class ) ) { return CollectionClassification.ID_BAG; } else { @@ -1166,6 +1173,12 @@ public abstract class CollectionBinder { this.collectionElementType = collectionElementType; } + public void setTargetEntity(Class targetEntity) { + final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + final ClassDetailsRegistry classDetailsRegistry = sourceModelContext.getClassDetailsRegistry(); + setTargetEntity( classDetailsRegistry.resolveClassDetails( targetEntity.getName() ) ); + } + public void setTargetEntity(ClassDetails targetEntity) { setTargetEntity( new ClassTypeDetailsImpl( targetEntity, TypeDetails.Kind.CLASS ) ); } @@ -1221,11 +1234,11 @@ public abstract class CollectionBinder { } private boolean isMutable() { - return !property.hasAnnotationUsage( Immutable.class ); + return !property.hasDirectAnnotationUsage( Immutable.class ); } private void checkMapKeyColumn() { - if ( property.hasAnnotationUsage( MapKeyColumn.class ) && hasMapKeyProperty ) { + if ( property.hasDirectAnnotationUsage( MapKeyColumn.class ) && hasMapKeyProperty ) { throw new AnnotationException( "Collection '" + qualify( propertyHolder.getPath(), propertyName ) + "' is annotated both '@MapKey' and '@MapKeyColumn'" ); } @@ -1245,8 +1258,8 @@ public abstract class CollectionBinder { } private void bindOptimisticLock(boolean isMappedBy) { - final AnnotationUsage lockAnn = property.getAnnotationUsage( OptimisticLock.class ); - final boolean includeInOptimisticLockChecks = lockAnn != null ? !lockAnn.getBoolean( "excluded" ) : !isMappedBy; + final OptimisticLock lockAnn = property.getDirectAnnotationUsage( OptimisticLock.class ); + final boolean includeInOptimisticLockChecks = lockAnn != null ? !lockAnn.excluded() : !isMappedBy; collection.setOptimisticLocked( includeInOptimisticLockChecks ); } @@ -1277,8 +1290,8 @@ public abstract class CollectionBinder { private void detectMappedByProblem(boolean isMappedBy) { if ( isMappedBy - && ( property.hasAnnotationUsage( JoinColumn.class ) - || property.hasAnnotationUsage( JoinColumns.class ) ) ) { + && ( property.hasDirectAnnotationUsage( JoinColumn.class ) + || property.hasDirectAnnotationUsage( JoinColumns.class ) ) ) { throw new AnnotationException( "Association '" + qualify( propertyHolder.getPath(), propertyName ) + "' is 'mappedBy' another entity and may not specify the '@JoinColumn'" ); @@ -1293,9 +1306,9 @@ public abstract class CollectionBinder { if ( !isMappedBy && oneToMany - && property.hasAnnotationUsage( OnDelete.class ) - && !property.hasAnnotationUsage( JoinColumn.class ) - && !property.hasAnnotationUsage( JoinColumns.class )) { + && property.hasDirectAnnotationUsage( OnDelete.class ) + && !property.hasDirectAnnotationUsage( JoinColumn.class ) + && !property.hasDirectAnnotationUsage( JoinColumns.class )) { throw new AnnotationException( "Unidirectional '@OneToMany' association '" + qualify( propertyHolder.getPath(), propertyName ) + "' is annotated '@OnDelete' and must explicitly specify a '@JoinColumn'" ); @@ -1312,9 +1325,9 @@ public abstract class CollectionBinder { collection.setOrphanDelete( true ); } binder.setLazy( collection.isLazy() ); - final AnnotationUsage lazyGroupAnnotation = property.getAnnotationUsage( LazyGroup.class ); + final LazyGroup lazyGroupAnnotation = property.getDirectAnnotationUsage( LazyGroup.class ); if ( lazyGroupAnnotation != null ) { - binder.setLazyGroup( lazyGroupAnnotation.getString( "value" ) ); + binder.setLazyGroup( lazyGroupAnnotation.value() ); } binder.setAccessType( accessType ); binder.setMemberDetails( property ); @@ -1335,59 +1348,59 @@ public abstract class CollectionBinder { private void bindLoader() { //SQL overriding - final AnnotationUsage sqlInsert = property.getAnnotationUsage( SQLInsert.class ); + final SQLInsert sqlInsert = property.getDirectAnnotationUsage( SQLInsert.class ); if ( sqlInsert != null ) { collection.setCustomSQLInsert( - sqlInsert.getString( "sql" ).trim(), - sqlInsert.getBoolean( "callable" ), - fromResultCheckStyle( sqlInsert.getEnum( "check" ) ) + sqlInsert.sql().trim(), + sqlInsert.callable(), + fromResultCheckStyle( sqlInsert.check() ) ); - final ClassDetails verifier = sqlInsert.getClassDetails( "verify" ); - if ( !verifier.getName().equals( Expectation.class.getName() ) ) { - collection.setInsertExpectation( getDefaultSupplier( verifier.toJavaClass() ) ); + final Class verifier = sqlInsert.verify(); + if ( !Expectation.class.equals( verifier ) ) { + collection.setInsertExpectation( getDefaultSupplier( verifier ) ); } } - final AnnotationUsage sqlUpdate = property.getAnnotationUsage( SQLUpdate.class ); + final SQLUpdate sqlUpdate = property.getDirectAnnotationUsage( SQLUpdate.class ); if ( sqlUpdate != null ) { collection.setCustomSQLUpdate( - sqlUpdate.getString( "sql" ).trim(), - sqlUpdate.getBoolean( "callable" ), - fromResultCheckStyle( sqlUpdate.getEnum( "check" ) ) + sqlUpdate.sql().trim(), + sqlUpdate.callable(), + fromResultCheckStyle( sqlUpdate.check() ) ); - final ClassDetails verifier = sqlUpdate.getClassDetails( "verify" ); - if ( !verifier.getName().equals( Expectation.class.getName() ) ) { - collection.setUpdateExpectation( getDefaultSupplier( verifier.toJavaClass() ) ); + final Class verifier = sqlUpdate.verify(); + if ( !Expectation.class.equals( verifier ) ) { + collection.setUpdateExpectation( getDefaultSupplier( verifier ) ); } } - final AnnotationUsage sqlDelete = property.getAnnotationUsage( SQLDelete.class ); + final SQLDelete sqlDelete = property.getDirectAnnotationUsage( SQLDelete.class ); if ( sqlDelete != null ) { collection.setCustomSQLDelete( - sqlDelete.getString( "sql" ).trim(), - sqlDelete.getBoolean( "callable" ), - fromResultCheckStyle( sqlDelete.getEnum( "check" ) ) + sqlDelete.sql().trim(), + sqlDelete.callable(), + fromResultCheckStyle( sqlDelete.check() ) ); - final ClassDetails verifier = sqlDelete.getClassDetails( "verify" ); - if ( !verifier.getName().equals( Expectation.class.getName() ) ) { - collection.setDeleteExpectation( getDefaultSupplier( verifier.toJavaClass() ) ); + final Class verifier = sqlDelete.verify(); + if ( !Expectation.class.equals( verifier ) ) { + collection.setDeleteExpectation( getDefaultSupplier( verifier ) ); } } - final AnnotationUsage sqlDeleteAll = property.getAnnotationUsage( SQLDeleteAll.class ); + final SQLDeleteAll sqlDeleteAll = property.getDirectAnnotationUsage( SQLDeleteAll.class ); if ( sqlDeleteAll != null ) { collection.setCustomSQLDeleteAll( - sqlDeleteAll.getString( "sql" ).trim(), - sqlDeleteAll.getBoolean( "callable" ), - fromResultCheckStyle( sqlDeleteAll.getEnum( "check" ) ) + sqlDeleteAll.sql().trim(), + sqlDeleteAll.callable(), + fromResultCheckStyle( sqlDeleteAll.check() ) ); - final ClassDetails verifier = sqlDeleteAll.getClassDetails( "verify" ); - if ( !verifier.getName().equals( Expectation.class.getName() ) ) { - collection.setDeleteAllExpectation( getDefaultSupplier( verifier.toJavaClass() ) ); + final Class verifier = sqlDeleteAll.verify(); + if ( !Expectation.class.equals( verifier ) ) { + collection.setDeleteAllExpectation( getDefaultSupplier( verifier ) ); } } - final AnnotationUsage sqlSelect = property.getAnnotationUsage( SQLSelect.class ); + final SQLSelect sqlSelect = property.getDirectAnnotationUsage( SQLSelect.class ); if ( sqlSelect != null ) { final String loaderName = collection.getRole() + "$SQLSelect"; collection.setLoaderName( loaderName ); @@ -1395,16 +1408,16 @@ public abstract class CollectionBinder { QueryBinder.bindNativeQuery( loaderName, sqlSelect, null, buildingContext ); } - final AnnotationUsage hqlSelect = property.getAnnotationUsage( HQLSelect.class ); + final HQLSelect hqlSelect = property.getDirectAnnotationUsage( HQLSelect.class ); if ( hqlSelect != null ) { final String loaderName = collection.getRole() + "$HQLSelect"; collection.setLoaderName( loaderName ); QueryBinder.bindQuery( loaderName, hqlSelect, buildingContext ); } - final AnnotationUsage loader = property.getAnnotationUsage( Loader.class ); + final Loader loader = property.getDirectAnnotationUsage( Loader.class ); if ( loader != null ) { - collection.setLoaderName( loader.getString( "namedQuery" ) ); + collection.setLoaderName( loader.namedQuery() ); } } @@ -1419,7 +1432,7 @@ public abstract class CollectionBinder { comparatorClass = null; } else if ( comparatorSort != null ) { - comparatorClass = comparatorSort.getClassDetails( "value" ).toJavaClass(); + comparatorClass = comparatorSort.value(); } else { comparatorClass = null; @@ -1432,10 +1445,10 @@ public abstract class CollectionBinder { if ( ordered ) { // we can only apply the sql-based order by up front. The jpa order by has to wait for second pass if ( sqlOrderBy != null ) { - collection.setOrderBy( sqlOrderBy.getString( "clause" ) ); + collection.setOrderBy( sqlOrderBy.clause() ); } if ( sqlOrder != null ) { - collection.setOrderBy( sqlOrder.getString( "value" ) ); + collection.setOrderBy( sqlOrder.value() ); } } @@ -1508,8 +1521,12 @@ public abstract class CollectionBinder { handleFetchProfileOverrides(); } + private SourceModelBuildingContext sourceModelContext() { + return buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + } + private void handleFetchProfileOverrides() { - property.forEachAnnotationUsage( FetchProfileOverride.class, (usage) -> { + property.forEachAnnotationUsage( FetchProfileOverride.class, sourceModelContext(), (usage) -> { buildingContext.getMetadataCollector().addSecondPass( new FetchSecondPass( usage, propertyHolder, @@ -1520,10 +1537,10 @@ public abstract class CollectionBinder { } private void handleFetch() { - final AnnotationUsage fetchAnnotation = property.getAnnotationUsage( Fetch.class ); + final Fetch fetchAnnotation = property.getDirectAnnotationUsage( Fetch.class ); if ( fetchAnnotation != null ) { // Hibernate @Fetch annotation takes precedence - setHibernateFetchMode( fetchAnnotation.getEnum( "value" ) ); + setHibernateFetchMode( fetchAnnotation.value() ); } else { collection.setFetchMode( getFetchMode( getJpaFetchType() ) ); @@ -1553,9 +1570,9 @@ public abstract class CollectionBinder { @SuppressWarnings("deprecation") private void handleLazy() { final FetchType jpaFetchType = getJpaFetchType(); - final AnnotationUsage lazyCollectionAnnotation = property.getAnnotationUsage( LazyCollection.class ); + final LazyCollection lazyCollectionAnnotation = property.getDirectAnnotationUsage( LazyCollection.class ); if ( lazyCollectionAnnotation != null ) { - final LazyCollectionOption option = lazyCollectionAnnotation.getEnum( "value" ); + final LazyCollectionOption option = lazyCollectionAnnotation.value(); boolean eager = option == LazyCollectionOption.FALSE; if ( !eager && jpaFetchType == EAGER ) { throw new AnnotationException("Collection '" + safeCollectionRole() @@ -1571,20 +1588,20 @@ public abstract class CollectionBinder { } private FetchType getJpaFetchType() { - final AnnotationUsage oneToMany = property.getAnnotationUsage( OneToMany.class ); - final AnnotationUsage manyToMany = property.getAnnotationUsage( ManyToMany.class ); - final AnnotationUsage elementCollection = property.getAnnotationUsage( ElementCollection.class ); - final AnnotationUsage manyToAny = property.getAnnotationUsage( ManyToAny.class ); + final OneToMany oneToMany = property.getDirectAnnotationUsage( OneToMany.class ); + final ManyToMany manyToMany = property.getDirectAnnotationUsage( ManyToMany.class ); + final ElementCollection elementCollection = property.getDirectAnnotationUsage( ElementCollection.class ); + final ManyToAny manyToAny = property.getDirectAnnotationUsage( ManyToAny.class ); if ( oneToMany != null ) { - return oneToMany.getEnum( "fetch" ); + return oneToMany.fetch(); } if ( manyToMany != null ) { - return manyToMany.getEnum( "fetch" ); + return manyToMany.fetch(); } if ( elementCollection != null ) { - return elementCollection.getEnum( "fetch" ); + return elementCollection.fetch(); } if ( manyToAny != null ) { @@ -1756,7 +1773,7 @@ public abstract class CollectionBinder { private void handleJpaOrderBy(Collection collection, PersistentClass associatedClass) { if ( jpaOrderBy != null ) { - final String orderByFragment = buildOrderByClauseFromHql( jpaOrderBy.getString( "value" ), associatedClass ); + final String orderByFragment = buildOrderByClauseFromHql( jpaOrderBy.value(), associatedClass ); if ( isNotEmpty( orderByFragment ) ) { collection.setOrderBy( orderByFragment ); } @@ -1764,11 +1781,11 @@ public abstract class CollectionBinder { } private void bindSynchronize() { - final AnnotationUsage synchronizeAnnotation = property.getAnnotationUsage( Synchronize.class ); + final Synchronize synchronizeAnnotation = property.getDirectAnnotationUsage( Synchronize.class ); if ( synchronizeAnnotation != null ) { final JdbcEnvironment jdbcEnvironment = buildingContext.getMetadataCollector().getDatabase().getJdbcEnvironment(); - for ( String table : synchronizeAnnotation.getList( "value" ) ) { - String physicalName = synchronizeAnnotation.getBoolean( "logical" ) + for ( String table : synchronizeAnnotation.value() ) { + String physicalName = synchronizeAnnotation.logical() ? toPhysicalName( jdbcEnvironment, table ) : table; collection.addSynchronizedTable( physicalName ); @@ -1786,47 +1803,47 @@ public abstract class CollectionBinder { } private void bindFilters(boolean hasAssociationTable) { - property.forEachAnnotationUsage( Filter.class, (usage) -> { + property.forEachAnnotationUsage( Filter.class, sourceModelContext(), (usage) -> { addFilter( hasAssociationTable, usage ); } ); - property.forEachAnnotationUsage( FilterJoinTable.class, (usage) -> { + property.forEachAnnotationUsage( FilterJoinTable.class, sourceModelContext(), (usage) -> { addFilterJoinTable( hasAssociationTable, usage ); } ); } - private void addFilter(boolean hasAssociationTable, AnnotationUsage filterAnnotation) { + private void addFilter(boolean hasAssociationTable, Filter filterAnnotation) { final Map aliasTableMap = new HashMap<>(); final Map aliasEntityMap = new HashMap<>(); - final List> aliasAnnotations = filterAnnotation.getList( "aliases" ); - for ( AnnotationUsage aliasAnnotation : aliasAnnotations ) { - final String alias = aliasAnnotation.getString( "alias" ); + final SqlFragmentAlias[] aliasAnnotations = filterAnnotation.aliases(); + for ( SqlFragmentAlias aliasAnnotation : aliasAnnotations ) { + final String alias = aliasAnnotation.alias(); - final String table = aliasAnnotation.getString( "table" ); + final String table = aliasAnnotation.table(); if ( isNotEmpty( table ) ) { aliasTableMap.put( alias, table ); } - final ClassDetails entityClassDetails = aliasAnnotation.getClassDetails( "entity" ); - if ( entityClassDetails != ClassDetails.VOID_CLASS_DETAILS ) { + final Class entityClassDetails = aliasAnnotation.entity(); + if ( entityClassDetails != void.class ) { aliasEntityMap.put( alias, entityClassDetails.getName() ); } } if ( hasAssociationTable ) { collection.addManyToManyFilter( - filterAnnotation.getString( "name" ), + filterAnnotation.name(), getFilterCondition( filterAnnotation ), - filterAnnotation.getBoolean( "deduceAliasInjectionPoints" ), + filterAnnotation.deduceAliasInjectionPoints(), aliasTableMap, aliasEntityMap ); } else { collection.addFilter( - filterAnnotation.getString( "name" ), + filterAnnotation.name(), getFilterCondition( filterAnnotation ), - filterAnnotation.getBoolean( "deduceAliasInjectionPoints" ), + filterAnnotation.deduceAliasInjectionPoints(), aliasTableMap, aliasEntityMap ); @@ -1866,12 +1883,12 @@ public abstract class CollectionBinder { } private String getWhereJoinTableClause() { - final AnnotationUsage joinTableRestriction = property.getAnnotationUsage( SQLJoinTableRestriction.class ); + final SQLJoinTableRestriction joinTableRestriction = property.getDirectAnnotationUsage( SQLJoinTableRestriction.class ); if ( joinTableRestriction != null ) { - return joinTableRestriction.getString( "value" ); + return joinTableRestriction.value(); } - final AnnotationUsage whereJoinTable = property.getAnnotationUsage( WhereJoinTable.class ); - return whereJoinTable == null ? null : whereJoinTable.getString( "clause" ); + final WhereJoinTable whereJoinTable = property.getDirectAnnotationUsage( WhereJoinTable.class ); + return whereJoinTable == null ? null : whereJoinTable.clause(); } private String getWhereClause() { @@ -1885,14 +1902,14 @@ public abstract class CollectionBinder { } private String getWhereOnCollectionClause() { - final AnnotationUsage restrictionOnCollection = getOverridableAnnotation( property, SQLRestriction.class, getBuildingContext() ); + final SQLRestriction restrictionOnCollection = getOverridableAnnotation( property, SQLRestriction.class, getBuildingContext() ); if ( restrictionOnCollection != null ) { - return restrictionOnCollection.getString( "value" ); + return restrictionOnCollection.value(); } - final AnnotationUsage whereOnCollection = getOverridableAnnotation( property, Where.class, buildingContext ); + final Where whereOnCollection = getOverridableAnnotation( property, Where.class, buildingContext ); if ( whereOnCollection != null ) { - return whereOnCollection.getString( "clause" ); + return whereOnCollection.clause(); } return null; @@ -1901,17 +1918,17 @@ public abstract class CollectionBinder { private String getWhereOnClassClause() { final TypeDetails elementType = property.getElementType(); if ( elementType != null && useEntityWhereClauseForCollections( buildingContext ) ) { - final AnnotationUsage restrictionOnClass = getOverridableAnnotation( + final SQLRestriction restrictionOnClass = getOverridableAnnotation( property.getAssociatedType().determineRawClass(), SQLRestriction.class, buildingContext ); if ( restrictionOnClass != null ) { - return restrictionOnClass.getString( "value" ); + return restrictionOnClass.value(); } - final AnnotationUsage whereOnClass = getOverridableAnnotation( property, Where.class, buildingContext ); + final Where whereOnClass = getOverridableAnnotation( property, Where.class, buildingContext ); if ( whereOnClass != null ) { - return whereOnClass.getString( "clause" ); + return whereOnClass.clause(); } return null; } @@ -1920,29 +1937,29 @@ public abstract class CollectionBinder { } } - private void addFilterJoinTable(boolean hasAssociationTable, AnnotationUsage filter) { + private void addFilterJoinTable(boolean hasAssociationTable, FilterJoinTable filter) { if ( hasAssociationTable ) { final Map aliasTableMap = new HashMap<>(); final Map aliasEntityMap = new HashMap<>(); - final List> aliasAnnotations = filter.getList( "aliases" ); - for ( AnnotationUsage aliasAnnotation : aliasAnnotations ) { - final String alias = aliasAnnotation.getString( "alias" ); + final SqlFragmentAlias[] aliasAnnotations = filter.aliases(); + for ( SqlFragmentAlias aliasAnnotation : aliasAnnotations ) { + final String alias = aliasAnnotation.alias(); - final String table = aliasAnnotation.getString( "table" ); + final String table = aliasAnnotation.table(); if ( isNotEmpty( table ) ) { aliasTableMap.put( alias, table ); } - final ClassDetails entityClassDetails = aliasAnnotation.getClassDetails( "entity" ); - if ( entityClassDetails != ClassDetails.VOID_CLASS_DETAILS ) { + final Class entityClassDetails = aliasAnnotation.entity(); + if ( entityClassDetails != void.class ) { aliasEntityMap.put( alias, entityClassDetails.getName() ); } } collection.addFilter( - filter.getString( "name" ), + filter.name(), getFilterConditionForJoinTable( filter ), - filter.getBoolean( "deduceAliasInjectionPoints" ), + filter.deduceAliasInjectionPoints(), aliasTableMap, aliasEntityMap ); @@ -1953,41 +1970,41 @@ public abstract class CollectionBinder { } } - private String getFilterConditionForJoinTable(AnnotationUsage filterJoinTableAnnotation) { - final String condition = filterJoinTableAnnotation.getString( "condition" ); + private String getFilterConditionForJoinTable(FilterJoinTable filterJoinTableAnnotation) { + final String condition = filterJoinTableAnnotation.condition(); return condition.isEmpty() - ? getDefaultFilterCondition( filterJoinTableAnnotation.getString( "name" ), filterJoinTableAnnotation ) + ? getDefaultFilterCondition( filterJoinTableAnnotation.name(), filterJoinTableAnnotation ) : condition; } - private String getFilterCondition(AnnotationUsage filter) { - final String condition = filter.getString( "condition" ); + private String getFilterCondition(Filter filter) { + final String condition = filter.condition(); return condition.isEmpty() - ? getDefaultFilterCondition( filter.getString( "name" ), filter ) + ? getDefaultFilterCondition( filter.name(), filter ) : condition; } - private String getDefaultFilterCondition(String name, AnnotationUsage annotation) { + private String getDefaultFilterCondition(String name, Annotation annotation) { final FilterDefinition definition = buildingContext.getMetadataCollector().getFilterDefinition( name ); if ( definition == null ) { throw new AnnotationException( "Collection '" + qualify( propertyHolder.getPath(), propertyName ) - + "' has a '@" + annotation.getAnnotationType().getSimpleName() + + "' has a '@" + annotation.annotationType().getSimpleName() + "' for an undefined filter named '" + name + "'" ); } final String defaultCondition = definition.getDefaultFilterCondition(); if ( isEmpty( defaultCondition ) ) { throw new AnnotationException( "Collection '" + qualify( propertyHolder.getPath(), propertyName ) + - "' has a '@" + annotation.getAnnotationType().getSimpleName() + "' has a '@" + annotation.annotationType().getSimpleName() + "' with no 'condition' and no default condition was given by the '@FilterDef' named '" + name + "'" ); } return defaultCondition; } - public void setCache(AnnotationUsage cache) { + public void setCache(Cache cache) { if ( cache != null ) { - cacheRegionName = nullIfEmpty( cache.getString( "region" )); - cacheConcurrencyStrategy = EntityBinder.getCacheConcurrencyStrategy( cache.getEnum( "usage" ) ); + cacheRegionName = nullIfEmpty( cache.region() ); + cacheConcurrencyStrategy = EntityBinder.getCacheConcurrencyStrategy( cache.usage() ); } else { cacheConcurrencyStrategy = null; @@ -1995,8 +2012,8 @@ public abstract class CollectionBinder { } } - public void setQueryCacheLayout(AnnotationUsage queryCacheLayout) { - this.queryCacheLayout = queryCacheLayout == null ? null : queryCacheLayout.getEnum( "layout" ); + public void setQueryCacheLayout(QueryCacheLayout queryCacheLayout) { + this.queryCacheLayout = queryCacheLayout == null ? null : queryCacheLayout.layout(); } public void setOneToMany(boolean oneToMany) { @@ -2007,10 +2024,10 @@ public abstract class CollectionBinder { this.indexColumn = indexColumn; } - public void setMapKey(AnnotationUsage key) { + public void setMapKey(MapKey key) { hasMapKeyProperty = key != null; if ( hasMapKeyProperty ) { - mapKeyPropertyName = nullIfEmpty( key.getString( "name" ) ); + mapKeyPropertyName = nullIfEmpty( key.name() ); } } @@ -2091,50 +2108,50 @@ public abstract class CollectionBinder { collection.setKey( key ); if ( property != null ) { - final AnnotationUsage fk = property.getAnnotationUsage( org.hibernate.annotations.ForeignKey.class ); - if ( fk != null && !fk.getString( "name" ).isEmpty() ) { - key.setForeignKeyName( fk.getString( "name" ) ); + final org.hibernate.annotations.ForeignKey fk = property.getDirectAnnotationUsage( org.hibernate.annotations.ForeignKey.class ); + if ( fk != null && !fk.name().isEmpty() ) { + key.setForeignKeyName( fk.name() ); } else { - final AnnotationUsage collectionTableAnn = property.getAnnotationUsage( CollectionTable.class ); + final CollectionTable collectionTableAnn = property.getDirectAnnotationUsage( CollectionTable.class ); if ( collectionTableAnn != null ) { - final AnnotationUsage foreignKey = collectionTableAnn.getNestedUsage( "foreignKey" ); - final ConstraintMode constraintMode = foreignKey.getEnum( "value" ); + final ForeignKey foreignKey = collectionTableAnn.foreignKey(); + final ConstraintMode constraintMode = foreignKey.value(); if ( constraintMode == NO_CONSTRAINT || constraintMode == PROVIDER_DEFAULT && noConstraintByDefault ) { key.disableForeignKey(); } else { - key.setForeignKeyName( nullIfEmpty( foreignKey.getString( "name" ) ) ); - key.setForeignKeyDefinition( nullIfEmpty( foreignKey.getString( "foreignKeyDefinition" ) ) ); + key.setForeignKeyName( nullIfEmpty( foreignKey.name() ) ); + key.setForeignKeyDefinition( nullIfEmpty( foreignKey.foreignKeyDefinition() ) ); if ( key.getForeignKeyName() == null && key.getForeignKeyDefinition() == null - && collectionTableAnn.getList( "joinColumns" ).size() == 1 ) { + && collectionTableAnn.joinColumns().length == 1 ) { //noinspection unchecked - final AnnotationUsage joinColumn = (AnnotationUsage) collectionTableAnn.getList( "joinColumns" ).get( 0 ); - final AnnotationUsage nestedForeignKey = joinColumn.getNestedUsage( "foreignKey" ); - key.setForeignKeyName( nullIfEmpty( nestedForeignKey.getString( "name" ) ) ); - key.setForeignKeyDefinition( nullIfEmpty( nestedForeignKey.getString( "foreignKeyDefinition" ) ) ); + final JoinColumn joinColumn = collectionTableAnn.joinColumns()[0]; + final ForeignKey nestedForeignKey = joinColumn.foreignKey(); + key.setForeignKeyName( nullIfEmpty( nestedForeignKey.name() ) ); + key.setForeignKeyDefinition( nullIfEmpty( nestedForeignKey.foreignKeyDefinition() ) ); } } } else { - final AnnotationUsage joinTableAnn = property.getAnnotationUsage( JoinTable.class ); + final JoinTable joinTableAnn = property.getDirectAnnotationUsage( JoinTable.class ); if ( joinTableAnn != null ) { - final AnnotationUsage foreignKey = joinTableAnn.getNestedUsage( "foreignKey" ); - String foreignKeyName = foreignKey.getString( "name" ); - String foreignKeyDefinition = foreignKey.getString( "foreignKeyDefinition" ); - ConstraintMode foreignKeyValue = foreignKey.getEnum( "value" ); - List> joinColumnAnnotations = joinTableAnn.getList( "joinColumns" ); - if ( !joinColumnAnnotations.isEmpty() ) { - final AnnotationUsage joinColumnAnn = joinColumnAnnotations.get( 0 ); - final AnnotationUsage joinColumnForeignKey = joinColumnAnn.getNestedUsage( "foreignKey" ); + final ForeignKey foreignKey = joinTableAnn.foreignKey(); + String foreignKeyName = foreignKey.name(); + String foreignKeyDefinition = foreignKey.foreignKeyDefinition(); + ConstraintMode foreignKeyValue = foreignKey.value(); + final JoinColumn[] joinColumnAnnotations = joinTableAnn.joinColumns(); + if ( !ArrayHelper.isEmpty( joinColumnAnnotations ) ) { + final JoinColumn joinColumnAnn = joinColumnAnnotations[0]; + final ForeignKey joinColumnForeignKey = joinColumnAnn.foreignKey(); if ( foreignKeyName.isEmpty() ) { - foreignKeyName = joinColumnForeignKey.getString( "name" ); - foreignKeyDefinition = joinColumnForeignKey.getString( "foreignKeyDefinition" ); + foreignKeyName = joinColumnForeignKey.name(); + foreignKeyDefinition = joinColumnForeignKey.foreignKeyDefinition(); } if ( foreignKeyValue != NO_CONSTRAINT ) { - foreignKeyValue = joinColumnForeignKey.getEnum( "value" ); + foreignKeyValue = joinColumnForeignKey.value(); } } if ( foreignKeyValue == NO_CONSTRAINT @@ -2148,24 +2165,24 @@ public abstract class CollectionBinder { } else { final String propertyPath = qualify( propertyHolder.getPath(), property.getName() ); - final AnnotationUsage foreignKey = propertyHolder.getOverriddenForeignKey( propertyPath ); + final ForeignKey foreignKey = propertyHolder.getOverriddenForeignKey( propertyPath ); if ( foreignKey != null ) { handleForeignKeyConstraint( noConstraintByDefault, key, foreignKey ); } else { - final AnnotationUsage oneToManyAnn = property.getAnnotationUsage( OneToMany.class ); - final AnnotationUsage onDeleteAnn = property.getAnnotationUsage( OnDelete.class ); + final OneToMany oneToManyAnn = property.getDirectAnnotationUsage( OneToMany.class ); + final OnDelete onDeleteAnn = property.getDirectAnnotationUsage( OnDelete.class ); if ( oneToManyAnn != null - && !oneToManyAnn.getString( "mappedBy" ).isEmpty() - && ( onDeleteAnn == null || onDeleteAnn.getEnum( "action" ) != OnDeleteAction.CASCADE ) ) { + && !oneToManyAnn.mappedBy().isEmpty() + && ( onDeleteAnn == null || onDeleteAnn.action() != OnDeleteAction.CASCADE ) ) { // foreign key should be up to @ManyToOne side // @OnDelete generate "on delete cascade" foreign key key.disableForeignKey(); } else { - final AnnotationUsage joinColumnAnn = property.getSingleAnnotationUsage( JoinColumn.class ); + final JoinColumn joinColumnAnn = property.getDirectAnnotationUsage( JoinColumn.class ); if ( joinColumnAnn != null ) { - handleForeignKeyConstraint( noConstraintByDefault, key, joinColumnAnn.getNestedUsage( "foreignKey" ) ); + handleForeignKeyConstraint( noConstraintByDefault, key, joinColumnAnn.foreignKey() ); } } } @@ -2180,15 +2197,15 @@ public abstract class CollectionBinder { private static void handleForeignKeyConstraint( boolean noConstraintByDefault, DependantValue key, - AnnotationUsage foreignKey) { - final ConstraintMode constraintMode = foreignKey.getEnum( "value" ); + ForeignKey foreignKey) { + final ConstraintMode constraintMode = foreignKey.value(); if ( constraintMode == NO_CONSTRAINT || constraintMode == PROVIDER_DEFAULT && noConstraintByDefault) { key.disableForeignKey(); } else { - key.setForeignKeyName( nullIfEmpty( foreignKey.getString( "name" ) ) ); - key.setForeignKeyDefinition( nullIfEmpty( foreignKey.getString( "foreignKeyDefinition" ) ) ); + key.setForeignKeyName( nullIfEmpty( foreignKey.name() ) ); + key.setForeignKeyDefinition( nullIfEmpty( foreignKey.foreignKeyDefinition() ) ); } } @@ -2219,7 +2236,7 @@ public abstract class CollectionBinder { final String hqlOrderBy = extractHqlOrderBy( jpaOrderBy ); final boolean isCollectionOfEntities = targetEntity != null; - final boolean isManyToAny = property.hasAnnotationUsage( ManyToAny.class ); + final boolean isManyToAny = property.hasDirectAnnotationUsage( ManyToAny.class ); logManyToManySecondPass( oneToMany, isCollectionOfEntities, isManyToAny ); @@ -2331,7 +2348,7 @@ public abstract class CollectionBinder { // We create a new entity binder here because it is needed for processing the embeddable // Since this is an element collection, there is no real entity binder though, // so we just create an "empty shell" for the purpose of avoiding null checks in the fillEmbeddable() method etc. - final EntityBinder entityBinder = new EntityBinder(); + final EntityBinder entityBinder = new EntityBinder( buildingContext ); // Copy over the access type that we resolve for the element collection, // so that nested components use the same access type. This fixes HHH-15966 entityBinder.setPropertyAccessType( accessType ); @@ -2360,10 +2377,10 @@ public abstract class CollectionBinder { } static AccessType accessType(MemberDetails property, PersistentClass owner) { - final AnnotationUsage accessAnn = property.getAnnotationUsage( Access.class ); + final Access accessAnn = property.getDirectAnnotationUsage( Access.class ); if ( accessAnn != null ) { // the attribute is locally annotated with `@Access`, use that - return accessAnn.getEnum( "value" ) == PROPERTY + return accessAnn.value() == PROPERTY ? AccessType.PROPERTY : AccessType.FIELD; } @@ -2396,8 +2413,8 @@ public abstract class CollectionBinder { } else { //force in case of attribute override - final boolean attributeOverride = property.hasAnnotationUsage( AttributeOverride.class ) - || property.hasAnnotationUsage( AttributeOverrides.class ); + final boolean attributeOverride = property.hasDirectAnnotationUsage( AttributeOverride.class ) + || property.hasDirectAnnotationUsage( AttributeOverrides.class ); // todo : force in the case of Convert annotation(s) with embedded paths (beyond key/value prefixes)? return isEmbedded || attributeOverride ? EMBEDDABLE @@ -2450,28 +2467,28 @@ public abstract class CollectionBinder { collection.setManyToManyOrdering( buildOrderByClauseFromHql( hqlOrderBy, collectionEntity ) ); } - final AnnotationUsage fk = property.getAnnotationUsage( org.hibernate.annotations.ForeignKey.class ); - if ( fk != null && !fk.getString( "name" ).isEmpty() ) { - element.setForeignKeyName( fk.getString( "name" ) ); + final org.hibernate.annotations.ForeignKey fk = property.getDirectAnnotationUsage( org.hibernate.annotations.ForeignKey.class ); + if ( fk != null && !fk.name().isEmpty() ) { + element.setForeignKeyName( fk.name() ); } else { - final AnnotationUsage joinTableAnn = property.getAnnotationUsage( JoinTable.class ); + final JoinTable joinTableAnn = property.getDirectAnnotationUsage( JoinTable.class ); if ( joinTableAnn != null ) { - final AnnotationUsage inverseForeignKey = joinTableAnn.getNestedUsage( "inverseForeignKey" ); - String foreignKeyName = inverseForeignKey.getString( "name" ); - String foreignKeyDefinition = inverseForeignKey.getString( "foreignKeyDefinition" ); + final ForeignKey inverseForeignKey = joinTableAnn.inverseForeignKey(); + String foreignKeyName = inverseForeignKey.name(); + String foreignKeyDefinition = inverseForeignKey.foreignKeyDefinition(); - final List> inverseJoinColumns = joinTableAnn.getList( "inverseJoinColumns" ); - if ( !inverseJoinColumns.isEmpty() ) { - final AnnotationUsage joinColumnAnn = inverseJoinColumns.get( 0); + final JoinColumn[] inverseJoinColumns = joinTableAnn.inverseJoinColumns(); + if ( !ArrayHelper.isEmpty( inverseJoinColumns ) ) { + final JoinColumn joinColumnAnn = inverseJoinColumns[0]; if ( foreignKeyName.isEmpty() ) { - final AnnotationUsage inverseJoinColumnForeignKey = joinColumnAnn.getNestedUsage( "foreignKey" ); - foreignKeyName = inverseJoinColumnForeignKey.getString( "name" ); - foreignKeyDefinition = inverseJoinColumnForeignKey.getString( "foreignKeyDefinition" ); + final ForeignKey inverseJoinColumnForeignKey = joinColumnAnn.foreignKey(); + foreignKeyName = inverseJoinColumnForeignKey.name(); + foreignKeyDefinition = inverseJoinColumnForeignKey.foreignKeyDefinition(); } } - final ConstraintMode constraintMode = inverseForeignKey.getEnum( "value" ); + final ConstraintMode constraintMode = inverseForeignKey.value(); if ( constraintMode == NO_CONSTRAINT || constraintMode == PROVIDER_DEFAULT && buildingContext.getBuildingOptions().isNoConstraintByDefault() ) { @@ -2498,23 +2515,23 @@ public abstract class CollectionBinder { ); final MemberDetails prop = inferredData.getAttributeMember(); - final AnnotationUsage discriminatorColumnAnn = prop.getAnnotationUsage( jakarta.persistence.Column.class ); - final AnnotationUsage discriminatorFormulaAnn = getOverridableAnnotation( prop, Formula.class, buildingContext ); + final jakarta.persistence.Column discriminatorColumnAnn = prop.getDirectAnnotationUsage( jakarta.persistence.Column.class ); + final Formula discriminatorFormulaAnn = getOverridableAnnotation( prop, Formula.class, buildingContext ); //override the table inverseJoinColumns.setTable( collection.getCollectionTable() ); - final AnnotationUsage anyAnn = property.getAnnotationUsage( ManyToAny.class ); + final ManyToAny anyAnn = property.getDirectAnnotationUsage( ManyToAny.class ); final Any any = buildAnyValue( discriminatorColumnAnn, discriminatorFormulaAnn, inverseJoinColumns, inferredData, onDeleteAction, - anyAnn.getEnum( "fetch" ) == LAZY, + anyAnn.fetch() == LAZY, Nullability.NO_CONSTRAINT, propertyHolder, - new EntityBinder(), + new EntityBinder( buildingContext ), true, buildingContext ); @@ -2567,7 +2584,7 @@ public abstract class CollectionBinder { ); } tableBinder.setJPA2ElementCollection( - !isCollectionOfEntities && property.hasAnnotationUsage( ElementCollection.class ) + !isCollectionOfEntities && property.hasDirectAnnotationUsage( ElementCollection.class ) ); final Table collectionTable = tableBinder.bind(); collection.setCollectionTable( collectionTable ); @@ -2576,22 +2593,19 @@ public abstract class CollectionBinder { } private void handleCheckConstraints(Table collectionTable) { - property.forEachAnnotationUsage( Check.class, (usage) -> { + property.forEachAnnotationUsage( Check.class, sourceModelContext(), (usage) -> { addCheckToCollection( collectionTable, usage ); } ); - property.forEachAnnotationUsage( - jakarta.persistence.JoinTable.class, - (usage) -> { - TableBinder.addTableCheck( collectionTable, usage.findAttributeValue( "check" ) ); - TableBinder.addTableComment( collectionTable, usage.getString( "comment" ) ); - TableBinder.addTableOptions( collectionTable, usage.getString( "options" ) ); - } - ); + property.forEachAnnotationUsage( jakarta.persistence.JoinTable.class, sourceModelContext(), (usage) -> { + TableBinder.addTableCheck( collectionTable, usage.check() ); + TableBinder.addTableComment( collectionTable, usage.comment() ); + TableBinder.addTableOptions( collectionTable, usage.options() ); + } ); } - private static void addCheckToCollection(Table collectionTable, AnnotationUsage check) { - final String name = check.getString( "name" ); - final String constraint = check.getString( "constraints" ); + private static void addCheckToCollection(Table collectionTable, Check check) { + final String name = check.name(); + final String constraint = check.constraints(); collectionTable.addCheck( name.isEmpty() ? new CheckConstraint( constraint ) : new CheckConstraint( name, constraint ) ); @@ -2600,7 +2614,7 @@ public abstract class CollectionBinder { private void processSoftDeletes() { assert collection.getCollectionTable() != null; - final AnnotationUsage softDelete = extractSoftDelete( property, propertyHolder, buildingContext ); + final SoftDelete softDelete = extractSoftDelete( property, propertyHolder, buildingContext ); if ( softDelete == null ) { return; } @@ -2613,11 +2627,11 @@ public abstract class CollectionBinder { ); } - private static AnnotationUsage extractSoftDelete( + private static SoftDelete extractSoftDelete( MemberDetails property, PropertyHolder propertyHolder, MetadataBuildingContext context) { - final AnnotationUsage fromProperty = property.getAnnotationUsage( SoftDelete.class ); + final SoftDelete fromProperty = property.getDirectAnnotationUsage( SoftDelete.class ); if ( fromProperty != null ) { return fromProperty; } @@ -2658,8 +2672,8 @@ public abstract class CollectionBinder { collection.setCollectionTable( table ); processSoftDeletes(); - if ( property.hasAnnotationUsage( Checks.class ) - || property.hasAnnotationUsage( Check.class ) ) { + if ( property.hasDirectAnnotationUsage( Checks.class ) + || property.hasDirectAnnotationUsage( Check.class ) ) { throw new AnnotationException( "Association '" + safeCollectionRole() + " is an unowned collection and may not be annotated '@Check'" ); } @@ -2671,7 +2685,8 @@ public abstract class CollectionBinder { boolean isManyToAny) { if ( !isCollectionOfEntities) { - if ( property.hasAnnotationUsage( ManyToMany.class ) || property.hasAnnotationUsage( OneToMany.class ) ) { + if ( property.hasDirectAnnotationUsage( ManyToMany.class ) + || property.hasDirectAnnotationUsage( OneToMany.class ) ) { throw new AnnotationException( "Association '" + safeCollectionRole() + "'" + targetEntityMessage( elementType ) ); } @@ -2682,8 +2697,8 @@ public abstract class CollectionBinder { } } else { - final AnnotationUsage joinTableAnn = propertyHolder.getJoinTable( property ); - if ( joinTableAnn != null && !joinTableAnn.getList( "inverseJoinColumns" ).isEmpty() ) { + final JoinTable joinTableAnn = propertyHolder.getJoinTable( property ); + if ( joinTableAnn != null && !ArrayHelper.isEmpty( joinTableAnn.inverseJoinColumns() ) ) { throw new AnnotationException( "Association '" + safeCollectionRole() + " has a '@JoinTable' with 'inverseJoinColumns' and" + targetEntityMessage( elementType ) ); @@ -2693,7 +2708,7 @@ public abstract class CollectionBinder { } static String targetEntityMessage(TypeDetails elementType) { - final String problem = elementType.determineRawClass().hasAnnotationUsage( Entity.class ) + final String problem = elementType.determineRawClass().hasDirectAnnotationUsage( Entity.class ) ? " which does not belong to the same persistence unit" : " which is not an '@Entity' type"; return " targets the type '" + elementType.getName() + "'" + problem; @@ -2703,17 +2718,17 @@ public abstract class CollectionBinder { MemberDetails property, TypeDetails propertyClass, MetadataBuildingContext context) { - final AnnotationUsage propertyAnnotation - = property.getAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); + final org.hibernate.annotations.EmbeddableInstantiator propertyAnnotation + = property.getDirectAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); if ( propertyAnnotation != null ) { - return propertyAnnotation.getClassDetails( "value" ).toJavaClass(); + return propertyAnnotation.value(); } final ClassDetails rawPropertyClassDetails = propertyClass.determineRawClass(); - final AnnotationUsage classAnnotation - = rawPropertyClassDetails.getAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); + final org.hibernate.annotations.EmbeddableInstantiator classAnnotation + = rawPropertyClassDetails.getDirectAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); if ( classAnnotation != null ) { - return classAnnotation.getClassDetails( "value" ).toJavaClass(); + return classAnnotation.value(); } final Class embeddableClass = rawPropertyClassDetails.toJavaClass(); @@ -2728,9 +2743,9 @@ public abstract class CollectionBinder { MemberDetails property, ClassDetails returnedClass, MetadataBuildingContext context) { - final AnnotationUsage compositeType = property.getAnnotationUsage( CompositeType.class ); + final CompositeType compositeType = property.getDirectAnnotationUsage( CompositeType.class ); if ( compositeType != null ) { - return compositeType.getClassDetails( "value" ).toJavaClass(); + return compositeType.value(); } if ( returnedClass != null ) { @@ -2743,10 +2758,10 @@ public abstract class CollectionBinder { return null; } - private String extractHqlOrderBy(AnnotationUsage jpaOrderBy) { + private String extractHqlOrderBy(OrderBy jpaOrderBy) { if ( jpaOrderBy != null ) { // Null not possible. In case of empty expression, apply default ordering. - return jpaOrderBy.getString( "value" ); + return jpaOrderBy.value(); } else { // @OrderBy not found. @@ -2809,7 +2824,7 @@ public abstract class CollectionBinder { ); } - if ( property.hasAnnotationUsage( ElementCollection.class ) ) { + if ( property.hasDirectAnnotationUsage( ElementCollection.class ) ) { joinColumns.setElementCollection( true ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java index 35fda16358..d2d8ef50f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java @@ -24,7 +24,6 @@ import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.TypeDetails; @@ -87,7 +86,7 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { return; } - collectionProperty.forEachAnnotationUsage( Convert.class, (usage) -> { + collectionProperty.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { applyLocalConvert( usage, collectionProperty, @@ -99,7 +98,7 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { } private void applyLocalConvert( - AnnotationUsage convertAnnotation, + Convert convertAnnotation, MemberDetails collectionProperty, boolean isComposite, Map elementAttributeConversionInfoMap, @@ -311,12 +310,12 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { } @Override - public Join addJoin(AnnotationUsage joinTableAnn, boolean noDelayInPkColumnCreation) { + public Join addJoin(JoinTable joinTableAnn, boolean noDelayInPkColumnCreation) { throw new AssertionFailure( "Add join in a second pass" ); } @Override - public Join addJoin(AnnotationUsage joinTableAnn, Table table, boolean noDelayInPkColumnCreation) { + public Join addJoin(JoinTable joinTableAnn, Table table, boolean noDelayInPkColumnCreation) { throw new AssertionFailure( "Add join in a second pass" ); } @@ -340,16 +339,16 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { prepared = true; if ( collection.isMap() ) { - if ( collectionProperty.hasAnnotationUsage( MapKeyEnumerated.class ) ) { + if ( collectionProperty.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ) { canKeyBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( MapKeyTemporal.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( MapKeyTemporal.class ) ) { canKeyBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( MapKeyClass.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( MapKeyClass.class ) ) { canKeyBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( MapKeyType.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( MapKeyType.class ) ) { canKeyBeConverted = false; } } @@ -357,22 +356,22 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { canKeyBeConverted = false; } - if ( collectionProperty.hasAnnotationUsage( ManyToAny.class ) ) { + if ( collectionProperty.hasDirectAnnotationUsage( ManyToAny.class ) ) { canElementBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( OneToMany.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( OneToMany.class ) ) { canElementBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( ManyToMany.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( ManyToMany.class ) ) { canElementBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( Enumerated.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( Enumerated.class ) ) { canElementBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( Temporal.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( Temporal.class ) ) { canElementBeConverted = false; } - else if ( collectionProperty.hasAnnotationUsage( CollectionType.class ) ) { + else if ( collectionProperty.hasDirectAnnotationUsage( CollectionType.class ) ) { canElementBeConverted = false; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java index 3da5a9b16b..d7c31a92ec 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java @@ -6,28 +6,24 @@ */ package org.hibernate.boot.model.internal; -import java.util.ArrayList; -import java.util.List; - import org.hibernate.AnnotationException; import org.hibernate.annotations.Columns; import org.hibernate.annotations.Formula; import org.hibernate.annotations.FractionalSeconds; import org.hibernate.annotations.JoinColumnOrFormula; -import org.hibernate.annotations.JoinColumnsOrFormulas; import org.hibernate.annotations.JoinFormula; +import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.MemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.SourceModelBuildingContext; import jakarta.persistence.Column; import jakarta.persistence.ElementCollection; import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinColumns; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; @@ -35,16 +31,14 @@ import jakarta.persistence.MapsId; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import jakarta.persistence.PrimaryKeyJoinColumn; -import jakarta.persistence.PrimaryKeyJoinColumns; import static org.hibernate.boot.model.internal.AnnotatedColumn.buildColumnFromAnnotation; import static org.hibernate.boot.model.internal.AnnotatedColumn.buildColumnFromNoAnnotation; import static org.hibernate.boot.model.internal.AnnotatedColumn.buildColumnsFromAnnotations; import static org.hibernate.boot.model.internal.AnnotatedColumn.buildFormulaFromAnnotation; -import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; import static org.hibernate.boot.model.internal.BinderHelper.getPath; import static org.hibernate.boot.model.internal.BinderHelper.getPropertyOverriddenByMapperOrMapsId; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified; +import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; /** @@ -92,13 +86,14 @@ class ColumnsBuilder { columns = null; joinColumns = buildExplicitJoinColumns( property, inferredData ); - final AnnotationUsage columnAnn = property.getAnnotationUsage( Column.class ); - final AnnotationUsage formulaAnn = property.getAnnotationUsage( Formula.class ); - final AnnotationUsage columnsAnn = property.getAnnotationUsage( Columns.class ); + final Column columnAnn = property.getDirectAnnotationUsage( Column.class ); + final Columns columnsAnn = property.getDirectAnnotationUsage( Columns.class ); + final Formula formulaAnn = property.getDirectAnnotationUsage( Formula.class ); + if ( columnAnn != null ) { columns = buildColumnFromAnnotation( - property.getAnnotationUsage( Column.class ), - property.getAnnotationUsage( FractionalSeconds.class ), + columnAnn, + property.getDirectAnnotationUsage( FractionalSeconds.class ), // comment, nullability, propertyHolder, @@ -119,7 +114,7 @@ class ColumnsBuilder { } else if ( columnsAnn != null ) { columns = buildColumnsFromAnnotations( - columnsAnn.getList( "columns" ), + columnsAnn.columns(), null, nullability, propertyHolder, @@ -131,18 +126,18 @@ class ColumnsBuilder { //set default values if needed if ( joinColumns == null - && ( property.hasAnnotationUsage( ManyToOne.class ) - || property.hasAnnotationUsage( OneToOne.class ) ) ) { + && ( property.hasDirectAnnotationUsage( ManyToOne.class ) + || property.hasDirectAnnotationUsage( OneToOne.class ) ) ) { joinColumns = buildDefaultJoinColumnsForToOne( property, inferredData ); } else if ( joinColumns == null - && ( property.hasAnnotationUsage( OneToMany.class ) - || property.hasAnnotationUsage( ElementCollection.class ) ) ) { - AnnotationUsage oneToMany = property.getAnnotationUsage( OneToMany.class ); + && ( property.hasDirectAnnotationUsage( OneToMany.class ) + || property.hasDirectAnnotationUsage( ElementCollection.class ) ) ) { + OneToMany oneToMany = property.getDirectAnnotationUsage( OneToMany.class ); joinColumns = AnnotatedJoinColumns.buildJoinColumns( null, // comment, - oneToMany == null ? null : nullIfEmpty( oneToMany.getString( "mappedBy" ) ), + oneToMany == null ? null : nullIfEmpty( oneToMany.mappedBy() ), entityBinder.getSecondaryTables(), propertyHolder, inferredData, @@ -150,14 +145,14 @@ class ColumnsBuilder { ); } else if ( joinColumns == null - && property.hasAnnotationUsage( org.hibernate.annotations.Any.class ) ) { + && property.hasDirectAnnotationUsage( org.hibernate.annotations.Any.class ) ) { throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData ) + "' is annotated '@Any' and must declare at least one '@JoinColumn'" ); } - if ( columns == null && !property.hasAnnotationUsage( ManyToMany.class ) ) { + if ( columns == null && !property.hasDirectAnnotationUsage( ManyToMany.class ) ) { //useful for collection of embedded elements columns = buildColumnFromNoAnnotation( - property.getAnnotationUsage( FractionalSeconds.class ), + property.getDirectAnnotationUsage( FractionalSeconds.class ), // comment, nullability, propertyHolder, @@ -179,11 +174,11 @@ class ColumnsBuilder { private AnnotatedJoinColumns buildDefaultJoinColumnsForToOne( MemberDetails property, PropertyData inferredData) { - final AnnotationUsage joinTableAnn = propertyHolder.getJoinTable( property ); + final JoinTable joinTableAnn = propertyHolder.getJoinTable( property ); // final Comment comment = property.getAnnotation(Comment.class); if ( joinTableAnn != null ) { return AnnotatedJoinColumns.buildJoinColumns( - joinTableAnn.getList( "inverseJoinColumns" ), + joinTableAnn.inverseJoinColumns(), // comment, null, entityBinder.getSecondaryTables(), @@ -193,11 +188,11 @@ class ColumnsBuilder { ); } else { - final AnnotationUsage oneToOneAnn = property.getAnnotationUsage( OneToOne.class ); + final OneToOne oneToOneAnn = property.getDirectAnnotationUsage( OneToOne.class ); return AnnotatedJoinColumns.buildJoinColumns( null, // comment, - oneToOneAnn == null ? null : nullIfEmpty( oneToOneAnn.getString( "mappedBy" ) ), + oneToOneAnn == null ? null : nullIfEmpty( oneToOneAnn.mappedBy() ), entityBinder.getSecondaryTables(), propertyHolder, inferredData, @@ -208,7 +203,7 @@ class ColumnsBuilder { private AnnotatedJoinColumns buildExplicitJoinColumns(MemberDetails property, PropertyData inferredData) { // process @JoinColumns before @Columns to handle collection of entities properly - final List> joinColumnAnnotations = getJoinColumnAnnotations( property, inferredData ); + final JoinColumn[] joinColumnAnnotations = getJoinColumnAnnotations( property, inferredData ); if ( joinColumnAnnotations != null ) { return AnnotatedJoinColumns.buildJoinColumns( joinColumnAnnotations, @@ -220,7 +215,7 @@ class ColumnsBuilder { ); } - final List> joinColumnOrFormulaAnnotations = joinColumnOrFormulaAnnotations( property, inferredData ); + final JoinColumnOrFormula[] joinColumnOrFormulaAnnotations = joinColumnOrFormulaAnnotations( property, inferredData ); if ( joinColumnOrFormulaAnnotations != null ) { return AnnotatedJoinColumns.buildJoinColumnsOrFormulas( joinColumnOrFormulaAnnotations, @@ -232,8 +227,8 @@ class ColumnsBuilder { ); } - if ( property.hasAnnotationUsage( JoinFormula.class) ) { - final AnnotationUsage joinFormula = getOverridableAnnotation( property, JoinFormula.class, buildingContext ); + if ( property.hasDirectAnnotationUsage( JoinFormula.class) ) { + final JoinFormula joinFormula = getOverridableAnnotation( property, JoinFormula.class, buildingContext ); return AnnotatedJoinColumns.buildJoinColumnsWithFormula( joinFormula, entityBinder.getSecondaryTables(), @@ -246,99 +241,50 @@ class ColumnsBuilder { return null; } - private List> joinColumnOrFormulaAnnotations(MemberDetails property, PropertyData inferredData) { - if ( property.hasAnnotationUsage( JoinColumnOrFormula.class ) ) { - return List.of( property.getAnnotationUsage( JoinColumnOrFormula.class ) ); - } - - if ( property.hasAnnotationUsage( JoinColumnsOrFormulas.class ) ) { - final AnnotationUsage joinColumnsOrFormulas = property.getAnnotationUsage( JoinColumnsOrFormulas.class ); - final List> joinColumnOrFormulaList = joinColumnsOrFormulas.getList( "value" ); - if ( joinColumnOrFormulaList.isEmpty() ) { - throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData) - + "' has an empty '@JoinColumnsOrFormulas' annotation" ); - } - return joinColumnOrFormulaList; + private JoinColumnOrFormula[] joinColumnOrFormulaAnnotations(MemberDetails property, PropertyData inferredData) { + final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + final JoinColumnOrFormula[] annotations = property.getRepeatedAnnotationUsages( + HibernateAnnotations.JOIN_COLUMN_OR_FORMULA, + sourceModelContext + ); + if ( CollectionHelper.isNotEmpty( annotations ) ) { + return annotations; } return null; } - private List> getJoinColumnAnnotations(MemberDetails property, PropertyData inferredData) { - if ( property.hasAnnotationUsage( JoinColumn.class ) ) { - return List.of( property.getAnnotationUsage( JoinColumn.class ) ); + private JoinColumn[] getJoinColumnAnnotations(MemberDetails property, PropertyData inferredData) { + final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + + final JoinColumn[] joinColumns = property.getRepeatedAnnotationUsages( + JpaAnnotations.JOIN_COLUMN, + sourceModelContext + ); + if ( CollectionHelper.isNotEmpty( joinColumns ) ) { + return joinColumns; } - if ( property.hasAnnotationUsage( JoinColumns.class ) ) { - final AnnotationUsage joinColumns = property.getAnnotationUsage( JoinColumns.class ); - final List> joinColumnsList = joinColumns.getList( "value" ); - if ( joinColumnsList.isEmpty() ) { - throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData) - + "' has an empty '@JoinColumns' annotation" ); - } - return joinColumnsList; - } - - if ( property.hasAnnotationUsage( MapsId.class ) ) { + if ( property.hasDirectAnnotationUsage( MapsId.class ) ) { // inelegant solution to HHH-16463, let the PrimaryKeyJoinColumn // masquerade as a regular JoinColumn (when a @OneToOne maps to // the primary key of the child table, it's more elegant and more // spec-compliant to map the association with @PrimaryKeyJoinColumn) - // - // todo : another option better leveraging hibernate-models would be to simply use an untyped AnnotationUsage - if ( property.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ) { - final List> adapters = new ArrayList<>(); - property.forEachAnnotationUsage( PrimaryKeyJoinColumn.class, (usage) -> { - adapters.add( makePrimaryKeyJoinColumnAdapter( usage, property ) ); - } ); + final PrimaryKeyJoinColumn[] primaryKeyJoinColumns = property.getRepeatedAnnotationUsages( + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + sourceModelContext + ); + if ( CollectionHelper.isNotEmpty( primaryKeyJoinColumns ) ) { + final JoinColumn[] adapters = new JoinColumn[primaryKeyJoinColumns.length]; + for ( int i = 0; i < primaryKeyJoinColumns.length; i++ ) { + final PrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns[i]; + adapters[i] = JoinColumnJpaAnnotation.toJoinColumn( primaryKeyJoinColumn, sourceModelContext ); + } return adapters; } - else { - final AnnotationUsage pkJoinColumnAnn = property.getAnnotationUsage( PrimaryKeyJoinColumn.class ); - if ( pkJoinColumnAnn != null ) { - return List.of( makePrimaryKeyJoinColumnAdapter( pkJoinColumnAnn, property ) ); - } - else { - return null; - } - } } - else { - return null; - } - } - private AnnotationUsage makePrimaryKeyJoinColumnAdapter( - AnnotationUsage pkJoinColumnAnn, - MemberDetails property) { - final SourceModelBuildingContext hibernateModelsContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); - final MutableAnnotationUsage usage = JpaAnnotations.JOIN_COLUMN.createUsage( hibernateModelsContext ); - applyAttributeIfSpecified( - "name", - pkJoinColumnAnn.getAttributeValue( "name" ), - usage - ); - applyAttributeIfSpecified( - "referencedColumnName", - pkJoinColumnAnn.getAttributeValue( "referencedColumnName" ), - usage - ); - applyAttributeIfSpecified( - "columnDefinition", - pkJoinColumnAnn.getAttributeValue( "columnDefinition" ), - usage - ); - applyAttributeIfSpecified( - "options", - pkJoinColumnAnn.getAttributeValue( "options" ), - usage - ); - applyAttributeIfSpecified( - "foreignKey", - pkJoinColumnAnn.getAttributeValue( "foreignKey" ), - usage - ); - return usage; + return null; } /** diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ComponentPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ComponentPropertyHolder.java index 9099cec93c..60022206dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ComponentPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ComponentPropertyHolder.java @@ -8,7 +8,6 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.hibernate.AnnotationException; @@ -21,7 +20,6 @@ import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.TypeDetails; @@ -111,7 +109,7 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder { return false; } - return memberDetails.hasAnnotationUsage( annotationType ); + return memberDetails.hasDirectAnnotationUsage( annotationType ); } private boolean hasAnnotation( @@ -149,7 +147,7 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder { processAttributeConversions( embeddableTypeDetails, infoMap ); // then we can overlay any conversions from the Embedded attribute - embeddedMemberDetails.forEachAnnotationUsage( Convert.class, (usage) -> { + embeddedMemberDetails.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { final AttributeConversionInfo info = new AttributeConversionInfo( usage, embeddedMemberDetails ); if ( isEmpty( info.getAttributeName() ) ) { throw new IllegalStateException( "Convert placed on Embedded attribute must define (sub)attributeName" ); @@ -162,7 +160,7 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder { private void processAttributeConversions(TypeDetails embeddableTypeDetails, Map infoMap) { final ClassDetails embeddableClassDetails = embeddableTypeDetails.determineRawClass(); - embeddableClassDetails.forEachAnnotationUsage( Convert.class, (usage) -> { + embeddableClassDetails.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { final AttributeConversionInfo info = new AttributeConversionInfo( usage, embeddableClassDetails ); if ( isEmpty( info.getAttributeName() ) ) { throw new IllegalStateException( "@Convert placed on @Embeddable must define attributeName" ); @@ -205,7 +203,7 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder { return; } - propertyMemberDetails.forEachAnnotationUsage( Convert.class, (usage) -> { + propertyMemberDetails.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { final AttributeConversionInfo info = new AttributeConversionInfo( usage, propertyMemberDetails ); attributeConversionInfoMap.put( attributeName, info ); } ); @@ -263,12 +261,12 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder { } @Override - public Join addJoin(AnnotationUsage joinTable, boolean noDelayInPkColumnCreation) { + public Join addJoin(JoinTable joinTable, boolean noDelayInPkColumnCreation) { return parent.addJoin( joinTable, noDelayInPkColumnCreation ); } @Override - public Join addJoin(AnnotationUsage joinTable, Table table, boolean noDelayInPkColumnCreation) { + public Join addJoin(JoinTable joinTable, Table table, boolean noDelayInPkColumnCreation) { return parent.addJoin( joinTable, table, noDelayInPkColumnCreation ); } @@ -340,9 +338,9 @@ public class ComponentPropertyHolder extends AbstractPropertyHolder { } @Override - public List> getOverriddenColumn(String propertyName) { + public Column[] getOverriddenColumn(String propertyName) { //FIXME this is yukky - List> result = super.getOverriddenColumn( propertyName ); + Column[] result = super.getOverriddenColumn( propertyName ); if ( result == null ) { final String userPropertyName = extractUserPropertyName( "id", propertyName ); if ( userPropertyName != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java index 2bf659531a..0ec9b22da5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java @@ -8,18 +8,18 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; import java.util.HashMap; -import java.util.List; import java.util.Locale; import java.util.Map; import org.hibernate.HibernateException; import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.DatabaseVersion; import org.hibernate.dialect.Dialect; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; /** * @author Sanne Grinovero @@ -75,46 +75,34 @@ public class DialectOverridesAnnotationHelper { return (Class) OVERRIDE_MAP.get( annotationType ); } - public static AnnotationUsage getOverridableAnnotation( + public static T getOverridableAnnotation( AnnotationTarget element, Class annotationType, MetadataBuildingContext context) { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); final Class overrideAnnotation = OVERRIDE_MAP.get( annotationType ); + if ( overrideAnnotation != null ) { // the requested annotation does have a DialectOverride variant - look for matching one of those... final Dialect dialect = context.getMetadataCollector().getDatabase().getDialect(); - final DatabaseVersion version = dialect.getVersion(); - final List> overrides = element.getRepeatedAnnotationUsages( overrideAnnotation ); - for ( AnnotationUsage override : overrides ) { - if ( overrideMatchesDialect( override, dialect ) ) { - // we found an override match... - // the override's `override` attribute is the thing to return - return override.getNestedUsage( "override" ); + final Annotation[] overrides = element.getRepeatedAnnotationUsages( overrideAnnotation, sourceModelContext ); + if ( CollectionHelper.isNotEmpty( overrides ) ) { + for ( int i = 0; i < overrides.length; i++ ) { + //noinspection unchecked + final DialectOverrider override = (DialectOverrider) overrides[i]; + if ( override.matches( dialect ) ) { + return override.override(); + } } } } // no override was found. return the base annotation (if one) - return element.getSingleAnnotationUsage( annotationType ); + return element.getAnnotationUsage( annotationType, sourceModelContext ); } - public static boolean overrideMatchesDialect(AnnotationUsage override, Dialect dialect) { - final ClassDetails overrideDialect = override.getClassDetails( "dialect" ); - final Class overrideDialectJavaType = overrideDialect.toJavaClass(); - if ( !overrideDialectJavaType.isAssignableFrom( dialect.getClass() ) ) { - return false; - } - - final AnnotationUsage beforeAnn = override.getNestedUsage( "before" ); - final AnnotationUsage sameOrAfterAnn = override.getNestedUsage( "sameOrAfter" ); - final DatabaseVersion version = dialect.getVersion(); - - if ( version.isBefore( beforeAnn.getInteger( "major" ), beforeAnn.getInteger( "minor" ) ) - && version.isSameOrAfter( sameOrAfterAnn.getInteger( "major" ), sameOrAfterAnn.getInteger( "minor" ) ) ) { - return true; - } - - return false; + public static boolean overrideMatchesDialect(DialectOverrider override, Dialect dialect) { + return override.matches( dialect ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java index b9a7257c30..a8769fcb86 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java @@ -24,6 +24,7 @@ import org.hibernate.boot.spi.AccessType; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; @@ -31,11 +32,11 @@ import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SingleTableSubclass; import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping; import org.hibernate.metamodel.spi.EmbeddableInstantiator; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.MethodDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.property.access.internal.PropertyAccessStrategyCompositeUserTypeImpl; import org.hibernate.property.access.internal.PropertyAccessStrategyMixedImpl; @@ -160,18 +161,19 @@ public class EmbeddableBinder { } static boolean isEmbedded(MemberDetails property, ClassDetails returnedClass) { - return property.hasAnnotationUsage( Embedded.class ) - || property.hasAnnotationUsage( EmbeddedId.class ) - || returnedClass.hasAnnotationUsage( Embeddable.class ) && !property.hasAnnotationUsage( Convert.class ); + return property.hasDirectAnnotationUsage( Embedded.class ) + || property.hasDirectAnnotationUsage( EmbeddedId.class ) + || returnedClass.hasDirectAnnotationUsage( Embeddable.class ) && !property.hasDirectAnnotationUsage( Convert.class ); } static boolean isEmbedded(MemberDetails property, TypeDetails returnedClass) { - if ( property.hasAnnotationUsage( Embedded.class ) || property.hasAnnotationUsage( EmbeddedId.class ) ) { + if ( property.hasDirectAnnotationUsage( Embedded.class ) || property.hasDirectAnnotationUsage( EmbeddedId.class ) ) { return true; } final ClassDetails returnClassDetails = returnedClass.determineRawClass(); - return returnClassDetails.hasAnnotationUsage( Embeddable.class ) && !property.hasAnnotationUsage( Convert.class ); + return returnClassDetails.hasDirectAnnotationUsage( Embeddable.class ) + && !property.hasDirectAnnotationUsage( Convert.class ); } public static Component bindEmbeddable( @@ -234,14 +236,22 @@ public class EmbeddableBinder { } private static void callTypeBinders(Component component, MetadataBuildingContext context, TypeDetails annotatedClass ) { - final List> metaAnnotatedAnnotations = annotatedClass.determineRawClass().getMetaAnnotated( TypeBinderType.class ); - for ( AnnotationUsage metaAnnotated : metaAnnotatedAnnotations ) { - final AnnotationUsage binderType = metaAnnotated.getAnnotationDescriptor().getAnnotationUsage( TypeBinderType.class ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + + final List metaAnnotatedAnnotations = annotatedClass.determineRawClass().getMetaAnnotated( TypeBinderType.class, sourceModelContext ); + if ( CollectionHelper.isEmpty( metaAnnotatedAnnotations ) ) { + return; + } + + for ( Annotation metaAnnotated : metaAnnotatedAnnotations ) { + final TypeBinderType binderType = metaAnnotated.annotationType().getAnnotation( TypeBinderType.class ); try { - final ClassDetails binderImpl = binderType.getClassDetails( "binder" ); - final Class> binderJavaType = binderImpl.toJavaClass(); - final TypeBinder binder = binderJavaType.getDeclaredConstructor().newInstance(); - binder.bind( metaAnnotated.toAnnotation(), context, component ); + //noinspection rawtypes + final Class binderImpl = binderType.binder(); + //noinspection rawtypes + final TypeBinder binder = binderImpl.getDeclaredConstructor().newInstance(); + //noinspection unchecked + binder.bind( metaAnnotated, context, component ); } catch ( Exception e ) { throw new AnnotationException( "error processing @TypeBinderType annotation '" + metaAnnotated + "'", e ); @@ -464,7 +474,7 @@ public class EmbeddableBinder { ); final MemberDetails property = propertyAnnotatedElement.getAttributeMember(); - if ( property.hasAnnotationUsage( GeneratedValue.class ) ) { + if ( property.hasDirectAnnotationUsage( GeneratedValue.class ) ) { if ( isIdClass || subholder.isOrWithinEmbeddedId() ) { processGeneratedId( context, component, property ); } @@ -529,8 +539,8 @@ public class EmbeddableBinder { PropertyHolder holder, InheritanceState inheritanceState, MetadataBuildingContext context) { - final AnnotationUsage discriminatorColumn = annotatedClass.getAnnotationUsage( DiscriminatorColumn.class ); - final AnnotationUsage discriminatorFormula = getOverridableAnnotation( + final DiscriminatorColumn discriminatorColumn = annotatedClass.getDirectAnnotationUsage( DiscriminatorColumn.class ); + final DiscriminatorFormula discriminatorFormula = getOverridableAnnotation( annotatedClass, DiscriminatorFormula.class, context @@ -539,7 +549,7 @@ public class EmbeddableBinder { if ( inheritanceState.hasSiblings() ) { final String path = qualify( holder.getPath(), EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME ); final String columnPrefix; - final List> overrides; + final Column[] overrides; if ( holder.isWithinElementCollection() ) { columnPrefix = unqualify( parentHolder.getPath() ); overrides = parentHolder.getOverriddenColumn( path ); @@ -551,7 +561,7 @@ public class EmbeddableBinder { return buildDiscriminatorColumn( discriminatorColumn, discriminatorFormula, - overrides == null ? null : overrides.get(0), + overrides == null ? null : overrides[0], columnPrefix + "_" + DEFAULT_DISCRIMINATOR_COLUMN_NAME, context ); @@ -687,8 +697,8 @@ public class EmbeddableBinder { ClassDetails annotatedClass, BasicType discriminatorType, Map discriminatorValues) { - final String explicitValue = annotatedClass.hasAnnotationUsage( DiscriminatorValue.class ) - ? annotatedClass.getAnnotationUsage( DiscriminatorValue.class ).getString( "value" ) + final String explicitValue = annotatedClass.hasDirectAnnotationUsage( DiscriminatorValue.class ) + ? annotatedClass.getDirectAnnotationUsage( DiscriminatorValue.class ).value() : null; final String discriminatorValue; if ( isEmpty( explicitValue ) ) { @@ -721,7 +731,7 @@ public class EmbeddableBinder { return false; } - return superClass.hasAnnotationUsage( MappedSuperclass.class ) + return superClass.hasDirectAnnotationUsage( MappedSuperclass.class ) || ( isIdClass && !superClass.getName().equals( Object.class.getName() ) && !superClass.getName().equals( "java.lang.Record" ) ); @@ -793,21 +803,21 @@ public class EmbeddableBinder { } private static boolean hasTriggeringAnnotation(MemberDetails property) { - return property.hasAnnotationUsage(Column.class) - || property.hasAnnotationUsage(OneToMany.class) - || property.hasAnnotationUsage(ManyToOne.class) - || property.hasAnnotationUsage(Id.class) - || property.hasAnnotationUsage(GeneratedValue.class) - || property.hasAnnotationUsage(OneToOne.class) - || property.hasAnnotationUsage(ManyToMany.class); + return property.hasDirectAnnotationUsage(Column.class) + || property.hasDirectAnnotationUsage(OneToMany.class) + || property.hasDirectAnnotationUsage(ManyToOne.class) + || property.hasDirectAnnotationUsage(Id.class) + || property.hasDirectAnnotationUsage(GeneratedValue.class) + || property.hasDirectAnnotationUsage(OneToOne.class) + || property.hasDirectAnnotationUsage(ManyToMany.class); } private static void processGeneratedId(MetadataBuildingContext context, Component component, MemberDetails property) { - final AnnotationUsage generatedValue = property.getAnnotationUsage( GeneratedValue.class ); + final GeneratedValue generatedValue = property.getDirectAnnotationUsage( GeneratedValue.class ); final String generatorType = generatedValue != null ? generatorType( generatedValue, property.getType().determineRawClass(), context ) : GeneratorBinder.ASSIGNED_GENERATOR_NAME; - final String generator = generatedValue != null ? generatedValue.getString( "generator" ) : ""; + final String generator = generatedValue != null ? generatedValue.generator() : ""; if ( isGlobalGeneratorNameGlobal( context ) ) { buildGenerators( property, context ); @@ -926,21 +936,21 @@ public class EmbeddableBinder { MemberDetails property, ClassDetails returnedClass, MetadataBuildingContext context) { - if ( property.hasAnnotationUsage( EmbeddedId.class ) ) { + if ( property.hasDirectAnnotationUsage( EmbeddedId.class ) ) { // we don't allow custom instantiators for composite ids return null; } - final AnnotationUsage propertyAnnotation = - property.getAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); + final org.hibernate.annotations.EmbeddableInstantiator propertyAnnotation = + property.getDirectAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); if ( propertyAnnotation != null ) { - return propertyAnnotation.getClassDetails( "value" ).toJavaClass(); + return propertyAnnotation.value(); } - final AnnotationUsage classAnnotation = - returnedClass.getAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); + final org.hibernate.annotations.EmbeddableInstantiator classAnnotation = + returnedClass.getDirectAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); if ( classAnnotation != null ) { - return classAnnotation.getClassDetails( "value" ).toJavaClass(); + return classAnnotation.value(); } if ( returnedClass.getClassName() != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index d904466f3e..9ef1339960 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -70,17 +70,23 @@ import org.hibernate.boot.model.naming.ImplicitEntityNameSource; import org.hibernate.boot.model.naming.NamingStrategyHelper; import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.CacheAnnotation; +import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.spi.AccessType; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jdbc.Expectation; import org.hibernate.jpa.event.internal.CallbackDefinitionResolver; @@ -104,10 +110,9 @@ import org.hibernate.mapping.UnionSubclass; import org.hibernate.mapping.Value; import org.hibernate.models.internal.ClassTypeDetailsImpl; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.spi.NavigablePath; @@ -150,7 +155,6 @@ import static org.hibernate.boot.model.internal.BinderHelper.toAliasEntityMap; import static org.hibernate.boot.model.internal.BinderHelper.toAliasTableMap; import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverrideAnnotation; -import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.overrideMatchesDialect; import static org.hibernate.boot.model.internal.EmbeddableBinder.fillEmbeddable; import static org.hibernate.boot.model.internal.GeneratorBinder.makeIdGenerator; import static org.hibernate.boot.model.internal.InheritanceState.getInheritanceStateOfSuperEntity; @@ -160,7 +164,6 @@ import static org.hibernate.boot.model.internal.PropertyBinder.processElementAnn import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPropertyHolder; import static org.hibernate.boot.model.internal.TableBinder.bindForeignKey; import static org.hibernate.boot.model.naming.Identifier.toIdentifier; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified; import static org.hibernate.engine.OptimisticLockStyle.fromLockType; import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.fromResultCheckStyle; import static org.hibernate.internal.util.ReflectHelper.getDefaultSupplier; @@ -198,7 +201,7 @@ public class EntityBinder { private final java.util.Map secondaryTablesFromAnnotation = new HashMap<>(); private final java.util.Map secondaryTableFromAnnotationJoins = new HashMap<>(); - private final List> filters = new ArrayList<>(); + private final List filters = new ArrayList<>(); private boolean ignoreIdAnnotations; private AccessType propertyAccessType = AccessType.DEFAULT; private boolean wrapIdsInEmbeddedComponents; @@ -211,6 +214,10 @@ public class EntityBinder { private String naturalIdCacheRegion; private CacheLayout queryCacheLayout; + private SourceModelBuildingContext getSourceModelContext() { + return context.getMetadataCollector().getSourceModelBuildingContext(); + } + /** * Bind an entity class. This can be done in a single pass. */ @@ -228,7 +235,7 @@ public class EntityBinder { final InheritanceState inheritanceState = inheritanceStates.get( clazzToProcess ); final PersistentClass superEntity = getSuperEntity( clazzToProcess, inheritanceStates, context, inheritanceState ); final PersistentClass persistentClass = makePersistentClass( inheritanceState, superEntity, context ); - checkOverrides( clazzToProcess, superEntity ); + checkOverrides( clazzToProcess, superEntity, context.getMetadataCollector().getSourceModelBuildingContext() ); final EntityBinder entityBinder = new EntityBinder( clazzToProcess, persistentClass, context ); entityBinder.bindEntity(); @@ -272,18 +279,20 @@ public class EntityBinder { handleSecondaryTables(); } - private static void checkOverrides(ClassDetails clazzToProcess, PersistentClass superEntity) { + private static void checkOverrides(ClassDetails clazzToProcess, PersistentClass superEntity, SourceModelBuildingContext sourceModelContext) { if ( superEntity != null ) { //TODO: correctly handle compound paths (embeddables) - clazzToProcess.forEachAnnotationUsage( AttributeOverride.class, (usage) -> checkOverride( + clazzToProcess.forEachAnnotationUsage( AttributeOverride.class, sourceModelContext, (usage) -> checkOverride( superEntity, - usage.getString( "name" ), - clazzToProcess, AttributeOverride.class + usage.name(), + clazzToProcess, + AttributeOverride.class ) ); - clazzToProcess.forEachAnnotationUsage( AssociationOverride.class, (usage) -> checkOverride( + clazzToProcess.forEachAnnotationUsage( AssociationOverride.class, sourceModelContext, (usage) -> checkOverride( superEntity, - usage.getString( "name" ), - clazzToProcess, AttributeOverride.class + usage.name(), + clazzToProcess, + AttributeOverride.class ) ); } } @@ -313,7 +322,7 @@ public class EntityBinder { // todo (soft-delete) : do we assume all package-level registrations are already available? // or should this be a "second pass"? - final AnnotationUsage softDelete = extractSoftDelete( classDetails, inheritanceState, context ); + final SoftDelete softDelete = extractSoftDelete( classDetails, inheritanceState, context ); if ( softDelete != null ) { SoftDeleteHelper.bindSoftDeleteIndicator( softDelete, @@ -324,19 +333,20 @@ public class EntityBinder { } } - private static AnnotationUsage extractSoftDelete( + private static SoftDelete extractSoftDelete( ClassDetails classDetails, InheritanceState inheritanceState, MetadataBuildingContext context) { - final AnnotationUsage fromClass = classDetails.getAnnotationUsage( SoftDelete.class ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + final SoftDelete fromClass = classDetails.getAnnotationUsage( SoftDelete.class, sourceModelContext ); if ( fromClass != null ) { return fromClass; } ClassDetails classToCheck = classDetails.getSuperClass(); while ( classToCheck != null ) { - final AnnotationUsage fromSuper = classToCheck.getAnnotationUsage( SoftDelete.class ); - if ( fromSuper != null && classToCheck.hasAnnotationUsage( jakarta.persistence.MappedSuperclass.class ) ) { + final SoftDelete fromSuper = classToCheck.getAnnotationUsage( SoftDelete.class, sourceModelContext ); + if ( fromSuper != null && classToCheck.hasAnnotationUsage( jakarta.persistence.MappedSuperclass.class, sourceModelContext ) ) { return fromSuper; } @@ -347,15 +357,15 @@ public class EntityBinder { } private void handleCheckConstraints() { - if ( annotatedClass.hasAnnotationUsage( Checks.class ) ) { + if ( annotatedClass.hasAnnotationUsage( Checks.class, getSourceModelContext() ) ) { // if we have more than one of them they are not overrideable - final AnnotationUsage explicitUsage = annotatedClass.getAnnotationUsage( Checks.class ); - for ( AnnotationUsage check : explicitUsage.>getList( "value" ) ) { + final Checks explicitUsage = annotatedClass.getAnnotationUsage( Checks.class, getSourceModelContext() ); + for ( Check check : explicitUsage.value() ) { addCheckToEntity( check ); } } else { - final AnnotationUsage check = getOverridableAnnotation( annotatedClass, Check.class, context ); + final Check check = getOverridableAnnotation( annotatedClass, Check.class, context ); if ( check != null ) { addCheckToEntity( check ); } @@ -366,28 +376,26 @@ public class EntityBinder { * For now, we store it on the entity. * Later we will come back and figure out which table it belongs to. */ - private void addCheckToEntity(AnnotationUsage check) { - final String name = check.getString( "name" ); - final String constraint = check.getString( "constraints" ); + private void addCheckToEntity(Check check) { + final String name = check.name(); + final String constraint = check.constraints(); persistentClass.addCheckConstraint( name.isEmpty() ? new CheckConstraint( constraint ) : new CheckConstraint( name, constraint ) ); } private void callTypeBinders(PersistentClass persistentClass) { - final List> metaAnnotatedList = annotatedClass.getMetaAnnotated( TypeBinderType.class ); - for ( AnnotationUsage metaAnnotated : metaAnnotatedList ) { + final List metaAnnotatedList = annotatedClass.getMetaAnnotated( TypeBinderType.class, getSourceModelContext() ); + for ( Annotation metaAnnotated : metaAnnotatedList ) { applyTypeBinder( metaAnnotated, persistentClass ); } } - private void applyTypeBinder(AnnotationUsage metaAnnotated, PersistentClass persistentClass) { - final Class> binderClass = metaAnnotated.getAnnotationType() + private void applyTypeBinder(Annotation containingAnnotation, PersistentClass persistentClass) { + final Class> binderClass = containingAnnotation.annotationType() .getAnnotation( TypeBinderType.class ) .binder(); - final Annotation containingAnnotation = metaAnnotated.toAnnotation(); - try { //noinspection rawtypes final TypeBinder binder = binderClass.getConstructor().newInstance(); @@ -426,43 +434,42 @@ public class EntityBinder { } private void processComplementaryTableDefinitions() { - annotatedClass.forEachAnnotationUsage( org.hibernate.annotations.Table.class, (usage) -> { + annotatedClass.forEachAnnotationUsage( org.hibernate.annotations.Table.class, getSourceModelContext(), (usage) -> { + final Table appliedTable = findTable( usage.appliesTo() ); - final Table appliedTable = findTable( usage.getString( "appliesTo" ) ); - - final String comment = usage.getString( "comment" ); + final String comment = usage.comment(); if ( !comment.isEmpty() ) { appliedTable.setComment( comment ); } - final String checkConstraint = usage.getString( "checkConstraint" ); + final String checkConstraint = usage.checkConstraint(); if ( !checkConstraint.isEmpty() ) { //noinspection deprecation appliedTable.addCheckConstraint( checkConstraint ); } - TableBinder.addIndexes( appliedTable, usage.getList( "indexes" ), context ); + TableBinder.addIndexes( appliedTable, usage.indexes(), context ); } ); - final AnnotationUsage jpaTableUsage = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class ); + final jakarta.persistence.Table jpaTableUsage = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class, getSourceModelContext() ); if ( jpaTableUsage != null ) { final Table table = persistentClass.getTable(); - TableBinder.addJpaIndexes( table, jpaTableUsage.getList( "indexes" ), context ); - TableBinder.addTableCheck( table, jpaTableUsage.findAttributeValue( "check" ) ); - TableBinder.addTableComment( table, jpaTableUsage.getString( "comment" ) ); - TableBinder.addTableOptions( table, jpaTableUsage.getString( "options" ) ); + TableBinder.addJpaIndexes( table, jpaTableUsage.indexes(), context ); + TableBinder.addTableCheck( table, jpaTableUsage.check() ); + TableBinder.addTableComment( table, jpaTableUsage.comment() ); + TableBinder.addTableOptions( table, jpaTableUsage.options() ); } final InFlightMetadataCollector.EntityTableXref entityTableXref = context .getMetadataCollector() .getEntityTableXref( persistentClass.getEntityName() ); - annotatedClass.forEachAnnotationUsage( jakarta.persistence.SecondaryTable.class, (usage) -> { - final Identifier secondaryTableLogicalName = toIdentifier( usage.getString( "name" ) ); + annotatedClass.forEachAnnotationUsage( jakarta.persistence.SecondaryTable.class, getSourceModelContext(), (usage) -> { + final Identifier secondaryTableLogicalName = toIdentifier( usage.name() ); final Table table = entityTableXref.resolveTable( secondaryTableLogicalName ); assert table != null; - TableBinder.addJpaIndexes( table, usage.getList( "indexes" ), context ); + TableBinder.addJpaIndexes( table, usage.indexes(), context ); } ); } @@ -503,7 +510,8 @@ public class EntityBinder { // properties and create an identifier mapper containing the id properties of the main entity final ClassDetails classWithIdClass = inheritanceState.getClassWithIdClass( false ); if ( classWithIdClass != null ) { - final Class idClassValue = classWithIdClass.getAnnotationUsage( IdClass.class ).getClassDetails( "value" ).toJavaClass(); + final IdClass idClassAnn = classWithIdClass.getDirectAnnotationUsage( IdClass.class ); + final Class idClassValue = idClassAnn.value(); final ClassDetails compositeClass = context.getMetadataCollector().getSourceModelBuildingContext().getClassDetailsRegistry().resolveClassDetails( idClassValue.getName() ); final TypeDetails compositeType = new ClassTypeDetailsImpl( compositeClass, TypeDetails.Kind.CLASS ); final TypeDetails classWithIdType = new ClassTypeDetailsImpl( classWithIdClass, TypeDetails.Kind.CLASS ); @@ -685,8 +693,9 @@ public class EntityBinder { } else { - final AnnotationUsage idClass = associatedClassWithIdClass.getAnnotationUsage( IdClass.class ); - return compositeClass.equals( idClass.getClassDetails( "value" ) ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + final IdClass idClass = associatedClassWithIdClass.getAnnotationUsage( IdClass.class, sourceModelContext ); + return compositeClass.getName().equals( idClass.value().getName() ); } } else { @@ -772,7 +781,7 @@ public class EntityBinder { } private void handleSecondaryTables() { - annotatedClass.forEachAnnotationUsage( SecondaryTable.class, (usage) -> { + annotatedClass.forEachRepeatedAnnotationUsages( JpaAnnotations.SECONDARY_TABLE, getSourceModelContext(), (usage) -> { addSecondaryTable( usage, null, false ); } ); } @@ -781,21 +790,20 @@ public class EntityBinder { final String schema; final String table; final String catalog; - final List> uniqueConstraints; - final boolean hasTableAnnotation = annotatedClass.hasAnnotationUsage( jakarta.persistence.Table.class ); - if ( hasTableAnnotation ) { - final AnnotationUsage tableAnnotation = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class ); - table = tableAnnotation.getString( "name" ); - schema = tableAnnotation.getString( "schema" ); - catalog = tableAnnotation.getString( "catalog" ); - uniqueConstraints = tableAnnotation.getList( "uniqueConstraints" ); + final UniqueConstraint[] uniqueConstraints; + final jakarta.persistence.Table tableAnnotation = annotatedClass.getAnnotationUsage( jakarta.persistence.Table.class, getSourceModelContext() ); + if ( tableAnnotation != null ) { + table = tableAnnotation.name(); + schema = tableAnnotation.schema(); + catalog = tableAnnotation.catalog(); + uniqueConstraints = tableAnnotation.uniqueConstraints(); } else { //might be no @Table annotation on the annotated class schema = ""; table = ""; catalog = ""; - uniqueConstraints = Collections.emptyList(); + uniqueConstraints = new UniqueConstraint[0]; } if ( inheritanceState.hasTable() ) { @@ -803,7 +811,7 @@ public class EntityBinder { } else { // if we get here we have SINGLE_TABLE inheritance - if ( hasTableAnnotation ) { + if ( tableAnnotation != null ) { throw new AnnotationException( "Entity '" + annotatedClass.getName() + "' is a subclass in a 'SINGLE_TABLE' hierarchy and may not be annotated '@Table'" + " (the root class declares the table mapping for the hierarchy)"); @@ -819,16 +827,16 @@ public class EntityBinder { String schema, String table, String catalog, - List> uniqueConstraints) { - final AnnotationUsage rowId = annotatedClass.getAnnotationUsage( RowId.class ); - final AnnotationUsage view = annotatedClass.getAnnotationUsage( View.class ); + UniqueConstraint[] uniqueConstraints) { + final RowId rowId = annotatedClass.getAnnotationUsage( RowId.class, getSourceModelContext() ); + final View view = annotatedClass.getAnnotationUsage( View.class, getSourceModelContext() ); bindTable( schema, catalog, table, uniqueConstraints, - rowId == null ? null : rowId.getString( "value" ), - view == null ? null : view.getString( "query" ), + rowId == null ? null : rowId.value(), + view == null ? null : view.query(), inheritanceState.hasDenormalizedTable() ? context.getMetadataCollector().getEntityTableXref( superEntity.getEntityName() ) : null @@ -887,8 +895,8 @@ public class EntityBinder { final DependantValue key = new DependantValue( context, jsc.getTable(), jsc.getIdentifier() ); jsc.setKey( key ); handleForeignKeys( annotatedClass, context, key ); - final AnnotationUsage onDelete = annotatedClass.getAnnotationUsage( OnDelete.class ); - key.setOnDeleteAction( onDelete == null ? null : onDelete.getEnum( "action" ) ); + final OnDelete onDelete = annotatedClass.getAnnotationUsage( OnDelete.class, getSourceModelContext() ); + key.setOnDeleteAction( onDelete == null ? null : onDelete.action() ); //we are never in a second pass at that stage, so queue it context.getMetadataCollector() .addSecondPass( new JoinedSubclassFkSecondPass( jsc, joinColumns, key, context) ); @@ -915,55 +923,54 @@ public class EntityBinder { } private void checkNoJoinColumns(ClassDetails annotatedClass) { - if ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) - || annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ) { + if ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class, getSourceModelContext() ) + || annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class, getSourceModelContext() ) ) { throw new AnnotationException( "Entity class '" + annotatedClass.getName() + "' may not specify a '@PrimaryKeyJoinColumn'" ); } } - private static void checkNoOnDelete(ClassDetails annotatedClass) { - if ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) - || annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ) { + private void checkNoOnDelete(ClassDetails annotatedClass) { + if ( annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumns.class, getSourceModelContext() ) + || annotatedClass.hasAnnotationUsage( PrimaryKeyJoinColumn.class, getSourceModelContext() ) ) { throw new AnnotationException( "Entity class '" + annotatedClass.getName() + "' may not be annotated '@OnDelete'" ); } } - private static void handleForeignKeys(ClassDetails clazzToProcess, MetadataBuildingContext context, DependantValue key) { - final AnnotationUsage pkJoinColumn = clazzToProcess.getSingleAnnotationUsage( PrimaryKeyJoinColumn.class ); - final AnnotationUsage pkJoinColumns = clazzToProcess.getAnnotationUsage( PrimaryKeyJoinColumns.class ); + private void handleForeignKeys(ClassDetails clazzToProcess, MetadataBuildingContext context, DependantValue key) { + final PrimaryKeyJoinColumn pkJoinColumn = clazzToProcess.getDirectAnnotationUsage( PrimaryKeyJoinColumn.class ); + final PrimaryKeyJoinColumns pkJoinColumns = clazzToProcess.getDirectAnnotationUsage( PrimaryKeyJoinColumns.class ); final boolean noConstraintByDefault = context.getBuildingOptions().isNoConstraintByDefault(); - if ( pkJoinColumn != null && noConstraint( pkJoinColumn.getNestedUsage( "foreignKey" ), noConstraintByDefault ) - || pkJoinColumns != null && noConstraint( pkJoinColumns.getNestedUsage( "foreignKey" ), noConstraintByDefault ) ) { + if ( pkJoinColumn != null && noConstraint( pkJoinColumn.foreignKey(), noConstraintByDefault ) + || pkJoinColumns != null && noConstraint( pkJoinColumns.foreignKey(), noConstraintByDefault ) ) { key.disableForeignKey(); } else { - final AnnotationUsage fk = - clazzToProcess.getAnnotationUsage( org.hibernate.annotations.ForeignKey.class ); - if ( fk != null && isNotEmpty( fk.getString( "name" ) ) ) { - key.setForeignKeyName( fk.getString( "name" ) ); + final org.hibernate.annotations.ForeignKey fk = clazzToProcess.getDirectAnnotationUsage( org.hibernate.annotations.ForeignKey.class); + if ( fk != null && isNotEmpty( fk.name() ) ) { + key.setForeignKeyName( fk.name() ); } else { - final AnnotationUsage foreignKey = clazzToProcess.getAnnotationUsage( ForeignKey.class ); + final ForeignKey foreignKey = clazzToProcess.getDirectAnnotationUsage( ForeignKey.class ); if ( noConstraint( foreignKey, noConstraintByDefault ) ) { key.disableForeignKey(); } else if ( foreignKey != null ) { - key.setForeignKeyName( nullIfEmpty( foreignKey.getString( "name" ) ) ); - key.setForeignKeyDefinition( nullIfEmpty( foreignKey.getString( "foreignKeyDefinition" ) ) ); + key.setForeignKeyName( nullIfEmpty( foreignKey.name() ) ); + key.setForeignKeyDefinition( nullIfEmpty( foreignKey.foreignKeyDefinition() ) ); } else if ( noConstraintByDefault ) { key.disableForeignKey(); } else if ( pkJoinColumns != null ) { - final AnnotationUsage nestedFk = pkJoinColumns.getNestedUsage( "foreignKey" ); - key.setForeignKeyName( nullIfEmpty( nestedFk.getString( "name" ) ) ); - key.setForeignKeyDefinition( nullIfEmpty( nestedFk.getString( "foreignKeyDefinition" ) ) ); + final ForeignKey nestedFk = pkJoinColumns.foreignKey(); + key.setForeignKeyName( nullIfEmpty( nestedFk.name() ) ); + key.setForeignKeyDefinition( nullIfEmpty( nestedFk.foreignKeyDefinition() ) ); } else if ( pkJoinColumn != null ) { - final AnnotationUsage nestedFk = pkJoinColumn.getNestedUsage( "foreignKey" ); - key.setForeignKeyName( nullIfEmpty( nestedFk.getString( "name" ) ) ); - key.setForeignKeyDefinition( nullIfEmpty( nestedFk.getString( "foreignKeyDefinition" ) ) ); + final ForeignKey nestedFk = pkJoinColumn.foreignKey(); + key.setForeignKeyName( nullIfEmpty( nestedFk.name() ) ); + key.setForeignKeyDefinition( nullIfEmpty( nestedFk.foreignKeyDefinition() ) ); } } } @@ -1001,10 +1008,10 @@ public class EntityBinder { * Process all discriminator-related metadata per rules for "single table" inheritance */ private AnnotatedDiscriminatorColumn processSingleTableDiscriminatorProperties(InheritanceState inheritanceState) { - final AnnotationUsage discriminatorColumn = annotatedClass.getAnnotationUsage( DiscriminatorColumn.class ); - final AnnotationUsage discriminatorFormula = getOverridableAnnotation( annotatedClass, DiscriminatorFormula.class, context ); + final DiscriminatorColumn discriminatorColumn = annotatedClass.getAnnotationUsage( DiscriminatorColumn.class, getSourceModelContext() ); + final DiscriminatorFormula discriminatorFormula = getOverridableAnnotation( annotatedClass, DiscriminatorFormula.class, context ); - if ( !inheritanceState.hasParents() || annotatedClass.hasAnnotationUsage( Inheritance.class ) ) { + if ( !inheritanceState.hasParents() || annotatedClass.hasAnnotationUsage( Inheritance.class, getSourceModelContext() ) ) { return buildDiscriminatorColumn( discriminatorColumn, discriminatorFormula, @@ -1033,13 +1040,13 @@ public class EntityBinder { * and {@value AvailableSettings#IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS}. */ private AnnotatedDiscriminatorColumn processJoinedDiscriminatorProperties(InheritanceState inheritanceState) { - if ( annotatedClass.hasAnnotationUsage( DiscriminatorFormula.class ) ) { + if ( annotatedClass.hasAnnotationUsage( DiscriminatorFormula.class, getSourceModelContext() ) ) { throw new AnnotationException( "Entity class '" + annotatedClass.getName() + "' has 'JOINED' inheritance and is annotated '@DiscriminatorFormula'" ); } - final AnnotationUsage discriminatorColumn = annotatedClass.getAnnotationUsage( DiscriminatorColumn.class ); - if ( !inheritanceState.hasParents() || annotatedClass.hasAnnotationUsage( Inheritance.class ) ) { + final DiscriminatorColumn discriminatorColumn = annotatedClass.getAnnotationUsage( DiscriminatorColumn.class, getSourceModelContext() ); + if ( !inheritanceState.hasParents() || annotatedClass.hasAnnotationUsage( Inheritance.class, getSourceModelContext() ) ) { return useDiscriminatorColumnForJoined( discriminatorColumn ) ? buildDiscriminatorColumn( discriminatorColumn, null, null, DEFAULT_DISCRIMINATOR_COLUMN_NAME, context ) : null; @@ -1063,7 +1070,7 @@ public class EntityBinder { * implicitly via {@value AvailableSettings#IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS}. * */ - private boolean useDiscriminatorColumnForJoined(AnnotationUsage discriminatorColumn) { + private boolean useDiscriminatorColumnForJoined(DiscriminatorColumn discriminatorColumn) { if ( discriminatorColumn != null ) { boolean ignore = context.getBuildingOptions().ignoreExplicitDiscriminatorsForJoinedInheritance(); if ( ignore ) { @@ -1104,7 +1111,7 @@ public class EntityBinder { boolean subclassAndSingleTableStrategy = inheritanceState.getType() == SINGLE_TABLE && inheritanceState.hasParents(); - if ( !hasIdAnnotation && property.hasAnnotationUsage( GeneratedValue.class ) ) { + if ( !hasIdAnnotation && property.hasAnnotationUsage( GeneratedValue.class, getSourceModelContext() ) ) { throw new AnnotationException( "Property '" + BinderHelper.getPath( propertyHolder, propertyAnnotatedElement ) @@ -1184,11 +1191,13 @@ public class EntityBinder { final AnnotatedJoinColumns joinColumns = new AnnotatedJoinColumns(); joinColumns.setBuildingContext( context ); - final AnnotationUsage primaryKeyJoinColumns = clazzToProcess.getAnnotationUsage( PrimaryKeyJoinColumns.class ); + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + + final PrimaryKeyJoinColumns primaryKeyJoinColumns = clazzToProcess.getAnnotationUsage( PrimaryKeyJoinColumns.class, sourceModelContext ); if ( primaryKeyJoinColumns != null ) { - final List> columns = primaryKeyJoinColumns.getList( "value" ); - if ( !columns.isEmpty() ) { - for ( AnnotationUsage column : columns ) { + final PrimaryKeyJoinColumn[] columns = primaryKeyJoinColumns.value(); + if ( !ArrayHelper.isEmpty( columns ) ) { + for ( PrimaryKeyJoinColumn column : columns ) { buildInheritanceJoinColumn( column, null, @@ -1199,7 +1208,7 @@ public class EntityBinder { } } else { - final AnnotationUsage columnAnnotation = clazzToProcess.getAnnotationUsage( PrimaryKeyJoinColumn.class ); + final PrimaryKeyJoinColumn columnAnnotation = clazzToProcess.getAnnotationUsage( PrimaryKeyJoinColumn.class, sourceModelContext ); buildInheritanceJoinColumn( columnAnnotation, null, @@ -1211,7 +1220,7 @@ public class EntityBinder { } else { buildInheritanceJoinColumn( - clazzToProcess.getAnnotationUsage( PrimaryKeyJoinColumn.class ), + clazzToProcess.getAnnotationUsage( PrimaryKeyJoinColumn.class, sourceModelContext ), null, superEntity.getIdentifier(), joinColumns, @@ -1284,7 +1293,8 @@ public class EntityBinder { /** * Use as a fake one for Collection of elements */ - public EntityBinder() { + public EntityBinder(MetadataBuildingContext context) { + this.context = context; } public EntityBinder(ClassDetails annotatedClass, PersistentClass persistentClass, MetadataBuildingContext context) { @@ -1309,40 +1319,41 @@ public class EntityBinder { } private void bindRowManagement() { - final AnnotationUsage dynamicInsertAnn = annotatedClass.getAnnotationUsage( DynamicInsert.class ); - persistentClass.setDynamicInsert( dynamicInsertAnn != null && dynamicInsertAnn.getBoolean( "value" ) ); - final AnnotationUsage dynamicUpdateAnn = annotatedClass.getAnnotationUsage( DynamicUpdate.class ); - persistentClass.setDynamicUpdate( dynamicUpdateAnn != null && dynamicUpdateAnn.getBoolean( "value" ) ); + final DynamicInsert dynamicInsertAnn = annotatedClass.getAnnotationUsage( DynamicInsert.class, getSourceModelContext() ); + persistentClass.setDynamicInsert( dynamicInsertAnn != null && dynamicInsertAnn.value() ); - if ( persistentClass.useDynamicInsert() && annotatedClass.hasAnnotationUsage( SQLInsert.class ) ) { + final DynamicUpdate dynamicUpdateAnn = annotatedClass.getAnnotationUsage( DynamicUpdate.class, getSourceModelContext() ); + persistentClass.setDynamicUpdate( dynamicUpdateAnn != null && dynamicUpdateAnn.value() ); + + if ( persistentClass.useDynamicInsert() && annotatedClass.hasAnnotationUsage( SQLInsert.class, getSourceModelContext() ) ) { throw new AnnotationException( "Entity '" + name + "' is annotated both '@DynamicInsert' and '@SQLInsert'" ); } - if ( persistentClass.useDynamicUpdate() && annotatedClass.hasAnnotationUsage( SQLUpdate.class ) ) { + if ( persistentClass.useDynamicUpdate() && annotatedClass.hasAnnotationUsage( SQLUpdate.class, getSourceModelContext() ) ) { throw new AnnotationException( "Entity '" + name + "' is annotated both '@DynamicUpdate' and '@SQLUpdate'" ); } - final AnnotationUsage selectBeforeUpdateAnn = annotatedClass.getAnnotationUsage( SelectBeforeUpdate.class ); - persistentClass.setSelectBeforeUpdate( selectBeforeUpdateAnn != null && selectBeforeUpdateAnn.getBoolean( "value" ) ); + final SelectBeforeUpdate selectBeforeUpdateAnn = annotatedClass.getAnnotationUsage( SelectBeforeUpdate.class, getSourceModelContext() ); + persistentClass.setSelectBeforeUpdate( selectBeforeUpdateAnn != null && selectBeforeUpdateAnn.value() ); } private void bindOptimisticLocking() { - final AnnotationUsage optimisticLockingAnn = annotatedClass.getAnnotationUsage( OptimisticLocking.class ); + final OptimisticLocking optimisticLockingAnn = annotatedClass.getAnnotationUsage( OptimisticLocking.class, getSourceModelContext() ); persistentClass.setOptimisticLockStyle( fromLockType( optimisticLockingAnn == null ? OptimisticLockType.VERSION - : optimisticLockingAnn.getEnum( "type" ) ) ); + : optimisticLockingAnn.type() ) ); } private void bindPolymorphism() { - final AnnotationUsage polymorphismAnn = annotatedClass.getAnnotationUsage( Polymorphism.class ); - polymorphismType = polymorphismAnn == null ? IMPLICIT : polymorphismAnn.getEnum( "type" ); + final Polymorphism polymorphismAnn = annotatedClass.getAnnotationUsage( Polymorphism.class, getSourceModelContext() ); + polymorphismType = polymorphismAnn == null ? IMPLICIT : polymorphismAnn.type(); } private void bindEntityAnnotation() { - final AnnotationUsage entity = annotatedClass.getAnnotationUsage( Entity.class ); + final Entity entity = annotatedClass.getAnnotationUsage( Entity.class, getSourceModelContext() ); if ( entity == null ) { throw new AssertionFailure( "@Entity should never be missing" ); } - final String entityName = entity.getString( "name" ); + final String entityName = entity.name(); name = entityName.isEmpty() ? unqualify( annotatedClass.getName() ) : entityName; } @@ -1394,13 +1405,13 @@ public class EntityBinder { } private void ensureNoMutabilityPlan() { - if ( annotatedClass.hasAnnotationUsage( Mutability.class ) ) { + if ( annotatedClass.hasAnnotationUsage( Mutability.class, getSourceModelContext() ) ) { throw new MappingException( "@Mutability is not allowed on entity" ); } } private boolean isMutable() { - return !annotatedClass.hasAnnotationUsage(Immutable.class); + return !annotatedClass.hasAnnotationUsage( Immutable.class, getSourceModelContext() ); } private void registerImportName() { @@ -1435,68 +1446,68 @@ public class EntityBinder { private void bindCustomSql() { final String primaryTableName = persistentClass.getTable().getName(); - AnnotationUsage sqlInsert = resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, primaryTableName ); + SQLInsert sqlInsert = resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, primaryTableName ); if ( sqlInsert == null ) { sqlInsert = resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, "" ); } if ( sqlInsert != null ) { persistentClass.setCustomSQLInsert( - sqlInsert.getString( "sql" ).trim(), - sqlInsert.getBoolean( "callable" ), - fromResultCheckStyle( sqlInsert.getEnum( "check" ) ) + sqlInsert.sql().trim(), + sqlInsert.callable(), + fromResultCheckStyle( sqlInsert.check() ) ); - final Class expectationClass = sqlInsert.getClassDetails("verify").toJavaClass(); + final Class expectationClass = sqlInsert.verify(); if ( expectationClass != Expectation.class ) { persistentClass.setInsertExpectation( getDefaultSupplier( expectationClass ) ); } } - AnnotationUsage sqlUpdate = resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, primaryTableName ); + SQLUpdate sqlUpdate = resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, primaryTableName ); if ( sqlUpdate == null ) { sqlUpdate = resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, "" ); } if ( sqlUpdate != null ) { persistentClass.setCustomSQLUpdate( - sqlUpdate.getString( "sql" ).trim(), - sqlUpdate.getBoolean( "callable" ), - fromResultCheckStyle( sqlUpdate.getEnum( "check" ) ) + sqlUpdate.sql().trim(), + sqlUpdate.callable(), + fromResultCheckStyle( sqlUpdate.check() ) ); - final Class expectationClass = sqlUpdate.getClassDetails("verify").toJavaClass(); + final Class expectationClass = sqlUpdate.verify(); if ( expectationClass != Expectation.class ) { persistentClass.setUpdateExpectation( getDefaultSupplier( expectationClass ) ); } } - AnnotationUsage sqlDelete = resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, primaryTableName ); + SQLDelete sqlDelete = resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, primaryTableName ); if ( sqlDelete == null ) { sqlDelete = resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, "" ); } if ( sqlDelete != null ) { persistentClass.setCustomSQLDelete( - sqlDelete.getString( "sql" ).trim(), - sqlDelete.getBoolean( "callable" ), - fromResultCheckStyle( sqlDelete.getEnum( "check" ) ) + sqlDelete.sql().trim(), + sqlDelete.callable(), + fromResultCheckStyle( sqlDelete.check() ) ); - final Class expectationClass = sqlDelete.getClassDetails("verify").toJavaClass(); + final Class expectationClass = sqlDelete.verify(); if ( expectationClass != Expectation.class ) { persistentClass.setDeleteExpectation( getDefaultSupplier( expectationClass ) ); } } - final AnnotationUsage sqlDeleteAll = resolveCustomSqlAnnotation( annotatedClass, SQLDeleteAll.class, "" ); + final SQLDeleteAll sqlDeleteAll = resolveCustomSqlAnnotation( annotatedClass, SQLDeleteAll.class, "" ); if ( sqlDeleteAll != null ) { throw new AnnotationException("@SQLDeleteAll does not apply to entities: " + persistentClass.getEntityName()); } - final AnnotationUsage sqlSelect = getOverridableAnnotation( annotatedClass, SQLSelect.class, context ); + final SQLSelect sqlSelect = getOverridableAnnotation( annotatedClass, SQLSelect.class, context ); if ( sqlSelect != null ) { final String loaderName = persistentClass.getEntityName() + "$SQLSelect"; persistentClass.setLoaderName( loaderName ); QueryBinder.bindNativeQuery( loaderName, sqlSelect, annotatedClass, context ); } - final AnnotationUsage hqlSelect = annotatedClass.getAnnotationUsage( HQLSelect.class ); + final HQLSelect hqlSelect = annotatedClass.getAnnotationUsage( HQLSelect.class, getSourceModelContext() ); if ( hqlSelect != null ) { final String loaderName = persistentClass.getEntityName() + "$HQLSelect"; persistentClass.setLoaderName( loaderName ); @@ -1505,59 +1516,70 @@ public class EntityBinder { } private void bindCustomLoader() { - final AnnotationUsage loader = annotatedClass.getAnnotationUsage( Loader.class ); + final Loader loader = annotatedClass.getAnnotationUsage( Loader.class, getSourceModelContext() ); if ( loader != null ) { - persistentClass.setLoaderName( loader.getString( "namedQuery" ) ); + persistentClass.setLoaderName( loader.namedQuery() ); } } private void bindSubselect() { - final AnnotationUsage subselect = annotatedClass.getAnnotationUsage( Subselect.class ); + final Subselect subselect = annotatedClass.getAnnotationUsage( Subselect.class, getSourceModelContext() ); if ( subselect != null ) { - this.subselect = subselect.getString( "value" ); + this.subselect = subselect.value(); } } - private AnnotationUsage resolveCustomSqlAnnotation( + private A resolveCustomSqlAnnotation( ClassDetails annotatedClass, Class annotationType, String tableName) { + // E.g. we are looking for SQLInsert... + // - the overrideAnnotation would be DialectOverride.SQLInsert + // - we first look for all uses of DialectOverride.SQLInsert, if any, and see if they "match" + // - if so, we return the matched override + // - if not, we return the normal SQLInsert (if one) final Class overrideAnnotation = getOverrideAnnotation( annotationType ); - final List> dialectOverrides = annotatedClass.getRepeatedAnnotationUsages( overrideAnnotation ); + final Annotation[] dialectOverrides = annotatedClass.getRepeatedAnnotationUsages( + overrideAnnotation, + getSourceModelContext() + ); if ( isNotEmpty( dialectOverrides ) ) { - for ( AnnotationUsage dialectOverride : dialectOverrides ) { - if ( !overrideMatchesDialect( dialectOverride, context.getMetadataCollector().getDatabase().getDialect() ) ) { + final Dialect dialect = context.getMetadataCollector().getDatabase().getDialect(); + for ( int i = 0; i < dialectOverrides.length; i++ ) { + //noinspection unchecked + final DialectOverrider dialectOverride = (DialectOverrider) dialectOverrides[i]; + if ( !dialectOverride.matches( dialect ) ) { continue; } - final AnnotationUsage override = dialectOverride.getNestedUsage( "override" ); + final A override = dialectOverride.override(); if ( isEmpty( tableName ) - && isEmpty( override.getString( "table" ) ) ) { + && isEmpty( ( (CustomSqlDetails) override ).table() ) ) { return override; } else if ( isNotEmpty( tableName ) - && tableName.equals( override.getString( "table" ) ) ) { + && tableName.equals( ( (CustomSqlDetails) override ).table() ) ) { return override; } } } - return annotatedClass.getNamedAnnotationUsage( annotationType, tableName, "table" ); + return annotatedClass.getNamedAnnotationUsage( annotationType, tableName, "table", getSourceModelContext() ); } private void bindFilters() { - for ( AnnotationUsage filter : filters ) { - final String filterName = filter.getString( "name" ); - String condition = filter.getString( "condition" ); + for ( Filter filter : filters ) { + final String filterName = filter.name(); + String condition = filter.condition(); if ( condition.isEmpty() ) { condition = getDefaultFilterCondition( filterName ); } persistentClass.addFilter( filterName, condition, - filter.getBoolean( "deduceAliasInjectionPoints" ), - toAliasTableMap( filter.getList( "aliases" ) ), - toAliasEntityMap( filter.getList( "aliases" ) ) + filter.deduceAliasInjectionPoints(), + toAliasTableMap( filter.aliases() ), + toAliasEntityMap( filter.aliases() ) ); } } @@ -1578,15 +1600,17 @@ public class EntityBinder { } private void bindSynchronize() { - if ( annotatedClass.hasAnnotationUsage( Synchronize.class ) ) { - final JdbcEnvironment jdbcEnvironment = context.getMetadataCollector().getDatabase().getJdbcEnvironment(); - final AnnotationUsage synchronize = annotatedClass.getAnnotationUsage( Synchronize.class); - final boolean logical = synchronize.getBoolean( "logical" ); - final List tableNames = synchronize.getList( "value" ); - for ( String tableName : tableNames ) { - String physicalName = logical ? toPhysicalName( jdbcEnvironment, tableName ) : tableName; - persistentClass.addSynchronizedTable( physicalName ); - } + final Synchronize synchronize = annotatedClass.getAnnotationUsage( Synchronize.class, getSourceModelContext() ); + if ( synchronize == null ) { + return; + } + + final JdbcEnvironment jdbcEnvironment = context.getMetadataCollector().getDatabase().getJdbcEnvironment(); + final boolean logical = synchronize.logical(); + final String[] tableNames = synchronize.value(); + for ( String tableName : tableNames ) { + String physicalName = logical ? toPhysicalName( jdbcEnvironment, tableName ) : tableName; + persistentClass.addSynchronizedTable( physicalName ); } } @@ -1603,21 +1627,22 @@ public class EntityBinder { } private void processNamedEntityGraphs() { - annotatedClass.forEachAnnotationUsage( NamedEntityGraph.class, this::processNamedEntityGraph ); + annotatedClass.forEachAnnotationUsage( NamedEntityGraph.class, getSourceModelContext(), this::processNamedEntityGraph ); } - private void processNamedEntityGraph(AnnotationUsage annotation) { + private void processNamedEntityGraph(NamedEntityGraph annotation) { if ( annotation == null ) { return; } context.getMetadataCollector().addNamedEntityGraph( - new NamedEntityGraphDefinition( annotation.toAnnotation(), name, persistentClass.getEntityName() ) + new NamedEntityGraphDefinition( annotation, name, persistentClass.getEntityName() ) ); } public void bindDiscriminatorValue() { - final String discriminatorValue = annotatedClass.hasAnnotationUsage( DiscriminatorValue.class ) - ? annotatedClass.getAnnotationUsage( DiscriminatorValue.class ).getString( "value" ) + final DiscriminatorValue discriminatorValueAnn = annotatedClass.getAnnotationUsage( DiscriminatorValue.class, getSourceModelContext() ); + final String discriminatorValue = discriminatorValueAnn != null + ? discriminatorValueAnn.value() : null; if ( isEmpty( discriminatorValue ) ) { final Value discriminator = persistentClass.getDiscriminator(); @@ -1641,10 +1666,10 @@ public class EntityBinder { } public void bindProxy() { - final AnnotationUsage proxy = annotatedClass.getAnnotationUsage( Proxy.class ); + final Proxy proxy = annotatedClass.getAnnotationUsage( Proxy.class, getSourceModelContext() ); if ( proxy != null ) { - lazy = proxy.getBoolean( "lazy" ); - proxyClass = lazy ? resolveProxyClass( proxy, annotatedClass ) : null; + lazy = proxy.lazy(); + proxyClass = lazy ? resolveProxyClass( proxy, annotatedClass, getSourceModelContext() ) : null; } else { //needed to allow association lazy loading. @@ -1653,16 +1678,19 @@ public class EntityBinder { } } - private static ClassDetails resolveProxyClass(AnnotationUsage proxy, ClassDetails annotatedClass) { - final ClassDetails proxyClass = proxy.getClassDetails( "proxyClass" ); - if ( proxyClass == ClassDetails.VOID_CLASS_DETAILS ) { + private static ClassDetails resolveProxyClass( + Proxy proxy, + ClassDetails annotatedClass, + SourceModelBuildingContext sourceModelContext) { + final Class explicitProxyClass = proxy.proxyClass(); + if ( explicitProxyClass == void.class ) { return annotatedClass; } - return proxyClass; + return sourceModelContext.getClassDetailsRegistry().resolveClassDetails( explicitProxyClass.getName() ); } public void bindConcreteProxy() { - final AnnotationUsage annotationUsage = annotatedClass.getAnnotationUsage( ConcreteProxy.class ); + final ConcreteProxy annotationUsage = annotatedClass.getAnnotationUsage( ConcreteProxy.class, getSourceModelContext() ); if ( annotationUsage != null ) { if ( persistentClass.getSuperclass() != null ) { throw new AnnotationException( "Entity class '" + persistentClass.getClassName() @@ -1673,13 +1701,13 @@ public class EntityBinder { } public void bindWhere() { - final AnnotationUsage where = getOverridableAnnotation( annotatedClass, Where.class, context ); + final Where where = getOverridableAnnotation( annotatedClass, Where.class, context ); if ( where != null ) { - this.where = where.getString( "clause" ); + this.where = where.clause(); } - final AnnotationUsage restriction = getOverridableAnnotation( annotatedClass, SQLRestriction.class, context ); + final SQLRestriction restriction = getOverridableAnnotation( annotatedClass, SQLRestriction.class, context ); if ( restriction != null ) { - this.where = restriction.getString( "value" ); + this.where = restriction.value(); } } @@ -1689,21 +1717,21 @@ public class EntityBinder { private void bindNaturalIdCache() { naturalIdCacheRegion = null; - final AnnotationUsage naturalIdCacheAnn = annotatedClass.getAnnotationUsage( NaturalIdCache.class ); + final NaturalIdCache naturalIdCacheAnn = annotatedClass.getAnnotationUsage( NaturalIdCache.class, getSourceModelContext() ); if ( naturalIdCacheAnn == null ) { return; } - final String region = naturalIdCacheAnn.getString( "region" ); + final String region = naturalIdCacheAnn.region(); if ( region.isEmpty() ) { - final AnnotationUsage explicitCacheAnn = annotatedClass.getAnnotationUsage( Cache.class ); + final Cache explicitCacheAnn = annotatedClass.getAnnotationUsage( Cache.class, getSourceModelContext() ); - naturalIdCacheRegion = explicitCacheAnn != null && isNotEmpty( explicitCacheAnn.getString( "region") ) - ? explicitCacheAnn.getString( "region") + NATURAL_ID_CACHE_SUFFIX + naturalIdCacheRegion = explicitCacheAnn != null && isNotEmpty( explicitCacheAnn.region() ) + ? explicitCacheAnn.region() + NATURAL_ID_CACHE_SUFFIX : annotatedClass.getName() + NATURAL_ID_CACHE_SUFFIX; } else { - naturalIdCacheRegion = naturalIdCacheAnn.getString( "region" ); + naturalIdCacheRegion = naturalIdCacheAnn.region(); } } @@ -1723,7 +1751,7 @@ public class EntityBinder { } private void bindSubclassCache(SharedCacheMode sharedCacheMode) { - if ( annotatedClass.hasAnnotationUsage( Cache.class ) ) { + if ( annotatedClass.hasAnnotationUsage( Cache.class, getSourceModelContext() ) ) { final String className = persistentClass.getClassName() == null ? annotatedClass.getName() : persistentClass.getClassName(); @@ -1732,7 +1760,7 @@ public class EntityBinder { +" (only root classes may define second-level caching semantics)"); } - final AnnotationUsage cacheable = annotatedClass.getAnnotationUsage( Cacheable.class ); + final Cacheable cacheable = annotatedClass.getAnnotationUsage( Cacheable.class, getSourceModelContext() ); isCached = cacheable == null && persistentClass.getSuperclass() != null // we should inherit the root class caching config ? persistentClass.getSuperclass().isCached() @@ -1742,9 +1770,9 @@ public class EntityBinder { } private void bindRootClassCache(SharedCacheMode sharedCacheMode, MetadataBuildingContext context) { - final AnnotationUsage cache = annotatedClass.getAnnotationUsage( Cache.class ); - final AnnotationUsage cacheable = annotatedClass.getAnnotationUsage( Cacheable.class ); - final AnnotationUsage effectiveCache; + final Cache cache = annotatedClass.getAnnotationUsage( Cache.class, getSourceModelContext() ); + final Cacheable cacheable = annotatedClass.getAnnotationUsage( Cacheable.class, getSourceModelContext() ); + final Cache effectiveCache; if ( cache != null ) { // preserve legacy behavior of circumventing SharedCacheMode when Hibernate's @Cache is used. isCached = true; @@ -1754,28 +1782,28 @@ public class EntityBinder { effectiveCache = buildCacheMock( annotatedClass, context ); isCached = isCacheable( sharedCacheMode, cacheable ); } - cacheConcurrentStrategy = resolveCacheConcurrencyStrategy( effectiveCache.getEnum( "usage" ) ); - cacheRegion = effectiveCache.getString( "region" ); + cacheConcurrentStrategy = resolveCacheConcurrencyStrategy( effectiveCache.usage() ); + cacheRegion = effectiveCache.region(); cacheLazyProperty = isCacheLazy( effectiveCache, annotatedClass ); - final AnnotationUsage queryCache = annotatedClass.getAnnotationUsage( QueryCacheLayout.class ); - queryCacheLayout = queryCache == null ? null : queryCache.getEnum( "layout" ); + final QueryCacheLayout queryCache = annotatedClass.getAnnotationUsage( QueryCacheLayout.class, getSourceModelContext() ); + queryCacheLayout = queryCache == null ? null : queryCache.layout(); } - private static boolean isCacheLazy(AnnotationUsage effectiveCache, ClassDetails annotatedClass) { - if ( !effectiveCache.getBoolean( "includeLazy" ) ) { + private static boolean isCacheLazy(Cache effectiveCache, ClassDetails annotatedClass) { + if ( !effectiveCache.includeLazy() ) { return false; } - return switch ( effectiveCache.getString( "include" ).toLowerCase( Locale.ROOT ) ) { + return switch ( effectiveCache.include().toLowerCase( Locale.ROOT ) ) { case "all" -> true; case "non-lazy" -> false; default -> throw new AnnotationException( "Class '" + annotatedClass.getName() - + "' has a '@Cache' with undefined option 'include=\"" + effectiveCache.getString( "include" ) + "\"'" ); + + "' has a '@Cache' with undefined option 'include=\"" + effectiveCache.include() + "\"'" ); }; } - private static boolean isCacheable(SharedCacheMode sharedCacheMode, AnnotationUsage explicitCacheableAnn) { + private static boolean isCacheable(SharedCacheMode sharedCacheMode, Cacheable explicitCacheableAnn) { return switch ( sharedCacheMode ) { case ALL -> // all entities should be cached @@ -1783,10 +1811,10 @@ public class EntityBinder { case ENABLE_SELECTIVE, UNSPECIFIED -> // Hibernate defaults to ENABLE_SELECTIVE, the only sensible setting // only entities with @Cacheable(true) should be cached - explicitCacheableAnn != null && explicitCacheableAnn.getBoolean( "value" ); + explicitCacheableAnn != null && explicitCacheableAnn.value(); case DISABLE_SELECTIVE -> // only entities with @Cacheable(false) should not be cached - explicitCacheableAnn == null || explicitCacheableAnn.getBoolean( "value" ); + explicitCacheableAnn == null || explicitCacheableAnn.value(); default -> // treat both NONE and UNSPECIFIED the same false; @@ -1798,10 +1826,10 @@ public class EntityBinder { return accessType == null ? null : accessType.getExternalName(); } - private static AnnotationUsage buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) { - final MutableAnnotationUsage cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); - applyAttributeIfSpecified( "region", classDetails.getName(), cacheUsage ); - applyAttributeIfSpecified( "usage", determineCacheConcurrencyStrategy( context ), cacheUsage ); + private static Cache buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) { + final CacheAnnotation cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); + cacheUsage.region( classDetails.getName() ); + cacheUsage.usage( determineCacheConcurrencyStrategy( context ) ); return cacheUsage; } @@ -1895,7 +1923,7 @@ public class EntityBinder { String schema, String catalog, String tableName, - List> uniqueConstraints, + UniqueConstraint[] uniqueConstraints, String rowId, String viewQuery, InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) { @@ -1962,38 +1990,35 @@ public class EntityBinder { } } - private void createPrimaryColumnsToSecondaryTable(Object column, PropertyHolder propertyHolder, Join join) { - // `column` will be a list of some sort... - //noinspection unchecked,rawtypes - final List joinColumnSource = (List) column; + private void createPrimaryColumnsToSecondaryTable( + Object incoming, + PropertyHolder propertyHolder, + Join join) { + // `incoming` will be an array of some sort of annotation + final Annotation[] joinColumnSource = (Annotation[]) incoming; final AnnotatedJoinColumns annotatedJoinColumns; if ( CollectionHelper.isEmpty( joinColumnSource ) ) { annotatedJoinColumns = createDefaultJoinColumn( propertyHolder ); } else { - final List> pkJoinColumns; - final List> joinColumns; + final PrimaryKeyJoinColumn[] pkJoinColumns; + final JoinColumn[] joinColumns; - //noinspection rawtypes - final AnnotationUsage first = joinColumnSource.get( 0 ); - if ( first.getAnnotationDescriptor().getAnnotationType() - .equals( PrimaryKeyJoinColumn.class ) ) { - //noinspection unchecked,rawtypes - pkJoinColumns = (List) joinColumnSource; + final Annotation first = joinColumnSource[0]; + if ( first instanceof PrimaryKeyJoinColumn ) { + pkJoinColumns = (PrimaryKeyJoinColumn[]) joinColumnSource; joinColumns = null; } - else if ( first.getAnnotationDescriptor().getAnnotationType() - .equals( JoinColumn.class ) ) { + else if ( first instanceof JoinColumn ) { pkJoinColumns = null; - //noinspection unchecked,rawtypes - joinColumns = (List) joinColumnSource; + joinColumns = (JoinColumn[]) joinColumnSource; } else { throw new IllegalArgumentException( "Expecting list of AnnotationUsages for either @JoinColumn or @PrimaryKeyJoinColumn" + ", but got as list of AnnotationUsages for @" - + first.getAnnotationDescriptor().getAnnotationType().getName() + + first.annotationType().getName() ); } @@ -2024,9 +2049,9 @@ public class EntityBinder { private AnnotatedJoinColumns createJoinColumns( PropertyHolder propertyHolder, - List> primaryKeyJoinColumns, - List> joinColumns) { - final int joinColumnCount = primaryKeyJoinColumns != null ? primaryKeyJoinColumns.size() : joinColumns.size(); + PrimaryKeyJoinColumn[] primaryKeyJoinColumns, + JoinColumn[] joinColumns) { + final int joinColumnCount = primaryKeyJoinColumns != null ? primaryKeyJoinColumns.length : joinColumns.length; if ( joinColumnCount == 0 ) { return createDefaultJoinColumn( propertyHolder ); } @@ -2036,14 +2061,12 @@ public class EntityBinder { columns.setJoins( secondaryTables ); columns.setPropertyHolder( propertyHolder ); for ( int colIndex = 0; colIndex < joinColumnCount; colIndex++ ) { - final AnnotationUsage primaryKeyJoinColumn = - primaryKeyJoinColumns != null - ? primaryKeyJoinColumns.get( colIndex) - : null; - final AnnotationUsage joinColumn = - joinColumns != null - ? joinColumns.get(colIndex) - : null; + final PrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns != null + ? primaryKeyJoinColumns[colIndex] + : null; + final JoinColumn joinColumn = joinColumns != null + ? joinColumns[colIndex] + : null; buildInheritanceJoinColumn( primaryKeyJoinColumn, joinColumn, @@ -2070,38 +2093,38 @@ public class EntityBinder { private void setForeignKeyNameIfDefined(Join join) { final String tableName = join.getTable().getQuotedName(); - final AnnotationUsage matchingTable = findMatchingComplementaryTableAnnotation( tableName ); + final org.hibernate.annotations.Table matchingTable = findMatchingComplementaryTableAnnotation( tableName ); final SimpleValue key = (SimpleValue) join.getKey(); - if ( matchingTable != null && !matchingTable.getNestedUsage( "foreignKey" ).getString( "name" ).isEmpty() ) { - key.setForeignKeyName( matchingTable.getNestedUsage( "foreignKey" ).getString( "name" ) ); + if ( matchingTable != null && !matchingTable.foreignKey().name().isEmpty() ) { + key.setForeignKeyName( matchingTable.foreignKey().name() ); } else { - final AnnotationUsage jpaSecondaryTable = findMatchingSecondaryTable( join ); + final SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable( join ); if ( jpaSecondaryTable != null ) { final boolean noConstraintByDefault = context.getBuildingOptions().isNoConstraintByDefault(); - if ( jpaSecondaryTable.getNestedUsage( "foreignKey" ).getEnum( "value" ) == ConstraintMode.NO_CONSTRAINT - || jpaSecondaryTable.getNestedUsage( "foreignKey" ).getEnum( "value" ) == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) { + if ( jpaSecondaryTable.foreignKey().value() == ConstraintMode.NO_CONSTRAINT + || jpaSecondaryTable.foreignKey().value() == ConstraintMode.PROVIDER_DEFAULT && noConstraintByDefault ) { key.disableForeignKey(); } else { - key.setForeignKeyName( nullIfEmpty( jpaSecondaryTable.getNestedUsage( "foreignKey" ).getString( "name" ) ) ); - key.setForeignKeyDefinition( nullIfEmpty( jpaSecondaryTable.getNestedUsage( "foreignKey" ).getString( "foreignKeyDefinition" ) ) ); + key.setForeignKeyName( nullIfEmpty( jpaSecondaryTable.foreignKey().name() ) ); + key.setForeignKeyDefinition( nullIfEmpty( jpaSecondaryTable.foreignKey().foreignKeyDefinition() ) ); } } } } - private AnnotationUsage findMatchingSecondaryTable(Join join) { + private SecondaryTable findMatchingSecondaryTable(Join join) { final String nameToMatch = join.getTable().getQuotedName(); - final AnnotationUsage secondaryTable = annotatedClass.getSingleAnnotationUsage( SecondaryTable.class ); - if ( secondaryTable != null && nameToMatch.equals( secondaryTable.getString( "name" ) ) ) { + final SecondaryTable secondaryTable = annotatedClass.getDirectAnnotationUsage( SecondaryTable.class ); + if ( secondaryTable != null && nameToMatch.equals( secondaryTable.name() ) ) { return secondaryTable; } - final AnnotationUsage secondaryTables = annotatedClass.getAnnotationUsage( SecondaryTables.class ); + final SecondaryTables secondaryTables = annotatedClass.getDirectAnnotationUsage( SecondaryTables.class ); if ( secondaryTables != null ) { - final List> nestedSecondaryTableList = secondaryTables.getList( "value" ); - for ( AnnotationUsage nestedSecondaryTable : nestedSecondaryTableList ) { - if ( nestedSecondaryTable != null && nameToMatch.equals( nestedSecondaryTable.getString( "name" ) ) ) { + final SecondaryTable[] nestedSecondaryTableList = secondaryTables.value(); + for ( SecondaryTable nestedSecondaryTable : nestedSecondaryTableList ) { + if ( nestedSecondaryTable != null && nameToMatch.equals( nestedSecondaryTable.name() ) ) { return nestedSecondaryTable; } } @@ -2109,16 +2132,16 @@ public class EntityBinder { return null; } - private AnnotationUsage findMatchingComplementaryTableAnnotation(String tableName) { - final AnnotationUsage table = annotatedClass.getSingleAnnotationUsage( org.hibernate.annotations.Table.class ); - if ( table != null && tableName.equals( table.getString( "appliesTo" ) ) ) { + private org.hibernate.annotations.Table findMatchingComplementaryTableAnnotation(String tableName) { + final org.hibernate.annotations.Table table = annotatedClass.getDirectAnnotationUsage( org.hibernate.annotations.Table.class ); + if ( table != null && tableName.equals( table.appliesTo() ) ) { return table; } else { - final AnnotationUsage tables = annotatedClass.getAnnotationUsage( Tables.class ); + final Tables tables = annotatedClass.getAnnotationUsage( Tables.class, getSourceModelContext() ); if ( tables != null ) { - for (AnnotationUsage nested : tables.>getList( "value" )) { - if ( tableName.equals( nested.getString( "appliesTo" ) ) ) { + for (org.hibernate.annotations.Table nested : tables.value()) { + if ( tableName.equals( nested.appliesTo() ) ) { return nested; } } @@ -2127,17 +2150,17 @@ public class EntityBinder { } } - private AnnotationUsage findMatchingSecondaryRowAnnotation(String tableName) { - final AnnotationUsage row = annotatedClass.getSingleAnnotationUsage( SecondaryRow.class ); - if ( row != null && ( row.getString( "table" ).isEmpty() || tableName.equals( row.getString( "table" ) ) ) ) { + private SecondaryRow findMatchingSecondaryRowAnnotation(String tableName) { + final SecondaryRow row = annotatedClass.getDirectAnnotationUsage( SecondaryRow.class ); + if ( row != null && ( row.table().isEmpty() || tableName.equals( row.table() ) ) ) { return row; } else { - final AnnotationUsage tables = annotatedClass.getAnnotationUsage( SecondaryRows.class ); + final SecondaryRows tables = annotatedClass.getDirectAnnotationUsage( SecondaryRows.class ); if ( tables != null ) { - final List> rowList = tables.getList( "value" ); - for ( AnnotationUsage current : rowList ) { - if ( tableName.equals( current.getString( "table" ) ) ) { + final SecondaryRow[] rowList = tables.value(); + for ( SecondaryRow current : rowList ) { + if ( tableName.equals( current.table() ) ) { return current; } } @@ -2146,63 +2169,41 @@ public class EntityBinder { } } - private AnnotationUsage findMatchingSqlAnnotation( - String tableName, - Class annotationType, - Class repeatableType) { - final AnnotationUsage sqlAnnotation = getOverridableAnnotation( annotatedClass, annotationType, context ); - if ( sqlAnnotation != null ) { - if ( tableName.equals( sqlAnnotation.getString( "table" ) ) ) { - return sqlAnnotation; - } - } - //TODO: getOverridableAnnotation() does not yet handle @Repeatable annotations - final AnnotationUsage repeatable = annotatedClass.getAnnotationUsage( repeatableType ); - if ( repeatable != null ) { - for ( AnnotationUsage nested : repeatable.>getList( "value" ) ) { - if ( tableName.equals( nested.getString( "table" ) ) ) { - return nested; - } - } - } - return null; - } - //Used for @*ToMany @JoinTable - public Join addJoinTable(AnnotationUsage joinTable, PropertyHolder holder, boolean noDelayInPkColumnCreation) { + public Join addJoinTable(JoinTable joinTable, PropertyHolder holder, boolean noDelayInPkColumnCreation) { final Join join = addJoin( holder, noDelayInPkColumnCreation, false, - joinTable.getString( "name" ), - joinTable.getString( "schema" ), - joinTable.getString( "catalog" ), - joinTable.getList( "joinColumns" ), - joinTable.getList( "uniqueConstraints" ) + joinTable.name(), + joinTable.schema(), + joinTable.catalog(), + joinTable.joinColumns(), + joinTable.uniqueConstraints() ); final Table table = join.getTable(); - TableBinder.addTableCheck( table, joinTable.findAttributeValue( "check" ) ); - TableBinder.addTableComment( table, joinTable.getString( "comment" ) ); - TableBinder.addTableOptions( table, joinTable.getString( "options" ) ); + TableBinder.addTableCheck( table, joinTable.check() ); + TableBinder.addTableComment( table, joinTable.comment() ); + TableBinder.addTableOptions( table, joinTable.options() ); return join; } - public Join addSecondaryTable(AnnotationUsage secondaryTable, PropertyHolder holder, boolean noDelayInPkColumnCreation) { + public Join addSecondaryTable(SecondaryTable secondaryTable, PropertyHolder holder, boolean noDelayInPkColumnCreation) { final Join join = addJoin( holder, noDelayInPkColumnCreation, true, - secondaryTable.getString( "name" ), - secondaryTable.getString( "schema" ), - secondaryTable.getString( "catalog" ), - secondaryTable.getList( "pkJoinColumns" ), - secondaryTable.getList( "uniqueConstraints" ) + secondaryTable.name(), + secondaryTable.schema(), + secondaryTable.catalog(), + secondaryTable.pkJoinColumns(), + secondaryTable.uniqueConstraints() ); final Table table = join.getTable(); - new IndexBinder( context ).bindIndexes( table, secondaryTable.getList( "indexes" ) ); - TableBinder.addTableCheck( table, secondaryTable.findAttributeValue( "check" ) ); - TableBinder.addTableComment( table, secondaryTable.getString( "comment" ) ); - TableBinder.addTableOptions( table, secondaryTable.getString( "options" ) ); + new IndexBinder( context ).bindIndexes( table, secondaryTable.indexes() ); + TableBinder.addTableCheck( table, secondaryTable.check() ); + TableBinder.addTableComment( table, secondaryTable.comment() ); + TableBinder.addTableOptions( table, secondaryTable.options() ); return join; } @@ -2214,7 +2215,7 @@ public class EntityBinder { String schema, String catalog, Object joinColumns, - List> uniqueConstraints) { + UniqueConstraint[] uniqueConstraints) { final QualifiedTableName logicalName = logicalTableName( name, schema, catalog ); return createJoin( propertyHolder, @@ -2293,15 +2294,15 @@ public class EntityBinder { private void handleSecondaryRowManagement(Join join) { final String tableName = join.getTable().getQuotedName(); - final AnnotationUsage matchingTable = findMatchingComplementaryTableAnnotation( tableName ); - final AnnotationUsage matchingRow = findMatchingSecondaryRowAnnotation( tableName ); + final org.hibernate.annotations.Table matchingTable = findMatchingComplementaryTableAnnotation( tableName ); + final SecondaryRow matchingRow = findMatchingSecondaryRowAnnotation( tableName ); if ( matchingRow != null ) { - join.setInverse( !matchingRow.getBoolean( "owned" ) ); - join.setOptional( matchingRow.getBoolean( "optional" ) ); + join.setInverse( !matchingRow.owned() ); + join.setOptional( matchingRow.optional() ); } else if ( matchingTable != null ) { - join.setInverse( matchingTable.getBoolean( "inverse" ) ); - join.setOptional( matchingTable.getBoolean( "optional" ) ); + join.setInverse( matchingTable.inverse() ); + join.setOptional( matchingTable.optional() ); } else { //default @@ -2312,80 +2313,76 @@ public class EntityBinder { private void processSecondaryTableCustomSql(Join join) { final String tableName = join.getTable().getQuotedName(); - final AnnotationUsage matchingTable = - findMatchingComplementaryTableAnnotation( tableName ); + final org.hibernate.annotations.Table matchingTable = findMatchingComplementaryTableAnnotation( tableName ); - final AnnotationUsage sqlInsert = - resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, tableName ); + final SQLInsert sqlInsert = resolveCustomSqlAnnotation( annotatedClass, SQLInsert.class, tableName ); if ( sqlInsert != null ) { join.setCustomSQLInsert( - sqlInsert.getString( "sql" ).trim(), - sqlInsert.getBoolean( "callable" ), - fromResultCheckStyle( sqlInsert.getEnum( "check" ) ) + sqlInsert.sql().trim(), + sqlInsert.callable(), + fromResultCheckStyle( sqlInsert.check() ) ); - final Class expectationClass = sqlInsert.getClassDetails("verify").toJavaClass(); + final Class expectationClass = sqlInsert.verify(); if ( expectationClass != Expectation.class ) { join.setInsertExpectation( getDefaultSupplier( expectationClass ) ); } } else if ( matchingTable != null ) { - final AnnotationUsage matchingTableInsert = matchingTable.getNestedUsage( "sqlInsert" ); - final String matchingTableInsertSql = matchingTableInsert.getString( "sql" ).trim(); + final SQLInsert matchingTableInsert = matchingTable.sqlInsert(); + final String matchingTableInsertSql = matchingTableInsert.sql().trim(); if ( !matchingTableInsertSql.isEmpty() ) { join.setCustomSQLInsert( matchingTableInsertSql, - matchingTableInsert.getBoolean( "callable" ), - fromResultCheckStyle( matchingTableInsert.getEnum( "check" ) ) + matchingTableInsert.callable(), + fromResultCheckStyle( matchingTableInsert.check() ) ); } } - final AnnotationUsage sqlUpdate = - resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, tableName ); + final SQLUpdate sqlUpdate = resolveCustomSqlAnnotation( annotatedClass, SQLUpdate.class, tableName ); if ( sqlUpdate != null ) { join.setCustomSQLUpdate( - sqlUpdate.getString( "sql" ).trim(), - sqlUpdate.getBoolean( "callable" ), - fromResultCheckStyle( sqlUpdate.getEnum( "check" ) ) + sqlUpdate.sql().trim(), + sqlUpdate.callable(), + fromResultCheckStyle( sqlUpdate.check() ) ); - final Class expectationClass = sqlUpdate.getClassDetails("verify").toJavaClass(); + final Class expectationClass = sqlUpdate.verify(); if ( expectationClass != Expectation.class ) { join.setUpdateExpectation( getDefaultSupplier( expectationClass ) ); } } else if ( matchingTable != null ) { - final AnnotationUsage matchingTableUpdate = matchingTable.getNestedUsage( "sqlUpdate" ); - final String matchingTableUpdateSql = matchingTableUpdate.getString( "sql" ).trim(); + final SQLUpdate matchingTableUpdate = matchingTable.sqlUpdate(); + final String matchingTableUpdateSql = matchingTableUpdate.sql().trim(); if ( !matchingTableUpdateSql.isEmpty() ) { join.setCustomSQLUpdate( matchingTableUpdateSql, - matchingTableUpdate.getBoolean( "callable" ), - fromResultCheckStyle( matchingTableUpdate.getEnum( "check" ) ) + matchingTableUpdate.callable(), + fromResultCheckStyle( matchingTableUpdate.check() ) ); } } - final AnnotationUsage sqlDelete = - resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, tableName ); + final SQLDelete sqlDelete = resolveCustomSqlAnnotation( annotatedClass, SQLDelete.class, tableName ); if ( sqlDelete != null ) { join.setCustomSQLDelete( - sqlDelete.getString( "sql" ).trim(), - sqlDelete.getBoolean( "callable" ), - fromResultCheckStyle( sqlDelete.getEnum( "check" ) ) + sqlDelete.sql().trim(), + sqlDelete.callable(), + fromResultCheckStyle( sqlDelete.check() ) ); - final Class expectationClass = sqlDelete.getClassDetails("verify").toJavaClass(); + final Class expectationClass = sqlDelete.verify(); if ( expectationClass != Expectation.class ) { join.setDeleteExpectation( getDefaultSupplier( expectationClass ) ); } } else if ( matchingTable != null ) { - final AnnotationUsage matchingTableDelete = matchingTable.getNestedUsage( "sqlDelete" ); - final String deleteSql = matchingTableDelete.getString( "sql" ).trim(); + final SQLDelete matchingTableDelete = matchingTable.sqlDelete(); + final String deleteSql = matchingTableDelete.sql().trim(); if ( !deleteSql.isEmpty() ) { join.setCustomSQLDelete( deleteSql, - matchingTableDelete.getBoolean( "callable" ), - fromResultCheckStyle( matchingTableDelete.getEnum( "check" ) ) + matchingTableDelete.callable(), + fromResultCheckStyle( matchingTableDelete.check() ) ); } } @@ -2400,7 +2397,7 @@ public class EntityBinder { return accessType == null ? null : accessType.getExternalName(); } - public void addFilter(AnnotationUsage filter) { + public void addFilter(Filter filter) { filters.add( filter ); } @@ -2450,9 +2447,9 @@ public class EntityBinder { public AccessType getExplicitAccessType(AnnotationTarget element) { AccessType accessType = null; if ( element != null ) { - final AnnotationUsage access = element.getAnnotationUsage( Access.class ); + final Access access = element.getAnnotationUsage( Access.class, getSourceModelContext() ); if ( access != null ) { - accessType = AccessType.getAccessStrategy( access.getEnum( "value" ) ); + accessType = AccessType.getAccessStrategy( access.value() ); } } return accessType; @@ -2480,13 +2477,13 @@ public class EntityBinder { } private void bindFilters(AnnotationTarget element) { - final AnnotationUsage filters = getOverridableAnnotation( element, Filters.class, context ); + final Filters filters = getOverridableAnnotation( element, Filters.class, context ); if ( filters != null ) { - for ( AnnotationUsage filter : filters.>getList( "value" ) ) { + for ( Filter filter : filters.value() ) { addFilter( filter ); } } - final AnnotationUsage filter = element.getSingleAnnotationUsage( Filter.class ); + final Filter filter = element.getDirectAnnotationUsage( Filter.class ); if ( filter != null ) { addFilter( filter ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchOverrideSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchOverrideSecondPass.java index 7a33fdaf6f..45e62606e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchOverrideSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchOverrideSecondPass.java @@ -6,28 +6,26 @@ */ package org.hibernate.boot.model.internal; +import java.util.Map; + import org.hibernate.MappingException; import org.hibernate.annotations.FetchProfile.FetchOverride; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.SecondPass; import org.hibernate.mapping.FetchProfile; import org.hibernate.mapping.PersistentClass; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; - -import java.util.Map; /** * @author Hardy Ferentschik */ public class FetchOverrideSecondPass implements SecondPass { private final String fetchProfileName; - private final AnnotationUsage fetch; + private final FetchOverride fetch; private final MetadataBuildingContext buildingContext; public FetchOverrideSecondPass( String fetchProfileName, - AnnotationUsage fetch, + FetchOverride fetch, MetadataBuildingContext buildingContext) { this.fetchProfileName = fetchProfileName; this.fetch = fetch; @@ -36,8 +34,8 @@ public class FetchOverrideSecondPass implements SecondPass { @Override public void doSecondPass(Map persistentClasses) throws MappingException { - final ClassDetails entityClassDetails = fetch.getClassDetails( "entity" ); - final String attributeName = fetch.getString( "association" ); + final Class entityClassDetails = fetch.entity(); + final String attributeName = fetch.association(); // throws MappingException in case the property does not exist buildingContext.getMetadataCollector() @@ -49,8 +47,8 @@ public class FetchOverrideSecondPass implements SecondPass { profile.addFetch( new FetchProfile.Fetch( entityClassDetails.getName(), attributeName, - fetch.getEnum( "mode" ), - fetch.getEnum( "fetch" ) + fetch.mode(), + fetch.fetch() ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchSecondPass.java index 6528c1ae56..478a3be6f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchSecondPass.java @@ -15,7 +15,6 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.SecondPass; import org.hibernate.mapping.FetchProfile; import org.hibernate.mapping.PersistentClass; -import org.hibernate.models.spi.AnnotationUsage; import static org.hibernate.internal.util.StringHelper.qualify; import static org.hibernate.mapping.MetadataSource.ANNOTATIONS; @@ -24,13 +23,13 @@ import static org.hibernate.mapping.MetadataSource.ANNOTATIONS; * @author Gavin King */ public class FetchSecondPass implements SecondPass { - private final AnnotationUsage fetch; + private final FetchProfileOverride fetch; private final PropertyHolder propertyHolder; private final String propertyName; private final MetadataBuildingContext buildingContext; public FetchSecondPass( - AnnotationUsage fetch, + FetchProfileOverride fetch, PropertyHolder propertyHolder, String propertyName, MetadataBuildingContext buildingContext) { @@ -42,7 +41,7 @@ public class FetchSecondPass implements SecondPass { @Override public void doSecondPass(Map persistentClasses) throws MappingException { - final String profileName = fetch.getString( "profile" ); + final String profileName = fetch.profile(); final FetchProfile profile = buildingContext.getMetadataCollector().getFetchProfile( profileName ); if ( profile == null ) { throw new AnnotationException( @@ -55,8 +54,8 @@ public class FetchSecondPass implements SecondPass { profile.addFetch( new FetchProfile.Fetch( propertyHolder.getEntityName(), propertyName, - fetch.getEnum( "mode" ), - fetch.getEnum( "fetch" ) + fetch.mode(), + fetch.fetch() ) ); } // otherwise, it's a fetch profile defined in XML, and it overrides diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java index ef2937e6d9..b241d83b7a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java @@ -7,7 +7,6 @@ package org.hibernate.boot.model.internal; import java.util.HashMap; -import java.util.List; import java.util.Locale; import java.util.Map; import java.util.function.Supplier; @@ -20,10 +19,10 @@ import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.type.descriptor.java.JavaType; @@ -45,31 +44,32 @@ public class FilterDefBinder { private static final CoreMessageLogger LOG = messageLogger( FilterDefBinder.class ); public static void bindFilterDefs(AnnotationTarget annotatedElement, MetadataBuildingContext context) { - annotatedElement.forEachAnnotationUsage( FilterDef.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + annotatedElement.forEachAnnotationUsage( FilterDef.class, sourceModelContext, (usage) -> { bindFilterDef( usage, context ); } ); } - public static void bindFilterDef(AnnotationUsage filterDef, MetadataBuildingContext context) { - final String name = filterDef.getString( "name" ); + public static void bindFilterDef(FilterDef filterDef, MetadataBuildingContext context) { + final String name = filterDef.name(); if ( context.getMetadataCollector().getFilterDefinition( name ) != null ) { throw new AnnotationException( "Multiple '@FilterDef' annotations define a filter named '" + name + "'" ); } final Map paramJdbcMappings; final Map>> parameterResolvers; - final List> explicitParameters = filterDef.getList( "parameters" ); - if ( explicitParameters.isEmpty() ) { + final ParamDef[] explicitParameters = filterDef.parameters(); + if ( CollectionHelper.isEmpty( explicitParameters ) ) { paramJdbcMappings = emptyMap(); parameterResolvers = emptyMap(); } else { paramJdbcMappings = new HashMap<>(); parameterResolvers = new HashMap<>(); - for ( AnnotationUsage explicitParameter : explicitParameters ) { - final String parameterName = explicitParameter.getString( "name" ); - final ClassDetails typeClassDetails = explicitParameter.getClassDetails( "type" ); - final JdbcMapping jdbcMapping = resolveFilterParamType( typeClassDetails.toJavaClass(), context ); + for ( ParamDef explicitParameter : explicitParameters ) { + final String parameterName = explicitParameter.name(); + final Class typeClassDetails = explicitParameter.type(); + final JdbcMapping jdbcMapping = resolveFilterParamType( typeClassDetails, context ); if ( jdbcMapping == null ) { throw new MappingException( String.format( @@ -82,17 +82,17 @@ public class FilterDefBinder { } paramJdbcMappings.put( parameterName, jdbcMapping ); - final ClassDetails resolverClassDetails = explicitParameter.getClassDetails( "resolver" ); - if ( !resolverClassDetails.getName().equals( Supplier.class.getName() ) ) { - parameterResolvers.put( explicitParameter.getString( "name" ), resolveParamResolver( resolverClassDetails, context ) ); + final Class resolverClass = explicitParameter.resolver(); + if ( !Supplier.class.equals( resolverClass ) ) { + parameterResolvers.put( explicitParameter.name(), resolveParamResolver( resolverClass, context ) ); } } } final FilterDefinition filterDefinition = new FilterDefinition( name, - filterDef.getString( "defaultCondition" ), - filterDef.getBoolean( "autoEnabled" ), + filterDef.defaultCondition(), + filterDef.autoEnabled(), filterDef.applyToLoadByKey(), paramJdbcMappings, parameterResolvers @@ -103,13 +103,12 @@ public class FilterDefBinder { } @SuppressWarnings({"rawtypes", "unchecked"}) - private static ManagedBean> resolveParamResolver(ClassDetails resolverClassDetails, MetadataBuildingContext context) { - final Class clazz = resolverClassDetails.toJavaClass(); - assert clazz != Supplier.class; + private static ManagedBean> resolveParamResolver(Class resolverClass, MetadataBuildingContext context) { + assert resolverClass != Supplier.class; final BootstrapContext bootstrapContext = context.getBootstrapContext(); return (ManagedBean>) bootstrapContext.getServiceRegistry() .requireService(ManagedBeanRegistry.class) - .getBean(clazz, bootstrapContext.getCustomTypeProducer()); + .getBean(resolverClass, bootstrapContext.getCustomTypeProducer()); } @SuppressWarnings("unchecked") diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java index a1791b3147..94c9176446 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java @@ -32,6 +32,7 @@ import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.generator.AnnotationBasedGenerator; import org.hibernate.generator.Assigned; import org.hibernate.generator.BeforeExecutionGenerator; +import org.hibernate.generator.CustomIdGeneratorCreationContext; import org.hibernate.generator.Generator; import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.OnExecutionGenerator; @@ -49,7 +50,6 @@ import org.hibernate.id.UUIDHexGenerator; import org.hibernate.id.enhanced.LegacyNamingStrategy; import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.SingleNamingStrategy; -import org.hibernate.generator.CustomIdGeneratorCreationContext; import org.hibernate.internal.CoreLogging; import org.hibernate.mapping.Column; import org.hibernate.mapping.GeneratorCreator; @@ -58,16 +58,15 @@ import org.hibernate.mapping.RootClass; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.resource.beans.container.spi.BeanContainer; -import org.hibernate.resource.beans.container.spi.ContainedBean; import org.hibernate.resource.beans.spi.BeanInstanceProducer; - import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.service.ServiceRegistry; import org.hibernate.type.Type; + import org.jboss.logging.Logger; import jakarta.persistence.GeneratedValue; @@ -77,6 +76,7 @@ import jakarta.persistence.TableGenerator; import jakarta.persistence.Version; import static java.util.Collections.emptyMap; +import static org.hibernate.boot.internal.GenerationStrategyInterpreter.STRATEGY_INTERPRETER; import static org.hibernate.boot.model.internal.AnnotationHelper.extractParameterMap; import static org.hibernate.boot.model.internal.BinderHelper.isCompositeId; import static org.hibernate.boot.model.internal.BinderHelper.isGlobalGeneratorNameGlobal; @@ -338,7 +338,7 @@ public class GeneratorBinder { LOG.debugf( "Could not resolve explicit IdentifierGeneratorDefinition - using implicit interpretation (%s)", name ); - final AnnotationUsage generatedValue = idAttributeMember.getAnnotationUsage( GeneratedValue.class ); + final GeneratedValue generatedValue = idAttributeMember.getDirectAnnotationUsage( GeneratedValue.class ); if ( generatedValue == null ) { // this should really never happen, but it's easy to protect against it... return new IdentifierGeneratorDefinition(ASSIGNED_GENERATOR_NAME, ASSIGNED_GENERATOR_NAME); @@ -347,38 +347,38 @@ public class GeneratorBinder { return IdentifierGeneratorDefinition.createImplicit( name, idAttributeMember.getType().determineRawClass().toJavaClass(), - generatedValue.getString( "generator" ), + generatedValue.generator(), interpretGenerationType( generatedValue ) ); } - private static GenerationType interpretGenerationType(AnnotationUsage generatedValueAnn) { + private static GenerationType interpretGenerationType(GeneratedValue generatedValueAnn) { // todo (jpa32) : when can this ever be null? - final GenerationType strategy = generatedValueAnn.getEnum( "strategy" ); + final GenerationType strategy = generatedValueAnn.strategy(); return strategy == null ? GenerationType.AUTO : strategy; } public static Map buildGenerators( AnnotationTarget annotatedElement, MetadataBuildingContext context) { - + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); final InFlightMetadataCollector metadataCollector = context.getMetadataCollector(); final Map generators = new HashMap<>(); - annotatedElement.forEachAnnotationUsage( TableGenerator.class, usage -> { - IdentifierGeneratorDefinition idGenerator = buildTableIdGenerator( usage ); + annotatedElement.forEachAnnotationUsage( TableGenerator.class, sourceModelContext, (usage) -> { + IdentifierGeneratorDefinition idGenerator = buildIdGenerator( usage, context ); generators.put( idGenerator.getName(), idGenerator ); metadataCollector.addIdentifierGenerator( idGenerator ); } ); - annotatedElement.forEachAnnotationUsage( SequenceGenerator.class, usage -> { - IdentifierGeneratorDefinition idGenerator = buildSequenceIdGenerator( usage ); + annotatedElement.forEachAnnotationUsage( SequenceGenerator.class, sourceModelContext, (usage) -> { + IdentifierGeneratorDefinition idGenerator = buildIdGenerator( usage, context ); generators.put( idGenerator.getName(), idGenerator ); metadataCollector.addIdentifierGenerator( idGenerator ); } ); - annotatedElement.forEachAnnotationUsage( GenericGenerator.class, usage -> { - final IdentifierGeneratorDefinition idGenerator = buildIdGenerator( usage ); + annotatedElement.forEachAnnotationUsage( GenericGenerator.class, sourceModelContext, (usage) -> { + final IdentifierGeneratorDefinition idGenerator = buildIdGenerator( usage, context ); generators.put( idGenerator.getName(), idGenerator ); metadataCollector.addIdentifierGenerator( idGenerator ); } ); @@ -390,7 +390,7 @@ public class GeneratorBinder { MetadataBuildingContext context, ClassDetails entityXClass, boolean isComponent, - AnnotationUsage generatedValue) { + GeneratedValue generatedValue) { if ( isComponent ) { //a component must not have any generator return ASSIGNED_GENERATOR_NAME; @@ -401,11 +401,11 @@ public class GeneratorBinder { } static String generatorType( - AnnotationUsage generatedValue, + GeneratedValue generatedValue, final ClassDetails javaClass, MetadataBuildingContext context) { - return GenerationStrategyInterpreter.STRATEGY_INTERPRETER.determineGeneratorName( - generatedValue.getEnum( "strategy" ), + return STRATEGY_INTERPRETER.determineGeneratorName( + generatedValue.strategy(), new GenerationStrategyInterpreter.GeneratorNameDeterminationContext() { Class javaType = null; @Override @@ -417,54 +417,61 @@ public class GeneratorBinder { } @Override public String getGeneratedValueGeneratorName() { - return generatedValue.getString( "generator" ); + return generatedValue.generator(); } } ); } - static IdentifierGeneratorDefinition buildIdGenerator(AnnotationUsage generatorAnnotation) { + static IdentifierGeneratorDefinition buildIdGenerator( + Annotation generatorAnnotation, + MetadataBuildingContext context) { if ( generatorAnnotation == null ) { return null; } final IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder(); - definitionBuilder.setName( generatorAnnotation.getString( "name" ) ); - final Class generatorClass = - generatorAnnotation.getClassDetails( "type" ).toJavaClass(); - final String strategy = generatorClass.equals(Generator.class) - ? generatorAnnotation.getString( "strategy" ) - : generatorClass.getName(); - definitionBuilder.setStrategy( strategy ); - definitionBuilder.addParams( extractParameterMap( generatorAnnotation.getList( "parameters" ) ) ); - if ( LOG.isTraceEnabled() ) { - LOG.tracev( "Add generic generator with name: {0}", definitionBuilder.getName() ); + if ( generatorAnnotation instanceof TableGenerator tableGenerator ) { + STRATEGY_INTERPRETER.interpretTableGenerator( + tableGenerator, + definitionBuilder + ); + if ( LOG.isTraceEnabled() ) { + LOG.tracev( "Add table generator with name: {0}", definitionBuilder.getName() ); + } } + else if ( generatorAnnotation instanceof SequenceGenerator sequenceGenerator ) { + STRATEGY_INTERPRETER.interpretSequenceGenerator( + sequenceGenerator, + definitionBuilder + ); + if ( LOG.isTraceEnabled() ) { + LOG.tracev( "Add sequence generator with name: {0}", definitionBuilder.getName() ); + } + } + else if ( generatorAnnotation instanceof GenericGenerator genericGenerator ) { + definitionBuilder.setName( genericGenerator.name() ); + final Class generatorClass = genericGenerator.type(); + final String strategy = generatorClass.equals( Generator.class ) + ? genericGenerator.strategy() + : generatorClass.getName(); + definitionBuilder.setStrategy( strategy ); + definitionBuilder.addParams( extractParameterMap( genericGenerator.parameters() ) ); + if ( LOG.isTraceEnabled() ) { + LOG.tracev( "Add generic generator with name: {0}", definitionBuilder.getName() ); + } + } + return definitionBuilder.build(); } - static IdentifierGeneratorDefinition buildTableIdGenerator(AnnotationUsage generatorAnnotation) { + static IdentifierGeneratorDefinition buildSequenceIdGenerator(SequenceGenerator generatorAnnotation) { if ( generatorAnnotation == null ) { return null; } final IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder(); - GenerationStrategyInterpreter.STRATEGY_INTERPRETER - .interpretTableGenerator( generatorAnnotation, definitionBuilder ); - if ( LOG.isTraceEnabled() ) { - LOG.tracev( "Add table generator with name: {0}", definitionBuilder.getName() ); - } - return definitionBuilder.build(); - } - - static IdentifierGeneratorDefinition buildSequenceIdGenerator(AnnotationUsage generatorAnnotation) { - if ( generatorAnnotation == null ) { - return null; - } - - final IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder(); - GenerationStrategyInterpreter.STRATEGY_INTERPRETER - .interpretSequenceGenerator( generatorAnnotation, definitionBuilder ); + STRATEGY_INTERPRETER.interpretSequenceGenerator( generatorAnnotation, definitionBuilder ); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Add sequence generator with name: {0}", definitionBuilder.getName() ); } @@ -501,9 +508,9 @@ public class GeneratorBinder { */ static GeneratorCreator generatorCreator( MemberDetails memberDetails, - AnnotationUsage annotation, + Annotation annotation, BeanContainer beanContainer) { - final Class annotationType = annotation.getAnnotationType(); + final Class annotationType = annotation.annotationType(); final ValueGenerationType generatorAnnotation = annotationType.getAnnotation( ValueGenerationType.class ); if ( generatorAnnotation == null ) { return null; @@ -528,10 +535,10 @@ public class GeneratorBinder { static IdentifierGeneratorCreator identifierGeneratorCreator( MemberDetails idAttributeMember, - AnnotationUsage annotation, + Annotation annotation, SimpleValue identifierValue, BeanContainer beanContainer) { - final Class annotationType = annotation.getAnnotationType(); + final Class annotationType = annotation.annotationType(); final IdGeneratorType idGeneratorType = annotationType.getAnnotation( IdGeneratorType.class ); assert idGeneratorType != null; final Class generatorClass = idGeneratorType.value(); @@ -563,7 +570,7 @@ public class GeneratorBinder { * @param generatorClass a class which implements {@code Generator} */ private static Generator instantiateGenerator( - AnnotationUsage annotation, + Annotation annotation, BeanContainer beanContainer, C creationContext, Class creationContextClass, @@ -602,7 +609,7 @@ public class GeneratorBinder { * @param generatorClass a class which implements {@code Generator} */ private static Generator instantiateGeneratorAsBean( - AnnotationUsage annotation, + Annotation annotation, BeanContainer beanContainer, C creationContext, Class creationContextClass, @@ -691,7 +698,7 @@ public class GeneratorBinder { * @param generatorClass a class which implements {@code Generator} */ private static G instantiateGenerator( - AnnotationUsage annotation, + Annotation annotation, MemberDetails memberDetails, Class annotationType, C creationContext, @@ -700,12 +707,12 @@ public class GeneratorBinder { try { try { return generatorClass.getConstructor( annotationType, Member.class, contextClass ) - .newInstance( annotation.toAnnotation(), memberDetails.toJavaMember(), creationContext); + .newInstance( annotation, memberDetails.toJavaMember(), creationContext); } catch (NoSuchMethodException ignore) { try { return generatorClass.getConstructor( annotationType ) - .newInstance( annotation.toAnnotation() ); + .newInstance( annotation ); } catch (NoSuchMethodException i) { return instantiateGeneratorViaDefaultConstructor( generatorClass ); @@ -751,7 +758,7 @@ public class GeneratorBinder { } private static void callInitialize( - AnnotationUsage annotation, + A annotation, MemberDetails memberDetails, GeneratorCreationContext creationContext, Generator generator) { @@ -761,12 +768,12 @@ public class GeneratorBinder { // check this explicitly; If required, this could be done e.g. using ClassMate @SuppressWarnings("unchecked") final AnnotationBasedGenerator generation = (AnnotationBasedGenerator) generator; - generation.initialize( annotation.toAnnotation(), memberDetails.toJavaMember(), creationContext ); + generation.initialize( annotation, memberDetails.toJavaMember(), creationContext ); } } private static void checkVersionGenerationAlways(MemberDetails property, Generator generator) { - if ( property.hasAnnotationUsage(Version.class) ) { + if ( property.hasDirectAnnotationUsage( Version.class ) ) { if ( !generator.generatesOnInsert() ) { throw new AnnotationException("Property '" + property.getName() + "' is annotated '@Version' but has a 'Generator' which does not generate on inserts" @@ -821,9 +828,9 @@ public class GeneratorBinder { MemberDetails idAttributeMember) { //manage composite related metadata //guess if its a component and find id data access (property, field etc) - final AnnotationUsage generatedValue = idAttributeMember.getAnnotationUsage( GeneratedValue.class ); + final GeneratedValue generatedValue = idAttributeMember.getDirectAnnotationUsage( GeneratedValue.class ); final String generatorType = generatorType( context, entityClass, isCompositeId( entityClass, idAttributeMember ), generatedValue ); - final String generatorName = generatedValue == null ? "" : generatedValue.getString( "generator" ); + final String generatorName = generatedValue == null ? "" : generatedValue.generator(); if ( isGlobalGeneratorNameGlobal( context ) ) { buildGenerators( idAttributeMember, context ); context.getMetadataCollector() diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java index 085e52a421..df8c1c20aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java @@ -7,7 +7,6 @@ package org.hibernate.boot.model.internal; import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -22,10 +21,11 @@ import org.hibernate.mapping.IdentifierBag; import org.hibernate.mapping.IdentifierCollection; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.usertype.UserCollectionType; +import jakarta.persistence.Column; + import static org.hibernate.boot.model.internal.GeneratorBinder.makeIdGenerator; /** @@ -51,7 +51,7 @@ public class IdBagBinder extends BagBinder { protected boolean bindStarToManySecondPass(Map persistentClasses) { boolean result = super.bindStarToManySecondPass( persistentClasses ); - final AnnotationUsage collectionIdAnn = property.getAnnotationUsage( CollectionId.class ); + final CollectionId collectionIdAnn = property.getDirectAnnotationUsage( CollectionId.class ); if ( collectionIdAnn == null ) { throw new MappingException( "idbag mapping missing '@CollectionId' annotation" ); } @@ -69,7 +69,7 @@ public class IdBagBinder extends BagBinder { ); final AnnotatedColumns idColumns = AnnotatedColumn.buildColumnsFromAnnotations( - List.of( collectionIdAnn.getNestedUsage( "column" ) ), + new Column[]{collectionIdAnn.column()}, // null, null, Nullability.FORCED_NOT_NULL, @@ -101,7 +101,7 @@ public class IdBagBinder extends BagBinder { final BasicValue id = valueBinder.make(); ( (IdentifierCollection) collection ).setIdentifier( id ); - final String namedGenerator = collectionIdAnn.getString( "generator" ); + final String namedGenerator = collectionIdAnn.generator(); switch (namedGenerator) { case "identity": { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java index 4befbf7e1a..8e58094ee7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java @@ -6,7 +6,8 @@ */ package org.hibernate.boot.model.internal; -import jakarta.persistence.JoinTable; +import java.util.Map; + import org.hibernate.annotations.NotFoundAction; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; @@ -17,9 +18,8 @@ import org.hibernate.mapping.Join; import org.hibernate.mapping.ManyToOne; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; -import java.util.Map; +import jakarta.persistence.JoinTable; import static org.hibernate.boot.model.internal.ToOneBinder.getReferenceEntityName; import static org.hibernate.internal.util.StringHelper.isEmpty; @@ -38,7 +38,7 @@ public class ImplicitToOneJoinTableSecondPass implements SecondPass { private final PropertyData inferredData; private final MetadataBuildingContext context; private final AnnotatedJoinColumns joinColumns; - private final AnnotationUsage joinTable; + private final JoinTable joinTable; private final NotFoundAction notFoundAction; private final ManyToOne value; @@ -47,7 +47,7 @@ public class ImplicitToOneJoinTableSecondPass implements SecondPass { PropertyData inferredData, MetadataBuildingContext context, AnnotatedJoinColumns joinColumns, - AnnotationUsage joinTable, + JoinTable joinTable, NotFoundAction notFoundAction, ManyToOne value) { this.propertyHolder = propertyHolder; @@ -89,24 +89,24 @@ public class ImplicitToOneJoinTableSecondPass implements SecondPass { final TableBinder tableBinder = new TableBinder(); tableBinder.setBuildingContext( context ); - final String schema = joinTable.getString( "schema" ); + final String schema = joinTable.schema(); if ( StringHelper.isNotEmpty( schema ) ) { tableBinder.setSchema( schema ); } - final String catalog = joinTable.getString( "catalog" ); + final String catalog = joinTable.catalog(); if ( StringHelper.isNotEmpty( catalog ) ) { tableBinder.setCatalog( catalog ); } - final String tableName = joinTable.getString( "name" ); + final String tableName = joinTable.name(); if ( StringHelper.isNotEmpty( tableName ) ) { tableBinder.setName( tableName ); } - tableBinder.setUniqueConstraints( joinTable.getList( "uniqueConstraints" ) ); - tableBinder.setJpaIndex( joinTable.getList( "indexes" ) ); - tableBinder.setOptions( joinTable.getString( "options" ) ); + tableBinder.setUniqueConstraints( joinTable.uniqueConstraints() ); + tableBinder.setJpaIndex( joinTable.indexes() ); + tableBinder.setOptions( joinTable.options() ); return tableBinder; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexBinder.java index 168a67e66a..045530a39d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexBinder.java @@ -20,14 +20,12 @@ import org.hibernate.boot.model.naming.PhysicalNamingStrategy; import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.Dialect; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.Column; import org.hibernate.mapping.Formula; import org.hibernate.mapping.Index; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Table; import org.hibernate.mapping.UniqueKey; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.UniqueConstraint; @@ -115,8 +113,8 @@ class IndexBinder { return new Column( physicalName ); } - private Selectable[] selectables(Table table, String name, List columnNames) { - final int size = columnNames.size(); + private Selectable[] selectables(Table table, String name, String[] columnNames) { + final int size = columnNames.length; if ( size == 0 ) { throw new AnnotationException( "Index" + ( isEmpty( name ) ? "" : " '" + name + "'" ) @@ -124,7 +122,7 @@ class IndexBinder { } final Selectable[] columns = new Selectable[size]; for ( int index = 0; index < size; index++ ) { - final String columnName = columnNames.get( index ); + final String columnName = columnNames[index]; if ( isEmpty( columnName ) ) { throw new AnnotationException( "Index" + ( isEmpty( name ) ? "" : " '" + name + "'" ) @@ -135,8 +133,8 @@ class IndexBinder { return columns; } - private Column[] columns(Table table, String name, final List columnNames) { - final int size = columnNames.size(); + private Column[] columns(Table table, String name, final String[] columnNames) { + final int size = columnNames.length; if ( size == 0 ) { throw new AnnotationException( "Unique constraint" + ( isEmpty( name ) ? "" : " '" + name + "'" ) @@ -144,7 +142,7 @@ class IndexBinder { } final Column[] columns = new Column[size]; for ( int index = 0; index < size; index++ ) { - final String columnName = columnNames.get( index ); + final String columnName = columnNames[index]; if ( isEmpty( columnName ) ) { throw new AnnotationException( "Unique constraint" + ( isEmpty( name ) ? "" : " '" + name + "'" ) @@ -159,7 +157,7 @@ class IndexBinder { Table table, String originalKeyName, boolean nameExplicit, - List columnNames, + String[] columnNames, String[] orderings, boolean unique, Selectable[] columns) { @@ -190,9 +188,9 @@ class IndexBinder { } } - void bindIndexes(Table table, List> indexes) { - for ( AnnotationUsage index : indexes ) { - final StringTokenizer tokenizer = new StringTokenizer( index.getString( "columnList" ), "," ); + void bindIndexes(Table table, jakarta.persistence.Index[] indexes) { + for ( jakarta.persistence.Index index : indexes ) { + final StringTokenizer tokenizer = new StringTokenizer( index.columnList(), "," ); final List parsed = new ArrayList<>(); while ( tokenizer.hasMoreElements() ) { final String trimmed = tokenizer.nextToken().trim(); @@ -200,11 +198,11 @@ class IndexBinder { parsed.add( trimmed ) ; } } - final List columnExpressions = CollectionHelper.populatedArrayList( parsed.size(), null ); + final String[] columnExpressions = new String[parsed.size()]; final String[] ordering = new String[parsed.size()]; initializeColumns( columnExpressions, ordering, parsed ); - final String name = index.getString( "name" ); - final boolean unique = index.getBoolean( "unique" ); + final String name = index.name(); + final boolean unique = index.unique(); createIndexOrUniqueKey( table, name, @@ -217,10 +215,10 @@ class IndexBinder { } } - void bindUniqueConstraints(Table table, List> constraints) { - for ( AnnotationUsage constraint : constraints ) { - final String name = constraint.getString( "name" ); - final List columnNames = constraint.getList( "columnNames" ); + void bindUniqueConstraints(Table table, UniqueConstraint[] constraints) { + for ( UniqueConstraint constraint : constraints ) { + final String name = constraint.name(); + final String[] columnNames = constraint.columnNames(); createIndexOrUniqueKey( table, name, @@ -233,20 +231,20 @@ class IndexBinder { } } - private void initializeColumns(List columns, String[] ordering, List list) { + private void initializeColumns(String[] columns, String[] ordering, List list) { for ( int i = 0, size = list.size(); i < size; i++ ) { final String description = list.get( i ); final String tmp = description.toLowerCase(Locale.ROOT); if ( tmp.endsWith( " desc" ) ) { - columns.set( i, description.substring( 0, description.length() - 5 ) ); + columns[i] = description.substring( 0, description.length() - 5 ); ordering[i] = "desc"; } else if ( tmp.endsWith( " asc" ) ) { - columns.set( i, description.substring( 0, description.length() - 4 ) ); + columns[i] = description.substring( 0, description.length() - 4 ); ordering[i] = "asc"; } else { - columns.set( i, description ); + columns[i] = description; ordering[i] = null; } } @@ -255,10 +253,10 @@ class IndexBinder { private class IndexOrUniqueKeyNameSource implements ImplicitIndexNameSource, ImplicitUniqueKeyNameSource { private final MetadataBuildingContext buildingContext; private final Table table; - private final List columnNames; + private final String[] columnNames; private final String originalKeyName; - public IndexOrUniqueKeyNameSource(MetadataBuildingContext buildingContext, Table table, List columnNames, String originalKeyName) { + public IndexOrUniqueKeyNameSource(MetadataBuildingContext buildingContext, Table table, String[] columnNames, String originalKeyName) { this.buildingContext = buildingContext; this.table = table; this.columnNames = columnNames; @@ -292,12 +290,12 @@ class IndexBinder { } } - private List toIdentifiers(List names) { + private List toIdentifiers(String[] names) { if ( names == null ) { return emptyList(); } - final List columnNames = arrayList( names.size() ); + final List columnNames = arrayList( names.length ); for ( String name : names ) { columnNames.add( getDatabase().toIdentifier( name ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java index a6f312a250..db08735cca 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java @@ -12,7 +12,6 @@ import org.hibernate.annotations.ListIndexBase; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.mapping.Join; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.OrderColumn; @@ -33,9 +32,9 @@ public class IndexColumn extends AnnotatedColumn { } public static IndexColumn fromAnnotations( - AnnotationUsage orderColumn, - AnnotationUsage indexColumn, - AnnotationUsage listIndexBase, + OrderColumn orderColumn, + org.hibernate.annotations.IndexColumn indexColumn, + ListIndexBase listIndexBase, PropertyHolder propertyHolder, PropertyData inferredData, Map secondaryTables, @@ -46,7 +45,7 @@ public class IndexColumn extends AnnotatedColumn { } else if ( indexColumn != null ) { column = buildColumnFromIndexColumn( indexColumn, propertyHolder, inferredData, context ); - column.setBase( indexColumn.getInteger( "base" ) ); + column.setBase( indexColumn.base() ); } else { column = new IndexColumn(); @@ -59,7 +58,7 @@ public class IndexColumn extends AnnotatedColumn { } if ( listIndexBase != null ) { - column.setBase( listIndexBase.getInteger( "value" ) ); + column.setBase( listIndexBase.value() ); } return column; @@ -96,25 +95,25 @@ public class IndexColumn extends AnnotatedColumn { * @return The index column */ public static IndexColumn buildColumnFromOrderColumn( - AnnotationUsage orderColumn, + OrderColumn orderColumn, PropertyHolder propertyHolder, PropertyData inferredData, Map secondaryTables, MetadataBuildingContext context) { if ( orderColumn != null ) { - final String sqlType = nullIfEmpty( orderColumn.getString( "columnDefinition" ) ); - final String explicitName = orderColumn.getString( "name" ); + final String sqlType = nullIfEmpty( orderColumn.columnDefinition() ); + final String explicitName = orderColumn.name(); final String name = explicitName.isEmpty() ? inferredData.getPropertyName() + "_ORDER" : explicitName; final IndexColumn column = new IndexColumn(); column.setLogicalColumnName( name ); column.setSqlType( sqlType ); - column.setNullable( orderColumn.getBoolean( "nullable" ) ); + column.setNullable( orderColumn.nullable() ); // column.setJoins( secondaryTables ); - column.setInsertable( orderColumn.getBoolean( "insertable" ) ); - column.setUpdatable( orderColumn.getBoolean( "updatable" ) ); - column.setOptions( orderColumn.getString( "options" ) ); + column.setInsertable( orderColumn.insertable() ); + column.setUpdatable( orderColumn.updatable() ); + column.setOptions( orderColumn.options() ); // column.setContext( context ); // column.setPropertyHolder( propertyHolder ); createParent( propertyHolder, secondaryTables, column, context ); @@ -142,22 +141,22 @@ public class IndexColumn extends AnnotatedColumn { * @return The index column */ public static IndexColumn buildColumnFromIndexColumn( - AnnotationUsage indexColumn, + org.hibernate.annotations.IndexColumn indexColumn, PropertyHolder propertyHolder, PropertyData inferredData, MetadataBuildingContext context) { if ( indexColumn != null ) { - final String explicitName = indexColumn.getString( "name" ); + final String explicitName = indexColumn.name(); final String name = explicitName.isEmpty() ? inferredData.getPropertyName() : explicitName; - final String sqlType = nullIfEmpty( indexColumn.getString( "columnDefinition" ) ); + final String sqlType = nullIfEmpty( indexColumn.columnDefinition() ); //TODO move it to a getter based system and remove the constructor final IndexColumn column = new IndexColumn(); column.setLogicalColumnName( name ); column.setSqlType( sqlType ); - column.setNullable( indexColumn.getBoolean( "nullable" ) ); - column.setBase( indexColumn.getInteger( "base" ) ); + column.setNullable( indexColumn.nullable() ); + column.setBase( indexColumn.base() ); // column.setContext( context ); // column.setPropertyHolder( propertyHolder ); createParent( propertyHolder, null, column, context ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java index bbc758554a..4048feec29 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java @@ -72,14 +72,14 @@ public class InheritanceState { } private void extractInheritanceType(ClassDetails classDetails) { - final AnnotationUsage inheritanceAnn = classDetails.getAnnotationUsage( Inheritance.class ); - final AnnotationUsage mappedSuperAnn = classDetails.getAnnotationUsage( MappedSuperclass.class ); + final Inheritance inheritanceAnn = classDetails.getDirectAnnotationUsage( Inheritance.class ); + final MappedSuperclass mappedSuperAnn = classDetails.getDirectAnnotationUsage( MappedSuperclass.class ); if ( mappedSuperAnn != null ) { setEmbeddableSuperclass( true ); - setType( inheritanceAnn == null ? null : inheritanceAnn.getEnum( "strategy", InheritanceType.class ) ); + setType( inheritanceAnn == null ? null : inheritanceAnn.strategy() ); } else { - setType( inheritanceAnn == null ? SINGLE_TABLE : inheritanceAnn.getEnum( "strategy", InheritanceType.class ) ); + setType( inheritanceAnn == null ? SINGLE_TABLE : inheritanceAnn.strategy() ); } } @@ -182,7 +182,7 @@ public class InheritanceState { if ( !evenIfSubclass && hasParents() ) { return null; } - else if ( classDetails.hasAnnotationUsage( IdClass.class ) ) { + else if ( classDetails.hasDirectAnnotationUsage( IdClass.class ) ) { return classDetails; } else { @@ -205,7 +205,7 @@ public class InheritanceState { else { final ElementsToProcess process = getElementsToProcess(); for ( PropertyData property : process.getElements() ) { - if ( property.getAttributeMember().hasAnnotationUsage( EmbeddedId.class ) ) { + if ( property.getAttributeMember().hasDirectAnnotationUsage( EmbeddedId.class ) ) { hasIdClassOrEmbeddedId = true; break; } @@ -259,9 +259,9 @@ public class InheritanceState { private AccessType determineDefaultAccessType() { for ( ClassDetails candidate = classDetails; candidate != null; candidate = candidate.getSuperClass() ) { if ( ( candidate.getSuperClass() == null || Object.class.getName().equals( candidate.getSuperClass().getName() ) ) - && ( candidate.hasAnnotationUsage( Entity.class ) || candidate.hasAnnotationUsage( MappedSuperclass.class ) ) - && candidate.hasAnnotationUsage( Access.class ) ) { - return AccessType.getAccessStrategy( candidate.getAnnotationUsage( Access.class ).getEnum( "value" ) ); + && ( candidate.hasDirectAnnotationUsage( Entity.class ) || candidate.hasDirectAnnotationUsage( MappedSuperclass.class ) ) + && candidate.hasDirectAnnotationUsage( Access.class ) ) { + return AccessType.getAccessStrategy( candidate.getDirectAnnotationUsage( Access.class ).value() ); } } // Guess from identifier. @@ -270,19 +270,19 @@ public class InheritanceState { for ( ClassDetails candidate = classDetails; candidate != null && !Object.class.getName().equals( candidate.getName() ); candidate = candidate.getSuperClass() ) { - if ( candidate.hasAnnotationUsage( Entity.class ) || candidate.hasAnnotationUsage( MappedSuperclass.class ) ) { + if ( candidate.hasDirectAnnotationUsage( Entity.class ) || candidate.hasDirectAnnotationUsage( MappedSuperclass.class ) ) { for ( MethodDetails method : candidate.getMethods() ) { if ( method.getMethodKind() != MethodDetails.MethodKind.GETTER ) { continue; } - if ( method.hasAnnotationUsage( Id.class ) || method.hasAnnotationUsage( EmbeddedId.class ) ) { + if ( method.hasDirectAnnotationUsage( Id.class ) || method.hasDirectAnnotationUsage( EmbeddedId.class ) ) { return AccessType.PROPERTY; } } for ( FieldDetails field : candidate.getFields() ) { - if ( field.hasAnnotationUsage( Id.class ) || field.hasAnnotationUsage( EmbeddedId.class ) ) { + if ( field.hasDirectAnnotationUsage( Id.class ) || field.hasDirectAnnotationUsage( EmbeddedId.class ) ) { return AccessType.FIELD; } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java index b2b4640bfc..4e63684575 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java @@ -20,7 +20,6 @@ import org.hibernate.mapping.List; import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.SimpleValue; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.usertype.UserCollectionType; @@ -50,7 +49,7 @@ public class ListBinder extends CollectionBinder { } @Override - public void setSqlOrderBy(AnnotationUsage orderByAnn) { + public void setSqlOrderBy(OrderBy orderByAnn) { if ( orderByAnn != null ) { throw new AnnotationException( "A collection of type 'List' is annotated '@OrderBy'" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java index 1be3707566..920a1d4687 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapBinder.java @@ -34,7 +34,6 @@ import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Table; import org.hibernate.mapping.Value; import org.hibernate.models.internal.ClassTypeDetailsImpl; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.TypeDetails; @@ -112,7 +111,7 @@ public class MapBinder extends CollectionBinder { private void makeOneToManyMapKeyColumnNullableIfNotInProperty(MemberDetails property) { final Map map = (Map) this.collection; - if ( map.isOneToMany() && property.hasAnnotationUsage( MapKeyColumn.class ) ) { + if ( map.isOneToMany() && property.hasDirectAnnotationUsage( MapKeyColumn.class ) ) { final Value indexValue = map.getIndex(); if ( indexValue.getColumnSpan() != 1 ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" ); @@ -234,9 +233,9 @@ public class MapBinder extends CollectionBinder { private static String getKeyType(MemberDetails property) { //target has priority over reflection for the map key type //JPA 2 has priority - final AnnotationUsage mapKeyClassAnn = property.getAnnotationUsage( MapKeyClass.class ); + final MapKeyClass mapKeyClassAnn = property.getDirectAnnotationUsage( MapKeyClass.class ); final Class target = mapKeyClassAnn != null - ? mapKeyClassAnn.getClassDetails( "value" ).toJavaClass() + ? mapKeyClassAnn.value() : void.class; return void.class.equals( target ) ? property.getMapKeyType().getName() : target.getName(); } @@ -290,16 +289,16 @@ public class MapBinder extends CollectionBinder { } private void handleForeignKey(MemberDetails property, ManyToOne element) { - final AnnotationUsage foreignKey = getMapKeyForeignKey( property ); + final ForeignKey foreignKey = getMapKeyForeignKey( property ); if ( foreignKey != null ) { - final ConstraintMode constraintMode = foreignKey.getEnum( "value" ); + final ConstraintMode constraintMode = foreignKey.value(); if ( constraintMode == ConstraintMode.NO_CONSTRAINT || constraintMode == ConstraintMode.PROVIDER_DEFAULT && getBuildingContext().getBuildingOptions().isNoConstraintByDefault() ) { element.disableForeignKey(); } else { - element.setForeignKeyName( nullIfEmpty( foreignKey.getString( "name" ) ) ); - element.setForeignKeyDefinition( nullIfEmpty( foreignKey.getString( "foreignKeyDefinition" ) ) ); + element.setForeignKeyName( nullIfEmpty( foreignKey.name() ) ); + element.setForeignKeyDefinition( nullIfEmpty( foreignKey.foreignKeyDefinition() ) ); } } } @@ -378,7 +377,7 @@ public class MapBinder extends CollectionBinder { accessType, //TODO be smart with isNullable true, - new EntityBinder(), + new EntityBinder( buildingContext ), false, false, true, @@ -401,10 +400,9 @@ public class MapBinder extends CollectionBinder { MemberDetails property, TypeDetails returnedClass, MetadataBuildingContext context) { - final AnnotationUsage compositeType = property.getAnnotationUsage( MapKeyCompositeType.class ); + final MapKeyCompositeType compositeType = property.getDirectAnnotationUsage( MapKeyCompositeType.class ); if ( compositeType != null ) { - final ClassDetails compositeTypeImplDetails = compositeType.getClassDetails( "value" ); - return compositeTypeImplDetails.toJavaClass(); + return compositeType.value(); } if ( returnedClass != null ) { @@ -414,28 +412,30 @@ public class MapBinder extends CollectionBinder { return null; } - private AnnotationUsage getMapKeyForeignKey(MemberDetails property) { - final AnnotationUsage mapKeyJoinColumns = property.getAnnotationUsage( MapKeyJoinColumns.class ); - final AnnotationUsage mapKeyJoinColumn = property.getSingleAnnotationUsage( MapKeyJoinColumn.class ); + private jakarta.persistence.ForeignKey getMapKeyForeignKey(MemberDetails property) { + final MapKeyJoinColumns mapKeyJoinColumns = property.getDirectAnnotationUsage( MapKeyJoinColumns.class ); if ( mapKeyJoinColumns != null ) { - return mapKeyJoinColumns.getNestedUsage( "foreignKey" ); + return mapKeyJoinColumns.foreignKey(); } - else if ( mapKeyJoinColumn != null ) { - return mapKeyJoinColumn.getNestedUsage( "foreignKey" ); - } - else { - return null; + + final MapKeyJoinColumn mapKeyJoinColumn = property.getDirectAnnotationUsage( MapKeyJoinColumn.class ); + if ( mapKeyJoinColumn != null ) { + return mapKeyJoinColumn.foreignKey(); } + + return null; } private boolean mappingDefinedAttributeOverrideOnMapKey(MemberDetails property) { - if ( property.hasAnnotationUsage( AttributeOverride.class ) ) { - return namedMapKey( property.getAnnotationUsage( AttributeOverride.class ) ); + final AttributeOverride overrideAnn = property.getDirectAnnotationUsage( AttributeOverride.class ); + if ( overrideAnn != null ) { + return namedMapKey( overrideAnn ); } - if ( property.hasAnnotationUsage( AttributeOverrides.class ) ) { - final AnnotationUsage annotations = property.getAnnotationUsage( AttributeOverrides.class ); - for ( AnnotationUsage attributeOverride : annotations.>getList( "value" ) ) { - if ( namedMapKey( attributeOverride ) ) { + + final AttributeOverrides overridesAnn = property.getDirectAnnotationUsage( AttributeOverrides.class ); + if ( overridesAnn != null ) { + for ( AttributeOverride nestedAnn : overridesAnn.value() ) { + if ( namedMapKey( nestedAnn ) ) { return true; } } @@ -443,8 +443,8 @@ public class MapBinder extends CollectionBinder { return false; } - private boolean namedMapKey(AnnotationUsage annotation) { - return annotation.getString( "name" ).startsWith( "key." ); + private boolean namedMapKey(AttributeOverride annotation) { + return annotation.name().startsWith( "key." ); } private Value createFormulatedValue( diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapKeyJoinColumnDelegator.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapKeyJoinColumnDelegator.java deleted file mode 100644 index fc8e050694..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/MapKeyJoinColumnDelegator.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.model.internal; - -import java.lang.annotation.Annotation; - -import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.MemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; - -import jakarta.persistence.CheckConstraint; -import jakarta.persistence.Column; -import jakarta.persistence.ForeignKey; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.MapKeyJoinColumn; - -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified; - - -/** - * @author Emmanuel Bernard - */ -@SuppressWarnings({ "ClassExplicitlyAnnotation" }) -public class MapKeyJoinColumnDelegator implements JoinColumn { - private final MapKeyJoinColumn column; - - public MapKeyJoinColumnDelegator(AnnotationUsage column) { - this( column.toAnnotation() ); - } - - public MapKeyJoinColumnDelegator(MapKeyJoinColumn column) { - this.column = column; - } - - public static MutableAnnotationUsage fromMapKeyJoinColumn( - AnnotationUsage mapKeyJoinColumn, - MemberDetails attributeMember, - MetadataBuildingContext context) { - final MutableAnnotationUsage joinColumn = JpaAnnotations.JOIN_COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); - - applyStringAttributeIfSpecified( - "name", - mapKeyJoinColumn.getAttributeValue( "name" ), - joinColumn - ); - applyStringAttributeIfSpecified( - "table", - mapKeyJoinColumn.getAttributeValue( "table" ), - joinColumn - ); - applyAttributeIfSpecified( - "unique", - mapKeyJoinColumn.getAttributeValue( "unique" ), - joinColumn - ); - applyAttributeIfSpecified( - "nullable", - mapKeyJoinColumn.getAttributeValue( "nullable" ), - joinColumn - ); - applyAttributeIfSpecified( - "insertable", - mapKeyJoinColumn.getAttributeValue( "insertable" ), - joinColumn - ); - applyStringAttributeIfSpecified( - "referencedColumnName", - mapKeyJoinColumn.getAttributeValue( "referencedColumnName" ), - joinColumn - ); - applyStringAttributeIfSpecified( - "columnDefinition", - mapKeyJoinColumn.getAttributeValue( "columnDefinition" ), - joinColumn - ); - applyStringAttributeIfSpecified( - "options", - mapKeyJoinColumn.getAttributeValue( "options" ), - joinColumn - ); -// joinColumn.setAttributeValue( "comment", mapKeyJoinColumn.getAttributeValue( "comment" ) ); - applyAttributeIfSpecified( - "foreignKey", - mapKeyJoinColumn.getAttributeValue( "foreignKey" ), - joinColumn - ); - - return joinColumn; - } - - @Override - public String name() { - return column.name(); - } - - @Override - public String referencedColumnName() { - return column.referencedColumnName(); - } - - @Override - public boolean unique() { - return column.unique(); - } - - @Override - public boolean nullable() { - return column.nullable(); - } - - @Override - public boolean insertable() { - return column.insertable(); - } - - @Override - public boolean updatable() { - return column.updatable(); - } - - @Override - public String columnDefinition() { - return column.columnDefinition(); - } - - @Override - public String options() { - return column.options(); - } - - @Override - public String table() { - return column.table(); - } - - @Override - public ForeignKey foreignKey() { - return column.foreignKey(); - } - - @Override - public CheckConstraint[] check() { - return new CheckConstraint[0]; - } - - @Override - public String comment() { - return ""; - } - - @Override - public Class annotationType() { - return Column.class; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/OneToOneSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/OneToOneSecondPass.java index a8d8d3ff3c..ab51c31cf0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/OneToOneSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/OneToOneSecondPass.java @@ -26,8 +26,6 @@ import org.hibernate.mapping.OneToOne; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.SortableValue; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.type.ForeignKeyDirection; @@ -105,7 +103,7 @@ public class OneToOneSecondPass implements SecondPass { value.setConstrained( !optional ); value.setForeignKeyType( getForeignKeyDirection() ); - bindForeignKeyNameAndDefinition( value, property, property.getAnnotationUsage( ForeignKey.class ), buildingContext ); + bindForeignKeyNameAndDefinition( value, property, property.getDirectAnnotationUsage( ForeignKey.class ), buildingContext ); final PropertyBinder binder = new PropertyBinder(); binder.setName( propertyName ); @@ -116,9 +114,9 @@ public class OneToOneSecondPass implements SecondPass { binder.setBuildingContext( buildingContext ); binder.setHolder( propertyHolder ); - final AnnotationUsage lazyGroupAnnotation = property.getAnnotationUsage( LazyGroup.class ); + final LazyGroup lazyGroupAnnotation = property.getDirectAnnotationUsage( LazyGroup.class ); if ( lazyGroupAnnotation != null ) { - binder.setLazyGroup( lazyGroupAnnotation.getString( "value" ) ); + binder.setLazyGroup( lazyGroupAnnotation.value() ); } final Property result = binder.makeProperty(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index 5cec074047..c12422125b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -9,6 +9,7 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; import java.util.EnumSet; import java.util.List; +import java.util.Locale; import java.util.Map; import org.hibernate.AnnotationException; @@ -32,6 +33,7 @@ import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.ImplicitNamingStrategy; import org.hibernate.boot.model.naming.ImplicitUniqueKeyNameSource; import org.hibernate.boot.model.relational.Database; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.spi.AccessType; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; @@ -42,6 +44,7 @@ import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Component; import org.hibernate.mapping.GeneratorCreator; @@ -55,18 +58,15 @@ import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.ToOne; import org.hibernate.mapping.Value; import org.hibernate.metamodel.spi.EmbeddableInstantiator; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptorRegistry; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.models.spi.TypeVariableScope; - -import org.hibernate.resource.beans.container.spi.BeanContainer; -import org.hibernate.resource.beans.spi.ManagedBeanRegistry; -import org.hibernate.service.ServiceRegistry; import org.hibernate.usertype.CompositeUserType; -import org.hibernate.resource.beans.container.spi.BeanContainer; import org.jboss.logging.Logger; import jakarta.persistence.Basic; @@ -107,7 +107,6 @@ import static org.hibernate.boot.model.internal.ToOneBinder.bindOneToOne; import static org.hibernate.boot.model.naming.Identifier.toIdentifier; import static org.hibernate.id.IdentifierGeneratorHelper.getForeignId; import static org.hibernate.internal.util.StringHelper.qualify; -import static org.hibernate.internal.util.collections.CollectionHelper.combine; /** * A stateful binder responsible for creating {@link Property} objects. @@ -139,6 +138,10 @@ public class PropertyBinder { private boolean toMany; private String referencedEntityName; + protected SourceModelBuildingContext getSourceModelContext() { + return buildingContext.getMetadataCollector().getSourceModelBuildingContext(); + } + public void setReferencedEntityName(String referencedEntityName) { this.referencedEntityName = referencedEntityName; } @@ -286,17 +289,29 @@ public class PropertyBinder { @SuppressWarnings({"rawtypes", "unchecked"}) private void callAttributeBinders(Property property, Map persistentClasses) { - for ( AnnotationUsage binderAnnotationUsage : memberDetails.getMetaAnnotated( AttributeBinderType.class ) ) { - final AttributeBinderType binderType = binderAnnotationUsage.getAnnotationType().getAnnotation( AttributeBinderType.class ); + final List metaAnnotatedTargets = memberDetails.getMetaAnnotated( + AttributeBinderType.class, + getSourceModelContext() + ); + + if ( CollectionHelper.isEmpty( metaAnnotatedTargets ) ) { + return; + } + + final AnnotationDescriptorRegistry descriptorRegistry = getSourceModelContext().getAnnotationDescriptorRegistry(); + for ( int i = 0; i < metaAnnotatedTargets.size(); i++ ) { + final Annotation metaAnnotatedTarget = metaAnnotatedTargets.get( i ); + final AnnotationDescriptor metaAnnotatedDescriptor = descriptorRegistry.getDescriptor( metaAnnotatedTarget.annotationType() ); + final AttributeBinderType binderTypeAnn = metaAnnotatedDescriptor.getDirectAnnotationUsage( AttributeBinderType.class ); try { - final AttributeBinder binder = binderType.binder().getConstructor().newInstance(); + final AttributeBinder binder = binderTypeAnn.binder().getConstructor().newInstance(); final PersistentClass persistentClass = entityBinder != null ? entityBinder.getPersistentClass() : persistentClasses.get( holder.getEntityName() ); - binder.bind( binderAnnotationUsage.toAnnotation(), buildingContext, persistentClass, property ); + binder.bind( metaAnnotatedTarget, buildingContext, persistentClass, property ); } catch ( Exception e ) { - throw new AnnotationException( "error processing @AttributeBinderType annotation '" + binderAnnotationUsage.getAnnotationType() + "'", e ); + throw new AnnotationException( "error processing @AttributeBinderType annotation '" + metaAnnotatedDescriptor.getAnnotationType().getName() + "'", e ); } } } @@ -394,20 +409,20 @@ public class PropertyBinder { } } - private Class resolveCustomInstantiator(MemberDetails property, ClassDetails embeddableClass) { - if ( property.hasAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ) ) { - final AnnotationUsage annotationUsage = property.getAnnotationUsage( - org.hibernate.annotations.EmbeddableInstantiator.class ); - return annotationUsage.getClassDetails( "value" ).toJavaClass(); + private Class resolveCustomInstantiator( + MemberDetails property, + ClassDetails embeddableClass) { + final org.hibernate.annotations.EmbeddableInstantiator onEmbedded = property.getDirectAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); + if ( onEmbedded != null ) { + return onEmbedded.value(); } - else if ( embeddableClass.hasAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ) ) { - final AnnotationUsage annotationUsage = embeddableClass.getAnnotationUsage( - org.hibernate.annotations.EmbeddableInstantiator.class ); - return annotationUsage.getClassDetails( "value" ).toJavaClass(); - } - else { - return null; + + final org.hibernate.annotations.EmbeddableInstantiator onEmbeddable = embeddableClass.getDirectAnnotationUsage( org.hibernate.annotations.EmbeddableInstantiator.class ); + if ( onEmbeddable != null ) { + return onEmbeddable.value(); } + + return null; } //used when the value is provided and the binding is done elsewhere @@ -443,10 +458,13 @@ public class PropertyBinder { * Returns the value generation strategy for the given property, if any. */ private GeneratorCreator getValueGenerationFromAnnotations(MemberDetails property) { - final BeanContainer beanContainer = beanContainer( buildingContext ); GeneratorCreator creator = null; - for ( AnnotationUsage usage : property.getAllAnnotationUsages() ) { - final GeneratorCreator candidate = generatorCreator( property, usage, beanContainer ); + final List metaAnnotatedTargets = property.getMetaAnnotated( + ValueGenerationType.class, + getSourceModelContext() + ); + for ( Annotation metaAnnotatedTarget : metaAnnotatedTargets ) { + final GeneratorCreator candidate = generatorCreator( property, metaAnnotatedTarget, beanContainer( buildingContext ) ); if ( candidate != null ) { if ( creator != null ) { throw new AnnotationException( "Property '" + qualify( holder.getPath(), name ) @@ -463,12 +481,12 @@ public class PropertyBinder { private void handleLob(Property property) { if ( this.memberDetails != null ) { // HHH-4635 -- needed for dialect-specific property ordering - property.setLob( this.memberDetails.hasAnnotationUsage( Lob.class ) ); + property.setLob( this.memberDetails.hasDirectAnnotationUsage( Lob.class ) ); } } private void handleMutability(Property property) { - if ( this.memberDetails != null && this.memberDetails.hasAnnotationUsage( Immutable.class ) ) { + if ( this.memberDetails != null && this.memberDetails.hasDirectAnnotationUsage( Immutable.class ) ) { updatable = false; } property.setInsertable( insertable ); @@ -507,14 +525,14 @@ public class PropertyBinder { private void handleNaturalId(Property property) { if ( this.memberDetails != null && entityBinder != null ) { - final AnnotationUsage naturalId = this.memberDetails.getAnnotationUsage( NaturalId.class ); + final NaturalId naturalId = this.memberDetails.getDirectAnnotationUsage( NaturalId.class ); if ( naturalId != null ) { if ( !entityBinder.isRootEntity() ) { throw new AnnotationException( "Property '" + qualify( holder.getPath(), name ) + "' belongs to an entity subclass and may not be annotated '@NaturalId'" + " (only a property of a root '@Entity' or a '@MappedSuperclass' may be a '@NaturalId')" ); } - if ( !naturalId.getBoolean( "mutable" ) ) { + if ( !naturalId.mutable() ) { updatable = false; } property.setNaturalIdentifier( true ); @@ -527,9 +545,9 @@ public class PropertyBinder { if ( value instanceof Collection ) { property.setOptimisticLocked( ((Collection) value).isOptimisticLocked() ); } - else if ( this.memberDetails != null && this.memberDetails.hasAnnotationUsage( OptimisticLock.class ) ) { - final AnnotationUsage optimisticLock = this.memberDetails.getAnnotationUsage( OptimisticLock.class ); - final boolean excluded = optimisticLock.getBoolean( "excluded" ); + else if ( this.memberDetails != null && this.memberDetails.hasDirectAnnotationUsage( OptimisticLock.class ) ) { + final OptimisticLock optimisticLock = this.memberDetails.getDirectAnnotationUsage( OptimisticLock.class ); + final boolean excluded = optimisticLock.excluded(); validateOptimisticLock( excluded ); property.setOptimisticLocked( !excluded ); } @@ -540,15 +558,15 @@ public class PropertyBinder { private void validateOptimisticLock(boolean excluded) { if ( excluded ) { - if ( memberDetails.hasAnnotationUsage( Version.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( Version.class ) ) { throw new AnnotationException("Property '" + qualify( holder.getPath(), name ) + "' is annotated '@OptimisticLock(excluded=true)' and '@Version'" ); } - if ( memberDetails.hasAnnotationUsage( Id.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( Id.class ) ) { throw new AnnotationException("Property '" + qualify( holder.getPath(), name ) + "' is annotated '@OptimisticLock(excluded=true)' and '@Id'" ); } - if ( memberDetails.hasAnnotationUsage( EmbeddedId.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( EmbeddedId.class ) ) { throw new AnnotationException( "Property '" + qualify( holder.getPath(), name ) + "' is annotated '@OptimisticLock(excluded=true)' and '@EmbeddedId'" ); } @@ -613,7 +631,7 @@ public class PropertyBinder { else { inFlightPropertyDataList.add( propertyAnnotatedElement ); } - if ( element.hasAnnotationUsage( MapsId.class ) ) { + if ( element.hasDirectAnnotationUsage( MapsId.class ) ) { context.getMetadataCollector().addPropertyAnnotatedWithMapsId( ownerType.determineRawClass(), propertyAnnotatedElement ); } @@ -621,8 +639,8 @@ public class PropertyBinder { } private static void checkIdProperty(MemberDetails property, PropertyData propertyData) { - final AnnotationUsage incomingIdProperty = property.getAnnotationUsage( Id.class ); - final AnnotationUsage existingIdProperty = propertyData.getAttributeMember().getAnnotationUsage( Id.class ); + final Id incomingIdProperty = property.getDirectAnnotationUsage( Id.class ); + final Id existingIdProperty = propertyData.getAttributeMember().getDirectAnnotationUsage( Id.class ); if ( incomingIdProperty != null && existingIdProperty == null ) { throw new MappingException( String.format( @@ -645,11 +663,12 @@ public class PropertyBinder { //TODO support true/false/default on the property instead of present / not present //TODO is @Column mandatory? //TODO add method support + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); if ( context.getBuildingOptions().isSpecjProprietarySyntaxEnabled() ) { - if ( element.hasAnnotationUsage( Id.class ) && element.hasAnnotationUsage( Column.class ) ) { - final String columnName = element.getAnnotationUsage( Column.class ).getString( "name" ); + if ( element.hasDirectAnnotationUsage( Id.class ) && element.hasDirectAnnotationUsage( Column.class ) ) { + final String columnName = element.getDirectAnnotationUsage( Column.class ).name(); declaringClass.forEachField( (index, fieldDetails) -> { - if ( !element.hasAnnotationUsage( MapsId.class ) && isJoinColumnPresent( columnName, element ) ) { + if ( !element.hasDirectAnnotationUsage( MapsId.class ) && isJoinColumnPresent( columnName, element, sourceModelContext ) ) { //create a PropertyData for the specJ property holding the mapping context.getMetadataCollector().addPropertyAnnotatedWithMapsIdSpecj( ownerType.determineRawClass(), @@ -671,12 +690,15 @@ public class PropertyBinder { } } - private static boolean isJoinColumnPresent(String columnName, MemberDetails property) { + private static boolean isJoinColumnPresent(String columnName, MemberDetails property, SourceModelBuildingContext modelContext) { //The detection of a configured individual JoinColumn differs between Annotation //and XML configuration processing. - final List> joinColumnAnnotations = property.getRepeatedAnnotationUsages( JoinColumn.class ); - for ( AnnotationUsage joinColumnAnnotation : joinColumnAnnotations ) { - if ( joinColumnAnnotation.getString( "name" ).equals( columnName ) ) { + final JoinColumn[] joinColumnAnnotations = property.getRepeatedAnnotationUsages( + JpaAnnotations.JOIN_COLUMN, + modelContext + ); + for ( JoinColumn joinColumnAnnotation : joinColumnAnnotations ) { + if ( joinColumnAnnotation.name().equals( columnName ) ) { return true; } } @@ -684,8 +706,8 @@ public class PropertyBinder { } static boolean hasIdAnnotation(MemberDetails element) { - return element.hasAnnotationUsage( Id.class ) - || element.hasAnnotationUsage( EmbeddedId.class ); + return element.hasDirectAnnotationUsage( Id.class ) + || element.hasDirectAnnotationUsage( EmbeddedId.class ); } /** @@ -724,7 +746,7 @@ public class PropertyBinder { } final MemberDetails property = inferredData.getAttributeMember(); - if ( property.hasAnnotationUsage( Parent.class ) ) { + if ( property.hasDirectAnnotationUsage( Parent.class ) ) { handleParentProperty( propertyHolder, inferredData, property ); } else { @@ -803,9 +825,9 @@ public class PropertyBinder { propertyBinder.setInheritanceStatePerClass( inheritanceStatePerClass ); propertyBinder.setId( !entityBinder.isIgnoreIdAnnotations() && hasIdAnnotation( property ) ); - final AnnotationUsage lazyGroupAnnotation = property.getAnnotationUsage( LazyGroup.class ); + final LazyGroup lazyGroupAnnotation = property.getDirectAnnotationUsage( LazyGroup.class ); if ( lazyGroupAnnotation != null ) { - propertyBinder.setLazyGroup( lazyGroupAnnotation.getString( "value" ) ); + propertyBinder.setLazyGroup( lazyGroupAnnotation.value() ); } final AnnotatedJoinColumns joinColumns = columnsBuilder.getJoinColumns(); @@ -929,27 +951,32 @@ public class PropertyBinder { } private static boolean isVersion(MemberDetails property) { - return property.hasAnnotationUsage( Version.class ); + return property.hasDirectAnnotationUsage( Version.class ); } private static boolean isOneToOne(MemberDetails property) { - return property.hasAnnotationUsage( OneToOne.class ); + return property.hasDirectAnnotationUsage( OneToOne.class ); } private static boolean isManyToOne(MemberDetails property) { - return property.hasAnnotationUsage( ManyToOne.class ); + return property.hasDirectAnnotationUsage( ManyToOne.class ); } private static boolean isAny(MemberDetails property) { - return property.hasAnnotationUsage( Any.class ); + return property.hasDirectAnnotationUsage( Any.class ); } private static boolean isCollection(MemberDetails property) { - return property.hasAnnotationUsage( OneToMany.class ) - || property.hasAnnotationUsage( ManyToMany.class ) - || property.hasAnnotationUsage( ElementCollection.class ) - || property.hasAnnotationUsage( ManyToAny.class ); -} + return property.hasDirectAnnotationUsage( OneToMany.class ) + || property.hasDirectAnnotationUsage( ManyToMany.class ) + || property.hasDirectAnnotationUsage( ElementCollection.class ) + || property.hasDirectAnnotationUsage( ManyToAny.class ); + } + + private static boolean isForcePersist(MemberDetails property) { + return property.hasDirectAnnotationUsage( MapsId.class ) + || property.hasDirectAnnotationUsage( Id.class ); + } private static void bindVersionProperty( PropertyHolder propertyHolder, @@ -1267,13 +1294,13 @@ public class PropertyBinder { * @apiNote Poorly named to a degree. The intention is really whether non-optional is explicit */ private static boolean isExplicitlyOptional(MemberDetails attributeMember) { - final AnnotationUsage basicAnn = attributeMember.getAnnotationUsage( Basic.class ); + final Basic basicAnn = attributeMember.getDirectAnnotationUsage( Basic.class ); if ( basicAnn == null ) { // things are optional (nullable) by default. If there is no annotation, that cannot be altered return true; } - return basicAnn.getBoolean( "optional" ); + return basicAnn.optional(); } /** @@ -1281,9 +1308,9 @@ public class PropertyBinder { * account whether it is primitive? */ public static boolean isOptional(MemberDetails attributeMember, PropertyHolder propertyHolder) { - final AnnotationUsage basicAnn = attributeMember.getAnnotationUsage( Basic.class ); + final Basic basicAnn = attributeMember.getDirectAnnotationUsage( Basic.class ); if ( basicAnn != null ) { - return basicAnn.getBoolean( "optional" ); + return basicAnn.optional(); } if ( attributeMember.isArray() ) { @@ -1302,8 +1329,8 @@ public class PropertyBinder { } private static boolean isLazy(MemberDetails property) { - final AnnotationUsage annotationUsage = property.getAnnotationUsage( Basic.class ); - return annotationUsage != null && annotationUsage.getEnum( "fetch" ) == LAZY; + final Basic annotationUsage = property.getDirectAnnotationUsage( Basic.class ); + return annotationUsage != null && annotationUsage.fetch() == LAZY; } private static void addIndexes( @@ -1312,7 +1339,7 @@ public class PropertyBinder { AnnotatedColumns columns, AnnotatedJoinColumns joinColumns) { //process indexes after everything: in second pass, many to one has to be done before indexes - final AnnotationUsage index = property.getAnnotationUsage( Index.class ); + final Index index = property.getDirectAnnotationUsage( Index.class ); if ( index == null ) { return; } @@ -1341,61 +1368,59 @@ public class PropertyBinder { // For now, simply ensure consistent naming. // TODO: AFAIK, there really isn't a reason for these UKs to be created // on the SecondPass. This whole area should go away... - final AnnotationUsage naturalId = property.getAnnotationUsage( NaturalId.class ); + final NaturalId naturalId = property.getDirectAnnotationUsage( NaturalId.class ); if ( naturalId != null ) { final Database database = context.getMetadataCollector().getDatabase(); final ImplicitNamingStrategy implicitNamingStrategy = context.getBuildingOptions().getImplicitNamingStrategy(); if ( joinColumns != null ) { - final Identifier name = - implicitNamingStrategy.determineUniqueKeyName( new ImplicitUniqueKeyNameSource() { - @Override - public Identifier getTableName() { - return joinColumns.getTable().getNameIdentifier(); - } + final Identifier name = implicitNamingStrategy.determineUniqueKeyName( new ImplicitUniqueKeyNameSource() { + @Override + public Identifier getTableName() { + return joinColumns.getTable().getNameIdentifier(); + } - @Override - public List getColumnNames() { - return singletonList(toIdentifier("_NaturalID")); - } + @Override + public List getColumnNames() { + return singletonList(toIdentifier("_NaturalID")); + } - @Override - public Identifier getUserProvidedIdentifier() { - return null; - } + @Override + public Identifier getUserProvidedIdentifier() { + return null; + } - @Override - public MetadataBuildingContext getBuildingContext() { - return context; - } - }); + @Override + public MetadataBuildingContext getBuildingContext() { + return context; + } + }); final String keyName = name.render( database.getDialect() ); for ( AnnotatedColumn column : joinColumns.getColumns() ) { column.addUniqueKey( keyName, inSecondPass ); } } else { - final Identifier name = - implicitNamingStrategy.determineUniqueKeyName(new ImplicitUniqueKeyNameSource() { - @Override - public Identifier getTableName() { - return columns.getTable().getNameIdentifier(); - } + final Identifier name = implicitNamingStrategy.determineUniqueKeyName(new ImplicitUniqueKeyNameSource() { + @Override + public Identifier getTableName() { + return columns.getTable().getNameIdentifier(); + } - @Override - public List getColumnNames() { - return singletonList(toIdentifier("_NaturalID")); - } + @Override + public List getColumnNames() { + return singletonList(toIdentifier("_NaturalID")); + } - @Override - public Identifier getUserProvidedIdentifier() { - return null; - } + @Override + public Identifier getUserProvidedIdentifier() { + return null; + } - @Override - public MetadataBuildingContext getBuildingContext() { - return context; - } - }); + @Override + public MetadataBuildingContext getBuildingContext() { + return context; + } + }); final String keyName = name.render( database.getDialect() ); for ( AnnotatedColumn column : columns.getColumns() ) { column.addUniqueKey( keyName, inSecondPass ); @@ -1407,14 +1432,15 @@ public class PropertyBinder { private static Class> resolveCompositeUserType( PropertyData inferredData, MetadataBuildingContext context) { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); final MemberDetails attributeMember = inferredData.getAttributeMember(); final TypeDetails classOrElementType = inferredData.getClassOrElementType(); final ClassDetails returnedClass = classOrElementType.determineRawClass(); if ( attributeMember != null ) { - final AnnotationUsage compositeType = attributeMember.locateAnnotationUsage( CompositeType.class ); + final CompositeType compositeType = attributeMember.locateAnnotationUsage( CompositeType.class, sourceModelContext ); if ( compositeType != null ) { - return compositeType.getClassDetails( "value" ).toJavaClass(); + return compositeType.value(); } final Class> compositeUserType = resolveTimeZoneStorageCompositeUserType( attributeMember, returnedClass, context ); if ( compositeUserType != null ) { @@ -1443,24 +1469,36 @@ public class PropertyBinder { throw new AnnotationException( "Property '"+ getPath( propertyHolder, inferredData ) + "' belongs to an '@IdClass' and may not be annotated '@Id' or '@EmbeddedId'" ); } + + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); final MemberDetails idAttributeMember = inferredData.getAttributeMember(); - final List> idGeneratorAnnotations = idAttributeMember.getMetaAnnotated( IdGeneratorType.class ); - final List> generatorAnnotations = idAttributeMember.getMetaAnnotated( ValueGenerationType.class ); + final List idGeneratorAnnotations = idAttributeMember.getMetaAnnotated( IdGeneratorType.class, sourceModelContext ); + final List generatorAnnotations = idAttributeMember.getMetaAnnotated( ValueGenerationType.class, sourceModelContext ); removeIdGenerators( generatorAnnotations, idGeneratorAnnotations ); if ( idGeneratorAnnotations.size() + generatorAnnotations.size() > 1 ) { - throw new AnnotationException( "Property '"+ getPath( propertyHolder, inferredData ) - + "' has too many generator annotations " + combine( idGeneratorAnnotations, generatorAnnotations ) ); + throw new AnnotationException( String.format( + Locale.ROOT, + "Property `%s` has too many generator annotations : %s", + getPath( propertyHolder, inferredData ), + CollectionHelper.combineUntyped( idGeneratorAnnotations, generatorAnnotations ) + ) ); } if ( !idGeneratorAnnotations.isEmpty() ) { - final AnnotationUsage annotation = idGeneratorAnnotations.get(0); - idValue.setCustomIdGeneratorCreator( identifierGeneratorCreator( idAttributeMember, annotation, - idValue, beanContainer( context ) ) ); + idValue.setCustomIdGeneratorCreator( identifierGeneratorCreator( + idAttributeMember, + idGeneratorAnnotations.get(0), + idValue, + beanContainer( context ) + ) ); } else if ( !generatorAnnotations.isEmpty() ) { // idValue.setCustomGeneratorCreator( generatorCreator( idAttributeMember, generatorAnnotation ) ); - throw new AnnotationException( "Property '"+ getPath( propertyHolder, inferredData ) - + "' is annotated '" + generatorAnnotations.get(0).getAnnotationType() - + "' which is not an '@IdGeneratorType'" ); + throw new AnnotationException( String.format( + Locale.ROOT, + "Property '%s' is annotated `%s` which is not an `@IdGeneratorType`", + getPath( propertyHolder, inferredData ), + generatorAnnotations.get(0).annotationType() + ) ); } else { final ClassDetails entityClass = inferredData.getClassOrElementType().determineRawClass(); @@ -1479,12 +1517,11 @@ public class PropertyBinder { // collection methods as those proxies do not implement hashcode/equals and even a simple `a.equals(a)` will return `false`. // Instead, we will check the annotation types, since generator annotations should not be "repeatable" we should have only // at most one annotation for a generator: - // todo (jpa32) : is this still necessary with s/hibernate-common-annotations/hibernate-models? private static void removeIdGenerators( - List> generatorAnnotations, - List> idGeneratorAnnotations) { - for ( AnnotationUsage id : idGeneratorAnnotations ) { - generatorAnnotations.removeIf( gen -> gen.getAnnotationType().equals( id.getAnnotationType() ) ); + List generatorAnnotations, + List idGeneratorAnnotations) { + for ( Annotation id : idGeneratorAnnotations ) { + generatorAnnotations.removeIf( gen -> gen.annotationType().equals( id.annotationType() ) ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyContainer.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyContainer.java index 708534f6db..7bb38fd9c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyContainer.java @@ -29,7 +29,6 @@ import org.hibernate.boot.spi.AccessType; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.MemberDetails; @@ -179,9 +178,9 @@ public class PropertyContainer { // Check fields... for ( int i = 0; i < fields.size(); i++ ) { final FieldDetails fieldDetails = fields.get( i ); - final AnnotationUsage localAccessAnnotation = fieldDetails.getAnnotationUsage( Access.class ); + final Access localAccessAnnotation = fieldDetails.getDirectAnnotationUsage( Access.class ); if ( localAccessAnnotation == null - || localAccessAnnotation.getEnum( "value" ) != jakarta.persistence.AccessType.FIELD ) { + || localAccessAnnotation.value() != jakarta.persistence.AccessType.FIELD ) { continue; } persistentAttributeMap.put( fieldDetails.getName(), fieldDetails ); @@ -190,9 +189,9 @@ public class PropertyContainer { // Check getters... for ( int i = 0; i < getters.size(); i++ ) { final MethodDetails getterDetails = getters.get( i ); - final AnnotationUsage localAccessAnnotation = getterDetails.getAnnotationUsage( Access.class ); + final Access localAccessAnnotation = getterDetails.getDirectAnnotationUsage( Access.class ); if ( localAccessAnnotation == null - || localAccessAnnotation.getEnum( "value" ) != jakarta.persistence.AccessType.PROPERTY ) { + || localAccessAnnotation.value() != jakarta.persistence.AccessType.PROPERTY ) { continue; } @@ -218,7 +217,7 @@ public class PropertyContainer { // Check record components... for ( int i = 0; i < recordComponents.size(); i++ ) { final RecordComponentDetails componentDetails = recordComponents.get( i ); - final AnnotationUsage localAccessAnnotation = componentDetails.getAnnotationUsage( Access.class ); + final Access localAccessAnnotation = componentDetails.getDirectAnnotationUsage( Access.class ); if ( localAccessAnnotation == null ) { continue; } @@ -330,65 +329,60 @@ public class PropertyContainer { private AccessType determineLocalClassDefinedAccessStrategy() { AccessType classDefinedAccessType = AccessType.DEFAULT; - final AnnotationUsage access = classDetails.getAnnotationUsage( Access.class ); + final Access access = classDetails.getDirectAnnotationUsage( Access.class ); if ( access != null ) { - classDefinedAccessType = AccessType.getAccessStrategy( access.getEnum( "value" ) ); + classDefinedAccessType = AccessType.getAccessStrategy( access.value() ); } return classDefinedAccessType; } private static boolean discoverTypeWithoutReflection(ClassDetails classDetails, MemberDetails memberDetails) { - if ( memberDetails.hasAnnotationUsage( Target.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( Target.class ) ) { return true; } - if ( memberDetails.hasAnnotationUsage( Basic.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( Basic.class ) ) { return true; } - if ( memberDetails.hasAnnotationUsage( Type.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( Type.class ) ) { return true; } - if ( memberDetails.hasAnnotationUsage( JavaType.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( JavaType.class ) ) { return true; } - final AnnotationUsage oneToOneAnn = memberDetails.getAnnotationUsage( OneToOne.class ); + final OneToOne oneToOneAnn = memberDetails.getDirectAnnotationUsage( OneToOne.class ); if ( oneToOneAnn != null ) { - final ClassDetails targetEntity = oneToOneAnn.getClassDetails( "targetEntity" ); - return targetEntity != ClassDetails.VOID_CLASS_DETAILS; + return oneToOneAnn.targetEntity() != void.class; } - - final AnnotationUsage oneToManyAnn = memberDetails.getAnnotationUsage( OneToMany.class ); + final OneToMany oneToManyAnn = memberDetails.getDirectAnnotationUsage( OneToMany.class ); if ( oneToManyAnn != null ) { - final ClassDetails targetEntity = oneToManyAnn.getClassDetails( "targetEntity" ); - return targetEntity != ClassDetails.VOID_CLASS_DETAILS; + return oneToManyAnn.targetEntity() != void.class; } - - final AnnotationUsage manToOneAnn = memberDetails.getAnnotationUsage( ManyToOne.class ); - if ( manToOneAnn != null ) { - final ClassDetails targetEntity = manToOneAnn.getClassDetails( "targetEntity" ); - return targetEntity != ClassDetails.VOID_CLASS_DETAILS; + final ManyToOne manyToOneAnn = memberDetails.getDirectAnnotationUsage( ManyToOne.class ); + if ( manyToOneAnn != null ) { + return manyToOneAnn.targetEntity() != void.class; } - final AnnotationUsage manToManyAnn = memberDetails.getAnnotationUsage( ManyToMany.class ); - if ( manToManyAnn != null ) { - final ClassDetails targetEntity = manToManyAnn.getClassDetails( "targetEntity" ); - return targetEntity != ClassDetails.VOID_CLASS_DETAILS; + final ManyToMany manyToManyAnn = memberDetails.getDirectAnnotationUsage( ManyToMany.class ); + if ( manyToManyAnn != null ) { + return manyToManyAnn.targetEntity() != void.class; } - if ( memberDetails.hasAnnotationUsage( Any.class ) ) { + if ( memberDetails.hasDirectAnnotationUsage( Any.class ) ) { return true; } - final AnnotationUsage manToAnyAnn = memberDetails.getAnnotationUsage( ManyToAny.class ); + final ManyToAny manToAnyAnn = memberDetails.getDirectAnnotationUsage( ManyToAny.class ); if ( manToAnyAnn != null ) { return true; } - else if ( memberDetails.hasAnnotationUsage( JdbcTypeCode.class ) ) { + + if ( memberDetails.hasDirectAnnotationUsage( JdbcTypeCode.class ) ) { return true; } @@ -403,7 +397,7 @@ public class PropertyContainer { private static boolean mustBeSkipped(MemberDetails memberDetails) { //TODO make those hardcoded tests more portable (through the bytecode provider?) - return memberDetails.hasAnnotationUsage( Transient.class ) + return memberDetails.hasDirectAnnotationUsage( Transient.class ) || (memberDetails.getType() != null && "net.sf.cglib.transform.impl.InterceptFieldCallback".equals( memberDetails.getType().getName() ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyHolder.java index 047ed2342f..ba230325e9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyHolder.java @@ -6,8 +6,6 @@ */ package org.hibernate.boot.model.internal; -import java.util.List; - import org.hibernate.annotations.ColumnTransformer; import org.hibernate.boot.model.convert.spi.ConverterDescriptor; import org.hibernate.mapping.Join; @@ -15,7 +13,6 @@ import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; @@ -65,22 +62,22 @@ public interface PropertyHolder { /** * return null if the column is not overridden, or an array of column if true */ - List> getOverriddenColumn(String propertyName); + Column[] getOverriddenColumn(String propertyName); /** * return null if the column is not overridden, or an array of column if true */ - List> getOverriddenJoinColumn(String propertyName); + JoinColumn[] getOverriddenJoinColumn(String propertyName); /** * return null if hte foreign key is not overridden, or the foreign key if true */ - default AnnotationUsage getOverriddenForeignKey(String propertyName) { + default ForeignKey getOverriddenForeignKey(String propertyName) { // todo: does this necessarily need to be a default method? return null; } - AnnotationUsage getOverriddenColumnTransformer(String logicalColumnName); + ColumnTransformer getOverriddenColumnTransformer(String logicalColumnName); /** * return @@ -88,13 +85,13 @@ public interface PropertyHolder { * - the join table if not overridden, * - the overridden join table otherwise */ - AnnotationUsage getJoinTable(MemberDetails attributeMember); + JoinTable getJoinTable(MemberDetails attributeMember); String getEntityName(); - Join addJoin(AnnotationUsage joinTableAnn, boolean noDelayInPkColumnCreation); + Join addJoin(JoinTable joinTableAnn, boolean noDelayInPkColumnCreation); - Join addJoin(AnnotationUsage joinTable, Table table, boolean noDelayInPkColumnCreation); + Join addJoin(JoinTable joinTable, Table table, boolean noDelayInPkColumnCreation); boolean isInIdClass(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyInferredData.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyInferredData.java index af6b71493e..000cde6257 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyInferredData.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyInferredData.java @@ -13,8 +13,8 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.models.internal.ClassTypeDetailsImpl; import org.hibernate.models.internal.dynamic.DynamicClassDetails; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; @@ -63,9 +63,9 @@ public class PropertyInferredData implements PropertyData { AccessType jpaAccessType = AccessType.DEFAULT; - AnnotationUsage access = propertyMember.getAnnotationUsage( Access.class ); + Access access = propertyMember.getDirectAnnotationUsage( Access.class ); if ( access != null ) { - jpaAccessType = AccessType.getAccessStrategy( access.getEnum( "value" ) ); + jpaAccessType = AccessType.getAccessStrategy( access.value() ); } if ( jpaAccessType != AccessType.DEFAULT ) { @@ -81,12 +81,12 @@ public class PropertyInferredData implements PropertyData { @Override public TypeDetails getPropertyType() throws MappingException { - final AnnotationUsage targetAnnotation = propertyMember.getAnnotationUsage( org.hibernate.boot.internal.Target.class ); + final org.hibernate.boot.internal.Target targetAnnotation = propertyMember.getDirectAnnotationUsage( org.hibernate.boot.internal.Target.class ); + final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector() + .getSourceModelBuildingContext(); if ( targetAnnotation != null ) { - final String targetName = targetAnnotation.getString( "value" ); - final SourceModelBuildingContext sourceModelBuildingContext = buildingContext - .getMetadataCollector() - .getSourceModelBuildingContext(); + final String targetName = targetAnnotation.value(); + final SourceModelBuildingContext sourceModelBuildingContext = sourceModelContext; final ClassDetails classDetails = sourceModelBuildingContext.getClassDetailsRegistry().resolveClassDetails( targetName, name -> new DynamicClassDetails( targetName, sourceModelBuildingContext ) @@ -94,22 +94,31 @@ public class PropertyInferredData implements PropertyData { return new ClassTypeDetailsImpl( classDetails, TypeDetails.Kind.CLASS ); } - final AnnotationUsage legacyTargetAnnotation = propertyMember.getAnnotationUsage( Target.class ); + final Target legacyTargetAnnotation = propertyMember.getDirectAnnotationUsage( Target.class ); if ( legacyTargetAnnotation != null ) { - return new ClassTypeDetailsImpl( legacyTargetAnnotation.getClassDetails( "value" ), TypeDetails.Kind.CLASS ); + return resolveLegacyTargetAnnotation( legacyTargetAnnotation, sourceModelContext ); } return propertyMember.resolveRelativeType( ownerType ); } + private static ClassTypeDetailsImpl resolveLegacyTargetAnnotation( + Target legacyTargetAnnotation, + SourceModelBuildingContext sourceModelContext) { + final ClassDetailsRegistry classDetailsRegistry = sourceModelContext.getClassDetailsRegistry(); + final ClassDetails targetClassDetails = classDetailsRegistry.resolveClassDetails( legacyTargetAnnotation.value().getName() ); + return new ClassTypeDetailsImpl( targetClassDetails, TypeDetails.Kind.CLASS ); + } + @Override public TypeDetails getClassOrElementType() throws MappingException { - final AnnotationUsage annotationUsage = propertyMember.getAnnotationUsage( org.hibernate.boot.internal.Target.class ); + final SourceModelBuildingContext sourceModelBuildingContext = buildingContext + .getMetadataCollector() + .getSourceModelBuildingContext(); + + final org.hibernate.boot.internal.Target annotationUsage = propertyMember.getDirectAnnotationUsage( org.hibernate.boot.internal.Target.class ); if ( annotationUsage != null ) { - final String targetName = annotationUsage.getString( "value" ); - final SourceModelBuildingContext sourceModelBuildingContext = buildingContext - .getMetadataCollector() - .getSourceModelBuildingContext(); + final String targetName = annotationUsage.value(); final ClassDetails classDetails = sourceModelBuildingContext.getClassDetailsRegistry().resolveClassDetails( targetName, name -> new DynamicClassDetails( targetName, sourceModelBuildingContext ) @@ -117,9 +126,9 @@ public class PropertyInferredData implements PropertyData { return new ClassTypeDetailsImpl( classDetails, TypeDetails.Kind.CLASS ); } - final AnnotationUsage legacyAnnotationUsage = propertyMember.getAnnotationUsage( Target.class ); - if ( legacyAnnotationUsage != null ) { - return new ClassTypeDetailsImpl( legacyAnnotationUsage.getClassDetails( "value" ), TypeDetails.Kind.CLASS ); + final Target legacyTargetAnnotation = propertyMember.getDirectAnnotationUsage( Target.class ); + if ( legacyTargetAnnotation != null ) { + return resolveLegacyTargetAnnotation( legacyTargetAnnotation, sourceModelBuildingContext ); } return propertyMember.resolveRelativeAssociatedType( ownerType ); @@ -127,9 +136,15 @@ public class PropertyInferredData implements PropertyData { @Override public ClassDetails getClassOrPluralElement() throws MappingException { - final AnnotationUsage targetAnnotationUsage = propertyMember.getAnnotationUsage( Target.class ); - if ( targetAnnotationUsage != null ) { - return targetAnnotationUsage.getClassDetails( "value" ); + final org.hibernate.boot.internal.Target xmlTarget = propertyMember.getDirectAnnotationUsage( org.hibernate.boot.internal.Target.class ); + if ( xmlTarget != null ) { + return buildingContext.getMetadataCollector().getClassDetailsRegistry().getClassDetails( xmlTarget.value() ); + } + + final Target legacyTarget = propertyMember.getDirectAnnotationUsage( Target.class ); + if ( legacyTarget != null ) { + final String targetName = legacyTarget.value().getName(); + return buildingContext.getMetadataCollector().getClassDetailsRegistry().getClassDetails( targetName ); } if ( propertyMember.isPlural() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java index 7b22124965..315a5da68f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java @@ -7,6 +7,7 @@ package org.hibernate.boot.model.internal; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.function.Supplier; @@ -22,6 +23,9 @@ import org.hibernate.annotations.SQLSelect; import org.hibernate.boot.internal.NamedHqlQueryDefinitionImpl; import org.hibernate.boot.internal.NamedProcedureCallDefinitionImpl; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.NamedStoredProcedureQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.QueryHintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.StoredProcedureParameterJpaAnnotation; import org.hibernate.boot.query.NamedHqlQueryDefinition; import org.hibernate.boot.query.NamedNativeQueryDefinition; import org.hibernate.boot.query.NamedProcedureCallDefinition; @@ -30,11 +34,10 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.log.DeprecationLogger; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.jpa.HibernateHints; import org.hibernate.models.internal.util.StringHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.query.sql.internal.ParameterParser; import org.hibernate.query.sql.spi.ParameterRecognizer; @@ -42,6 +45,8 @@ import org.hibernate.type.BasicType; import org.jboss.logging.Logger; +import jakarta.persistence.CacheRetrieveMode; +import jakarta.persistence.CacheStoreMode; import jakarta.persistence.NamedNativeQuery; import jakarta.persistence.NamedQuery; import jakarta.persistence.NamedStoredProcedureQuery; @@ -67,15 +72,15 @@ public abstract class QueryBinder { private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, QueryBinder.class.getName()); public static void bindQuery( - AnnotationUsage namedQuery, + NamedQuery namedQuery, MetadataBuildingContext context, boolean isDefault) { if ( namedQuery == null ) { return; } - final String queryName = namedQuery.getString( "name" ); - final String queryString = namedQuery.getString( "query" ); + final String queryName = namedQuery.name(); + final String queryString = namedQuery.query(); if ( queryName.isEmpty() ) { throw new AnnotationException( "Class or package level '@NamedQuery' annotation must specify a 'name'" ); @@ -85,11 +90,11 @@ public abstract class QueryBinder { LOG.debugf( "Binding named query: %s => %s", queryName, queryString ); } - final QueryHintDefinition hints = new QueryHintDefinition( queryName, namedQuery.getList( "hints" ) ); + final QueryHintDefinition hints = new QueryHintDefinition( queryName, namedQuery.hints() ); final NamedHqlQueryDefinition queryMapping = new NamedHqlQueryDefinitionImpl.Builder<>( queryName ) .setHqlString( queryString ) - .setResultClass( loadClass( namedQuery.getClassDetails( "resultClass" ), context ) ) + .setResultClass( (Class) namedQuery.resultClass() ) .setCacheable( hints.getCacheability() ) .setCacheMode( hints.getCacheMode() ) .setCacheRegion( hints.getString( HibernateHints.HINT_CACHE_REGION ) ) @@ -119,28 +124,27 @@ public abstract class QueryBinder { } public static void bindNativeQuery( - AnnotationUsage namedNativeQuery, + NamedNativeQuery namedNativeQuery, MetadataBuildingContext context, boolean isDefault) { if ( namedNativeQuery == null ) { return; } - final String registrationName = namedNativeQuery.getString( "name" ); - final String queryString = namedNativeQuery.getString( "query" ); + final String registrationName = namedNativeQuery.name(); + final String queryString = namedNativeQuery.query(); if ( registrationName.isEmpty() ) { throw new AnnotationException( "Class or package level '@NamedNativeQuery' annotation must specify a 'name'" ); } - final QueryHintDefinition hints = new QueryHintDefinition( registrationName, namedNativeQuery.getList( "hints" ) ); + final QueryHintDefinition hints = new QueryHintDefinition( registrationName, namedNativeQuery.hints() ); - final String resultSetMappingName = namedNativeQuery.getString( "resultSetMapping" ); - final ClassDetails resultClassDetails = namedNativeQuery.getClassDetails( "resultClass" ); - final Class resultClass = ClassDetails.VOID_CLASS_DETAILS == resultClassDetails + final String resultSetMappingName = namedNativeQuery.resultSetMapping(); + final Class resultClassDetails = namedNativeQuery.resultClass(); + final Class resultClass = void.class == resultClassDetails ? null - : context.getBootstrapContext().getServiceRegistry().requireService( ClassLoaderService.class ) - .classForName( resultClassDetails.getClassName() ); + : (Class) resultClassDetails; final NamedNativeQueryDefinition.Builder builder = new NamedNativeQueryDefinition.Builder<>( registrationName ) .setSqlString( queryString ) @@ -173,13 +177,13 @@ public abstract class QueryBinder { public static void bindNativeQuery( String name, - AnnotationUsage sqlSelect, + SQLSelect sqlSelect, ClassDetails annotatedClass, MetadataBuildingContext context) { final NamedNativeQueryDefinition.Builder builder = new NamedNativeQueryDefinition.Builder<>( name ) .setFlushMode( FlushMode.MANUAL ) - .setSqlString( sqlSelect.getString( "sql" ) ) - .setQuerySpaces( setOf( sqlSelect.getList( "querySpaces" ) ) ); + .setSqlString( sqlSelect.sql() ) + .setQuerySpaces( setOf( sqlSelect.querySpaces() ) ); if ( annotatedClass != null ) { builder.setResultClass( @@ -188,10 +192,10 @@ public abstract class QueryBinder { ); } - final AnnotationUsage resultSetMapping = sqlSelect.getNestedUsage( "resultSetMapping" ); - if ( !resultSetMapping.getList( "columns" ).isEmpty() - || !resultSetMapping.getList( "entities" ).isEmpty() - || !resultSetMapping.getList( "classes" ).isEmpty() ) { + final SqlResultSetMapping resultSetMapping = sqlSelect.resultSetMapping(); + if ( !ArrayHelper.isEmpty( resultSetMapping.columns() ) + || !ArrayHelper.isEmpty( resultSetMapping.entities() ) + || !ArrayHelper.isEmpty( resultSetMapping.classes() ) ) { context.getMetadataCollector().addResultSetMapping( SqlResultSetMappingDescriptor.from( resultSetMapping, name ) ); builder.setResultSetMappingName( name ); } @@ -200,48 +204,47 @@ public abstract class QueryBinder { } public static void bindNativeQuery( - AnnotationUsage namedNativeQuery, + org.hibernate.annotations.NamedNativeQuery namedNativeQuery, MetadataBuildingContext context) { if ( namedNativeQuery == null ) { return; } - final String registrationName = namedNativeQuery.getString( "name" ); + final String registrationName = namedNativeQuery.name(); //ResultSetMappingDefinition mappingDefinition = mappings.getJdbcValuesMappingProducer( queryAnn.resultSetMapping() ); if ( registrationName.isEmpty() ) { throw new AnnotationException( "Class or package level '@NamedNativeQuery' annotation must specify a 'name'" ); } - final String resultSetMappingName = namedNativeQuery.getString( "resultSetMapping" ); - final ClassDetails resultClassDetails = namedNativeQuery.getClassDetails( "resultClass" ); - final Class resultClass = ClassDetails.VOID_CLASS_DETAILS == resultClassDetails + final String resultSetMappingName = namedNativeQuery.resultSetMapping(); + final Class resultClassDetails = namedNativeQuery.resultClass(); + final Class resultClass = resultClassDetails == void.class ? null - : context.getBootstrapContext().getServiceRegistry().requireService( ClassLoaderService.class ) - .classForName( resultClassDetails.getClassName() ); + : (Class) resultClassDetails; - final Integer timeout = namedNativeQuery.getInteger( "timeout" ); - final Integer fetchSize = namedNativeQuery.getInteger( "fetchSize" ); + final Integer timeout = namedNativeQuery.timeout(); + final Integer fetchSize = namedNativeQuery.fetchSize(); - final List querySpacesList = namedNativeQuery.getList( "querySpaces" ); - final HashSet querySpaces = new HashSet<>( determineProperSizing( querySpacesList.size() ) ); - querySpaces.addAll( querySpacesList ); + final String[] querySpacesList = namedNativeQuery.querySpaces(); + final HashSet querySpaces = new HashSet<>( determineProperSizing( querySpacesList.length ) ); + Collections.addAll( querySpaces, querySpacesList ); final NamedNativeQueryDefinition.Builder builder = new NamedNativeQueryDefinition.Builder<>( registrationName ) - .setSqlString( namedNativeQuery.getString( "query" ) ) + .setSqlString( namedNativeQuery.query() ) .setResultSetMappingName( resultSetMappingName ) .setResultClass( resultClass ) - .setCacheable( namedNativeQuery.getBoolean( "cacheable" ) ) - .setCacheRegion( nullIfEmpty( namedNativeQuery.getString( "cacheRegion" ) ) ) - .setCacheMode( getCacheMode( namedNativeQuery ) ) + .setCacheable( namedNativeQuery.cacheable() ) + .setCacheRegion( nullIfEmpty( namedNativeQuery.cacheRegion() ) ) + .setCacheMode( getCacheMode( namedNativeQuery.cacheRetrieveMode(), namedNativeQuery.cacheStoreMode(), namedNativeQuery.cacheMode() ) ) .setTimeout( timeout < 0 ? null : timeout ) .setFetchSize( fetchSize < 0 ? null : fetchSize ) - .setFlushMode( getFlushMode( namedNativeQuery.getEnum( "flushMode" ) ) ) - .setReadOnly( namedNativeQuery.getBoolean( "readOnly" ) ) + .setFlushMode( getFlushMode( namedNativeQuery.flushMode() ) ) + .setReadOnly( namedNativeQuery.readOnly() ) .setQuerySpaces( querySpaces ) - .setComment( nullIfEmpty( namedNativeQuery.getString( "comment" ) ) ); + .setComment( nullIfEmpty( namedNativeQuery.comment() ) ); - if ( TRUE == namedNativeQuery.getBoolean( "callable" ) ) { + if ( TRUE == namedNativeQuery.callable() ) { final NamedProcedureCallDefinition definition = createStoredProcedure( builder, context, () -> illegalCallSyntax( namedNativeQuery ) ); context.getMetadataCollector().addNamedProcedureCallDefinition( definition ); @@ -264,6 +267,12 @@ public abstract class QueryBinder { } } + /** + * Handles legacy cases where a named native query was used to specify a procedure call + * + * @deprecated User should use {@linkplain NamedStoredProcedureQuery} instead + */ + @Deprecated public static NamedProcedureCallDefinition createStoredProcedure( NamedNativeQueryDefinition.Builder builder, MetadataBuildingContext context, @@ -276,18 +285,22 @@ public abstract class QueryBinder { final SourceModelBuildingContext sourceModelBuildingContext = context.getMetadataCollector() .getSourceModelBuildingContext(); - final MutableAnnotationUsage nameStoredProcedureQueryAnn = - JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY.createUsage( sourceModelBuildingContext ); - nameStoredProcedureQueryAnn.setAttributeValue( "name", builder.getName() ); - nameStoredProcedureQueryAnn.setAttributeValue( "procedureName", jdbcCall.callableName ); + final NamedStoredProcedureQueryJpaAnnotation nameStoredProcedureQueryAnn = JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY.createUsage( sourceModelBuildingContext ); + nameStoredProcedureQueryAnn.name( builder.getName() ); + nameStoredProcedureQueryAnn.procedureName( jdbcCall.callableName ); - final List> storedProcedureParameters = new ArrayList<>(); - for ( String parameterName : jdbcCall.parameters ) { - final MutableAnnotationUsage storedProcedureParameterAnn = - JpaAnnotations.STORED_PROCEDURE_PARAMETER.createUsage( sourceModelBuildingContext ); - storedProcedureParameterAnn.setAttributeValue( "name", parameterName ); - storedProcedureParameterAnn.setAttributeValue( "mode", ParameterMode.IN ); - final String typeName = builder.getParameterTypes().get( parameterName ); + final StoredProcedureParameter[] parameters = new StoredProcedureParameter[jdbcCall.parameters.size()]; + nameStoredProcedureQueryAnn.parameters( parameters ); + + for ( int i = 0; i < jdbcCall.parameters.size(); i++ ) { + final StoredProcedureParameterJpaAnnotation param = JpaAnnotations.STORED_PROCEDURE_PARAMETER.createUsage( sourceModelBuildingContext ); + parameters[i] = param; + + final String paramName = jdbcCall.parameters.get( i ); + param.name( paramName ); + param.mode( ParameterMode.IN ); + + final String typeName = builder.getParameterTypes().get( paramName ); final ClassDetails classDetails; if ( StringHelper.isEmpty( typeName ) ) { classDetails = ClassDetails.VOID_CLASS_DETAILS; @@ -297,89 +310,82 @@ public abstract class QueryBinder { .getTypeConfiguration() .getBasicTypeRegistry() .getRegisteredType( typeName ); - classDetails = storedProcedureParameterAnn.getClassDetails( registeredType.getJavaType().getName() ); + classDetails = context.getMetadataCollector().getClassDetailsRegistry().getClassDetails( registeredType.getJavaType().getName() ); } - storedProcedureParameterAnn.setAttributeValue( "type", classDetails ); - - storedProcedureParameters.add( storedProcedureParameterAnn ); + param.type( classDetails.toJavaClass() ); } - nameStoredProcedureQueryAnn.setAttributeValue( "parameters", storedProcedureParameters ); if ( builder.getResultSetMappingName() != null ) { - final List resultSetMappings = new ArrayList<>( 1 ); - resultSetMappings.add( builder.getResultSetMappingName() ); - nameStoredProcedureQueryAnn.setAttributeValue( "resultSetMappings", resultSetMappings ); + nameStoredProcedureQueryAnn.resultSetMappings( new String[] { builder.getResultSetMappingName() } ); } final Class resultClass = builder.getResultClass(); if ( resultClass != null ) { - final List resultClasses = new ArrayList<>( 1 ); - final ClassDetails classDetails = nameStoredProcedureQueryAnn.getClassDetails( resultClass.getName() ); - resultClasses.add( classDetails ); - nameStoredProcedureQueryAnn.setAttributeValue( "resultClasses", resultClasses ); + nameStoredProcedureQueryAnn.resultClasses( new Class[]{ builder.getResultClass() } ); } - final List> queryHints = new ArrayList<>(); + final List hints = new ArrayList<>(); + if ( builder.getQuerySpaces() != null ) { - final MutableAnnotationUsage queryHintAnn = JpaAnnotations.QUERY_HINT.createUsage( sourceModelBuildingContext ); - queryHintAnn.setAttributeValue( "name", HibernateHints.HINT_NATIVE_SPACES ); - queryHintAnn.setAttributeValue( "value", String.join( " ", builder.getQuerySpaces() ) ); - queryHints.add( queryHintAnn ); + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelBuildingContext ); + hint.name( HibernateHints.HINT_NATIVE_SPACES ); + hint.value( String.join( " ", builder.getQuerySpaces() ) ); + hints.add( hint ); } if ( jdbcCall.resultParameter ) { // Mark native queries that have a result parameter as callable functions - final MutableAnnotationUsage queryHintAnn = JpaAnnotations.QUERY_HINT.createUsage( sourceModelBuildingContext ); - queryHintAnn.setAttributeValue( "name", HibernateHints.HINT_CALLABLE_FUNCTION ); - queryHintAnn.setAttributeValue( "value", "true" ); - queryHints.add( queryHintAnn ); + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelBuildingContext ); + hint.name( HibernateHints.HINT_CALLABLE_FUNCTION ); + hint.value( "true" ); + hints.add( hint ); } - nameStoredProcedureQueryAnn.setAttributeValue( "hints", queryHints ); + nameStoredProcedureQueryAnn.hints( hints.toArray(QueryHint[]::new) ); - return new NamedProcedureCallDefinitionImpl( nameStoredProcedureQueryAnn ); + return new NamedProcedureCallDefinitionImpl( nameStoredProcedureQueryAnn ); } public static void bindQuery( String name, - AnnotationUsage hqlSelect, + HQLSelect hqlSelect, MetadataBuildingContext context) { final NamedHqlQueryDefinition hqlQueryDefinition = new NamedHqlQueryDefinition.Builder<>( name ) .setFlushMode( FlushMode.MANUAL ) - .setHqlString( hqlSelect.getString( "query" ) ) + .setHqlString( hqlSelect.query() ) .build(); context.getMetadataCollector().addNamedQuery( hqlQueryDefinition ); } public static void bindQuery( - AnnotationUsage namedQuery, + org.hibernate.annotations.NamedQuery namedQuery, MetadataBuildingContext context) { if ( namedQuery == null ) { return; } - final String registrationName = namedQuery.getString( "name" ); + final String registrationName = namedQuery.name(); //ResultSetMappingDefinition mappingDefinition = mappings.getJdbcValuesMappingProducer( namedQuery.resultSetMapping() ); if ( registrationName.isEmpty() ) { throw new AnnotationException( "Class or package level '@NamedQuery' annotation must specify a 'name'" ); } - final Integer timeout = namedQuery.getInteger( "timeout" ); - final Integer fetchSize = namedQuery.getInteger( "fetchSize" ); + final int timeout = namedQuery.timeout(); + final int fetchSize = namedQuery.fetchSize(); final NamedHqlQueryDefinition.Builder builder = new NamedHqlQueryDefinition.Builder<>( registrationName ) - .setHqlString( namedQuery.getString( "query" ) ) - .setResultClass( loadClass( namedQuery.getClassDetails( "resultClass" ), context ) ) - .setCacheable( namedQuery.getBoolean( "cacheable" ) ) - .setCacheRegion( nullIfEmpty( namedQuery.getString( "cacheRegion" ) ) ) - .setCacheMode( getCacheMode( namedQuery ) ) + .setHqlString( namedQuery.query() ) + .setResultClass( (Class) namedQuery.resultClass() ) + .setCacheable( namedQuery.cacheable() ) + .setCacheRegion( nullIfEmpty( namedQuery.cacheRegion() ) ) + .setCacheMode( getCacheMode( namedQuery.cacheRetrieveMode(), namedQuery.cacheStoreMode(), namedQuery.cacheMode() ) ) .setTimeout( timeout < 0 ? null : timeout ) .setFetchSize( fetchSize < 0 ? null : fetchSize ) - .setFlushMode( getFlushMode( namedQuery.getEnum( "flushMode" ) ) ) - .setReadOnly( namedQuery.getBoolean( "readOnly" ) ) - .setComment( nullIfEmpty( namedQuery.getString( "comment" ) ) ); + .setFlushMode( getFlushMode( namedQuery.flushMode() ) ) + .setReadOnly( namedQuery.readOnly() ) + .setComment( nullIfEmpty( namedQuery.comment() ) ); final NamedHqlQueryDefinitionImpl hqlQueryDefinition = builder.build(); @@ -390,13 +396,10 @@ public abstract class QueryBinder { context.getMetadataCollector().addNamedQuery( hqlQueryDefinition ); } - private static CacheMode getCacheMode(AnnotationUsage namedQuery) { - final CacheMode cacheMode = CacheMode.fromJpaModes( - namedQuery.getEnum( "cacheRetrieveMode" ), - namedQuery.getEnum( "cacheStoreMode" ) - ); + private static CacheMode getCacheMode(CacheRetrieveMode cacheRetrieveMode, CacheStoreMode cacheStoreMode, CacheModeType cacheModeType) { + final CacheMode cacheMode = CacheMode.fromJpaModes( cacheRetrieveMode, cacheStoreMode ); return cacheMode == null || cacheMode == CacheMode.NORMAL - ? interpretCacheMode( namedQuery.getEnum( "cacheMode" ) ) + ? interpretCacheMode( cacheModeType ) : cacheMode; } @@ -435,11 +438,11 @@ public abstract class QueryBinder { } public static void bindNamedStoredProcedureQuery( - AnnotationUsage namedStoredProcedureQuery, + NamedStoredProcedureQuery namedStoredProcedureQuery, MetadataBuildingContext context, boolean isDefault) { if ( namedStoredProcedureQuery != null ) { - if ( namedStoredProcedureQuery.getString( "name" ).isEmpty() ) { + if ( namedStoredProcedureQuery.name().isEmpty() ) { throw new AnnotationException( "Class or package level '@NamedStoredProcedureQuery' annotation must specify a 'name'" ); } @@ -455,7 +458,7 @@ public abstract class QueryBinder { } public static void bindSqlResultSetMapping( - AnnotationUsage resultSetMappingAnn, + SqlResultSetMapping resultSetMappingAnn, MetadataBuildingContext context, boolean isDefault) { //no need to handle inSecondPass @@ -543,8 +546,8 @@ public abstract class QueryBinder { return i; } - private static AnnotationException illegalCallSyntax(AnnotationUsage queryAnn) { - return new AnnotationException( "Callable 'NamedNativeQuery' named '" + queryAnn.getString( "name" ) + private static AnnotationException illegalCallSyntax(org.hibernate.annotations.NamedNativeQuery queryAnn) { + return new AnnotationException( "Callable 'NamedNativeQuery' named '" + queryAnn.name() + "' does not use the JDBC call syntax" ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java index 6fd76b64b1..035c09b8da 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java @@ -7,7 +7,6 @@ package org.hibernate.boot.model.internal; import java.util.Collections; -import java.util.List; import java.util.Map; import org.hibernate.AnnotationException; @@ -23,7 +22,6 @@ import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.jpa.HibernateHints; import org.hibernate.jpa.LegacySpecHints; import org.hibernate.jpa.SpecHints; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.LockModeType; import jakarta.persistence.NamedQuery; @@ -38,15 +36,15 @@ public class QueryHintDefinition { private final String queryName; private final Map hintsMap; - public QueryHintDefinition(String queryName, final List> hints) { + public QueryHintDefinition(String queryName, final QueryHint[] hints) { this.queryName = queryName; if ( CollectionHelper.isEmpty( hints ) ) { hintsMap = Collections.emptyMap(); } else { - final Map hintsMap = mapOfSize( hints.size() ); - for ( AnnotationUsage hint : hints ) { - hintsMap.put( hint.getString( "name" ), hint.getString( "value" ) ); + final Map hintsMap = mapOfSize( hints.length ); + for ( QueryHint hint : hints ) { + hintsMap.put( hint.name(), hint.value() ); } this.hintsMap = hintsMap; } @@ -153,8 +151,8 @@ public class QueryHintDefinition { } } - public LockOptions determineLockOptions(AnnotationUsage namedQueryAnnotation) { - final LockModeType lockModeType = namedQueryAnnotation.getEnum( "lockMode" ); + public LockOptions determineLockOptions(NamedQuery namedQueryAnnotation) { + final LockModeType lockModeType = namedQueryAnnotation.lockMode(); final Integer lockTimeoutHint = specLockTimeout(); final Boolean followOnLocking = getBooleanWrapper( HibernateHints.HINT_FOLLOW_ON_LOCKING ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ResultSetMappingSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ResultSetMappingSecondPass.java index afd2a95bbb..f322037374 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ResultSetMappingSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ResultSetMappingSecondPass.java @@ -12,7 +12,6 @@ import org.hibernate.MappingException; import org.hibernate.boot.query.SqlResultSetMappingDescriptor; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.mapping.PersistentClass; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.SqlResultSetMapping; @@ -22,11 +21,11 @@ import jakarta.persistence.SqlResultSetMapping; public class ResultSetMappingSecondPass implements QuerySecondPass { // private static final CoreMessageLogger LOG = CoreLogging.messageLogger( ResultsetMappingSecondPass.class ); - private final AnnotationUsage annotation; + private final SqlResultSetMapping annotation; private final MetadataBuildingContext context; private final boolean isDefault; - public ResultSetMappingSecondPass(AnnotationUsage annotation, MetadataBuildingContext context, boolean isDefault) { + public ResultSetMappingSecondPass(SqlResultSetMapping annotation, MetadataBuildingContext context, boolean isDefault) { this.annotation = annotation; this.context = context; this.isDefault = isDefault; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java index da67beff09..84aef1becc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java @@ -13,7 +13,6 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Set; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.usertype.UserCollectionType; @@ -38,7 +37,7 @@ public class SetBinder extends CollectionBinder { } @Override - public void setSqlOrderBy(AnnotationUsage orderByAnn) { + public void setSqlOrderBy(OrderBy orderByAnn) { if ( orderByAnn != null ) { super.setSqlOrderBy( orderByAnn ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java index cd37fd7451..a075a20979 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java @@ -21,7 +21,6 @@ import org.hibernate.metamodel.mapping.SoftDeletableModelPart; import org.hibernate.metamodel.mapping.SoftDeleteMapping; import org.hibernate.metamodel.mapping.internal.MappingModelCreationProcess; import org.hibernate.metamodel.mapping.internal.SoftDeleteMappingImpl; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.sql.ast.spi.SqlExpressionResolver; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; @@ -45,19 +44,18 @@ public class SoftDeleteHelper { /** * Creates and binds the column and value for modeling the soft-delete in the database * - * @param softDeleteConfigAnnotation The SoftDelete annotation + * @param softDeleteConfig The SoftDelete annotation * @param target The thing which is to be soft-deleted * @param table The table to which the soft-delete should be applied * @param context The processing context for access to needed info and services */ public static void bindSoftDeleteIndicator( - AnnotationUsage softDeleteConfigAnnotation, + SoftDelete softDeleteConfig, SoftDeletable target, Table table, MetadataBuildingContext context) { - assert softDeleteConfigAnnotation != null; + assert softDeleteConfig != null; - final SoftDelete softDeleteConfig = softDeleteConfigAnnotation.toAnnotation(); final BasicValue softDeleteIndicatorValue = createSoftDeleteIndicatorValue( softDeleteConfig, table, context ); final Column softDeleteIndicatorColumn = createSoftDeleteIndicatorColumn( softDeleteConfig, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java index 9a165dd14f..7789eb5cba 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java @@ -40,7 +40,6 @@ import org.hibernate.mapping.SortableValue; import org.hibernate.mapping.Table; import org.hibernate.mapping.ToOne; import org.hibernate.mapping.Value; -import org.hibernate.models.spi.AnnotationUsage; import org.jboss.logging.Logger; @@ -76,8 +75,8 @@ public class TableBinder { private String associatedEntity; private String associatedJpaEntity; private boolean isJPA2ElementCollection; - private List> uniqueConstraints; - private List> indexes; + private UniqueConstraint[] uniqueConstraints; + private Index[] indexes; private String options; public void setBuildingContext(MetadataBuildingContext buildingContext) { @@ -104,11 +103,11 @@ public class TableBinder { isAbstract = anAbstract; } - public void setUniqueConstraints(List> uniqueConstraints) { + public void setUniqueConstraints(UniqueConstraint[] uniqueConstraints) { this.uniqueConstraints = uniqueConstraints; } - public void setJpaIndex(List> indexes){ + public void setJpaIndex(Index[] indexes){ this.indexes = indexes; } @@ -441,7 +440,7 @@ public class TableBinder { String catalog, Identifier logicalName, boolean isAbstract, - List> uniqueConstraints, + UniqueConstraint[] uniqueConstraints, MetadataBuildingContext buildingContext) { return buildAndFillTable( schema, @@ -462,7 +461,7 @@ public class TableBinder { String catalog, Identifier logicalName, boolean isAbstract, - List> uniqueConstraints, + UniqueConstraint[] uniqueConstraints, MetadataBuildingContext buildingContext, String subselect, InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) { @@ -485,8 +484,8 @@ public class TableBinder { String catalog, Identifier logicalName, boolean isAbstract, - List> uniqueConstraints, - List> indexes, + UniqueConstraint[] uniqueConstraints, + Index[] indexes, String options, MetadataBuildingContext buildingContext, String subselect, @@ -863,10 +862,10 @@ public class TableBinder { } } - static void addIndexes(Table table, List> indexes, MetadataBuildingContext context) { - for ( AnnotationUsage indexUsage : indexes ) { - final String name = indexUsage.getString( "name" ); - final String[] columnNames = indexUsage.getList( "columnNames" ).toArray(new String[0]); + static void addIndexes(Table table, org.hibernate.annotations.Index[] indexes, MetadataBuildingContext context) { + for ( org.hibernate.annotations.Index indexUsage : indexes ) { + final String name = indexUsage.name(); + final String[] columnNames = indexUsage.columnNames(); //no need to handle inSecondPass here since it is only called from EntityBinder context.getMetadataCollector().addSecondPass( new IndexOrUniqueKeySecondPass( @@ -880,21 +879,21 @@ public class TableBinder { static void addJpaIndexes( Table table, - List> indexes, + jakarta.persistence.Index[] indexes, MetadataBuildingContext context) { new IndexBinder( context ).bindIndexes( table, indexes ); } static void addTableCheck( Table table, - List> checkConstraintAnnotationUsages) { + jakarta.persistence.CheckConstraint[] checkConstraintAnnotationUsages) { if ( CollectionHelper.isNotEmpty( checkConstraintAnnotationUsages ) ) { - for ( AnnotationUsage checkConstraintAnnotationUsage : checkConstraintAnnotationUsages ) { + for ( jakarta.persistence.CheckConstraint checkConstraintAnnotationUsage : checkConstraintAnnotationUsages ) { table.addCheck( new CheckConstraint( - checkConstraintAnnotationUsage.getString( "name" ), - checkConstraintAnnotationUsage.getString( "constraint" ), - checkConstraintAnnotationUsage.getString( "options" ) + checkConstraintAnnotationUsage.name(), + checkConstraintAnnotationUsage.constraint(), + checkConstraintAnnotationUsage.options() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TimeZoneStorageHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TimeZoneStorageHelper.java index bd844aaa96..3b2b780c88 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TimeZoneStorageHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TimeZoneStorageHelper.java @@ -11,10 +11,8 @@ import java.time.OffsetTime; import java.time.ZonedDateTime; import org.hibernate.annotations.TimeZoneStorage; -import org.hibernate.annotations.TimeZoneStorageType; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.TypeDetails; @@ -78,7 +76,7 @@ public class TimeZoneStorageHelper { } static boolean useColumnForTimeZoneStorage(AnnotationTarget element, MetadataBuildingContext context) { - final AnnotationUsage timeZoneStorage = element.getAnnotationUsage( TimeZoneStorage.class ); + final TimeZoneStorage timeZoneStorage = element.getDirectAnnotationUsage( TimeZoneStorage.class ); if ( timeZoneStorage == null ) { if ( element instanceof MemberDetails attributeMember ) { return isTemporalWithTimeZoneClass( attributeMember.getType().getName() ) @@ -90,7 +88,7 @@ public class TimeZoneStorageHelper { } } else { - return switch ( timeZoneStorage.getEnum( "value", TimeZoneStorageType.class ) ) { + return switch ( timeZoneStorage.value() ) { case COLUMN -> true; // if the db has native support for timezones, we use that, not a column case AUTO -> context.getBuildingOptions().getTimeZoneSupport() != NATIVE; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java index 0c64104a59..59d6b6aa53 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java @@ -9,7 +9,6 @@ package org.hibernate.boot.model.internal; import java.util.ArrayList; import java.util.List; -import jakarta.persistence.Entity; import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.FetchMode; @@ -32,11 +31,12 @@ import org.hibernate.mapping.Join; import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.ToOne; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import jakarta.persistence.Column; +import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.ForeignKey; import jakarta.persistence.Id; @@ -83,11 +83,11 @@ public class ToOneBinder { MemberDetails property, AnnotatedJoinColumns joinColumns, PropertyBinder propertyBinder) { - final AnnotationUsage manyToOne = property.getAnnotationUsage( ManyToOne.class ); + final ManyToOne manyToOne = property.getDirectAnnotationUsage( ManyToOne.class ); //check validity - if ( property.hasAnnotationUsage( Column.class ) - || property.hasAnnotationUsage( Columns.class ) ) { + if ( property.hasDirectAnnotationUsage( Column.class ) + || property.hasDirectAnnotationUsage( Columns.class ) ) { throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData ) + "' is a '@ManyToOne' association and may not use '@Column' to specify column mappings (use '@JoinColumn' instead)" @@ -101,19 +101,19 @@ public class ToOneBinder { ); } - final AnnotationUsage hibernateCascade = property.getAnnotationUsage( Cascade.class ); - final AnnotationUsage notFound = property.getAnnotationUsage( NotFound.class ); - final NotFoundAction notFoundAction = notFound == null ? null : notFound.getEnum( "action" ); - matchIgnoreNotFoundWithFetchType( propertyHolder.getEntityName(), property.getName(), notFoundAction, manyToOne.getEnum( "fetch" ) ); - final AnnotationUsage onDelete = property.getAnnotationUsage( OnDelete.class ); - final AnnotationUsage joinTable = propertyHolder.getJoinTable( property ); + final Cascade hibernateCascade = property.getDirectAnnotationUsage( Cascade.class ); + final NotFound notFound = property.getDirectAnnotationUsage( NotFound.class ); + final NotFoundAction notFoundAction = notFound == null ? null : notFound.action(); + matchIgnoreNotFoundWithFetchType( propertyHolder.getEntityName(), property.getName(), notFoundAction, manyToOne.fetch() ); + final OnDelete onDelete = property.getDirectAnnotationUsage( OnDelete.class ); + final JoinTable joinTable = propertyHolder.getJoinTable( property ); bindManyToOne( - getCascadeStrategy( manyToOne.getList( "cascade" ), hibernateCascade, false, context ), + getCascadeStrategy( manyToOne.cascade(), hibernateCascade, false, context ), joinColumns, joinTable, - !isMandatory( manyToOne.getBoolean( "optional" ), property, notFoundAction ), + !isMandatory( manyToOne.optional(), property, notFoundAction ), notFoundAction, - onDelete == null ? null : onDelete.getEnum( "action" ), + onDelete == null ? null : onDelete.action(), getTargetEntity( inferredData, context ), propertyHolder, inferredData, @@ -144,14 +144,14 @@ public class ToOneBinder { // the association is optional. // @OneToOne(optional = true) with @PKJC makes the association optional. return !optional - || property.hasAnnotationUsage( Id.class ) - || property.hasAnnotationUsage( MapsId.class ) && notFoundAction != NotFoundAction.IGNORE; + || property.hasDirectAnnotationUsage( Id.class ) + || property.hasDirectAnnotationUsage( MapsId.class ) && notFoundAction != NotFoundAction.IGNORE; } private static void bindManyToOne( String cascadeStrategy, AnnotatedJoinColumns joinColumns, - AnnotationUsage joinTable, + JoinTable joinTable, boolean optional, NotFoundAction notFoundAction, OnDeleteAction onDeleteAction, @@ -163,7 +163,7 @@ public class ToOneBinder { boolean inSecondPass, PropertyBinder propertyBinder, MetadataBuildingContext context) { - if ( joinTable != null && !isEmpty( joinTable.getString( "name" ) ) ) { + if ( joinTable != null && !isEmpty( joinTable.name() ) ) { final Join join = propertyHolder.addJoin( joinTable, false ); // TODO: if notFoundAction!=null should we call join.disableForeignKeyCreation() ? for ( AnnotatedJoinColumn joinColumn : joinColumns.getJoinColumns() ) { @@ -178,7 +178,7 @@ public class ToOneBinder { final org.hibernate.mapping.ManyToOne value = new org.hibernate.mapping.ManyToOne( context, joinColumns.getTable() ); - if ( joinTable != null && isEmpty( joinTable.getString( "name" ) ) ) { + if ( joinTable != null && isEmpty( joinTable.name() ) ) { context.getMetadataCollector().addSecondPass( new ImplicitToOneJoinTableSecondPass( propertyHolder, inferredData, @@ -207,15 +207,15 @@ public class ToOneBinder { } } - if ( property.hasAnnotationUsage( MapsId.class ) ) { - final AnnotationUsage mapsId = property.getAnnotationUsage( MapsId.class ); + if ( property.hasDirectAnnotationUsage( MapsId.class ) ) { + final MapsId mapsId = property.getDirectAnnotationUsage( MapsId.class ); final List joinColumnList = joinColumns.getJoinColumns(); //read only for ( AnnotatedJoinColumn column : joinColumnList ) { column.setInsertable( false ); column.setUpdatable( false ); } - joinColumns.setMapsId( mapsId.getString( "value" ) ); + joinColumns.setMapsId( mapsId.value() ); } final boolean hasSpecjManyToOne = handleSpecjSyntax( joinColumns, inferredData, context, property ); @@ -259,7 +259,7 @@ public class ToOneBinder { static boolean isTargetAnnotatedEntity(ClassDetails targetEntity, MemberDetails property, MetadataBuildingContext context) { final ClassDetails target = isDefault( targetEntity, context ) ? property.getType().determineRawClass() : targetEntity; - return target.hasAnnotationUsage( Entity.class ); + return target.hasDirectAnnotationUsage( Entity.class ); } private static boolean handleSpecjSyntax( @@ -270,18 +270,18 @@ public class ToOneBinder { //Make sure that JPA1 key-many-to-one columns are read only too boolean hasSpecjManyToOne = false; if ( context.getBuildingOptions().isSpecjProprietarySyntaxEnabled() ) { - final AnnotationUsage joinColumn = property.getAnnotationUsage( JoinColumn.class ); + final JoinColumn joinColumn = property.getDirectAnnotationUsage( JoinColumn.class ); String columnName = ""; for ( MemberDetails prop : inferredData.getDeclaringClass().getFields() ) { - if ( prop.hasAnnotationUsage( Id.class ) && prop.hasAnnotationUsage( Column.class ) ) { - columnName = prop.getAnnotationUsage( Column.class ).getString( "name" ); + if ( prop.hasDirectAnnotationUsage( Id.class ) && prop.hasDirectAnnotationUsage( Column.class ) ) { + columnName = prop.getDirectAnnotationUsage( Column.class ).name(); } - if ( property.hasAnnotationUsage( ManyToOne.class ) && joinColumn != null ) { - final String joinColumnName = joinColumn.getString( "name" ); + if ( property.hasDirectAnnotationUsage( ManyToOne.class ) && joinColumn != null ) { + final String joinColumnName = joinColumn.name(); if ( StringHelper.isNotEmpty( joinColumnName ) && joinColumnName.equals( columnName ) - && !property.hasAnnotationUsage( MapsId.class ) ) { + && !property.hasDirectAnnotationUsage( MapsId.class ) ) { hasSpecjManyToOne = true; for ( AnnotatedJoinColumn column : columns.getJoinColumns() ) { column.setInsertable( false ); @@ -326,19 +326,19 @@ public class ToOneBinder { propertyBinder.setMemberDetails( property ); propertyBinder.setToMany( true ); - final AnnotationUsage joinColumn = property.getSingleAnnotationUsage( JoinColumn.class ); - final AnnotationUsage joinColumns = property.getAnnotationUsage( JoinColumns.class ); + final JoinColumn joinColumn = property.getDirectAnnotationUsage( JoinColumn.class ); + final JoinColumns joinColumns = property.getDirectAnnotationUsage( JoinColumns.class ); propertyBinder.makePropertyAndBind().setOptional( optional && isNullable( joinColumns, joinColumn ) ); } - private static boolean isNullable(AnnotationUsage joinColumns, AnnotationUsage joinColumn) { + private static boolean isNullable(JoinColumns joinColumns, JoinColumn joinColumn) { if ( joinColumn != null ) { - return joinColumn.getBoolean( "nullable" ); + return joinColumn.nullable(); } if ( joinColumns != null ) { - for ( AnnotationUsage column : joinColumns.>getList( "value" ) ) { - if ( column.getBoolean( "nullable" ) ) { + for ( JoinColumn column : joinColumns.value() ) { + if ( column.nullable() ) { return true; } } @@ -359,7 +359,7 @@ public class ToOneBinder { } private static void handleLazy(ToOne toOne, MemberDetails property, PropertyData inferredData, PropertyHolder propertyHolder) { - if ( property.hasAnnotationUsage( NotFound.class ) ) { + if ( property.hasDirectAnnotationUsage( NotFound.class ) ) { toOne.setLazy( false ); toOne.setUnwrapProxy( true ); } @@ -378,16 +378,17 @@ public class ToOneBinder { PropertyData inferredData) { final MetadataBuildingContext context = toOne.getBuildingContext(); final InFlightMetadataCollector collector = context.getMetadataCollector(); - property.forEachAnnotationUsage( FetchProfileOverride.class, (usage) -> { + final SourceModelBuildingContext sourceModelContext = collector.getSourceModelBuildingContext(); + property.forEachAnnotationUsage( FetchProfileOverride.class, sourceModelContext, (usage) -> { collector.addSecondPass( new FetchSecondPass( usage, propertyHolder, inferredData.getPropertyName(), context ) ); } ); } private static void handleFetch(ToOne toOne, MemberDetails property) { - final AnnotationUsage fetchAnnotationUsage = property.getAnnotationUsage( Fetch.class ); + final Fetch fetchAnnotationUsage = property.getDirectAnnotationUsage( Fetch.class ); if ( fetchAnnotationUsage != null ) { // Hibernate @Fetch annotation takes precedence - setHibernateFetchMode( toOne, property, fetchAnnotationUsage.getEnum( "value" ) ); + setHibernateFetchMode( toOne, property, fetchAnnotationUsage.value() ); } else { toOne.setFetchMode( getFetchMode( getJpaFetchType( property ) ) ); @@ -415,9 +416,9 @@ public class ToOneBinder { private static boolean isEager(MemberDetails property, PropertyData inferredData, PropertyHolder propertyHolder) { final FetchType fetchType = getJpaFetchType( property ); - final AnnotationUsage lazyToOneAnnotationUsage = property.getAnnotationUsage( LazyToOne.class ); + final LazyToOne lazyToOneAnnotationUsage = property.getDirectAnnotationUsage( LazyToOne.class ); if ( lazyToOneAnnotationUsage != null ) { - final LazyToOneOption option = lazyToOneAnnotationUsage.getEnum( "value" ); + final LazyToOneOption option = lazyToOneAnnotationUsage.value(); boolean eager = option == LazyToOneOption.FALSE; if ( eager && fetchType == LAZY ) { // conflicts with non-default setting @@ -432,13 +433,13 @@ public class ToOneBinder { } private static FetchType getJpaFetchType(MemberDetails property) { - final AnnotationUsage manyToOne = property.getAnnotationUsage( ManyToOne.class ); - final AnnotationUsage oneToOne = property.getAnnotationUsage( OneToOne.class ); + final ManyToOne manyToOne = property.getDirectAnnotationUsage( ManyToOne.class ); + final OneToOne oneToOne = property.getDirectAnnotationUsage( OneToOne.class ); if ( manyToOne != null ) { - return manyToOne.getEnum( "fetch" ); + return manyToOne.fetch(); } else if ( oneToOne != null ) { - return oneToOne.getEnum( "fetch" ); + return oneToOne.fetch(); } else { throw new AssertionFailure("Define fetch strategy on a property not annotated with @OneToMany nor @OneToOne"); @@ -454,11 +455,11 @@ public class ToOneBinder { MemberDetails property, AnnotatedJoinColumns joinColumns, PropertyBinder propertyBinder) { - final AnnotationUsage oneToOne = property.getAnnotationUsage( OneToOne.class ); + final OneToOne oneToOne = property.getDirectAnnotationUsage( OneToOne.class ); //check validity - if ( property.hasAnnotationUsage( Column.class ) - || property.hasAnnotationUsage( Columns.class ) ) { + if ( property.hasDirectAnnotationUsage( Column.class ) + || property.hasDirectAnnotationUsage( Columns.class ) ) { throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData ) + "' is a '@OneToOne' association and may not use '@Column' to specify column mappings" @@ -474,28 +475,28 @@ public class ToOneBinder { } //FIXME support a proper PKJCs - final boolean trueOneToOne = property.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) - || property.hasAnnotationUsage( PrimaryKeyJoinColumns.class ); - final AnnotationUsage hibernateCascade = property.getAnnotationUsage( Cascade.class ); - final AnnotationUsage notFound = property.getAnnotationUsage( NotFound.class ); - final NotFoundAction notFoundAction = notFound == null ? null : notFound.getEnum( "action" ); + final boolean trueOneToOne = property.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) + || property.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ); + final Cascade hibernateCascade = property.getDirectAnnotationUsage( Cascade.class ); + final NotFound notFound = property.getDirectAnnotationUsage( NotFound.class ); + final NotFoundAction notFoundAction = notFound == null ? null : notFound.action(); - matchIgnoreNotFoundWithFetchType( propertyHolder.getEntityName(), property.getName(), notFoundAction, oneToOne.getEnum( "fetch" ) ); - final AnnotationUsage onDelete = property.getAnnotationUsage( OnDelete.class ); - final AnnotationUsage joinTable = propertyHolder.getJoinTable( property ); + matchIgnoreNotFoundWithFetchType( propertyHolder.getEntityName(), property.getName(), notFoundAction, oneToOne.fetch() ); + final OnDelete onDelete = property.getDirectAnnotationUsage( OnDelete.class ); + final JoinTable joinTable = propertyHolder.getJoinTable( property ); bindOneToOne( - getCascadeStrategy( oneToOne.getList( "cascade" ), hibernateCascade, oneToOne.getBoolean( "orphanRemoval" ), context ), + getCascadeStrategy( oneToOne.cascade(), hibernateCascade, oneToOne.orphanRemoval(), context ), joinColumns, joinTable, - !isMandatory( oneToOne.getBoolean( "optional" ), property, notFoundAction ), - getFetchMode( oneToOne.getEnum( "fetch" ) ), + !isMandatory( oneToOne.optional(), property, notFoundAction ), + getFetchMode( oneToOne.fetch() ), notFoundAction, - onDelete == null ? null : onDelete.getEnum( "action" ), + onDelete == null ? null : onDelete.action(), getTargetEntity( inferredData, context ), property, propertyHolder, inferredData, - nullIfEmpty( oneToOne.getString( "mappedBy" ) ), + nullIfEmpty( oneToOne.mappedBy() ), trueOneToOne, isIdentifierMapper, inSecondPass, @@ -507,7 +508,7 @@ public class ToOneBinder { private static void bindOneToOne( String cascadeStrategy, AnnotatedJoinColumns joinColumns, - AnnotationUsage joinTable, + JoinTable joinTable, boolean optional, FetchMode fetchMode, NotFoundAction notFoundAction, @@ -606,46 +607,46 @@ public class ToOneBinder { public static void bindForeignKeyNameAndDefinition( SimpleValue value, MemberDetails property, - AnnotationUsage foreignKey, + ForeignKey foreignKey, MetadataBuildingContext context) { - if ( property.hasAnnotationUsage( NotFound.class ) ) { + if ( property.hasDirectAnnotationUsage( NotFound.class ) ) { // supersedes all others value.disableForeignKey(); } else { - final AnnotationUsage joinColumn = property.getSingleAnnotationUsage( JoinColumn.class ); - final AnnotationUsage joinColumns = property.getAnnotationUsage( JoinColumns.class ); + final JoinColumn joinColumn = property.getDirectAnnotationUsage( JoinColumn.class ); + final JoinColumns joinColumns = property.getDirectAnnotationUsage( JoinColumns.class ); final boolean noConstraintByDefault = context.getBuildingOptions().isNoConstraintByDefault(); - if ( joinColumn != null && noConstraint( joinColumn.getNestedUsage( "foreignKey" ), noConstraintByDefault ) - || joinColumns != null && noConstraint( joinColumns.getNestedUsage( "foreignKey" ), noConstraintByDefault ) ) { + if ( joinColumn != null && noConstraint( joinColumn.foreignKey(), noConstraintByDefault ) + || joinColumns != null && noConstraint( joinColumns.foreignKey(), noConstraintByDefault ) ) { value.disableForeignKey(); } else { - final AnnotationUsage fk = - property.getAnnotationUsage( org.hibernate.annotations.ForeignKey.class ); - if ( fk != null && isNotEmpty( fk.getString( "name" ) ) ) { - value.setForeignKeyName( fk.getString( "name" ) ); + final org.hibernate.annotations.ForeignKey fk = + property.getDirectAnnotationUsage( org.hibernate.annotations.ForeignKey.class ); + if ( fk != null && isNotEmpty( fk.name() ) ) { + value.setForeignKeyName( fk.name() ); } else { if ( noConstraint( foreignKey, noConstraintByDefault ) ) { value.disableForeignKey(); } else if ( foreignKey != null ) { - value.setForeignKeyName( nullIfEmpty( foreignKey.getString( "name" ) ) ); - value.setForeignKeyDefinition( nullIfEmpty( foreignKey.getString( "foreignKeyDefinition" ) ) ); + value.setForeignKeyName( nullIfEmpty( foreignKey.name() ) ); + value.setForeignKeyDefinition( nullIfEmpty( foreignKey.foreignKeyDefinition() ) ); } else if ( noConstraintByDefault ) { value.disableForeignKey(); } else if ( joinColumns != null ) { - final AnnotationUsage joinColumnsForeignKey = joinColumns.getNestedUsage( "foreignKey" ); - value.setForeignKeyName( nullIfEmpty( joinColumnsForeignKey.getString( "name" ) ) ); - value.setForeignKeyDefinition( nullIfEmpty( joinColumnsForeignKey.getString( "foreignKeyDefinition" ) ) ); + final ForeignKey joinColumnsForeignKey = joinColumns.foreignKey(); + value.setForeignKeyName( nullIfEmpty( joinColumnsForeignKey.name() ) ); + value.setForeignKeyDefinition( nullIfEmpty( joinColumnsForeignKey.foreignKeyDefinition() ) ); } else if ( joinColumn != null ) { - final AnnotationUsage joinColumnForeignKey = joinColumn.getNestedUsage( "foreignKey" ); - value.setForeignKeyName( nullIfEmpty( joinColumnForeignKey.getString( "name" ) ) ); - value.setForeignKeyDefinition( nullIfEmpty( joinColumnForeignKey.getString( "foreignKeyDefinition" ) ) ); + final ForeignKey joinColumnForeignKey = joinColumn.foreignKey(); + value.setForeignKeyName( nullIfEmpty( joinColumnForeignKey.name() ) ); + value.setForeignKeyDefinition( nullIfEmpty( joinColumnForeignKey.foreignKeyDefinition() ) ); } } } @@ -663,17 +664,18 @@ public class ToOneBinder { } public static ClassDetails getTargetEntity(PropertyData propertyData, MetadataBuildingContext context) { - return getTargetEntityClass( propertyData.getAttributeMember() ); + return getTargetEntityClass( propertyData.getAttributeMember(), context ); } - private static ClassDetails getTargetEntityClass(MemberDetails property) { - final AnnotationUsage manyToOne = property.getAnnotationUsage( ManyToOne.class ); + private static ClassDetails getTargetEntityClass(MemberDetails property, MetadataBuildingContext context) { + final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + final ManyToOne manyToOne = property.getDirectAnnotationUsage( ManyToOne.class ); if ( manyToOne != null ) { - return manyToOne.getClassDetails( "targetEntity" ); + return sourceModelContext.getClassDetailsRegistry().resolveClassDetails( manyToOne.targetEntity().getName() ); } - final AnnotationUsage oneToOne = property.getAnnotationUsage( OneToOne.class ); + final OneToOne oneToOne = property.getDirectAnnotationUsage( OneToOne.class ); if ( oneToOne != null ) { - return oneToOne.getClassDetails( "targetEntity" ); + return sourceModelContext.getClassDetailsRegistry().resolveClassDetails( oneToOne.targetEntity().getName() ); } throw new AssertionFailure( "Unexpected discovery of a targetEntity: " + property.getName() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java index a8f8fe74aa..3c412de80c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java @@ -50,8 +50,8 @@ import org.hibernate.boot.model.source.internal.hbm.HbmMetadataSourceProcessorIm import org.hibernate.boot.model.source.internal.hbm.MappingDocument; import org.hibernate.boot.model.source.internal.hbm.ModelBinder; import org.hibernate.boot.model.source.spi.MetadataSourceProcessor; -import org.hibernate.boot.models.categorize.internal.DomainModelCategorizationCollector; -import org.hibernate.boot.models.categorize.internal.OrmAnnotationHelper; +import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; +import org.hibernate.boot.models.internal.OrmAnnotationHelper; import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult; import org.hibernate.boot.models.xml.spi.XmlPreProcessor; import org.hibernate.boot.models.xml.spi.XmlProcessingResult; @@ -551,7 +551,7 @@ public class MetadataBuildingProcess { //noinspection unchecked annotationDescriptorRegistry.resolveDescriptor( annotationClass, - (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext.getAnnotationDescriptorRegistry() ) + (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java index a22b6dd35f..494d0e71bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java @@ -13,9 +13,7 @@ import java.util.Map; import java.util.Set; import org.hibernate.boot.internal.MetadataBuildingContextRootImpl; -import org.hibernate.boot.jaxb.Origin; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; -import org.hibernate.boot.jaxb.spi.Binding; import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor; import org.hibernate.boot.model.convert.spi.ConverterRegistry; import org.hibernate.boot.model.convert.spi.RegisteredConversion; @@ -24,7 +22,7 @@ import org.hibernate.boot.model.internal.InheritanceState; import org.hibernate.boot.model.process.spi.ManagedResources; import org.hibernate.boot.model.process.spi.MetadataBuildingProcess; import org.hibernate.boot.model.source.spi.MetadataSourceProcessor; -import org.hibernate.boot.models.categorize.spi.FilterDefRegistration; +import org.hibernate.boot.models.spi.FilterDefRegistration; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.JpaOrmXmlPersistenceUnitDefaultAware; import org.hibernate.boot.spi.MetadataBuildingOptions; @@ -36,10 +34,6 @@ import org.jboss.logging.Logger; import jakarta.persistence.Entity; import jakarta.persistence.MappedSuperclass; -import static org.hibernate.boot.jaxb.SourceType.OTHER; -import static org.hibernate.models.spi.ClassDetails.VOID_CLASS_DETAILS; -import static org.hibernate.models.spi.ClassDetails.VOID_OBJECT_CLASS_DETAILS; - /** * @author Steve Ebersole */ @@ -75,15 +69,16 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc final ConverterRegistry converterRegistry = rootMetadataBuildingContext.getMetadataCollector().getConverterRegistry(); domainModelSource.getConversionRegistrations().forEach( (registration) -> { final Class domainType; - if ( registration.getExplicitDomainType() == VOID_CLASS_DETAILS || registration.getExplicitDomainType() == VOID_OBJECT_CLASS_DETAILS ) { + if ( registration.getExplicitDomainType() == void.class + || registration.getExplicitDomainType() == Void.class ) { domainType = void.class; } else { - domainType = classLoaderService.classForName( registration.getExplicitDomainType().getClassName() ); + domainType = registration.getExplicitDomainType(); } converterRegistry.addRegisteredConversion( new RegisteredConversion( domainType, - classLoaderService.classForName( registration.getConverterType().getClassName() ), + registration.getConverterType(), registration.isAutoApply(), rootMetadataBuildingContext ) ); @@ -234,7 +229,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc List clazzHierarchy = new ArrayList<>(); for ( ClassDetails clazz : classes ) { - if ( clazz.hasAnnotationUsage( MappedSuperclass.class ) ) { + if ( clazz.hasDirectAnnotationUsage( MappedSuperclass.class ) ) { if ( debug ) { log.debugf( "Skipping explicit MappedSuperclass %s, the class will be discovered analyzing the implementing class", @@ -253,8 +248,8 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc ClassDetails superClass = clazz.getSuperClass(); while ( superClass != null && !Object.class.getName().equals( superClass.getName() ) ) { - if ( superClass.hasAnnotationUsage( Entity.class ) - || superClass.hasAnnotationUsage( MappedSuperclass.class ) ) { + if ( superClass.hasDirectAnnotationUsage( Entity.class ) + || superClass.hasDirectAnnotationUsage( MappedSuperclass.class ) ) { if ( orderedClasses.contains( superClass ) ) { break; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/DomainModelSource.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/DomainModelSource.java index cbe560a19d..419b6d3810 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/DomainModelSource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/DomainModelSource.java @@ -10,9 +10,9 @@ import java.util.List; import java.util.Set; import org.hibernate.boot.internal.RootMappingDefaults; -import org.hibernate.boot.models.categorize.spi.ConversionRegistration; -import org.hibernate.boot.models.categorize.spi.ConverterRegistration; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; +import org.hibernate.boot.models.spi.ConversionRegistration; +import org.hibernate.boot.models.spi.ConverterRegistration; +import org.hibernate.boot.models.spi.GlobalRegistrations; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; import org.hibernate.models.spi.ClassDetailsRegistry; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/DialectOverrideAnnotations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/DialectOverrideAnnotations.java new file mode 100644 index 0000000000..723f6c437f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/DialectOverrideAnnotations.java @@ -0,0 +1,229 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models; + +import java.util.function.Consumer; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.FetchProfileOverride; +import org.hibernate.annotations.FetchProfileOverrides; +import org.hibernate.boot.models.annotations.internal.FetchProfileOverrideAnnotation; +import org.hibernate.boot.models.annotations.internal.FetchProfileOverridesAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenCheckAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenChecksAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenColumnDefaultAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenColumnDefaultsAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenDiscriminatorFormulaAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenDiscriminatorFormulasAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenFilterDefOverridesAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenFilterDefsAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenFilterOverridesAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenFiltersAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenFormulaAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenFormulasAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenGeneratedColumnAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenGeneratedColumnsAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenJoinFormulaAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenJoinFormulasAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenOrderByAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenOrderBysAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLDeleteAllAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLDeleteAllsAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLDeleteAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLDeletesAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLInsertAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLInsertsAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLOrderAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLOrdersAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLRestrictionAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLRestrictionsAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLSelectAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLSelectsAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLUpdateAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenSQLUpdatesAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenWhereAnnotation; +import org.hibernate.boot.models.annotations.internal.OverriddenWheresAnnotation; +import org.hibernate.boot.models.annotations.internal.OverrideVersionAnnotation; +import org.hibernate.boot.models.internal.OrmAnnotationHelper; +import org.hibernate.models.internal.OrmAnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptor; + +/** + * @author Steve Ebersole + */ +public interface DialectOverrideAnnotations { + OrmAnnotationDescriptor DIALECT_OVERRIDE_CHECKS = new OrmAnnotationDescriptor<>( + DialectOverride.Checks.class, + OverriddenChecksAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_CHECK = new OrmAnnotationDescriptor<>( + DialectOverride.Check.class, + OverriddenCheckAnnotation.class, + DIALECT_OVERRIDE_CHECKS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_ORDER_BYS = new OrmAnnotationDescriptor<>( + DialectOverride.OrderBys.class, + OverriddenOrderBysAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_ORDER_BY = new OrmAnnotationDescriptor<>( + DialectOverride.OrderBy.class, + OverriddenOrderByAnnotation.class, + DIALECT_OVERRIDE_ORDER_BYS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_COLUMN_DEFAULTS = new OrmAnnotationDescriptor<>( + DialectOverride.ColumnDefaults.class, + OverriddenColumnDefaultsAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_COLUMN_DEFAULT = new OrmAnnotationDescriptor<>( + DialectOverride.ColumnDefault.class, + OverriddenColumnDefaultAnnotation.class, + DIALECT_OVERRIDE_COLUMN_DEFAULTS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_GENERATED_COLUMNS = new OrmAnnotationDescriptor<>( + DialectOverride.GeneratedColumns.class, + OverriddenGeneratedColumnsAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_GENERATED_COLUMN = new OrmAnnotationDescriptor<>( + DialectOverride.GeneratedColumn.class, + OverriddenGeneratedColumnAnnotation.class, + DIALECT_OVERRIDE_GENERATED_COLUMNS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_DISCRIMINATOR_FORMULAS = new OrmAnnotationDescriptor<>( + DialectOverride.DiscriminatorFormulas.class, + OverriddenDiscriminatorFormulasAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_DISCRIMINATOR_FORMULA = new OrmAnnotationDescriptor<>( + DialectOverride.DiscriminatorFormula.class, + OverriddenDiscriminatorFormulaAnnotation.class, + DIALECT_OVERRIDE_DISCRIMINATOR_FORMULAS + ); + OrmAnnotationDescriptor FETCH_PROFILE_OVERRIDES = new OrmAnnotationDescriptor<>( + FetchProfileOverrides.class, + FetchProfileOverridesAnnotation.class + ); + OrmAnnotationDescriptor FETCH_PROFILE_OVERRIDE = new OrmAnnotationDescriptor<>( + FetchProfileOverride.class, + FetchProfileOverrideAnnotation.class, + FETCH_PROFILE_OVERRIDES + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_FILTER_OVERRIDES = new OrmAnnotationDescriptor<>( + DialectOverride.FilterOverrides.class, + OverriddenFilterOverridesAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_FILTERS = new OrmAnnotationDescriptor( + DialectOverride.Filters.class, + OverriddenFiltersAnnotation.class, + DIALECT_OVERRIDE_FILTER_OVERRIDES + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES = new OrmAnnotationDescriptor<>( + DialectOverride.FilterDefOverrides.class, + OverriddenFilterDefOverridesAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_FILTER_DEFS = new OrmAnnotationDescriptor<>( + DialectOverride.FilterDefs.class, + OverriddenFilterDefsAnnotation.class, + DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_FORMULAS = new OrmAnnotationDescriptor<>( + DialectOverride.Formulas.class, + OverriddenFormulasAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_FORMULA = new OrmAnnotationDescriptor<>( + DialectOverride.Formula.class, + OverriddenFormulaAnnotation.class, + DIALECT_OVERRIDE_FORMULAS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_JOIN_FORMULAS = new OrmAnnotationDescriptor<>( + DialectOverride.JoinFormulas.class, + OverriddenJoinFormulasAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_JOIN_FORMULA = new OrmAnnotationDescriptor<>( + DialectOverride.JoinFormula.class, + OverriddenJoinFormulaAnnotation.class, + DIALECT_OVERRIDE_JOIN_FORMULAS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_WHERES = new OrmAnnotationDescriptor<>( + DialectOverride.Wheres.class, + OverriddenWheresAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_WHERE = new OrmAnnotationDescriptor<>( + DialectOverride.Where.class, + OverriddenWhereAnnotation.class, + DIALECT_OVERRIDE_WHERES + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_INSERTS = new OrmAnnotationDescriptor<>( + DialectOverride.SQLInserts.class, + OverriddenSQLInsertsAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_INSERT = new OrmAnnotationDescriptor<>( + DialectOverride.SQLInsert.class, + OverriddenSQLInsertAnnotation.class, + DIALECT_OVERRIDE_SQL_INSERTS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_UPDATES = new OrmAnnotationDescriptor<>( + DialectOverride.SQLUpdates.class, + OverriddenSQLUpdatesAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_UPDATE = new OrmAnnotationDescriptor<>( + DialectOverride.SQLUpdate.class, + OverriddenSQLUpdateAnnotation.class, + DIALECT_OVERRIDE_SQL_UPDATES + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETES = new OrmAnnotationDescriptor<>( + DialectOverride.SQLDeletes.class, + OverriddenSQLDeletesAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETE = new OrmAnnotationDescriptor<>( + DialectOverride.SQLDelete.class, + OverriddenSQLDeleteAnnotation.class, + DIALECT_OVERRIDE_SQL_DELETES + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETE_ALLS = new OrmAnnotationDescriptor<>( + DialectOverride.SQLDeleteAlls.class, + OverriddenSQLDeleteAllsAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETE_ALL = new OrmAnnotationDescriptor<>( + DialectOverride.SQLDeleteAll.class, + OverriddenSQLDeleteAllAnnotation.class, + DIALECT_OVERRIDE_SQL_DELETE_ALLS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_ORDERS = new OrmAnnotationDescriptor<>( + DialectOverride.SQLOrders.class, + OverriddenSQLOrdersAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_ORDER = new OrmAnnotationDescriptor<>( + DialectOverride.SQLOrder.class, + OverriddenSQLOrderAnnotation.class, + DIALECT_OVERRIDE_SQL_ORDERS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_RESTRICTIONS = new OrmAnnotationDescriptor<>( + DialectOverride.SQLRestrictions.class, + OverriddenSQLRestrictionsAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_RESTRICTION = new OrmAnnotationDescriptor<>( + DialectOverride.SQLRestriction.class, + OverriddenSQLRestrictionAnnotation.class, + DIALECT_OVERRIDE_SQL_RESTRICTIONS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_SELECTS = new OrmAnnotationDescriptor<>( + DialectOverride.SQLSelects.class, + OverriddenSQLSelectsAnnotation.class + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_SQL_SELECT = new OrmAnnotationDescriptor<>( + DialectOverride.SQLSelect.class, + OverriddenSQLSelectAnnotation.class, + DIALECT_OVERRIDE_SQL_SELECTS + ); + OrmAnnotationDescriptor DIALECT_OVERRIDE_VERSION = new OrmAnnotationDescriptor<>( + DialectOverride.Version.class, + OverrideVersionAnnotation.class + ); + + static void forEachAnnotation(Consumer> consumer) { + OrmAnnotationHelper.forEachOrmAnnotation( DialectOverrideAnnotations.class, consumer ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java index fdc4b428dd..1e98000379 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java @@ -10,16 +10,12 @@ import java.lang.annotation.Annotation; import java.util.function.Consumer; import org.hibernate.annotations.*; -import org.hibernate.boot.internal.Abstract; import org.hibernate.boot.internal.AnyKeyType; -import org.hibernate.boot.internal.CollectionClassification; -import org.hibernate.boot.internal.Extends; -import org.hibernate.boot.internal.Target; -import org.hibernate.boot.models.categorize.internal.OrmAnnotationHelper; +import org.hibernate.boot.models.annotations.internal.*; +import org.hibernate.boot.models.internal.OrmAnnotationHelper; +import org.hibernate.models.internal.OrmAnnotationDescriptor; import org.hibernate.models.spi.AnnotationDescriptor; -import static org.hibernate.models.internal.AnnotationHelper.createOrmDescriptor; - /** * Details about Hibernate annotations. * @@ -33,186 +29,657 @@ import static org.hibernate.models.internal.AnnotationHelper.createOrmDescriptor */ @SuppressWarnings({ "deprecation", "removal", "unused" }) public interface HibernateAnnotations { - AnnotationDescriptor ANY = createOrmDescriptor( Any.class ); - AnnotationDescriptor ANY_DISCRIMINATOR = createOrmDescriptor( AnyDiscriminator.class ); - AnnotationDescriptor ANY_DISCRIMINATOR_VALUES = createOrmDescriptor( AnyDiscriminatorValues.class ); - AnnotationDescriptor ANY_DISCRIMINATOR_VALUE = createOrmDescriptor( AnyDiscriminatorValue.class, ANY_DISCRIMINATOR_VALUES ); - AnnotationDescriptor ANY_KEY_JAVA_CLASS = createOrmDescriptor( AnyKeyJavaClass.class ); - AnnotationDescriptor ANY_KEY_JAVA_TYPE = createOrmDescriptor( AnyKeyJavaType.class ); - AnnotationDescriptor ANY_KEY_JDBC_TYPE = createOrmDescriptor( AnyKeyJdbcType.class ); - AnnotationDescriptor ANY_KEY_JDBC_TYPE_CODE = createOrmDescriptor( AnyKeyJdbcTypeCode.class ); - AnnotationDescriptor ATTRIBUTE_ACCESSOR = createOrmDescriptor( AttributeAccessor.class ); - AnnotationDescriptor ATTRIBUTE_BINDER_TYPE = createOrmDescriptor( AttributeBinderType.class ); - AnnotationDescriptor BAG = createOrmDescriptor( Bag.class ); - AnnotationDescriptor BATCH_SIZE = createOrmDescriptor( BatchSize.class ); - AnnotationDescriptor CACHE = createOrmDescriptor( Cache.class ); - AnnotationDescriptor CASCADE = createOrmDescriptor( Cascade.class ); - AnnotationDescriptor CHECKS = createOrmDescriptor( Checks.class ); - AnnotationDescriptor CHECK = createOrmDescriptor( Check.class, CHECKS ); - AnnotationDescriptor COLLECTION_ID = createOrmDescriptor( CollectionId.class ); - AnnotationDescriptor COLLECTION_ID_JAVA_TYPE = createOrmDescriptor( CollectionIdJavaType.class ); - AnnotationDescriptor COLLECTION_ID_JDBC_TYPE = createOrmDescriptor( CollectionIdJdbcType.class ); - AnnotationDescriptor COLLECTION_ID_JDBC_TYPE_CODE = createOrmDescriptor( CollectionIdJdbcTypeCode.class ); - AnnotationDescriptor COLLECTION_ID_MUTABILITY = createOrmDescriptor( CollectionIdMutability.class ); - AnnotationDescriptor COLLECTION_ID_TYPE = createOrmDescriptor( CollectionIdType.class ); - AnnotationDescriptor COLLECTION_TYPE = createOrmDescriptor( CollectionType.class ); - AnnotationDescriptor COLLECTION_TYPE_REGS = createOrmDescriptor( CollectionTypeRegistrations.class ); - AnnotationDescriptor COLLECTION_TYPE_REG = createOrmDescriptor( CollectionTypeRegistration.class, COLLECTION_TYPE_REGS ); - AnnotationDescriptor COLUMN_DEFAULT = createOrmDescriptor( ColumnDefault.class ); - AnnotationDescriptor COLUMN_TRANSFORMERS = createOrmDescriptor( ColumnTransformers.class ); - AnnotationDescriptor COLUMN_TRANSFORMER = createOrmDescriptor( ColumnTransformer.class, COLUMN_TRANSFORMERS ); - AnnotationDescriptor COMMENT = createOrmDescriptor( Comment.class ); - AnnotationDescriptor COMPOSITE_TYPE = createOrmDescriptor( CompositeType.class ); - AnnotationDescriptor COMPOSITE_TYPE_REGS = createOrmDescriptor( CompositeTypeRegistrations.class ); - AnnotationDescriptor COMPOSITE_TYPE_REG = createOrmDescriptor( CompositeTypeRegistration.class, COMPOSITE_TYPE_REGS ); - AnnotationDescriptor CONVERTER_REGS = createOrmDescriptor( ConverterRegistrations.class ); - AnnotationDescriptor CONVERTER_REG = createOrmDescriptor( ConverterRegistration.class, CONVERTER_REGS ); - AnnotationDescriptor CREATION_TIMESTAMP = createOrmDescriptor( CreationTimestamp.class ); - AnnotationDescriptor CURRENT_TIMESTAMP = createOrmDescriptor( CurrentTimestamp.class ); - AnnotationDescriptor DISCRIMINATOR_FORMULA = createOrmDescriptor( DiscriminatorFormula.class ); - AnnotationDescriptor DISCRIMINATOR_OPTIONS = createOrmDescriptor( DiscriminatorOptions.class ); - AnnotationDescriptor DYNAMIC_INSERT = createOrmDescriptor( DynamicInsert.class ); - AnnotationDescriptor DYNAMIC_UPDATE = createOrmDescriptor( DynamicUpdate.class ); - AnnotationDescriptor EMBEDDABLE_INSTANTIATOR = createOrmDescriptor( EmbeddableInstantiator.class ); - AnnotationDescriptor EMBEDDABLE_INSTANTIATOR_REGS = createOrmDescriptor( EmbeddableInstantiatorRegistrations.class ); - AnnotationDescriptor EMBEDDABLE_INSTANTIATOR_REG = createOrmDescriptor( EmbeddableInstantiatorRegistration.class, EMBEDDABLE_INSTANTIATOR_REGS ); - AnnotationDescriptor FETCH = createOrmDescriptor( Fetch.class ); - AnnotationDescriptor FETCH_PROFILES = createOrmDescriptor( FetchProfiles.class ); - AnnotationDescriptor FETCH_PROFILE = createOrmDescriptor( FetchProfile.class, FETCH_PROFILES ); - AnnotationDescriptor FILTERS = createOrmDescriptor( Filters.class ); - AnnotationDescriptor FILTER = createOrmDescriptor( Filter.class, FILTERS ); - AnnotationDescriptor FILTER_DEFS = createOrmDescriptor( FilterDefs.class ); - AnnotationDescriptor FILTER_DEF = createOrmDescriptor( FilterDef.class, FILTER_DEFS ); - AnnotationDescriptor FILTER_JOIN_TABLES = createOrmDescriptor( FilterJoinTables.class ); - AnnotationDescriptor FILTER_JOIN_TABLE = createOrmDescriptor( FilterJoinTable.class, FILTER_JOIN_TABLES ); - AnnotationDescriptor FOREIGN_KEY = createOrmDescriptor( ForeignKey.class ); - AnnotationDescriptor FORMULA = createOrmDescriptor( Formula.class ); - AnnotationDescriptor GENERATED = createOrmDescriptor( Generated.class ); - AnnotationDescriptor GENERATED_COLUMN = createOrmDescriptor( GeneratedColumn.class ); - AnnotationDescriptor GENERATOR_TYPE = createOrmDescriptor( GeneratorType.class ); - AnnotationDescriptor GENERIC_GENERATORS = createOrmDescriptor( GenericGenerators.class ); - AnnotationDescriptor GENERIC_GENERATOR = createOrmDescriptor( GenericGenerator.class, GENERIC_GENERATORS ); - AnnotationDescriptor ID_GENERATOR_TYPE = createOrmDescriptor( IdGeneratorType.class ); - AnnotationDescriptor IMMUTABLE = createOrmDescriptor( Immutable.class ); - AnnotationDescriptor IMPORTED = createOrmDescriptor( Imported.class ); - AnnotationDescriptor INDEX = createOrmDescriptor( Index.class ); - AnnotationDescriptor INDEX_COLUMN = createOrmDescriptor( IndexColumn.class ); - AnnotationDescriptor INSTANTIATOR = createOrmDescriptor( Instantiator.class ); - AnnotationDescriptor JAVA_TYPE = createOrmDescriptor( JavaType.class ); - AnnotationDescriptor JAVA_TYPE_REGS = createOrmDescriptor( JavaTypeRegistrations.class ); - AnnotationDescriptor JAVA_TYPE_REG = createOrmDescriptor( JavaTypeRegistration.class, JAVA_TYPE_REGS ); - AnnotationDescriptor JDBC_TYPE = createOrmDescriptor( JdbcType.class ); - AnnotationDescriptor JDBC_TYPE_CODE = createOrmDescriptor( JdbcTypeCode.class ); - AnnotationDescriptor JDBC_TYPE_REGS = createOrmDescriptor( JdbcTypeRegistrations.class ); - AnnotationDescriptor JDBC_TYPE_REG = createOrmDescriptor( JdbcTypeRegistration.class, JDBC_TYPE_REGS ); - AnnotationDescriptor JOIN_COLUMNS_OR_FORMULAS = createOrmDescriptor( JoinColumnsOrFormulas.class ); - AnnotationDescriptor JOIN_COLUMN_OR_FORMULA = createOrmDescriptor( JoinColumnOrFormula.class, JOIN_COLUMNS_OR_FORMULAS ); - AnnotationDescriptor JOIN_FORMULA = createOrmDescriptor( JoinFormula.class ); - AnnotationDescriptor LAZY_COLLECTION = createOrmDescriptor( LazyCollection.class ); - AnnotationDescriptor LAZY_GROUP = createOrmDescriptor( LazyGroup.class ); - AnnotationDescriptor LAZY_TO_ONE = createOrmDescriptor( LazyToOne.class ); - AnnotationDescriptor LIST_INDEX_BASE = createOrmDescriptor( ListIndexBase.class ); - AnnotationDescriptor LIST_INDEX_JAVA_TYPE = createOrmDescriptor( ListIndexJavaType.class ); - AnnotationDescriptor LIST_INDEX_JDBC_TYPE = createOrmDescriptor( ListIndexJdbcType.class ); - AnnotationDescriptor LIST_INDEX_JDBC_TYPE_CODE = createOrmDescriptor( ListIndexJdbcTypeCode.class ); - AnnotationDescriptor LOADER = createOrmDescriptor( Loader.class ); - AnnotationDescriptor MANY_TO_ANY = createOrmDescriptor( ManyToAny.class ); - AnnotationDescriptor MAP_KEY_COMPOSITE_TYPE = createOrmDescriptor( MapKeyCompositeType.class ); - AnnotationDescriptor MAP_KEY_JAVA_TYPE = createOrmDescriptor( MapKeyJavaType.class ); - AnnotationDescriptor MAP_KEY_JDBC_TYPE = createOrmDescriptor( MapKeyJdbcType.class ); - AnnotationDescriptor MAP_KEY_JDBC_TYPE_CODE = createOrmDescriptor( MapKeyJdbcTypeCode.class ); - AnnotationDescriptor MAP_KEY_MUTABILITY = createOrmDescriptor( MapKeyMutability.class ); - AnnotationDescriptor MAP_KEY_TYPE = createOrmDescriptor( MapKeyType.class ); - AnnotationDescriptor MUTABILITY = createOrmDescriptor( Mutability.class ); - AnnotationDescriptor NAMED_NATIVE_QUERIES = createOrmDescriptor( NamedNativeQueries.class ); - AnnotationDescriptor NAMED_NATIVE_QUERY = createOrmDescriptor( NamedNativeQuery.class, NAMED_NATIVE_QUERIES ); - AnnotationDescriptor NAMED_QUERIES = createOrmDescriptor( NamedQueries.class ); - AnnotationDescriptor NAMED_QUERY = createOrmDescriptor( NamedQuery.class, NAMED_QUERIES ); - AnnotationDescriptor NATIONALIZED = createOrmDescriptor( Nationalized.class ); - AnnotationDescriptor NATURAL_ID = createOrmDescriptor( NaturalId.class ); - AnnotationDescriptor NATURAL_ID_CACHE = createOrmDescriptor( NaturalIdCache.class ); - AnnotationDescriptor NOT_FOUND = createOrmDescriptor( NotFound.class ); - AnnotationDescriptor ON_DELETE = createOrmDescriptor( OnDelete.class ); - AnnotationDescriptor OPTIMISTIC_LOCK = createOrmDescriptor( OptimisticLock.class ); - AnnotationDescriptor OPTIMISTIC_LOCKING = createOrmDescriptor( OptimisticLocking.class ); - AnnotationDescriptor ORDER_BY = createOrmDescriptor( OrderBy.class ); - AnnotationDescriptor PARAM_DEF = createOrmDescriptor( ParamDef.class ); - AnnotationDescriptor PARAMETER = createOrmDescriptor( Parameter.class ); - AnnotationDescriptor PARENT = createOrmDescriptor( Parent.class ); - AnnotationDescriptor PARTITION_KEY = createOrmDescriptor( PartitionKey.class ); - AnnotationDescriptor POLYMORPHISM = createOrmDescriptor( Polymorphism.class ); - AnnotationDescriptor PROXY = createOrmDescriptor( Proxy.class ); - AnnotationDescriptor ROW_ID = createOrmDescriptor( RowId.class ); - AnnotationDescriptor SECONDARY_ROWS = createOrmDescriptor( SecondaryRows.class ); - AnnotationDescriptor SECONDARY_ROW = createOrmDescriptor( SecondaryRow.class, SECONDARY_ROWS ); - AnnotationDescriptor SELECT_BEFORE_UPDATE = createOrmDescriptor( SelectBeforeUpdate.class ); - AnnotationDescriptor SORT_COMPARATOR = createOrmDescriptor( SortComparator.class ); - AnnotationDescriptor SORT_NATURAL = createOrmDescriptor( SortNatural.class ); - AnnotationDescriptor SOURCE = createOrmDescriptor( Source.class ); - AnnotationDescriptor SQL_DELETES = createOrmDescriptor( SQLDeletes.class ); - AnnotationDescriptor SQL_DELETE = createOrmDescriptor( SQLDelete.class, SQL_DELETES ); - AnnotationDescriptor SQL_DELETE_ALL = createOrmDescriptor( SQLDeleteAll.class ); - AnnotationDescriptor SQL_FRAGMENT_ALIAS = createOrmDescriptor( SqlFragmentAlias.class ); - AnnotationDescriptor SQL_INSERTS = createOrmDescriptor( SQLInserts.class ); - AnnotationDescriptor SQL_INSERT = createOrmDescriptor( SQLInsert.class, SQL_INSERTS ); - AnnotationDescriptor SQL_RESTRICTION = createOrmDescriptor( SQLRestriction.class, SQL_INSERTS ); - AnnotationDescriptor SQL_RESTRICTION_JOIN_TABLE = createOrmDescriptor( SQLJoinTableRestriction.class, SQL_INSERTS ); - AnnotationDescriptor SQL_UPDATES = createOrmDescriptor( SQLUpdates.class ); - AnnotationDescriptor SQL_UPDATE = createOrmDescriptor( SQLUpdate.class, SQL_UPDATES ); - AnnotationDescriptor STRUCT = createOrmDescriptor( Struct.class ); - AnnotationDescriptor SUBSELECT = createOrmDescriptor( Subselect.class ); - AnnotationDescriptor SYNCHRONIZE = createOrmDescriptor( Synchronize.class ); - AnnotationDescriptor TABLES = createOrmDescriptor( Tables.class ); - AnnotationDescriptor TABLE = createOrmDescriptor( Table.class, TABLES ); - AnnotationDescriptor TENANT_ID = createOrmDescriptor( TenantId.class ); - AnnotationDescriptor TZ_COLUMN = createOrmDescriptor( TimeZoneColumn.class ); - AnnotationDescriptor TZ_STORAGE = createOrmDescriptor( TimeZoneStorage.class ); - AnnotationDescriptor TYPE = createOrmDescriptor( Type.class ); - AnnotationDescriptor TYPE_BINDER_TYPE = createOrmDescriptor( TypeBinderType.class ); - AnnotationDescriptor TYPE_REGS = createOrmDescriptor( TypeRegistrations.class ); - AnnotationDescriptor TYPE_REG = createOrmDescriptor( TypeRegistration.class, TYPE_REGS ); - AnnotationDescriptor UPDATE_TIMESTAMP = createOrmDescriptor( UpdateTimestamp.class ); - AnnotationDescriptor UUID_GENERATOR = createOrmDescriptor( UuidGenerator.class ); - AnnotationDescriptor VALUE_GENERATION_TYPE = createOrmDescriptor( ValueGenerationType.class ); - AnnotationDescriptor WHERE = createOrmDescriptor( Where.class ); - AnnotationDescriptor WHERE_JOIN_TABLE = createOrmDescriptor( WhereJoinTable.class ); - - AnnotationDescriptor ABSTRACT = createOrmDescriptor( Abstract.class ); - AnnotationDescriptor ANY_KEY_TYPE = createOrmDescriptor( AnyKeyType.class ); - AnnotationDescriptor COLLECTION_CLASSIFICATION = createOrmDescriptor( CollectionClassification.class ); - AnnotationDescriptor EXTENDS = createOrmDescriptor( Extends.class ); - AnnotationDescriptor TARGET = createOrmDescriptor( Target.class ); - - AnnotationDescriptor DIALECT_OVERRIDE_CHECKS = createOrmDescriptor( DialectOverride.Checks.class ); - AnnotationDescriptor DIALECT_OVERRIDE_CHECK = createOrmDescriptor( DialectOverride.Check.class, DIALECT_OVERRIDE_CHECKS ); - AnnotationDescriptor DIALECT_OVERRIDE_ORDER_BYS = createOrmDescriptor( DialectOverride.OrderBys.class ); - AnnotationDescriptor DIALECT_OVERRIDE_ORDER_BY = createOrmDescriptor( DialectOverride.OrderBy.class, DIALECT_OVERRIDE_ORDER_BYS ); - AnnotationDescriptor DIALECT_OVERRIDE_COLUMN_DEFAULTS = createOrmDescriptor( DialectOverride.ColumnDefaults.class ); - AnnotationDescriptor DIALECT_OVERRIDE_COLUMN_DEFAULT = createOrmDescriptor( DialectOverride.ColumnDefault.class, DIALECT_OVERRIDE_COLUMN_DEFAULTS ); - AnnotationDescriptor DIALECT_OVERRIDE_GENERATED_COLUMNS = createOrmDescriptor( DialectOverride.GeneratedColumns.class ); - AnnotationDescriptor DIALECT_OVERRIDE_GENERATED_COLUMN = createOrmDescriptor( DialectOverride.GeneratedColumn.class, DIALECT_OVERRIDE_GENERATED_COLUMNS ); - AnnotationDescriptor DIALECT_OVERRIDE_DISCRIMINATOR_FORMULAS = createOrmDescriptor( DialectOverride.DiscriminatorFormulas.class ); - AnnotationDescriptor DIALECT_OVERRIDE_DISCRIMINATOR_FORMULA = createOrmDescriptor( DialectOverride.DiscriminatorFormula.class, DIALECT_OVERRIDE_DISCRIMINATOR_FORMULAS ); - AnnotationDescriptor DIALECT_OVERRIDE_FORMULAS = createOrmDescriptor( DialectOverride.Formulas.class ); - AnnotationDescriptor DIALECT_OVERRIDE_FORMULA = createOrmDescriptor( DialectOverride.Formula.class, DIALECT_OVERRIDE_FORMULAS ); - AnnotationDescriptor DIALECT_OVERRIDE_JOIN_FORMULAS = createOrmDescriptor( DialectOverride.JoinFormulas.class ); - AnnotationDescriptor DIALECT_OVERRIDE_JOIN_FORMULA = createOrmDescriptor( DialectOverride.JoinFormula.class, DIALECT_OVERRIDE_JOIN_FORMULAS ); - AnnotationDescriptor DIALECT_OVERRIDE_WHERES = createOrmDescriptor( DialectOverride.Wheres.class ); - AnnotationDescriptor DIALECT_OVERRIDE_WHERE = createOrmDescriptor( DialectOverride.Where.class, DIALECT_OVERRIDE_WHERES ); - AnnotationDescriptor DIALECT_OVERRIDE_FILTER_OVERRIDES = createOrmDescriptor( DialectOverride.FilterOverrides.class ); - AnnotationDescriptor DIALECT_OVERRIDE_FILTERS = createOrmDescriptor( DialectOverride.Filters.class, DIALECT_OVERRIDE_FILTER_OVERRIDES ); - AnnotationDescriptor DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES = createOrmDescriptor( DialectOverride.FilterDefOverrides.class ); - AnnotationDescriptor DIALECT_OVERRIDE_FILTER_DEFS = createOrmDescriptor( DialectOverride.FilterDefs.class, DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES ); - AnnotationDescriptor DIALECT_OVERRIDE_VERSION = createOrmDescriptor( DialectOverride.Version.class ); - - AnnotationDescriptor DIALECT_OVERRIDE_SQL_INSERTS = createOrmDescriptor( DialectOverride.SQLInserts.class ); - AnnotationDescriptor DIALECT_OVERRIDE_SQL_INSERT = createOrmDescriptor( DialectOverride.SQLInsert.class, DIALECT_OVERRIDE_SQL_INSERTS ); - AnnotationDescriptor DIALECT_OVERRIDE_SQL_UPDATES = createOrmDescriptor( DialectOverride.SQLUpdates.class ); - AnnotationDescriptor DIALECT_OVERRIDE_SQL_UPDATE = createOrmDescriptor( DialectOverride.SQLUpdate.class, DIALECT_OVERRIDE_SQL_UPDATES ); - AnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETES = createOrmDescriptor( DialectOverride.SQLDeletes.class ); - AnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETE = createOrmDescriptor( DialectOverride.SQLDelete.class, DIALECT_OVERRIDE_SQL_DELETES ); - AnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETE_ALLS = createOrmDescriptor( DialectOverride.SQLDeleteAlls.class ); - AnnotationDescriptor DIALECT_OVERRIDE_SQL_DELETE_ALL = createOrmDescriptor( DialectOverride.SQLDeleteAll.class, DIALECT_OVERRIDE_SQL_DELETE_ALLS ); + OrmAnnotationDescriptor ANY = new OrmAnnotationDescriptor<>( + Any.class, + AnyAnnotation.class + ); + OrmAnnotationDescriptor ANY_DISCRIMINATOR = new OrmAnnotationDescriptor<>( + AnyDiscriminator.class, + AnyDiscriminatorAnnotation.class + ); + OrmAnnotationDescriptor ANY_DISCRIMINATOR_VALUES = new OrmAnnotationDescriptor<>( + AnyDiscriminatorValues.class, + AnyDiscriminatorValuesAnnotation.class + ); + OrmAnnotationDescriptor ANY_DISCRIMINATOR_VALUE = new OrmAnnotationDescriptor<>( + AnyDiscriminatorValue.class, + AnyDiscriminatorValueAnnotation.class, + ANY_DISCRIMINATOR_VALUES + ); + OrmAnnotationDescriptor ANY_KEY_JAVA_CLASS = new OrmAnnotationDescriptor<>( + AnyKeyJavaClass.class, + AnyKeyJavaClassAnnotation.class + ); + OrmAnnotationDescriptor ANY_KEY_JAVA_TYPE = new OrmAnnotationDescriptor<>( + AnyKeyJavaType.class, + AnyKeyJavaTypeAnnotation.class + ); + OrmAnnotationDescriptor ANY_KEY_JDBC_TYPE = new OrmAnnotationDescriptor<>( + AnyKeyJdbcType.class, + AnyKeyJdbcTypeAnnotation.class + ); + OrmAnnotationDescriptor ANY_KEY_JDBC_TYPE_CODE = new OrmAnnotationDescriptor<>( + AnyKeyJdbcTypeCode.class, + AnyKeyJdbcTypeCodeAnnotation.class + ); + OrmAnnotationDescriptor ANY_KEY_TYPE = new OrmAnnotationDescriptor<>( + AnyKeyType.class, + AnyKeTypeAnnotation.class + ); + OrmAnnotationDescriptor ARRAY = new OrmAnnotationDescriptor<>( + Array.class, + ArrayAnnotation.class + ); + SpecializedAnnotationDescriptor ATTRIBUTE_ACCESSOR = new SpecializedAnnotationDescriptor<>( + AttributeAccessor.class, + AttributeAccessorAnnotation.class + ); + OrmAnnotationDescriptor ATTRIBUTE_BINDER_TYPE = new OrmAnnotationDescriptor<>( + AttributeBinderType.class, + AttributeBinderTypeAnnotation.class + ); + OrmAnnotationDescriptor BAG = new OrmAnnotationDescriptor<>( + Bag.class, + BagAnnotation.class + ); + SpecializedAnnotationDescriptor BATCH_SIZE = new SpecializedAnnotationDescriptor<>( + BatchSize.class, + BatchSizeAnnotation.class + ); + OrmAnnotationDescriptor CACHE = new OrmAnnotationDescriptor<>( + Cache.class, + CacheAnnotation.class + ); + OrmAnnotationDescriptor CASCADE = new OrmAnnotationDescriptor<>( + Cascade.class, + CascadeAnnotation.class + ); + OrmAnnotationDescriptor CHECKS = new OrmAnnotationDescriptor<>( + Checks.class, + ChecksAnnotation.class + ); + OrmAnnotationDescriptor CHECK = new OrmAnnotationDescriptor<>( + Check.class, + CheckAnnotation.class, + CHECKS + ); + SpecializedAnnotationDescriptor COLLATE = new SpecializedAnnotationDescriptor<>( + Collate.class, + CollateAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_ID = new OrmAnnotationDescriptor<>( + CollectionId.class, + CollectionIdAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_ID_JAVA_TYPE = new OrmAnnotationDescriptor<>( + CollectionIdJavaType.class, + CollectionIdJavaTypeAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_ID_JDBC_TYPE = new OrmAnnotationDescriptor<>( + CollectionIdJdbcType.class, + CollectionIdJdbcTypeAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_ID_JDBC_TYPE_CODE = new OrmAnnotationDescriptor<>( + CollectionIdJdbcTypeCode.class, + CollectionIdJdbcTypeCodeAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_ID_MUTABILITY = new OrmAnnotationDescriptor<>( + CollectionIdMutability.class, + CollectionIdMutabilityAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_ID_TYPE = new OrmAnnotationDescriptor<>( + CollectionIdType.class, + CollectionIdTypeAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_TYPE = new OrmAnnotationDescriptor<>( + CollectionType.class, + CollectionTypeAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_TYPE_REGISTRATIONS = new OrmAnnotationDescriptor<>( + CollectionTypeRegistrations.class, + CollectionTypeRegistrationsAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_TYPE_REGISTRATION = new OrmAnnotationDescriptor<>( + CollectionTypeRegistration.class, + CollectionTypeRegistrationAnnotation.class, + COLLECTION_TYPE_REGISTRATIONS + ); + OrmAnnotationDescriptor COLUMN_DEFAULT = new OrmAnnotationDescriptor<>( + ColumnDefault.class, + ColumnDefaultAnnotation.class + ); + OrmAnnotationDescriptor COLUMNS = new OrmAnnotationDescriptor<>( + Columns.class, + ColumnsAnnotation.class + ); + OrmAnnotationDescriptor COLUMN_TRANSFORMERS = new OrmAnnotationDescriptor<>( + ColumnTransformers.class, + ColumnTransformersAnnotation.class + ); + OrmAnnotationDescriptor COLUMN_TRANSFORMER = new OrmAnnotationDescriptor<>( + ColumnTransformer.class, + ColumnTransformerAnnotation.class, + COLUMN_TRANSFORMERS + ); + SpecializedAnnotationDescriptor COMMENTS = new SpecializedAnnotationDescriptor<>( + Comments.class, + CommentsAnnotation.class + ); + SpecializedAnnotationDescriptor COMMENT = new SpecializedAnnotationDescriptor<>( + Comment.class, + CommentAnnotation.class, + COMMENTS + ); + OrmAnnotationDescriptor COMPOSITE_TYPE = new OrmAnnotationDescriptor<>( + CompositeType.class, + CompositeTypeAnnotation.class + ); + OrmAnnotationDescriptor COMPOSITE_TYPE_REGISTRATIONS = new OrmAnnotationDescriptor<>( + CompositeTypeRegistrations.class, + CompositeTypeRegistrationsAnnotation.class + ); + OrmAnnotationDescriptor COMPOSITE_TYPE_REGISTRATION = new OrmAnnotationDescriptor<>( + CompositeTypeRegistration.class, + CompositeTypeRegistrationAnnotation.class, + COMPOSITE_TYPE_REGISTRATIONS + ); + OrmAnnotationDescriptor CONCRETE_PROXY = new OrmAnnotationDescriptor<>( + ConcreteProxy.class, + ConcreteProxyAnnotation.class + ); + OrmAnnotationDescriptor CONVERTER_REGISTRATIONS = new OrmAnnotationDescriptor<>( + ConverterRegistrations.class, + ConverterRegistrationsAnnotation.class + ); + OrmAnnotationDescriptor CONVERTER_REGISTRATION = new OrmAnnotationDescriptor<>( + ConverterRegistration.class, + ConverterRegistrationAnnotation.class, + CONVERTER_REGISTRATIONS + ); + OrmAnnotationDescriptor CREATION_TIMESTAMP = new OrmAnnotationDescriptor<>( + CreationTimestamp.class, + CreationTimestampAnnotation.class + ); + OrmAnnotationDescriptor CURRENT_TIMESTAMP = new OrmAnnotationDescriptor<>( + CurrentTimestamp.class, + CurrentTimestampAnnotation.class + ); + OrmAnnotationDescriptor DISCRIMINATOR_FORMULA = new OrmAnnotationDescriptor<>( + DiscriminatorFormula.class, + DiscriminatorFormulaAnnotation.class + ); + SpecializedAnnotationDescriptor DISCRIMINATOR_OPTIONS = new SpecializedAnnotationDescriptor<>( + DiscriminatorOptions.class, + DiscriminatorOptionsAnnotation.class + ); + OrmAnnotationDescriptor DYNAMIC_INSERT = new OrmAnnotationDescriptor<>( + DynamicInsert.class, + DynamicInsertAnnotation.class + ); + OrmAnnotationDescriptor DYNAMIC_UPDATE = new OrmAnnotationDescriptor<>( + DynamicUpdate.class, + DynamicUpdateAnnotation.class + ); + OrmAnnotationDescriptor EMBEDDABLE_INSTANTIATOR = new OrmAnnotationDescriptor<>( + EmbeddableInstantiator.class, + EmbeddableInstantiatorAnnotation.class + ); + OrmAnnotationDescriptor EMBEDDABLE_INSTANTIATOR_REGISTRATIONS = new OrmAnnotationDescriptor<>( + EmbeddableInstantiatorRegistrations.class, + EmbeddableInstantiatorRegistrationsAnnotation.class + ); + OrmAnnotationDescriptor EMBEDDABLE_INSTANTIATOR_REGISTRATION = new OrmAnnotationDescriptor<>( + EmbeddableInstantiatorRegistration.class, + EmbeddableInstantiatorRegistrationAnnotation.class, + EMBEDDABLE_INSTANTIATOR_REGISTRATIONS + ); + OrmAnnotationDescriptor FETCH = new OrmAnnotationDescriptor<>( + Fetch.class, + FetchAnnotation.class + ); + OrmAnnotationDescriptor FETCH_PROFILES = new OrmAnnotationDescriptor<>( + FetchProfiles.class, + FetchProfilesAnnotation.class + ); + OrmAnnotationDescriptor FETCH_PROFILE = new OrmAnnotationDescriptor<>( + FetchProfile.class, + FetchProfileAnnotation.class, + FETCH_PROFILES + ); + OrmAnnotationDescriptor FILTERS = new OrmAnnotationDescriptor<>( + Filters.class, + FiltersAnnotation.class + ); + OrmAnnotationDescriptor FILTER = new OrmAnnotationDescriptor<>( + Filter.class, + FilterAnnotation.class, + FILTERS + ); + OrmAnnotationDescriptor FILTER_DEFS = new OrmAnnotationDescriptor<>( + FilterDefs.class, + FilterDefsAnnotation.class + ); + OrmAnnotationDescriptor FILTER_DEF = new OrmAnnotationDescriptor<>( + FilterDef.class, + FilterDefAnnotation.class, + FILTER_DEFS + ); + OrmAnnotationDescriptor FILTER_JOIN_TABLES = new OrmAnnotationDescriptor<>( + FilterJoinTables.class, + FilterJoinTablesAnnotation.class + ); + OrmAnnotationDescriptor FILTER_JOIN_TABLE = new OrmAnnotationDescriptor<>( + FilterJoinTable.class, + FilterJoinTableAnnotation.class, + FILTER_JOIN_TABLES + ); + OrmAnnotationDescriptor FOREIGN_KEY = new OrmAnnotationDescriptor<>( + ForeignKey.class, + ForeignKeyAnnotation.class + ); + OrmAnnotationDescriptor FORMULA = new OrmAnnotationDescriptor<>( + Formula.class, + FormulaAnnotation.class + ); + OrmAnnotationDescriptor FRACTIONAL_SECONDS = new OrmAnnotationDescriptor<>( + FractionalSeconds.class, + FractionalSecondsAnnotation.class + ); + OrmAnnotationDescriptor GENERATED = new OrmAnnotationDescriptor<>( + Generated.class, + GeneratedAnnotation.class + ); + OrmAnnotationDescriptor GENERATED_COLUMN = new OrmAnnotationDescriptor<>( + GeneratedColumn.class, + GeneratedColumnAnnotation.class + ); + OrmAnnotationDescriptor GENERATOR_TYPE = new OrmAnnotationDescriptor<>( + GeneratorType.class, + GeneratorTypeAnnotation.class + ); + OrmAnnotationDescriptor GENERIC_GENERATORS = new OrmAnnotationDescriptor<>( + GenericGenerators.class, + GenericGeneratorsAnnotation.class + ); + OrmAnnotationDescriptor GENERIC_GENERATOR = new OrmAnnotationDescriptor<>( + GenericGenerator.class, + GenericGeneratorAnnotation.class, + GENERIC_GENERATORS + ); + OrmAnnotationDescriptor HQL_SELECT = new OrmAnnotationDescriptor<>( + HQLSelect.class, + HQLSelectAnnotation.class + ); + OrmAnnotationDescriptor ID_GENERATOR_TYPE = new OrmAnnotationDescriptor<>( + IdGeneratorType.class, + IdGeneratorTypeAnnotation.class + ); + OrmAnnotationDescriptor IMMUTABLE = new OrmAnnotationDescriptor<>( + Immutable.class, + ImmutableAnnotation.class + ); + OrmAnnotationDescriptor IMPORTED = new OrmAnnotationDescriptor<>( + Imported.class, + ImportedAnnotation.class + ); + OrmAnnotationDescriptor INDEX = new OrmAnnotationDescriptor<>( + Index.class, + IndexAnnotation.class + ); + OrmAnnotationDescriptor INDEX_COLUMN = new OrmAnnotationDescriptor<>( + IndexColumn.class, + IndexColumnAnnotation.class + ); + OrmAnnotationDescriptor INSTANTIATOR = new OrmAnnotationDescriptor<>( + Instantiator.class, + InstantiatorAnnotation.class + ); + OrmAnnotationDescriptor JAVA_TYPE = new OrmAnnotationDescriptor<>( + JavaType.class, + JavaTypeAnnotation.class + ); + OrmAnnotationDescriptor JAVA_TYPE_REGISTRATIONS = new OrmAnnotationDescriptor<>( + JavaTypeRegistrations.class, + JavaTypeRegistrationsAnnotation.class + ); + OrmAnnotationDescriptor JAVA_TYPE_REGISTRATION = new OrmAnnotationDescriptor<>( + JavaTypeRegistration.class, + JavaTypeRegistrationAnnotation.class, + JAVA_TYPE_REGISTRATIONS + ); + OrmAnnotationDescriptor JDBC_TYPE = new OrmAnnotationDescriptor<>( + JdbcType.class, + JdbcTypeAnnotation.class + ); + OrmAnnotationDescriptor JDBC_TYPE_CODE = new OrmAnnotationDescriptor<>( + JdbcTypeCode.class, + JdbcTypeCodeAnnotation.class + ); + OrmAnnotationDescriptor JDBC_TYPE_REGISTRATIONS = new OrmAnnotationDescriptor<>( + JdbcTypeRegistrations.class, + JdbcTypeRegistrationsAnnotation.class + ); + OrmAnnotationDescriptor JDBC_TYPE_REGISTRATION = new OrmAnnotationDescriptor<>( + JdbcTypeRegistration.class, + JdbcTypeRegistrationAnnotation.class, + JDBC_TYPE_REGISTRATIONS + ); + OrmAnnotationDescriptor JOIN_COLUMNS_OR_FORMULAS = new OrmAnnotationDescriptor<>( + JoinColumnsOrFormulas.class, + JoinColumnsOrFormulasAnnotation.class + ); + OrmAnnotationDescriptor JOIN_COLUMN_OR_FORMULA = new OrmAnnotationDescriptor<>( + JoinColumnOrFormula.class, + JoinColumnOrFormulaAnnotation.class, + JOIN_COLUMNS_OR_FORMULAS + ); + OrmAnnotationDescriptor JOIN_FORMULA = new OrmAnnotationDescriptor<>( + JoinFormula.class, + JoinFormulaAnnotation.class + ); + OrmAnnotationDescriptor LAZY_COLLECTION = new OrmAnnotationDescriptor<>( + LazyCollection.class, + LazyCollectionAnnotation.class + ); + OrmAnnotationDescriptor LAZY_GROUP = new OrmAnnotationDescriptor<>( + LazyGroup.class, + LazyGroupAnnotation.class + ); + OrmAnnotationDescriptor LAZY_TO_ONE = new OrmAnnotationDescriptor<>( + LazyToOne.class, + LazyToOneAnnotation.class + ); + OrmAnnotationDescriptor LIST_INDEX_BASE = new OrmAnnotationDescriptor<>( + ListIndexBase.class, + ListIndexBaseAnnotation.class + ); + OrmAnnotationDescriptor LIST_INDEX_JAVA_TYPE = new OrmAnnotationDescriptor<>( + ListIndexJavaType.class, + ListIndexJavaTypeAnnotation.class + ); + OrmAnnotationDescriptor LIST_INDEX_JDBC_TYPE = new OrmAnnotationDescriptor<>( + ListIndexJdbcType.class, + ListIndexJdbcTypeAnnotation.class + ); + OrmAnnotationDescriptor LIST_INDEX_JDBC_TYPE_CODE = new OrmAnnotationDescriptor<>( + ListIndexJdbcTypeCode.class, + ListIndexJdbcTypeCodeAnnotation.class + ); + OrmAnnotationDescriptor LOADER = new OrmAnnotationDescriptor<>( + Loader.class, + LoaderAnnotation.class + ); + OrmAnnotationDescriptor MANY_TO_ANY = new OrmAnnotationDescriptor<>( + ManyToAny.class, + ManyToAnyAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_COMPOSITE_TYPE = new OrmAnnotationDescriptor<>( + MapKeyCompositeType.class, + MapKeyCompositeTypeAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_JAVA_TYPE = new OrmAnnotationDescriptor<>( + MapKeyJavaType.class, + MapKeyJavaTypeAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_JDBC_TYPE = new OrmAnnotationDescriptor<>( + MapKeyJdbcType.class, + MapKeyJdbcTypeAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_JDBC_TYPE_CODE = new OrmAnnotationDescriptor<>( + MapKeyJdbcTypeCode.class, + MapKeyJdbcTypeCodeAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_MUTABILITY = new OrmAnnotationDescriptor<>( + MapKeyMutability.class, + MapKeyMutabilityAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_TYPE = new OrmAnnotationDescriptor<>( + MapKeyType.class, + MapKeyTypeAnnotation.class + ); + OrmAnnotationDescriptor MUTABILITY = new OrmAnnotationDescriptor<>( + Mutability.class, + MutabilityAnnotation.class + ); + OrmAnnotationDescriptor NAMED_NATIVE_QUERIES = new OrmAnnotationDescriptor<>( + NamedNativeQueries.class, + NamedNativeQueriesAnnotation.class + ); + OrmAnnotationDescriptor NAMED_NATIVE_QUERY = new OrmAnnotationDescriptor<>( + NamedNativeQuery.class, + NamedNativeQueryAnnotation.class, + NAMED_NATIVE_QUERIES + ); + OrmAnnotationDescriptor NAMED_QUERIES = new OrmAnnotationDescriptor<>( + NamedQueries.class, + NamedQueriesAnnotation.class + ); + OrmAnnotationDescriptor NAMED_QUERY = new OrmAnnotationDescriptor<>( + NamedQuery.class, + NamedQueryAnnotation.class, + NAMED_QUERIES + ); + OrmAnnotationDescriptor NATIONALIZED = new OrmAnnotationDescriptor<>( + Nationalized.class, + NationalizedAnnotation.class + ); + OrmAnnotationDescriptor NATURAL_ID = new OrmAnnotationDescriptor<>( + NaturalId.class, + NaturalIdAnnotation.class + ); + OrmAnnotationDescriptor NATURAL_ID_CACHE = new OrmAnnotationDescriptor<>( + NaturalIdCache.class, + NaturalIdCacheAnnotation.class + ); + OrmAnnotationDescriptor NOT_FOUND = new OrmAnnotationDescriptor<>( + NotFound.class, + NotFoundAnnotation.class + ); + OrmAnnotationDescriptor ON_DELETE = new OrmAnnotationDescriptor<>( + OnDelete.class, + OnDeleteAnnotation.class + ); + OrmAnnotationDescriptor OPTIMISTIC_LOCK = new OrmAnnotationDescriptor<>( + OptimisticLock.class, + OptimisticLockAnnotation.class + ); + OrmAnnotationDescriptor OPTIMISTIC_LOCKING = new OrmAnnotationDescriptor<>( + OptimisticLocking.class, + OptimisticLockingAnnotation.class + ); + OrmAnnotationDescriptor ORDER_BY = new OrmAnnotationDescriptor<>( + OrderBy.class, + OrderByAnnotation.class + ); + OrmAnnotationDescriptor PARAM_DEF = new OrmAnnotationDescriptor<>( + ParamDef.class, + ParamDefAnnotation.class + ); + OrmAnnotationDescriptor PARAMETER = new OrmAnnotationDescriptor<>( + Parameter.class, + ParameterAnnotation.class + ); + OrmAnnotationDescriptor PARENT = new OrmAnnotationDescriptor<>( + Parent.class, + ParentAnnotation.class + ); + OrmAnnotationDescriptor PARTITION_KEY = new OrmAnnotationDescriptor<>( + PartitionKey.class, + PartitionKeyAnnotation.class + ); + OrmAnnotationDescriptor POLYMORPHISM = new OrmAnnotationDescriptor<>( + Polymorphism.class, + PolymorphismAnnotation.class + ); + OrmAnnotationDescriptor PROXY = new OrmAnnotationDescriptor<>( + Proxy.class, + ProxyAnnotation.class + ); + OrmAnnotationDescriptor QUERY_CACHE_LAYOUT = new OrmAnnotationDescriptor<>( + QueryCacheLayout.class, + QueryCacheLayoutAnnotation.class + ); + OrmAnnotationDescriptor ROW_ID = new OrmAnnotationDescriptor<>( + RowId.class, + RowIdAnnotation.class + ); + OrmAnnotationDescriptor SECONDARY_ROWS = new OrmAnnotationDescriptor<>( + SecondaryRows.class, + SecondaryRowsAnnotation.class + ); + OrmAnnotationDescriptor SECONDARY_ROW = new OrmAnnotationDescriptor<>( + SecondaryRow.class, + SecondaryRowAnnotation.class + ); + OrmAnnotationDescriptor SELECT_BEFORE_UPDATE = new OrmAnnotationDescriptor<>( + SelectBeforeUpdate.class, + SelectBeforeUpdateAnnotation.class + ); + OrmAnnotationDescriptor SOFT_DELETE = new OrmAnnotationDescriptor<>( + SoftDelete.class, + SoftDeleteAnnotation.class + ); + OrmAnnotationDescriptor SORT_COMPARATOR = new OrmAnnotationDescriptor<>( + SortComparator.class, + SortComparatorAnnotation.class + ); + OrmAnnotationDescriptor SORT_NATURAL = new OrmAnnotationDescriptor<>( + SortNatural.class, + SortNaturalAnnotation.class + ); + OrmAnnotationDescriptor SOURCE = new OrmAnnotationDescriptor<>( + Source.class, + SourceAnnotation.class + ); + OrmAnnotationDescriptor SQL_DELETES = new OrmAnnotationDescriptor<>( + SQLDeletes.class, + SQLDeletesAnnotation.class + ); + OrmAnnotationDescriptor SQL_DELETE = new OrmAnnotationDescriptor<>( + SQLDelete.class, + SQLDeleteAnnotation.class, + SQL_DELETES + ); + OrmAnnotationDescriptor SQL_DELETE_ALL = new OrmAnnotationDescriptor<>( + SQLDeleteAll.class, + SQLDeleteAllAnnotation.class + ); + OrmAnnotationDescriptor SQL_FRAGMENT_ALIAS = new OrmAnnotationDescriptor<>( + SqlFragmentAlias.class, + SqlFragmentAliasAnnotation.class + ); + OrmAnnotationDescriptor SQL_INSERTS = new OrmAnnotationDescriptor<>( + SQLInserts.class, + SQLInsertsAnnotation.class + ); + OrmAnnotationDescriptor SQL_INSERT = new OrmAnnotationDescriptor<>( + SQLInsert.class, + SQLInsertAnnotation.class, + SQL_INSERTS + ); + OrmAnnotationDescriptor SQL_ORDER = new OrmAnnotationDescriptor<>( + SQLOrder.class, + SQLOrderAnnotation.class + ); + OrmAnnotationDescriptor SQL_RESTRICTION = new OrmAnnotationDescriptor<>( + SQLRestriction.class, + SQLRestrictionAnnotation.class + ); + OrmAnnotationDescriptor SQL_SELECT = new OrmAnnotationDescriptor<>( + SQLSelect.class, + SQLSelectAnnotation.class + ); + OrmAnnotationDescriptor SQL_JOIN_TABLE_RESTRICTION = new OrmAnnotationDescriptor<>( + SQLJoinTableRestriction.class, + SQLJoinTableRestrictionAnnotation.class + ); + OrmAnnotationDescriptor SQL_UPDATES = new OrmAnnotationDescriptor<>( + SQLUpdates.class, + SQLUpdatesAnnotation.class + ); + OrmAnnotationDescriptor SQL_UPDATE = new OrmAnnotationDescriptor<>( + SQLUpdate.class, + SQLUpdateAnnotation.class, + SQL_UPDATES + ); + OrmAnnotationDescriptor STRUCT = new OrmAnnotationDescriptor<>( + Struct.class, + StructAnnotation.class + ); + OrmAnnotationDescriptor SUBSELECT = new OrmAnnotationDescriptor<>( + Subselect.class, + SubselectAnnotation.class + ); + OrmAnnotationDescriptor SYNCHRONIZE = new OrmAnnotationDescriptor<>( + Synchronize.class, + SynchronizeAnnotation.class + ); + OrmAnnotationDescriptor TABLES = new OrmAnnotationDescriptor<>( + Tables.class, + TablesAnnotation.class + ); + OrmAnnotationDescriptor TABLE = new OrmAnnotationDescriptor<>( + Table.class, + TableAnnotation.class, + TABLES + ); + OrmAnnotationDescriptor TARGET_LEGACY = new OrmAnnotationDescriptor<>( + Target.class, + TargetLegacyAnnotation.class + ); + SpecializedAnnotationDescriptor TENANT_ID = new SpecializedAnnotationDescriptor<>( + TenantId.class, + TenantIdAnnotation.class + ); + OrmAnnotationDescriptor TIME_ZONE_COLUMN = new OrmAnnotationDescriptor<>( + TimeZoneColumn.class, + TimeZoneColumnAnnotation.class + ); + OrmAnnotationDescriptor TIME_ZONE_STORAGE = new OrmAnnotationDescriptor<>( + TimeZoneStorage.class, + TimeZoneStorageAnnotation.class + ); + OrmAnnotationDescriptor TYPE = new OrmAnnotationDescriptor<>( + Type.class, + TypeAnnotation.class + ); + SpecializedAnnotationDescriptor TYPE_BINDER_TYPE = new SpecializedAnnotationDescriptor<>( + TypeBinderType.class, + TypeBinderTypeAnnotation.class + ); + OrmAnnotationDescriptor TYPE_REGISTRATIONS = new OrmAnnotationDescriptor<>( + TypeRegistrations.class, + TypeRegistrationsAnnotation.class + ); + OrmAnnotationDescriptor TYPE_REGISTRATION = new OrmAnnotationDescriptor<>( + TypeRegistration.class, + TypeRegistrationAnnotation.class, + TYPE_REGISTRATIONS + ); + OrmAnnotationDescriptor UPDATE_TIMESTAMP = new OrmAnnotationDescriptor<>( + UpdateTimestamp.class, + UpdateTimestampAnnotation.class + ); + OrmAnnotationDescriptor UUID_GENERATOR = new OrmAnnotationDescriptor<>( + UuidGenerator.class, + UuidGeneratorAnnotation.class + ); + OrmAnnotationDescriptor VALUE_GENERATION_TYPE = new OrmAnnotationDescriptor<>( + ValueGenerationType.class, + ValueGenerationTypeAnnotation.class + ); + OrmAnnotationDescriptor VIEW = new OrmAnnotationDescriptor<>( + View.class, + ViewAnnotation.class + ); + OrmAnnotationDescriptor WHERE = new OrmAnnotationDescriptor<>( + Where.class, + WhereAnnotation.class + ); + OrmAnnotationDescriptor WHERE_JOIN_TABLE = new OrmAnnotationDescriptor<>( + WhereJoinTable.class, + WhereJoinTableAnnotation.class + ); static void forEachAnnotation(Consumer> consumer) { OrmAnnotationHelper.forEachOrmAnnotation( HibernateAnnotations.class, consumer ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/JpaAnnotations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/JpaAnnotations.java index 09aa8ad0fc..d9a82b1908 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/JpaAnnotations.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/JpaAnnotations.java @@ -9,7 +9,96 @@ package org.hibernate.boot.models; import java.lang.annotation.Annotation; import java.util.function.Consumer; -import org.hibernate.boot.models.categorize.internal.OrmAnnotationHelper; +import org.hibernate.boot.models.annotations.internal.AccessJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AssociationOverrideJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AssociationOverridesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AttributeOverrideJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AttributeOverridesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.BasicJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.CacheableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.CheckConstraintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.CollectionTableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ColumnResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ConstructorResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ConvertJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ConverterJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ConvertsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.DiscriminatorColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.DiscriminatorValueJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ElementCollectionJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EmbeddableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EmbeddedIdJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EmbeddedJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EntityJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EntityListenersJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EntityResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EnumeratedJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EnumeratedValueJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ExcludeDefaultListenersJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ExcludeSuperclassListenersJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.FieldResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ForeignKeyJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.GeneratedValueJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.IdClassJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.IdJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.IndexJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.InheritanceJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.JoinColumnsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.JoinTableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.LobJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ManyToManyJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ManyToOneJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyClassJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyEnumeratedJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyJoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyJoinColumnsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyTemporalJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MappedSuperclassJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapsIdJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedAttributeNodeJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedEntityGraphJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedEntityGraphsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedNativeQueriesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedNativeQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedQueriesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedStoredProcedureQueriesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedStoredProcedureQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedSubgraphJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.OneToManyJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.OneToOneJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.OrderByJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.OrderColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PostLoadJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PostPersistJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PostRemoveJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PostUpdateJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PrePersistJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PreRemoveJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PreUpdateJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PrimaryKeyJoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PrimaryKeyJoinColumnsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.QueryHintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SecondaryTableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SecondaryTablesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SequenceGeneratorJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SequenceGeneratorsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SqlResultSetMappingJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SqlResultSetMappingsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.StoredProcedureParameterJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TableGeneratorJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TableGeneratorsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TemporalJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TransientJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.UniqueConstraintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.VersionJpaAnnotation; +import org.hibernate.boot.models.internal.OrmAnnotationHelper; +import org.hibernate.models.internal.OrmAnnotationDescriptor; import org.hibernate.models.spi.AnnotationDescriptor; import jakarta.persistence.Access; @@ -37,6 +126,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; import jakarta.persistence.EntityResult; import jakarta.persistence.Enumerated; +import jakarta.persistence.EnumeratedValue; import jakarta.persistence.ExcludeDefaultListeners; import jakarta.persistence.ExcludeSuperclassListeners; import jakarta.persistence.FieldResult; @@ -100,101 +190,379 @@ import jakarta.persistence.Transient; import jakarta.persistence.UniqueConstraint; import jakarta.persistence.Version; -import static org.hibernate.models.internal.AnnotationHelper.createOrmDescriptor; - /** * Descriptors for JPA annotations * * @author Steve Ebersole */ public interface JpaAnnotations { - AnnotationDescriptor ACCESS = createOrmDescriptor( Access.class ); - AnnotationDescriptor ASSOCIATION_OVERRIDES = createOrmDescriptor( AssociationOverrides.class ); - AnnotationDescriptor ASSOCIATION_OVERRIDE = createOrmDescriptor( AssociationOverride.class, ASSOCIATION_OVERRIDES ); - AnnotationDescriptor ATTRIBUTE_OVERRIDES = createOrmDescriptor( AttributeOverrides.class ); - AnnotationDescriptor ATTRIBUTE_OVERRIDE = createOrmDescriptor( AttributeOverride.class, ATTRIBUTE_OVERRIDES ); - AnnotationDescriptor BASIC = createOrmDescriptor( Basic.class ); - AnnotationDescriptor CACHEABLE = createOrmDescriptor( Cacheable.class ); - AnnotationDescriptor CHECK_CONSTRAINT = createOrmDescriptor(CheckConstraint.class ); - AnnotationDescriptor COLLECTION_TABLE = createOrmDescriptor( CollectionTable.class ); - AnnotationDescriptor COLUMN = createOrmDescriptor( Column.class ); - AnnotationDescriptor COLUMN_RESULT = createOrmDescriptor( ColumnResult.class ); - AnnotationDescriptor CONSTRUCTOR_RESULT = createOrmDescriptor( ConstructorResult.class ); - AnnotationDescriptor CONVERTS = createOrmDescriptor( Converts.class ); - AnnotationDescriptor CONVERT = createOrmDescriptor( Convert.class, CONVERTS ); - AnnotationDescriptor CONVERTER = createOrmDescriptor( Converter.class ); - AnnotationDescriptor DISCRIMINATOR_COLUMN = createOrmDescriptor( DiscriminatorColumn.class ); - AnnotationDescriptor DISCRIMINATOR_VALUE = createOrmDescriptor( DiscriminatorValue.class ); - AnnotationDescriptor ELEMENT_COLLECTION = createOrmDescriptor( ElementCollection.class ); - AnnotationDescriptor EMBEDDABLE = createOrmDescriptor( Embeddable.class ); - AnnotationDescriptor EMBEDDED = createOrmDescriptor( Embedded.class ); - AnnotationDescriptor EMBEDDED_ID = createOrmDescriptor( EmbeddedId.class ); - AnnotationDescriptor ENTITY = createOrmDescriptor( Entity.class ); - AnnotationDescriptor ENTITY_LISTENERS = createOrmDescriptor( EntityListeners.class ); - AnnotationDescriptor ENTITY_RESULT = createOrmDescriptor( EntityResult.class ); - AnnotationDescriptor ENUMERATED = createOrmDescriptor( Enumerated.class ); - AnnotationDescriptor EXCLUDE_DEFAULT_LISTENERS = createOrmDescriptor( ExcludeDefaultListeners.class ); - AnnotationDescriptor EXCLUDE_SUPERCLASS_LISTENERS = createOrmDescriptor( ExcludeSuperclassListeners.class ); - AnnotationDescriptor FIELD_RESULT = createOrmDescriptor( FieldResult.class ); - AnnotationDescriptor FOREIGN_KEY = createOrmDescriptor( ForeignKey.class ); - AnnotationDescriptor GENERATED_VALUE = createOrmDescriptor( GeneratedValue.class ); - AnnotationDescriptor ID = createOrmDescriptor( Id.class ); - AnnotationDescriptor ID_CLASS = createOrmDescriptor( IdClass.class ); - AnnotationDescriptor INDEX = createOrmDescriptor( Index.class ); - AnnotationDescriptor INHERITANCE = createOrmDescriptor( Inheritance.class ); - AnnotationDescriptor JOIN_COLUMNS = createOrmDescriptor( JoinColumns.class ); - AnnotationDescriptor JOIN_COLUMN = createOrmDescriptor( JoinColumn.class, JOIN_COLUMNS ); - AnnotationDescriptor JOIN_TABLE = createOrmDescriptor( JoinTable.class ); - AnnotationDescriptor LOB = createOrmDescriptor( Lob.class ); - AnnotationDescriptor MANY_TO_MANY = createOrmDescriptor( ManyToMany.class ); - AnnotationDescriptor MANY_TO_ONE = createOrmDescriptor( ManyToOne.class ); - AnnotationDescriptor MAP_KEY = createOrmDescriptor( MapKey.class ); - AnnotationDescriptor MAP_KEY_CLASS = createOrmDescriptor( MapKeyClass.class ); - AnnotationDescriptor MAP_KEY_COLUMN = createOrmDescriptor( MapKeyColumn.class ); - AnnotationDescriptor MAP_KEY_ENUMERATED = createOrmDescriptor( MapKeyEnumerated.class ); - AnnotationDescriptor MAP_KEY_JOIN_COLUMNS = createOrmDescriptor( MapKeyJoinColumns.class ); - AnnotationDescriptor MAP_KEY_JOIN_COLUMN = createOrmDescriptor( MapKeyJoinColumn.class, MAP_KEY_JOIN_COLUMNS ); - AnnotationDescriptor MAP_KEY_TEMPORAL = createOrmDescriptor( MapKeyTemporal.class ); - AnnotationDescriptor MAPPED_SUPERCLASS = createOrmDescriptor( MappedSuperclass.class ); - AnnotationDescriptor MAPS_ID = createOrmDescriptor( MapsId.class ); - AnnotationDescriptor NAMED_ATTRIBUTE_NODE = createOrmDescriptor( NamedAttributeNode.class ); - AnnotationDescriptor NAMED_ENTITY_GRAPHS = createOrmDescriptor( NamedEntityGraphs.class ); - AnnotationDescriptor NAMED_ENTITY_GRAPH = createOrmDescriptor( NamedEntityGraph.class, NAMED_ENTITY_GRAPHS ); - AnnotationDescriptor NAMED_NATIVE_QUERIES = createOrmDescriptor( NamedNativeQueries.class ); - AnnotationDescriptor NAMED_NATIVE_QUERY = createOrmDescriptor( NamedNativeQuery.class, NAMED_NATIVE_QUERIES ); - AnnotationDescriptor NAMED_QUERIES = createOrmDescriptor( NamedQueries.class ); - AnnotationDescriptor NAMED_QUERY = createOrmDescriptor( NamedQuery.class, NAMED_QUERIES ); - AnnotationDescriptor NAMED_STORED_PROCEDURE_QUERIES = createOrmDescriptor( NamedStoredProcedureQueries.class ); - AnnotationDescriptor NAMED_STORED_PROCEDURE_QUERY = createOrmDescriptor( NamedStoredProcedureQuery.class, NAMED_STORED_PROCEDURE_QUERIES ); - AnnotationDescriptor NAMED_SUB_GRAPH = createOrmDescriptor( NamedSubgraph.class ); - AnnotationDescriptor ONE_TO_MANY = createOrmDescriptor( OneToMany.class ); - AnnotationDescriptor ONE_TO_ONE = createOrmDescriptor( OneToOne.class ); - AnnotationDescriptor ORDER_BY = createOrmDescriptor( OrderBy.class ); - AnnotationDescriptor ORDER_COLUMN = createOrmDescriptor( OrderColumn.class ); - AnnotationDescriptor POST_LOAD = createOrmDescriptor( PostLoad.class ); - AnnotationDescriptor POST_PERSIST = createOrmDescriptor( PostPersist.class ); - AnnotationDescriptor POST_REMOVE = createOrmDescriptor( PostRemove.class ); - AnnotationDescriptor POST_UPDATE = createOrmDescriptor( PostUpdate.class ); - AnnotationDescriptor PRE_PERSIST = createOrmDescriptor( PrePersist.class ); - AnnotationDescriptor PRE_REMOVE = createOrmDescriptor( PreRemove.class ); - AnnotationDescriptor PRE_UPDATE = createOrmDescriptor( PreUpdate.class ); - AnnotationDescriptor PRIMARY_KEY_JOIN_COLUMNS = createOrmDescriptor( PrimaryKeyJoinColumns.class ); - AnnotationDescriptor PRIMARY_KEY_JOIN_COLUMN = createOrmDescriptor( PrimaryKeyJoinColumn.class, PRIMARY_KEY_JOIN_COLUMNS ); - AnnotationDescriptor QUERY_HINT = createOrmDescriptor( QueryHint.class ); - AnnotationDescriptor SECONDARY_TABLES = createOrmDescriptor( SecondaryTables.class ); - AnnotationDescriptor SECONDARY_TABLE = createOrmDescriptor( SecondaryTable.class, SECONDARY_TABLES ); - AnnotationDescriptor SEQUENCE_GENERATORS = createOrmDescriptor( SequenceGenerators.class ); - AnnotationDescriptor SEQUENCE_GENERATOR = createOrmDescriptor( SequenceGenerator.class, SEQUENCE_GENERATORS ); - AnnotationDescriptor SQL_RESULT_SET_MAPPINGS = createOrmDescriptor( SqlResultSetMappings.class ); - AnnotationDescriptor SQL_RESULT_SET_MAPPING = createOrmDescriptor( SqlResultSetMapping.class, SQL_RESULT_SET_MAPPINGS ); - AnnotationDescriptor STORED_PROCEDURE_PARAMETER = createOrmDescriptor( StoredProcedureParameter.class ); - AnnotationDescriptor
TABLE = createOrmDescriptor( Table.class ); - AnnotationDescriptor TABLE_GENERATORS = createOrmDescriptor( TableGenerators.class ); - AnnotationDescriptor TABLE_GENERATOR = createOrmDescriptor( TableGenerator.class, TABLE_GENERATORS ); - AnnotationDescriptor TEMPORAL = createOrmDescriptor( Temporal.class ); - AnnotationDescriptor TRANSIENT = createOrmDescriptor( Transient.class ); - AnnotationDescriptor UNIQUE_CONSTRAINT = createOrmDescriptor( UniqueConstraint.class ); - AnnotationDescriptor VERSION = createOrmDescriptor( Version.class ); + OrmAnnotationDescriptor ACCESS = new OrmAnnotationDescriptor<>( + Access.class, + AccessJpaAnnotation.class + ); + + OrmAnnotationDescriptor ASSOCIATION_OVERRIDES = new OrmAnnotationDescriptor<>( + AssociationOverrides.class, + AssociationOverridesJpaAnnotation.class + ); + OrmAnnotationDescriptor ASSOCIATION_OVERRIDE = new OrmAnnotationDescriptor<>( + AssociationOverride.class, + AssociationOverrideJpaAnnotation.class, + ASSOCIATION_OVERRIDES + ); + OrmAnnotationDescriptor ATTRIBUTE_OVERRIDES = new OrmAnnotationDescriptor<>( + AttributeOverrides.class, + AttributeOverridesJpaAnnotation.class + ); + OrmAnnotationDescriptor ATTRIBUTE_OVERRIDE = new OrmAnnotationDescriptor<>( + AttributeOverride.class, + AttributeOverrideJpaAnnotation.class, + ATTRIBUTE_OVERRIDES + ); + OrmAnnotationDescriptor BASIC = new OrmAnnotationDescriptor<>( + Basic.class, + BasicJpaAnnotation.class + ); + OrmAnnotationDescriptor CACHEABLE = new OrmAnnotationDescriptor<>( + Cacheable.class, + CacheableJpaAnnotation.class + ); + OrmAnnotationDescriptor CHECK_CONSTRAINT = new OrmAnnotationDescriptor<>( + CheckConstraint.class, + CheckConstraintJpaAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_TABLE = new OrmAnnotationDescriptor<>( + CollectionTable.class, + CollectionTableJpaAnnotation.class + ); + OrmAnnotationDescriptor COLUMN = new OrmAnnotationDescriptor<>( + Column.class, + ColumnJpaAnnotation.class + ); + OrmAnnotationDescriptor COLUMN_RESULT = new OrmAnnotationDescriptor<>( + ColumnResult.class, + ColumnResultJpaAnnotation.class + ); + OrmAnnotationDescriptor CONSTRUCTOR_RESULT = new OrmAnnotationDescriptor<>( + ConstructorResult.class, + ConstructorResultJpaAnnotation.class + ); + OrmAnnotationDescriptor CONVERTS = new OrmAnnotationDescriptor<>( + Converts.class, + ConvertsJpaAnnotation.class + ); + OrmAnnotationDescriptor CONVERT = new OrmAnnotationDescriptor<>( + Convert.class, + ConvertJpaAnnotation.class, + CONVERTS + ); + OrmAnnotationDescriptor CONVERTER = new OrmAnnotationDescriptor<>( + Converter.class, + ConverterJpaAnnotation.class + ); + OrmAnnotationDescriptor DISCRIMINATOR_COLUMN = new OrmAnnotationDescriptor<>( + DiscriminatorColumn.class, + DiscriminatorColumnJpaAnnotation.class + ); + OrmAnnotationDescriptor DISCRIMINATOR_VALUE = new OrmAnnotationDescriptor<>( + DiscriminatorValue.class, + DiscriminatorValueJpaAnnotation.class + ); + OrmAnnotationDescriptor ELEMENT_COLLECTION = new OrmAnnotationDescriptor<>( + ElementCollection.class, + ElementCollectionJpaAnnotation.class + ); + OrmAnnotationDescriptor EMBEDDABLE = new OrmAnnotationDescriptor<>( + Embeddable.class, + EmbeddableJpaAnnotation.class + ); + OrmAnnotationDescriptor EMBEDDED = new OrmAnnotationDescriptor<>( + Embedded.class, + EmbeddedJpaAnnotation.class + ); + OrmAnnotationDescriptor EMBEDDED_ID = new OrmAnnotationDescriptor<>( + EmbeddedId.class, + EmbeddedIdJpaAnnotation.class + ); + OrmAnnotationDescriptor ENTITY = new OrmAnnotationDescriptor<>( + Entity.class, + EntityJpaAnnotation.class + ); + OrmAnnotationDescriptor ENTITY_LISTENERS = new OrmAnnotationDescriptor<>( + EntityListeners.class, + EntityListenersJpaAnnotation.class + ); + OrmAnnotationDescriptor ENTITY_RESULT = new OrmAnnotationDescriptor<>( + EntityResult.class, + EntityResultJpaAnnotation.class + ); + OrmAnnotationDescriptor ENUMERATED = new OrmAnnotationDescriptor<>( + Enumerated.class, + EnumeratedJpaAnnotation.class + ); + OrmAnnotationDescriptor ENUMERATED_VALUE = new OrmAnnotationDescriptor<>( + EnumeratedValue.class, + EnumeratedValueJpaAnnotation.class + ); + OrmAnnotationDescriptor EXCLUDE_DEFAULT_LISTENERS = new OrmAnnotationDescriptor<>( + ExcludeDefaultListeners.class, + ExcludeDefaultListenersJpaAnnotation.class + ); + OrmAnnotationDescriptor EXCLUDE_SUPERCLASS_LISTENERS = new OrmAnnotationDescriptor<>( + ExcludeSuperclassListeners.class, + ExcludeSuperclassListenersJpaAnnotation.class + ); + OrmAnnotationDescriptor FIELD_RESULT = new OrmAnnotationDescriptor<>( + FieldResult.class, + FieldResultJpaAnnotation.class + ); + OrmAnnotationDescriptor FOREIGN_KEY = new OrmAnnotationDescriptor<>( + ForeignKey.class, + ForeignKeyJpaAnnotation.class + ); + OrmAnnotationDescriptor GENERATED_VALUE = new OrmAnnotationDescriptor<>( + GeneratedValue.class, + GeneratedValueJpaAnnotation.class + ); + OrmAnnotationDescriptor ID = new OrmAnnotationDescriptor<>( + Id.class, + IdJpaAnnotation.class + ); + OrmAnnotationDescriptor ID_CLASS = new OrmAnnotationDescriptor<>( + IdClass.class, + IdClassJpaAnnotation.class + ); + OrmAnnotationDescriptor INDEX = new OrmAnnotationDescriptor<>( + Index.class, + IndexJpaAnnotation.class + ); + OrmAnnotationDescriptor INHERITANCE = new OrmAnnotationDescriptor<>( + Inheritance.class, + InheritanceJpaAnnotation.class + ); + OrmAnnotationDescriptor JOIN_COLUMNS = new OrmAnnotationDescriptor<>( + JoinColumns.class, + JoinColumnsJpaAnnotation.class + ); + OrmAnnotationDescriptor JOIN_COLUMN = new OrmAnnotationDescriptor<>( + JoinColumn.class, + JoinColumnJpaAnnotation.class, + JOIN_COLUMNS + ); + OrmAnnotationDescriptor JOIN_TABLE = new OrmAnnotationDescriptor<>( + JoinTable.class, + JoinTableJpaAnnotation.class + ); + OrmAnnotationDescriptor LOB = new OrmAnnotationDescriptor<>( + Lob.class, + LobJpaAnnotation.class + ); + OrmAnnotationDescriptor MANY_TO_MANY = new OrmAnnotationDescriptor<>( + ManyToMany.class, + ManyToManyJpaAnnotation.class + ); + OrmAnnotationDescriptor MANY_TO_ONE = new OrmAnnotationDescriptor<>( + ManyToOne.class, + ManyToOneJpaAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY = new OrmAnnotationDescriptor<>( + MapKey.class, + MapKeyJpaAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_CLASS = new OrmAnnotationDescriptor<>( + MapKeyClass.class, + MapKeyClassJpaAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_COLUMN = new OrmAnnotationDescriptor<>( + MapKeyColumn.class, + MapKeyColumnJpaAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_ENUMERATED = new OrmAnnotationDescriptor<>( + MapKeyEnumerated.class, + MapKeyEnumeratedJpaAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_JOIN_COLUMNS = new OrmAnnotationDescriptor<>( + MapKeyJoinColumns.class, + MapKeyJoinColumnsJpaAnnotation.class + ); + OrmAnnotationDescriptor MAP_KEY_JOIN_COLUMN = new OrmAnnotationDescriptor<>( + MapKeyJoinColumn.class, + MapKeyJoinColumnJpaAnnotation.class, + MAP_KEY_JOIN_COLUMNS + ); + OrmAnnotationDescriptor MAP_KEY_TEMPORAL = new OrmAnnotationDescriptor<>( + MapKeyTemporal.class, + MapKeyTemporalJpaAnnotation.class + ); + OrmAnnotationDescriptor MAPPED_SUPERCLASS = new OrmAnnotationDescriptor<>( + MappedSuperclass.class, + MappedSuperclassJpaAnnotation.class + ); + OrmAnnotationDescriptor MAPS_ID = new OrmAnnotationDescriptor<>( + MapsId.class, + MapsIdJpaAnnotation.class + ); + OrmAnnotationDescriptor NAMED_ATTRIBUTE_NODE = new OrmAnnotationDescriptor<>( + NamedAttributeNode.class, + NamedAttributeNodeJpaAnnotation.class + ); + OrmAnnotationDescriptor NAMED_ENTITY_GRAPHS = new OrmAnnotationDescriptor<>( + NamedEntityGraphs.class, + NamedEntityGraphsJpaAnnotation.class + ); + OrmAnnotationDescriptor NAMED_ENTITY_GRAPH = new OrmAnnotationDescriptor<>( + NamedEntityGraph.class, + NamedEntityGraphJpaAnnotation.class, + NAMED_ENTITY_GRAPHS + ); + OrmAnnotationDescriptor NAMED_NATIVE_QUERIES = new OrmAnnotationDescriptor<>( + NamedNativeQueries.class, + NamedNativeQueriesJpaAnnotation.class + ); + OrmAnnotationDescriptor NAMED_NATIVE_QUERY = new OrmAnnotationDescriptor<>( + NamedNativeQuery.class, + NamedNativeQueryJpaAnnotation.class, + NAMED_NATIVE_QUERIES + ); + OrmAnnotationDescriptor NAMED_QUERIES = new OrmAnnotationDescriptor<>( + NamedQueries.class, + NamedQueriesJpaAnnotation.class + ); + OrmAnnotationDescriptor NAMED_QUERY = new OrmAnnotationDescriptor<>( + NamedQuery.class, + NamedQueryJpaAnnotation.class, + NAMED_QUERIES + ); + OrmAnnotationDescriptor NAMED_STORED_PROCEDURE_QUERIES = new OrmAnnotationDescriptor<>( + NamedStoredProcedureQueries.class, + NamedStoredProcedureQueriesJpaAnnotation.class + ); + OrmAnnotationDescriptor NAMED_STORED_PROCEDURE_QUERY = new OrmAnnotationDescriptor<>( + NamedStoredProcedureQuery.class, + NamedStoredProcedureQueryJpaAnnotation.class, + NAMED_STORED_PROCEDURE_QUERIES + ); + OrmAnnotationDescriptor NAMED_SUBGRAPH = new OrmAnnotationDescriptor<>( + NamedSubgraph.class, + NamedSubgraphJpaAnnotation.class + ); + OrmAnnotationDescriptor ONE_TO_MANY = new OrmAnnotationDescriptor<>( + OneToMany.class, + OneToManyJpaAnnotation.class + ); + OrmAnnotationDescriptor ONE_TO_ONE = new OrmAnnotationDescriptor<>( + OneToOne.class, + OneToOneJpaAnnotation.class + ); + OrmAnnotationDescriptor ORDER_BY = new OrmAnnotationDescriptor<>( + OrderBy.class, + OrderByJpaAnnotation.class + ); + OrmAnnotationDescriptor ORDER_COLUMN = new OrmAnnotationDescriptor<>( + OrderColumn.class, + OrderColumnJpaAnnotation.class + ); + OrmAnnotationDescriptor POST_LOAD = new OrmAnnotationDescriptor<>( + PostLoad.class, + PostLoadJpaAnnotation.class + ); + OrmAnnotationDescriptor POST_PERSIST = new OrmAnnotationDescriptor<>( + PostPersist.class, + PostPersistJpaAnnotation.class + ); + OrmAnnotationDescriptor POST_REMOVE = new OrmAnnotationDescriptor<>( + PostRemove.class, + PostRemoveJpaAnnotation.class + ); + OrmAnnotationDescriptor POST_UPDATE = new OrmAnnotationDescriptor<>( + PostUpdate.class, + PostUpdateJpaAnnotation.class + ); + OrmAnnotationDescriptor PRE_PERSIST = new OrmAnnotationDescriptor<>( + PrePersist.class, + PrePersistJpaAnnotation.class + ); + OrmAnnotationDescriptor PRE_REMOVE = new OrmAnnotationDescriptor<>( + PreRemove.class, + PreRemoveJpaAnnotation.class + ); + OrmAnnotationDescriptor PRE_UPDATE = new OrmAnnotationDescriptor<>( + PreUpdate.class, + PreUpdateJpaAnnotation.class + ); + OrmAnnotationDescriptor PRIMARY_KEY_JOIN_COLUMNS = new OrmAnnotationDescriptor<>( + PrimaryKeyJoinColumns.class, + PrimaryKeyJoinColumnsJpaAnnotation.class + ); + OrmAnnotationDescriptor PRIMARY_KEY_JOIN_COLUMN = new OrmAnnotationDescriptor<>( + PrimaryKeyJoinColumn.class, + PrimaryKeyJoinColumnJpaAnnotation.class, + PRIMARY_KEY_JOIN_COLUMNS + ); + OrmAnnotationDescriptor QUERY_HINT = new OrmAnnotationDescriptor<>( + QueryHint.class, + QueryHintJpaAnnotation.class + ); + OrmAnnotationDescriptor SECONDARY_TABLES = new OrmAnnotationDescriptor<>( + SecondaryTables.class, + SecondaryTablesJpaAnnotation.class + ); + OrmAnnotationDescriptor SECONDARY_TABLE = new OrmAnnotationDescriptor<>( + SecondaryTable.class, + SecondaryTableJpaAnnotation.class, + SECONDARY_TABLES + ); + OrmAnnotationDescriptor SEQUENCE_GENERATORS = new OrmAnnotationDescriptor<>( + SequenceGenerators.class, + SequenceGeneratorsJpaAnnotation.class + ); + OrmAnnotationDescriptor SEQUENCE_GENERATOR = new OrmAnnotationDescriptor<>( + SequenceGenerator.class, + SequenceGeneratorJpaAnnotation.class, + SEQUENCE_GENERATORS + ); + OrmAnnotationDescriptor SQL_RESULT_SET_MAPPINGS = new OrmAnnotationDescriptor<>( + SqlResultSetMappings.class, + SqlResultSetMappingsJpaAnnotation.class + ); + OrmAnnotationDescriptor SQL_RESULT_SET_MAPPING = new OrmAnnotationDescriptor<>( + SqlResultSetMapping.class, + SqlResultSetMappingJpaAnnotation.class, + SQL_RESULT_SET_MAPPINGS + ); + OrmAnnotationDescriptor STORED_PROCEDURE_PARAMETER = new OrmAnnotationDescriptor<>( + StoredProcedureParameter.class, + StoredProcedureParameterJpaAnnotation.class + ); + OrmAnnotationDescriptor TABLE = new OrmAnnotationDescriptor<>( + Table.class, + TableJpaAnnotation.class + ); + OrmAnnotationDescriptor TABLE_GENERATORS = new OrmAnnotationDescriptor<>( + TableGenerators.class, + TableGeneratorsJpaAnnotation.class + ); + OrmAnnotationDescriptor TABLE_GENERATOR = new OrmAnnotationDescriptor<>( + TableGenerator.class, + TableGeneratorJpaAnnotation.class, + TABLE_GENERATORS + ); + OrmAnnotationDescriptor TEMPORAL = new OrmAnnotationDescriptor<>( + Temporal.class, + TemporalJpaAnnotation.class + ); + OrmAnnotationDescriptor TRANSIENT = new OrmAnnotationDescriptor<>( + Transient.class, + TransientJpaAnnotation.class + ); + OrmAnnotationDescriptor UNIQUE_CONSTRAINT = new OrmAnnotationDescriptor<>( + UniqueConstraint.class, + UniqueConstraintJpaAnnotation.class + ); + OrmAnnotationDescriptor VERSION = new OrmAnnotationDescriptor<>( + Version.class, + VersionJpaAnnotation.class + ); static void forEachAnnotation(Consumer> consumer) { OrmAnnotationHelper.forEachOrmAnnotation( JpaAnnotations.class, consumer ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/XmlAnnotations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/XmlAnnotations.java new file mode 100644 index 0000000000..fdb7e87e40 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/XmlAnnotations.java @@ -0,0 +1,53 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models; + +import java.util.function.Consumer; + +import org.hibernate.boot.internal.Abstract; +import org.hibernate.boot.internal.AnyKeyType; +import org.hibernate.boot.internal.CollectionClassification; +import org.hibernate.boot.internal.Extends; +import org.hibernate.boot.internal.Target; +import org.hibernate.boot.models.annotations.internal.AbstractXmlAnnotation; +import org.hibernate.boot.models.annotations.internal.AnyKeyTypeXmlAnnotation; +import org.hibernate.boot.models.annotations.internal.CollectionClassificationXmlAnnotation; +import org.hibernate.boot.models.annotations.internal.ExtendsXmlAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; +import org.hibernate.boot.models.internal.OrmAnnotationHelper; +import org.hibernate.models.internal.OrmAnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptor; + +/** + * @author Steve Ebersole + */ +public interface XmlAnnotations { + OrmAnnotationDescriptor ABSTRACT = new OrmAnnotationDescriptor<>( + Abstract.class, + AbstractXmlAnnotation.class + ); + OrmAnnotationDescriptor ANY_KEY_TYPE = new OrmAnnotationDescriptor<>( + AnyKeyType.class, + AnyKeyTypeXmlAnnotation.class + ); + OrmAnnotationDescriptor COLLECTION_CLASSIFICATION = new OrmAnnotationDescriptor<>( + CollectionClassification.class, + CollectionClassificationXmlAnnotation.class + ); + OrmAnnotationDescriptor EXTENDS = new OrmAnnotationDescriptor<>( + Extends.class, + ExtendsXmlAnnotation.class + ); + OrmAnnotationDescriptor TARGET = new OrmAnnotationDescriptor<>( + Target.class, + TargetXmlAnnotation.class + ); + + static void forEachAnnotation(Consumer> consumer) { + OrmAnnotationHelper.forEachOrmAnnotation( XmlAnnotations.class, consumer ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AbstractXmlAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AbstractXmlAnnotation.java new file mode 100644 index 0000000000..73396679fc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AbstractXmlAnnotation.java @@ -0,0 +1,25 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.internal.Abstract; +import org.hibernate.models.spi.SourceModelBuildingContext; + +/** + * @author Steve Ebersole + */ +public class AbstractXmlAnnotation implements Abstract { + public AbstractXmlAnnotation(SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Abstract.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AccessJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AccessJpaAnnotation.java new file mode 100644 index 0000000000..14ff32aaa7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AccessJpaAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Access; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AccessJpaAnnotation implements Access { + + private jakarta.persistence.AccessType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AccessJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AccessJpaAnnotation(Access annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.ACCESS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AccessJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.ACCESS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Access.class; + } + + @Override + public jakarta.persistence.AccessType value() { + return value; + } + + public void value(jakarta.persistence.AccessType value) { + this.value = value; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyAnnotation.java new file mode 100644 index 0000000000..cdab33181f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyAnnotation.java @@ -0,0 +1,77 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Any; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyAnnotation implements Any, AttributeMarker, AttributeMarker.Fetchable, AttributeMarker.Optionalable { + private jakarta.persistence.FetchType fetch; + private boolean optional; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyAnnotation(SourceModelBuildingContext modelContext) { + this.fetch = jakarta.persistence.FetchType.EAGER; + this.optional = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyAnnotation(Any annotation, SourceModelBuildingContext modelContext) { + this.fetch = extractJdkValue( annotation, HibernateAnnotations.ANY, "fetch", modelContext ); + this.optional = extractJdkValue( annotation, HibernateAnnotations.ANY, "optional", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.fetch = extractJandexValue( annotation, HibernateAnnotations.ANY, "fetch", modelContext ); + this.optional = extractJandexValue( annotation, HibernateAnnotations.ANY, "optional", modelContext ); + } + + @Override + public Class annotationType() { + return Any.class; + } + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + + @Override + public boolean optional() { + return optional; + } + + public void optional(boolean value) { + this.optional = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorAnnotation.java new file mode 100644 index 0000000000..0771c5c6f8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AnyDiscriminator; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyDiscriminatorAnnotation implements AnyDiscriminator { + private jakarta.persistence.DiscriminatorType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyDiscriminatorAnnotation(SourceModelBuildingContext modelContext) { + this.value = jakarta.persistence.DiscriminatorType.STRING; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyDiscriminatorAnnotation(AnyDiscriminator annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.ANY_DISCRIMINATOR, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyDiscriminatorAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.ANY_DISCRIMINATOR, "value", modelContext ); + } + + @Override + public Class annotationType() { + return AnyDiscriminator.class; + } + + @Override + public jakarta.persistence.DiscriminatorType value() { + return value; + } + + public void value(jakarta.persistence.DiscriminatorType value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorValueAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorValueAnnotation.java new file mode 100644 index 0000000000..3d1d87af01 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorValueAnnotation.java @@ -0,0 +1,94 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AnyDiscriminatorValue; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyDiscriminatorValueAnnotation implements AnyDiscriminatorValue { + private String discriminator; + private java.lang.Class entity; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyDiscriminatorValueAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyDiscriminatorValueAnnotation(AnyDiscriminatorValue annotation, SourceModelBuildingContext modelContext) { + this.discriminator = extractJdkValue( + annotation, + HibernateAnnotations.ANY_DISCRIMINATOR_VALUE, + "discriminator", + modelContext + ); + this.entity = extractJdkValue( + annotation, + HibernateAnnotations.ANY_DISCRIMINATOR_VALUE, + "entity", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyDiscriminatorValueAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.discriminator = extractJandexValue( + annotation, + HibernateAnnotations.ANY_DISCRIMINATOR_VALUE, + "discriminator", + modelContext + ); + this.entity = extractJandexValue( + annotation, + HibernateAnnotations.ANY_DISCRIMINATOR_VALUE, + "entity", + modelContext + ); + } + + @Override + public Class annotationType() { + return AnyDiscriminatorValue.class; + } + + @Override + public String discriminator() { + return discriminator; + } + + public void discriminator(String value) { + this.discriminator = value; + } + + + @Override + public java.lang.Class entity() { + return entity; + } + + public void entity(java.lang.Class value) { + this.entity = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorValuesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorValuesAnnotation.java new file mode 100644 index 0000000000..f6800cd353 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyDiscriminatorValuesAnnotation.java @@ -0,0 +1,76 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.annotations.AnyDiscriminatorValue; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AnyDiscriminatorValues; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyDiscriminatorValuesAnnotation + implements AnyDiscriminatorValues, RepeatableContainer { + private org.hibernate.annotations.AnyDiscriminatorValue[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyDiscriminatorValuesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyDiscriminatorValuesAnnotation( + AnyDiscriminatorValues annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.ANY_DISCRIMINATOR_VALUES, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyDiscriminatorValuesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.ANY_DISCRIMINATOR_VALUES, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return AnyDiscriminatorValues.class; + } + + @Override + public org.hibernate.annotations.AnyDiscriminatorValue[] value() { + return value; + } + + public void value(org.hibernate.annotations.AnyDiscriminatorValue[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeTypeAnnotation.java new file mode 100644 index 0000000000..36019d688b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeTypeAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.models.internal.OrmAnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import org.hibernate.boot.internal.AnyKeyType; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyKeTypeAnnotation implements AnyKeyType { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyKeTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyKeTypeAnnotation(AnyKeyType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, XmlAnnotations.ANY_KEY_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyKeTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, XmlAnnotations.ANY_KEY_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return AnyKeyType.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJavaClassAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJavaClassAnnotation.java new file mode 100644 index 0000000000..5189df0d02 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJavaClassAnnotation.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AnyKeyJavaClass; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyKeyJavaClassAnnotation implements AnyKeyJavaClass { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyKeyJavaClassAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyKeyJavaClassAnnotation(AnyKeyJavaClass annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JAVA_CLASS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyKeyJavaClassAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JAVA_CLASS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return AnyKeyJavaClass.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJavaTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJavaTypeAnnotation.java new file mode 100644 index 0000000000..d5bc87cfe7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJavaTypeAnnotation.java @@ -0,0 +1,71 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AnyKeyJavaType; +import org.hibernate.type.descriptor.java.BasicJavaType; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyKeyJavaTypeAnnotation implements AnyKeyJavaType { + private Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyKeyJavaTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyKeyJavaTypeAnnotation(AnyKeyJavaType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JAVA_TYPE, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyKeyJavaTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JAVA_TYPE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return AnyKeyJavaType.class; + } + + @Override + public Class> value() { + return value; + } + + public void value(Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJdbcTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJdbcTypeAnnotation.java new file mode 100644 index 0000000000..26aa65d8e5 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJdbcTypeAnnotation.java @@ -0,0 +1,71 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AnyKeyJdbcType; +import org.hibernate.type.descriptor.jdbc.JdbcType; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyKeyJdbcTypeAnnotation implements AnyKeyJdbcType { + private Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyKeyJdbcTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyKeyJdbcTypeAnnotation(AnyKeyJdbcType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JDBC_TYPE, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyKeyJdbcTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JDBC_TYPE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return AnyKeyJdbcType.class; + } + + @Override + public Class value() { + return value; + } + + public void value(Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJdbcTypeCodeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJdbcTypeCodeAnnotation.java new file mode 100644 index 0000000000..82ec7c09ff --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyJdbcTypeCodeAnnotation.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AnyKeyJdbcTypeCode; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AnyKeyJdbcTypeCodeAnnotation implements AnyKeyJdbcTypeCode { + private int value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyKeyJdbcTypeCodeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyKeyJdbcTypeCodeAnnotation(AnyKeyJdbcTypeCode annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JDBC_TYPE_CODE, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyKeyJdbcTypeCodeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ANY_KEY_JDBC_TYPE_CODE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return AnyKeyJdbcTypeCode.class; + } + + @Override + public int value() { + return value; + } + + public void value(int value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyTypeXmlAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyTypeXmlAnnotation.java new file mode 100644 index 0000000000..3c86838a9f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AnyKeyTypeXmlAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.internal.Abstract; +import org.hibernate.boot.internal.AnyKeyType; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +public class AnyKeyTypeXmlAnnotation implements AnyKeyType { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AnyKeyTypeXmlAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AnyKeyTypeXmlAnnotation(AnyKeyType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + org.hibernate.boot.models.XmlAnnotations.ANY_KEY_TYPE, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AnyKeyTypeXmlAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + org.hibernate.boot.models.XmlAnnotations.ANY_KEY_TYPE, + "value", + modelContext + ); + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + @Override + public Class annotationType() { + return Abstract.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ArrayAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ArrayAnnotation.java new file mode 100644 index 0000000000..72c4e5df8b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ArrayAnnotation.java @@ -0,0 +1,64 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Array; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ArrayAnnotation implements Array { + private int length; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ArrayAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ArrayAnnotation(Array annotation, SourceModelBuildingContext modelContext) { + this.length = extractJdkValue( annotation, HibernateAnnotations.ARRAY, "length", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ArrayAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.length = extractJandexValue( annotation, HibernateAnnotations.ARRAY, "length", modelContext ); + } + + @Override + public Class annotationType() { + return Array.class; + } + + @Override + public int length() { + return length; + } + + public void length(int value) { + this.length = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AssociationOverrideJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AssociationOverrideJpaAnnotation.java new file mode 100644 index 0000000000..a219e0f968 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AssociationOverrideJpaAnnotation.java @@ -0,0 +1,133 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.AssociationOverride; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AssociationOverrideJpaAnnotation implements AssociationOverride { + + private String name; + private jakarta.persistence.JoinColumn[] joinColumns; + private jakarta.persistence.ForeignKey foreignKey; + private jakarta.persistence.JoinTable joinTable; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AssociationOverrideJpaAnnotation(SourceModelBuildingContext modelContext) { + this.joinColumns = new jakarta.persistence.JoinColumn[0]; + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + this.joinTable = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.JoinTable.class ) + .createUsage( modelContext ); + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AssociationOverrideJpaAnnotation(AssociationOverride annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.ASSOCIATION_OVERRIDE, "name", modelContext ); + this.joinColumns = extractJdkValue( + annotation, + JpaAnnotations.ASSOCIATION_OVERRIDE, + "joinColumns", + modelContext + ); + this.foreignKey = extractJdkValue( + annotation, + JpaAnnotations.ASSOCIATION_OVERRIDE, + "foreignKey", + modelContext + ); + this.joinTable = extractJdkValue( annotation, JpaAnnotations.ASSOCIATION_OVERRIDE, "joinTable", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AssociationOverrideJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.ASSOCIATION_OVERRIDE, "name", modelContext ); + this.joinColumns = extractJandexValue( + annotation, + JpaAnnotations.ASSOCIATION_OVERRIDE, + "joinColumns", + modelContext + ); + this.foreignKey = extractJandexValue( + annotation, + JpaAnnotations.ASSOCIATION_OVERRIDE, + "foreignKey", + modelContext + ); + this.joinTable = extractJandexValue( + annotation, + JpaAnnotations.ASSOCIATION_OVERRIDE, + "joinTable", + modelContext + ); + } + + @Override + public Class annotationType() { + return AssociationOverride.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public jakarta.persistence.JoinColumn[] joinColumns() { + return joinColumns; + } + + public void joinColumns(jakarta.persistence.JoinColumn[] value) { + this.joinColumns = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + + @Override + public jakarta.persistence.JoinTable joinTable() { + return joinTable; + } + + public void joinTable(jakarta.persistence.JoinTable value) { + this.joinTable = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AssociationOverridesJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AssociationOverridesJpaAnnotation.java new file mode 100644 index 0000000000..508de0e439 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AssociationOverridesJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.AssociationOverrides; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AssociationOverridesJpaAnnotation implements AssociationOverrides { + private jakarta.persistence.AssociationOverride[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AssociationOverridesJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AssociationOverridesJpaAnnotation(AssociationOverrides annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.ASSOCIATION_OVERRIDES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AssociationOverridesJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.ASSOCIATION_OVERRIDES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return AssociationOverrides.class; + } + + @Override + public jakarta.persistence.AssociationOverride[] value() { + return value; + } + + public void value(jakarta.persistence.AssociationOverride[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeAccessorAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeAccessorAnnotation.java new file mode 100644 index 0000000000..2eb8cbd768 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeAccessorAnnotation.java @@ -0,0 +1,85 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AttributeAccessor; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AttributeAccessorAnnotation implements AttributeAccessor { + private String value; + private java.lang.Class strategy; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AttributeAccessorAnnotation(SourceModelBuildingContext modelContext) { + this.value = ""; + this.strategy = org.hibernate.property.access.spi.PropertyAccessStrategy.class; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AttributeAccessorAnnotation(AttributeAccessor annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.ATTRIBUTE_ACCESSOR, "value", modelContext ); + this.strategy = extractJdkValue( + annotation, + HibernateAnnotations.ATTRIBUTE_ACCESSOR, + "strategy", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AttributeAccessorAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.ATTRIBUTE_ACCESSOR, "value", modelContext ); + this.strategy = extractJandexValue( + annotation, + HibernateAnnotations.ATTRIBUTE_ACCESSOR, + "strategy", + modelContext + ); + } + + @Override + public Class annotationType() { + return AttributeAccessor.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + + @Override + public java.lang.Class strategy() { + return strategy; + } + + public void strategy(java.lang.Class value) { + this.strategy = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeBinderTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeBinderTypeAnnotation.java new file mode 100644 index 0000000000..97bf389c57 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeBinderTypeAnnotation.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AttributeBinderType; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AttributeBinderTypeAnnotation implements AttributeBinderType { + private java.lang.Class> binder; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AttributeBinderTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AttributeBinderTypeAnnotation(AttributeBinderType annotation, SourceModelBuildingContext modelContext) { + this.binder = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ATTRIBUTE_BINDER_TYPE, + "binder", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AttributeBinderTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.binder = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.ATTRIBUTE_BINDER_TYPE, + "binder", + modelContext + ); + } + + @Override + public Class annotationType() { + return AttributeBinderType.class; + } + + @Override + public java.lang.Class> binder() { + return binder; + } + + public void binder(java.lang.Class> value) { + this.binder = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeOverrideJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeOverrideJpaAnnotation.java new file mode 100644 index 0000000000..b7cff749dc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeOverrideJpaAnnotation.java @@ -0,0 +1,75 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.AttributeOverride; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AttributeOverrideJpaAnnotation implements AttributeOverride { + + private String name; + private jakarta.persistence.Column column; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AttributeOverrideJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AttributeOverrideJpaAnnotation(AttributeOverride annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.ATTRIBUTE_OVERRIDE, "name", modelContext ); + this.column = extractJdkValue( annotation, JpaAnnotations.ATTRIBUTE_OVERRIDE, "column", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AttributeOverrideJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.ATTRIBUTE_OVERRIDE, "name", modelContext ); + this.column = extractJandexValue( annotation, JpaAnnotations.ATTRIBUTE_OVERRIDE, "column", modelContext ); + } + + @Override + public Class annotationType() { + return AttributeOverride.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public jakarta.persistence.Column column() { + return column; + } + + public void column(jakarta.persistence.Column value) { + this.column = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeOverridesJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeOverridesJpaAnnotation.java new file mode 100644 index 0000000000..c18e9863f8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/AttributeOverridesJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.AttributeOverrides; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class AttributeOverridesJpaAnnotation implements AttributeOverrides { + private jakarta.persistence.AttributeOverride[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public AttributeOverridesJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public AttributeOverridesJpaAnnotation(AttributeOverrides annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.ATTRIBUTE_OVERRIDES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public AttributeOverridesJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.ATTRIBUTE_OVERRIDES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return AttributeOverrides.class; + } + + @Override + public jakarta.persistence.AttributeOverride[] value() { + return value; + } + + public void value(jakarta.persistence.AttributeOverride[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BagAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BagAnnotation.java new file mode 100644 index 0000000000..7c8e54f2de --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BagAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Bag; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class BagAnnotation implements Bag { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public BagAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public BagAnnotation(Bag annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public BagAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Bag.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BasicJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BasicJpaAnnotation.java new file mode 100644 index 0000000000..3740a428bf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BasicJpaAnnotation.java @@ -0,0 +1,79 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Basic; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class BasicJpaAnnotation + implements Basic, AttributeMarker, AttributeMarker.Fetchable, AttributeMarker.Optionalable { + + private jakarta.persistence.FetchType fetch; + private boolean optional; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public BasicJpaAnnotation(SourceModelBuildingContext modelContext) { + this.fetch = jakarta.persistence.FetchType.EAGER; + this.optional = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public BasicJpaAnnotation(Basic annotation, SourceModelBuildingContext modelContext) { + this.fetch = extractJdkValue( annotation, JpaAnnotations.BASIC, "fetch", modelContext ); + this.optional = extractJdkValue( annotation, JpaAnnotations.BASIC, "optional", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public BasicJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.fetch = extractJandexValue( annotation, JpaAnnotations.BASIC, "fetch", modelContext ); + this.optional = extractJandexValue( annotation, JpaAnnotations.BASIC, "optional", modelContext ); + } + + @Override + public Class annotationType() { + return Basic.class; + } + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + + @Override + public boolean optional() { + return optional; + } + + public void optional(boolean value) { + this.optional = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BatchSizeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BatchSizeAnnotation.java new file mode 100644 index 0000000000..83c6ce0420 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/BatchSizeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.BatchSize; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class BatchSizeAnnotation implements BatchSize { + private int size; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public BatchSizeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public BatchSizeAnnotation(BatchSize annotation, SourceModelBuildingContext modelContext) { + this.size = extractJdkValue( annotation, HibernateAnnotations.BATCH_SIZE, "size", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public BatchSizeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.size = extractJandexValue( annotation, HibernateAnnotations.BATCH_SIZE, "size", modelContext ); + } + + @Override + public Class annotationType() { + return BatchSize.class; + } + + @Override + public int size() { + return size; + } + + public void size(int value) { + this.size = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CacheAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CacheAnnotation.java new file mode 100644 index 0000000000..9cb6dc8da9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CacheAnnotation.java @@ -0,0 +1,102 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Cache; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CacheAnnotation implements Cache { + private org.hibernate.annotations.CacheConcurrencyStrategy usage; + private String region; + private boolean includeLazy; + private String include; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CacheAnnotation(SourceModelBuildingContext modelContext) { + this.region = ""; + this.includeLazy = true; + this.include = "all"; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CacheAnnotation(Cache annotation, SourceModelBuildingContext modelContext) { + this.usage = extractJdkValue( annotation, HibernateAnnotations.CACHE, "usage", modelContext ); + this.region = extractJdkValue( annotation, HibernateAnnotations.CACHE, "region", modelContext ); + this.includeLazy = extractJdkValue( annotation, HibernateAnnotations.CACHE, "includeLazy", modelContext ); + this.include = extractJdkValue( annotation, HibernateAnnotations.CACHE, "include", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CacheAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.usage = extractJandexValue( annotation, HibernateAnnotations.CACHE, "usage", modelContext ); + this.region = extractJandexValue( annotation, HibernateAnnotations.CACHE, "region", modelContext ); + this.includeLazy = extractJandexValue( annotation, HibernateAnnotations.CACHE, "includeLazy", modelContext ); + this.include = extractJandexValue( annotation, HibernateAnnotations.CACHE, "include", modelContext ); + } + + @Override + public Class annotationType() { + return Cache.class; + } + + @Override + public org.hibernate.annotations.CacheConcurrencyStrategy usage() { + return usage; + } + + public void usage(org.hibernate.annotations.CacheConcurrencyStrategy value) { + this.usage = value; + } + + + @Override + public String region() { + return region; + } + + public void region(String value) { + this.region = value; + } + + + @Override + public boolean includeLazy() { + return includeLazy; + } + + public void includeLazy(boolean value) { + this.includeLazy = value; + } + + + @Override + public String include() { + return include; + } + + public void include(String value) { + this.include = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CacheableJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CacheableJpaAnnotation.java new file mode 100644 index 0000000000..bc4b43b1be --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CacheableJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Cacheable; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CacheableJpaAnnotation implements Cacheable { + private boolean value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CacheableJpaAnnotation(SourceModelBuildingContext modelContext) { + this.value = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CacheableJpaAnnotation(Cacheable annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.CACHEABLE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CacheableJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.CACHEABLE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Cacheable.class; + } + + @Override + public boolean value() { + return value; + } + + public void value(boolean value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CascadeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CascadeAnnotation.java new file mode 100644 index 0000000000..7f258b61d7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CascadeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Cascade; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CascadeAnnotation implements Cascade { + private org.hibernate.annotations.CascadeType[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CascadeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CascadeAnnotation(Cascade annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.CASCADE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CascadeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.CASCADE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Cascade.class; + } + + @Override + public org.hibernate.annotations.CascadeType[] value() { + return value; + } + + public void value(org.hibernate.annotations.CascadeType[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CheckAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CheckAnnotation.java new file mode 100644 index 0000000000..25c62dd398 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CheckAnnotation.java @@ -0,0 +1,94 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Check; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CheckAnnotation implements Check { + private String name; + private String constraints; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CheckAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CheckAnnotation(Check annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.CHECK, + "name", + modelContext + ); + this.constraints = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.CHECK, + "constraints", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CheckAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.CHECK, + "name", + modelContext + ); + this.constraints = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.CHECK, + "constraints", + modelContext + ); + } + + @Override + public Class annotationType() { + return Check.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String constraints() { + return constraints; + } + + public void constraints(String value) { + this.constraints = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CheckConstraintJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CheckConstraintJpaAnnotation.java new file mode 100644 index 0000000000..43736a5320 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CheckConstraintJpaAnnotation.java @@ -0,0 +1,90 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.CheckConstraint; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CheckConstraintJpaAnnotation implements CheckConstraint { + + private String name; + private String constraint; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CheckConstraintJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CheckConstraintJpaAnnotation(CheckConstraint annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.CHECK_CONSTRAINT, "name", modelContext ); + this.constraint = extractJdkValue( annotation, JpaAnnotations.CHECK_CONSTRAINT, "constraint", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.CHECK_CONSTRAINT, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CheckConstraintJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.CHECK_CONSTRAINT, "name", modelContext ); + this.constraint = extractJandexValue( annotation, JpaAnnotations.CHECK_CONSTRAINT, "constraint", modelContext ); + this.options = extractJandexValue( annotation, JpaAnnotations.CHECK_CONSTRAINT, "options", modelContext ); + } + + @Override + public Class annotationType() { + return CheckConstraint.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String constraint() { + return constraint; + } + + public void constraint(String value) { + this.constraint = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ChecksAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ChecksAnnotation.java new file mode 100644 index 0000000000..1d344967d4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ChecksAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Check; +import org.hibernate.annotations.Checks; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ChecksAnnotation implements Checks, RepeatableContainer { + private org.hibernate.annotations.Check[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ChecksAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ChecksAnnotation(Checks annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.CHECKS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ChecksAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.CHECKS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Checks.class; + } + + @Override + public org.hibernate.annotations.Check[] value() { + return value; + } + + public void value(org.hibernate.annotations.Check[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollateAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollateAnnotation.java new file mode 100644 index 0000000000..fed97d4b46 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollateAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Collate; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollateAnnotation implements Collate { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollateAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollateAnnotation(Collate annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COLLATE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollateAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.COLLATE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Collate.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionClassificationXmlAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionClassificationXmlAnnotation.java new file mode 100644 index 0000000000..8cd21ebc08 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionClassificationXmlAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.internal.CollectionClassification; +import org.hibernate.boot.internal.LimitedCollectionClassification; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionClassificationXmlAnnotation implements CollectionClassification { + private LimitedCollectionClassification value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionClassificationXmlAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionClassificationXmlAnnotation( + CollectionClassification annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, XmlAnnotations.COLLECTION_CLASSIFICATION, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionClassificationXmlAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, XmlAnnotations.COLLECTION_CLASSIFICATION, "value", modelContext ); + } + + @Override + public Class annotationType() { + return CollectionClassification.class; + } + + @Override + public LimitedCollectionClassification value() { + return value; + } + + public void value(LimitedCollectionClassification value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdAnnotation.java new file mode 100644 index 0000000000..fe742b5322 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdAnnotation.java @@ -0,0 +1,106 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionId; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionIdAnnotation implements CollectionId { + private jakarta.persistence.Column column; + private java.lang.Class generatorImplementation; + private String generator; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionIdAnnotation(SourceModelBuildingContext modelContext) { + this.column = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.Column.class ) + .createUsage( modelContext ); + this.generatorImplementation = org.hibernate.id.IdentifierGenerator.class; + this.generator = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionIdAnnotation(CollectionId annotation, SourceModelBuildingContext modelContext) { + this.column = extractJdkValue( annotation, HibernateAnnotations.COLLECTION_ID, "column", modelContext ); + this.generatorImplementation = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_ID, + "generatorImplementation", + modelContext + ); + this.generator = extractJdkValue( annotation, HibernateAnnotations.COLLECTION_ID, "generator", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionIdAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.column = extractJandexValue( annotation, HibernateAnnotations.COLLECTION_ID, "column", modelContext ); + this.generatorImplementation = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_ID, + "generatorImplementation", + modelContext + ); + this.generator = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_ID, + "generator", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionId.class; + } + + @Override + public jakarta.persistence.Column column() { + return column; + } + + public void column(jakarta.persistence.Column value) { + this.column = value; + } + + + @Override + public java.lang.Class generatorImplementation() { + return generatorImplementation; + } + + public void generatorImplementation(java.lang.Class value) { + this.generatorImplementation = value; + } + + + @Override + public String generator() { + return generator; + } + + public void generator(String value) { + this.generator = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJavaTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJavaTypeAnnotation.java new file mode 100644 index 0000000000..4af08e52eb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJavaTypeAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionIdJavaType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionIdJavaTypeAnnotation implements CollectionIdJavaType { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionIdJavaTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionIdJavaTypeAnnotation(CollectionIdJavaType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COLLECTION_ID_JAVA_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionIdJavaTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_ID_JAVA_TYPE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionIdJavaType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJdbcTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJdbcTypeAnnotation.java new file mode 100644 index 0000000000..847aba09ca --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJdbcTypeAnnotation.java @@ -0,0 +1,66 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionIdJdbcType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.type.descriptor.jdbc.JdbcType; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionIdJdbcTypeAnnotation implements CollectionIdJdbcType { + private Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionIdJdbcTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionIdJdbcTypeAnnotation(CollectionIdJdbcType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COLLECTION_ID_JDBC_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionIdJdbcTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_ID_JDBC_TYPE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionIdJdbcType.class; + } + + @Override + public Class value() { + return value; + } + + public void value(Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJdbcTypeCodeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJdbcTypeCodeAnnotation.java new file mode 100644 index 0000000000..5aeda2bbaa --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdJdbcTypeCodeAnnotation.java @@ -0,0 +1,72 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionIdJdbcTypeCode; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionIdJdbcTypeCodeAnnotation implements CollectionIdJdbcTypeCode { + private int value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionIdJdbcTypeCodeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionIdJdbcTypeCodeAnnotation( + CollectionIdJdbcTypeCode annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_ID_JDBC_TYPE_CODE, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionIdJdbcTypeCodeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_ID_JDBC_TYPE_CODE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionIdJdbcTypeCode.class; + } + + @Override + public int value() { + return value; + } + + public void value(int value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdMutabilityAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdMutabilityAnnotation.java new file mode 100644 index 0000000000..c08709e365 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdMutabilityAnnotation.java @@ -0,0 +1,72 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionIdMutability; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionIdMutabilityAnnotation implements CollectionIdMutability { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionIdMutabilityAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionIdMutabilityAnnotation( + CollectionIdMutability annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_ID_MUTABILITY, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionIdMutabilityAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_ID_MUTABILITY, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionIdMutability.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdTypeAnnotation.java new file mode 100644 index 0000000000..0a58fbffdf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionIdTypeAnnotation.java @@ -0,0 +1,84 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionIdType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionIdTypeAnnotation implements CollectionIdType { + private java.lang.Class> value; + private org.hibernate.annotations.Parameter[] parameters; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionIdTypeAnnotation(SourceModelBuildingContext modelContext) { + this.parameters = new org.hibernate.annotations.Parameter[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionIdTypeAnnotation(CollectionIdType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COLLECTION_ID_TYPE, "value", modelContext ); + this.parameters = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_ID_TYPE, + "parameters", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionIdTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.COLLECTION_ID_TYPE, "value", modelContext ); + this.parameters = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_ID_TYPE, + "parameters", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionIdType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + + @Override + public org.hibernate.annotations.Parameter[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.Parameter[] value) { + this.parameters = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTableJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTableJpaAnnotation.java new file mode 100644 index 0000000000..24a4d71f59 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTableJpaAnnotation.java @@ -0,0 +1,208 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionTableImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTableImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.CommonTableDetails; +import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; +import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.CollectionTable; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyCatalog; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyOptionalString; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applySchema; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectIndexes; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectUniqueConstraints; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionTableJpaAnnotation implements CollectionTable, CommonTableDetails { + + private String name; + private String catalog; + private String schema; + private jakarta.persistence.JoinColumn[] joinColumns; + private jakarta.persistence.ForeignKey foreignKey; + private jakarta.persistence.UniqueConstraint[] uniqueConstraints; + private jakarta.persistence.Index[] indexes; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionTableJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.catalog = ""; + this.schema = ""; + this.joinColumns = new jakarta.persistence.JoinColumn[0]; + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + this.uniqueConstraints = new jakarta.persistence.UniqueConstraint[0]; + this.indexes = new jakarta.persistence.Index[0]; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionTableJpaAnnotation(CollectionTable annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.COLLECTION_TABLE, "name", modelContext ); + this.catalog = extractJdkValue( annotation, JpaAnnotations.COLLECTION_TABLE, "catalog", modelContext ); + this.schema = extractJdkValue( annotation, JpaAnnotations.COLLECTION_TABLE, "schema", modelContext ); + this.joinColumns = extractJdkValue( annotation, JpaAnnotations.COLLECTION_TABLE, "joinColumns", modelContext ); + this.foreignKey = extractJdkValue( annotation, JpaAnnotations.COLLECTION_TABLE, "foreignKey", modelContext ); + this.uniqueConstraints = extractJdkValue( + annotation, + JpaAnnotations.COLLECTION_TABLE, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJdkValue( annotation, JpaAnnotations.COLLECTION_TABLE, "indexes", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.COLLECTION_TABLE, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionTableJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.COLLECTION_TABLE, "name", modelContext ); + this.catalog = extractJandexValue( annotation, JpaAnnotations.COLLECTION_TABLE, "catalog", modelContext ); + this.schema = extractJandexValue( annotation, JpaAnnotations.COLLECTION_TABLE, "schema", modelContext ); + this.joinColumns = extractJandexValue( + annotation, + JpaAnnotations.COLLECTION_TABLE, + "joinColumns", + modelContext + ); + this.foreignKey = extractJandexValue( annotation, JpaAnnotations.COLLECTION_TABLE, "foreignKey", modelContext ); + this.uniqueConstraints = extractJandexValue( + annotation, + JpaAnnotations.COLLECTION_TABLE, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJandexValue( annotation, JpaAnnotations.COLLECTION_TABLE, "indexes", modelContext ); + this.options = extractJandexValue( annotation, JpaAnnotations.COLLECTION_TABLE, "options", modelContext ); + } + + @Override + public Class annotationType() { + return CollectionTable.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String catalog() { + return catalog; + } + + public void catalog(String value) { + this.catalog = value; + } + + + @Override + public String schema() { + return schema; + } + + public void schema(String value) { + this.schema = value; + } + + + @Override + public jakarta.persistence.JoinColumn[] joinColumns() { + return joinColumns; + } + + public void joinColumns(jakarta.persistence.JoinColumn[] value) { + this.joinColumns = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + + @Override + public jakarta.persistence.UniqueConstraint[] uniqueConstraints() { + return uniqueConstraints; + } + + public void uniqueConstraints(jakarta.persistence.UniqueConstraint[] value) { + this.uniqueConstraints = value; + } + + + @Override + public jakarta.persistence.Index[] indexes() { + return indexes; + } + + public void indexes(jakarta.persistence.Index[] value) { + this.indexes = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + public void apply(JaxbCollectionTableImpl jaxbTable, XmlDocumentContext xmlDocumentContext) { + applyOptionalString( jaxbTable.getName(), this::name ); + applyCatalog( jaxbTable, this, xmlDocumentContext ); + applySchema( jaxbTable, this, xmlDocumentContext ); + applyOptionalString( jaxbTable.getOptions(), this::options ); + + joinColumns( JoinColumnProcessing.transformJoinColumnList( jaxbTable.getJoinColumns(), xmlDocumentContext ) ); + + if ( jaxbTable.getForeignKeys() != null ) { + foreignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbTable.getForeignKeys(), + xmlDocumentContext + ) ); + } + + indexes( collectIndexes( jaxbTable.getIndexes(), xmlDocumentContext ) ); + uniqueConstraints( collectUniqueConstraints( jaxbTable.getUniqueConstraints(), xmlDocumentContext ) ); + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeAnnotation.java new file mode 100644 index 0000000000..c5ef2280cb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeAnnotation.java @@ -0,0 +1,84 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionTypeAnnotation implements CollectionType { + private java.lang.Class type; + private org.hibernate.annotations.Parameter[] parameters; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionTypeAnnotation(SourceModelBuildingContext modelContext) { + this.parameters = new org.hibernate.annotations.Parameter[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionTypeAnnotation(CollectionType annotation, SourceModelBuildingContext modelContext) { + this.type = extractJdkValue( annotation, HibernateAnnotations.COLLECTION_TYPE, "type", modelContext ); + this.parameters = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE, + "parameters", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.type = extractJandexValue( annotation, HibernateAnnotations.COLLECTION_TYPE, "type", modelContext ); + this.parameters = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE, + "parameters", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionType.class; + } + + @Override + public java.lang.Class type() { + return type; + } + + public void type(java.lang.Class value) { + this.type = value; + } + + + @Override + public org.hibernate.annotations.Parameter[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.Parameter[] value) { + this.parameters = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeRegistrationAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeRegistrationAnnotation.java new file mode 100644 index 0000000000..27fd74f558 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeRegistrationAnnotation.java @@ -0,0 +1,121 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionTypeRegistration; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionTypeRegistrationAnnotation implements CollectionTypeRegistration { + private org.hibernate.metamodel.CollectionClassification classification; + private java.lang.Class type; + private org.hibernate.annotations.Parameter[] parameters; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionTypeRegistrationAnnotation(SourceModelBuildingContext modelContext) { + this.parameters = new org.hibernate.annotations.Parameter[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionTypeRegistrationAnnotation( + CollectionTypeRegistration annotation, + SourceModelBuildingContext modelContext) { + this.classification = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATION, + "classification", + modelContext + ); + this.type = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATION, + "type", + modelContext + ); + this.parameters = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATION, + "parameters", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionTypeRegistrationAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.classification = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATION, + "classification", + modelContext + ); + this.type = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATION, + "type", + modelContext + ); + this.parameters = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATION, + "parameters", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionTypeRegistration.class; + } + + @Override + public org.hibernate.metamodel.CollectionClassification classification() { + return classification; + } + + public void classification(org.hibernate.metamodel.CollectionClassification value) { + this.classification = value; + } + + + @Override + public java.lang.Class type() { + return type; + } + + public void type(java.lang.Class value) { + this.type = value; + } + + + @Override + public org.hibernate.annotations.Parameter[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.Parameter[] value) { + this.parameters = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeRegistrationsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeRegistrationsAnnotation.java new file mode 100644 index 0000000000..e3c31fb110 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CollectionTypeRegistrationsAnnotation.java @@ -0,0 +1,77 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CollectionTypeRegistration; +import org.hibernate.annotations.CollectionTypeRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CollectionTypeRegistrationsAnnotation + implements CollectionTypeRegistrations, RepeatableContainer { + private org.hibernate.annotations.CollectionTypeRegistration[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CollectionTypeRegistrationsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CollectionTypeRegistrationsAnnotation( + CollectionTypeRegistrations annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATIONS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CollectionTypeRegistrationsAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.COLLECTION_TYPE_REGISTRATIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return CollectionTypeRegistrations.class; + } + + @Override + public org.hibernate.annotations.CollectionTypeRegistration[] value() { + return value; + } + + public void value(org.hibernate.annotations.CollectionTypeRegistration[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnDefaultAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnDefaultAnnotation.java new file mode 100644 index 0000000000..49c687ff84 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnDefaultAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ColumnDefaultAnnotation implements ColumnDefault { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ColumnDefaultAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ColumnDefaultAnnotation(ColumnDefault annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COLUMN_DEFAULT, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ColumnDefaultAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.COLUMN_DEFAULT, "value", modelContext ); + } + + @Override + public Class annotationType() { + return ColumnDefault.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnJpaAnnotation.java new file mode 100644 index 0000000000..f19fb81ee6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnJpaAnnotation.java @@ -0,0 +1,320 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.CheckConstraintCollector; +import org.hibernate.boot.models.annotations.spi.ColumnDetails; +import org.hibernate.boot.models.annotations.spi.Commentable; +import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Column; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ColumnJpaAnnotation implements Column, + ColumnDetails.Nullable, + ColumnDetails.Mutable, + ColumnDetails.Sizable, + ColumnDetails.Uniqueable, + ColumnDetails.Definable, + ColumnDetails.AlternateTableCapable, + Commentable, + CheckConstraintCollector { + + private String name; + private boolean unique; + private boolean nullable; + private boolean insertable; + private boolean updatable; + private String columnDefinition; + private String options; + private String table; + private int length; + private int precision; + private int scale; + private int secondPrecision; + private jakarta.persistence.CheckConstraint[] check; + private String comment; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ColumnJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.unique = false; + this.nullable = true; + this.insertable = true; + this.updatable = true; + this.columnDefinition = ""; + this.options = ""; + this.table = ""; + this.length = 255; + this.precision = 0; + this.scale = 0; + this.secondPrecision = -1; + this.check = new jakarta.persistence.CheckConstraint[0]; + this.comment = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ColumnJpaAnnotation(Column annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.COLUMN, "name", modelContext ); + this.unique = extractJdkValue( annotation, JpaAnnotations.COLUMN, "unique", modelContext ); + this.nullable = extractJdkValue( annotation, JpaAnnotations.COLUMN, "nullable", modelContext ); + this.insertable = extractJdkValue( annotation, JpaAnnotations.COLUMN, "insertable", modelContext ); + this.updatable = extractJdkValue( annotation, JpaAnnotations.COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJdkValue( annotation, JpaAnnotations.COLUMN, "columnDefinition", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.COLUMN, "options", modelContext ); + this.table = extractJdkValue( annotation, JpaAnnotations.COLUMN, "table", modelContext ); + this.length = extractJdkValue( annotation, JpaAnnotations.COLUMN, "length", modelContext ); + this.precision = extractJdkValue( annotation, JpaAnnotations.COLUMN, "precision", modelContext ); + this.scale = extractJdkValue( annotation, JpaAnnotations.COLUMN, "scale", modelContext ); + this.secondPrecision = extractJdkValue( annotation, JpaAnnotations.COLUMN, "secondPrecision", modelContext ); + this.check = extractJdkValue( annotation, JpaAnnotations.COLUMN, "check", modelContext ); + this.comment = extractJdkValue( annotation, JpaAnnotations.COLUMN, "comment", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ColumnJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.COLUMN, "name", modelContext ); + this.unique = extractJandexValue( annotation, JpaAnnotations.COLUMN, "unique", modelContext ); + this.nullable = extractJandexValue( annotation, JpaAnnotations.COLUMN, "nullable", modelContext ); + this.insertable = extractJandexValue( annotation, JpaAnnotations.COLUMN, "insertable", modelContext ); + this.updatable = extractJandexValue( annotation, JpaAnnotations.COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJandexValue( + annotation, + JpaAnnotations.COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.COLUMN, "options", modelContext ); + this.table = extractJandexValue( annotation, JpaAnnotations.COLUMN, "table", modelContext ); + this.length = extractJandexValue( annotation, JpaAnnotations.COLUMN, "length", modelContext ); + this.precision = extractJandexValue( annotation, JpaAnnotations.COLUMN, "precision", modelContext ); + this.scale = extractJandexValue( annotation, JpaAnnotations.COLUMN, "scale", modelContext ); + this.secondPrecision = extractJandexValue( annotation, JpaAnnotations.COLUMN, "secondPrecision", modelContext ); + this.check = extractJandexValue( annotation, JpaAnnotations.COLUMN, "check", modelContext ); + this.comment = extractJandexValue( annotation, JpaAnnotations.COLUMN, "comment", modelContext ); + } + + @Override + public Class annotationType() { + return Column.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public boolean unique() { + return unique; + } + + public void unique(boolean value) { + this.unique = value; + } + + + @Override + public boolean nullable() { + return nullable; + } + + public void nullable(boolean value) { + this.nullable = value; + } + + + @Override + public boolean insertable() { + return insertable; + } + + public void insertable(boolean value) { + this.insertable = value; + } + + + @Override + public boolean updatable() { + return updatable; + } + + public void updatable(boolean value) { + this.updatable = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + + @Override + public int length() { + return length; + } + + public void length(int value) { + this.length = value; + } + + + @Override + public int precision() { + return precision; + } + + public void precision(int value) { + this.precision = value; + } + + + @Override + public int scale() { + return scale; + } + + public void scale(int value) { + this.scale = value; + } + + + @Override + public int secondPrecision() { + return secondPrecision; + } + + public void secondPrecision(int value) { + this.secondPrecision = value; + } + + + @Override + public jakarta.persistence.CheckConstraint[] check() { + return check; + } + + public void check(jakarta.persistence.CheckConstraint[] value) { + this.check = value; + } + + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + public void apply(JaxbColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) { + table( jaxbColumn.getTable() ); + } + + if ( jaxbColumn.isNullable() != null ) { + nullable( jaxbColumn.isNullable() ); + } + + if ( jaxbColumn.isUnique() != null ) { + unique( jaxbColumn.isUnique() ); + } + + if ( jaxbColumn.isInsertable() != null ) { + insertable( jaxbColumn.isInsertable() ); + } + + if ( jaxbColumn.isUpdatable() != null ) { + updatable( jaxbColumn.isUpdatable() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getComment() ) ) { + comment( jaxbColumn.getComment() ); + } + + if ( jaxbColumn.getLength() != null ) { + length( jaxbColumn.getLength() ); + } + + if ( jaxbColumn.getPrecision() != null ) { + precision( jaxbColumn.getPrecision() ); + } + + if ( jaxbColumn.getScale() != null ) { + scale( jaxbColumn.getScale() ); + } + + if ( jaxbColumn.getSecondPrecision() != null ) { + secondPrecision( jaxbColumn.getSecondPrecision() ); + } + + check( XmlAnnotationHelper.collectCheckConstraints( jaxbColumn.getCheckConstraints(), xmlDocumentContext ) ); + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnResultJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnResultJpaAnnotation.java new file mode 100644 index 0000000000..19b963c31c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnResultJpaAnnotation.java @@ -0,0 +1,75 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.ColumnResult; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ColumnResultJpaAnnotation implements ColumnResult { + private String name; + private java.lang.Class type; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ColumnResultJpaAnnotation(SourceModelBuildingContext modelContext) { + this.type = void.class; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ColumnResultJpaAnnotation(ColumnResult annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.COLUMN_RESULT, "name", modelContext ); + this.type = extractJdkValue( annotation, JpaAnnotations.COLUMN_RESULT, "type", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ColumnResultJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.COLUMN_RESULT, "name", modelContext ); + this.type = extractJandexValue( annotation, JpaAnnotations.COLUMN_RESULT, "type", modelContext ); + } + + @Override + public Class annotationType() { + return ColumnResult.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public java.lang.Class type() { + return type; + } + + public void type(java.lang.Class value) { + this.type = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnTransformerAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnTransformerAnnotation.java new file mode 100644 index 0000000000..c2c7bc54b0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnTransformerAnnotation.java @@ -0,0 +1,99 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ColumnTransformer; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ColumnTransformerAnnotation implements ColumnTransformer { + private String forColumn; + private String read; + private String write; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ColumnTransformerAnnotation(SourceModelBuildingContext modelContext) { + this.forColumn = ""; + this.read = ""; + this.write = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ColumnTransformerAnnotation(ColumnTransformer annotation, SourceModelBuildingContext modelContext) { + this.forColumn = extractJdkValue( + annotation, + HibernateAnnotations.COLUMN_TRANSFORMER, + "forColumn", + modelContext + ); + this.read = extractJdkValue( annotation, HibernateAnnotations.COLUMN_TRANSFORMER, "read", modelContext ); + this.write = extractJdkValue( annotation, HibernateAnnotations.COLUMN_TRANSFORMER, "write", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ColumnTransformerAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.forColumn = extractJandexValue( + annotation, + HibernateAnnotations.COLUMN_TRANSFORMER, + "forColumn", + modelContext + ); + this.read = extractJandexValue( annotation, HibernateAnnotations.COLUMN_TRANSFORMER, "read", modelContext ); + this.write = extractJandexValue( annotation, HibernateAnnotations.COLUMN_TRANSFORMER, "write", modelContext ); + } + + @Override + public Class annotationType() { + return ColumnTransformer.class; + } + + @Override + public String forColumn() { + return forColumn; + } + + public void forColumn(String value) { + this.forColumn = value; + } + + + @Override + public String read() { + return read; + } + + public void read(String value) { + this.read = value; + } + + + @Override + public String write() { + return write; + } + + public void write(String value) { + this.write = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnTransformersAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnTransformersAnnotation.java new file mode 100644 index 0000000000..5b0dbf93dc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnTransformersAnnotation.java @@ -0,0 +1,53 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ColumnTransformer; +import org.hibernate.annotations.ColumnTransformers; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ColumnTransformersAnnotation implements ColumnTransformers, RepeatableContainer { + private org.hibernate.annotations.ColumnTransformer[] value; + + public ColumnTransformersAnnotation(SourceModelBuildingContext modelContext) { + } + + public ColumnTransformersAnnotation(ColumnTransformers annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COLUMN_TRANSFORMERS, "value", modelContext ); + } + + public ColumnTransformersAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.COLUMN_TRANSFORMERS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return ColumnTransformers.class; + } + + @Override + public org.hibernate.annotations.ColumnTransformer[] value() { + return value; + } + + public void value(org.hibernate.annotations.ColumnTransformer[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnsAnnotation.java new file mode 100644 index 0000000000..57d7b7f829 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ColumnsAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Columns; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ColumnsAnnotation implements Columns { + public static final AnnotationDescriptor COLUMNS = null; + + private jakarta.persistence.Column[] columns; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ColumnsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ColumnsAnnotation(Columns annotation, SourceModelBuildingContext modelContext) { + this.columns = extractJdkValue( annotation, HibernateAnnotations.COLUMNS, "columns", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ColumnsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.columns = extractJandexValue( annotation, HibernateAnnotations.COLUMNS, "columns", modelContext ); + } + + @Override + public Class annotationType() { + return Columns.class; + } + + @Override + public jakarta.persistence.Column[] columns() { + return columns; + } + + public void columns(jakarta.persistence.Column[] value) { + this.columns = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CommentAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CommentAnnotation.java new file mode 100644 index 0000000000..e8f8bfb347 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CommentAnnotation.java @@ -0,0 +1,74 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Comment; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CommentAnnotation implements Comment { + private String value; + private String on; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CommentAnnotation(SourceModelBuildingContext modelContext) { + this.on = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CommentAnnotation(Comment annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COMMENT, "value", modelContext ); + this.on = extractJdkValue( annotation, HibernateAnnotations.COMMENT, "on", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CommentAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.COMMENT, "value", modelContext ); + this.on = extractJandexValue( annotation, HibernateAnnotations.COMMENT, "on", modelContext ); + } + + @Override + public Class annotationType() { + return Comment.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + + @Override + public String on() { + return on; + } + + public void on(String value) { + this.on = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CommentsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CommentsAnnotation.java new file mode 100644 index 0000000000..f02499f23e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CommentsAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Comments; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CommentsAnnotation implements Comments, RepeatableContainer { + + private org.hibernate.annotations.Comment[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CommentsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CommentsAnnotation(Comments annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COMMENTS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CommentsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.COMMENTS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Comments.class; + } + + @Override + public org.hibernate.annotations.Comment[] value() { + return value; + } + + public void value(org.hibernate.annotations.Comment[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeAnnotation.java new file mode 100644 index 0000000000..e41c493976 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CompositeType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CompositeTypeAnnotation implements CompositeType { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CompositeTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CompositeTypeAnnotation(CompositeType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.COMPOSITE_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CompositeTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.COMPOSITE_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return CompositeType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeRegistrationAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeRegistrationAnnotation.java new file mode 100644 index 0000000000..412e3724e4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeRegistrationAnnotation.java @@ -0,0 +1,95 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CompositeTypeRegistration; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CompositeTypeRegistrationAnnotation implements CompositeTypeRegistration { + private java.lang.Class embeddableClass; + private java.lang.Class> userType; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CompositeTypeRegistrationAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CompositeTypeRegistrationAnnotation( + CompositeTypeRegistration annotation, + SourceModelBuildingContext modelContext) { + this.embeddableClass = extractJdkValue( + annotation, + HibernateAnnotations.COMPOSITE_TYPE_REGISTRATION, + "embeddableClass", + modelContext + ); + this.userType = extractJdkValue( + annotation, + HibernateAnnotations.COMPOSITE_TYPE_REGISTRATION, + "userType", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CompositeTypeRegistrationAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.embeddableClass = extractJandexValue( + annotation, + HibernateAnnotations.COMPOSITE_TYPE_REGISTRATION, + "embeddableClass", + modelContext + ); + this.userType = extractJandexValue( + annotation, + HibernateAnnotations.COMPOSITE_TYPE_REGISTRATION, + "userType", + modelContext + ); + } + + @Override + public Class annotationType() { + return CompositeTypeRegistration.class; + } + + @Override + public java.lang.Class embeddableClass() { + return embeddableClass; + } + + public void embeddableClass(java.lang.Class value) { + this.embeddableClass = value; + } + + + @Override + public java.lang.Class> userType() { + return userType; + } + + public void userType(java.lang.Class> value) { + this.userType = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeRegistrationsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeRegistrationsAnnotation.java new file mode 100644 index 0000000000..699c97479f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CompositeTypeRegistrationsAnnotation.java @@ -0,0 +1,77 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CompositeTypeRegistration; +import org.hibernate.annotations.CompositeTypeRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CompositeTypeRegistrationsAnnotation + implements CompositeTypeRegistrations, RepeatableContainer { + private org.hibernate.annotations.CompositeTypeRegistration[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CompositeTypeRegistrationsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CompositeTypeRegistrationsAnnotation( + CompositeTypeRegistrations annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.COMPOSITE_TYPE_REGISTRATIONS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CompositeTypeRegistrationsAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.COMPOSITE_TYPE_REGISTRATIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return CompositeTypeRegistrations.class; + } + + @Override + public org.hibernate.annotations.CompositeTypeRegistration[] value() { + return value; + } + + public void value(org.hibernate.annotations.CompositeTypeRegistration[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConcreteProxyAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConcreteProxyAnnotation.java new file mode 100644 index 0000000000..c994d72006 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConcreteProxyAnnotation.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.internal.OrmAnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ConcreteProxy; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ConcreteProxyAnnotation implements ConcreteProxy { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ConcreteProxyAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ConcreteProxyAnnotation(ConcreteProxy annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ConcreteProxyAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return ConcreteProxy.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConstructorResultJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConstructorResultJpaAnnotation.java new file mode 100644 index 0000000000..9f902562ba --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConstructorResultJpaAnnotation.java @@ -0,0 +1,85 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.ConstructorResult; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ConstructorResultJpaAnnotation implements ConstructorResult { + + private java.lang.Class targetClass; + private jakarta.persistence.ColumnResult[] columns; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ConstructorResultJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ConstructorResultJpaAnnotation(ConstructorResult annotation, SourceModelBuildingContext modelContext) { + this.targetClass = extractJdkValue( + annotation, + JpaAnnotations.CONSTRUCTOR_RESULT, + "targetClass", + modelContext + ); + this.columns = extractJdkValue( annotation, JpaAnnotations.CONSTRUCTOR_RESULT, "columns", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ConstructorResultJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.targetClass = extractJandexValue( + annotation, + JpaAnnotations.CONSTRUCTOR_RESULT, + "targetClass", + modelContext + ); + this.columns = extractJandexValue( annotation, JpaAnnotations.CONSTRUCTOR_RESULT, "columns", modelContext ); + } + + @Override + public Class annotationType() { + return ConstructorResult.class; + } + + @Override + public java.lang.Class targetClass() { + return targetClass; + } + + public void targetClass(java.lang.Class value) { + this.targetClass = value; + } + + + @Override + public jakarta.persistence.ColumnResult[] columns() { + return columns; + } + + public void columns(jakarta.persistence.ColumnResult[] value) { + this.columns = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConvertJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConvertJpaAnnotation.java new file mode 100644 index 0000000000..2518d1f2c4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConvertJpaAnnotation.java @@ -0,0 +1,101 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Convert; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ConvertJpaAnnotation implements Convert { + + private java.lang.Class converter; + private String attributeName; + private boolean disableConversion; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ConvertJpaAnnotation(SourceModelBuildingContext modelContext) { + this.converter = jakarta.persistence.AttributeConverter.class; + this.attributeName = ""; + this.disableConversion = false; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ConvertJpaAnnotation(Convert annotation, SourceModelBuildingContext modelContext) { + this.converter = extractJdkValue( annotation, JpaAnnotations.CONVERT, "converter", modelContext ); + this.attributeName = extractJdkValue( annotation, JpaAnnotations.CONVERT, "attributeName", modelContext ); + this.disableConversion = extractJdkValue( + annotation, + JpaAnnotations.CONVERT, + "disableConversion", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ConvertJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.converter = extractJandexValue( annotation, JpaAnnotations.CONVERT, "converter", modelContext ); + this.attributeName = extractJandexValue( annotation, JpaAnnotations.CONVERT, "attributeName", modelContext ); + this.disableConversion = extractJandexValue( + annotation, + JpaAnnotations.CONVERT, + "disableConversion", + modelContext + ); + } + + @Override + public Class annotationType() { + return Convert.class; + } + + @Override + public java.lang.Class converter() { + return converter; + } + + public void converter(java.lang.Class value) { + this.converter = value; + } + + + @Override + public String attributeName() { + return attributeName; + } + + public void attributeName(String value) { + this.attributeName = value; + } + + + @Override + public boolean disableConversion() { + return disableConversion; + } + + public void disableConversion(boolean value) { + this.disableConversion = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterJpaAnnotation.java new file mode 100644 index 0000000000..1a0d9f20f9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterJpaAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Converter; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ConverterJpaAnnotation implements Converter { + + private boolean autoApply; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ConverterJpaAnnotation(SourceModelBuildingContext modelContext) { + this.autoApply = false; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ConverterJpaAnnotation(Converter annotation, SourceModelBuildingContext modelContext) { + this.autoApply = extractJdkValue( annotation, JpaAnnotations.CONVERTER, "autoApply", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ConverterJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.autoApply = extractJandexValue( annotation, JpaAnnotations.CONVERTER, "autoApply", modelContext ); + } + + @Override + public Class annotationType() { + return Converter.class; + } + + @Override + public boolean autoApply() { + return autoApply; + } + + public void autoApply(boolean value) { + this.autoApply = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterRegistrationAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterRegistrationAnnotation.java new file mode 100644 index 0000000000..b857c54871 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterRegistrationAnnotation.java @@ -0,0 +1,118 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ConverterRegistration; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ConverterRegistrationAnnotation implements ConverterRegistration { + private java.lang.Class> converter; + private java.lang.Class domainType; + private boolean autoApply; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ConverterRegistrationAnnotation(SourceModelBuildingContext modelContext) { + this.domainType = void.class; + this.autoApply = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ConverterRegistrationAnnotation(ConverterRegistration annotation, SourceModelBuildingContext modelContext) { + this.converter = extractJdkValue( + annotation, + HibernateAnnotations.CONVERTER_REGISTRATION, + "converter", + modelContext + ); + this.domainType = extractJdkValue( + annotation, + HibernateAnnotations.CONVERTER_REGISTRATION, + "domainType", + modelContext + ); + this.autoApply = extractJdkValue( + annotation, + HibernateAnnotations.CONVERTER_REGISTRATION, + "autoApply", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ConverterRegistrationAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.converter = extractJandexValue( + annotation, + HibernateAnnotations.CONVERTER_REGISTRATION, + "converter", + modelContext + ); + this.domainType = extractJandexValue( + annotation, + HibernateAnnotations.CONVERTER_REGISTRATION, + "domainType", + modelContext + ); + this.autoApply = extractJandexValue( + annotation, + HibernateAnnotations.CONVERTER_REGISTRATION, + "autoApply", + modelContext + ); + } + + @Override + public Class annotationType() { + return ConverterRegistration.class; + } + + @Override + public java.lang.Class> converter() { + return converter; + } + + public void converter(java.lang.Class> value) { + this.converter = value; + } + + + @Override + public java.lang.Class domainType() { + return domainType; + } + + public void domainType(java.lang.Class value) { + this.domainType = value; + } + + + @Override + public boolean autoApply() { + return autoApply; + } + + public void autoApply(boolean value) { + this.autoApply = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterRegistrationsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterRegistrationsAnnotation.java new file mode 100644 index 0000000000..2a140a3f3b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConverterRegistrationsAnnotation.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ConverterRegistration; +import org.hibernate.annotations.ConverterRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ConverterRegistrationsAnnotation + implements ConverterRegistrations, RepeatableContainer { + private org.hibernate.annotations.ConverterRegistration[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ConverterRegistrationsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ConverterRegistrationsAnnotation( + ConverterRegistrations annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.CONVERTER_REGISTRATIONS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ConverterRegistrationsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.CONVERTER_REGISTRATIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return ConverterRegistrations.class; + } + + @Override + public org.hibernate.annotations.ConverterRegistration[] value() { + return value; + } + + public void value(org.hibernate.annotations.ConverterRegistration[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConvertsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConvertsJpaAnnotation.java new file mode 100644 index 0000000000..c08424091f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ConvertsJpaAnnotation.java @@ -0,0 +1,71 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.Converts; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ConvertsJpaAnnotation implements Converts, RepeatableContainer { + private jakarta.persistence.Convert[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ConvertsJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ConvertsJpaAnnotation(Converts annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.CONVERTS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ConvertsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.CONVERTS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return Converts.class; + } + + @Override + public jakarta.persistence.Convert[] value() { + return value; + } + + public void value(jakarta.persistence.Convert[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CreationTimestampAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CreationTimestampAnnotation.java new file mode 100644 index 0000000000..f7b880db56 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CreationTimestampAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CreationTimestampAnnotation implements CreationTimestamp { + private org.hibernate.annotations.SourceType source; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CreationTimestampAnnotation(SourceModelBuildingContext modelContext) { + this.source = org.hibernate.annotations.SourceType.VM; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CreationTimestampAnnotation(CreationTimestamp annotation, SourceModelBuildingContext modelContext) { + this.source = extractJdkValue( annotation, HibernateAnnotations.CREATION_TIMESTAMP, "source", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CreationTimestampAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.source = extractJandexValue( annotation, HibernateAnnotations.CREATION_TIMESTAMP, "source", modelContext ); + } + + @Override + public Class annotationType() { + return CreationTimestamp.class; + } + + @Override + public org.hibernate.annotations.SourceType source() { + return source; + } + + public void source(org.hibernate.annotations.SourceType value) { + this.source = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CurrentTimestampAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CurrentTimestampAnnotation.java new file mode 100644 index 0000000000..a3ee5d8f3f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/CurrentTimestampAnnotation.java @@ -0,0 +1,89 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.CurrentTimestamp; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class CurrentTimestampAnnotation implements CurrentTimestamp { + private org.hibernate.generator.EventType[] event; + private org.hibernate.tuple.GenerationTiming timing; + private org.hibernate.annotations.SourceType source; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public CurrentTimestampAnnotation(SourceModelBuildingContext modelContext) { + this.event = new org.hibernate.generator.EventType[0]; + this.timing = org.hibernate.tuple.GenerationTiming.ALWAYS; + this.source = org.hibernate.annotations.SourceType.DB; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public CurrentTimestampAnnotation(CurrentTimestamp annotation, SourceModelBuildingContext modelContext) { + this.event = extractJdkValue( annotation, HibernateAnnotations.CURRENT_TIMESTAMP, "event", modelContext ); + this.timing = extractJdkValue( annotation, HibernateAnnotations.CURRENT_TIMESTAMP, "timing", modelContext ); + this.source = extractJdkValue( annotation, HibernateAnnotations.CURRENT_TIMESTAMP, "source", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public CurrentTimestampAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.event = extractJandexValue( annotation, HibernateAnnotations.CURRENT_TIMESTAMP, "event", modelContext ); + this.timing = extractJandexValue( annotation, HibernateAnnotations.CURRENT_TIMESTAMP, "timing", modelContext ); + this.source = extractJandexValue( annotation, HibernateAnnotations.CURRENT_TIMESTAMP, "source", modelContext ); + } + + @Override + public Class annotationType() { + return CurrentTimestamp.class; + } + + @Override + public org.hibernate.generator.EventType[] event() { + return event; + } + + public void event(org.hibernate.generator.EventType[] value) { + this.event = value; + } + + + @Override + public org.hibernate.tuple.GenerationTiming timing() { + return timing; + } + + public void timing(org.hibernate.tuple.GenerationTiming value) { + this.timing = value; + } + + + @Override + public org.hibernate.annotations.SourceType source() { + return source; + } + + public void source(org.hibernate.annotations.SourceType value) { + this.source = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorColumnJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorColumnJpaAnnotation.java new file mode 100644 index 0000000000..787ae6c51d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorColumnJpaAnnotation.java @@ -0,0 +1,192 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbDiscriminatorColumnImpl; +import org.hibernate.boot.models.annotations.spi.ColumnDetails; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.DiscriminatorColumn; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class DiscriminatorColumnJpaAnnotation implements DiscriminatorColumn, ColumnDetails { + + private String name; + private jakarta.persistence.DiscriminatorType discriminatorType; + private String columnDefinition; + private String options; + private int length; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public DiscriminatorColumnJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = "DTYPE"; + this.discriminatorType = jakarta.persistence.DiscriminatorType.STRING; + this.columnDefinition = ""; + this.options = ""; + this.length = 31; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public DiscriminatorColumnJpaAnnotation(DiscriminatorColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "name", + modelContext + ); + this.discriminatorType = extractJdkValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "discriminatorType", + modelContext + ); + this.columnDefinition = extractJdkValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJdkValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "options", + modelContext + ); + this.length = extractJdkValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "length", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public DiscriminatorColumnJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "name", + modelContext + ); + this.discriminatorType = extractJandexValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "discriminatorType", + modelContext + ); + this.columnDefinition = extractJandexValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJandexValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "options", + modelContext + ); + this.length = extractJandexValue( + annotation, + org.hibernate.boot.models.JpaAnnotations.DISCRIMINATOR_COLUMN, + "length", + modelContext + ); + } + + @Override + public Class annotationType() { + return DiscriminatorColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public jakarta.persistence.DiscriminatorType discriminatorType() { + return discriminatorType; + } + + public void discriminatorType(jakarta.persistence.DiscriminatorType value) { + this.discriminatorType = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + @Override + public int length() { + return length; + } + + public void length(int value) { + this.length = value; + } + + + public void apply(JaxbDiscriminatorColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( jaxbColumn.getDiscriminatorType() != null ) { + discriminatorType( jaxbColumn.getDiscriminatorType() ); + } + + if ( jaxbColumn.getLength() != null ) { + length( jaxbColumn.getLength() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorFormulaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorFormulaAnnotation.java new file mode 100644 index 0000000000..3ebe9b680e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorFormulaAnnotation.java @@ -0,0 +1,94 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DiscriminatorFormula; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class DiscriminatorFormulaAnnotation implements DiscriminatorFormula { + private String value; + private jakarta.persistence.DiscriminatorType discriminatorType; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public DiscriminatorFormulaAnnotation(SourceModelBuildingContext modelContext) { + this.discriminatorType = jakarta.persistence.DiscriminatorType.STRING; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public DiscriminatorFormulaAnnotation(DiscriminatorFormula annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.DISCRIMINATOR_FORMULA, + "value", + modelContext + ); + this.discriminatorType = extractJdkValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.DISCRIMINATOR_FORMULA, + "discriminatorType", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public DiscriminatorFormulaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.DISCRIMINATOR_FORMULA, + "value", + modelContext + ); + this.discriminatorType = extractJandexValue( + annotation, + org.hibernate.boot.models.HibernateAnnotations.DISCRIMINATOR_FORMULA, + "discriminatorType", + modelContext + ); + } + + @Override + public Class annotationType() { + return DiscriminatorFormula.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + + @Override + public jakarta.persistence.DiscriminatorType discriminatorType() { + return discriminatorType; + } + + public void discriminatorType(jakarta.persistence.DiscriminatorType value) { + this.discriminatorType = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorOptionsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorOptionsAnnotation.java new file mode 100644 index 0000000000..c97e40ebc2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorOptionsAnnotation.java @@ -0,0 +1,85 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DiscriminatorOptions; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class DiscriminatorOptionsAnnotation implements DiscriminatorOptions { + private boolean force; + private boolean insert; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public DiscriminatorOptionsAnnotation(SourceModelBuildingContext modelContext) { + this.force = false; + this.insert = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public DiscriminatorOptionsAnnotation(DiscriminatorOptions annotation, SourceModelBuildingContext modelContext) { + this.force = extractJdkValue( annotation, HibernateAnnotations.DISCRIMINATOR_OPTIONS, "force", modelContext ); + this.insert = extractJdkValue( annotation, HibernateAnnotations.DISCRIMINATOR_OPTIONS, "insert", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public DiscriminatorOptionsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.force = extractJandexValue( + annotation, + HibernateAnnotations.DISCRIMINATOR_OPTIONS, + "force", + modelContext + ); + this.insert = extractJandexValue( + annotation, + HibernateAnnotations.DISCRIMINATOR_OPTIONS, + "insert", + modelContext + ); + } + + @Override + public Class annotationType() { + return DiscriminatorOptions.class; + } + + @Override + public boolean force() { + return force; + } + + public void force(boolean value) { + this.force = value; + } + + + @Override + public boolean insert() { + return insert; + } + + public void insert(boolean value) { + this.insert = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorValueJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorValueJpaAnnotation.java new file mode 100644 index 0000000000..bbabef9be8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DiscriminatorValueJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.DiscriminatorValue; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class DiscriminatorValueJpaAnnotation implements DiscriminatorValue { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public DiscriminatorValueJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public DiscriminatorValueJpaAnnotation(DiscriminatorValue annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.DISCRIMINATOR_VALUE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public DiscriminatorValueJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.DISCRIMINATOR_VALUE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return DiscriminatorValue.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DynamicInsertAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DynamicInsertAnnotation.java new file mode 100644 index 0000000000..abd3b32a01 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DynamicInsertAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class DynamicInsertAnnotation implements DynamicInsert { + private boolean value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public DynamicInsertAnnotation(SourceModelBuildingContext modelContext) { + this.value = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public DynamicInsertAnnotation(DynamicInsert annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.DYNAMIC_INSERT, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public DynamicInsertAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.DYNAMIC_INSERT, "value", modelContext ); + } + + @Override + public Class annotationType() { + return DynamicInsert.class; + } + + @Override + public boolean value() { + return value; + } + + public void value(boolean value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DynamicUpdateAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DynamicUpdateAnnotation.java new file mode 100644 index 0000000000..d6d23f1541 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/DynamicUpdateAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class DynamicUpdateAnnotation implements DynamicUpdate { + private boolean value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public DynamicUpdateAnnotation(SourceModelBuildingContext modelContext) { + this.value = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public DynamicUpdateAnnotation(DynamicUpdate annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.DYNAMIC_UPDATE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public DynamicUpdateAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.DYNAMIC_UPDATE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return DynamicUpdate.class; + } + + @Override + public boolean value() { + return value; + } + + public void value(boolean value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ElementCollectionJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ElementCollectionJpaAnnotation.java new file mode 100644 index 0000000000..73fbe01d91 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ElementCollectionJpaAnnotation.java @@ -0,0 +1,87 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.ElementCollection; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ElementCollectionJpaAnnotation implements ElementCollection, AttributeMarker.Fetchable { + private java.lang.Class targetClass; + private jakarta.persistence.FetchType fetch; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ElementCollectionJpaAnnotation(SourceModelBuildingContext modelContext) { + this.targetClass = void.class; + this.fetch = jakarta.persistence.FetchType.LAZY; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ElementCollectionJpaAnnotation(ElementCollection annotation, SourceModelBuildingContext modelContext) { + this.targetClass = extractJdkValue( + annotation, + JpaAnnotations.ELEMENT_COLLECTION, + "targetClass", + modelContext + ); + this.fetch = extractJdkValue( annotation, JpaAnnotations.ELEMENT_COLLECTION, "fetch", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ElementCollectionJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.targetClass = extractJandexValue( + annotation, + JpaAnnotations.ELEMENT_COLLECTION, + "targetClass", + modelContext + ); + this.fetch = extractJandexValue( annotation, JpaAnnotations.ELEMENT_COLLECTION, "fetch", modelContext ); + } + + @Override + public Class annotationType() { + return ElementCollection.class; + } + + @Override + public java.lang.Class targetClass() { + return targetClass; + } + + public void targetClass(java.lang.Class value) { + this.targetClass = value; + } + + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorAnnotation.java new file mode 100644 index 0000000000..633f232696 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.EmbeddableInstantiator; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EmbeddableInstantiatorAnnotation implements EmbeddableInstantiator { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EmbeddableInstantiatorAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EmbeddableInstantiatorAnnotation( + EmbeddableInstantiator annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.EMBEDDABLE_INSTANTIATOR, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EmbeddableInstantiatorAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.EMBEDDABLE_INSTANTIATOR, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return EmbeddableInstantiator.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorRegistrationAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorRegistrationAnnotation.java new file mode 100644 index 0000000000..da9b1a3b7a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorRegistrationAnnotation.java @@ -0,0 +1,97 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.EmbeddableInstantiatorRegistration; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EmbeddableInstantiatorRegistrationAnnotation implements EmbeddableInstantiatorRegistration { + private java.lang.Class embeddableClass; + private java.lang.Class instantiator; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EmbeddableInstantiatorRegistrationAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EmbeddableInstantiatorRegistrationAnnotation( + EmbeddableInstantiatorRegistration annotation, + SourceModelBuildingContext modelContext) { + this.embeddableClass = extractJdkValue( + annotation, + HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REGISTRATION, + "embeddableClass", + modelContext + ); + this.instantiator = extractJdkValue( + annotation, + HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REGISTRATION, + "instantiator", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EmbeddableInstantiatorRegistrationAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.embeddableClass = extractJandexValue( + annotation, + HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REGISTRATION, + "embeddableClass", + modelContext + ); + this.instantiator = extractJandexValue( + annotation, + HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REGISTRATION, + "instantiator", + modelContext + ); + } + + @Override + public Class annotationType() { + return EmbeddableInstantiatorRegistration.class; + } + + @Override + public java.lang.Class embeddableClass() { + return embeddableClass; + } + + public void embeddableClass(java.lang.Class value) { + this.embeddableClass = value; + } + + + @Override + public java.lang.Class instantiator() { + return instantiator; + } + + public void instantiator(java.lang.Class value) { + this.instantiator = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorRegistrationsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorRegistrationsAnnotation.java new file mode 100644 index 0000000000..1c250cecf6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableInstantiatorRegistrationsAnnotation.java @@ -0,0 +1,77 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.EmbeddableInstantiatorRegistration; +import org.hibernate.annotations.EmbeddableInstantiatorRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EmbeddableInstantiatorRegistrationsAnnotation + implements EmbeddableInstantiatorRegistrations, RepeatableContainer { + private org.hibernate.annotations.EmbeddableInstantiatorRegistration[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EmbeddableInstantiatorRegistrationsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EmbeddableInstantiatorRegistrationsAnnotation( + EmbeddableInstantiatorRegistrations annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REGISTRATIONS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EmbeddableInstantiatorRegistrationsAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REGISTRATIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return EmbeddableInstantiatorRegistrations.class; + } + + @Override + public org.hibernate.annotations.EmbeddableInstantiatorRegistration[] value() { + return value; + } + + public void value(org.hibernate.annotations.EmbeddableInstantiatorRegistration[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableJpaAnnotation.java new file mode 100644 index 0000000000..06483f2ccf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddableJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.Embeddable; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EmbeddableJpaAnnotation implements Embeddable { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EmbeddableJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EmbeddableJpaAnnotation(Embeddable annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EmbeddableJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Embeddable.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddedIdJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddedIdJpaAnnotation.java new file mode 100644 index 0000000000..9fb367219d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddedIdJpaAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.EmbeddedId; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EmbeddedIdJpaAnnotation implements EmbeddedId { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EmbeddedIdJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EmbeddedIdJpaAnnotation(EmbeddedId annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EmbeddedIdJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return EmbeddedId.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddedJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddedJpaAnnotation.java new file mode 100644 index 0000000000..3519c021ba --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EmbeddedJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.Embedded; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EmbeddedJpaAnnotation implements Embedded { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EmbeddedJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EmbeddedJpaAnnotation(Embedded annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EmbeddedJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Embedded.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityJpaAnnotation.java new file mode 100644 index 0000000000..c903a8ccbe --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Entity; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EntityJpaAnnotation implements Entity { + private String name; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EntityJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EntityJpaAnnotation(Entity annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.ENTITY, "name", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EntityJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.ENTITY, "name", modelContext ); + } + + @Override + public Class annotationType() { + return Entity.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityListenersJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityListenersJpaAnnotation.java new file mode 100644 index 0000000000..b83698395e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityListenersJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.EntityListeners; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EntityListenersJpaAnnotation implements EntityListeners { + private java.lang.Class[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EntityListenersJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EntityListenersJpaAnnotation(EntityListeners annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.ENTITY_LISTENERS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EntityListenersJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.ENTITY_LISTENERS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return EntityListeners.class; + } + + @Override + public java.lang.Class[] value() { + return value; + } + + public void value(java.lang.Class[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityResultJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityResultJpaAnnotation.java new file mode 100644 index 0000000000..1f7d68ff33 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EntityResultJpaAnnotation.java @@ -0,0 +1,113 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.EntityResult; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EntityResultJpaAnnotation implements EntityResult { + private java.lang.Class entityClass; + private jakarta.persistence.LockModeType lockMode; + private jakarta.persistence.FieldResult[] fields; + private String discriminatorColumn; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EntityResultJpaAnnotation(SourceModelBuildingContext modelContext) { + this.lockMode = jakarta.persistence.LockModeType.OPTIMISTIC; + this.fields = new jakarta.persistence.FieldResult[0]; + this.discriminatorColumn = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EntityResultJpaAnnotation(EntityResult annotation, SourceModelBuildingContext modelContext) { + this.entityClass = extractJdkValue( annotation, JpaAnnotations.ENTITY_RESULT, "entityClass", modelContext ); + this.lockMode = extractJdkValue( annotation, JpaAnnotations.ENTITY_RESULT, "lockMode", modelContext ); + this.fields = extractJdkValue( annotation, JpaAnnotations.ENTITY_RESULT, "fields", modelContext ); + this.discriminatorColumn = extractJdkValue( + annotation, + JpaAnnotations.ENTITY_RESULT, + "discriminatorColumn", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EntityResultJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.entityClass = extractJandexValue( annotation, JpaAnnotations.ENTITY_RESULT, "entityClass", modelContext ); + this.lockMode = extractJandexValue( annotation, JpaAnnotations.ENTITY_RESULT, "lockMode", modelContext ); + this.fields = extractJandexValue( annotation, JpaAnnotations.ENTITY_RESULT, "fields", modelContext ); + this.discriminatorColumn = extractJandexValue( + annotation, + JpaAnnotations.ENTITY_RESULT, + "discriminatorColumn", + modelContext + ); + } + + @Override + public Class annotationType() { + return EntityResult.class; + } + + @Override + public java.lang.Class entityClass() { + return entityClass; + } + + public void entityClass(java.lang.Class value) { + this.entityClass = value; + } + + + @Override + public jakarta.persistence.LockModeType lockMode() { + return lockMode; + } + + public void lockMode(jakarta.persistence.LockModeType value) { + this.lockMode = value; + } + + + @Override + public jakarta.persistence.FieldResult[] fields() { + return fields; + } + + public void fields(jakarta.persistence.FieldResult[] value) { + this.fields = value; + } + + + @Override + public String discriminatorColumn() { + return discriminatorColumn; + } + + public void discriminatorColumn(String value) { + this.discriminatorColumn = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EnumeratedJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EnumeratedJpaAnnotation.java new file mode 100644 index 0000000000..686f2e5190 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EnumeratedJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Enumerated; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EnumeratedJpaAnnotation implements Enumerated { + private jakarta.persistence.EnumType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EnumeratedJpaAnnotation(SourceModelBuildingContext modelContext) { + this.value = jakarta.persistence.EnumType.ORDINAL; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EnumeratedJpaAnnotation(Enumerated annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.ENUMERATED, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EnumeratedJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.ENUMERATED, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Enumerated.class; + } + + @Override + public jakarta.persistence.EnumType value() { + return value; + } + + public void value(jakarta.persistence.EnumType value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EnumeratedValueJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EnumeratedValueJpaAnnotation.java new file mode 100644 index 0000000000..892dc8492f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/EnumeratedValueJpaAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.EnumeratedValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class EnumeratedValueJpaAnnotation implements EnumeratedValue { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public EnumeratedValueJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public EnumeratedValueJpaAnnotation(EnumeratedValue annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public EnumeratedValueJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return EnumeratedValue.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExcludeDefaultListenersJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExcludeDefaultListenersJpaAnnotation.java new file mode 100644 index 0000000000..776d96840d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExcludeDefaultListenersJpaAnnotation.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.ExcludeDefaultListeners; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ExcludeDefaultListenersJpaAnnotation implements ExcludeDefaultListeners { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ExcludeDefaultListenersJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ExcludeDefaultListenersJpaAnnotation( + ExcludeDefaultListeners annotation, + SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ExcludeDefaultListenersJpaAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return ExcludeDefaultListeners.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExcludeSuperclassListenersJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExcludeSuperclassListenersJpaAnnotation.java new file mode 100644 index 0000000000..a27ad9c0ef --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExcludeSuperclassListenersJpaAnnotation.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.ExcludeSuperclassListeners; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ExcludeSuperclassListenersJpaAnnotation implements ExcludeSuperclassListeners { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ExcludeSuperclassListenersJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ExcludeSuperclassListenersJpaAnnotation( + ExcludeSuperclassListeners annotation, + SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ExcludeSuperclassListenersJpaAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return ExcludeSuperclassListeners.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExtendsXmlAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExtendsXmlAnnotation.java new file mode 100644 index 0000000000..293ca59fa1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ExtendsXmlAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.internal.Extends; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ExtendsXmlAnnotation implements Extends { + private String superType; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ExtendsXmlAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ExtendsXmlAnnotation(Extends annotation, SourceModelBuildingContext modelContext) { + this.superType = extractJdkValue( annotation, XmlAnnotations.EXTENDS, "superType", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ExtendsXmlAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.superType = extractJandexValue( annotation, XmlAnnotations.EXTENDS, "superType", modelContext ); + } + + @Override + public Class annotationType() { + return Extends.class; + } + + @Override + public String superType() { + return superType; + } + + public void superType(String value) { + this.superType = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchAnnotation.java new file mode 100644 index 0000000000..0f19ec879e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Fetch; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FetchAnnotation implements Fetch { + private org.hibernate.annotations.FetchMode value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FetchAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FetchAnnotation(Fetch annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.FETCH, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FetchAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.FETCH, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Fetch.class; + } + + @Override + public org.hibernate.annotations.FetchMode value() { + return value; + } + + public void value(org.hibernate.annotations.FetchMode value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileAnnotation.java new file mode 100644 index 0000000000..6d78775b22 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileAnnotation.java @@ -0,0 +1,84 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FetchProfile; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FetchProfileAnnotation implements FetchProfile { + private String name; + private org.hibernate.annotations.FetchProfile.FetchOverride[] fetchOverrides; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FetchProfileAnnotation(SourceModelBuildingContext modelContext) { + this.fetchOverrides = new org.hibernate.annotations.FetchProfile.FetchOverride[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FetchProfileAnnotation(FetchProfile annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.FETCH_PROFILE, "name", modelContext ); + this.fetchOverrides = extractJdkValue( + annotation, + HibernateAnnotations.FETCH_PROFILE, + "fetchOverrides", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FetchProfileAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.FETCH_PROFILE, "name", modelContext ); + this.fetchOverrides = extractJandexValue( + annotation, + HibernateAnnotations.FETCH_PROFILE, + "fetchOverrides", + modelContext + ); + } + + @Override + public Class annotationType() { + return FetchProfile.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public org.hibernate.annotations.FetchProfile.FetchOverride[] fetchOverrides() { + return fetchOverrides; + } + + public void fetchOverrides(org.hibernate.annotations.FetchProfile.FetchOverride[] value) { + this.fetchOverrides = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileOverrideAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileOverrideAnnotation.java new file mode 100644 index 0000000000..f9c959a858 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileOverrideAnnotation.java @@ -0,0 +1,119 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FetchProfileOverride; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FetchProfileOverrideAnnotation implements FetchProfileOverride { + + private org.hibernate.annotations.FetchMode mode; + private jakarta.persistence.FetchType fetch; + private String profile; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FetchProfileOverrideAnnotation(SourceModelBuildingContext modelContext) { + this.mode = org.hibernate.annotations.FetchMode.JOIN; + this.fetch = jakarta.persistence.FetchType.EAGER; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FetchProfileOverrideAnnotation(FetchProfileOverride annotation, SourceModelBuildingContext modelContext) { + this.mode = extractJdkValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDE, + "mode", + modelContext + ); + this.fetch = extractJdkValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDE, + "fetch", + modelContext + ); + this.profile = extractJdkValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDE, + "profile", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FetchProfileOverrideAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.mode = extractJandexValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDE, + "mode", + modelContext + ); + this.fetch = extractJandexValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDE, + "fetch", + modelContext + ); + this.profile = extractJandexValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDE, + "profile", + modelContext + ); + } + + @Override + public Class annotationType() { + return FetchProfileOverride.class; + } + + @Override + public org.hibernate.annotations.FetchMode mode() { + return mode; + } + + public void mode(org.hibernate.annotations.FetchMode value) { + this.mode = value; + } + + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + + @Override + public String profile() { + return profile; + } + + public void profile(String value) { + this.profile = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileOverridesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileOverridesAnnotation.java new file mode 100644 index 0000000000..5d72a8cddd --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfileOverridesAnnotation.java @@ -0,0 +1,72 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FetchProfileOverrides; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FetchProfileOverridesAnnotation + implements FetchProfileOverrides, RepeatableContainer { + private org.hibernate.annotations.FetchProfileOverride[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FetchProfileOverridesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FetchProfileOverridesAnnotation(FetchProfileOverrides annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDES, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FetchProfileOverridesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + DialectOverrideAnnotations.FETCH_PROFILE_OVERRIDES, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return FetchProfileOverrides.class; + } + + @Override + public org.hibernate.annotations.FetchProfileOverride[] value() { + return value; + } + + public void value(org.hibernate.annotations.FetchProfileOverride[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfilesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfilesAnnotation.java new file mode 100644 index 0000000000..c3a287aed8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FetchProfilesAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FetchProfile; +import org.hibernate.annotations.FetchProfiles; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FetchProfilesAnnotation implements FetchProfiles, RepeatableContainer { + private org.hibernate.annotations.FetchProfile[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FetchProfilesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FetchProfilesAnnotation(FetchProfiles annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.FETCH_PROFILES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FetchProfilesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.FETCH_PROFILES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return FetchProfiles.class; + } + + @Override + public org.hibernate.annotations.FetchProfile[] value() { + return value; + } + + public void value(org.hibernate.annotations.FetchProfile[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FieldResultJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FieldResultJpaAnnotation.java new file mode 100644 index 0000000000..4091edbdb8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FieldResultJpaAnnotation.java @@ -0,0 +1,74 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.FieldResult; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FieldResultJpaAnnotation implements FieldResult { + private String name; + private String column; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FieldResultJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FieldResultJpaAnnotation(FieldResult annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.FIELD_RESULT, "name", modelContext ); + this.column = extractJdkValue( annotation, JpaAnnotations.FIELD_RESULT, "column", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FieldResultJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.FIELD_RESULT, "name", modelContext ); + this.column = extractJandexValue( annotation, JpaAnnotations.FIELD_RESULT, "column", modelContext ); + } + + @Override + public Class annotationType() { + return FieldResult.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String column() { + return column; + } + + public void column(String value) { + this.column = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterAnnotation.java new file mode 100644 index 0000000000..dae6ba48b0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterAnnotation.java @@ -0,0 +1,135 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Filter; +import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.FilterDetails; +import org.hibernate.boot.models.xml.internal.FilterProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FilterAnnotation implements Filter, FilterDetails { + private String name; + private String condition; + private boolean deduceAliasInjectionPoints; + private org.hibernate.annotations.SqlFragmentAlias[] aliases; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FilterAnnotation(SourceModelBuildingContext modelContext) { + this.condition = ""; + this.deduceAliasInjectionPoints = true; + this.aliases = new org.hibernate.annotations.SqlFragmentAlias[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FilterAnnotation(Filter annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.FILTER, "name", modelContext ); + this.condition = extractJdkValue( annotation, HibernateAnnotations.FILTER, "condition", modelContext ); + this.deduceAliasInjectionPoints = extractJdkValue( + annotation, + HibernateAnnotations.FILTER, + "deduceAliasInjectionPoints", + modelContext + ); + this.aliases = extractJdkValue( annotation, HibernateAnnotations.FILTER, "aliases", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FilterAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.FILTER, "name", modelContext ); + this.condition = extractJandexValue( annotation, HibernateAnnotations.FILTER, "condition", modelContext ); + this.deduceAliasInjectionPoints = extractJandexValue( + annotation, + HibernateAnnotations.FILTER, + "deduceAliasInjectionPoints", + modelContext + ); + this.aliases = extractJandexValue( annotation, HibernateAnnotations.FILTER, "aliases", modelContext ); + } + + + @Override + public Class annotationType() { + return Filter.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String condition() { + return condition; + } + + public void condition(String value) { + this.condition = value; + } + + + @Override + public boolean deduceAliasInjectionPoints() { + return deduceAliasInjectionPoints; + } + + public void deduceAliasInjectionPoints(boolean value) { + this.deduceAliasInjectionPoints = value; + } + + + @Override + public org.hibernate.annotations.SqlFragmentAlias[] aliases() { + return aliases; + } + + public void aliases(org.hibernate.annotations.SqlFragmentAlias[] value) { + this.aliases = value; + } + + + @Override + public void apply(JaxbHbmFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext) { + name( jaxbFilter.getName() ); + + if ( StringHelper.isNotEmpty( jaxbFilter.getCondition() ) ) { + condition( jaxbFilter.getCondition() ); + } + + if ( jaxbFilter.isAutoAliasInjection() != null ) { + deduceAliasInjectionPoints( jaxbFilter.isAutoAliasInjection() ); + } + + aliases( FilterProcessing.collectSqlFragmentAliases( + jaxbFilter.getAliases(), + xmlDocumentContext + ) ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefAnnotation.java new file mode 100644 index 0000000000..ce000fd63f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefAnnotation.java @@ -0,0 +1,117 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FilterDef; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FilterDefAnnotation implements FilterDef { + private String name; + private String defaultCondition; + private org.hibernate.annotations.ParamDef[] parameters; + private boolean autoEnabled; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FilterDefAnnotation(SourceModelBuildingContext modelContext) { + this.defaultCondition = ""; + this.parameters = new org.hibernate.annotations.ParamDef[0]; + this.autoEnabled = false; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FilterDefAnnotation(FilterDef annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.FILTER_DEF, "name", modelContext ); + this.defaultCondition = extractJdkValue( + annotation, + HibernateAnnotations.FILTER_DEF, + "defaultCondition", + modelContext + ); + this.parameters = extractJdkValue( annotation, HibernateAnnotations.FILTER_DEF, "parameters", modelContext ); + this.autoEnabled = extractJdkValue( annotation, HibernateAnnotations.FILTER_DEF, "autoEnabled", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FilterDefAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.FILTER_DEF, "name", modelContext ); + this.defaultCondition = extractJandexValue( + annotation, + HibernateAnnotations.FILTER_DEF, + "defaultCondition", + modelContext + ); + this.parameters = extractJandexValue( annotation, HibernateAnnotations.FILTER_DEF, "parameters", modelContext ); + this.autoEnabled = extractJandexValue( + annotation, + HibernateAnnotations.FILTER_DEF, + "autoEnabled", + modelContext + ); + } + + @Override + public Class annotationType() { + return FilterDef.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String defaultCondition() { + return defaultCondition; + } + + public void defaultCondition(String value) { + this.defaultCondition = value; + } + + + @Override + public org.hibernate.annotations.ParamDef[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.ParamDef[] value) { + this.parameters = value; + } + + + @Override + public boolean autoEnabled() { + return autoEnabled; + } + + public void autoEnabled(boolean value) { + this.autoEnabled = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefsAnnotation.java new file mode 100644 index 0000000000..b20facbb53 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterDefsAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.FilterDefs; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FilterDefsAnnotation implements FilterDefs, RepeatableContainer { + private org.hibernate.annotations.FilterDef[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FilterDefsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FilterDefsAnnotation(FilterDefs annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.FILTER_DEFS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FilterDefsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.FILTER_DEFS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return FilterDefs.class; + } + + @Override + public org.hibernate.annotations.FilterDef[] value() { + return value; + } + + public void value(org.hibernate.annotations.FilterDef[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTableAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTableAnnotation.java new file mode 100644 index 0000000000..d2537806b1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTableAnnotation.java @@ -0,0 +1,133 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FilterJoinTable; +import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.models.annotations.spi.FilterDetails; +import org.hibernate.boot.models.xml.internal.FilterProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.HibernateAnnotations.FILTER_JOIN_TABLE; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FilterJoinTableAnnotation implements FilterJoinTable, FilterDetails { + private String name; + private String condition; + private boolean deduceAliasInjectionPoints; + private org.hibernate.annotations.SqlFragmentAlias[] aliases; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FilterJoinTableAnnotation(SourceModelBuildingContext modelContext) { + this.condition = ""; + this.deduceAliasInjectionPoints = true; + this.aliases = new org.hibernate.annotations.SqlFragmentAlias[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FilterJoinTableAnnotation(FilterJoinTable annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, FILTER_JOIN_TABLE, "name", modelContext ); + this.condition = extractJdkValue( annotation, FILTER_JOIN_TABLE, "condition", modelContext ); + this.deduceAliasInjectionPoints = extractJdkValue( + annotation, + FILTER_JOIN_TABLE, + "deduceAliasInjectionPoints", + modelContext + ); + this.aliases = extractJdkValue( annotation, FILTER_JOIN_TABLE, "aliases", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FilterJoinTableAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, FILTER_JOIN_TABLE, "name", modelContext ); + this.condition = extractJandexValue( annotation, FILTER_JOIN_TABLE, "condition", modelContext ); + this.deduceAliasInjectionPoints = extractJandexValue( + annotation, + FILTER_JOIN_TABLE, + "deduceAliasInjectionPoints", + modelContext + ); + this.aliases = extractJandexValue( annotation, FILTER_JOIN_TABLE, "aliases", modelContext ); + } + + @Override + public Class annotationType() { + return FilterJoinTable.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String condition() { + return condition; + } + + public void condition(String value) { + this.condition = value; + } + + + @Override + public boolean deduceAliasInjectionPoints() { + return deduceAliasInjectionPoints; + } + + public void deduceAliasInjectionPoints(boolean value) { + this.deduceAliasInjectionPoints = value; + } + + + @Override + public org.hibernate.annotations.SqlFragmentAlias[] aliases() { + return aliases; + } + + public void aliases(org.hibernate.annotations.SqlFragmentAlias[] value) { + this.aliases = value; + } + + @Override + public void apply(JaxbHbmFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext) { + name( jaxbFilter.getName() ); + + if ( StringHelper.isNotEmpty( jaxbFilter.getCondition() ) ) { + condition( jaxbFilter.getCondition() ); + } + + if ( jaxbFilter.isAutoAliasInjection() != null ) { + deduceAliasInjectionPoints( jaxbFilter.isAutoAliasInjection() ); + } + + aliases( FilterProcessing.collectSqlFragmentAliases( + jaxbFilter.getAliases(), + xmlDocumentContext + ) ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTablesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTablesAnnotation.java new file mode 100644 index 0000000000..8334a43aad --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FilterJoinTablesAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FilterJoinTable; +import org.hibernate.annotations.FilterJoinTables; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FilterJoinTablesAnnotation implements FilterJoinTables, RepeatableContainer { + private org.hibernate.annotations.FilterJoinTable[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FilterJoinTablesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FilterJoinTablesAnnotation(FilterJoinTables annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.FILTER_JOIN_TABLES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FilterJoinTablesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.FILTER_JOIN_TABLES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return FilterJoinTables.class; + } + + @Override + public org.hibernate.annotations.FilterJoinTable[] value() { + return value; + } + + public void value(org.hibernate.annotations.FilterJoinTable[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FiltersAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FiltersAnnotation.java new file mode 100644 index 0000000000..b694d2ecfa --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FiltersAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.Filters; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FiltersAnnotation implements Filters, RepeatableContainer { + private org.hibernate.annotations.Filter[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FiltersAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FiltersAnnotation(Filters annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.FILTERS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FiltersAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.FILTERS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Filters.class; + } + + @Override + public org.hibernate.annotations.Filter[] value() { + return value; + } + + public void value(org.hibernate.annotations.Filter[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ForeignKeyAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ForeignKeyAnnotation.java new file mode 100644 index 0000000000..a9ad2d1579 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ForeignKeyAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import org.hibernate.annotations.ForeignKey; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ForeignKeyAnnotation implements ForeignKey { + private String name; + private String inverseName; + + public ForeignKeyAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.inverseName = ""; + } + + public ForeignKeyAnnotation(ForeignKey annotation, SourceModelBuildingContext modelContext) { + name( annotation.name() ); + inverseName( annotation.inverseName() ); + } + + public ForeignKeyAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + name( extractJandexValue( annotation, HibernateAnnotations.FOREIGN_KEY, "name", modelContext ) ); + inverseName( extractJandexValue( annotation, HibernateAnnotations.FOREIGN_KEY, "inverseName", modelContext ) ); + } + + @Override + public Class annotationType() { + return ForeignKey.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + @Override + public String inverseName() { + return inverseName; + } + + public void inverseName(String value) { + this.inverseName = value; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ForeignKeyJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ForeignKeyJpaAnnotation.java new file mode 100644 index 0000000000..22ebf532a0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ForeignKeyJpaAnnotation.java @@ -0,0 +1,114 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.ForeignKey; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ForeignKeyJpaAnnotation implements ForeignKey { + private String name; + private jakarta.persistence.ConstraintMode value; + private String foreignKeyDefinition; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ForeignKeyJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.value = jakarta.persistence.ConstraintMode.CONSTRAINT; + this.foreignKeyDefinition = ""; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ForeignKeyJpaAnnotation(ForeignKey annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.FOREIGN_KEY, "name", modelContext ); + this.value = extractJdkValue( annotation, JpaAnnotations.FOREIGN_KEY, "value", modelContext ); + this.foreignKeyDefinition = extractJdkValue( + annotation, + JpaAnnotations.FOREIGN_KEY, + "foreignKeyDefinition", + modelContext + ); + this.options = extractJdkValue( annotation, JpaAnnotations.FOREIGN_KEY, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ForeignKeyJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.FOREIGN_KEY, "name", modelContext ); + this.value = extractJandexValue( annotation, JpaAnnotations.FOREIGN_KEY, "value", modelContext ); + this.foreignKeyDefinition = extractJandexValue( + annotation, + JpaAnnotations.FOREIGN_KEY, + "foreignKeyDefinition", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.FOREIGN_KEY, "options", modelContext ); + } + + @Override + public Class annotationType() { + return ForeignKey.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public jakarta.persistence.ConstraintMode value() { + return value; + } + + public void value(jakarta.persistence.ConstraintMode value) { + this.value = value; + } + + + @Override + public String foreignKeyDefinition() { + return foreignKeyDefinition; + } + + public void foreignKeyDefinition(String value) { + this.foreignKeyDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FormulaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FormulaAnnotation.java new file mode 100644 index 0000000000..9110c4a4ca --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FormulaAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Formula; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FormulaAnnotation implements Formula { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FormulaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FormulaAnnotation(Formula annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.FORMULA, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FormulaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.FORMULA, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Formula.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FractionalSecondsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FractionalSecondsAnnotation.java new file mode 100644 index 0000000000..caf2522a44 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/FractionalSecondsAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FractionalSeconds; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class FractionalSecondsAnnotation implements FractionalSeconds { + private int value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public FractionalSecondsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public FractionalSecondsAnnotation(FractionalSeconds annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.FRACTIONAL_SECONDS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public FractionalSecondsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.FRACTIONAL_SECONDS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return FractionalSeconds.class; + } + + @Override + public int value() { + return value; + } + + public void value(int value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedAnnotation.java new file mode 100644 index 0000000000..f5403b691c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedAnnotation.java @@ -0,0 +1,103 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Generated; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class GeneratedAnnotation implements Generated { + private org.hibernate.generator.EventType[] event; + private org.hibernate.annotations.GenerationTime value; + private String sql; + private boolean writable; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public GeneratedAnnotation(SourceModelBuildingContext modelContext) { + this.event = new org.hibernate.generator.EventType[0]; + this.value = org.hibernate.annotations.GenerationTime.INSERT; + this.sql = ""; + this.writable = false; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public GeneratedAnnotation(Generated annotation, SourceModelBuildingContext modelContext) { + this.event = extractJdkValue( annotation, HibernateAnnotations.GENERATED, "event", modelContext ); + this.value = extractJdkValue( annotation, HibernateAnnotations.GENERATED, "value", modelContext ); + this.sql = extractJdkValue( annotation, HibernateAnnotations.GENERATED, "sql", modelContext ); + this.writable = extractJdkValue( annotation, HibernateAnnotations.GENERATED, "writable", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public GeneratedAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.event = extractJandexValue( annotation, HibernateAnnotations.GENERATED, "event", modelContext ); + this.value = extractJandexValue( annotation, HibernateAnnotations.GENERATED, "value", modelContext ); + this.sql = extractJandexValue( annotation, HibernateAnnotations.GENERATED, "sql", modelContext ); + this.writable = extractJandexValue( annotation, HibernateAnnotations.GENERATED, "writable", modelContext ); + } + + @Override + public Class annotationType() { + return Generated.class; + } + + @Override + public org.hibernate.generator.EventType[] event() { + return event; + } + + public void event(org.hibernate.generator.EventType[] value) { + this.event = value; + } + + + @Override + public org.hibernate.annotations.GenerationTime value() { + return value; + } + + public void value(org.hibernate.annotations.GenerationTime value) { + this.value = value; + } + + + @Override + public String sql() { + return sql; + } + + public void sql(String value) { + this.sql = value; + } + + + @Override + public boolean writable() { + return writable; + } + + public void writable(boolean value) { + this.writable = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedColumnAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedColumnAnnotation.java new file mode 100644 index 0000000000..e07591cd19 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedColumnAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.GeneratedColumn; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class GeneratedColumnAnnotation implements GeneratedColumn { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public GeneratedColumnAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public GeneratedColumnAnnotation(GeneratedColumn annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.GENERATED_COLUMN, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public GeneratedColumnAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.GENERATED_COLUMN, "value", modelContext ); + } + + @Override + public Class annotationType() { + return GeneratedColumn.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedValueJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedValueJpaAnnotation.java new file mode 100644 index 0000000000..0d8318427f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratedValueJpaAnnotation.java @@ -0,0 +1,76 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.GeneratedValue; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class GeneratedValueJpaAnnotation implements GeneratedValue { + private jakarta.persistence.GenerationType strategy; + private String generator; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public GeneratedValueJpaAnnotation(SourceModelBuildingContext modelContext) { + this.strategy = jakarta.persistence.GenerationType.AUTO; + this.generator = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public GeneratedValueJpaAnnotation(GeneratedValue annotation, SourceModelBuildingContext modelContext) { + this.strategy = extractJdkValue( annotation, JpaAnnotations.GENERATED_VALUE, "strategy", modelContext ); + this.generator = extractJdkValue( annotation, JpaAnnotations.GENERATED_VALUE, "generator", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public GeneratedValueJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.strategy = extractJandexValue( annotation, JpaAnnotations.GENERATED_VALUE, "strategy", modelContext ); + this.generator = extractJandexValue( annotation, JpaAnnotations.GENERATED_VALUE, "generator", modelContext ); + } + + @Override + public Class annotationType() { + return GeneratedValue.class; + } + + @Override + public jakarta.persistence.GenerationType strategy() { + return strategy; + } + + public void strategy(jakarta.persistence.GenerationType value) { + this.strategy = value; + } + + + @Override + public String generator() { + return generator; + } + + public void generator(String value) { + this.generator = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratorTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratorTypeAnnotation.java new file mode 100644 index 0000000000..9cfb59a2f3 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GeneratorTypeAnnotation.java @@ -0,0 +1,74 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.GeneratorType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class GeneratorTypeAnnotation implements GeneratorType { + private java.lang.Class> type; + private org.hibernate.annotations.GenerationTime when; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public GeneratorTypeAnnotation(SourceModelBuildingContext modelContext) { + this.when = org.hibernate.annotations.GenerationTime.ALWAYS; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public GeneratorTypeAnnotation(GeneratorType annotation, SourceModelBuildingContext modelContext) { + this.type = extractJdkValue( annotation, HibernateAnnotations.GENERATOR_TYPE, "type", modelContext ); + this.when = extractJdkValue( annotation, HibernateAnnotations.GENERATOR_TYPE, "when", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public GeneratorTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.type = extractJandexValue( annotation, HibernateAnnotations.GENERATOR_TYPE, "type", modelContext ); + this.when = extractJandexValue( annotation, HibernateAnnotations.GENERATOR_TYPE, "when", modelContext ); + } + + @Override + public Class annotationType() { + return GeneratorType.class; + } + + @Override + public java.lang.Class> type() { + return type; + } + + public void type(java.lang.Class> value) { + this.type = value; + } + + + @Override + public org.hibernate.annotations.GenerationTime when() { + return when; + } + + public void when(org.hibernate.annotations.GenerationTime value) { + this.when = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GenericGeneratorAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GenericGeneratorAnnotation.java new file mode 100644 index 0000000000..36b3eb442a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GenericGeneratorAnnotation.java @@ -0,0 +1,117 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class GenericGeneratorAnnotation implements GenericGenerator { + private String name; + private java.lang.Class type; + private String strategy; + private org.hibernate.annotations.Parameter[] parameters; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public GenericGeneratorAnnotation(SourceModelBuildingContext modelContext) { + this.type = org.hibernate.generator.Generator.class; + this.strategy = "native"; + this.parameters = new org.hibernate.annotations.Parameter[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public GenericGeneratorAnnotation(GenericGenerator annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.GENERIC_GENERATOR, "name", modelContext ); + this.type = extractJdkValue( annotation, HibernateAnnotations.GENERIC_GENERATOR, "type", modelContext ); + this.strategy = extractJdkValue( annotation, HibernateAnnotations.GENERIC_GENERATOR, "strategy", modelContext ); + this.parameters = extractJdkValue( + annotation, + HibernateAnnotations.GENERIC_GENERATOR, + "parameters", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public GenericGeneratorAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.GENERIC_GENERATOR, "name", modelContext ); + this.type = extractJandexValue( annotation, HibernateAnnotations.GENERIC_GENERATOR, "type", modelContext ); + this.strategy = extractJandexValue( + annotation, + HibernateAnnotations.GENERIC_GENERATOR, + "strategy", + modelContext + ); + this.parameters = extractJandexValue( + annotation, + HibernateAnnotations.GENERIC_GENERATOR, + "parameters", + modelContext + ); + } + + @Override + public Class annotationType() { + return GenericGenerator.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public java.lang.Class type() { + return type; + } + + public void type(java.lang.Class value) { + this.type = value; + } + + + @Override + public String strategy() { + return strategy; + } + + public void strategy(String value) { + this.strategy = value; + } + + + @Override + public org.hibernate.annotations.Parameter[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.Parameter[] value) { + this.parameters = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GenericGeneratorsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GenericGeneratorsAnnotation.java new file mode 100644 index 0000000000..c4b89c775f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/GenericGeneratorsAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.GenericGenerators; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class GenericGeneratorsAnnotation implements GenericGenerators, RepeatableContainer { + private org.hibernate.annotations.GenericGenerator[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public GenericGeneratorsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public GenericGeneratorsAnnotation(GenericGenerators annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.GENERIC_GENERATORS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public GenericGeneratorsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.GENERIC_GENERATORS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return GenericGenerators.class; + } + + @Override + public org.hibernate.annotations.GenericGenerator[] value() { + return value; + } + + public void value(org.hibernate.annotations.GenericGenerator[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/HQLSelectAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/HQLSelectAnnotation.java new file mode 100644 index 0000000000..def8eb061c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/HQLSelectAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.HQLSelect; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class HQLSelectAnnotation implements HQLSelect { + + + private String query; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public HQLSelectAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public HQLSelectAnnotation(HQLSelect annotation, SourceModelBuildingContext modelContext) { + this.query = extractJdkValue( annotation, HibernateAnnotations.HQL_SELECT, "query", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public HQLSelectAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.query = extractJandexValue( annotation, HibernateAnnotations.HQL_SELECT, "query", modelContext ); + } + + @Override + public Class annotationType() { + return HQLSelect.class; + } + + @Override + public String query() { + return query; + } + + public void query(String value) { + this.query = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdClassJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdClassJpaAnnotation.java new file mode 100644 index 0000000000..7c3b7dacd9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdClassJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.IdClass; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class IdClassJpaAnnotation implements IdClass { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public IdClassJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public IdClassJpaAnnotation(IdClass annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.ID_CLASS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public IdClassJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.ID_CLASS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return IdClass.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdGeneratorTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdGeneratorTypeAnnotation.java new file mode 100644 index 0000000000..7443ba4ecf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdGeneratorTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.IdGeneratorType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class IdGeneratorTypeAnnotation implements IdGeneratorType { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public IdGeneratorTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public IdGeneratorTypeAnnotation(IdGeneratorType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.ID_GENERATOR_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public IdGeneratorTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.ID_GENERATOR_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return IdGeneratorType.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdJpaAnnotation.java new file mode 100644 index 0000000000..18c8c74ea2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IdJpaAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Id; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class IdJpaAnnotation implements Id { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public IdJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public IdJpaAnnotation(Id annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public IdJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Id.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ImmutableAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ImmutableAnnotation.java new file mode 100644 index 0000000000..90bd644874 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ImmutableAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Immutable; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ImmutableAnnotation implements Immutable { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ImmutableAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ImmutableAnnotation(Immutable annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ImmutableAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Immutable.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ImportedAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ImportedAnnotation.java new file mode 100644 index 0000000000..5a0d335cdd --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ImportedAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Imported; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ImportedAnnotation implements Imported { + private String rename; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ImportedAnnotation(SourceModelBuildingContext modelContext) { + this.rename = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ImportedAnnotation(Imported annotation, SourceModelBuildingContext modelContext) { + this.rename = extractJdkValue( annotation, HibernateAnnotations.IMPORTED, "rename", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ImportedAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.rename = extractJandexValue( annotation, HibernateAnnotations.IMPORTED, "rename", modelContext ); + } + + @Override + public Class annotationType() { + return Imported.class; + } + + @Override + public String rename() { + return rename; + } + + public void rename(String value) { + this.rename = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexAnnotation.java new file mode 100644 index 0000000000..3d6f74a606 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import org.hibernate.annotations.Index; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class IndexAnnotation implements Index { + private String name; + private String[] columnNames; + + public IndexAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.columnNames = new String[0]; + } + + public IndexAnnotation(Index annotation, SourceModelBuildingContext modelContext) { + name( annotation.name() ); + columnNames( annotation.columnNames() ); + } + + public IndexAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + name( extractJandexValue( annotation, HibernateAnnotations.INDEX, "name", modelContext ) ); + columnNames( extractJandexValue( annotation, HibernateAnnotations.INDEX, "columnNames", modelContext ) ); + } + + @Override + public Class annotationType() { + return Index.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String[] columnNames() { + return columnNames; + } + + public void columnNames(String[] value) { + this.columnNames = value; + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexColumnAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexColumnAnnotation.java new file mode 100644 index 0000000000..e4ae6359fc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexColumnAnnotation.java @@ -0,0 +1,112 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.IndexColumn; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class IndexColumnAnnotation implements IndexColumn { + private String name; + private int base; + private boolean nullable; + private String columnDefinition; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public IndexColumnAnnotation(SourceModelBuildingContext modelContext) { + this.base = 0; + this.nullable = true; + this.columnDefinition = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public IndexColumnAnnotation(IndexColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.INDEX_COLUMN, "name", modelContext ); + this.base = extractJdkValue( annotation, HibernateAnnotations.INDEX_COLUMN, "base", modelContext ); + this.nullable = extractJdkValue( annotation, HibernateAnnotations.INDEX_COLUMN, "nullable", modelContext ); + this.columnDefinition = extractJdkValue( + annotation, + HibernateAnnotations.INDEX_COLUMN, + "columnDefinition", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public IndexColumnAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.INDEX_COLUMN, "name", modelContext ); + this.base = extractJandexValue( annotation, HibernateAnnotations.INDEX_COLUMN, "base", modelContext ); + this.nullable = extractJandexValue( annotation, HibernateAnnotations.INDEX_COLUMN, "nullable", modelContext ); + this.columnDefinition = extractJandexValue( + annotation, + HibernateAnnotations.INDEX_COLUMN, + "columnDefinition", + modelContext + ); + } + + @Override + public Class annotationType() { + return IndexColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public int base() { + return base; + } + + public void base(int value) { + this.base = value; + } + + + @Override + public boolean nullable() { + return nullable; + } + + public void nullable(boolean value) { + this.nullable = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexJpaAnnotation.java new file mode 100644 index 0000000000..835aae15bc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexJpaAnnotation.java @@ -0,0 +1,103 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Index; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class IndexJpaAnnotation implements Index { + private String name; + private String columnList; + private boolean unique; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public IndexJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.unique = false; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public IndexJpaAnnotation(Index annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.INDEX, "name", modelContext ); + this.columnList = extractJdkValue( annotation, JpaAnnotations.INDEX, "columnList", modelContext ); + this.unique = extractJdkValue( annotation, JpaAnnotations.INDEX, "unique", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.INDEX, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public IndexJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.INDEX, "name", modelContext ); + this.columnList = extractJandexValue( annotation, JpaAnnotations.INDEX, "columnList", modelContext ); + this.unique = extractJandexValue( annotation, JpaAnnotations.INDEX, "unique", modelContext ); + this.options = extractJandexValue( annotation, JpaAnnotations.INDEX, "options", modelContext ); + } + + @Override + public Class annotationType() { + return Index.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String columnList() { + return columnList; + } + + public void columnList(String value) { + this.columnList = value; + } + + + @Override + public boolean unique() { + return unique; + } + + public void unique(boolean value) { + this.unique = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/InheritanceJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/InheritanceJpaAnnotation.java new file mode 100644 index 0000000000..74c427ad89 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/InheritanceJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Inheritance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class InheritanceJpaAnnotation implements Inheritance { + private jakarta.persistence.InheritanceType strategy; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public InheritanceJpaAnnotation(SourceModelBuildingContext modelContext) { + this.strategy = jakarta.persistence.InheritanceType.SINGLE_TABLE; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public InheritanceJpaAnnotation(Inheritance annotation, SourceModelBuildingContext modelContext) { + this.strategy = extractJdkValue( annotation, JpaAnnotations.INHERITANCE, "strategy", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public InheritanceJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.strategy = extractJandexValue( annotation, JpaAnnotations.INHERITANCE, "strategy", modelContext ); + } + + @Override + public Class annotationType() { + return Inheritance.class; + } + + @Override + public jakarta.persistence.InheritanceType strategy() { + return strategy; + } + + public void strategy(jakarta.persistence.InheritanceType value) { + this.strategy = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/InstantiatorAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/InstantiatorAnnotation.java new file mode 100644 index 0000000000..01354eeccc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/InstantiatorAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Instantiator; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class InstantiatorAnnotation implements Instantiator { + private String[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public InstantiatorAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public InstantiatorAnnotation(Instantiator annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.INSTANTIATOR, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public InstantiatorAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.INSTANTIATOR, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Instantiator.class; + } + + @Override + public String[] value() { + return value; + } + + public void value(String[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeAnnotation.java new file mode 100644 index 0000000000..b501ddd9cf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JavaType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JavaTypeAnnotation implements JavaType { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JavaTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JavaTypeAnnotation(JavaType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.JAVA_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JavaTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.JAVA_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return JavaType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeRegistrationAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeRegistrationAnnotation.java new file mode 100644 index 0000000000..e4f1ba80d0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeRegistrationAnnotation.java @@ -0,0 +1,93 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JavaTypeRegistration; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JavaTypeRegistrationAnnotation implements JavaTypeRegistration { + private java.lang.Class javaType; + private java.lang.Class> descriptorClass; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JavaTypeRegistrationAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JavaTypeRegistrationAnnotation(JavaTypeRegistration annotation, SourceModelBuildingContext modelContext) { + this.javaType = extractJdkValue( + annotation, + HibernateAnnotations.JAVA_TYPE_REGISTRATION, + "javaType", + modelContext + ); + this.descriptorClass = extractJdkValue( + annotation, + HibernateAnnotations.JAVA_TYPE_REGISTRATION, + "descriptorClass", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JavaTypeRegistrationAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.javaType = extractJandexValue( + annotation, + HibernateAnnotations.JAVA_TYPE_REGISTRATION, + "javaType", + modelContext + ); + this.descriptorClass = extractJandexValue( + annotation, + HibernateAnnotations.JAVA_TYPE_REGISTRATION, + "descriptorClass", + modelContext + ); + } + + @Override + public Class annotationType() { + return JavaTypeRegistration.class; + } + + @Override + public java.lang.Class javaType() { + return javaType; + } + + public void javaType(java.lang.Class value) { + this.javaType = value; + } + + + @Override + public java.lang.Class> descriptorClass() { + return descriptorClass; + } + + public void descriptorClass(java.lang.Class> value) { + this.descriptorClass = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeRegistrationsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeRegistrationsAnnotation.java new file mode 100644 index 0000000000..bc9d79bfda --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JavaTypeRegistrationsAnnotation.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JavaTypeRegistration; +import org.hibernate.annotations.JavaTypeRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JavaTypeRegistrationsAnnotation + implements JavaTypeRegistrations, RepeatableContainer { + private org.hibernate.annotations.JavaTypeRegistration[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JavaTypeRegistrationsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JavaTypeRegistrationsAnnotation(JavaTypeRegistrations annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.JAVA_TYPE_REGISTRATIONS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JavaTypeRegistrationsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.JAVA_TYPE_REGISTRATIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return JavaTypeRegistrations.class; + } + + @Override + public org.hibernate.annotations.JavaTypeRegistration[] value() { + return value; + } + + public void value(org.hibernate.annotations.JavaTypeRegistration[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeAnnotation.java new file mode 100644 index 0000000000..639d4f6f44 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JdbcType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JdbcTypeAnnotation implements JdbcType { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JdbcTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JdbcTypeAnnotation(JdbcType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.JDBC_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JdbcTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.JDBC_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return JdbcType.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeCodeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeCodeAnnotation.java new file mode 100644 index 0000000000..56dfa020de --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeCodeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JdbcTypeCodeAnnotation implements JdbcTypeCode { + private int value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JdbcTypeCodeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JdbcTypeCodeAnnotation(JdbcTypeCode annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.JDBC_TYPE_CODE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JdbcTypeCodeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.JDBC_TYPE_CODE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return JdbcTypeCode.class; + } + + @Override + public int value() { + return value; + } + + public void value(int value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeRegistrationAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeRegistrationAnnotation.java new file mode 100644 index 0000000000..88c84099ba --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeRegistrationAnnotation.java @@ -0,0 +1,89 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JdbcTypeRegistration; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JdbcTypeRegistrationAnnotation implements JdbcTypeRegistration { + private java.lang.Class value; + private int registrationCode; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JdbcTypeRegistrationAnnotation(SourceModelBuildingContext modelContext) { + this.registrationCode = -2147483648; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JdbcTypeRegistrationAnnotation(JdbcTypeRegistration annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.JDBC_TYPE_REGISTRATION, "value", modelContext ); + this.registrationCode = extractJdkValue( + annotation, + HibernateAnnotations.JDBC_TYPE_REGISTRATION, + "registrationCode", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JdbcTypeRegistrationAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.JDBC_TYPE_REGISTRATION, + "value", + modelContext + ); + this.registrationCode = extractJandexValue( + annotation, + HibernateAnnotations.JDBC_TYPE_REGISTRATION, + "registrationCode", + modelContext + ); + } + + @Override + public Class annotationType() { + return JdbcTypeRegistration.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + + @Override + public int registrationCode() { + return registrationCode; + } + + public void registrationCode(int value) { + this.registrationCode = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeRegistrationsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeRegistrationsAnnotation.java new file mode 100644 index 0000000000..0190cfa971 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JdbcTypeRegistrationsAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JdbcTypeRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JdbcTypeRegistrationsAnnotation + implements JdbcTypeRegistrations, RepeatableContainer { + private org.hibernate.annotations.JdbcTypeRegistration[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JdbcTypeRegistrationsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JdbcTypeRegistrationsAnnotation(JdbcTypeRegistrations annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.JDBC_TYPE_REGISTRATIONS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JdbcTypeRegistrationsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.JDBC_TYPE_REGISTRATIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return JdbcTypeRegistrations.class; + } + + @Override + public org.hibernate.annotations.JdbcTypeRegistration[] value() { + return value; + } + + public void value(org.hibernate.annotations.JdbcTypeRegistration[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnJpaAnnotation.java new file mode 100644 index 0000000000..ce9a061432 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnJpaAnnotation.java @@ -0,0 +1,363 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinColumnImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; +import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.JoinColumn; +import jakarta.persistence.MapKeyJoinColumn; +import jakarta.persistence.PrimaryKeyJoinColumn; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JoinColumnJpaAnnotation implements JoinColumn { + private String name; + private String referencedColumnName; + private boolean unique; + private boolean nullable; + private boolean insertable; + private boolean updatable; + private String columnDefinition; + private String options; + private String table; + private jakarta.persistence.ForeignKey foreignKey; + private jakarta.persistence.CheckConstraint[] check; + private String comment; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JoinColumnJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.referencedColumnName = ""; + this.unique = false; + this.nullable = true; + this.insertable = true; + this.updatable = true; + this.columnDefinition = ""; + this.options = ""; + this.table = ""; + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + this.check = new jakarta.persistence.CheckConstraint[0]; + this.comment = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JoinColumnJpaAnnotation(JoinColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "name", modelContext ); + this.referencedColumnName = extractJdkValue( + annotation, + JpaAnnotations.JOIN_COLUMN, + "referencedColumnName", + modelContext + ); + this.unique = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "unique", modelContext ); + this.nullable = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "nullable", modelContext ); + this.insertable = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "insertable", modelContext ); + this.updatable = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJdkValue( + annotation, + JpaAnnotations.JOIN_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "options", modelContext ); + this.table = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "table", modelContext ); + this.foreignKey = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "foreignKey", modelContext ); + this.check = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "check", modelContext ); + this.comment = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMN, "comment", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JoinColumnJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "name", modelContext ); + this.referencedColumnName = extractJandexValue( + annotation, + JpaAnnotations.JOIN_COLUMN, + "referencedColumnName", + modelContext + ); + this.unique = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "unique", modelContext ); + this.nullable = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "nullable", modelContext ); + this.insertable = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "insertable", modelContext ); + this.updatable = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJandexValue( + annotation, + JpaAnnotations.JOIN_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "options", modelContext ); + this.table = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "table", modelContext ); + this.foreignKey = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "foreignKey", modelContext ); + this.check = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "check", modelContext ); + this.comment = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMN, "comment", modelContext ); + } + + @Override + public Class annotationType() { + return JoinColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String referencedColumnName() { + return referencedColumnName; + } + + public void referencedColumnName(String value) { + this.referencedColumnName = value; + } + + + @Override + public boolean unique() { + return unique; + } + + public void unique(boolean value) { + this.unique = value; + } + + + @Override + public boolean nullable() { + return nullable; + } + + public void nullable(boolean value) { + this.nullable = value; + } + + + @Override + public boolean insertable() { + return insertable; + } + + public void insertable(boolean value) { + this.insertable = value; + } + + + @Override + public boolean updatable() { + return updatable; + } + + public void updatable(boolean value) { + this.updatable = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + + @Override + public jakarta.persistence.CheckConstraint[] check() { + return check; + } + + public void check(jakarta.persistence.CheckConstraint[] value) { + this.check = value; + } + + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + + public void apply(JaxbJoinColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) { + table( jaxbColumn.getTable() ); + } + + if ( jaxbColumn.isNullable() != null ) { + nullable( jaxbColumn.isNullable() ); + } + + if ( jaxbColumn.isInsertable() != null ) { + insertable( jaxbColumn.isInsertable() ); + } + if ( jaxbColumn.isUpdatable() != null ) { + updatable( jaxbColumn.isUpdatable() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + + if ( jaxbColumn.isUnique() != null ) { + unique( jaxbColumn.isUnique() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getComment() ) ) { + comment( jaxbColumn.getComment() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getReferencedColumnName() ) ) { + referencedColumnName( jaxbColumn.getReferencedColumnName() ); + } + + if ( jaxbColumn.getForeignKey() != null ) { + foreignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbColumn.getForeignKey(), + xmlDocumentContext + ) ); + } + + check( XmlAnnotationHelper.collectCheckConstraints( jaxbColumn.getCheckConstraints(), xmlDocumentContext ) ); + } + + public void apply(JaxbColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + // NOTE : used for handling mappings + + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) { + table( jaxbColumn.getTable() ); + } + + if ( jaxbColumn.isNullable() != null ) { + nullable( jaxbColumn.isNullable() ); + } + + if ( jaxbColumn.isInsertable() != null ) { + insertable( jaxbColumn.isInsertable() ); + } + if ( jaxbColumn.isInsertable() != null ) { + updatable( jaxbColumn.isUpdatable() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + + if ( jaxbColumn.isUnique() != null ) { + unique( jaxbColumn.isUnique() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getComment() ) ) { + comment( jaxbColumn.getComment() ); + } + + check( XmlAnnotationHelper.collectCheckConstraints( jaxbColumn.getCheckConstraints(), xmlDocumentContext ) ); + } + + public static JoinColumn toJoinColumn( + PrimaryKeyJoinColumn pkJoinColumn, + SourceModelBuildingContext sourceModelBuildingContext) { + final JoinColumnJpaAnnotation joinColumn = JpaAnnotations.JOIN_COLUMN.createUsage( sourceModelBuildingContext ); + joinColumn.name( pkJoinColumn.name() ); + joinColumn.referencedColumnName( pkJoinColumn.referencedColumnName() ); + joinColumn.columnDefinition( pkJoinColumn.columnDefinition() ); + joinColumn.options( pkJoinColumn.options() ); + joinColumn.foreignKey( pkJoinColumn.foreignKey() ); + return joinColumn; + } + + public static JoinColumn toJoinColumn( + MapKeyJoinColumn mapKeyJoinColumn, + SourceModelBuildingContext sourceModelBuildingContext) { + final JoinColumnJpaAnnotation joinColumn = JpaAnnotations.JOIN_COLUMN.createUsage( sourceModelBuildingContext ); + joinColumn.name( mapKeyJoinColumn.name() ); + joinColumn.table( mapKeyJoinColumn.table() ); + joinColumn.referencedColumnName( mapKeyJoinColumn.referencedColumnName() ); + joinColumn.nullable( mapKeyJoinColumn.nullable() ); + joinColumn.unique( mapKeyJoinColumn.unique() ); + joinColumn.insertable( mapKeyJoinColumn.insertable() ); + joinColumn.updatable( mapKeyJoinColumn.updatable() ); + joinColumn.columnDefinition( mapKeyJoinColumn.columnDefinition() ); + joinColumn.options( mapKeyJoinColumn.options() ); + joinColumn.foreignKey( mapKeyJoinColumn.foreignKey() ); + return joinColumn; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnOrFormulaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnOrFormulaAnnotation.java new file mode 100644 index 0000000000..18a57a9545 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnOrFormulaAnnotation.java @@ -0,0 +1,99 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JoinColumnOrFormula; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JoinColumnOrFormulaAnnotation implements JoinColumnOrFormula { + private org.hibernate.annotations.JoinFormula formula; + private jakarta.persistence.JoinColumn column; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JoinColumnOrFormulaAnnotation(SourceModelBuildingContext modelContext) { + this.formula = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( org.hibernate.annotations.JoinFormula.class ) + .createUsage( modelContext ); + this.column = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.JoinColumn.class ) + .createUsage( modelContext ); + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JoinColumnOrFormulaAnnotation(JoinColumnOrFormula annotation, SourceModelBuildingContext modelContext) { + this.formula = extractJdkValue( + annotation, + HibernateAnnotations.JOIN_COLUMN_OR_FORMULA, + "formula", + modelContext + ); + this.column = extractJdkValue( + annotation, + HibernateAnnotations.JOIN_COLUMN_OR_FORMULA, + "column", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JoinColumnOrFormulaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.formula = extractJandexValue( + annotation, + HibernateAnnotations.JOIN_COLUMN_OR_FORMULA, + "formula", + modelContext + ); + this.column = extractJandexValue( + annotation, + HibernateAnnotations.JOIN_COLUMN_OR_FORMULA, + "column", + modelContext + ); + } + + @Override + public Class annotationType() { + return JoinColumnOrFormula.class; + } + + @Override + public org.hibernate.annotations.JoinFormula formula() { + return formula; + } + + public void formula(org.hibernate.annotations.JoinFormula value) { + this.formula = value; + } + + + @Override + public jakarta.persistence.JoinColumn column() { + return column; + } + + public void column(jakarta.persistence.JoinColumn value) { + this.column = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnsJpaAnnotation.java new file mode 100644 index 0000000000..46046a88fb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnsJpaAnnotation.java @@ -0,0 +1,79 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinColumns; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JoinColumnsJpaAnnotation implements JoinColumns, RepeatableContainer { + private jakarta.persistence.JoinColumn[] value; + private jakarta.persistence.ForeignKey foreignKey; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JoinColumnsJpaAnnotation(SourceModelBuildingContext modelContext) { + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JoinColumnsJpaAnnotation(JoinColumns annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMNS, "value", modelContext ); + this.foreignKey = extractJdkValue( annotation, JpaAnnotations.JOIN_COLUMNS, "foreignKey", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JoinColumnsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMNS, "value", modelContext ); + this.foreignKey = extractJandexValue( annotation, JpaAnnotations.JOIN_COLUMNS, "foreignKey", modelContext ); + } + + @Override + public Class annotationType() { + return JoinColumns.class; + } + + @Override + public jakarta.persistence.JoinColumn[] value() { + return value; + } + + public void value(jakarta.persistence.JoinColumn[] value) { + this.value = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnsOrFormulasAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnsOrFormulasAnnotation.java new file mode 100644 index 0000000000..32488af3a8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinColumnsOrFormulasAnnotation.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JoinColumnOrFormula; +import org.hibernate.annotations.JoinColumnsOrFormulas; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JoinColumnsOrFormulasAnnotation + implements JoinColumnsOrFormulas, RepeatableContainer { + private org.hibernate.annotations.JoinColumnOrFormula[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JoinColumnsOrFormulasAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JoinColumnsOrFormulasAnnotation(JoinColumnsOrFormulas annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.JOIN_COLUMNS_OR_FORMULAS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JoinColumnsOrFormulasAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.JOIN_COLUMNS_OR_FORMULAS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return JoinColumnsOrFormulas.class; + } + + @Override + public org.hibernate.annotations.JoinColumnOrFormula[] value() { + return value; + } + + public void value(org.hibernate.annotations.JoinColumnOrFormula[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinFormulaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinFormulaAnnotation.java new file mode 100644 index 0000000000..1b5fecad72 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinFormulaAnnotation.java @@ -0,0 +1,84 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.JoinFormula; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JoinFormulaAnnotation implements JoinFormula { + private String value; + private String referencedColumnName; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JoinFormulaAnnotation(SourceModelBuildingContext modelContext) { + this.referencedColumnName = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JoinFormulaAnnotation(JoinFormula annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.JOIN_FORMULA, "value", modelContext ); + this.referencedColumnName = extractJdkValue( + annotation, + HibernateAnnotations.JOIN_FORMULA, + "referencedColumnName", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JoinFormulaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.JOIN_FORMULA, "value", modelContext ); + this.referencedColumnName = extractJandexValue( + annotation, + HibernateAnnotations.JOIN_FORMULA, + "referencedColumnName", + modelContext + ); + } + + @Override + public Class annotationType() { + return JoinFormula.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + + @Override + public String referencedColumnName() { + return referencedColumnName; + } + + public void referencedColumnName(String value) { + this.referencedColumnName = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinTableJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinTableJpaAnnotation.java new file mode 100644 index 0000000000..aadca4432b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/JoinTableJpaAnnotation.java @@ -0,0 +1,303 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; +import java.util.List; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinColumnImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTableImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.CommonTableDetails; +import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; +import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.JoinTable; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyCatalog; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyOptionalString; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applySchema; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectCheckConstraints; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectIndexes; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectUniqueConstraints; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class JoinTableJpaAnnotation implements JoinTable, CommonTableDetails { + private String name; + private String catalog; + private String schema; + private jakarta.persistence.JoinColumn[] joinColumns; + private jakarta.persistence.JoinColumn[] inverseJoinColumns; + private jakarta.persistence.ForeignKey foreignKey; + private jakarta.persistence.ForeignKey inverseForeignKey; + private jakarta.persistence.UniqueConstraint[] uniqueConstraints; + private jakarta.persistence.Index[] indexes; + private jakarta.persistence.CheckConstraint[] check; + private String comment; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public JoinTableJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.catalog = ""; + this.schema = ""; + this.joinColumns = new jakarta.persistence.JoinColumn[0]; + this.inverseJoinColumns = new jakarta.persistence.JoinColumn[0]; + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + this.inverseForeignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + this.uniqueConstraints = new jakarta.persistence.UniqueConstraint[0]; + this.indexes = new jakarta.persistence.Index[0]; + this.check = new jakarta.persistence.CheckConstraint[0]; + this.comment = ""; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public JoinTableJpaAnnotation(JoinTable annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "name", modelContext ); + this.catalog = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "catalog", modelContext ); + this.schema = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "schema", modelContext ); + this.joinColumns = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "joinColumns", modelContext ); + this.inverseJoinColumns = extractJdkValue( + annotation, + JpaAnnotations.JOIN_TABLE, + "inverseJoinColumns", + modelContext + ); + this.foreignKey = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "foreignKey", modelContext ); + this.inverseForeignKey = extractJdkValue( + annotation, + JpaAnnotations.JOIN_TABLE, + "inverseForeignKey", + modelContext + ); + this.uniqueConstraints = extractJdkValue( + annotation, + JpaAnnotations.JOIN_TABLE, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "indexes", modelContext ); + this.check = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "check", modelContext ); + this.comment = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "comment", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.JOIN_TABLE, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public JoinTableJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "name", modelContext ); + this.catalog = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "catalog", modelContext ); + this.schema = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "schema", modelContext ); + this.joinColumns = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "joinColumns", modelContext ); + this.inverseJoinColumns = extractJandexValue( + annotation, + JpaAnnotations.JOIN_TABLE, + "inverseJoinColumns", + modelContext + ); + this.foreignKey = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "foreignKey", modelContext ); + this.inverseForeignKey = extractJandexValue( + annotation, + JpaAnnotations.JOIN_TABLE, + "inverseForeignKey", + modelContext + ); + this.uniqueConstraints = extractJandexValue( + annotation, + JpaAnnotations.JOIN_TABLE, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "indexes", modelContext ); + this.check = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "check", modelContext ); + this.comment = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "comment", modelContext ); + this.options = extractJandexValue( annotation, JpaAnnotations.JOIN_TABLE, "options", modelContext ); + } + + @Override + public Class annotationType() { + return JoinTable.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String catalog() { + return catalog; + } + + public void catalog(String value) { + this.catalog = value; + } + + + @Override + public String schema() { + return schema; + } + + public void schema(String value) { + this.schema = value; + } + + + @Override + public jakarta.persistence.JoinColumn[] joinColumns() { + return joinColumns; + } + + public void joinColumns(jakarta.persistence.JoinColumn[] value) { + this.joinColumns = value; + } + + + @Override + public jakarta.persistence.JoinColumn[] inverseJoinColumns() { + return inverseJoinColumns; + } + + public void inverseJoinColumns(jakarta.persistence.JoinColumn[] value) { + this.inverseJoinColumns = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + + @Override + public jakarta.persistence.ForeignKey inverseForeignKey() { + return inverseForeignKey; + } + + public void inverseForeignKey(jakarta.persistence.ForeignKey value) { + this.inverseForeignKey = value; + } + + + @Override + public jakarta.persistence.UniqueConstraint[] uniqueConstraints() { + return uniqueConstraints; + } + + public void uniqueConstraints(jakarta.persistence.UniqueConstraint[] value) { + this.uniqueConstraints = value; + } + + + @Override + public jakarta.persistence.Index[] indexes() { + return indexes; + } + + public void indexes(jakarta.persistence.Index[] value) { + this.indexes = value; + } + + + @Override + public jakarta.persistence.CheckConstraint[] check() { + return check; + } + + public void check(jakarta.persistence.CheckConstraint[] value) { + this.check = value; + } + + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + public void apply(JaxbJoinTableImpl jaxbJoinTable, XmlDocumentContext xmlDocumentContext) { + applyOptionalString( jaxbJoinTable.getName(), this::name ); + applyCatalog( jaxbJoinTable, this, xmlDocumentContext ); + applySchema( jaxbJoinTable, this, xmlDocumentContext ); + applyOptionalString( jaxbJoinTable.getComment(), this::comment ); + applyOptionalString( jaxbJoinTable.getOptions(), this::options ); + + check( collectCheckConstraints( jaxbJoinTable.getCheckConstraints(), xmlDocumentContext ) ); + indexes( collectIndexes( jaxbJoinTable.getIndexes(), xmlDocumentContext ) ); + uniqueConstraints( collectUniqueConstraints( jaxbJoinTable.getUniqueConstraints(), xmlDocumentContext ) ); + + final List joinColumns = jaxbJoinTable.getJoinColumn(); + if ( CollectionHelper.isNotEmpty( joinColumns ) ) { + joinColumns( JoinColumnProcessing.transformJoinColumnList( + joinColumns, + xmlDocumentContext + ) ); + } + final List inverseJoinColumns = jaxbJoinTable.getInverseJoinColumn(); + if ( CollectionHelper.isNotEmpty( inverseJoinColumns ) ) { + inverseJoinColumns( JoinColumnProcessing.transformJoinColumnList( + inverseJoinColumns, + xmlDocumentContext + ) ); + } + + if ( jaxbJoinTable.getForeignKey() != null ) { + foreignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbJoinTable.getForeignKey(), + xmlDocumentContext + ) ); + } + if ( jaxbJoinTable.getInverseForeignKey() != null ) { + inverseForeignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbJoinTable.getInverseForeignKey(), + xmlDocumentContext + ) ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyCollectionAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyCollectionAnnotation.java new file mode 100644 index 0000000000..034f999009 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyCollectionAnnotation.java @@ -0,0 +1,52 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.LazyCollection; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class LazyCollectionAnnotation implements LazyCollection { + private org.hibernate.annotations.LazyCollectionOption value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public LazyCollectionAnnotation(SourceModelBuildingContext modelContext) { + this.value = org.hibernate.annotations.LazyCollectionOption.TRUE; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public LazyCollectionAnnotation(LazyCollection annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.LAZY_COLLECTION, "value", modelContext ); + } + + + @Override + public Class annotationType() { + return LazyCollection.class; + } + + @Override + public org.hibernate.annotations.LazyCollectionOption value() { + return value; + } + + public void value(org.hibernate.annotations.LazyCollectionOption value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyGroupAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyGroupAnnotation.java new file mode 100644 index 0000000000..1ee5ace197 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyGroupAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.LazyGroup; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class LazyGroupAnnotation implements LazyGroup { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public LazyGroupAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public LazyGroupAnnotation(LazyGroup annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.LAZY_GROUP, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public LazyGroupAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.LAZY_GROUP, "value", modelContext ); + } + + @Override + public Class annotationType() { + return LazyGroup.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyToOneAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyToOneAnnotation.java new file mode 100644 index 0000000000..9a7da921ad --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LazyToOneAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.LazyToOne; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class LazyToOneAnnotation implements LazyToOne { + private org.hibernate.annotations.LazyToOneOption value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public LazyToOneAnnotation(SourceModelBuildingContext modelContext) { + this.value = org.hibernate.annotations.LazyToOneOption.PROXY; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public LazyToOneAnnotation(LazyToOne annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.LAZY_TO_ONE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public LazyToOneAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.LAZY_TO_ONE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return LazyToOne.class; + } + + @Override + public org.hibernate.annotations.LazyToOneOption value() { + return value; + } + + public void value(org.hibernate.annotations.LazyToOneOption value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexBaseAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexBaseAnnotation.java new file mode 100644 index 0000000000..42f0fabedf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexBaseAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ListIndexBase; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ListIndexBaseAnnotation implements ListIndexBase { + private int value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ListIndexBaseAnnotation(SourceModelBuildingContext modelContext) { + this.value = 0; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ListIndexBaseAnnotation(ListIndexBase annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.LIST_INDEX_BASE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ListIndexBaseAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.LIST_INDEX_BASE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return ListIndexBase.class; + } + + @Override + public int value() { + return value; + } + + public void value(int value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJavaTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJavaTypeAnnotation.java new file mode 100644 index 0000000000..9548f698b7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJavaTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ListIndexJavaType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ListIndexJavaTypeAnnotation implements ListIndexJavaType { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ListIndexJavaTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ListIndexJavaTypeAnnotation(ListIndexJavaType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.LIST_INDEX_JAVA_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ListIndexJavaTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.LIST_INDEX_JAVA_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return ListIndexJavaType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJdbcTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJdbcTypeAnnotation.java new file mode 100644 index 0000000000..cd133944b9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJdbcTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ListIndexJdbcType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ListIndexJdbcTypeAnnotation implements ListIndexJdbcType { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ListIndexJdbcTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ListIndexJdbcTypeAnnotation(ListIndexJdbcType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.LIST_INDEX_JDBC_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ListIndexJdbcTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.LIST_INDEX_JDBC_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return ListIndexJdbcType.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJdbcTypeCodeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJdbcTypeCodeAnnotation.java new file mode 100644 index 0000000000..c885212957 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ListIndexJdbcTypeCodeAnnotation.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ListIndexJdbcTypeCode; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ListIndexJdbcTypeCodeAnnotation implements ListIndexJdbcTypeCode { + private int value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ListIndexJdbcTypeCodeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ListIndexJdbcTypeCodeAnnotation(ListIndexJdbcTypeCode annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.LIST_INDEX_JDBC_TYPE_CODE, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ListIndexJdbcTypeCodeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.LIST_INDEX_JDBC_TYPE_CODE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return ListIndexJdbcTypeCode.class; + } + + @Override + public int value() { + return value; + } + + public void value(int value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LoaderAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LoaderAnnotation.java new file mode 100644 index 0000000000..12ba8f509c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LoaderAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Loader; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class LoaderAnnotation implements Loader { + private String namedQuery; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public LoaderAnnotation(SourceModelBuildingContext modelContext) { + this.namedQuery = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public LoaderAnnotation(Loader annotation, SourceModelBuildingContext modelContext) { + this.namedQuery = extractJdkValue( annotation, HibernateAnnotations.LOADER, "namedQuery", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public LoaderAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.namedQuery = extractJandexValue( annotation, HibernateAnnotations.LOADER, "namedQuery", modelContext ); + } + + @Override + public Class annotationType() { + return Loader.class; + } + + @Override + public String namedQuery() { + return namedQuery; + } + + public void namedQuery(String value) { + this.namedQuery = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LobJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LobJpaAnnotation.java new file mode 100644 index 0000000000..6e2764f951 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/LobJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Lob; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class LobJpaAnnotation implements Lob { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public LobJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public LobJpaAnnotation(Lob annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public LobJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Lob.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToAnyAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToAnyAnnotation.java new file mode 100644 index 0000000000..6957071ff0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToAnyAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ManyToAny; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ManyToAnyAnnotation implements ManyToAny { + private jakarta.persistence.FetchType fetch; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ManyToAnyAnnotation(SourceModelBuildingContext modelContext) { + this.fetch = jakarta.persistence.FetchType.EAGER; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ManyToAnyAnnotation(ManyToAny annotation, SourceModelBuildingContext modelContext) { + this.fetch = extractJdkValue( annotation, HibernateAnnotations.MANY_TO_ANY, "fetch", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ManyToAnyAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.fetch = extractJandexValue( annotation, HibernateAnnotations.MANY_TO_ANY, "fetch", modelContext ); + } + + @Override + public Class annotationType() { + return ManyToAny.class; + } + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToManyJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToManyJpaAnnotation.java new file mode 100644 index 0000000000..9c4e95a1db --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToManyJpaAnnotation.java @@ -0,0 +1,108 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.ManyToMany; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ManyToManyJpaAnnotation implements ManyToMany, + AttributeMarker.Fetchable, + AttributeMarker.Cascadeable, + AttributeMarker.Mappable { + private java.lang.Class targetEntity; + private jakarta.persistence.CascadeType[] cascade; + private jakarta.persistence.FetchType fetch; + private String mappedBy; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ManyToManyJpaAnnotation(SourceModelBuildingContext modelContext) { + this.targetEntity = void.class; + this.cascade = new jakarta.persistence.CascadeType[0]; + this.fetch = jakarta.persistence.FetchType.LAZY; + this.mappedBy = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ManyToManyJpaAnnotation(ManyToMany annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJdkValue( annotation, JpaAnnotations.MANY_TO_MANY, "targetEntity", modelContext ); + this.cascade = extractJdkValue( annotation, JpaAnnotations.MANY_TO_MANY, "cascade", modelContext ); + this.fetch = extractJdkValue( annotation, JpaAnnotations.MANY_TO_MANY, "fetch", modelContext ); + this.mappedBy = extractJdkValue( annotation, JpaAnnotations.MANY_TO_MANY, "mappedBy", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ManyToManyJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJandexValue( annotation, JpaAnnotations.MANY_TO_MANY, "targetEntity", modelContext ); + this.cascade = extractJandexValue( annotation, JpaAnnotations.MANY_TO_MANY, "cascade", modelContext ); + this.fetch = extractJandexValue( annotation, JpaAnnotations.MANY_TO_MANY, "fetch", modelContext ); + this.mappedBy = extractJandexValue( annotation, JpaAnnotations.MANY_TO_MANY, "mappedBy", modelContext ); + } + + @Override + public Class annotationType() { + return ManyToMany.class; + } + + @Override + public java.lang.Class targetEntity() { + return targetEntity; + } + + public void targetEntity(java.lang.Class value) { + this.targetEntity = value; + } + + + @Override + public jakarta.persistence.CascadeType[] cascade() { + return cascade; + } + + public void cascade(jakarta.persistence.CascadeType[] value) { + this.cascade = value; + } + + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + + @Override + public String mappedBy() { + return mappedBy; + } + + public void mappedBy(String value) { + this.mappedBy = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToOneJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToOneJpaAnnotation.java new file mode 100644 index 0000000000..d4ba1e3478 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ManyToOneJpaAnnotation.java @@ -0,0 +1,109 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.ManyToOne; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ManyToOneJpaAnnotation implements ManyToOne, + AttributeMarker, + AttributeMarker.Fetchable, + AttributeMarker.Cascadeable, + AttributeMarker.Optionalable { + private java.lang.Class targetEntity; + private jakarta.persistence.CascadeType[] cascade; + private jakarta.persistence.FetchType fetch; + private boolean optional; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ManyToOneJpaAnnotation(SourceModelBuildingContext modelContext) { + this.targetEntity = void.class; + this.cascade = new jakarta.persistence.CascadeType[0]; + this.fetch = jakarta.persistence.FetchType.EAGER; + this.optional = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ManyToOneJpaAnnotation(ManyToOne annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJdkValue( annotation, JpaAnnotations.MANY_TO_ONE, "targetEntity", modelContext ); + this.cascade = extractJdkValue( annotation, JpaAnnotations.MANY_TO_ONE, "cascade", modelContext ); + this.fetch = extractJdkValue( annotation, JpaAnnotations.MANY_TO_ONE, "fetch", modelContext ); + this.optional = extractJdkValue( annotation, JpaAnnotations.MANY_TO_ONE, "optional", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ManyToOneJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJandexValue( annotation, JpaAnnotations.MANY_TO_ONE, "targetEntity", modelContext ); + this.cascade = extractJandexValue( annotation, JpaAnnotations.MANY_TO_ONE, "cascade", modelContext ); + this.fetch = extractJandexValue( annotation, JpaAnnotations.MANY_TO_ONE, "fetch", modelContext ); + this.optional = extractJandexValue( annotation, JpaAnnotations.MANY_TO_ONE, "optional", modelContext ); + } + + @Override + public Class annotationType() { + return ManyToOne.class; + } + + @Override + public java.lang.Class targetEntity() { + return targetEntity; + } + + public void targetEntity(java.lang.Class value) { + this.targetEntity = value; + } + + + @Override + public jakarta.persistence.CascadeType[] cascade() { + return cascade; + } + + public void cascade(jakarta.persistence.CascadeType[] value) { + this.cascade = value; + } + + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + + @Override + public boolean optional() { + return optional; + } + + public void optional(boolean value) { + this.optional = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyClassJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyClassJpaAnnotation.java new file mode 100644 index 0000000000..b84684ee45 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyClassJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MapKeyClass; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyClassJpaAnnotation implements MapKeyClass { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyClassJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyClassJpaAnnotation(MapKeyClass annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_CLASS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyClassJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_CLASS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return MapKeyClass.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyColumnJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyColumnJpaAnnotation.java new file mode 100644 index 0000000000..3b8d28939b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyColumnJpaAnnotation.java @@ -0,0 +1,286 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyColumnImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.ColumnDetails; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Column; +import jakarta.persistence.MapKeyColumn; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyColumnJpaAnnotation implements MapKeyColumn, + ColumnDetails.Nullable, + ColumnDetails.Mutable, + ColumnDetails.Sizable, + ColumnDetails.Uniqueable, + ColumnDetails.Definable, + ColumnDetails.AlternateTableCapable { + private String name; + private boolean unique; + private boolean nullable; + private boolean insertable; + private boolean updatable; + private String columnDefinition; + private String options; + private String table; + private int length; + private int precision; + private int scale; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyColumnJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.unique = false; + this.nullable = false; + this.insertable = true; + this.updatable = true; + this.columnDefinition = ""; + this.options = ""; + this.table = ""; + this.length = 255; + this.precision = 0; + this.scale = 0; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyColumnJpaAnnotation(MapKeyColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "name", modelContext ); + this.unique = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "unique", modelContext ); + this.nullable = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "nullable", modelContext ); + this.insertable = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "insertable", modelContext ); + this.updatable = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJdkValue( + annotation, + JpaAnnotations.MAP_KEY_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "options", modelContext ); + this.table = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "table", modelContext ); + this.length = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "length", modelContext ); + this.precision = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "precision", modelContext ); + this.scale = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "scale", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyColumnJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "name", modelContext ); + this.unique = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "unique", modelContext ); + this.nullable = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "nullable", modelContext ); + this.insertable = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "insertable", modelContext ); + this.updatable = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJandexValue( + annotation, + JpaAnnotations.MAP_KEY_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "options", modelContext ); + this.table = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "table", modelContext ); + this.length = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "length", modelContext ); + this.precision = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "precision", modelContext ); + this.scale = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_COLUMN, "scale", modelContext ); + } + + @Override + public Class annotationType() { + return MapKeyColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public boolean unique() { + return unique; + } + + public void unique(boolean value) { + this.unique = value; + } + + + @Override + public boolean nullable() { + return nullable; + } + + public void nullable(boolean value) { + this.nullable = value; + } + + + @Override + public boolean insertable() { + return insertable; + } + + public void insertable(boolean value) { + this.insertable = value; + } + + + @Override + public boolean updatable() { + return updatable; + } + + public void updatable(boolean value) { + this.updatable = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + + @Override + public int length() { + return length; + } + + public void length(int value) { + this.length = value; + } + + + @Override + public int precision() { + return precision; + } + + public void precision(int value) { + this.precision = value; + } + + + @Override + public int scale() { + return scale; + } + + public void scale(int value) { + this.scale = value; + } + + + public void apply(JaxbMapKeyColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) { + table( jaxbColumn.getTable() ); + } + + if ( jaxbColumn.isNullable() != null ) { + nullable( jaxbColumn.isNullable() ); + } + + if ( jaxbColumn.isUnique() != null ) { + unique( jaxbColumn.isUnique() ); + } + + if ( jaxbColumn.isInsertable() != null ) { + insertable( jaxbColumn.isInsertable() ); + } + + if ( jaxbColumn.isUpdatable() != null ) { + updatable( jaxbColumn.isUpdatable() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + + if ( jaxbColumn.getLength() != null ) { + length( jaxbColumn.getLength() ); + } + + if ( jaxbColumn.getPrecision() != null ) { + precision( jaxbColumn.getPrecision() ); + } + + if ( jaxbColumn.getScale() != null ) { + scale( jaxbColumn.getScale() ); + } + } + + public static Column toColumnAnnotation( + MapKeyColumn mapKeyColumn, + SourceModelBuildingContext sourceModelBuildingContext) { + final ColumnJpaAnnotation column = new ColumnJpaAnnotation( sourceModelBuildingContext ); + column.name( mapKeyColumn.name() ); + column.table( mapKeyColumn.table() ); + column.nullable( mapKeyColumn.nullable() ); + column.unique( mapKeyColumn.unique() ); + column.insertable( mapKeyColumn.insertable() ); + column.updatable( mapKeyColumn.updatable() ); + column.columnDefinition( mapKeyColumn.columnDefinition() ); + column.options( mapKeyColumn.options() ); + column.length( mapKeyColumn.length() ); + column.precision( mapKeyColumn.precision() ); + column.scale( mapKeyColumn.scale() ); + return column; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyCompositeTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyCompositeTypeAnnotation.java new file mode 100644 index 0000000000..6855eed48e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyCompositeTypeAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.MapKeyCompositeType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyCompositeTypeAnnotation implements MapKeyCompositeType { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyCompositeTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyCompositeTypeAnnotation(MapKeyCompositeType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.MAP_KEY_COMPOSITE_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyCompositeTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.MAP_KEY_COMPOSITE_TYPE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return MapKeyCompositeType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyEnumeratedJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyEnumeratedJpaAnnotation.java new file mode 100644 index 0000000000..cb1574598f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyEnumeratedJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MapKeyEnumerated; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyEnumeratedJpaAnnotation implements MapKeyEnumerated { + private jakarta.persistence.EnumType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyEnumeratedJpaAnnotation(SourceModelBuildingContext modelContext) { + this.value = jakarta.persistence.EnumType.ORDINAL; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyEnumeratedJpaAnnotation(MapKeyEnumerated annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_ENUMERATED, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyEnumeratedJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_ENUMERATED, "value", modelContext ); + } + + @Override + public Class annotationType() { + return MapKeyEnumerated.class; + } + + @Override + public jakarta.persistence.EnumType value() { + return value; + } + + public void value(jakarta.persistence.EnumType value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJavaTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJavaTypeAnnotation.java new file mode 100644 index 0000000000..9bcb04ac96 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJavaTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.MapKeyJavaType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyJavaTypeAnnotation implements MapKeyJavaType { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyJavaTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyJavaTypeAnnotation(MapKeyJavaType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.MAP_KEY_JAVA_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyJavaTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.MAP_KEY_JAVA_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return MapKeyJavaType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJdbcTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJdbcTypeAnnotation.java new file mode 100644 index 0000000000..c282ace97c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJdbcTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.MapKeyJdbcType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyJdbcTypeAnnotation implements MapKeyJdbcType { + private java.lang.Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyJdbcTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyJdbcTypeAnnotation(MapKeyJdbcType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.MAP_KEY_JDBC_TYPE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyJdbcTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.MAP_KEY_JDBC_TYPE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return MapKeyJdbcType.class; + } + + @Override + public java.lang.Class value() { + return value; + } + + public void value(java.lang.Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJdbcTypeCodeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJdbcTypeCodeAnnotation.java new file mode 100644 index 0000000000..a15672a542 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJdbcTypeCodeAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.MapKeyJdbcTypeCode; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyJdbcTypeCodeAnnotation implements MapKeyJdbcTypeCode { + private int value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyJdbcTypeCodeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyJdbcTypeCodeAnnotation(MapKeyJdbcTypeCode annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.MAP_KEY_JDBC_TYPE_CODE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyJdbcTypeCodeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.MAP_KEY_JDBC_TYPE_CODE, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return MapKeyJdbcTypeCode.class; + } + + @Override + public int value() { + return value; + } + + public void value(int value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJoinColumnJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJoinColumnJpaAnnotation.java new file mode 100644 index 0000000000..2d22cccbca --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJoinColumnJpaAnnotation.java @@ -0,0 +1,271 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyJoinColumnImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MapKeyJoinColumn; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyJoinColumnJpaAnnotation implements MapKeyJoinColumn { + private String name; + private String referencedColumnName; + private boolean unique; + private boolean nullable; + private boolean insertable; + private boolean updatable; + private String columnDefinition; + private String options; + private String table; + private jakarta.persistence.ForeignKey foreignKey; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyJoinColumnJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.referencedColumnName = ""; + this.unique = false; + this.nullable = false; + this.insertable = true; + this.updatable = true; + this.columnDefinition = ""; + this.options = ""; + this.table = ""; + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyJoinColumnJpaAnnotation(MapKeyJoinColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "name", modelContext ); + this.referencedColumnName = extractJdkValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + "referencedColumnName", + modelContext + ); + this.unique = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "unique", modelContext ); + this.nullable = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "nullable", modelContext ); + this.insertable = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "insertable", modelContext ); + this.updatable = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJdkValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "options", modelContext ); + this.table = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "table", modelContext ); + this.foreignKey = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "foreignKey", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyJoinColumnJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "name", modelContext ); + this.referencedColumnName = extractJandexValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + "referencedColumnName", + modelContext + ); + this.unique = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "unique", modelContext ); + this.nullable = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "nullable", modelContext ); + this.insertable = extractJandexValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + "insertable", + modelContext + ); + this.updatable = extractJandexValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + "updatable", + modelContext + ); + this.columnDefinition = extractJandexValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "options", modelContext ); + this.table = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMN, "table", modelContext ); + this.foreignKey = extractJandexValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + "foreignKey", + modelContext + ); + } + + @Override + public Class annotationType() { + return MapKeyJoinColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String referencedColumnName() { + return referencedColumnName; + } + + public void referencedColumnName(String value) { + this.referencedColumnName = value; + } + + + @Override + public boolean unique() { + return unique; + } + + public void unique(boolean value) { + this.unique = value; + } + + + @Override + public boolean nullable() { + return nullable; + } + + public void nullable(boolean value) { + this.nullable = value; + } + + + @Override + public boolean insertable() { + return insertable; + } + + public void insertable(boolean value) { + this.insertable = value; + } + + + @Override + public boolean updatable() { + return updatable; + } + + public void updatable(boolean value) { + this.updatable = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + + public void apply(JaxbMapKeyJoinColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) { + table( jaxbColumn.getTable() ); + } + + if ( jaxbColumn.isNullable() != null ) { + nullable( jaxbColumn.isNullable() ); + } + + if ( jaxbColumn.isInsertable() != null ) { + insertable( jaxbColumn.isInsertable() ); + } + if ( jaxbColumn.isInsertable() != null ) { + updatable( jaxbColumn.isUpdatable() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + + if ( jaxbColumn.isUnique() != null ) { + unique( jaxbColumn.isUnique() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getReferencedColumnName() ) ) { + referencedColumnName( jaxbColumn.getReferencedColumnName() ); + } + + if ( jaxbColumn.getForeignKey() != null ) { + foreignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbColumn.getForeignKey(), + xmlDocumentContext + ) ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJoinColumnsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJoinColumnsJpaAnnotation.java new file mode 100644 index 0000000000..f16ba34a2f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJoinColumnsJpaAnnotation.java @@ -0,0 +1,89 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MapKeyJoinColumn; +import jakarta.persistence.MapKeyJoinColumns; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyJoinColumnsJpaAnnotation implements MapKeyJoinColumns, RepeatableContainer { + private jakarta.persistence.MapKeyJoinColumn[] value; + private jakarta.persistence.ForeignKey foreignKey; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyJoinColumnsJpaAnnotation(SourceModelBuildingContext modelContext) { + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyJoinColumnsJpaAnnotation(MapKeyJoinColumns annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMNS, "value", modelContext ); + this.foreignKey = extractJdkValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMNS, + "foreignKey", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyJoinColumnsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_JOIN_COLUMNS, "value", modelContext ); + this.foreignKey = extractJandexValue( + annotation, + JpaAnnotations.MAP_KEY_JOIN_COLUMNS, + "foreignKey", + modelContext + ); + } + + @Override + public Class annotationType() { + return MapKeyJoinColumns.class; + } + + @Override + public jakarta.persistence.MapKeyJoinColumn[] value() { + return value; + } + + public void value(jakarta.persistence.MapKeyJoinColumn[] value) { + this.value = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJpaAnnotation.java new file mode 100644 index 0000000000..b4449d3ec7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MapKey; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyJpaAnnotation implements MapKey { + private String name; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyJpaAnnotation(MapKey annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.MAP_KEY, "name", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.MAP_KEY, "name", modelContext ); + } + + @Override + public Class annotationType() { + return MapKey.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyMutabilityAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyMutabilityAnnotation.java new file mode 100644 index 0000000000..b198b31a5b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyMutabilityAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.MapKeyMutability; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyMutabilityAnnotation implements MapKeyMutability { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyMutabilityAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyMutabilityAnnotation(MapKeyMutability annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.MAP_KEY_MUTABILITY, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyMutabilityAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.MAP_KEY_MUTABILITY, "value", modelContext ); + } + + @Override + public Class annotationType() { + return MapKeyMutability.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyTemporalJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyTemporalJpaAnnotation.java new file mode 100644 index 0000000000..65d7908ff3 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyTemporalJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MapKeyTemporal; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyTemporalJpaAnnotation implements MapKeyTemporal { + private jakarta.persistence.TemporalType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyTemporalJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyTemporalJpaAnnotation(MapKeyTemporal annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.MAP_KEY_TEMPORAL, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyTemporalJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.MAP_KEY_TEMPORAL, "value", modelContext ); + } + + @Override + public Class annotationType() { + return MapKeyTemporal.class; + } + + @Override + public jakarta.persistence.TemporalType value() { + return value; + } + + public void value(jakarta.persistence.TemporalType value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyTypeAnnotation.java new file mode 100644 index 0000000000..0647c7fcc1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapKeyTypeAnnotation.java @@ -0,0 +1,79 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.MapKeyType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapKeyTypeAnnotation implements MapKeyType { + private java.lang.Class> value; + private org.hibernate.annotations.Parameter[] parameters; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapKeyTypeAnnotation(SourceModelBuildingContext modelContext) { + this.parameters = new org.hibernate.annotations.Parameter[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapKeyTypeAnnotation(MapKeyType annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.MAP_KEY_TYPE, "value", modelContext ); + this.parameters = extractJdkValue( annotation, HibernateAnnotations.MAP_KEY_TYPE, "parameters", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapKeyTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.MAP_KEY_TYPE, "value", modelContext ); + this.parameters = extractJandexValue( + annotation, + HibernateAnnotations.MAP_KEY_TYPE, + "parameters", + modelContext + ); + } + + @Override + public Class annotationType() { + return MapKeyType.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + + @Override + public org.hibernate.annotations.Parameter[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.Parameter[] value) { + this.parameters = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MappedSuperclassJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MappedSuperclassJpaAnnotation.java new file mode 100644 index 0000000000..d1db0d7089 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MappedSuperclassJpaAnnotation.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MappedSuperclass; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MappedSuperclassJpaAnnotation implements MappedSuperclass { + + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MappedSuperclassJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MappedSuperclassJpaAnnotation(MappedSuperclass annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MappedSuperclassJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return MappedSuperclass.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapsIdJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapsIdJpaAnnotation.java new file mode 100644 index 0000000000..817e9c7fa2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MapsIdJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.MapsId; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MapsIdJpaAnnotation implements MapsId { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MapsIdJpaAnnotation(SourceModelBuildingContext modelContext) { + this.value = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MapsIdJpaAnnotation(MapsId annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.MAPS_ID, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MapsIdJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.MAPS_ID, "value", modelContext ); + } + + @Override + public Class annotationType() { + return MapsId.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MutabilityAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MutabilityAnnotation.java new file mode 100644 index 0000000000..a03413a366 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/MutabilityAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Mutability; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class MutabilityAnnotation implements Mutability { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public MutabilityAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public MutabilityAnnotation(Mutability annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.MUTABILITY, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public MutabilityAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.MUTABILITY, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Mutability.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedAttributeNodeJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedAttributeNodeJpaAnnotation.java new file mode 100644 index 0000000000..58a0267370 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedAttributeNodeJpaAnnotation.java @@ -0,0 +1,99 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedAttributeNode; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedAttributeNodeJpaAnnotation implements NamedAttributeNode { + private String value; + private String subgraph; + private String keySubgraph; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedAttributeNodeJpaAnnotation(SourceModelBuildingContext modelContext) { + this.subgraph = ""; + this.keySubgraph = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedAttributeNodeJpaAnnotation(NamedAttributeNode annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.NAMED_ATTRIBUTE_NODE, "value", modelContext ); + this.subgraph = extractJdkValue( annotation, JpaAnnotations.NAMED_ATTRIBUTE_NODE, "subgraph", modelContext ); + this.keySubgraph = extractJdkValue( + annotation, + JpaAnnotations.NAMED_ATTRIBUTE_NODE, + "keySubgraph", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedAttributeNodeJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.NAMED_ATTRIBUTE_NODE, "value", modelContext ); + this.subgraph = extractJandexValue( annotation, JpaAnnotations.NAMED_ATTRIBUTE_NODE, "subgraph", modelContext ); + this.keySubgraph = extractJandexValue( + annotation, + JpaAnnotations.NAMED_ATTRIBUTE_NODE, + "keySubgraph", + modelContext + ); + } + + @Override + public Class annotationType() { + return NamedAttributeNode.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + + @Override + public String subgraph() { + return subgraph; + } + + public void subgraph(String value) { + this.subgraph = value; + } + + + @Override + public String keySubgraph() { + return keySubgraph; + } + + public void keySubgraph(String value) { + this.keySubgraph = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphJpaAnnotation.java new file mode 100644 index 0000000000..c34d34d978 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphJpaAnnotation.java @@ -0,0 +1,148 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedEntityGraph; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedEntityGraphJpaAnnotation implements NamedEntityGraph { + private String name; + private jakarta.persistence.NamedAttributeNode[] attributeNodes; + private boolean includeAllAttributes; + private jakarta.persistence.NamedSubgraph[] subgraphs; + private jakarta.persistence.NamedSubgraph[] subclassSubgraphs; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedEntityGraphJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.attributeNodes = new jakarta.persistence.NamedAttributeNode[0]; + this.includeAllAttributes = false; + this.subgraphs = new jakarta.persistence.NamedSubgraph[0]; + this.subclassSubgraphs = new jakarta.persistence.NamedSubgraph[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedEntityGraphJpaAnnotation(NamedEntityGraph annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.NAMED_ENTITY_GRAPH, "name", modelContext ); + this.attributeNodes = extractJdkValue( + annotation, + JpaAnnotations.NAMED_ENTITY_GRAPH, + "attributeNodes", + modelContext + ); + this.includeAllAttributes = extractJdkValue( + annotation, + JpaAnnotations.NAMED_ENTITY_GRAPH, + "includeAllAttributes", + modelContext + ); + this.subgraphs = extractJdkValue( annotation, JpaAnnotations.NAMED_ENTITY_GRAPH, "subgraphs", modelContext ); + this.subclassSubgraphs = extractJdkValue( + annotation, + JpaAnnotations.NAMED_ENTITY_GRAPH, + "subclassSubgraphs", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedEntityGraphJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.NAMED_ENTITY_GRAPH, "name", modelContext ); + this.attributeNodes = extractJandexValue( + annotation, + JpaAnnotations.NAMED_ENTITY_GRAPH, + "attributeNodes", + modelContext + ); + this.includeAllAttributes = extractJandexValue( + annotation, + JpaAnnotations.NAMED_ENTITY_GRAPH, + "includeAllAttributes", + modelContext + ); + this.subgraphs = extractJandexValue( annotation, JpaAnnotations.NAMED_ENTITY_GRAPH, "subgraphs", modelContext ); + this.subclassSubgraphs = extractJandexValue( + annotation, + JpaAnnotations.NAMED_ENTITY_GRAPH, + "subclassSubgraphs", + modelContext + ); + } + + @Override + public Class annotationType() { + return NamedEntityGraph.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public jakarta.persistence.NamedAttributeNode[] attributeNodes() { + return attributeNodes; + } + + public void attributeNodes(jakarta.persistence.NamedAttributeNode[] value) { + this.attributeNodes = value; + } + + + @Override + public boolean includeAllAttributes() { + return includeAllAttributes; + } + + public void includeAllAttributes(boolean value) { + this.includeAllAttributes = value; + } + + + @Override + public jakarta.persistence.NamedSubgraph[] subgraphs() { + return subgraphs; + } + + public void subgraphs(jakarta.persistence.NamedSubgraph[] value) { + this.subgraphs = value; + } + + + @Override + public jakarta.persistence.NamedSubgraph[] subclassSubgraphs() { + return subclassSubgraphs; + } + + public void subclassSubgraphs(jakarta.persistence.NamedSubgraph[] value) { + this.subclassSubgraphs = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphsJpaAnnotation.java new file mode 100644 index 0000000000..1c6a2cbc71 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphsJpaAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedEntityGraph; +import jakarta.persistence.NamedEntityGraphs; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedEntityGraphsJpaAnnotation implements NamedEntityGraphs, RepeatableContainer { + private jakarta.persistence.NamedEntityGraph[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedEntityGraphsJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedEntityGraphsJpaAnnotation(NamedEntityGraphs annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.NAMED_ENTITY_GRAPHS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedEntityGraphsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.NAMED_ENTITY_GRAPHS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return NamedEntityGraphs.class; + } + + @Override + public jakarta.persistence.NamedEntityGraph[] value() { + return value; + } + + public void value(jakarta.persistence.NamedEntityGraph[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueriesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueriesAnnotation.java new file mode 100644 index 0000000000..38cfc6fae0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueriesAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.NamedNativeQueries; +import org.hibernate.annotations.NamedNativeQuery; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.HibernateAnnotations.NAMED_NATIVE_QUERIES; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedNativeQueriesAnnotation implements NamedNativeQueries, RepeatableContainer { + private NamedNativeQuery[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedNativeQueriesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedNativeQueriesAnnotation(NamedNativeQueries annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, NAMED_NATIVE_QUERIES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedNativeQueriesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, NAMED_NATIVE_QUERIES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return NamedNativeQueries.class; + } + + @Override + public NamedNativeQuery[] value() { + return value; + } + + public void value(NamedNativeQuery[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueriesJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueriesJpaAnnotation.java new file mode 100644 index 0000000000..219a9ed4bf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueriesJpaAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedNativeQueries; +import jakarta.persistence.NamedNativeQuery; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedNativeQueriesJpaAnnotation implements NamedNativeQueries, RepeatableContainer { + private jakarta.persistence.NamedNativeQuery[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedNativeQueriesJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedNativeQueriesJpaAnnotation(NamedNativeQueries annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERIES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedNativeQueriesJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERIES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return NamedNativeQueries.class; + } + + @Override + public jakarta.persistence.NamedNativeQuery[] value() { + return value; + } + + public void value(jakarta.persistence.NamedNativeQuery[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryAnnotation.java new file mode 100644 index 0000000000..a8b5b2623a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryAnnotation.java @@ -0,0 +1,290 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.annotations.CacheModeType; +import org.hibernate.annotations.FlushModeType; +import org.hibernate.annotations.NamedNativeQuery; +import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbSynchronizedTableImpl; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.models.spi.MutableClassDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.CacheRetrieveMode; +import jakarta.persistence.CacheStoreMode; + +import static org.hibernate.boot.models.HibernateAnnotations.NAMED_NATIVE_QUERY; +import static org.hibernate.boot.models.HibernateAnnotations.NAMED_QUERY; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedNativeQueryAnnotation implements NamedNativeQuery { + private String name; + private String query; + private Class resultClass; + private String resultSetMapping; + private FlushModeType flushMode; + boolean cacheable; + String cacheRegion; + int fetchSize; + int timeout; + String comment; + CacheStoreMode cacheStoreMode; + CacheRetrieveMode cacheRetrieveMode; + CacheModeType cacheMode; + boolean readOnly; + String[] querySpaces; + boolean callable; + + public NamedNativeQueryAnnotation(SourceModelBuildingContext modelContext) { + resultClass = void.class; + resultSetMapping = ""; + flushMode = FlushModeType.PERSISTENCE_CONTEXT; + cacheable = false; + cacheRegion = ""; + fetchSize = -1; + timeout = -1; + comment = ""; + cacheStoreMode = CacheStoreMode.USE; + cacheRetrieveMode = CacheRetrieveMode.USE; + cacheMode = CacheModeType.NORMAL; + readOnly = false; + querySpaces = new String[0]; + callable = false; + } + + public NamedNativeQueryAnnotation(NamedNativeQuery annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "name", modelContext ); + this.query = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "query", modelContext ); + this.resultClass = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "resultClass", modelContext ); + this.resultSetMapping = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "resultSetMapping", modelContext ); + this.flushMode = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "flushMode", modelContext ); + this.cacheable = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "cacheable", modelContext ); + this.cacheRegion = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "cacheRegion", modelContext ); + this.fetchSize = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "fetchSize", modelContext ); + this.timeout = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "timeout", modelContext ); + this.comment = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "comment", modelContext ); + this.cacheStoreMode = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "cacheStoreMode", modelContext ); + this.cacheRetrieveMode = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "cacheRetrieveMode", modelContext ); + this.cacheMode = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "cacheMode", modelContext ); + this.readOnly = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "readOnly", modelContext ); + this.querySpaces = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "querySpaces", modelContext ); + this.callable = extractJdkValue( annotation, NAMED_NATIVE_QUERY, "callable", modelContext ); + } + + public NamedNativeQueryAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "name", modelContext ); + this.query = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "query", modelContext ); + this.resultClass = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "resultClass", modelContext ); + this.resultSetMapping = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "resultSetMapping", modelContext ); + this.flushMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "flushMode", modelContext ); + this.cacheable = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheable", modelContext ); + this.cacheRegion = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheRegion", modelContext ); + this.fetchSize = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "fetchSize", modelContext ); + this.timeout = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "timeout", modelContext ); + this.comment = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "comment", modelContext ); + this.cacheStoreMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheStoreMode", modelContext ); + this.cacheRetrieveMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheRetrieveMode", modelContext ); + this.cacheMode = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "cacheMode", modelContext ); + this.readOnly = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "readOnly", modelContext ); + this.querySpaces = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "querySpaces", modelContext ); + this.callable = extractJandexValue( annotation, NAMED_NATIVE_QUERY, "callable", modelContext ); + } + + @Override + public Class annotationType() { + return NamedNativeQuery.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String query() { + return query; + } + + public void query(String value) { + this.query = value; + } + + + @Override + public Class resultClass() { + return resultClass; + } + + public void resultClass(Class value) { + this.resultClass = value; + } + + @Override + public String resultSetMapping() { + return resultSetMapping; + } + + public void resultSetMapping(String value) { + this.resultSetMapping = value; + } + + @Override + public FlushModeType flushMode() { + return flushMode; + } + + public void flushMode(FlushModeType value) { + this.flushMode = value; + } + + @Override + public boolean cacheable() { + return cacheable; + } + + public void cacheable(boolean value) { + this.cacheable = value; + } + + @Override + public String cacheRegion() { + return cacheRegion; + } + + public void cacheRegion(String value) { + this.cacheRegion = value; + } + + @Override + public int fetchSize() { + return fetchSize; + } + + public void fetchSize(int value) { + this.fetchSize = value; + } + + @Override + public int timeout() { + return timeout; + } + + public void timeout(int value) { + this.timeout = value; + } + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + @Override + public CacheStoreMode cacheStoreMode() { + return cacheStoreMode; + } + + public void cacheStoreMode(CacheStoreMode value) { + this.cacheStoreMode = value; + } + + @Override + public CacheRetrieveMode cacheRetrieveMode() { + return cacheRetrieveMode; + } + + public void cacheRetrieveMode(CacheRetrieveMode value) { + this.cacheRetrieveMode = value; + } + + @Override + public CacheModeType cacheMode() { + return cacheMode; + } + + public void cacheMode(CacheModeType value) { + this.cacheMode = value; + } + + @Override + public boolean readOnly() { + return readOnly; + } + + public void readOnly(boolean value) { + this.readOnly = value; + } + + @Override + public String[] querySpaces() { + return querySpaces; + } + + public void querySpaces(String[] value) { + this.querySpaces = value; + } + + @Override + public boolean callable() { + return callable; + } + + public void callable(boolean value) { + this.callable = value; + } + + public void apply(JaxbNamedNativeQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { + name( jaxbNamedQuery.getName() ); + query( jaxbNamedQuery.getQuery() ); + + applyResultClassAndSynchronizations( jaxbNamedQuery, xmlDocumentContext ); + + if ( StringHelper.isNotEmpty( jaxbNamedQuery.getResultSetMapping() ) ) { + resultSetMapping( jaxbNamedQuery.getResultSetMapping() ); + } + } + + private void applyResultClassAndSynchronizations( + JaxbNamedNativeQueryImpl jaxbNamedQuery, + XmlDocumentContext xmlDocumentContext) { + final List syncSpaces = new ArrayList<>(); + + if ( StringHelper.isNotEmpty( jaxbNamedQuery.getResultClass() ) ) { + final MutableClassDetails resultClassDetails = xmlDocumentContext.resolveJavaType( jaxbNamedQuery.getResultClass() ); + syncSpaces.add( resultClassDetails.getName() ); + resultClass( resultClassDetails.toJavaClass() ); + } + + for ( JaxbSynchronizedTableImpl synchronization : jaxbNamedQuery.getSynchronizations() ) { + syncSpaces.add( synchronization.getTable() ); + } + + if ( CollectionHelper.isNotEmpty( syncSpaces ) ) { + querySpaces( syncSpaces.toArray( String[]::new ) ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryJpaAnnotation.java new file mode 100644 index 0000000000..562dddbde8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedNativeQueryJpaAnnotation.java @@ -0,0 +1,214 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.xml.internal.QueryProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.MutableClassDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedNativeQuery; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedNativeQueryJpaAnnotation implements NamedNativeQuery { + private String name; + private String query; + private jakarta.persistence.QueryHint[] hints; + private java.lang.Class resultClass; + private String resultSetMapping; + private jakarta.persistence.EntityResult[] entities; + private jakarta.persistence.ConstructorResult[] classes; + private jakarta.persistence.ColumnResult[] columns; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedNativeQueryJpaAnnotation(SourceModelBuildingContext modelContext) { + this.hints = new jakarta.persistence.QueryHint[0]; + this.resultClass = void.class; + this.resultSetMapping = ""; + this.entities = new jakarta.persistence.EntityResult[0]; + this.classes = new jakarta.persistence.ConstructorResult[0]; + this.columns = new jakarta.persistence.ColumnResult[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedNativeQueryJpaAnnotation(NamedNativeQuery annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "name", modelContext ); + this.query = extractJdkValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "query", modelContext ); + this.hints = extractJdkValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "hints", modelContext ); + this.resultClass = extractJdkValue( + annotation, + JpaAnnotations.NAMED_NATIVE_QUERY, + "resultClass", + modelContext + ); + this.resultSetMapping = extractJdkValue( + annotation, + JpaAnnotations.NAMED_NATIVE_QUERY, + "resultSetMapping", + modelContext + ); + this.entities = extractJdkValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "entities", modelContext ); + this.classes = extractJdkValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "classes", modelContext ); + this.columns = extractJdkValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "columns", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedNativeQueryJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "name", modelContext ); + this.query = extractJandexValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "query", modelContext ); + this.hints = extractJandexValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "hints", modelContext ); + this.resultClass = extractJandexValue( + annotation, + JpaAnnotations.NAMED_NATIVE_QUERY, + "resultClass", + modelContext + ); + this.resultSetMapping = extractJandexValue( + annotation, + JpaAnnotations.NAMED_NATIVE_QUERY, + "resultSetMapping", + modelContext + ); + this.entities = extractJandexValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "entities", modelContext ); + this.classes = extractJandexValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "classes", modelContext ); + this.columns = extractJandexValue( annotation, JpaAnnotations.NAMED_NATIVE_QUERY, "columns", modelContext ); + } + + @Override + public Class annotationType() { + return NamedNativeQuery.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String query() { + return query; + } + + public void query(String value) { + this.query = value; + } + + + @Override + public jakarta.persistence.QueryHint[] hints() { + return hints; + } + + public void hints(jakarta.persistence.QueryHint[] value) { + this.hints = value; + } + + + @Override + public java.lang.Class resultClass() { + return resultClass; + } + + public void resultClass(java.lang.Class value) { + this.resultClass = value; + } + + + @Override + public String resultSetMapping() { + return resultSetMapping; + } + + public void resultSetMapping(String value) { + this.resultSetMapping = value; + } + + + @Override + public jakarta.persistence.EntityResult[] entities() { + return entities; + } + + public void entities(jakarta.persistence.EntityResult[] value) { + this.entities = value; + } + + + @Override + public jakarta.persistence.ConstructorResult[] classes() { + return classes; + } + + public void classes(jakarta.persistence.ConstructorResult[] value) { + this.classes = value; + } + + + @Override + public jakarta.persistence.ColumnResult[] columns() { + return columns; + } + + public void columns(jakarta.persistence.ColumnResult[] value) { + this.columns = value; + } + + + public void apply(JaxbNamedNativeQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { + name( jaxbNamedQuery.getName() ); + query( jaxbNamedQuery.getQuery() ); + + hints( QueryProcessing.collectQueryHints( jaxbNamedQuery.getHints(), xmlDocumentContext ) ); + + if ( StringHelper.isNotEmpty( jaxbNamedQuery.getResultClass() ) ) { + final MutableClassDetails resultClassDetails = xmlDocumentContext.resolveJavaType( jaxbNamedQuery.getResultClass() ); + resultClass( resultClassDetails.toJavaClass() ); + } + + if ( StringHelper.isNotEmpty( jaxbNamedQuery.getResultSetMapping() ) ) { + resultSetMapping( jaxbNamedQuery.getResultSetMapping() ); + } + + columns( QueryProcessing.extractColumnResults( + jaxbNamedQuery.getColumnResult(), + xmlDocumentContext + ) ); + + + classes( QueryProcessing.extractConstructorResults( + jaxbNamedQuery.getConstructorResult(), + xmlDocumentContext + ) ); + + entities( QueryProcessing.extractEntityResults( + jaxbNamedQuery.getEntityResult(), + xmlDocumentContext + ) ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueriesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueriesAnnotation.java new file mode 100644 index 0000000000..da3748952e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueriesAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.NamedQueries; +import org.hibernate.annotations.NamedQuery; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.HibernateAnnotations.NAMED_QUERIES; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedQueriesAnnotation implements NamedQueries, RepeatableContainer { + private NamedQuery[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedQueriesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedQueriesAnnotation(NamedQueries annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, NAMED_QUERIES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedQueriesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, NAMED_QUERIES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return NamedQueries.class; + } + + @Override + public NamedQuery[] value() { + return value; + } + + public void value(NamedQuery[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueriesJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueriesJpaAnnotation.java new file mode 100644 index 0000000000..b0a83bc4a0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueriesJpaAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedQueries; +import jakarta.persistence.NamedQuery; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedQueriesJpaAnnotation implements NamedQueries, RepeatableContainer { + private jakarta.persistence.NamedQuery[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedQueriesJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedQueriesJpaAnnotation(NamedQueries annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.NAMED_QUERIES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedQueriesJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.NAMED_QUERIES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return NamedQueries.class; + } + + @Override + public jakarta.persistence.NamedQuery[] value() { + return value; + } + + public void value(jakarta.persistence.NamedQuery[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryAnnotation.java new file mode 100644 index 0000000000..a847e5c1ca --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryAnnotation.java @@ -0,0 +1,256 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.CacheMode; +import org.hibernate.annotations.CacheModeType; +import org.hibernate.annotations.FlushModeType; +import org.hibernate.annotations.NamedQuery; +import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.CacheRetrieveMode; +import jakarta.persistence.CacheStoreMode; + +import static org.hibernate.boot.models.HibernateAnnotations.NAMED_QUERY; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; +import static org.hibernate.boot.models.xml.internal.QueryProcessing.interpretFlushMode; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedQueryAnnotation implements NamedQuery { + private String name; + private String query; + private Class resultClass; + private FlushModeType flushMode; + boolean cacheable; + String cacheRegion; + int fetchSize; + int timeout; + String comment; + CacheStoreMode cacheStoreMode; + CacheRetrieveMode cacheRetrieveMode; + CacheModeType cacheMode; + boolean readOnly; + + public NamedQueryAnnotation(SourceModelBuildingContext modelContext) { + resultClass = void.class; + flushMode = FlushModeType.PERSISTENCE_CONTEXT; + cacheable = false; + cacheRegion = ""; + fetchSize = -1; + timeout = -1; + comment = ""; + cacheStoreMode = CacheStoreMode.USE; + cacheRetrieveMode = CacheRetrieveMode.USE; + cacheMode = CacheModeType.NORMAL; + readOnly = false; + } + + public NamedQueryAnnotation(NamedQuery annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, NAMED_QUERY, "name", modelContext ); + this.query = extractJdkValue( annotation, NAMED_QUERY, "query", modelContext ); + this.resultClass = extractJdkValue( annotation, NAMED_QUERY, "resultClass", modelContext ); + this.flushMode = extractJdkValue( annotation, NAMED_QUERY, "flushMode", modelContext ); + this.cacheable = extractJdkValue( annotation, NAMED_QUERY, "cacheable", modelContext ); + this.cacheRegion = extractJdkValue( annotation, NAMED_QUERY, "cacheRegion", modelContext ); + this.fetchSize = extractJdkValue( annotation, NAMED_QUERY, "fetchSize", modelContext ); + this.timeout = extractJdkValue( annotation, NAMED_QUERY, "timeout", modelContext ); + this.comment = extractJdkValue( annotation, NAMED_QUERY, "comment", modelContext ); + this.cacheStoreMode = extractJdkValue( annotation, NAMED_QUERY, "cacheStoreMode", modelContext ); + this.cacheRetrieveMode = extractJdkValue( annotation, NAMED_QUERY, "cacheRetrieveMode", modelContext ); + this.cacheMode = extractJdkValue( annotation, NAMED_QUERY, "cacheMode", modelContext ); + this.readOnly = extractJdkValue( annotation, NAMED_QUERY, "readOnly", modelContext ); + } + + public NamedQueryAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, NAMED_QUERY, "name", modelContext ); + this.query = extractJandexValue( annotation, NAMED_QUERY, "query", modelContext ); + this.resultClass = extractJandexValue( annotation, NAMED_QUERY, "resultClass", modelContext ); + this.flushMode = extractJandexValue( annotation, NAMED_QUERY, "flushMode", modelContext ); + this.cacheable = extractJandexValue( annotation, NAMED_QUERY, "cacheable", modelContext ); + this.cacheRegion = extractJandexValue( annotation, NAMED_QUERY, "cacheRegion", modelContext ); + this.fetchSize = extractJandexValue( annotation, NAMED_QUERY, "fetchSize", modelContext ); + this.timeout = extractJandexValue( annotation, NAMED_QUERY, "timeout", modelContext ); + this.comment = extractJandexValue( annotation, NAMED_QUERY, "comment", modelContext ); + this.cacheStoreMode = extractJandexValue( annotation, NAMED_QUERY, "cacheStoreMode", modelContext ); + this.cacheRetrieveMode = extractJandexValue( annotation, NAMED_QUERY, "cacheRetrieveMode", modelContext ); + this.cacheMode = extractJandexValue( annotation, NAMED_QUERY, "cacheMode", modelContext ); + this.readOnly = extractJandexValue( annotation, NAMED_QUERY, "readOnly", modelContext ); + } + + @Override + public Class annotationType() { + return NamedQuery.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String query() { + return query; + } + + public void query(String value) { + this.query = value; + } + + + @Override + public Class resultClass() { + return resultClass; + } + + public void resultClass(Class value) { + this.resultClass = value; + } + + @Override + public FlushModeType flushMode() { + return flushMode; + } + + public void flushMode(FlushModeType value) { + this.flushMode = value; + } + + @Override + public boolean cacheable() { + return cacheable; + } + + public void cacheable(boolean value) { + this.cacheable = value; + } + + @Override + public String cacheRegion() { + return cacheRegion; + } + + public void cacheRegion(String value) { + this.cacheRegion = value; + } + + @Override + public int fetchSize() { + return fetchSize; + } + + public void fetchSize(int value) { + this.fetchSize = value; + } + + @Override + public int timeout() { + return timeout; + } + + public void timeout(int value) { + this.timeout = value; + } + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + @Override + public CacheStoreMode cacheStoreMode() { + return cacheStoreMode; + } + + public void cacheStoreMode(CacheStoreMode value) { + this.cacheStoreMode = value; + } + + @Override + public CacheRetrieveMode cacheRetrieveMode() { + return cacheRetrieveMode; + } + + public void cacheRetrieveMode(CacheRetrieveMode value) { + this.cacheRetrieveMode = value; + } + + @Override + public CacheModeType cacheMode() { + return cacheMode; + } + + public void cacheMode(CacheModeType value) { + this.cacheMode = value; + } + + @Override + public boolean readOnly() { + return readOnly; + } + + public void readOnly(boolean value) { + this.readOnly = value; + } + + + public void apply(JaxbNamedQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { + name( jaxbNamedQuery.getName() ); + query( jaxbNamedQuery.getQuery() ); + + if ( jaxbNamedQuery.isCacheable() != null ) { + final boolean cacheable = jaxbNamedQuery.isCacheable(); + cacheable( cacheable ); + if ( cacheable ) { + if ( StringHelper.isNotEmpty( jaxbNamedQuery.getCacheRegion() ) ) { + cacheRegion( jaxbNamedQuery.getCacheRegion() ); + } + + final CacheMode cacheMode = jaxbNamedQuery.getCacheMode(); + if ( cacheMode != null && cacheMode != CacheMode.IGNORE ) { + cacheMode( CacheModeType.fromCacheMode( cacheMode ) ); + } + } + } + + if ( jaxbNamedQuery.getFetchSize() != null ) { + fetchSize( jaxbNamedQuery.getFetchSize() ); + } + + if ( jaxbNamedQuery.getTimeout() != null ) { + timeout( jaxbNamedQuery.getTimeout() ); + } + + if ( StringHelper.isNotEmpty( jaxbNamedQuery.getComment() ) ) { + comment( jaxbNamedQuery.getComment() ); + } + + if ( jaxbNamedQuery.isReadOnly() != null ) { + readOnly( jaxbNamedQuery.isReadOnly() ); + } + if ( jaxbNamedQuery.getFlushMode() != null ) { + flushMode( interpretFlushMode( jaxbNamedQuery.getFlushMode() ) ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryJpaAnnotation.java new file mode 100644 index 0000000000..a8dc6194fa --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedQueryJpaAnnotation.java @@ -0,0 +1,127 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.xml.internal.QueryProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedQuery; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; +import static org.hibernate.internal.util.NullnessHelper.coalesce; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedQueryJpaAnnotation implements NamedQuery { + private String name; + private String query; + private java.lang.Class resultClass; + private jakarta.persistence.LockModeType lockMode; + private jakarta.persistence.QueryHint[] hints; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedQueryJpaAnnotation(SourceModelBuildingContext modelContext) { + this.resultClass = void.class; + this.lockMode = jakarta.persistence.LockModeType.NONE; + this.hints = new jakarta.persistence.QueryHint[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedQueryJpaAnnotation(NamedQuery annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.NAMED_QUERY, "name", modelContext ); + this.query = extractJdkValue( annotation, JpaAnnotations.NAMED_QUERY, "query", modelContext ); + this.resultClass = extractJdkValue( annotation, JpaAnnotations.NAMED_QUERY, "resultClass", modelContext ); + this.lockMode = extractJdkValue( annotation, JpaAnnotations.NAMED_QUERY, "lockMode", modelContext ); + this.hints = extractJdkValue( annotation, JpaAnnotations.NAMED_QUERY, "hints", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedQueryJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.NAMED_QUERY, "name", modelContext ); + this.query = extractJandexValue( annotation, JpaAnnotations.NAMED_QUERY, "query", modelContext ); + this.resultClass = extractJandexValue( annotation, JpaAnnotations.NAMED_QUERY, "resultClass", modelContext ); + this.lockMode = extractJandexValue( annotation, JpaAnnotations.NAMED_QUERY, "lockMode", modelContext ); + this.hints = extractJandexValue( annotation, JpaAnnotations.NAMED_QUERY, "hints", modelContext ); + } + + @Override + public Class annotationType() { + return NamedQuery.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String query() { + return query; + } + + public void query(String value) { + this.query = value; + } + + + @Override + public java.lang.Class resultClass() { + return resultClass; + } + + public void resultClass(java.lang.Class value) { + this.resultClass = value; + } + + + @Override + public jakarta.persistence.LockModeType lockMode() { + return lockMode; + } + + public void lockMode(jakarta.persistence.LockModeType value) { + this.lockMode = value; + } + + + @Override + public jakarta.persistence.QueryHint[] hints() { + return hints; + } + + public void hints(jakarta.persistence.QueryHint[] value) { + this.hints = value; + } + + + public void apply(JaxbNamedQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { + name( jaxbNamedQuery.getName() ); + query( jaxbNamedQuery.getQuery() ); + lockMode( coalesce( jaxbNamedQuery.getLockMode(), jakarta.persistence.LockModeType.NONE ) ); + + hints( QueryProcessing.collectQueryHints( jaxbNamedQuery.getHints(), xmlDocumentContext ) ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedStoredProcedureQueriesJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedStoredProcedureQueriesJpaAnnotation.java new file mode 100644 index 0000000000..fec59aa14d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedStoredProcedureQueriesJpaAnnotation.java @@ -0,0 +1,78 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedStoredProcedureQueries; +import jakarta.persistence.NamedStoredProcedureQuery; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedStoredProcedureQueriesJpaAnnotation + implements NamedStoredProcedureQueries, RepeatableContainer { + private jakarta.persistence.NamedStoredProcedureQuery[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedStoredProcedureQueriesJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedStoredProcedureQueriesJpaAnnotation( + NamedStoredProcedureQueries annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERIES, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedStoredProcedureQueriesJpaAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERIES, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return NamedStoredProcedureQueries.class; + } + + @Override + public jakarta.persistence.NamedStoredProcedureQuery[] value() { + return value; + } + + public void value(jakarta.persistence.NamedStoredProcedureQuery[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedStoredProcedureQueryJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedStoredProcedureQueryJpaAnnotation.java new file mode 100644 index 0000000000..102057bbd1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedStoredProcedureQueryJpaAnnotation.java @@ -0,0 +1,192 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.xml.internal.QueryProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedStoredProcedureQuery; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedStoredProcedureQueryJpaAnnotation implements NamedStoredProcedureQuery { + private String name; + private String procedureName; + private jakarta.persistence.StoredProcedureParameter[] parameters; + private java.lang.Class[] resultClasses; + private String[] resultSetMappings; + private jakarta.persistence.QueryHint[] hints; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedStoredProcedureQueryJpaAnnotation(SourceModelBuildingContext modelContext) { + this.parameters = new jakarta.persistence.StoredProcedureParameter[0]; + this.resultClasses = new java.lang.Class[0]; + this.resultSetMappings = new String[0]; + this.hints = new jakarta.persistence.QueryHint[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedStoredProcedureQueryJpaAnnotation( + NamedStoredProcedureQuery annotation, + SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, "name", modelContext ); + this.procedureName = extractJdkValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "procedureName", + modelContext + ); + this.parameters = extractJdkValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "parameters", + modelContext + ); + this.resultClasses = extractJdkValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "resultClasses", + modelContext + ); + this.resultSetMappings = extractJdkValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "resultSetMappings", + modelContext + ); + this.hints = extractJdkValue( annotation, JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, "hints", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedStoredProcedureQueryJpaAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, "name", modelContext ); + this.procedureName = extractJandexValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "procedureName", + modelContext + ); + this.parameters = extractJandexValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "parameters", + modelContext + ); + this.resultClasses = extractJandexValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "resultClasses", + modelContext + ); + this.resultSetMappings = extractJandexValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "resultSetMappings", + modelContext + ); + this.hints = extractJandexValue( + annotation, + JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + "hints", + modelContext + ); + } + + @Override + public Class annotationType() { + return NamedStoredProcedureQuery.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String procedureName() { + return procedureName; + } + + public void procedureName(String value) { + this.procedureName = value; + } + + + @Override + public jakarta.persistence.StoredProcedureParameter[] parameters() { + return parameters; + } + + public void parameters(jakarta.persistence.StoredProcedureParameter[] value) { + this.parameters = value; + } + + + @Override + public java.lang.Class[] resultClasses() { + return resultClasses; + } + + public void resultClasses(java.lang.Class[] value) { + this.resultClasses = value; + } + + + @Override + public String[] resultSetMappings() { + return resultSetMappings; + } + + public void resultSetMappings(String[] value) { + this.resultSetMappings = value; + } + + + @Override + public jakarta.persistence.QueryHint[] hints() { + return hints; + } + + public void hints(jakarta.persistence.QueryHint[] value) { + this.hints = value; + } + + + public void apply(JaxbNamedStoredProcedureQueryImpl jaxbQuery, XmlDocumentContext xmlDocumentContext) { + name( jaxbQuery.getName() ); + procedureName( jaxbQuery.getProcedureName() ); + + hints( QueryProcessing.collectQueryHints( jaxbQuery.getHints(), xmlDocumentContext ) ); + parameters( QueryProcessing.collectParameters( jaxbQuery.getProcedureParameters(), xmlDocumentContext ) ); + + resultClasses( QueryProcessing.collectResultClasses( jaxbQuery.getResultClasses(), xmlDocumentContext ) ); + resultSetMappings( QueryProcessing.collectResultMappings( jaxbQuery.getResultClasses(), xmlDocumentContext ) ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedSubgraphJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedSubgraphJpaAnnotation.java new file mode 100644 index 0000000000..6cc357d5b2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NamedSubgraphJpaAnnotation.java @@ -0,0 +1,98 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.NamedSubgraph; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NamedSubgraphJpaAnnotation implements NamedSubgraph { + private String name; + private java.lang.Class type; + private jakarta.persistence.NamedAttributeNode[] attributeNodes; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NamedSubgraphJpaAnnotation(SourceModelBuildingContext modelContext) { + this.type = void.class; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NamedSubgraphJpaAnnotation(NamedSubgraph annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.NAMED_SUBGRAPH, "name", modelContext ); + this.type = extractJdkValue( annotation, JpaAnnotations.NAMED_SUBGRAPH, "type", modelContext ); + this.attributeNodes = extractJdkValue( + annotation, + JpaAnnotations.NAMED_SUBGRAPH, + "attributeNodes", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NamedSubgraphJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.NAMED_SUBGRAPH, "name", modelContext ); + this.type = extractJandexValue( annotation, JpaAnnotations.NAMED_SUBGRAPH, "type", modelContext ); + this.attributeNodes = extractJandexValue( + annotation, + JpaAnnotations.NAMED_SUBGRAPH, + "attributeNodes", + modelContext + ); + } + + @Override + public Class annotationType() { + return NamedSubgraph.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public java.lang.Class type() { + return type; + } + + public void type(java.lang.Class value) { + this.type = value; + } + + + @Override + public jakarta.persistence.NamedAttributeNode[] attributeNodes() { + return attributeNodes; + } + + public void attributeNodes(jakarta.persistence.NamedAttributeNode[] value) { + this.attributeNodes = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NationalizedAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NationalizedAnnotation.java new file mode 100644 index 0000000000..8b557f245c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NationalizedAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Nationalized; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NationalizedAnnotation implements Nationalized { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NationalizedAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NationalizedAnnotation(Nationalized annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NationalizedAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Nationalized.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NaturalIdAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NaturalIdAnnotation.java new file mode 100644 index 0000000000..25b9a30f35 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NaturalIdAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.NaturalId; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NaturalIdAnnotation implements NaturalId { + private boolean mutable; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NaturalIdAnnotation(SourceModelBuildingContext modelContext) { + this.mutable = false; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NaturalIdAnnotation(NaturalId annotation, SourceModelBuildingContext modelContext) { + this.mutable = extractJdkValue( annotation, HibernateAnnotations.NATURAL_ID, "mutable", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NaturalIdAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.mutable = extractJandexValue( annotation, HibernateAnnotations.NATURAL_ID, "mutable", modelContext ); + } + + @Override + public Class annotationType() { + return NaturalId.class; + } + + @Override + public boolean mutable() { + return mutable; + } + + public void mutable(boolean value) { + this.mutable = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NaturalIdCacheAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NaturalIdCacheAnnotation.java new file mode 100644 index 0000000000..11338023bc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NaturalIdCacheAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.NaturalIdCache; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NaturalIdCacheAnnotation implements NaturalIdCache { + private String region; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NaturalIdCacheAnnotation(SourceModelBuildingContext modelContext) { + this.region = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NaturalIdCacheAnnotation(NaturalIdCache annotation, SourceModelBuildingContext modelContext) { + this.region = extractJdkValue( annotation, HibernateAnnotations.NATURAL_ID_CACHE, "region", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NaturalIdCacheAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.region = extractJandexValue( annotation, HibernateAnnotations.NATURAL_ID_CACHE, "region", modelContext ); + } + + @Override + public Class annotationType() { + return NaturalIdCache.class; + } + + @Override + public String region() { + return region; + } + + public void region(String value) { + this.region = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NotFoundAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NotFoundAnnotation.java new file mode 100644 index 0000000000..6c87335f00 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/NotFoundAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.NotFound; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class NotFoundAnnotation implements NotFound { + private org.hibernate.annotations.NotFoundAction action; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public NotFoundAnnotation(SourceModelBuildingContext modelContext) { + this.action = org.hibernate.annotations.NotFoundAction.EXCEPTION; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public NotFoundAnnotation(NotFound annotation, SourceModelBuildingContext modelContext) { + this.action = extractJdkValue( annotation, HibernateAnnotations.NOT_FOUND, "action", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public NotFoundAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.action = extractJandexValue( annotation, HibernateAnnotations.NOT_FOUND, "action", modelContext ); + } + + @Override + public Class annotationType() { + return NotFound.class; + } + + @Override + public org.hibernate.annotations.NotFoundAction action() { + return action; + } + + public void action(org.hibernate.annotations.NotFoundAction value) { + this.action = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OnDeleteAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OnDeleteAnnotation.java new file mode 100644 index 0000000000..eccbacef9f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OnDeleteAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.OnDelete; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OnDeleteAnnotation implements OnDelete { + private org.hibernate.annotations.OnDeleteAction action; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OnDeleteAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OnDeleteAnnotation(OnDelete annotation, SourceModelBuildingContext modelContext) { + this.action = extractJdkValue( annotation, HibernateAnnotations.ON_DELETE, "action", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OnDeleteAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.action = extractJandexValue( annotation, HibernateAnnotations.ON_DELETE, "action", modelContext ); + } + + @Override + public Class annotationType() { + return OnDelete.class; + } + + @Override + public org.hibernate.annotations.OnDeleteAction action() { + return action; + } + + public void action(org.hibernate.annotations.OnDeleteAction value) { + this.action = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OneToManyJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OneToManyJpaAnnotation.java new file mode 100644 index 0000000000..3295e9238f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OneToManyJpaAnnotation.java @@ -0,0 +1,124 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.OneToMany; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OneToManyJpaAnnotation implements OneToMany, AttributeMarker.Fetchable, AttributeMarker.Cascadeable { + private java.lang.Class targetEntity; + private jakarta.persistence.CascadeType[] cascade; + private jakarta.persistence.FetchType fetch; + private String mappedBy; + private boolean orphanRemoval; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OneToManyJpaAnnotation(SourceModelBuildingContext modelContext) { + this.targetEntity = void.class; + this.cascade = new jakarta.persistence.CascadeType[0]; + this.fetch = jakarta.persistence.FetchType.LAZY; + this.mappedBy = ""; + this.orphanRemoval = false; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OneToManyJpaAnnotation(OneToMany annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJdkValue( annotation, JpaAnnotations.ONE_TO_MANY, "targetEntity", modelContext ); + this.cascade = extractJdkValue( annotation, JpaAnnotations.ONE_TO_MANY, "cascade", modelContext ); + this.fetch = extractJdkValue( annotation, JpaAnnotations.ONE_TO_MANY, "fetch", modelContext ); + this.mappedBy = extractJdkValue( annotation, JpaAnnotations.ONE_TO_MANY, "mappedBy", modelContext ); + this.orphanRemoval = extractJdkValue( annotation, JpaAnnotations.ONE_TO_MANY, "orphanRemoval", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OneToManyJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJandexValue( annotation, JpaAnnotations.ONE_TO_MANY, "targetEntity", modelContext ); + this.cascade = extractJandexValue( annotation, JpaAnnotations.ONE_TO_MANY, "cascade", modelContext ); + this.fetch = extractJandexValue( annotation, JpaAnnotations.ONE_TO_MANY, "fetch", modelContext ); + this.mappedBy = extractJandexValue( annotation, JpaAnnotations.ONE_TO_MANY, "mappedBy", modelContext ); + this.orphanRemoval = extractJandexValue( + annotation, + JpaAnnotations.ONE_TO_MANY, + "orphanRemoval", + modelContext + ); + } + + @Override + public Class annotationType() { + return OneToMany.class; + } + + @Override + public java.lang.Class targetEntity() { + return targetEntity; + } + + public void targetEntity(java.lang.Class value) { + this.targetEntity = value; + } + + + @Override + public jakarta.persistence.CascadeType[] cascade() { + return cascade; + } + + public void cascade(jakarta.persistence.CascadeType[] value) { + this.cascade = value; + } + + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + + @Override + public String mappedBy() { + return mappedBy; + } + + public void mappedBy(String value) { + this.mappedBy = value; + } + + + @Override + public boolean orphanRemoval() { + return orphanRemoval; + } + + public void orphanRemoval(boolean value) { + this.orphanRemoval = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OneToOneJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OneToOneJpaAnnotation.java new file mode 100644 index 0000000000..94937890be --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OneToOneJpaAnnotation.java @@ -0,0 +1,134 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.OneToOne; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OneToOneJpaAnnotation + implements OneToOne, AttributeMarker.Fetchable, AttributeMarker.Cascadeable, AttributeMarker.Optionalable { + private java.lang.Class targetEntity; + private jakarta.persistence.CascadeType[] cascade; + private jakarta.persistence.FetchType fetch; + private boolean optional; + private String mappedBy; + private boolean orphanRemoval; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OneToOneJpaAnnotation(SourceModelBuildingContext modelContext) { + this.targetEntity = void.class; + this.cascade = new jakarta.persistence.CascadeType[0]; + this.fetch = jakarta.persistence.FetchType.EAGER; + this.optional = true; + this.mappedBy = ""; + this.orphanRemoval = false; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OneToOneJpaAnnotation(OneToOne annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJdkValue( annotation, JpaAnnotations.ONE_TO_ONE, "targetEntity", modelContext ); + this.cascade = extractJdkValue( annotation, JpaAnnotations.ONE_TO_ONE, "cascade", modelContext ); + this.fetch = extractJdkValue( annotation, JpaAnnotations.ONE_TO_ONE, "fetch", modelContext ); + this.optional = extractJdkValue( annotation, JpaAnnotations.ONE_TO_ONE, "optional", modelContext ); + this.mappedBy = extractJdkValue( annotation, JpaAnnotations.ONE_TO_ONE, "mappedBy", modelContext ); + this.orphanRemoval = extractJdkValue( annotation, JpaAnnotations.ONE_TO_ONE, "orphanRemoval", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OneToOneJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.targetEntity = extractJandexValue( annotation, JpaAnnotations.ONE_TO_ONE, "targetEntity", modelContext ); + this.cascade = extractJandexValue( annotation, JpaAnnotations.ONE_TO_ONE, "cascade", modelContext ); + this.fetch = extractJandexValue( annotation, JpaAnnotations.ONE_TO_ONE, "fetch", modelContext ); + this.optional = extractJandexValue( annotation, JpaAnnotations.ONE_TO_ONE, "optional", modelContext ); + this.mappedBy = extractJandexValue( annotation, JpaAnnotations.ONE_TO_ONE, "mappedBy", modelContext ); + this.orphanRemoval = extractJandexValue( annotation, JpaAnnotations.ONE_TO_ONE, "orphanRemoval", modelContext ); + } + + @Override + public Class annotationType() { + return OneToOne.class; + } + + @Override + public java.lang.Class targetEntity() { + return targetEntity; + } + + public void targetEntity(java.lang.Class value) { + this.targetEntity = value; + } + + + @Override + public jakarta.persistence.CascadeType[] cascade() { + return cascade; + } + + public void cascade(jakarta.persistence.CascadeType[] value) { + this.cascade = value; + } + + + @Override + public jakarta.persistence.FetchType fetch() { + return fetch; + } + + public void fetch(jakarta.persistence.FetchType value) { + this.fetch = value; + } + + + @Override + public boolean optional() { + return optional; + } + + public void optional(boolean value) { + this.optional = value; + } + + + @Override + public String mappedBy() { + return mappedBy; + } + + public void mappedBy(String value) { + this.mappedBy = value; + } + + + @Override + public boolean orphanRemoval() { + return orphanRemoval; + } + + public void orphanRemoval(boolean value) { + this.orphanRemoval = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OptimisticLockAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OptimisticLockAnnotation.java new file mode 100644 index 0000000000..a718a2311b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OptimisticLockAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.OptimisticLock; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OptimisticLockAnnotation implements OptimisticLock { + private boolean excluded; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OptimisticLockAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OptimisticLockAnnotation(OptimisticLock annotation, SourceModelBuildingContext modelContext) { + this.excluded = extractJdkValue( annotation, HibernateAnnotations.OPTIMISTIC_LOCK, "excluded", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OptimisticLockAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.excluded = extractJandexValue( + annotation, + HibernateAnnotations.OPTIMISTIC_LOCK, + "excluded", + modelContext + ); + } + + @Override + public Class annotationType() { + return OptimisticLock.class; + } + + @Override + public boolean excluded() { + return excluded; + } + + public void excluded(boolean value) { + this.excluded = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OptimisticLockingAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OptimisticLockingAnnotation.java new file mode 100644 index 0000000000..11ad5826e2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OptimisticLockingAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.OptimisticLocking; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OptimisticLockingAnnotation implements OptimisticLocking { + private org.hibernate.annotations.OptimisticLockType type; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OptimisticLockingAnnotation(SourceModelBuildingContext modelContext) { + this.type = org.hibernate.annotations.OptimisticLockType.VERSION; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OptimisticLockingAnnotation(OptimisticLocking annotation, SourceModelBuildingContext modelContext) { + this.type = extractJdkValue( annotation, HibernateAnnotations.OPTIMISTIC_LOCKING, "type", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OptimisticLockingAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.type = extractJandexValue( annotation, HibernateAnnotations.OPTIMISTIC_LOCKING, "type", modelContext ); + } + + @Override + public Class annotationType() { + return OptimisticLocking.class; + } + + @Override + public org.hibernate.annotations.OptimisticLockType type() { + return type; + } + + public void type(org.hibernate.annotations.OptimisticLockType value) { + this.type = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderByAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderByAnnotation.java new file mode 100644 index 0000000000..c7ac9d2dcd --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderByAnnotation.java @@ -0,0 +1,46 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.OrderBy; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OrderByAnnotation implements OrderBy { + private String clause; + + public OrderByAnnotation(SourceModelBuildingContext modelContext) { + this.clause = ""; + } + + public OrderByAnnotation(OrderBy annotation, SourceModelBuildingContext modelContext) { + } + + public OrderByAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return OrderBy.class; + } + + @Override + public String clause() { + return clause; + } + + public void clause(String value) { + this.clause = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderByJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderByJpaAnnotation.java new file mode 100644 index 0000000000..f3d475d60f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderByJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.OrderBy; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OrderByJpaAnnotation implements OrderBy { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OrderByJpaAnnotation(SourceModelBuildingContext modelContext) { + this.value = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OrderByJpaAnnotation(OrderBy annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.ORDER_BY, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OrderByJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.ORDER_BY, "value", modelContext ); + } + + @Override + public Class annotationType() { + return OrderBy.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderColumnJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderColumnJpaAnnotation.java new file mode 100644 index 0000000000..0c0017229a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OrderColumnJpaAnnotation.java @@ -0,0 +1,175 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbOrderColumnImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.ColumnDetails; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.OrderColumn; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OrderColumnJpaAnnotation implements OrderColumn, + ColumnDetails, + ColumnDetails.Definable, + ColumnDetails.Nullable, + ColumnDetails.Mutable { + private String name; + private boolean nullable; + private boolean insertable; + private boolean updatable; + private String columnDefinition; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OrderColumnJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.nullable = true; + this.insertable = true; + this.updatable = true; + this.columnDefinition = ""; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OrderColumnJpaAnnotation(OrderColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.ORDER_COLUMN, "name", modelContext ); + this.nullable = extractJdkValue( annotation, JpaAnnotations.ORDER_COLUMN, "nullable", modelContext ); + this.insertable = extractJdkValue( annotation, JpaAnnotations.ORDER_COLUMN, "insertable", modelContext ); + this.updatable = extractJdkValue( annotation, JpaAnnotations.ORDER_COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJdkValue( + annotation, + JpaAnnotations.ORDER_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJdkValue( annotation, JpaAnnotations.ORDER_COLUMN, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OrderColumnJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.ORDER_COLUMN, "name", modelContext ); + this.nullable = extractJandexValue( annotation, JpaAnnotations.ORDER_COLUMN, "nullable", modelContext ); + this.insertable = extractJandexValue( annotation, JpaAnnotations.ORDER_COLUMN, "insertable", modelContext ); + this.updatable = extractJandexValue( annotation, JpaAnnotations.ORDER_COLUMN, "updatable", modelContext ); + this.columnDefinition = extractJandexValue( + annotation, + JpaAnnotations.ORDER_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.ORDER_COLUMN, "options", modelContext ); + } + + @Override + public Class annotationType() { + return OrderColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public boolean nullable() { + return nullable; + } + + public void nullable(boolean value) { + this.nullable = value; + } + + + @Override + public boolean insertable() { + return insertable; + } + + public void insertable(boolean value) { + this.insertable = value; + } + + + @Override + public boolean updatable() { + return updatable; + } + + public void updatable(boolean value) { + this.updatable = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + public void apply(JaxbOrderColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( jaxbColumn.isNullable() != null ) { + nullable( jaxbColumn.isNullable() ); + } + + if ( jaxbColumn.isInsertable() != null ) { + insertable( jaxbColumn.isInsertable() ); + } + + if ( jaxbColumn.isUpdatable() != null ) { + updatable( jaxbColumn.isUpdatable() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenCheckAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenCheckAnnotation.java new file mode 100644 index 0000000000..84ab2aef98 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenCheckAnnotation.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Check; +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_CHECK; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenCheckAnnotation + extends AbstractOverrider + implements DialectOverride.Check, DialectOverrider { + private Check override; + + public OverriddenCheckAnnotation(SourceModelBuildingContext modelContext) { + } + + public OverriddenCheckAnnotation(DialectOverride.Check annotation, SourceModelBuildingContext modelContext) { + dialect( annotation.dialect() ); + before( annotation.before() ); + sameOrAfter( annotation.sameOrAfter() ); + override( extractJdkValue( annotation, DIALECT_OVERRIDE_CHECK, "override", modelContext ) ); + } + + public OverriddenCheckAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + super( annotation, DIALECT_OVERRIDE_CHECK, modelContext ); + override( extractJandexValue( annotation, DIALECT_OVERRIDE_CHECK, "override", modelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.CHECK; + } + + @Override + public Check override() { + return override; + } + + public void override(Check value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Check.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenChecksAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenChecksAnnotation.java new file mode 100644 index 0000000000..1caf830e75 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenChecksAnnotation.java @@ -0,0 +1,59 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenChecksAnnotation + implements DialectOverride.Checks, RepeatableContainer { + private DialectOverride.Check[] value; + + public OverriddenChecksAnnotation(SourceModelBuildingContext modelContext) { + } + + public OverriddenChecksAnnotation(DialectOverride.Checks source, SourceModelBuildingContext modelContext) { + value( extractJdkValue( source, DialectOverrideAnnotations.DIALECT_OVERRIDE_CHECKS, "value", modelContext ) ); + } + + public OverriddenChecksAnnotation(AnnotationInstance source, SourceModelBuildingContext modelContext) { + value( extractJandexValue( + source, + DialectOverrideAnnotations.DIALECT_OVERRIDE_CHECKS, + "value", + modelContext + ) ); + } + + @Override + public DialectOverride.Check[] value() { + return value; + } + + @Override + public void value(DialectOverride.Check[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Checks.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenColumnDefaultAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenColumnDefaultAnnotation.java new file mode 100644 index 0000000000..4aa2c63173 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenColumnDefaultAnnotation.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_COLUMN_DEFAULT; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenColumnDefaultAnnotation + extends AbstractOverrider + implements DialectOverride.ColumnDefault, DialectOverrider { + private ColumnDefault override; + + public OverriddenColumnDefaultAnnotation(SourceModelBuildingContext modelContext) { + } + + public OverriddenColumnDefaultAnnotation( + DialectOverride.ColumnDefault annotation, + SourceModelBuildingContext modelContext) { + dialect( annotation.dialect() ); + before( annotation.before() ); + sameOrAfter( annotation.sameOrAfter() ); + override( extractJdkValue( annotation, DIALECT_OVERRIDE_COLUMN_DEFAULT, "override", modelContext ) ); + } + + public OverriddenColumnDefaultAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + super( annotation, DIALECT_OVERRIDE_COLUMN_DEFAULT, modelContext ); + override( extractJandexValue( annotation, DIALECT_OVERRIDE_COLUMN_DEFAULT, "override", modelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.COLUMN_DEFAULT; + } + + @Override + public ColumnDefault override() { + return override; + } + + public void override(ColumnDefault value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.ColumnDefault.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenColumnDefaultsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenColumnDefaultsAnnotation.java new file mode 100644 index 0000000000..6ea0de67e8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenColumnDefaultsAnnotation.java @@ -0,0 +1,66 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_COLUMN_DEFAULTS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenColumnDefaultsAnnotation + implements DialectOverride.ColumnDefaults, + RepeatableContainer { + private DialectOverride.ColumnDefault[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenColumnDefaultsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenColumnDefaultsAnnotation( + DialectOverride.ColumnDefaults annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_COLUMN_DEFAULTS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenColumnDefaultsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_COLUMN_DEFAULTS, "value", modelContext ); + } + + @Override + public DialectOverride.ColumnDefault[] value() { + return value; + } + + @Override + public void value(DialectOverride.ColumnDefault[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.ColumnDefaults.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenDiscriminatorFormulaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenDiscriminatorFormulaAnnotation.java new file mode 100644 index 0000000000..cb04e2a3bd --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenDiscriminatorFormulaAnnotation.java @@ -0,0 +1,72 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.DiscriminatorFormula; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_DISCRIMINATOR_FORMULA; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenDiscriminatorFormulaAnnotation + extends AbstractOverrider + implements DialectOverride.DiscriminatorFormula, DialectOverrider { + private DiscriminatorFormula override; + + public OverriddenDiscriminatorFormulaAnnotation(SourceModelBuildingContext modelContext) { + } + + public OverriddenDiscriminatorFormulaAnnotation( + DialectOverride.DiscriminatorFormula annotation, + SourceModelBuildingContext modelContext) { + dialect( annotation.dialect() ); + before( annotation.before() ); + sameOrAfter( annotation.sameOrAfter() ); + override( extractJdkValue( annotation, DIALECT_OVERRIDE_DISCRIMINATOR_FORMULA, "override", modelContext ) ); + } + + public OverriddenDiscriminatorFormulaAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + super( annotation, DIALECT_OVERRIDE_DISCRIMINATOR_FORMULA, modelContext ); + override( extractJandexValue( annotation, DIALECT_OVERRIDE_DISCRIMINATOR_FORMULA, "override", modelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.DISCRIMINATOR_FORMULA; + } + + @Override + public DiscriminatorFormula override() { + return override; + } + + public void override(DiscriminatorFormula value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.DiscriminatorFormula.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenDiscriminatorFormulasAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenDiscriminatorFormulasAnnotation.java new file mode 100644 index 0000000000..fdce337226 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenDiscriminatorFormulasAnnotation.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_DISCRIMINATOR_FORMULAS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenDiscriminatorFormulasAnnotation + implements DialectOverride.DiscriminatorFormulas, + RepeatableContainer { + private DialectOverride.DiscriminatorFormula[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenDiscriminatorFormulasAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenDiscriminatorFormulasAnnotation( + DialectOverride.DiscriminatorFormulas annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_DISCRIMINATOR_FORMULAS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenDiscriminatorFormulasAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_DISCRIMINATOR_FORMULAS, "value", modelContext ); + } + + @Override + public DialectOverride.DiscriminatorFormula[] value() { + return value; + } + + @Override + public void value(DialectOverride.DiscriminatorFormula[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.DiscriminatorFormulas.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterDefOverridesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterDefOverridesAnnotation.java new file mode 100644 index 0000000000..2c7b4b8423 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterDefOverridesAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenFilterDefOverridesAnnotation + implements DialectOverride.FilterDefOverrides, RepeatableContainer { + private DialectOverride.FilterDefs[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenFilterDefOverridesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenFilterDefOverridesAnnotation( + DialectOverride.FilterDefOverrides annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenFilterDefOverridesAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_FILTER_DEF_OVERRIDES, "value", modelContext ); + } + + @Override + public DialectOverride.FilterDefs[] value() { + return value; + } + + @Override + public void value(DialectOverride.FilterDefs[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.FilterDefOverrides.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterDefsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterDefsAnnotation.java new file mode 100644 index 0000000000..ab3697956a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterDefsAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.FilterDefs; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_FILTER_DEFS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenFilterDefsAnnotation + extends AbstractOverrider + implements DialectOverride.FilterDefs, DialectOverrider { + private FilterDefs override; + + public OverriddenFilterDefsAnnotation(SourceModelBuildingContext modelContext) { + } + + public OverriddenFilterDefsAnnotation(DialectOverride.FilterDefs source, SourceModelBuildingContext modelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_FILTER_DEFS, "override", modelContext ) ); + } + + public OverriddenFilterDefsAnnotation(AnnotationInstance source, SourceModelBuildingContext modelContext) { + super( source, DIALECT_OVERRIDE_FILTER_DEFS, modelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_FILTER_DEFS, "override", modelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.FILTER_DEFS; + } + + @Override + public FilterDefs override() { + return override; + } + + public void override(FilterDefs value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.FilterDefs.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterOverridesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterOverridesAnnotation.java new file mode 100644 index 0000000000..2b418186db --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFilterOverridesAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_FILTER_OVERRIDES; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenFilterOverridesAnnotation + implements DialectOverride.FilterOverrides, RepeatableContainer { + private DialectOverride.Filters[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenFilterOverridesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenFilterOverridesAnnotation( + DialectOverride.FilterOverrides annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_FILTER_OVERRIDES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenFilterOverridesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_FILTER_OVERRIDES, "value", modelContext ); + } + + @Override + public DialectOverride.Filters[] value() { + return value; + } + + @Override + public void value(DialectOverride.Filters[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Formulas.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFiltersAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFiltersAnnotation.java new file mode 100644 index 0000000000..34be0568ee --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFiltersAnnotation.java @@ -0,0 +1,68 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.Filters; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_FILTERS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenFiltersAnnotation + extends AbstractOverrider + implements DialectOverride.Filters, DialectOverrider { + private Filters override; + + public OverriddenFiltersAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenFiltersAnnotation(DialectOverride.Filters source, SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_FILTERS, "override", sourceModelContext ) ); + } + + public OverriddenFiltersAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_FILTERS, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_FILTERS, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.FILTERS; + } + + @Override + public Filters override() { + return override; + } + + public void override(Filters value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Filters.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFormulaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFormulaAnnotation.java new file mode 100644 index 0000000000..4b19690308 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFormulaAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.Formula; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_FORMULA; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenFormulaAnnotation + extends AbstractOverrider + implements DialectOverride.Formula, DialectOverrider { + private Formula override; + + public OverriddenFormulaAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenFormulaAnnotation(DialectOverride.Formula source, SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_FORMULA, "override", sourceModelContext ) ); + } + + public OverriddenFormulaAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_FORMULA, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_FORMULA, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.FORMULA; + } + + @Override + public Formula override() { + return override; + } + + public void override(Formula value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Formula.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFormulasAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFormulasAnnotation.java new file mode 100644 index 0000000000..a25ed6bd79 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenFormulasAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_FORMULAS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenFormulasAnnotation + implements DialectOverride.Formulas, RepeatableContainer { + private DialectOverride.Formula[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenFormulasAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenFormulasAnnotation(DialectOverride.Formulas annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_FORMULAS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenFormulasAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_FORMULAS, "value", modelContext ); + } + + @Override + public DialectOverride.Formula[] value() { + return value; + } + + @Override + public void value(DialectOverride.Formula[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Formulas.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenGeneratedColumnAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenGeneratedColumnAnnotation.java new file mode 100644 index 0000000000..a4cd945e8e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenGeneratedColumnAnnotation.java @@ -0,0 +1,71 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.GeneratedColumn; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_GENERATED_COLUMN; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenGeneratedColumnAnnotation + extends AbstractOverrider + implements DialectOverride.GeneratedColumn, DialectOverrider { + private GeneratedColumn override; + + public OverriddenGeneratedColumnAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenGeneratedColumnAnnotation( + DialectOverride.GeneratedColumn source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_GENERATED_COLUMN, "override", sourceModelContext ) ); + } + + public OverriddenGeneratedColumnAnnotation( + AnnotationInstance source, + SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_GENERATED_COLUMN, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_GENERATED_COLUMN, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.GENERATED_COLUMN; + } + + @Override + public GeneratedColumn override() { + return override; + } + + public void override(GeneratedColumn value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.GeneratedColumn.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenGeneratedColumnsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenGeneratedColumnsAnnotation.java new file mode 100644 index 0000000000..94ddda5b48 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenGeneratedColumnsAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_GENERATED_COLUMNS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenGeneratedColumnsAnnotation + implements DialectOverride.GeneratedColumns, RepeatableContainer { + private DialectOverride.GeneratedColumn[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenGeneratedColumnsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenGeneratedColumnsAnnotation( + DialectOverride.GeneratedColumns annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_GENERATED_COLUMNS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenGeneratedColumnsAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_GENERATED_COLUMNS, "value", modelContext ); + } + + @Override + public DialectOverride.GeneratedColumn[] value() { + return value; + } + + @Override + public void value(DialectOverride.GeneratedColumn[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.GeneratedColumns.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenJoinFormulaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenJoinFormulaAnnotation.java new file mode 100644 index 0000000000..1a95c33bbd --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenJoinFormulaAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.JoinFormula; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_JOIN_FORMULA; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenJoinFormulaAnnotation + extends AbstractOverrider + implements DialectOverride.JoinFormula, DialectOverrider { + private JoinFormula override; + + public OverriddenJoinFormulaAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenJoinFormulaAnnotation( + DialectOverride.JoinFormula source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_JOIN_FORMULA, "override", sourceModelContext ) ); + } + + public OverriddenJoinFormulaAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_JOIN_FORMULA, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_JOIN_FORMULA, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.JOIN_FORMULA; + } + + @Override + public JoinFormula override() { + return override; + } + + public void override(JoinFormula value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.JoinFormula.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenJoinFormulasAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenJoinFormulasAnnotation.java new file mode 100644 index 0000000000..8599f1926b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenJoinFormulasAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_JOIN_FORMULAS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenJoinFormulasAnnotation + implements DialectOverride.JoinFormulas, RepeatableContainer { + private DialectOverride.JoinFormula[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenJoinFormulasAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenJoinFormulasAnnotation( + DialectOverride.JoinFormulas annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_JOIN_FORMULAS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenJoinFormulasAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_JOIN_FORMULAS, "value", modelContext ); + } + + @Override + public DialectOverride.JoinFormula[] value() { + return value; + } + + @Override + public void value(DialectOverride.JoinFormula[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.JoinFormulas.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenOrderByAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenOrderByAnnotation.java new file mode 100644 index 0000000000..3cf3d172a0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenOrderByAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.OrderBy; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_ORDER_BY; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenOrderByAnnotation + extends AbstractOverrider + implements DialectOverride.OrderBy, DialectOverrider { + private OrderBy override; + + public OverriddenOrderByAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenOrderByAnnotation(DialectOverride.OrderBy source, SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_ORDER_BY, "override", sourceModelContext ) ); + } + + public OverriddenOrderByAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_ORDER_BY, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_ORDER_BY, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.ORDER_BY; + } + + @Override + public OrderBy override() { + return override; + } + + public void override(OrderBy value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.OrderBy.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenOrderBysAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenOrderBysAnnotation.java new file mode 100644 index 0000000000..6dd0a7a2a6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenOrderBysAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_ORDER_BYS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenOrderBysAnnotation + implements DialectOverride.OrderBys, RepeatableContainer { + private DialectOverride.OrderBy[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenOrderBysAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenOrderBysAnnotation(DialectOverride.OrderBys annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_ORDER_BYS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenOrderBysAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_ORDER_BYS, "value", modelContext ); + } + + @Override + public DialectOverride.OrderBy[] value() { + return value; + } + + @Override + public void value(DialectOverride.OrderBy[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.OrderBys.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAllAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAllAnnotation.java new file mode 100644 index 0000000000..385672ad97 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAllAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_DELETE_ALL; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLDeleteAllAnnotation + extends AbstractOverrider + implements DialectOverride.SQLDeleteAll, DialectOverrider { + private SQLDeleteAll override; + + public OverriddenSQLDeleteAllAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenSQLDeleteAllAnnotation( + DialectOverride.SQLDeleteAll source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_SQL_DELETE_ALL, "override", sourceModelContext ) ); + } + + public OverriddenSQLDeleteAllAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_SQL_DELETE_ALL, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_SQL_DELETE_ALL, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.SQL_DELETE_ALL; + } + + @Override + public SQLDeleteAll override() { + return override; + } + + public void override(SQLDeleteAll value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLDeleteAll.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAllsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAllsAnnotation.java new file mode 100644 index 0000000000..11be8f8b80 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAllsAnnotation.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_DELETE_ALLS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLDeleteAllsAnnotation + implements DialectOverride.SQLDeleteAlls, RepeatableContainer { + private DialectOverride.SQLDeleteAll[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenSQLDeleteAllsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenSQLDeleteAllsAnnotation( + DialectOverride.SQLDeleteAlls annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_SQL_DELETE_ALLS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenSQLDeleteAllsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_SQL_DELETE_ALLS, "value", modelContext ); + } + + @Override + public DialectOverride.SQLDeleteAll[] value() { + return value; + } + + @Override + public void value(DialectOverride.SQLDeleteAll[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLDeleteAlls.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAnnotation.java new file mode 100644 index 0000000000..248b9277ff --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeleteAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_DELETE; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLDeleteAnnotation + extends AbstractOverrider + implements DialectOverride.SQLDelete, DialectOverrider { + private SQLDelete override; + + public OverriddenSQLDeleteAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenSQLDeleteAnnotation( + DialectOverride.SQLDelete source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_SQL_DELETE, "override", sourceModelContext ) ); + } + + public OverriddenSQLDeleteAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_SQL_DELETE, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_SQL_DELETE, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.SQL_DELETE; + } + + @Override + public SQLDelete override() { + return override; + } + + public void override(SQLDelete value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLDelete.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeletesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeletesAnnotation.java new file mode 100644 index 0000000000..bbd81a082c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLDeletesAnnotation.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_DELETES; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLDeletesAnnotation + implements DialectOverride.SQLDeletes, RepeatableContainer { + private DialectOverride.SQLDelete[] value; + + public OverriddenSQLDeletesAnnotation(SourceModelBuildingContext modelContext) { + } + + public OverriddenSQLDeletesAnnotation( + DialectOverride.SQLDeletes annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_SQL_DELETES, "value", modelContext ); + } + + public OverriddenSQLDeletesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_SQL_DELETES, "value", modelContext ); + } + + @Override + public DialectOverride.SQLDelete[] value() { + return value; + } + + @Override + public void value(DialectOverride.SQLDelete[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLDeletes.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLInsertAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLInsertAnnotation.java new file mode 100644 index 0000000000..079aa3f3d4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLInsertAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.SQLInsert; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_INSERT; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLInsertAnnotation + extends AbstractOverrider + implements DialectOverride.SQLInsert, DialectOverrider { + private SQLInsert override; + + public OverriddenSQLInsertAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenSQLInsertAnnotation( + DialectOverride.SQLInsert source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_SQL_INSERT, "override", sourceModelContext ) ); + } + + public OverriddenSQLInsertAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_SQL_INSERT, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_SQL_INSERT, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.SQL_INSERT; + } + + @Override + public SQLInsert override() { + return override; + } + + public void override(SQLInsert value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLInsert.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLInsertsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLInsertsAnnotation.java new file mode 100644 index 0000000000..06b223821d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLInsertsAnnotation.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_INSERTS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLInsertsAnnotation + implements DialectOverride.SQLInserts, RepeatableContainer { + private DialectOverride.SQLInsert[] value; + + public OverriddenSQLInsertsAnnotation(SourceModelBuildingContext sourceModelBuildingContext) { + } + + public OverriddenSQLInsertsAnnotation( + DialectOverride.SQLInserts annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_SQL_INSERTS, "value", modelContext ); + } + + public OverriddenSQLInsertsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_SQL_INSERTS, "value", modelContext ); + } + + @Override + public DialectOverride.SQLInsert[] value() { + return value; + } + + @Override + public void value(DialectOverride.SQLInsert[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLInserts.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLOrderAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLOrderAnnotation.java new file mode 100644 index 0000000000..360041cc47 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLOrderAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.SQLOrder; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_ORDER; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLOrderAnnotation + extends AbstractOverrider + implements DialectOverride.SQLOrder, DialectOverrider { + private SQLOrder override; + + public OverriddenSQLOrderAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenSQLOrderAnnotation( + DialectOverride.SQLOrder source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_SQL_ORDER, "override", sourceModelContext ) ); + } + + public OverriddenSQLOrderAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_SQL_ORDER, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_SQL_ORDER, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.SQL_ORDER; + } + + @Override + public SQLOrder override() { + return override; + } + + public void override(SQLOrder value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLOrder.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLOrdersAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLOrdersAnnotation.java new file mode 100644 index 0000000000..44d40bd2c8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLOrdersAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.DialectOverride.SQLOrders; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_ORDERS; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OverriddenSQLOrdersAnnotation + implements DialectOverride.SQLOrders, RepeatableContainer { + private DialectOverride.SQLOrder[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenSQLOrdersAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenSQLOrdersAnnotation(SQLOrders annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_SQL_ORDERS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenSQLOrdersAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_SQL_ORDERS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SQLOrders.class; + } + + @Override + public DialectOverride.SQLOrder[] value() { + return value; + } + + public void value(DialectOverride.SQLOrder[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLRestrictionAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLRestrictionAnnotation.java new file mode 100644 index 0000000000..d233dae607 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLRestrictionAnnotation.java @@ -0,0 +1,72 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.SQLRestriction; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_ORDER; +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_RESTRICTION; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLRestrictionAnnotation + extends AbstractOverrider + implements DialectOverride.SQLRestriction, DialectOverrider { + private SQLRestriction override; + + public OverriddenSQLRestrictionAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenSQLRestrictionAnnotation( + DialectOverride.SQLRestriction source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_SQL_RESTRICTION, "override", sourceModelContext ) ); + } + + public OverriddenSQLRestrictionAnnotation( + AnnotationInstance source, + SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_SQL_ORDER, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_SQL_RESTRICTION, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.SQL_RESTRICTION; + } + + @Override + public SQLRestriction override() { + return override; + } + + public void override(SQLRestriction value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLRestriction.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLRestrictionsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLRestrictionsAnnotation.java new file mode 100644 index 0000000000..ac9b77c9bb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLRestrictionsAnnotation.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.DialectOverride.SQLRestrictions; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OverriddenSQLRestrictionsAnnotation + implements DialectOverride.SQLRestrictions, RepeatableContainer { + private DialectOverride.SQLRestriction[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenSQLRestrictionsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenSQLRestrictionsAnnotation(SQLRestrictions annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_RESTRICTIONS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenSQLRestrictionsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_RESTRICTIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return SQLRestrictions.class; + } + + @Override + public DialectOverride.SQLRestriction[] value() { + return value; + } + + public void value(DialectOverride.SQLRestriction[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLSelectAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLSelectAnnotation.java new file mode 100644 index 0000000000..2864cdd8b1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLSelectAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.SQLSelect; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_SELECT; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLSelectAnnotation + extends AbstractOverrider + implements DialectOverride.SQLSelect, DialectOverrider { + private SQLSelect override; + + public OverriddenSQLSelectAnnotation(SourceModelBuildingContext modelContext) { + } + + public OverriddenSQLSelectAnnotation( + DialectOverride.SQLSelect annotation, + SourceModelBuildingContext modelContext) { + dialect( annotation.dialect() ); + before( annotation.before() ); + sameOrAfter( annotation.sameOrAfter() ); + override( extractJdkValue( annotation, DIALECT_OVERRIDE_SQL_SELECT, "override", modelContext ) ); + } + + public OverriddenSQLSelectAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + super( annotation, DIALECT_OVERRIDE_SQL_SELECT, modelContext ); + override( extractJandexValue( annotation, DIALECT_OVERRIDE_SQL_SELECT, "override", modelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.SQL_SELECT; + } + + @Override + public SQLSelect override() { + return override; + } + + public void override(SQLSelect value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLSelect.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLSelectsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLSelectsAnnotation.java new file mode 100644 index 0000000000..0c4bb96469 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLSelectsAnnotation.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.DialectOverride.SQLRestrictions; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OverriddenSQLSelectsAnnotation + implements DialectOverride.SQLSelects, RepeatableContainer { + private DialectOverride.SQLSelect[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public OverriddenSQLSelectsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public OverriddenSQLSelectsAnnotation(SQLRestrictions annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_RESTRICTIONS, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public OverriddenSQLSelectsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_RESTRICTIONS, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return SQLRestrictions.class; + } + + @Override + public DialectOverride.SQLSelect[] value() { + return value; + } + + public void value(DialectOverride.SQLSelect[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLUpdateAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLUpdateAnnotation.java new file mode 100644 index 0000000000..d23ab1b90a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLUpdateAnnotation.java @@ -0,0 +1,69 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.SQLUpdate; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_UPDATE; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLUpdateAnnotation + extends AbstractOverrider + implements DialectOverride.SQLUpdate, DialectOverrider { + private SQLUpdate override; + + public OverriddenSQLUpdateAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenSQLUpdateAnnotation( + DialectOverride.SQLUpdate source, + SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_SQL_UPDATE, "override", sourceModelContext ) ); + } + + public OverriddenSQLUpdateAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_SQL_UPDATE, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_SQL_UPDATE, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.SQL_UPDATE; + } + + @Override + public SQLUpdate override() { + return override; + } + + public void override(SQLUpdate value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLUpdate.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLUpdatesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLUpdatesAnnotation.java new file mode 100644 index 0000000000..8d3358409e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenSQLUpdatesAnnotation.java @@ -0,0 +1,58 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_SQL_UPDATES; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenSQLUpdatesAnnotation + implements DialectOverride.SQLUpdates, RepeatableContainer { + private DialectOverride.SQLUpdate[] value; + + public OverriddenSQLUpdatesAnnotation(SourceModelBuildingContext sourceModelBuildingContext) { + } + + public OverriddenSQLUpdatesAnnotation( + DialectOverride.SQLUpdates annotation, + SourceModelBuildingContext sourceModelContext) { + this.value = extractJdkValue( annotation, DIALECT_OVERRIDE_SQL_UPDATES, "value", sourceModelContext ); + } + + public OverriddenSQLUpdatesAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext sourceModelContext) { + this.value = extractJandexValue( annotation, DIALECT_OVERRIDE_SQL_UPDATES, "value", sourceModelContext ); + } + + @Override + public DialectOverride.SQLUpdate[] value() { + return value; + } + + @Override + public void value(DialectOverride.SQLUpdate[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.SQLUpdates.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenWhereAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenWhereAnnotation.java new file mode 100644 index 0000000000..7a6187c600 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenWhereAnnotation.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.annotations.Where; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.AbstractOverrider; +import org.hibernate.boot.models.annotations.spi.DialectOverrider; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_WHERE; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenWhereAnnotation + extends AbstractOverrider + implements DialectOverride.Where, DialectOverrider { + private Where override; + + public OverriddenWhereAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenWhereAnnotation(DialectOverride.Where source, SourceModelBuildingContext sourceModelContext) { + dialect( source.dialect() ); + before( source.before() ); + sameOrAfter( source.sameOrAfter() ); + override( extractJdkValue( source, DIALECT_OVERRIDE_WHERE, "override", sourceModelContext ) ); + } + + public OverriddenWhereAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + super( source, DIALECT_OVERRIDE_WHERE, sourceModelContext ); + override( extractJandexValue( source, DIALECT_OVERRIDE_WHERE, "override", sourceModelContext ) ); + } + + @Override + public AnnotationDescriptor getOverriddenDescriptor() { + return HibernateAnnotations.WHERE; + } + + @Override + public Where override() { + return override; + } + + public void override(Where value) { + this.override = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Where.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenWheresAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenWheresAnnotation.java new file mode 100644 index 0000000000..43d5109a39 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverriddenWheresAnnotation.java @@ -0,0 +1,54 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.DialectOverrideAnnotations.DIALECT_OVERRIDE_WHERES; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("ClassExplicitlyAnnotation") +public class OverriddenWheresAnnotation + implements DialectOverride.Wheres, RepeatableContainer { + private DialectOverride.Where[] value; + + public OverriddenWheresAnnotation(SourceModelBuildingContext sourceModelContext) { + } + + public OverriddenWheresAnnotation(DialectOverride.Wheres source, SourceModelBuildingContext sourceModelContext) { + value = extractJdkValue( source, DIALECT_OVERRIDE_WHERES, "override", sourceModelContext ); + } + + public OverriddenWheresAnnotation(AnnotationInstance source, SourceModelBuildingContext sourceModelContext) { + value = extractJandexValue( source, DIALECT_OVERRIDE_WHERES, "override", sourceModelContext ); + } + + @Override + public DialectOverride.Where[] value() { + return value; + } + + @Override + public void value(DialectOverride.Where[] value) { + this.value = value; + } + + @Override + public Class annotationType() { + return DialectOverride.Wheres.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverrideVersionAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverrideVersionAnnotation.java new file mode 100644 index 0000000000..d01e736057 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/OverrideVersionAnnotation.java @@ -0,0 +1,57 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class OverrideVersionAnnotation implements DialectOverride.Version { + private int major; + private int minor; + + public OverrideVersionAnnotation(SourceModelBuildingContext modelContext) { + this.minor = 0; + } + + public OverrideVersionAnnotation(DialectOverride.Version annotation, SourceModelBuildingContext modelContext) { + major( annotation.major() ); + minor( annotation.minor() ); + } + + public OverrideVersionAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + throw new UnsupportedOperationException( "Not implemented yet" ); + } + + @Override + public Class annotationType() { + return DialectOverride.Version.class; + } + + @Override + public int major() { + return major; + } + + public void major(int value) { + this.major = value; + } + + @Override + public int minor() { + return minor; + } + + public void minor(int value) { + this.minor = value; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParamDefAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParamDefAnnotation.java new file mode 100644 index 0000000000..b4014efc8b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParamDefAnnotation.java @@ -0,0 +1,87 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ParamDef; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ParamDefAnnotation implements ParamDef { + private String name; + private java.lang.Class type; + private java.lang.Class resolver; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ParamDefAnnotation(SourceModelBuildingContext modelContext) { + this.resolver = java.util.function.Supplier.class; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ParamDefAnnotation(ParamDef annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.PARAM_DEF, "name", modelContext ); + this.type = extractJdkValue( annotation, HibernateAnnotations.PARAM_DEF, "type", modelContext ); + this.resolver = extractJdkValue( annotation, HibernateAnnotations.PARAM_DEF, "resolver", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ParamDefAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.PARAM_DEF, "name", modelContext ); + this.type = extractJandexValue( annotation, HibernateAnnotations.PARAM_DEF, "type", modelContext ); + this.resolver = extractJandexValue( annotation, HibernateAnnotations.PARAM_DEF, "resolver", modelContext ); + } + + @Override + public Class annotationType() { + return ParamDef.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public java.lang.Class type() { + return type; + } + + public void type(java.lang.Class value) { + this.type = value; + } + + + @Override + public java.lang.Class resolver() { + return resolver; + } + + public void resolver(java.lang.Class value) { + this.resolver = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParameterAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParameterAnnotation.java new file mode 100644 index 0000000000..f245632874 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParameterAnnotation.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Parameter; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ParameterAnnotation implements Parameter { + private String name; + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ParameterAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ParameterAnnotation(Parameter annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.PARAMETER, "name", modelContext ); + this.value = extractJdkValue( annotation, HibernateAnnotations.PARAMETER, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ParameterAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.PARAMETER, "name", modelContext ); + this.value = extractJandexValue( annotation, HibernateAnnotations.PARAMETER, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Parameter.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParentAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParentAnnotation.java new file mode 100644 index 0000000000..427b0b709d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ParentAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Parent; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ParentAnnotation implements Parent { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ParentAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ParentAnnotation(Parent annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ParentAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Parent.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PartitionKeyAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PartitionKeyAnnotation.java new file mode 100644 index 0000000000..b2d91e621b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PartitionKeyAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.PartitionKey; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PartitionKeyAnnotation implements PartitionKey { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PartitionKeyAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PartitionKeyAnnotation(PartitionKey annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PartitionKeyAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PartitionKey.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceContextJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceContextJpaAnnotation.java new file mode 100644 index 0000000000..40ef366983 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceContextJpaAnnotation.java @@ -0,0 +1,100 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.PersistenceContext; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PersistenceContextJpaAnnotation implements PersistenceContext { + public static final AnnotationDescriptor PERSISTENCE_CONTEXT = null; + + private String name; + private String unitName; + private jakarta.persistence.PersistenceContextType type; + private jakarta.persistence.SynchronizationType synchronization; + private jakarta.persistence.PersistenceProperty[] properties; + + public PersistenceContextJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.unitName = ""; + this.type = jakarta.persistence.PersistenceContextType.TRANSACTION; + this.synchronization = jakarta.persistence.SynchronizationType.SYNCHRONIZED; + this.properties = new jakarta.persistence.PersistenceProperty[0]; + } + + public PersistenceContextJpaAnnotation(PersistenceContext annotation, SourceModelBuildingContext modelContext) { + } + + public PersistenceContextJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PersistenceContext.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String unitName() { + return unitName; + } + + public void unitName(String value) { + this.unitName = value; + } + + + @Override + public jakarta.persistence.PersistenceContextType type() { + return type; + } + + public void type(jakarta.persistence.PersistenceContextType value) { + this.type = value; + } + + + @Override + public jakarta.persistence.SynchronizationType synchronization() { + return synchronization; + } + + public void synchronization(jakarta.persistence.SynchronizationType value) { + this.synchronization = value; + } + + + @Override + public jakarta.persistence.PersistenceProperty[] properties() { + return properties; + } + + public void properties(jakarta.persistence.PersistenceProperty[] value) { + this.properties = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceContextsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceContextsJpaAnnotation.java new file mode 100644 index 0000000000..f95948f48c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceContextsJpaAnnotation.java @@ -0,0 +1,51 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.PersistenceContexts; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PersistenceContextsJpaAnnotation implements PersistenceContexts { + public static final AnnotationDescriptor PERSISTENCE_CONTEXTS = null; + + private jakarta.persistence.PersistenceContext[] value; + + public PersistenceContextsJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + public PersistenceContextsJpaAnnotation(PersistenceContexts annotation, SourceModelBuildingContext modelContext) { + } + + public PersistenceContextsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PersistenceContexts.class; + } + + @Override + public jakarta.persistence.PersistenceContext[] value() { + return value; + } + + public void value(jakarta.persistence.PersistenceContext[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistencePropertyJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistencePropertyJpaAnnotation.java new file mode 100644 index 0000000000..9f2b6b9a5b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistencePropertyJpaAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.PersistenceProperty; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PersistencePropertyJpaAnnotation implements PersistenceProperty { + public static final AnnotationDescriptor PERSISTENCE_PROPERTY = null; + + private String name; + private String value; + + public PersistencePropertyJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + public PersistencePropertyJpaAnnotation(PersistenceProperty annotation, SourceModelBuildingContext modelContext) { + } + + public PersistencePropertyJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PersistenceProperty.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceUnitJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceUnitJpaAnnotation.java new file mode 100644 index 0000000000..15d4912c17 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceUnitJpaAnnotation.java @@ -0,0 +1,64 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.PersistenceUnit; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PersistenceUnitJpaAnnotation implements PersistenceUnit { + public static final AnnotationDescriptor PERSISTENCE_UNIT = null; + + private String name; + private String unitName; + + public PersistenceUnitJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.unitName = ""; + } + + public PersistenceUnitJpaAnnotation(PersistenceUnit annotation, SourceModelBuildingContext modelContext) { + } + + public PersistenceUnitJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PersistenceUnit.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String unitName() { + return unitName; + } + + public void unitName(String value) { + this.unitName = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceUnitsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceUnitsJpaAnnotation.java new file mode 100644 index 0000000000..d9b38c37df --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PersistenceUnitsJpaAnnotation.java @@ -0,0 +1,51 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.PersistenceUnits; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PersistenceUnitsJpaAnnotation implements PersistenceUnits { + public static final AnnotationDescriptor PERSISTENCE_UNITS = null; + + private jakarta.persistence.PersistenceUnit[] value; + + public PersistenceUnitsJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + public PersistenceUnitsJpaAnnotation(PersistenceUnits annotation, SourceModelBuildingContext modelContext) { + } + + public PersistenceUnitsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PersistenceUnits.class; + } + + @Override + public jakarta.persistence.PersistenceUnit[] value() { + return value; + } + + public void value(jakarta.persistence.PersistenceUnit[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PolymorphismAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PolymorphismAnnotation.java new file mode 100644 index 0000000000..6fbc7da4c2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PolymorphismAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Polymorphism; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PolymorphismAnnotation implements Polymorphism { + private org.hibernate.annotations.PolymorphismType type; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PolymorphismAnnotation(SourceModelBuildingContext modelContext) { + this.type = org.hibernate.annotations.PolymorphismType.IMPLICIT; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PolymorphismAnnotation(Polymorphism annotation, SourceModelBuildingContext modelContext) { + this.type = extractJdkValue( annotation, HibernateAnnotations.POLYMORPHISM, "type", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PolymorphismAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.type = extractJandexValue( annotation, HibernateAnnotations.POLYMORPHISM, "type", modelContext ); + } + + @Override + public Class annotationType() { + return Polymorphism.class; + } + + @Override + public org.hibernate.annotations.PolymorphismType type() { + return type; + } + + public void type(org.hibernate.annotations.PolymorphismType value) { + this.type = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostLoadJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostLoadJpaAnnotation.java new file mode 100644 index 0000000000..7c294f663c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostLoadJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PostLoad; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PostLoadJpaAnnotation implements PostLoad { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PostLoadJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PostLoadJpaAnnotation(PostLoad annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PostLoadJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PostLoad.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostPersistJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostPersistJpaAnnotation.java new file mode 100644 index 0000000000..70b386c5e7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostPersistJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PostPersist; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PostPersistJpaAnnotation implements PostPersist { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PostPersistJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PostPersistJpaAnnotation(PostPersist annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PostPersistJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PostPersist.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostRemoveJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostRemoveJpaAnnotation.java new file mode 100644 index 0000000000..c39269f5bf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostRemoveJpaAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PostRemove; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PostRemoveJpaAnnotation implements PostRemove { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PostRemoveJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PostRemoveJpaAnnotation(PostRemove annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PostRemoveJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PostRemove.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostUpdateJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostUpdateJpaAnnotation.java new file mode 100644 index 0000000000..df3bf473fb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PostUpdateJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PostUpdate; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PostUpdateJpaAnnotation implements PostUpdate { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PostUpdateJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PostUpdateJpaAnnotation(PostUpdate annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PostUpdateJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PostUpdate.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrePersistJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrePersistJpaAnnotation.java new file mode 100644 index 0000000000..4de639df47 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrePersistJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PrePersist; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PrePersistJpaAnnotation implements PrePersist { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PrePersistJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PrePersistJpaAnnotation(PrePersist annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PrePersistJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PrePersist.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PreRemoveJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PreRemoveJpaAnnotation.java new file mode 100644 index 0000000000..c7b41f19fb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PreRemoveJpaAnnotation.java @@ -0,0 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PreRemove; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PreRemoveJpaAnnotation implements PreRemove { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PreRemoveJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PreRemoveJpaAnnotation(PreRemove annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PreRemoveJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PreRemove.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PreUpdateJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PreUpdateJpaAnnotation.java new file mode 100644 index 0000000000..8f1019b517 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PreUpdateJpaAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PreUpdate; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PreUpdateJpaAnnotation implements PreUpdate { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PreUpdateJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PreUpdateJpaAnnotation(PreUpdate annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PreUpdateJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return PreUpdate.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrimaryKeyJoinColumnJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrimaryKeyJoinColumnJpaAnnotation.java new file mode 100644 index 0000000000..52976ef5bb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrimaryKeyJoinColumnJpaAnnotation.java @@ -0,0 +1,184 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumnImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.ColumnDetails; +import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PrimaryKeyJoinColumn; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PrimaryKeyJoinColumnJpaAnnotation implements PrimaryKeyJoinColumn, ColumnDetails, ColumnDetails.Definable { + private String name; + private String referencedColumnName; + private String columnDefinition; + private String options; + private jakarta.persistence.ForeignKey foreignKey; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PrimaryKeyJoinColumnJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.referencedColumnName = ""; + this.columnDefinition = ""; + this.options = ""; + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PrimaryKeyJoinColumnJpaAnnotation(PrimaryKeyJoinColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, "name", modelContext ); + this.referencedColumnName = extractJdkValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + "referencedColumnName", + modelContext + ); + this.columnDefinition = extractJdkValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJdkValue( annotation, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, "options", modelContext ); + this.foreignKey = extractJdkValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + "foreignKey", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PrimaryKeyJoinColumnJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, "name", modelContext ); + this.referencedColumnName = extractJandexValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + "referencedColumnName", + modelContext + ); + this.columnDefinition = extractJandexValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + "columnDefinition", + modelContext + ); + this.options = extractJandexValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + "options", + modelContext + ); + this.foreignKey = extractJandexValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, + "foreignKey", + modelContext + ); + } + + @Override + public Class annotationType() { + return PrimaryKeyJoinColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String referencedColumnName() { + return referencedColumnName; + } + + public void referencedColumnName(String value) { + this.referencedColumnName = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + + public void apply(JaxbPrimaryKeyJoinColumnImpl jaxbColumn, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + name( jaxbColumn.getName() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnDefinition( jaxbColumn.getColumnDefinition() ); + } + if ( StringHelper.isNotEmpty( jaxbColumn.getOptions() ) ) { + options( jaxbColumn.getOptions() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getReferencedColumnName() ) ) { + referencedColumnName( jaxbColumn.getReferencedColumnName() ); + } + + if ( jaxbColumn.getForeignKey() != null ) { + foreignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbColumn.getForeignKey(), + xmlDocumentContext + ) ); + } + + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrimaryKeyJoinColumnsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrimaryKeyJoinColumnsJpaAnnotation.java new file mode 100644 index 0000000000..d249d21469 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/PrimaryKeyJoinColumnsJpaAnnotation.java @@ -0,0 +1,92 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.PrimaryKeyJoinColumn; +import jakarta.persistence.PrimaryKeyJoinColumns; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class PrimaryKeyJoinColumnsJpaAnnotation + implements PrimaryKeyJoinColumns, RepeatableContainer { + private jakarta.persistence.PrimaryKeyJoinColumn[] value; + private jakarta.persistence.ForeignKey foreignKey; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public PrimaryKeyJoinColumnsJpaAnnotation(SourceModelBuildingContext modelContext) { + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + } + + /** + * Used in creating annotation instances from JDK variant + */ + public PrimaryKeyJoinColumnsJpaAnnotation( + PrimaryKeyJoinColumns annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS, "value", modelContext ); + this.foreignKey = extractJdkValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS, + "foreignKey", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public PrimaryKeyJoinColumnsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS, "value", modelContext ); + this.foreignKey = extractJandexValue( + annotation, + JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS, + "foreignKey", + modelContext + ); + } + + @Override + public Class annotationType() { + return PrimaryKeyJoinColumns.class; + } + + @Override + public jakarta.persistence.PrimaryKeyJoinColumn[] value() { + return value; + } + + public void value(jakarta.persistence.PrimaryKeyJoinColumn[] value) { + this.value = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ProxyAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ProxyAnnotation.java new file mode 100644 index 0000000000..811c4301b9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ProxyAnnotation.java @@ -0,0 +1,75 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Proxy; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ProxyAnnotation implements Proxy { + private boolean lazy; + private java.lang.Class proxyClass; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ProxyAnnotation(SourceModelBuildingContext modelContext) { + this.lazy = true; + this.proxyClass = void.class; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ProxyAnnotation(Proxy annotation, SourceModelBuildingContext modelContext) { + this.lazy = extractJdkValue( annotation, HibernateAnnotations.PROXY, "lazy", modelContext ); + this.proxyClass = extractJdkValue( annotation, HibernateAnnotations.PROXY, "proxyClass", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ProxyAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.lazy = extractJandexValue( annotation, HibernateAnnotations.PROXY, "lazy", modelContext ); + this.proxyClass = extractJandexValue( annotation, HibernateAnnotations.PROXY, "proxyClass", modelContext ); + } + + @Override + public Class annotationType() { + return Proxy.class; + } + + @Override + public boolean lazy() { + return lazy; + } + + public void lazy(boolean value) { + this.lazy = value; + } + + + @Override + public java.lang.Class proxyClass() { + return proxyClass; + } + + public void proxyClass(java.lang.Class value) { + this.proxyClass = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/QueryCacheLayoutAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/QueryCacheLayoutAnnotation.java new file mode 100644 index 0000000000..be61dad1a4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/QueryCacheLayoutAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.QueryCacheLayout; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class QueryCacheLayoutAnnotation implements QueryCacheLayout { + private org.hibernate.annotations.CacheLayout layout; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public QueryCacheLayoutAnnotation(SourceModelBuildingContext modelContext) { + this.layout = org.hibernate.annotations.CacheLayout.AUTO; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public QueryCacheLayoutAnnotation(QueryCacheLayout annotation, SourceModelBuildingContext modelContext) { + this.layout = extractJdkValue( annotation, HibernateAnnotations.QUERY_CACHE_LAYOUT, "layout", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public QueryCacheLayoutAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.layout = extractJandexValue( annotation, HibernateAnnotations.QUERY_CACHE_LAYOUT, "layout", modelContext ); + } + + @Override + public Class annotationType() { + return QueryCacheLayout.class; + } + + @Override + public org.hibernate.annotations.CacheLayout layout() { + return layout; + } + + public void layout(org.hibernate.annotations.CacheLayout value) { + this.layout = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/QueryHintJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/QueryHintJpaAnnotation.java new file mode 100644 index 0000000000..37886eea96 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/QueryHintJpaAnnotation.java @@ -0,0 +1,74 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.QueryHint; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class QueryHintJpaAnnotation implements QueryHint { + private String name; + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public QueryHintJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public QueryHintJpaAnnotation(QueryHint annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.QUERY_HINT, "name", modelContext ); + this.value = extractJdkValue( annotation, JpaAnnotations.QUERY_HINT, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public QueryHintJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.QUERY_HINT, "name", modelContext ); + this.value = extractJandexValue( annotation, JpaAnnotations.QUERY_HINT, "value", modelContext ); + } + + @Override + public Class annotationType() { + return QueryHint.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/RowIdAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/RowIdAnnotation.java new file mode 100644 index 0000000000..bb64721938 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/RowIdAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.RowId; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class RowIdAnnotation implements RowId { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public RowIdAnnotation(SourceModelBuildingContext modelContext) { + this.value = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public RowIdAnnotation(RowId annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.ROW_ID, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public RowIdAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.ROW_ID, "value", modelContext ); + } + + @Override + public Class annotationType() { + return RowId.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeleteAllAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeleteAllAnnotation.java new file mode 100644 index 0000000000..67ad1d657d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeleteAllAnnotation.java @@ -0,0 +1,117 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLDeleteAllAnnotation implements SQLDeleteAll, CustomSqlDetails { + private String sql; + private boolean callable; + private java.lang.Class verify; + private org.hibernate.annotations.ResultCheckStyle check; + private String table; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLDeleteAllAnnotation(SourceModelBuildingContext modelContext) { + this.callable = false; + this.verify = org.hibernate.jdbc.Expectation.class; + this.check = org.hibernate.annotations.ResultCheckStyle.NONE; + this.table = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLDeleteAllAnnotation(SQLDeleteAll annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "sql", modelContext ); + this.callable = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "callable", modelContext ); + this.verify = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "verify", modelContext ); + this.check = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "check", modelContext ); + this.table = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "table", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLDeleteAllAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "sql", modelContext ); + this.callable = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "callable", modelContext ); + this.verify = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "verify", modelContext ); + this.check = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "check", modelContext ); + this.table = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE_ALL, "table", modelContext ); + } + + @Override + public Class annotationType() { + return SQLDeleteAll.class; + } + + @Override + public String sql() { + return sql; + } + + public void sql(String value) { + this.sql = value; + } + + + @Override + public boolean callable() { + return callable; + } + + public void callable(boolean value) { + this.callable = value; + } + + + @Override + public java.lang.Class verify() { + return verify; + } + + public void verify(java.lang.Class value) { + this.verify = value; + } + + + @Override + public org.hibernate.annotations.ResultCheckStyle check() { + return check; + } + + public void check(org.hibernate.annotations.ResultCheckStyle value) { + this.check = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeleteAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeleteAnnotation.java new file mode 100644 index 0000000000..8986f7cb84 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeleteAnnotation.java @@ -0,0 +1,117 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLDeleteAnnotation implements SQLDelete, CustomSqlDetails { + private String sql; + private boolean callable; + private java.lang.Class verify; + private org.hibernate.annotations.ResultCheckStyle check; + private String table; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLDeleteAnnotation(SourceModelBuildingContext modelContext) { + this.callable = false; + this.verify = org.hibernate.jdbc.Expectation.class; + this.check = org.hibernate.annotations.ResultCheckStyle.NONE; + this.table = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLDeleteAnnotation(SQLDelete annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE, "sql", modelContext ); + this.callable = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE, "callable", modelContext ); + this.verify = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE, "verify", modelContext ); + this.check = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE, "check", modelContext ); + this.table = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETE, "table", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLDeleteAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE, "sql", modelContext ); + this.callable = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE, "callable", modelContext ); + this.verify = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE, "verify", modelContext ); + this.check = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE, "check", modelContext ); + this.table = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETE, "table", modelContext ); + } + + @Override + public Class annotationType() { + return SQLDelete.class; + } + + @Override + public String sql() { + return sql; + } + + public void sql(String value) { + this.sql = value; + } + + + @Override + public boolean callable() { + return callable; + } + + public void callable(boolean value) { + this.callable = value; + } + + + @Override + public java.lang.Class verify() { + return verify; + } + + public void verify(java.lang.Class value) { + this.verify = value; + } + + + @Override + public org.hibernate.annotations.ResultCheckStyle check() { + return check; + } + + public void check(org.hibernate.annotations.ResultCheckStyle value) { + this.check = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeletesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeletesAnnotation.java new file mode 100644 index 0000000000..7f781059e7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLDeletesAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLDeletes; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLDeletesAnnotation implements SQLDeletes, RepeatableContainer { + private org.hibernate.annotations.SQLDelete[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLDeletesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLDeletesAnnotation(SQLDeletes annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SQL_DELETES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLDeletesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SQL_DELETES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SQLDeletes.class; + } + + @Override + public org.hibernate.annotations.SQLDelete[] value() { + return value; + } + + public void value(org.hibernate.annotations.SQLDelete[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLInsertAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLInsertAnnotation.java new file mode 100644 index 0000000000..3bd37e97d1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLInsertAnnotation.java @@ -0,0 +1,117 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLInsert; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLInsertAnnotation implements SQLInsert, CustomSqlDetails { + private String sql; + private boolean callable; + private java.lang.Class verify; + private org.hibernate.annotations.ResultCheckStyle check; + private String table; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLInsertAnnotation(SourceModelBuildingContext modelContext) { + this.callable = false; + this.verify = org.hibernate.jdbc.Expectation.class; + this.check = org.hibernate.annotations.ResultCheckStyle.NONE; + this.table = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLInsertAnnotation(SQLInsert annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJdkValue( annotation, HibernateAnnotations.SQL_INSERT, "sql", modelContext ); + this.callable = extractJdkValue( annotation, HibernateAnnotations.SQL_INSERT, "callable", modelContext ); + this.verify = extractJdkValue( annotation, HibernateAnnotations.SQL_INSERT, "verify", modelContext ); + this.check = extractJdkValue( annotation, HibernateAnnotations.SQL_INSERT, "check", modelContext ); + this.table = extractJdkValue( annotation, HibernateAnnotations.SQL_INSERT, "table", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLInsertAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJandexValue( annotation, HibernateAnnotations.SQL_INSERT, "sql", modelContext ); + this.callable = extractJandexValue( annotation, HibernateAnnotations.SQL_INSERT, "callable", modelContext ); + this.verify = extractJandexValue( annotation, HibernateAnnotations.SQL_INSERT, "verify", modelContext ); + this.check = extractJandexValue( annotation, HibernateAnnotations.SQL_INSERT, "check", modelContext ); + this.table = extractJandexValue( annotation, HibernateAnnotations.SQL_INSERT, "table", modelContext ); + } + + @Override + public Class annotationType() { + return SQLInsert.class; + } + + @Override + public String sql() { + return sql; + } + + public void sql(String value) { + this.sql = value; + } + + + @Override + public boolean callable() { + return callable; + } + + public void callable(boolean value) { + this.callable = value; + } + + + @Override + public java.lang.Class verify() { + return verify; + } + + public void verify(java.lang.Class value) { + this.verify = value; + } + + + @Override + public org.hibernate.annotations.ResultCheckStyle check() { + return check; + } + + public void check(org.hibernate.annotations.ResultCheckStyle value) { + this.check = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLInsertsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLInsertsAnnotation.java new file mode 100644 index 0000000000..05e0dfe155 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLInsertsAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLInsert; +import org.hibernate.annotations.SQLInserts; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLInsertsAnnotation implements SQLInserts, RepeatableContainer { + private org.hibernate.annotations.SQLInsert[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLInsertsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLInsertsAnnotation(SQLInserts annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SQL_INSERTS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLInsertsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SQL_INSERTS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SQLInserts.class; + } + + @Override + public org.hibernate.annotations.SQLInsert[] value() { + return value; + } + + public void value(org.hibernate.annotations.SQLInsert[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLJoinTableRestrictionAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLJoinTableRestrictionAnnotation.java new file mode 100644 index 0000000000..b19c968650 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLJoinTableRestrictionAnnotation.java @@ -0,0 +1,73 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLJoinTableRestriction; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLJoinTableRestrictionAnnotation implements SQLJoinTableRestriction { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLJoinTableRestrictionAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLJoinTableRestrictionAnnotation( + SQLJoinTableRestriction annotation, + SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( + annotation, + HibernateAnnotations.SQL_JOIN_TABLE_RESTRICTION, + "value", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLJoinTableRestrictionAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( + annotation, + HibernateAnnotations.SQL_JOIN_TABLE_RESTRICTION, + "value", + modelContext + ); + } + + @Override + public Class annotationType() { + return SQLJoinTableRestriction.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLOrderAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLOrderAnnotation.java new file mode 100644 index 0000000000..c87441dea0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLOrderAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLOrder; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLOrderAnnotation implements SQLOrder { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLOrderAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLOrderAnnotation(SQLOrder annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SQL_ORDER, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLOrderAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SQL_ORDER, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SQLOrder.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLRestrictionAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLRestrictionAnnotation.java new file mode 100644 index 0000000000..03ad63cb1e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLRestrictionAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLRestriction; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLRestrictionAnnotation implements SQLRestriction { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLRestrictionAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLRestrictionAnnotation(SQLRestriction annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SQL_RESTRICTION, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLRestrictionAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SQL_RESTRICTION, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SQLRestriction.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLSelectAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLSelectAnnotation.java new file mode 100644 index 0000000000..08cfe652fc --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLSelectAnnotation.java @@ -0,0 +1,106 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLSelect; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLSelectAnnotation implements SQLSelect { + + private String sql; + private jakarta.persistence.SqlResultSetMapping resultSetMapping; + private String[] querySpaces; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLSelectAnnotation(SourceModelBuildingContext modelContext) { + this.resultSetMapping = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.SqlResultSetMapping.class ) + .createUsage( modelContext ); + this.querySpaces = new String[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLSelectAnnotation(SQLSelect annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJdkValue( annotation, HibernateAnnotations.SQL_SELECT, "sql", modelContext ); + this.resultSetMapping = extractJdkValue( + annotation, + HibernateAnnotations.SQL_SELECT, + "resultSetMapping", + modelContext + ); + this.querySpaces = extractJdkValue( annotation, HibernateAnnotations.SQL_SELECT, "querySpaces", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLSelectAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJandexValue( annotation, HibernateAnnotations.SQL_SELECT, "sql", modelContext ); + this.resultSetMapping = extractJandexValue( + annotation, + HibernateAnnotations.SQL_SELECT, + "resultSetMapping", + modelContext + ); + this.querySpaces = extractJandexValue( + annotation, + HibernateAnnotations.SQL_SELECT, + "querySpaces", + modelContext + ); + } + + @Override + public Class annotationType() { + return SQLSelect.class; + } + + @Override + public String sql() { + return sql; + } + + public void sql(String value) { + this.sql = value; + } + + + @Override + public jakarta.persistence.SqlResultSetMapping resultSetMapping() { + return resultSetMapping; + } + + public void resultSetMapping(jakarta.persistence.SqlResultSetMapping value) { + this.resultSetMapping = value; + } + + + @Override + public String[] querySpaces() { + return querySpaces; + } + + public void querySpaces(String[] value) { + this.querySpaces = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLUpdateAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLUpdateAnnotation.java new file mode 100644 index 0000000000..8407439226 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLUpdateAnnotation.java @@ -0,0 +1,117 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLUpdate; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLUpdateAnnotation implements SQLUpdate, CustomSqlDetails { + private String sql; + private boolean callable; + private java.lang.Class verify; + private org.hibernate.annotations.ResultCheckStyle check; + private String table; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLUpdateAnnotation(SourceModelBuildingContext modelContext) { + this.callable = false; + this.verify = org.hibernate.jdbc.Expectation.class; + this.check = org.hibernate.annotations.ResultCheckStyle.NONE; + this.table = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLUpdateAnnotation(SQLUpdate annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJdkValue( annotation, HibernateAnnotations.SQL_UPDATE, "sql", modelContext ); + this.callable = extractJdkValue( annotation, HibernateAnnotations.SQL_UPDATE, "callable", modelContext ); + this.verify = extractJdkValue( annotation, HibernateAnnotations.SQL_UPDATE, "verify", modelContext ); + this.check = extractJdkValue( annotation, HibernateAnnotations.SQL_UPDATE, "check", modelContext ); + this.table = extractJdkValue( annotation, HibernateAnnotations.SQL_UPDATE, "table", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLUpdateAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.sql = extractJandexValue( annotation, HibernateAnnotations.SQL_UPDATE, "sql", modelContext ); + this.callable = extractJandexValue( annotation, HibernateAnnotations.SQL_UPDATE, "callable", modelContext ); + this.verify = extractJandexValue( annotation, HibernateAnnotations.SQL_UPDATE, "verify", modelContext ); + this.check = extractJandexValue( annotation, HibernateAnnotations.SQL_UPDATE, "check", modelContext ); + this.table = extractJandexValue( annotation, HibernateAnnotations.SQL_UPDATE, "table", modelContext ); + } + + @Override + public Class annotationType() { + return SQLUpdate.class; + } + + @Override + public String sql() { + return sql; + } + + public void sql(String value) { + this.sql = value; + } + + + @Override + public boolean callable() { + return callable; + } + + public void callable(boolean value) { + this.callable = value; + } + + + @Override + public java.lang.Class verify() { + return verify; + } + + public void verify(java.lang.Class value) { + this.verify = value; + } + + + @Override + public org.hibernate.annotations.ResultCheckStyle check() { + return check; + } + + public void check(org.hibernate.annotations.ResultCheckStyle value) { + this.check = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLUpdatesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLUpdatesAnnotation.java new file mode 100644 index 0000000000..e8684e84cb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SQLUpdatesAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SQLUpdate; +import org.hibernate.annotations.SQLUpdates; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SQLUpdatesAnnotation implements SQLUpdates, RepeatableContainer { + private org.hibernate.annotations.SQLUpdate[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SQLUpdatesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SQLUpdatesAnnotation(SQLUpdates annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SQL_UPDATES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SQLUpdatesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SQL_UPDATES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SQLUpdates.class; + } + + @Override + public org.hibernate.annotations.SQLUpdate[] value() { + return value; + } + + public void value(org.hibernate.annotations.SQLUpdate[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryRowAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryRowAnnotation.java new file mode 100644 index 0000000000..5db10ec717 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryRowAnnotation.java @@ -0,0 +1,89 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SecondaryRow; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SecondaryRowAnnotation implements SecondaryRow { + private String table; + private boolean owned; + private boolean optional; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SecondaryRowAnnotation(SourceModelBuildingContext modelContext) { + this.table = ""; + this.owned = true; + this.optional = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SecondaryRowAnnotation(SecondaryRow annotation, SourceModelBuildingContext modelContext) { + this.table = extractJdkValue( annotation, HibernateAnnotations.SECONDARY_ROW, "table", modelContext ); + this.owned = extractJdkValue( annotation, HibernateAnnotations.SECONDARY_ROW, "owned", modelContext ); + this.optional = extractJdkValue( annotation, HibernateAnnotations.SECONDARY_ROW, "optional", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SecondaryRowAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.table = extractJandexValue( annotation, HibernateAnnotations.SECONDARY_ROW, "table", modelContext ); + this.owned = extractJandexValue( annotation, HibernateAnnotations.SECONDARY_ROW, "owned", modelContext ); + this.optional = extractJandexValue( annotation, HibernateAnnotations.SECONDARY_ROW, "optional", modelContext ); + } + + @Override + public Class annotationType() { + return SecondaryRow.class; + } + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + + @Override + public boolean owned() { + return owned; + } + + public void owned(boolean value) { + this.owned = value; + } + + + @Override + public boolean optional() { + return optional; + } + + public void optional(boolean value) { + this.optional = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryRowsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryRowsAnnotation.java new file mode 100644 index 0000000000..7c0a34fedb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryRowsAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SecondaryRow; +import org.hibernate.annotations.SecondaryRows; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SecondaryRowsAnnotation implements SecondaryRows, RepeatableContainer { + private org.hibernate.annotations.SecondaryRow[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SecondaryRowsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SecondaryRowsAnnotation(SecondaryRows annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SECONDARY_ROWS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SecondaryRowsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SECONDARY_ROWS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SecondaryRows.class; + } + + @Override + public org.hibernate.annotations.SecondaryRow[] value() { + return value; + } + + public void value(org.hibernate.annotations.SecondaryRow[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryTableJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryTableJpaAnnotation.java new file mode 100644 index 0000000000..cccd9185da --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryTableJpaAnnotation.java @@ -0,0 +1,241 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbSecondaryTableImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.CommonTableDetails; +import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; +import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.SecondaryTable; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyOptionalString; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectCheckConstraints; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectIndexes; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectUniqueConstraints; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SecondaryTableJpaAnnotation implements SecondaryTable, CommonTableDetails { + private String name; + private String catalog; + private String schema; + private jakarta.persistence.PrimaryKeyJoinColumn[] pkJoinColumns; + private jakarta.persistence.ForeignKey foreignKey; + private jakarta.persistence.UniqueConstraint[] uniqueConstraints; + private jakarta.persistence.Index[] indexes; + private jakarta.persistence.CheckConstraint[] check; + private String comment; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SecondaryTableJpaAnnotation(SourceModelBuildingContext modelContext) { + this.catalog = ""; + this.schema = ""; + this.pkJoinColumns = new jakarta.persistence.PrimaryKeyJoinColumn[0]; + this.foreignKey = modelContext.getAnnotationDescriptorRegistry() + .getDescriptor( jakarta.persistence.ForeignKey.class ) + .createUsage( modelContext ); + this.uniqueConstraints = new jakarta.persistence.UniqueConstraint[0]; + this.indexes = new jakarta.persistence.Index[0]; + this.check = new jakarta.persistence.CheckConstraint[0]; + this.comment = ""; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SecondaryTableJpaAnnotation(SecondaryTable annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "name", modelContext ); + this.catalog = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "catalog", modelContext ); + this.schema = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "schema", modelContext ); + this.pkJoinColumns = extractJdkValue( + annotation, + JpaAnnotations.SECONDARY_TABLE, + "pkJoinColumns", + modelContext + ); + this.foreignKey = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "foreignKey", modelContext ); + this.uniqueConstraints = extractJdkValue( + annotation, + JpaAnnotations.SECONDARY_TABLE, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "indexes", modelContext ); + this.check = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "check", modelContext ); + this.comment = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "comment", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLE, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SecondaryTableJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "name", modelContext ); + this.catalog = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "catalog", modelContext ); + this.schema = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "schema", modelContext ); + this.pkJoinColumns = extractJandexValue( + annotation, + JpaAnnotations.SECONDARY_TABLE, + "pkJoinColumns", + modelContext + ); + this.foreignKey = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "foreignKey", modelContext ); + this.uniqueConstraints = extractJandexValue( + annotation, + JpaAnnotations.SECONDARY_TABLE, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "indexes", modelContext ); + this.check = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "check", modelContext ); + this.comment = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "comment", modelContext ); + this.options = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLE, "options", modelContext ); + } + + @Override + public Class annotationType() { + return SecondaryTable.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String catalog() { + return catalog; + } + + public void catalog(String value) { + this.catalog = value; + } + + + @Override + public String schema() { + return schema; + } + + public void schema(String value) { + this.schema = value; + } + + + @Override + public jakarta.persistence.PrimaryKeyJoinColumn[] pkJoinColumns() { + return pkJoinColumns; + } + + public void pkJoinColumns(jakarta.persistence.PrimaryKeyJoinColumn[] value) { + this.pkJoinColumns = value; + } + + + @Override + public jakarta.persistence.ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(jakarta.persistence.ForeignKey value) { + this.foreignKey = value; + } + + + @Override + public jakarta.persistence.UniqueConstraint[] uniqueConstraints() { + return uniqueConstraints; + } + + public void uniqueConstraints(jakarta.persistence.UniqueConstraint[] value) { + this.uniqueConstraints = value; + } + + + @Override + public jakarta.persistence.Index[] indexes() { + return indexes; + } + + public void indexes(jakarta.persistence.Index[] value) { + this.indexes = value; + } + + + @Override + public jakarta.persistence.CheckConstraint[] check() { + return check; + } + + public void check(jakarta.persistence.CheckConstraint[] value) { + this.check = value; + } + + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + public void apply(JaxbSecondaryTableImpl jaxbTable, XmlDocumentContext xmlDocumentContext) { + name( jaxbTable.getName() ); + applyOptionalString( jaxbTable.getCatalog(), this::catalog ); + applyOptionalString( jaxbTable.getSchema(), this::schema ); + applyOptionalString( jaxbTable.getComment(), this::comment ); + applyOptionalString( jaxbTable.getOptions(), this::options ); + + check( collectCheckConstraints( jaxbTable.getCheckConstraints(), xmlDocumentContext ) ); + indexes( collectIndexes( jaxbTable.getIndexes(), xmlDocumentContext ) ); + uniqueConstraints( collectUniqueConstraints( jaxbTable.getUniqueConstraints(), xmlDocumentContext ) ); + + pkJoinColumns( JoinColumnProcessing.transformPrimaryKeyJoinColumns( + jaxbTable.getPrimaryKeyJoinColumn(), + xmlDocumentContext + ) ); + + if ( jaxbTable.getForeignKey() != null ) { + foreignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbTable.getForeignKey(), + xmlDocumentContext + ) ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryTablesJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryTablesJpaAnnotation.java new file mode 100644 index 0000000000..a7dab44eae --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SecondaryTablesJpaAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.SecondaryTable; +import jakarta.persistence.SecondaryTables; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SecondaryTablesJpaAnnotation implements SecondaryTables, RepeatableContainer { + private jakarta.persistence.SecondaryTable[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SecondaryTablesJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SecondaryTablesJpaAnnotation(SecondaryTables annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.SECONDARY_TABLES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SecondaryTablesJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.SECONDARY_TABLES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SecondaryTables.class; + } + + @Override + public jakarta.persistence.SecondaryTable[] value() { + return value; + } + + public void value(jakarta.persistence.SecondaryTable[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SelectBeforeUpdateAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SelectBeforeUpdateAnnotation.java new file mode 100644 index 0000000000..44f73c1381 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SelectBeforeUpdateAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SelectBeforeUpdate; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SelectBeforeUpdateAnnotation implements SelectBeforeUpdate { + private boolean value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SelectBeforeUpdateAnnotation(SourceModelBuildingContext modelContext) { + this.value = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SelectBeforeUpdateAnnotation(SelectBeforeUpdate annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SELECT_BEFORE_UPDATE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SelectBeforeUpdateAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SELECT_BEFORE_UPDATE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SelectBeforeUpdate.class; + } + + @Override + public boolean value() { + return value; + } + + public void value(boolean value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SequenceGeneratorJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SequenceGeneratorJpaAnnotation.java new file mode 100644 index 0000000000..cabee0931d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SequenceGeneratorJpaAnnotation.java @@ -0,0 +1,176 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.SequenceGenerator; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SequenceGeneratorJpaAnnotation implements SequenceGenerator { + private String name; + private String sequenceName; + private String catalog; + private String schema; + private int initialValue; + private int allocationSize; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SequenceGeneratorJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.sequenceName = ""; + this.catalog = ""; + this.schema = ""; + this.initialValue = 1; + this.allocationSize = 50; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SequenceGeneratorJpaAnnotation(SequenceGenerator annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "name", modelContext ); + this.sequenceName = extractJdkValue( + annotation, + JpaAnnotations.SEQUENCE_GENERATOR, + "sequenceName", + modelContext + ); + this.catalog = extractJdkValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "catalog", modelContext ); + this.schema = extractJdkValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "schema", modelContext ); + this.initialValue = extractJdkValue( + annotation, + JpaAnnotations.SEQUENCE_GENERATOR, + "initialValue", + modelContext + ); + this.allocationSize = extractJdkValue( + annotation, + JpaAnnotations.SEQUENCE_GENERATOR, + "allocationSize", + modelContext + ); + this.options = extractJdkValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SequenceGeneratorJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "name", modelContext ); + this.sequenceName = extractJandexValue( + annotation, + JpaAnnotations.SEQUENCE_GENERATOR, + "sequenceName", + modelContext + ); + this.catalog = extractJandexValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "catalog", modelContext ); + this.schema = extractJandexValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "schema", modelContext ); + this.initialValue = extractJandexValue( + annotation, + JpaAnnotations.SEQUENCE_GENERATOR, + "initialValue", + modelContext + ); + this.allocationSize = extractJandexValue( + annotation, + JpaAnnotations.SEQUENCE_GENERATOR, + "allocationSize", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.SEQUENCE_GENERATOR, "options", modelContext ); + } + + @Override + public Class annotationType() { + return SequenceGenerator.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String sequenceName() { + return sequenceName; + } + + public void sequenceName(String value) { + this.sequenceName = value; + } + + + @Override + public String catalog() { + return catalog; + } + + public void catalog(String value) { + this.catalog = value; + } + + + @Override + public String schema() { + return schema; + } + + public void schema(String value) { + this.schema = value; + } + + + @Override + public int initialValue() { + return initialValue; + } + + public void initialValue(int value) { + this.initialValue = value; + } + + + @Override + public int allocationSize() { + return allocationSize; + } + + public void allocationSize(int value) { + this.allocationSize = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SequenceGeneratorsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SequenceGeneratorsJpaAnnotation.java new file mode 100644 index 0000000000..8eb0f17d9b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SequenceGeneratorsJpaAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.SequenceGenerators; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SequenceGeneratorsJpaAnnotation implements SequenceGenerators, RepeatableContainer { + private SequenceGenerator[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SequenceGeneratorsJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SequenceGeneratorsJpaAnnotation(SequenceGenerators annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.SEQUENCE_GENERATORS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SequenceGeneratorsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.SEQUENCE_GENERATORS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SequenceGenerators.class; + } + + @Override + public SequenceGenerator[] value() { + return value; + } + + public void value(SequenceGenerator[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SoftDeleteAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SoftDeleteAnnotation.java new file mode 100644 index 0000000000..8087cad1be --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SoftDeleteAnnotation.java @@ -0,0 +1,94 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SoftDelete; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SoftDeleteAnnotation implements SoftDelete { + private String columnName; + private org.hibernate.annotations.SoftDeleteType strategy; + private java.lang.Class> converter; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SoftDeleteAnnotation(SourceModelBuildingContext modelContext) { + this.columnName = ""; + this.strategy = org.hibernate.annotations.SoftDeleteType.DELETED; + this.converter = org.hibernate.annotations.SoftDelete.UnspecifiedConversion.class; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SoftDeleteAnnotation(SoftDelete annotation, SourceModelBuildingContext modelContext) { + this.columnName = extractJdkValue( annotation, HibernateAnnotations.SOFT_DELETE, "columnName", modelContext ); + this.strategy = extractJdkValue( annotation, HibernateAnnotations.SOFT_DELETE, "strategy", modelContext ); + this.converter = extractJdkValue( annotation, HibernateAnnotations.SOFT_DELETE, "converter", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SoftDeleteAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.columnName = extractJandexValue( + annotation, + HibernateAnnotations.SOFT_DELETE, + "columnName", + modelContext + ); + this.strategy = extractJandexValue( annotation, HibernateAnnotations.SOFT_DELETE, "strategy", modelContext ); + this.converter = extractJandexValue( annotation, HibernateAnnotations.SOFT_DELETE, "converter", modelContext ); + } + + @Override + public Class annotationType() { + return SoftDelete.class; + } + + @Override + public String columnName() { + return columnName; + } + + public void columnName(String value) { + this.columnName = value; + } + + + @Override + public org.hibernate.annotations.SoftDeleteType strategy() { + return strategy; + } + + public void strategy(org.hibernate.annotations.SoftDeleteType value) { + this.strategy = value; + } + + + @Override + public java.lang.Class> converter() { + return converter; + } + + public void converter(java.lang.Class> value) { + this.converter = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SortComparatorAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SortComparatorAnnotation.java new file mode 100644 index 0000000000..4993a8f162 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SortComparatorAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SortComparator; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SortComparatorAnnotation implements SortComparator { + private java.lang.Class> value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SortComparatorAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SortComparatorAnnotation(SortComparator annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SORT_COMPARATOR, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SortComparatorAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SORT_COMPARATOR, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SortComparator.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SortNaturalAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SortNaturalAnnotation.java new file mode 100644 index 0000000000..56e5f1c774 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SortNaturalAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SortNatural; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SortNaturalAnnotation implements SortNatural { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SortNaturalAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SortNaturalAnnotation(SortNatural annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SortNaturalAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return SortNatural.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SourceAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SourceAnnotation.java new file mode 100644 index 0000000000..9c56430dc6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SourceAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Source; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SourceAnnotation implements Source { + private org.hibernate.annotations.SourceType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SourceAnnotation(SourceModelBuildingContext modelContext) { + this.value = org.hibernate.annotations.SourceType.VM; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SourceAnnotation(Source annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SOURCE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SourceAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SOURCE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Source.class; + } + + @Override + public org.hibernate.annotations.SourceType value() { + return value; + } + + public void value(org.hibernate.annotations.SourceType value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SpecializedAnnotationDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SpecializedAnnotationDescriptor.java new file mode 100644 index 0000000000..f6cf78dd6f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SpecializedAnnotationDescriptor.java @@ -0,0 +1,58 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.models.internal.OrmAnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptor; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractAnnotationTypeAnnotations; + +/** + * Much the same as {@linkplain org.hibernate.models.internal.OrmAnnotationDescriptor} except for + * special cases where we do care about annotations on the annotation type + * + * @author Steve Ebersole + */ +public class SpecializedAnnotationDescriptor extends OrmAnnotationDescriptor { + private final Map, ? extends Annotation> usagesMap; + + public SpecializedAnnotationDescriptor(Class annotationType, Class concreteType) { + super( annotationType, concreteType ); + usagesMap = extractAnnotationsMap( annotationType ); + } + + public SpecializedAnnotationDescriptor(Class annotationType, Class concreteType, AnnotationDescriptor container) { + super( annotationType, concreteType, container ); + usagesMap = extractAnnotationsMap( annotationType ); + } + + @Override + public Map, ? extends Annotation> getUsageMap() { + return usagesMap; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private Map, ? extends Annotation> extractAnnotationsMap(Class annotationType) { + final List annotationTypeAnnotations = extractAnnotationTypeAnnotations( annotationType ); + if ( CollectionHelper.isEmpty( annotationTypeAnnotations ) ) { + return Collections.emptyMap(); + } + + final HashMap result = new HashMap<>(); + annotationTypeAnnotations.forEach( (annotationTypeAnnotation) -> { + result.put( annotationTypeAnnotation.annotationType(), annotationTypeAnnotation ); + } ); + return result; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlFragmentAliasAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlFragmentAliasAnnotation.java new file mode 100644 index 0000000000..8f7f2c978c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlFragmentAliasAnnotation.java @@ -0,0 +1,88 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.SqlFragmentAlias; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SqlFragmentAliasAnnotation implements SqlFragmentAlias { + private String alias; + private String table; + private java.lang.Class entity; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SqlFragmentAliasAnnotation(SourceModelBuildingContext modelContext) { + this.table = ""; + this.entity = void.class; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SqlFragmentAliasAnnotation(SqlFragmentAlias annotation, SourceModelBuildingContext modelContext) { + this.alias = extractJdkValue( annotation, HibernateAnnotations.SQL_FRAGMENT_ALIAS, "alias", modelContext ); + this.table = extractJdkValue( annotation, HibernateAnnotations.SQL_FRAGMENT_ALIAS, "table", modelContext ); + this.entity = extractJdkValue( annotation, HibernateAnnotations.SQL_FRAGMENT_ALIAS, "entity", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SqlFragmentAliasAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.alias = extractJandexValue( annotation, HibernateAnnotations.SQL_FRAGMENT_ALIAS, "alias", modelContext ); + this.table = extractJandexValue( annotation, HibernateAnnotations.SQL_FRAGMENT_ALIAS, "table", modelContext ); + this.entity = extractJandexValue( annotation, HibernateAnnotations.SQL_FRAGMENT_ALIAS, "entity", modelContext ); + } + + @Override + public Class annotationType() { + return SqlFragmentAlias.class; + } + + @Override + public String alias() { + return alias; + } + + public void alias(String value) { + this.alias = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + + @Override + public java.lang.Class entity() { + return entity; + } + + public void entity(java.lang.Class value) { + this.entity = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlResultSetMappingJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlResultSetMappingJpaAnnotation.java new file mode 100644 index 0000000000..344bd374bd --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlResultSetMappingJpaAnnotation.java @@ -0,0 +1,108 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.SqlResultSetMapping; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SqlResultSetMappingJpaAnnotation implements SqlResultSetMapping { + private String name; + private jakarta.persistence.EntityResult[] entities; + private jakarta.persistence.ConstructorResult[] classes; + private jakarta.persistence.ColumnResult[] columns; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SqlResultSetMappingJpaAnnotation(SourceModelBuildingContext modelContext) { + this.entities = new jakarta.persistence.EntityResult[0]; + this.classes = new jakarta.persistence.ConstructorResult[0]; + this.columns = new jakarta.persistence.ColumnResult[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SqlResultSetMappingJpaAnnotation(SqlResultSetMapping annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPING, "name", modelContext ); + this.entities = extractJdkValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPING, "entities", modelContext ); + this.classes = extractJdkValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPING, "classes", modelContext ); + this.columns = extractJdkValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPING, "columns", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SqlResultSetMappingJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPING, "name", modelContext ); + this.entities = extractJandexValue( + annotation, + JpaAnnotations.SQL_RESULT_SET_MAPPING, + "entities", + modelContext + ); + this.classes = extractJandexValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPING, "classes", modelContext ); + this.columns = extractJandexValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPING, "columns", modelContext ); + } + + @Override + public Class annotationType() { + return SqlResultSetMapping.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public jakarta.persistence.EntityResult[] entities() { + return entities; + } + + public void entities(jakarta.persistence.EntityResult[] value) { + this.entities = value; + } + + + @Override + public jakarta.persistence.ConstructorResult[] classes() { + return classes; + } + + public void classes(jakarta.persistence.ConstructorResult[] value) { + this.classes = value; + } + + + @Override + public jakarta.persistence.ColumnResult[] columns() { + return columns; + } + + public void columns(jakarta.persistence.ColumnResult[] value) { + this.columns = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlResultSetMappingsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlResultSetMappingsJpaAnnotation.java new file mode 100644 index 0000000000..355980466a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SqlResultSetMappingsJpaAnnotation.java @@ -0,0 +1,64 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.SqlResultSetMapping; +import jakarta.persistence.SqlResultSetMappings; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SqlResultSetMappingsJpaAnnotation + implements SqlResultSetMappings, RepeatableContainer { + private SqlResultSetMapping[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SqlResultSetMappingsJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SqlResultSetMappingsJpaAnnotation(SqlResultSetMappings annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPINGS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SqlResultSetMappingsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.SQL_RESULT_SET_MAPPINGS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return SqlResultSetMappings.class; + } + + @Override + public SqlResultSetMapping[] value() { + return value; + } + + public void value(SqlResultSetMapping[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/StoredProcedureParameterJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/StoredProcedureParameterJpaAnnotation.java new file mode 100644 index 0000000000..b45602612c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/StoredProcedureParameterJpaAnnotation.java @@ -0,0 +1,109 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameterImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.StoredProcedureParameter; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class StoredProcedureParameterJpaAnnotation implements StoredProcedureParameter { + private String name; + private jakarta.persistence.ParameterMode mode; + private java.lang.Class type; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public StoredProcedureParameterJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.mode = jakarta.persistence.ParameterMode.IN; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public StoredProcedureParameterJpaAnnotation( + StoredProcedureParameter annotation, + SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.STORED_PROCEDURE_PARAMETER, "name", modelContext ); + this.mode = extractJdkValue( annotation, JpaAnnotations.STORED_PROCEDURE_PARAMETER, "mode", modelContext ); + this.type = extractJdkValue( annotation, JpaAnnotations.STORED_PROCEDURE_PARAMETER, "type", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public StoredProcedureParameterJpaAnnotation( + AnnotationInstance annotation, + SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.STORED_PROCEDURE_PARAMETER, "name", modelContext ); + this.mode = extractJandexValue( annotation, JpaAnnotations.STORED_PROCEDURE_PARAMETER, "mode", modelContext ); + this.type = extractJandexValue( annotation, JpaAnnotations.STORED_PROCEDURE_PARAMETER, "type", modelContext ); + } + + @Override + public Class annotationType() { + return StoredProcedureParameter.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public jakarta.persistence.ParameterMode mode() { + return mode; + } + + public void mode(jakarta.persistence.ParameterMode value) { + this.mode = value; + } + + + @Override + public java.lang.Class type() { + return type; + } + + public void type(java.lang.Class value) { + this.type = value; + } + + + public void apply(JaxbStoredProcedureParameterImpl jaxbParam, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbParam.getName() ) ) { + name( jaxbParam.getName() ); + } + + if ( jaxbParam.getMode() != null ) { + mode( jaxbParam.getMode() ); + } + + if ( StringHelper.isNotEmpty( jaxbParam.getClazz() ) ) { + type( xmlDocumentContext.resolveJavaType( jaxbParam.getClazz() ).toJavaClass() ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/StructAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/StructAnnotation.java new file mode 100644 index 0000000000..05d59f42f7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/StructAnnotation.java @@ -0,0 +1,93 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Struct; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class StructAnnotation implements Struct { + private String name; + private String catalog; + private String schema; + private String[] attributes; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public StructAnnotation(SourceModelBuildingContext modelContext) { + this.attributes = new String[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public StructAnnotation(Struct annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.STRUCT, "name", modelContext ); + this.attributes = extractJdkValue( annotation, HibernateAnnotations.STRUCT, "attributes", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public StructAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.STRUCT, "name", modelContext ); + this.attributes = extractJandexValue( annotation, HibernateAnnotations.STRUCT, "attributes", modelContext ); + } + + @Override + public Class annotationType() { + return Struct.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + @Override + public String catalog() { + return catalog; + } + + public void catalog(String value) { + this.catalog = value; + } + + @Override + public String schema() { + return schema; + } + + public void schema(String value) { + this.schema = value; + } + + @Override + public String[] attributes() { + return attributes; + } + + public void attributes(String[] value) { + this.attributes = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SubselectAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SubselectAnnotation.java new file mode 100644 index 0000000000..f76edfd98b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SubselectAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Subselect; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SubselectAnnotation implements Subselect { + private String value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SubselectAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SubselectAnnotation(Subselect annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SUBSELECT, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SubselectAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SUBSELECT, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Subselect.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SynchronizeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SynchronizeAnnotation.java new file mode 100644 index 0000000000..3b04aba4b0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/SynchronizeAnnotation.java @@ -0,0 +1,74 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Synchronize; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class SynchronizeAnnotation implements Synchronize { + private String[] value; + private boolean logical; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public SynchronizeAnnotation(SourceModelBuildingContext modelContext) { + this.logical = true; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public SynchronizeAnnotation(Synchronize annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.SYNCHRONIZE, "value", modelContext ); + this.logical = extractJdkValue( annotation, HibernateAnnotations.SYNCHRONIZE, "logical", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public SynchronizeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.SYNCHRONIZE, "value", modelContext ); + this.logical = extractJandexValue( annotation, HibernateAnnotations.SYNCHRONIZE, "logical", modelContext ); + } + + @Override + public Class annotationType() { + return Synchronize.class; + } + + @Override + public String[] value() { + return value; + } + + public void value(String[] value) { + this.value = value; + } + + + @Override + public boolean logical() { + return logical; + } + + public void logical(boolean value) { + this.logical = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableAnnotation.java new file mode 100644 index 0000000000..967b8eaa7f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableAnnotation.java @@ -0,0 +1,199 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.ForeignKey; +import org.hibernate.annotations.Index; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLInsert; +import org.hibernate.annotations.SQLUpdate; +import org.hibernate.annotations.Table; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TableAnnotation implements Table { + private String appliesTo; + private FetchMode fetch; + private boolean inverse; + private boolean optional; + private String checkConstraint; + private String comment; + private SQLInsert sqlInsert; + private SQLUpdate sqlUpdate; + private SQLDelete sqlDelete; + private ForeignKey foreignKey; + private Index[] indexes; + + public TableAnnotation(SourceModelBuildingContext modelContext) { + this.appliesTo = ""; + this.fetch = FetchMode.JOIN; + this.inverse = false; + this.optional = true; + this.checkConstraint = ""; + this.comment = ""; + this.sqlInsert = new SQLInsertAnnotation( modelContext ); + this.sqlUpdate = new SQLUpdateAnnotation( modelContext ); + this.sqlDelete = new SQLDeleteAnnotation( modelContext ); + this.foreignKey = new ForeignKeyAnnotation( modelContext ); + this.indexes = new Index[0]; + } + + public TableAnnotation(Table annotation, SourceModelBuildingContext modelContext) { + this.appliesTo = extractJdkValue( annotation, HibernateAnnotations.TABLE, "appliesTo", modelContext ); + this.fetch = extractJdkValue( annotation, HibernateAnnotations.TABLE, "fetch", modelContext ); + this.inverse = extractJdkValue( annotation, HibernateAnnotations.TABLE, "inverse", modelContext ); + this.optional = extractJdkValue( annotation, HibernateAnnotations.TABLE, "optional", modelContext ); + this.indexes = extractJdkValue( annotation, HibernateAnnotations.TABLE, "indexes", modelContext ); + this.checkConstraint = extractJdkValue( + annotation, + HibernateAnnotations.TABLE, + "checkConstraint", + modelContext + ); + this.comment = extractJdkValue( annotation, HibernateAnnotations.TABLE, "comment", modelContext ); + this.sqlInsert = extractJdkValue( annotation, HibernateAnnotations.TABLE, "sqlInsert", modelContext ); + this.sqlUpdate = extractJdkValue( annotation, HibernateAnnotations.TABLE, "sqlUpdate", modelContext ); + this.sqlDelete = extractJdkValue( annotation, HibernateAnnotations.TABLE, "sqlDelete", modelContext ); + this.foreignKey = extractJdkValue( annotation, HibernateAnnotations.TABLE, "foreignKey", modelContext ); + this.indexes = extractJdkValue( annotation, HibernateAnnotations.TABLE, "indexes", modelContext ); + } + + public TableAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.appliesTo = extractJandexValue( annotation, HibernateAnnotations.TABLE, "appliesTo", modelContext ); + this.fetch = extractJandexValue( annotation, HibernateAnnotations.TABLE, "fetch", modelContext ); + this.inverse = extractJandexValue( annotation, HibernateAnnotations.TABLE, "inverse", modelContext ); + this.optional = extractJandexValue( annotation, HibernateAnnotations.TABLE, "optional", modelContext ); + this.indexes = extractJandexValue( annotation, HibernateAnnotations.TABLE, "indexes", modelContext ); + this.checkConstraint = extractJandexValue( + annotation, + HibernateAnnotations.TABLE, + "checkConstraint", + modelContext + ); + this.comment = extractJandexValue( annotation, HibernateAnnotations.TABLE, "comment", modelContext ); + this.sqlInsert = extractJandexValue( annotation, HibernateAnnotations.TABLE, "sqlInsert", modelContext ); + this.sqlUpdate = extractJandexValue( annotation, HibernateAnnotations.TABLE, "sqlUpdate", modelContext ); + this.sqlDelete = extractJandexValue( annotation, HibernateAnnotations.TABLE, "sqlDelete", modelContext ); + this.foreignKey = extractJandexValue( annotation, HibernateAnnotations.TABLE, "foreignKey", modelContext ); + this.indexes = extractJandexValue( annotation, HibernateAnnotations.TABLE, "indexes", modelContext ); + } + + @Override + public Class annotationType() { + return Table.class; + } + + @Override + public String appliesTo() { + return appliesTo; + } + + public void appliesTo(String value) { + this.appliesTo = value; + } + + @Override + public FetchMode fetch() { + return fetch; + } + + public void fetch(FetchMode value) { + this.fetch = value; + } + + @Override + public boolean inverse() { + return inverse; + } + + public void inverse(boolean value) { + this.inverse = value; + } + + @Override + public boolean optional() { + return optional; + } + + public void optional(boolean value) { + this.optional = value; + } + + @Override + public String checkConstraint() { + return checkConstraint; + } + + public void checkConstraint(String value) { + this.checkConstraint = value; + } + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + @Override + public ForeignKey foreignKey() { + return foreignKey; + } + + public void foreignKey(ForeignKey value) { + this.foreignKey = value; + } + + @Override + public SQLInsert sqlInsert() { + return sqlInsert; + } + + public void sqlInsert(SQLInsert value) { + this.sqlInsert = value; + } + + @Override + public SQLUpdate sqlUpdate() { + return sqlUpdate; + } + + public void sqlUpdate(SQLUpdate value) { + this.sqlUpdate = value; + } + + @Override + public SQLDelete sqlDelete() { + return sqlDelete; + } + + public void sqlDelete(SQLDelete value) { + this.sqlDelete = value; + } + + @Override + public Index[] indexes() { + return indexes; + } + + public void indexes(Index[] value) { + this.indexes = value; + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableGeneratorJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableGeneratorJpaAnnotation.java new file mode 100644 index 0000000000..da0248f028 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableGeneratorJpaAnnotation.java @@ -0,0 +1,312 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbTableGeneratorImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.IndexCollector; +import org.hibernate.boot.models.annotations.spi.UniqueConstraintCollector; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.TableGenerator; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectIndexes; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectUniqueConstraints; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TableGeneratorJpaAnnotation implements TableGenerator, UniqueConstraintCollector, IndexCollector { + private String name; + private String table; + private String catalog; + private String schema; + private String pkColumnName; + private String valueColumnName; + private String pkColumnValue; + private int initialValue; + private int allocationSize; + private jakarta.persistence.UniqueConstraint[] uniqueConstraints; + private jakarta.persistence.Index[] indexes; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TableGeneratorJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.table = ""; + this.catalog = ""; + this.schema = ""; + this.pkColumnName = ""; + this.valueColumnName = ""; + this.pkColumnValue = ""; + this.initialValue = 0; + this.allocationSize = 50; + this.uniqueConstraints = new jakarta.persistence.UniqueConstraint[0]; + this.indexes = new jakarta.persistence.Index[0]; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TableGeneratorJpaAnnotation(TableGenerator annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "name", modelContext ); + this.table = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "table", modelContext ); + this.catalog = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "catalog", modelContext ); + this.schema = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "schema", modelContext ); + this.pkColumnName = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "pkColumnName", modelContext ); + this.valueColumnName = extractJdkValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "valueColumnName", + modelContext + ); + this.pkColumnValue = extractJdkValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "pkColumnValue", + modelContext + ); + this.initialValue = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "initialValue", modelContext ); + this.allocationSize = extractJdkValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "allocationSize", + modelContext + ); + this.uniqueConstraints = extractJdkValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "indexes", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATOR, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TableGeneratorJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.TABLE_GENERATOR, "name", modelContext ); + this.table = extractJandexValue( annotation, JpaAnnotations.TABLE_GENERATOR, "table", modelContext ); + this.catalog = extractJandexValue( annotation, JpaAnnotations.TABLE_GENERATOR, "catalog", modelContext ); + this.schema = extractJandexValue( annotation, JpaAnnotations.TABLE_GENERATOR, "schema", modelContext ); + this.pkColumnName = extractJandexValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "pkColumnName", + modelContext + ); + this.valueColumnName = extractJandexValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "valueColumnName", + modelContext + ); + this.pkColumnValue = extractJandexValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "pkColumnValue", + modelContext + ); + this.initialValue = extractJandexValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "initialValue", + modelContext + ); + this.allocationSize = extractJandexValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "allocationSize", + modelContext + ); + this.uniqueConstraints = extractJandexValue( + annotation, + JpaAnnotations.TABLE_GENERATOR, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJandexValue( annotation, JpaAnnotations.TABLE_GENERATOR, "indexes", modelContext ); + this.options = extractJandexValue( annotation, JpaAnnotations.TABLE_GENERATOR, "options", modelContext ); + } + + @Override + public Class annotationType() { + return TableGenerator.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + + @Override + public String catalog() { + return catalog; + } + + public void catalog(String value) { + this.catalog = value; + } + + + @Override + public String schema() { + return schema; + } + + public void schema(String value) { + this.schema = value; + } + + + @Override + public String pkColumnName() { + return pkColumnName; + } + + public void pkColumnName(String value) { + this.pkColumnName = value; + } + + + @Override + public String valueColumnName() { + return valueColumnName; + } + + public void valueColumnName(String value) { + this.valueColumnName = value; + } + + + @Override + public String pkColumnValue() { + return pkColumnValue; + } + + public void pkColumnValue(String value) { + this.pkColumnValue = value; + } + + + @Override + public int initialValue() { + return initialValue; + } + + public void initialValue(int value) { + this.initialValue = value; + } + + + @Override + public int allocationSize() { + return allocationSize; + } + + public void allocationSize(int value) { + this.allocationSize = value; + } + + + @Override + public jakarta.persistence.UniqueConstraint[] uniqueConstraints() { + return uniqueConstraints; + } + + public void uniqueConstraints(jakarta.persistence.UniqueConstraint[] value) { + this.uniqueConstraints = value; + } + + + @Override + public jakarta.persistence.Index[] indexes() { + return indexes; + } + + public void indexes(jakarta.persistence.Index[] value) { + this.indexes = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + public void apply(JaxbTableGeneratorImpl jaxbGenerator, XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbGenerator.getName() ) ) { + name( jaxbGenerator.getName() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getTable() ) ) { + table( jaxbGenerator.getTable() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getCatalog() ) ) { + catalog( jaxbGenerator.getCatalog() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getSchema() ) ) { + schema( jaxbGenerator.getSchema() ); + } + + if ( StringHelper.isNotEmpty( jaxbGenerator.getPkColumnName() ) ) { + pkColumnName( jaxbGenerator.getPkColumnName() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getPkColumnValue() ) ) { + pkColumnValue( jaxbGenerator.getPkColumnValue() ); + } + + if ( StringHelper.isNotEmpty( jaxbGenerator.getValueColumnName() ) ) { + valueColumnName( jaxbGenerator.getValueColumnName() ); + } + + if ( jaxbGenerator.getInitialValue() != null ) { + initialValue( jaxbGenerator.getInitialValue() ); + } + if ( jaxbGenerator.getAllocationSize() != null ) { + allocationSize( jaxbGenerator.getAllocationSize() ); + } + + if ( StringHelper.isNotEmpty( jaxbGenerator.getOptions() ) ) { + options( jaxbGenerator.getOptions() ); + } + + uniqueConstraints( collectUniqueConstraints( jaxbGenerator.getUniqueConstraints(), xmlDocumentContext ) ); + indexes( collectIndexes( jaxbGenerator.getIndexes(), xmlDocumentContext ) ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableGeneratorsJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableGeneratorsJpaAnnotation.java new file mode 100644 index 0000000000..d675d59375 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableGeneratorsJpaAnnotation.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.TableGenerator; +import jakarta.persistence.TableGenerators; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TableGeneratorsJpaAnnotation implements TableGenerators, RepeatableContainer { + private TableGenerator[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TableGeneratorsJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TableGeneratorsJpaAnnotation(TableGenerators annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.TABLE_GENERATORS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TableGeneratorsJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.TABLE_GENERATORS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return TableGenerators.class; + } + + @Override + public TableGenerator[] value() { + return value; + } + + public void value(TableGenerator[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableJpaAnnotation.java new file mode 100644 index 0000000000..3e321a8715 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TableJpaAnnotation.java @@ -0,0 +1,186 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbTableImpl; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.CommonTableDetails; +import org.hibernate.boot.models.annotations.spi.DatabaseObjectDetails; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Table; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyCatalog; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyOptionalString; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applySchema; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectCheckConstraints; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectIndexes; +import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.collectUniqueConstraints; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TableJpaAnnotation implements Table, CommonTableDetails { + private String name; + private String catalog; + private String schema; + private jakarta.persistence.UniqueConstraint[] uniqueConstraints; + private jakarta.persistence.Index[] indexes; + private jakarta.persistence.CheckConstraint[] check; + private String comment; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TableJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.catalog = ""; + this.schema = ""; + this.uniqueConstraints = new jakarta.persistence.UniqueConstraint[0]; + this.indexes = new jakarta.persistence.Index[0]; + this.check = new jakarta.persistence.CheckConstraint[0]; + this.comment = ""; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TableJpaAnnotation(Table annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.TABLE, "name", modelContext ); + this.catalog = extractJdkValue( annotation, JpaAnnotations.TABLE, "catalog", modelContext ); + this.schema = extractJdkValue( annotation, JpaAnnotations.TABLE, "schema", modelContext ); + this.uniqueConstraints = extractJdkValue( annotation, JpaAnnotations.TABLE, "uniqueConstraints", modelContext ); + this.indexes = extractJdkValue( annotation, JpaAnnotations.TABLE, "indexes", modelContext ); + this.check = extractJdkValue( annotation, JpaAnnotations.TABLE, "check", modelContext ); + this.comment = extractJdkValue( annotation, JpaAnnotations.TABLE, "comment", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.TABLE, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TableJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.TABLE, "name", modelContext ); + this.catalog = extractJandexValue( annotation, JpaAnnotations.TABLE, "catalog", modelContext ); + this.schema = extractJandexValue( annotation, JpaAnnotations.TABLE, "schema", modelContext ); + this.uniqueConstraints = extractJandexValue( + annotation, + JpaAnnotations.TABLE, + "uniqueConstraints", + modelContext + ); + this.indexes = extractJandexValue( annotation, JpaAnnotations.TABLE, "indexes", modelContext ); + this.check = extractJandexValue( annotation, JpaAnnotations.TABLE, "check", modelContext ); + this.comment = extractJandexValue( annotation, JpaAnnotations.TABLE, "comment", modelContext ); + this.options = extractJandexValue( annotation, JpaAnnotations.TABLE, "options", modelContext ); + } + + @Override + public Class annotationType() { + return Table.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String catalog() { + return catalog; + } + + public void catalog(String value) { + this.catalog = value; + } + + + @Override + public String schema() { + return schema; + } + + public void schema(String value) { + this.schema = value; + } + + + @Override + public jakarta.persistence.UniqueConstraint[] uniqueConstraints() { + return uniqueConstraints; + } + + public void uniqueConstraints(jakarta.persistence.UniqueConstraint[] value) { + this.uniqueConstraints = value; + } + + + @Override + public jakarta.persistence.Index[] indexes() { + return indexes; + } + + public void indexes(jakarta.persistence.Index[] value) { + this.indexes = value; + } + + + @Override + public jakarta.persistence.CheckConstraint[] check() { + return check; + } + + public void check(jakarta.persistence.CheckConstraint[] value) { + this.check = value; + } + + + @Override + public String comment() { + return comment; + } + + public void comment(String value) { + this.comment = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + + public void apply(JaxbTableImpl jaxbTable, XmlDocumentContext xmlDocumentContext) { + applyOptionalString( jaxbTable.getName(), this::name ); + applyCatalog( jaxbTable, this, xmlDocumentContext ); + applySchema( jaxbTable, this, xmlDocumentContext ); + applyOptionalString( jaxbTable.getComment(), this::comment ); + applyOptionalString( jaxbTable.getOptions(), this::options ); + + check( collectCheckConstraints( jaxbTable.getCheckConstraints(), xmlDocumentContext ) ); + indexes( collectIndexes( jaxbTable.getIndexes(), xmlDocumentContext ) ); + uniqueConstraints( collectUniqueConstraints( jaxbTable.getUniqueConstraints(), xmlDocumentContext ) ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TablesAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TablesAnnotation.java new file mode 100644 index 0000000000..84256695b8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TablesAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Table; +import org.hibernate.annotations.Tables; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TablesAnnotation implements Tables, RepeatableContainer
{ + private org.hibernate.annotations.Table[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TablesAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TablesAnnotation(Tables annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.TABLES, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TablesAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.TABLES, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Tables.class; + } + + @Override + public org.hibernate.annotations.Table[] value() { + return value; + } + + public void value(org.hibernate.annotations.Table[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TargetLegacyAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TargetLegacyAnnotation.java new file mode 100644 index 0000000000..08605f22d1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TargetLegacyAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Target; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TargetLegacyAnnotation implements Target { + private Class value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TargetLegacyAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TargetLegacyAnnotation(Target annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.TARGET_LEGACY, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TargetLegacyAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.TARGET_LEGACY, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Target.class; + } + + @Override + public Class value() { + return value; + } + + public void value(Class value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TargetXmlAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TargetXmlAnnotation.java new file mode 100644 index 0000000000..0962dc33a2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TargetXmlAnnotation.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.models.spi.AnnotationDescriptor; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.internal.Target; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TargetXmlAnnotation implements Target { + private String value; + + public TargetXmlAnnotation(SourceModelBuildingContext modelContext) { + } + + public TargetXmlAnnotation(Target annotation, SourceModelBuildingContext modelContext) { + } + + public TargetXmlAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Target.class; + } + + @Override + public String value() { + return value; + } + + public void value(String value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TemporalJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TemporalJpaAnnotation.java new file mode 100644 index 0000000000..8b54f988c2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TemporalJpaAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Temporal; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TemporalJpaAnnotation implements Temporal { + private jakarta.persistence.TemporalType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TemporalJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TemporalJpaAnnotation(Temporal annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, JpaAnnotations.TEMPORAL, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TemporalJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, JpaAnnotations.TEMPORAL, "value", modelContext ); + } + + @Override + public Class annotationType() { + return Temporal.class; + } + + @Override + public jakarta.persistence.TemporalType value() { + return value; + } + + public void value(jakarta.persistence.TemporalType value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TenantIdAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TenantIdAnnotation.java new file mode 100644 index 0000000000..03d0724193 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TenantIdAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.TenantId; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TenantIdAnnotation implements TenantId { + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TenantIdAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TenantIdAnnotation(TenantId annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TenantIdAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return TenantId.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TimeZoneColumnAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TimeZoneColumnAnnotation.java new file mode 100644 index 0000000000..334b5572da --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TimeZoneColumnAnnotation.java @@ -0,0 +1,147 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.TimeZoneColumn; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TimeZoneColumnAnnotation implements TimeZoneColumn { + private String name; + private boolean insertable; + private boolean updatable; + private String columnDefinition; + private String table; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TimeZoneColumnAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.insertable = true; + this.updatable = true; + this.columnDefinition = ""; + this.table = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TimeZoneColumnAnnotation(TimeZoneColumn annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, HibernateAnnotations.TIME_ZONE_COLUMN, "name", modelContext ); + this.insertable = extractJdkValue( + annotation, + HibernateAnnotations.TIME_ZONE_COLUMN, + "insertable", + modelContext + ); + this.updatable = extractJdkValue( + annotation, + HibernateAnnotations.TIME_ZONE_COLUMN, + "updatable", + modelContext + ); + this.columnDefinition = extractJdkValue( + annotation, + HibernateAnnotations.TIME_ZONE_COLUMN, + "columnDefinition", + modelContext + ); + this.table = extractJdkValue( annotation, HibernateAnnotations.TIME_ZONE_COLUMN, "table", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TimeZoneColumnAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, HibernateAnnotations.TIME_ZONE_COLUMN, "name", modelContext ); + this.insertable = extractJandexValue( + annotation, + HibernateAnnotations.TIME_ZONE_COLUMN, + "insertable", + modelContext + ); + this.updatable = extractJandexValue( + annotation, + HibernateAnnotations.TIME_ZONE_COLUMN, + "updatable", + modelContext + ); + this.columnDefinition = extractJandexValue( + annotation, + HibernateAnnotations.TIME_ZONE_COLUMN, + "columnDefinition", + modelContext + ); + this.table = extractJandexValue( annotation, HibernateAnnotations.TIME_ZONE_COLUMN, "table", modelContext ); + } + + @Override + public Class annotationType() { + return TimeZoneColumn.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public boolean insertable() { + return insertable; + } + + public void insertable(boolean value) { + this.insertable = value; + } + + + @Override + public boolean updatable() { + return updatable; + } + + public void updatable(boolean value) { + this.updatable = value; + } + + + @Override + public String columnDefinition() { + return columnDefinition; + } + + public void columnDefinition(String value) { + this.columnDefinition = value; + } + + + @Override + public String table() { + return table; + } + + public void table(String value) { + this.table = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TimeZoneStorageAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TimeZoneStorageAnnotation.java new file mode 100644 index 0000000000..c2d7218065 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TimeZoneStorageAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.TimeZoneStorage; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TimeZoneStorageAnnotation implements TimeZoneStorage { + private org.hibernate.annotations.TimeZoneStorageType value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TimeZoneStorageAnnotation(SourceModelBuildingContext modelContext) { + this.value = org.hibernate.annotations.TimeZoneStorageType.AUTO; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TimeZoneStorageAnnotation(TimeZoneStorage annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.TIME_ZONE_STORAGE, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TimeZoneStorageAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.TIME_ZONE_STORAGE, "value", modelContext ); + } + + @Override + public Class annotationType() { + return TimeZoneStorage.class; + } + + @Override + public org.hibernate.annotations.TimeZoneStorageType value() { + return value; + } + + public void value(org.hibernate.annotations.TimeZoneStorageType value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TransientJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TransientJpaAnnotation.java new file mode 100644 index 0000000000..4c7233f267 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TransientJpaAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Transient; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TransientJpaAnnotation implements Transient { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TransientJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TransientJpaAnnotation(Transient annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TransientJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Transient.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeAnnotation.java new file mode 100644 index 0000000000..c8da43b9d3 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeAnnotation.java @@ -0,0 +1,74 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Type; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TypeAnnotation implements Type { + private java.lang.Class> value; + private org.hibernate.annotations.Parameter[] parameters; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TypeAnnotation(SourceModelBuildingContext modelContext) { + this.parameters = new org.hibernate.annotations.Parameter[0]; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TypeAnnotation(Type annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.TYPE, "value", modelContext ); + this.parameters = extractJdkValue( annotation, HibernateAnnotations.TYPE, "parameters", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.TYPE, "value", modelContext ); + this.parameters = extractJandexValue( annotation, HibernateAnnotations.TYPE, "parameters", modelContext ); + } + + @Override + public Class annotationType() { + return Type.class; + } + + @Override + public java.lang.Class> value() { + return value; + } + + public void value(java.lang.Class> value) { + this.value = value; + } + + + @Override + public org.hibernate.annotations.Parameter[] parameters() { + return parameters; + } + + public void parameters(org.hibernate.annotations.Parameter[] value) { + this.parameters = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeBinderTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeBinderTypeAnnotation.java new file mode 100644 index 0000000000..5c07abb263 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeBinderTypeAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.TypeBinderType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TypeBinderTypeAnnotation implements TypeBinderType { + private java.lang.Class> binder; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TypeBinderTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TypeBinderTypeAnnotation(TypeBinderType annotation, SourceModelBuildingContext modelContext) { + this.binder = extractJdkValue( annotation, HibernateAnnotations.TYPE_BINDER_TYPE, "binder", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TypeBinderTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.binder = extractJandexValue( annotation, HibernateAnnotations.TYPE_BINDER_TYPE, "binder", modelContext ); + } + + @Override + public Class annotationType() { + return TypeBinderType.class; + } + + @Override + public java.lang.Class> binder() { + return binder; + } + + public void binder(java.lang.Class> value) { + this.binder = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeRegistrationAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeRegistrationAnnotation.java new file mode 100644 index 0000000000..d73959f079 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeRegistrationAnnotation.java @@ -0,0 +1,88 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.TypeRegistration; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TypeRegistrationAnnotation implements TypeRegistration { + private java.lang.Class basicClass; + private java.lang.Class> userType; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TypeRegistrationAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TypeRegistrationAnnotation(TypeRegistration annotation, SourceModelBuildingContext modelContext) { + this.basicClass = extractJdkValue( + annotation, + HibernateAnnotations.TYPE_REGISTRATION, + "basicClass", + modelContext + ); + this.userType = extractJdkValue( annotation, HibernateAnnotations.TYPE_REGISTRATION, "userType", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TypeRegistrationAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.basicClass = extractJandexValue( + annotation, + HibernateAnnotations.TYPE_REGISTRATION, + "basicClass", + modelContext + ); + this.userType = extractJandexValue( + annotation, + HibernateAnnotations.TYPE_REGISTRATION, + "userType", + modelContext + ); + } + + @Override + public Class annotationType() { + return TypeRegistration.class; + } + + @Override + public java.lang.Class basicClass() { + return basicClass; + } + + public void basicClass(java.lang.Class value) { + this.basicClass = value; + } + + + @Override + public java.lang.Class> userType() { + return userType; + } + + public void userType(java.lang.Class> value) { + this.userType = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeRegistrationsAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeRegistrationsAnnotation.java new file mode 100644 index 0000000000..81a01bb1b0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/TypeRegistrationsAnnotation.java @@ -0,0 +1,62 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.TypeRegistration; +import org.hibernate.annotations.TypeRegistrations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.spi.RepeatableContainer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class TypeRegistrationsAnnotation implements TypeRegistrations, RepeatableContainer { + private org.hibernate.annotations.TypeRegistration[] value; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public TypeRegistrationsAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public TypeRegistrationsAnnotation(TypeRegistrations annotation, SourceModelBuildingContext modelContext) { + this.value = extractJdkValue( annotation, HibernateAnnotations.TYPE_REGISTRATIONS, "value", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public TypeRegistrationsAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.value = extractJandexValue( annotation, HibernateAnnotations.TYPE_REGISTRATIONS, "value", modelContext ); + } + + @Override + public Class annotationType() { + return TypeRegistrations.class; + } + + @Override + public org.hibernate.annotations.TypeRegistration[] value() { + return value; + } + + public void value(org.hibernate.annotations.TypeRegistration[] value) { + this.value = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UniqueConstraintJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UniqueConstraintJpaAnnotation.java new file mode 100644 index 0000000000..e98d0eddce --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UniqueConstraintJpaAnnotation.java @@ -0,0 +1,94 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.UniqueConstraint; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class UniqueConstraintJpaAnnotation implements UniqueConstraint { + private String name; + private String[] columnNames; + private String options; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public UniqueConstraintJpaAnnotation(SourceModelBuildingContext modelContext) { + this.name = ""; + this.options = ""; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public UniqueConstraintJpaAnnotation(UniqueConstraint annotation, SourceModelBuildingContext modelContext) { + this.name = extractJdkValue( annotation, JpaAnnotations.UNIQUE_CONSTRAINT, "name", modelContext ); + this.columnNames = extractJdkValue( annotation, JpaAnnotations.UNIQUE_CONSTRAINT, "columnNames", modelContext ); + this.options = extractJdkValue( annotation, JpaAnnotations.UNIQUE_CONSTRAINT, "options", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public UniqueConstraintJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.name = extractJandexValue( annotation, JpaAnnotations.UNIQUE_CONSTRAINT, "name", modelContext ); + this.columnNames = extractJandexValue( + annotation, + JpaAnnotations.UNIQUE_CONSTRAINT, + "columnNames", + modelContext + ); + this.options = extractJandexValue( annotation, JpaAnnotations.UNIQUE_CONSTRAINT, "options", modelContext ); + } + + @Override + public Class annotationType() { + return UniqueConstraint.class; + } + + @Override + public String name() { + return name; + } + + public void name(String value) { + this.name = value; + } + + + @Override + public String[] columnNames() { + return columnNames; + } + + public void columnNames(String[] value) { + this.columnNames = value; + } + + + @Override + public String options() { + return options; + } + + public void options(String value) { + this.options = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UpdateTimestampAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UpdateTimestampAnnotation.java new file mode 100644 index 0000000000..9850c853a0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UpdateTimestampAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.UpdateTimestamp; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class UpdateTimestampAnnotation implements UpdateTimestamp { + private org.hibernate.annotations.SourceType source; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public UpdateTimestampAnnotation(SourceModelBuildingContext modelContext) { + this.source = org.hibernate.annotations.SourceType.VM; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public UpdateTimestampAnnotation(UpdateTimestamp annotation, SourceModelBuildingContext modelContext) { + this.source = extractJdkValue( annotation, HibernateAnnotations.UPDATE_TIMESTAMP, "source", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public UpdateTimestampAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.source = extractJandexValue( annotation, HibernateAnnotations.UPDATE_TIMESTAMP, "source", modelContext ); + } + + @Override + public Class annotationType() { + return UpdateTimestamp.class; + } + + @Override + public org.hibernate.annotations.SourceType source() { + return source; + } + + public void source(org.hibernate.annotations.SourceType value) { + this.source = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UuidGeneratorAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UuidGeneratorAnnotation.java new file mode 100644 index 0000000000..aeddd7fd98 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/UuidGeneratorAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.UuidGenerator; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class UuidGeneratorAnnotation implements UuidGenerator { + private org.hibernate.annotations.UuidGenerator.Style style; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public UuidGeneratorAnnotation(SourceModelBuildingContext modelContext) { + this.style = org.hibernate.annotations.UuidGenerator.Style.AUTO; + } + + /** + * Used in creating annotation instances from JDK variant + */ + public UuidGeneratorAnnotation(UuidGenerator annotation, SourceModelBuildingContext modelContext) { + this.style = extractJdkValue( annotation, HibernateAnnotations.UUID_GENERATOR, "style", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public UuidGeneratorAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.style = extractJandexValue( annotation, HibernateAnnotations.UUID_GENERATOR, "style", modelContext ); + } + + @Override + public Class annotationType() { + return UuidGenerator.class; + } + + @Override + public org.hibernate.annotations.UuidGenerator.Style style() { + return style; + } + + public void style(org.hibernate.annotations.UuidGenerator.Style value) { + this.style = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ValueGenerationTypeAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ValueGenerationTypeAnnotation.java new file mode 100644 index 0000000000..bd47345a0d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ValueGenerationTypeAnnotation.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ValueGenerationType; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ValueGenerationTypeAnnotation implements ValueGenerationType { + private java.lang.Class generatedBy; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ValueGenerationTypeAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ValueGenerationTypeAnnotation(ValueGenerationType annotation, SourceModelBuildingContext modelContext) { + this.generatedBy = extractJdkValue( + annotation, + HibernateAnnotations.VALUE_GENERATION_TYPE, + "generatedBy", + modelContext + ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ValueGenerationTypeAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.generatedBy = extractJandexValue( + annotation, + HibernateAnnotations.VALUE_GENERATION_TYPE, + "generatedBy", + modelContext + ); + } + + @Override + public Class annotationType() { + return ValueGenerationType.class; + } + + @Override + public java.lang.Class generatedBy() { + return generatedBy; + } + + public void generatedBy(java.lang.Class value) { + this.generatedBy = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/VersionJpaAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/VersionJpaAnnotation.java new file mode 100644 index 0000000000..c71e81889d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/VersionJpaAnnotation.java @@ -0,0 +1,42 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import jakarta.persistence.Version; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class VersionJpaAnnotation implements Version { + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public VersionJpaAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public VersionJpaAnnotation(Version annotation, SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public VersionJpaAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + } + + @Override + public Class annotationType() { + return Version.class; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ViewAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ViewAnnotation.java new file mode 100644 index 0000000000..617f9c2568 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/ViewAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.View; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class ViewAnnotation implements View { + + private String query; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public ViewAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public ViewAnnotation(View annotation, SourceModelBuildingContext modelContext) { + this.query = extractJdkValue( annotation, HibernateAnnotations.VIEW, "query", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public ViewAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.query = extractJandexValue( annotation, HibernateAnnotations.VIEW, "query", modelContext ); + } + + @Override + public Class annotationType() { + return View.class; + } + + @Override + public String query() { + return query; + } + + public void query(String value) { + this.query = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/WhereAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/WhereAnnotation.java new file mode 100644 index 0000000000..c6c15e658a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/WhereAnnotation.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.Where; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class WhereAnnotation implements Where { + private String clause; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public WhereAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public WhereAnnotation(Where annotation, SourceModelBuildingContext modelContext) { + this.clause = extractJdkValue( annotation, HibernateAnnotations.WHERE, "clause", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public WhereAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.clause = extractJandexValue( annotation, HibernateAnnotations.WHERE, "clause", modelContext ); + } + + @Override + public Class annotationType() { + return Where.class; + } + + @Override + public String clause() { + return clause; + } + + public void clause(String value) { + this.clause = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/WhereJoinTableAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/WhereJoinTableAnnotation.java new file mode 100644 index 0000000000..845e896892 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/WhereJoinTableAnnotation.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.internal; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.WhereJoinTable; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJdkValue; + +@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) +@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") +public class WhereJoinTableAnnotation implements WhereJoinTable { + private String clause; + + /** + * Used in creating dynamic annotation instances (e.g. from XML) + */ + public WhereJoinTableAnnotation(SourceModelBuildingContext modelContext) { + } + + /** + * Used in creating annotation instances from JDK variant + */ + public WhereJoinTableAnnotation(WhereJoinTable annotation, SourceModelBuildingContext modelContext) { + this.clause = extractJdkValue( annotation, HibernateAnnotations.WHERE_JOIN_TABLE, "clause", modelContext ); + } + + /** + * Used in creating annotation instances from Jandex variant + */ + public WhereJoinTableAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { + this.clause = extractJandexValue( annotation, HibernateAnnotations.WHERE_JOIN_TABLE, "clause", modelContext ); + } + + @Override + public Class annotationType() { + return WhereJoinTable.class; + } + + @Override + public String clause() { + return clause; + } + + public void clause(String value) { + this.clause = value; + } + + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/AbstractOverrider.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/AbstractOverrider.java new file mode 100644 index 0000000000..941e5cdfce --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/AbstractOverrider.java @@ -0,0 +1,81 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.dialect.DatabaseVersion; +import org.hibernate.dialect.Dialect; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; + +import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; + +/** + * Base support for {@linkplain DialectOverrider} annotations + * + * @author Steve Ebersole + */ +public abstract class AbstractOverrider implements DialectOverrider { + private Class dialect; + private DialectOverride.Version before; + private DialectOverride.Version sameOrAfter; + + public AbstractOverrider() { + } + + public AbstractOverrider( + AnnotationInstance annotation, + AnnotationDescriptor descriptor, + SourceModelBuildingContext modelContext) { + dialect( extractJandexValue( annotation, descriptor, "dialect", modelContext ) ); + before( extractJandexValue( annotation, descriptor, "before", modelContext ) ); + sameOrAfter( extractJandexValue( annotation, descriptor, "sameOrAfter", modelContext ) ); + } + + @Override + public Class dialect() { + return dialect; + } + + public void dialect(Class dialect) { + this.dialect = dialect; + } + + @Override + public DialectOverride.Version before() { + return before; + } + + public void before(DialectOverride.Version before) { + this.before = before; + } + + @Override + public DialectOverride.Version sameOrAfter() { + return sameOrAfter; + } + + public void sameOrAfter(DialectOverride.Version sameOrAfter) { + this.sameOrAfter = sameOrAfter; + } + + @Override + public boolean matches(Dialect dialectToMatch) { + if ( !dialect().isAssignableFrom( dialectToMatch.getClass() ) ) { + return false; + } + + final DatabaseVersion versionToMatch = dialectToMatch.getVersion(); + return versionToMatch.isBefore( before().major(), before().minor() ) + && versionToMatch.isSameOrAfter( sameOrAfter().major(), sameOrAfter().minor() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/AttributeMarker.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/AttributeMarker.java new file mode 100644 index 0000000000..4de8865c11 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/AttributeMarker.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.FetchType; + +/** + * Commonality for annotations which identify attributes. + * + * @apiNote All the interesting bits are in the optional sub-interfaces. + * + * @author Steve Ebersole + */ +public interface AttributeMarker extends Annotation { + interface Fetchable extends AttributeMarker { + FetchType fetch(); + + void fetch(FetchType value); + } + + interface Cascadeable extends AttributeMarker { + jakarta.persistence.CascadeType[] cascade(); + + void cascade(jakarta.persistence.CascadeType[] value); + } + + interface Optionalable extends AttributeMarker { + boolean optional(); + + void optional(boolean value); + } + + interface Mappable extends AttributeMarker { + String mappedBy(); + + void mappedBy(String value); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CheckConstraintCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CheckConstraintCollector.java new file mode 100644 index 0000000000..4dfbb7724d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CheckConstraintCollector.java @@ -0,0 +1,22 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.CheckConstraint; + +/** + * Commonality for annotations which define check-constraints + * + * @author Steve Ebersole + */ +public interface CheckConstraintCollector extends Annotation { + CheckConstraint[] check(); + + void check(CheckConstraint[] value); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/ColumnDetails.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/ColumnDetails.java new file mode 100644 index 0000000000..62c7592f05 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/ColumnDetails.java @@ -0,0 +1,76 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ + +package org.hibernate.boot.models.annotations.spi; + +/** + * @author Steve Ebersole + */ +public interface ColumnDetails { + String name(); + + void name(String value); + + interface AlternateTableCapable { + String table(); + + void table(String value); + } + + interface Nullable extends ColumnDetails { + boolean nullable(); + + void nullable(boolean value); + } + + interface Mutable extends ColumnDetails { + + boolean insertable(); + + void insertable(boolean value); + + boolean updatable(); + + void updatable(boolean value); + } + + interface Sizable extends ColumnDetails { + int length(); + + void length(int value); + + int precision(); + + void precision(int value); + + int scale(); + + void scale(int value); + } + + interface SecondSizable extends Sizable { + int secondPrecision(); + + void secondPrecision(int value); + } + + interface Uniqueable extends ColumnDetails { + boolean unique(); + + void unique(boolean value); + } + + interface Definable extends ColumnDetails { + String columnDefinition(); + + void columnDefinition(String value); + + String options(); + + void options(String value); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/Observable.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/Commentable.java similarity index 51% rename from hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/Observable.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/Commentable.java index cffb93c94d..1e407863fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/Observable.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/Commentable.java @@ -4,11 +4,17 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.bind.internal; +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; /** + * Commonality for annotations which contain SQL comments + * * @author Steve Ebersole */ -public interface Observable { - void whenResolved(ResolutionCallback callback); +public interface Commentable extends Annotation { + String comment(); + + void comment(String value); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CommonTableDetails.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CommonTableDetails.java new file mode 100644 index 0000000000..60efbb1b02 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CommonTableDetails.java @@ -0,0 +1,25 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ + +package org.hibernate.boot.models.annotations.spi; + +/** + * Information which is common across all table annotations + * + * @author Steve Ebersole + */ +public interface CommonTableDetails extends DatabaseObjectDetails, UniqueConstraintCollector, IndexCollector { + /** + * The table name + */ + String name(); + + /** + * Setter for {@linkplain #name()} + */ + void name(String name); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CustomSqlDetails.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CustomSqlDetails.java new file mode 100644 index 0000000000..3037ce6762 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/CustomSqlDetails.java @@ -0,0 +1,34 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.ResultCheckStyle; + +/** + * Commonality for annotations which define custom insert, update and delete SQL + * + * @author Steve Ebersole + */ +public interface CustomSqlDetails extends Annotation { + String sql(); + + void sql(String value); + + boolean callable(); + + void callable(boolean value); + + String table(); + + void table(String value); + + ResultCheckStyle check(); + + void check(ResultCheckStyle resultCheckStyle); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/DatabaseObjectDetails.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/DatabaseObjectDetails.java new file mode 100644 index 0000000000..bcf35cace2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/DatabaseObjectDetails.java @@ -0,0 +1,41 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ + +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.SequenceGenerator; + +/** + * Commonality for annotations which represent database objects. + * + * @apiNote While they all have names, some use an attribute other than {@code name()} - e.g. {@linkplain SequenceGenerator#sequenceName()} + * + * @author Steve Ebersole + */ +public interface DatabaseObjectDetails extends Annotation { + /** + * The catalog in which the object exists + */ + String catalog(); + + /** + * Setter for {@linkplain #catalog()} + */ + void catalog(String catalog); + + /** + * The schema in which the object exists + */ + String schema(); + + /** + * Setter for {@linkplain #schema()} + */ + void schema(String schema); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/DialectOverrider.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/DialectOverrider.java new file mode 100644 index 0000000000..987f271d77 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/DialectOverrider.java @@ -0,0 +1,32 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.DialectOverride; +import org.hibernate.dialect.Dialect; +import org.hibernate.models.spi.AnnotationDescriptor; + +/** + * Common contract for {@linkplain DialectOverride.OverridesAnnotation override} annotations defined in {@linkplain DialectOverride} + * + * @author Steve Ebersole + */ +public interface DialectOverrider extends Annotation { + Class dialect(); + + DialectOverride.Version before(); + + DialectOverride.Version sameOrAfter(); + + O override(); + + AnnotationDescriptor getOverriddenDescriptor(); + + boolean matches(Dialect dialectToMatch); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/FilterDetails.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/FilterDetails.java new file mode 100644 index 0000000000..edc65300ae --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/FilterDetails.java @@ -0,0 +1,22 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; + +/** + * Commonality for filter annotations + * + * @see org.hibernate.annotations.Filter + * @see org.hibernate.annotations.FilterJoinTable + * + * @author Steve Ebersole + */ +public interface FilterDetails { + void apply(JaxbHbmFilterImpl jaxbFilter, XmlDocumentContext xmlDocumentContext); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/IndexCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/IndexCollector.java new file mode 100644 index 0000000000..6ffc07adc3 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/IndexCollector.java @@ -0,0 +1,22 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.Index; + +/** + * Commonality for annotations which define indexes + * + * @author Steve Ebersole + */ +public interface IndexCollector extends Annotation { + Index[] indexes(); + + void indexes(Index[] value); +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/Listener2.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/Named.java similarity index 54% rename from hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/Listener2.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/Named.java index ab6539ba63..a154cad8de 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/Listener2.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/Named.java @@ -4,14 +4,16 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.orm.test.boot.models.bind.callbacks; -import jakarta.persistence.PostLoad; +package org.hibernate.boot.models.annotations.spi; /** + * Commonality for annotations that are named within a {@linkplain RepeatableContainer repeatable container}. + * * @author Steve Ebersole */ -public class Listener2 { - @PostLoad - public void wasLoaded(Object entity) {} +public interface Named { + String name(); + + void name(String name); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/Listener1.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/RepeatableContainer.java similarity index 56% rename from hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/Listener1.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/RepeatableContainer.java index 0bf5bca063..d8430c2d44 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/Listener1.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/RepeatableContainer.java @@ -4,14 +4,16 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.orm.test.boot.models.bind.callbacks; -import jakarta.persistence.PostLoad; +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; /** * @author Steve Ebersole */ -public class Listener1 { - @PostLoad - public void wasLoaded(HierarchySuper entity) {} +public interface RepeatableContainer extends Annotation { + R[] value(); + + void value(R[] value); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/UniqueConstraintCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/UniqueConstraintCollector.java new file mode 100644 index 0000000000..cacdcf3c81 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/spi/UniqueConstraintCollector.java @@ -0,0 +1,22 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.annotations.spi; + +import java.lang.annotation.Annotation; + +import jakarta.persistence.UniqueConstraint; + +/** + * Commonality for annotations which define unique-constraints + * + * @author Steve Ebersole + */ +public interface UniqueConstraintCollector extends Annotation { + UniqueConstraint[] uniqueConstraints(); + + void uniqueConstraints(UniqueConstraint[] value); +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/ModelBindingLogging.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/ModelBindingLogging.java deleted file mode 100644 index 4472d50c16..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/ModelBindingLogging.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind; - -import org.hibernate.Internal; - -import org.jboss.logging.BasicLogger; -import org.jboss.logging.Logger; -import org.jboss.logging.annotations.LogMessage; -import org.jboss.logging.annotations.Message; -import org.jboss.logging.annotations.MessageLogger; -import org.jboss.logging.annotations.ValidIdRange; - -import static org.jboss.logging.Logger.Level.INFO; - -/** - * todo : find the proper min/max id range - * - * @author Steve Ebersole - */ -@Internal -@MessageLogger( projectCode = "HHH" ) -@ValidIdRange( min = 999980, max = 999999 ) -public interface ModelBindingLogging extends BasicLogger { - String NAME = "org.hibernate.models.orm"; - - Logger MODEL_BINDING_LOGGER = Logger.getLogger( NAME ); - ModelBindingLogging MODEL_BINDING_MSG_LOGGER = Logger.getMessageLogger( ModelBindingLogging.class, NAME ); - - @LogMessage(level = INFO) - @Message( id = 999980, value = "Entity `%s` used both @DynamicInsert and @SQLInsert" ) - void dynamicAndCustomInsert(String entityName); - - @LogMessage(level = INFO) - @Message( id = 999981, value = "Entity `%s` used both @DynamicUpdate and @SQLUpdate" ) - void dynamicAndCustomUpdate(String entityName); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/AttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/AttributeBinding.java deleted file mode 100644 index 2065537bad..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/AttributeBinding.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; - -import org.hibernate.annotations.Immutable; -import org.hibernate.annotations.Mutability; -import org.hibernate.annotations.NaturalId; -import org.hibernate.annotations.OptimisticLock; -import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor; -import org.hibernate.boot.models.AnnotationPlacementException; -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.Table; -import org.hibernate.mapping.Value; -import org.hibernate.models.ModelsException; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MemberDetails; -import org.hibernate.type.descriptor.java.MutabilityPlan; - -import jakarta.persistence.AttributeConverter; -import jakarta.persistence.Column; -import jakarta.persistence.Convert; - -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.BASIC; -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.EMBEDDED; - -/** - * Binding for an attribute - * - * @author Steve Ebersole - */ -public class AttributeBinding extends Binding { - private final AttributeMetadata attributeMetadata; - - private final Property property; - private final Table attributeTable; - private final Value mappingValue; - - public AttributeBinding( - AttributeMetadata attributeMetadata, - PersistentClass owner, - Table primaryTable, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - super( bindingOptions, bindingState, bindingContext ); - - this.attributeMetadata = attributeMetadata; - this.property = new Property(); - this.property.setName( attributeMetadata.getName() ); - - final Value value; - if ( attributeMetadata.getNature() == BASIC ) { - value = createBasicValue( primaryTable ); - } - else if ( attributeMetadata.getNature() == EMBEDDED ) { - value = createComponentValue( primaryTable, owner ); - } - else { - throw new UnsupportedOperationException( "Not yet implemented" ); - } - - property.setValue( value ); - attributeTable = value.getTable(); - mappingValue = value; - - applyNaturalId( attributeMetadata, property ); - } - - public AttributeBinding( - AttributeMetadata attributeMetadata, - Component owner, - Table primaryTable, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - super( bindingOptions, bindingState, bindingContext ); - throw new UnsupportedOperationException( "Not yet implemented" ); - } - - private BasicValue createBasicValue(Table primaryTable) { - final BasicValue basicValue = new BasicValue( bindingState.getMetadataBuildingContext() ); - - final MemberDetails member = attributeMetadata.getMember(); - BasicValueHelper.bindImplicitJavaType( member, basicValue, bindingOptions, bindingState, bindingContext ); - bindMutability( member, property, basicValue ); - bindOptimisticLocking( member, property, basicValue ); - bindConversion( member, property, basicValue ); - - processColumn( member, property, basicValue, primaryTable, Column.class ); - - BasicValueHelper.bindJavaType( member, basicValue, bindingOptions, bindingState, bindingContext ); - BasicValueHelper.bindJdbcType( member, basicValue, bindingOptions, bindingState, bindingContext ); - BasicValueHelper.bindLob( member, basicValue, bindingOptions, bindingState, bindingContext ); - BasicValueHelper.bindNationalized( - member, - basicValue, - bindingOptions, - bindingState, - bindingContext - ); - BasicValueHelper.bindEnumerated( - member, - basicValue, - bindingOptions, - bindingState, - bindingContext - ); - BasicValueHelper.bindTemporalPrecision( - member, - basicValue, - bindingOptions, - bindingState, - bindingContext - ); - BasicValueHelper.bindTimeZoneStorage( - member, - property, - basicValue, - bindingOptions, - bindingState, - bindingContext - ); - - return basicValue; - } - - private Component createComponentValue(Table primaryTable, PersistentClass persistentClass) { - final Component component = new Component( bindingState.getMetadataBuildingContext(), persistentClass ); - - // 1. embeddable (attributes, etc) - // 2. overrides - final MemberDetails member = attributeMetadata.getMember(); - - return component; - } - - public Property getProperty() { - return property; - } - - public Table getAttributeTable() { - return attributeTable; - } - - public Value getMappingValue() { - return mappingValue; - } - - @Override - public Property getBinding() { - return getProperty(); - } - - private void bindMutability(MemberDetails member, Property property, BasicValue basicValue) { - final var mutabilityAnn = member.getAnnotationUsage( Mutability.class ); - final var immutableAnn = member.getAnnotationUsage( Immutable.class ); - - if ( immutableAnn != null ) { - if ( mutabilityAnn != null ) { - throw new AnnotationPlacementException( - "Illegal combination of @Mutability and @Immutable - " + member.getName() - ); - } - - property.setUpdateable( false ); - } - else if ( mutabilityAnn != null ) { - basicValue.setExplicitMutabilityPlanAccess( (typeConfiguration) -> { - final ClassDetails classDetails = mutabilityAnn.getClassDetails( "value" ); - final Class> javaClass = classDetails.toJavaClass(); - try { - return javaClass.getConstructor().newInstance(); - } - catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - final ModelsException modelsException = new ModelsException( "Error instantiating local @MutabilityPlan - " + member.getName() ); - modelsException.addSuppressed( e ); - throw modelsException; - } - } ); - } - } - - private void bindOptimisticLocking( - MemberDetails member, - Property property, - @SuppressWarnings("unused") BasicValue basicValue) { - final var annotationUsage = member.getAnnotationUsage( OptimisticLock.class ); - if ( annotationUsage != null ) { - if ( annotationUsage.getBoolean( "excluded" ) ) { - property.setOptimisticLocked( false ); - return; - } - } - - property.setOptimisticLocked( true ); - } - - private void bindConversion(MemberDetails member, @SuppressWarnings("unused") Property property, BasicValue basicValue) { - // todo : do we need to account for auto-applied converters here? - final var convertAnn = member.getAnnotationUsage( Convert.class ); - if ( convertAnn == null ) { - return; - } - - if ( convertAnn.getBoolean( "disableConversion" ) ) { - return; - } - - if ( convertAnn.getString( "attributeName" ) != null ) { - throw new ModelsException( "@Convert#attributeName should not be specified on basic mappings - " + member.getName() ); - } - - final ClassDetails converterClassDetails = convertAnn.getClassDetails( "converter" ); - final Class> javaClass = converterClassDetails.toJavaClass(); - basicValue.setJpaAttributeConverterDescriptor( new ClassBasedConverterDescriptor( - javaClass, - bindingContext.getClassmateContext() - ) ); - } - - public void processColumn( - MemberDetails member, - Property property, - BasicValue basicValue, - Table primaryTable, - Class annotation) { - BasicValueHelper.bindColumn( - member, - property::getName, - basicValue, - primaryTable, - bindingOptions, - bindingState, - bindingContext - ); - } - - private void applyNaturalId(AttributeMetadata attributeMetadata, Property property) { - final var naturalIdAnn = attributeMetadata.getMember().getAnnotationUsage( NaturalId.class ); - if ( naturalIdAnn == null ) { - return; - } - property.setNaturalIdentifier( true ); - property.setUpdateable( naturalIdAnn.getBoolean( "mutable" ) ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BasicValueHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BasicValueHelper.java deleted file mode 100644 index 9aef5d4bca..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BasicValueHelper.java +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; -import java.util.function.Supplier; - -import org.hibernate.MappingException; -import org.hibernate.annotations.JavaType; -import org.hibernate.annotations.JdbcType; -import org.hibernate.annotations.JdbcTypeCode; -import org.hibernate.annotations.Nationalized; -import org.hibernate.annotations.TimeZoneColumn; -import org.hibernate.annotations.TimeZoneStorage; -import org.hibernate.annotations.TimeZoneStorageType; -import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor; -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.AnnotationPlacementException; -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.bind.spi.TableReference; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.spi.InFlightMetadataCollector; -import org.hibernate.engine.spi.FilterDefinition; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.RootClass; -import org.hibernate.mapping.Table; -import org.hibernate.models.ModelsException; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MemberDetails; -import org.hibernate.type.BasicType; -import org.hibernate.type.descriptor.java.BasicJavaType; -import org.hibernate.type.spi.TypeConfiguration; - -import jakarta.persistence.AttributeConverter; -import jakarta.persistence.Column; -import jakarta.persistence.Convert; -import jakarta.persistence.Enumerated; -import jakarta.persistence.Lob; -import jakarta.persistence.Temporal; -import jakarta.persistence.TemporalType; - -import static java.util.Collections.singletonMap; -import static org.hibernate.annotations.TimeZoneStorageType.COLUMN; - -/** - * @author Steve Ebersole - */ -public class BasicValueHelper { - - public static final String TENANT_FILTER_NAME = "_tenantId"; - public static final String TENANT_PARAMETER_NAME = "tenantId"; - - public static void bindImplicitJavaType( - MemberDetails member, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - basicValue.setImplicitJavaTypeAccess( (typeConfiguration) -> member.getType().determineRawClass().toJavaClass() ); - } - - public static void bindJavaType( - MemberDetails member, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - // todo : do we need to account for JavaTypeRegistration here? - final var javaTypeAnn = member.getAnnotationUsage( JavaType.class ); - if ( javaTypeAnn == null ) { - return; - } - - basicValue.setExplicitJavaTypeAccess( (typeConfiguration) -> { - final var classDetails = javaTypeAnn.getClassDetails( "value" ); - final Class> javaClass = classDetails.toJavaClass(); - try { - return javaClass.getConstructor().newInstance(); - } - catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - final ModelsException modelsException = new ModelsException( "Error instantiating local @JavaType - " + member.getName() ); - modelsException.addSuppressed( e ); - throw modelsException; - } - } ); - } - - public static void bindJdbcType( - MemberDetails member, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - // todo : do we need to account for JdbcTypeRegistration here? - final var jdbcTypeAnn = member.getAnnotationUsage( JdbcType.class ); - final var jdbcTypeCodeAnn = member.getAnnotationUsage( JdbcTypeCode.class ); - - if ( jdbcTypeAnn != null ) { - if ( jdbcTypeCodeAnn != null ) { - throw new AnnotationPlacementException( - "Illegal combination of @JdbcType and @JdbcTypeCode - " + member.getName() - ); - } - - basicValue.setExplicitJdbcTypeAccess( (typeConfiguration) -> { - final var classDetails = jdbcTypeAnn.getClassDetails( "value" ); - final Class javaClass = classDetails.toJavaClass(); - try { - return javaClass.getConstructor().newInstance(); - } - catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - final ModelsException modelsException = new ModelsException( "Error instantiating local @JdbcType - " + member.getName() ); - modelsException.addSuppressed( e ); - throw modelsException; - } - } ); - } - else if ( jdbcTypeCodeAnn != null ) { - final Integer typeCode = jdbcTypeCodeAnn.getInteger( "value" ); - basicValue.setExplicitJdbcTypeCode( typeCode ); - } - } - - public static void bindNationalized( - MemberDetails member, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - if ( member.getAnnotationUsage( Nationalized.class ) != null ) { - basicValue.makeNationalized(); - } - } - - public static void bindLob( - MemberDetails member, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - if ( member.getAnnotationUsage( Lob.class ) != null ) { - basicValue.makeLob(); - } - } - - public static void bindEnumerated( - MemberDetails member, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - final AnnotationUsage enumerated = member.getAnnotationUsage( Enumerated.class ); - if ( enumerated == null ) { - return; - } - - basicValue.setEnumerationStyle( enumerated.getEnum( "value" ) ); - } - - public static void bindTemporalPrecision( - MemberDetails member, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - final AnnotationUsage temporalAnn = member.getAnnotationUsage( Temporal.class ); - if ( temporalAnn == null ) { - return; - } - - //noinspection deprecation - final TemporalType precision = temporalAnn.getEnum( "value" ); - basicValue.setTemporalPrecision( precision ); - } - - public static void bindTimeZoneStorage( - MemberDetails member, - Property property, - BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - final AnnotationUsage storageAnn = member.getAnnotationUsage( TimeZoneStorage.class ); - final AnnotationUsage columnAnn = member.getAnnotationUsage( TimeZoneColumn.class ); - if ( storageAnn != null ) { - final TimeZoneStorageType strategy = storageAnn.getEnum( "value" ); - if ( strategy != COLUMN && columnAnn != null ) { - throw new AnnotationPlacementException( - "Illegal combination of @TimeZoneStorage(" + strategy.name() + ") and @TimeZoneColumn" - ); - } - basicValue.setTimeZoneStorageType( strategy ); - } - - if ( columnAnn != null ) { - final org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) basicValue.getColumn(); - final String name = columnAnn.getString( "name" ); - if ( StringHelper.isEmpty( name ) ) { - column.setName( property.getName() + "_tz" ); - } - else { - column.setName( name ); - } - column.setSqlType( columnAnn.getString( "columnDefinition" ) ); - - final var tableName = columnAnn.getString( "table" ); - TableReference tableByName = null; - if ( tableName != null ) { - final Identifier identifier = Identifier.toIdentifier( tableName ); - tableByName = bindingState.getTableByName( identifier.getCanonicalName() ); - basicValue.setTable( tableByName.table() ); - } - - property.setInsertable( columnAnn.getBoolean( "insertable" ) ); - property.setUpdateable( columnAnn.getBoolean( "updatable" ) ); - } - } - - public static void bindConversion( - MemberDetails member, - @SuppressWarnings("unused") BasicValue basicValue, - @SuppressWarnings("unused") BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - // todo : do we need to account for auto-applied converters here? - final var convertAnn = member.getAnnotationUsage( Convert.class ); - if ( convertAnn == null ) { - return; - } - - if ( convertAnn.getBoolean( "disableConversion" ) ) { - return; - } - - if ( convertAnn.getString( "attributeName" ) != null ) { - throw new ModelsException( "@Convert#attributeName should not be specified on basic mappings - " + member.getName() ); - } - - final ClassDetails converterClassDetails = convertAnn.getClassDetails( "converter" ); - final Class> javaClass = converterClassDetails.toJavaClass(); - basicValue.setJpaAttributeConverterDescriptor( new ClassBasedConverterDescriptor( - javaClass, - bindingContext.getClassmateContext() - ) ); - } - - public static org.hibernate.mapping.Column bindColumn( - MemberDetails member, - Supplier defaultNameSupplier, - BasicValue basicValue, - Table primaryTable, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - return bindColumn( - member, - Column.class, - defaultNameSupplier, - basicValue, - primaryTable, - bindingOptions, - bindingState, - bindingContext - ); - } - - public static org.hibernate.mapping.Column bindColumn( - MemberDetails member, - Class annotationType, - Supplier defaultNameSupplier, - BasicValue basicValue, - Table primaryTable, - @SuppressWarnings("unused") BindingOptions bindingOptions, - BindingState bindingState, - @SuppressWarnings("unused") BindingContext bindingContext) { - final var columnAnn = member.getAnnotationUsage( annotationType ); - final var column = ColumnHelper.bindColumn( columnAnn, defaultNameSupplier ); - - var tableName = BindingHelper.getValue( columnAnn, "table", "" ); - if ( StringHelper.isEmpty( tableName ) ) { - basicValue.setTable( primaryTable ); - } - else { - final Identifier identifier = Identifier.toIdentifier( tableName ); - final TableReference tableByName = bindingState.getTableByName( identifier.getCanonicalName() ); - basicValue.setTable( tableByName.table() ); - } - - basicValue.addColumn( column ); - - return column; - } - - public static void bindTenantId( - EntityTypeMetadata managedType, - RootClass rootClass, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final AttributeMetadata tenantIdAttribute = managedType.getHierarchy().getTenantIdAttribute(); - if ( tenantIdAttribute == null ) { - return; - } - - final InFlightMetadataCollector collector = bindingState.getMetadataBuildingContext().getMetadataCollector(); - final TypeConfiguration typeConfiguration = collector.getTypeConfiguration(); - - final MemberDetails memberDetails = tenantIdAttribute.getMember(); - final String returnedClassName = memberDetails.getType().determineRawClass().getClassName(); - final BasicType tenantIdType = typeConfiguration - .getBasicTypeRegistry() - .getRegisteredType( returnedClassName ); - - final FilterDefinition filterDefinition = collector.getFilterDefinition( TENANT_FILTER_NAME ); - if ( filterDefinition == null ) { - collector.addFilterDefinition( new FilterDefinition( - TENANT_FILTER_NAME, - "", - singletonMap( TENANT_PARAMETER_NAME, tenantIdType ) - ) ); - } - else { - final org.hibernate.type.descriptor.java.JavaType tenantIdTypeJtd = tenantIdType.getJavaTypeDescriptor(); - final org.hibernate.type.descriptor.java.JavaType parameterJtd = filterDefinition - .getParameterJdbcMapping( TENANT_PARAMETER_NAME ) - .getJavaTypeDescriptor(); - if ( !parameterJtd.getJavaTypeClass().equals( tenantIdTypeJtd.getJavaTypeClass() ) ) { - throw new MappingException( - "all @TenantId fields must have the same type: " - + parameterJtd.getJavaType().getTypeName() - + " differs from " - + tenantIdTypeJtd.getJavaType().getTypeName() - ); - } - } - - final Property property = new Property(); - rootClass.addProperty( property ); - property.setName( tenantIdAttribute.getName() ); - - final BasicValue basicValue = new BasicValue( bindingState.getMetadataBuildingContext(), rootClass.getRootTable() ); - property.setValue( basicValue ); - - bindImplicitJavaType( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - bindJavaType( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - bindJdbcType( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - - bindConversion( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - bindEnumerated( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - - BasicValueHelper.bindColumn( - memberDetails, - property::getName, - basicValue, - rootClass.getRootTable(), - bindingOptions, - bindingState, - bindingContext - ); - - property.resetUpdateable( false ); - property.resetOptional( false ); - } - - public static void bindVersion( - EntityTypeMetadata typeMetadata, - RootClass rootClass, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final AttributeMetadata versionAttribute = typeMetadata.getHierarchy().getVersionAttribute(); - if ( versionAttribute == null ) { - return; - } - - final Property property = new Property(); - property.setName( versionAttribute.getName() ); - rootClass.setVersion( property ); - rootClass.addProperty( property ); - - final BasicValue basicValue = new BasicValue( - bindingState.getMetadataBuildingContext(), - rootClass.getRootTable() - ); - property.setValue( basicValue ); - - final MemberDetails memberDetails = versionAttribute.getMember(); - bindImplicitJavaType( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - bindJavaType( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - bindJdbcType( memberDetails, basicValue, bindingOptions, bindingState, bindingContext ); - - final org.hibernate.mapping.Column column = bindColumn( - memberDetails, - property::getName, - basicValue, - rootClass.getRootTable(), - bindingOptions, - bindingState, - bindingContext - ); - // force it to be non-nullable - column.setNullable( false ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/Binding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/Binding.java deleted file mode 100644 index af11722322..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/Binding.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; - -/** - * @author Steve Ebersole - */ -public abstract class Binding { - protected final BindingState bindingState; - protected final BindingOptions bindingOptions; - protected final BindingContext bindingContext; - - public Binding(BindingOptions bindingOptions, BindingState bindingState, BindingContext bindingContext) { - this.bindingOptions = bindingOptions; - this.bindingState = bindingState; - this.bindingContext = bindingContext; - } - - public abstract Object getBinding(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingContextImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingContextImpl.java deleted file mode 100644 index ede60cfb14..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingContextImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.internal.ClassmateContext; -import org.hibernate.boot.model.naming.ImplicitNamingStrategy; -import org.hibernate.boot.model.naming.PhysicalNamingStrategy; -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.boot.spi.BootstrapContext; -import org.hibernate.models.spi.AnnotationDescriptorRegistry; -import org.hibernate.models.spi.ClassDetailsRegistry; - -import jakarta.persistence.SharedCacheMode; - -/** - * @author Steve Ebersole - */ -public class BindingContextImpl implements BindingContext { - private final ClassDetailsRegistry classDetailsRegistry; - private final AnnotationDescriptorRegistry annotationDescriptorRegistry; - private final GlobalRegistrations globalRegistrations; - - private final ImplicitNamingStrategy implicitNamingStrategy; - private final PhysicalNamingStrategy physicalNamingStrategy; - private final SharedCacheMode sharedCacheMode; - private final ClassmateContext classmateContext; - private final BootstrapContext bootstrapContext; - - public BindingContextImpl(CategorizedDomainModel categorizedDomainModel, BootstrapContext bootstrapContext) { - this( - categorizedDomainModel.getClassDetailsRegistry(), - categorizedDomainModel.getAnnotationDescriptorRegistry(), - categorizedDomainModel.getGlobalRegistrations(), - bootstrapContext.getMetadataBuildingOptions().getImplicitNamingStrategy(), - bootstrapContext.getMetadataBuildingOptions().getPhysicalNamingStrategy(), - bootstrapContext.getMetadataBuildingOptions().getSharedCacheMode(), - bootstrapContext.getClassmateContext(), - bootstrapContext - ); - } - - public BindingContextImpl( - ClassDetailsRegistry classDetailsRegistry, - AnnotationDescriptorRegistry annotationDescriptorRegistry, - GlobalRegistrations globalRegistrations, - ImplicitNamingStrategy implicitNamingStrategy, - PhysicalNamingStrategy physicalNamingStrategy, - SharedCacheMode sharedCacheMode, - ClassmateContext classmateContext, - BootstrapContext bootstrapContext) { - this.classDetailsRegistry = classDetailsRegistry; - this.annotationDescriptorRegistry = annotationDescriptorRegistry; - this.implicitNamingStrategy = implicitNamingStrategy; - this.physicalNamingStrategy = physicalNamingStrategy; - this.bootstrapContext = bootstrapContext; - this.globalRegistrations = globalRegistrations; - this.classmateContext = classmateContext; - this.sharedCacheMode = sharedCacheMode; - } - - @Override - public ClassDetailsRegistry getClassDetailsRegistry() { - return classDetailsRegistry; - } - - @Override - public AnnotationDescriptorRegistry getAnnotationDescriptorRegistry() { - return annotationDescriptorRegistry; - } - - @Override - public BootstrapContext getBootstrapContext() { - return bootstrapContext; - } - - @Override - public GlobalRegistrations getGlobalRegistrations() { - return globalRegistrations; - } - - @Override - public ClassmateContext getClassmateContext() { - return classmateContext; - } - - @Override - public SharedCacheMode getSharedCacheMode() { - return sharedCacheMode; - } - - @Override - public ImplicitNamingStrategy getImplicitNamingStrategy() { - return implicitNamingStrategy; - } - - @Override - public PhysicalNamingStrategy getPhysicalNamingStrategy() { - return physicalNamingStrategy; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingHelper.java deleted file mode 100644 index eccb79ac50..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingHelper.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.lang.annotation.Annotation; -import java.util.function.Supplier; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.model.naming.ObjectNameNormalizer; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.bind.spi.QuotedIdentifierTarget; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.models.spi.AnnotationDescriptor; -import org.hibernate.models.spi.AnnotationUsage; - -/** - * @author Steve Ebersole - */ -public class BindingHelper { - /** - * Applies global quoting to the passed name, returning the {@linkplain Identifier} form - */ - public static Identifier toIdentifier( - String name, - QuotedIdentifierTarget target, - BindingOptions options, - JdbcEnvironment jdbcEnvironment) { - final boolean globallyQuoted = options.getGloballyQuotedIdentifierTargets().contains( target ); - return jdbcEnvironment.getIdentifierHelper().toIdentifier( name, globallyQuoted ); - } - - /** - * Get a named attribute value from the annotation usage. - * The default value is used if the passed annotation usage is null. - */ - public static T getValue(AnnotationUsage ann, String attributeName, T defaultValue) { - if ( ann == null ) { - return defaultValue; - } - - return ann.getAttributeValue( attributeName ); - } - - /** - * Get a named attribute value from the annotation usage. - * The attribute's default value is used if the passed annotation usage is null. - */ - public static T getValue(AnnotationUsage ann, String attributeName, AnnotationDescriptor descriptor) { - if ( ann == null ) { - //noinspection unchecked - return (T) descriptor.getAttribute( attributeName ).getAttributeMethod().getDefaultValue(); - } - - return ann.getAttributeValue( attributeName ); - } - - /** - * Get a named attribute value from the annotation usage. - * The value from the supplier is used if the passed annotation usage is null. - */ - public static T getValue(AnnotationUsage ann, String attributeName, Supplier defaultValueSupplier) { - if ( ann == null ) { - return defaultValueSupplier.get(); - } - - return ann.getAttributeValue( attributeName ); - } - - public static String getGloballyQuotedValue( - AnnotationUsage ann, - String attributeName, - Supplier defaultValueSupplier, - BindingOptions bindingOptions, - BindingState bindingState) { - final String value = getValue( ann, attributeName, defaultValueSupplier ); - return applyGlobalQuoting( value, QuotedIdentifierTarget.COLUMN_DEFINITION, bindingOptions, bindingState ); - } - - public static String applyGlobalQuoting( - String text, - QuotedIdentifierTarget target, - BindingOptions options, - BindingState bindingState) { - final boolean globallyQuoted = options.getGloballyQuotedIdentifierTargets().contains( target ); - if ( !globallyQuoted ) { - return text; - } - final ObjectNameNormalizer objectNameNormalizer = bindingState - .getMetadataBuildingContext() - .getObjectNameNormalizer(); - return objectNameNormalizer.applyGlobalQuoting( text ); - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingOptionsImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingOptionsImpl.java deleted file mode 100644 index bdd56e1394..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingOptionsImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.lang.annotation.Annotation; -import java.util.EnumSet; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.QuotedIdentifierTarget; -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.engine.config.spi.ConfigurationService; -import org.hibernate.engine.config.spi.StandardConverters; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; - -/** - * @author Steve Ebersole - */ -public class BindingOptionsImpl implements BindingOptions { - private final Identifier defaultCatalogName; - private final Identifier defaultSchemaName; - private final EnumSet globallyQuotedIdentifierTargets; - - public BindingOptionsImpl(MetadataBuildingContext metadataBuildingContext) { - final boolean globallyQuote = metadataBuildingContext.getEffectiveDefaults().isDefaultQuoteIdentifiers(); - final boolean skipColumnDefinitions = metadataBuildingContext - .getBootstrapContext() - .getServiceRegistry() - .getService( ConfigurationService.class ) - .getSetting( - AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS_SKIP_COLUMN_DEFINITIONS, - StandardConverters.BOOLEAN, - false - ); - - if ( !globallyQuote ) { - globallyQuotedIdentifierTargets = EnumSet.noneOf( QuotedIdentifierTarget.class ); - } - else { - globallyQuotedIdentifierTargets = EnumSet.allOf( QuotedIdentifierTarget.class ); - if ( skipColumnDefinitions ) { - globallyQuotedIdentifierTargets.remove( QuotedIdentifierTarget.COLUMN_DEFINITION ); - } - } - - final JdbcEnvironment jdbcEnvironment = metadataBuildingContext.getMetadataCollector() - .getDatabase() - .getJdbcEnvironment(); - - defaultCatalogName = toIdentifier( - metadataBuildingContext.getEffectiveDefaults().getDefaultCatalogName(), - QuotedIdentifierTarget.CATALOG_NAME, - globallyQuotedIdentifierTargets, - jdbcEnvironment - ); - defaultSchemaName = toIdentifier( - metadataBuildingContext.getEffectiveDefaults().getDefaultSchemaName(), - QuotedIdentifierTarget.SCHEMA_NAME, - globallyQuotedIdentifierTargets, - jdbcEnvironment - ); - } - - public static Identifier toIdentifier( - String name, - QuotedIdentifierTarget target, - EnumSet globallyQuotedIdentifierTargets, - JdbcEnvironment jdbcEnvironment) { - final boolean globallyQuoted = globallyQuotedIdentifierTargets.contains( target ); - return jdbcEnvironment.getIdentifierHelper().toIdentifier( name, globallyQuoted ); - } - - public BindingOptionsImpl(Identifier defaultCatalogName, Identifier defaultSchemaName) { - this( defaultCatalogName, defaultSchemaName, EnumSet.noneOf( QuotedIdentifierTarget.class ) ); - } - - public BindingOptionsImpl( - Identifier defaultCatalogName, - Identifier defaultSchemaName, - EnumSet globallyQuotedIdentifierTargets) { - this.defaultCatalogName = defaultCatalogName; - this.defaultSchemaName = defaultSchemaName; - this.globallyQuotedIdentifierTargets = globallyQuotedIdentifierTargets; - } - - @Override - public Identifier getDefaultCatalogName() { - return defaultCatalogName; - } - - @Override - public Identifier getDefaultSchemaName() { - return defaultSchemaName; - } - - @Override - public EnumSet getGloballyQuotedIdentifierTargets() { - return globallyQuotedIdentifierTargets; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingStateImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingStateImpl.java deleted file mode 100644 index b24302fbe8..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/BindingStateImpl.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.BiConsumer; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.model.relational.Database; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.bind.spi.TableReference; -import org.hibernate.boot.models.categorize.spi.FilterDefRegistration; -import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; -import org.hibernate.boot.models.categorize.spi.ManagedTypeMetadata; -import org.hibernate.boot.models.categorize.spi.TableOwner; -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.engine.jdbc.spi.JdbcServices; -import org.hibernate.internal.util.KeyedConsumer; -import org.hibernate.models.spi.ClassDetails; - -/** - * @author Steve Ebersole - */ -public class BindingStateImpl implements BindingState { - private final MetadataBuildingContext metadataBuildingContext; - - private final Database database; - private final JdbcServices jdbcServices; - - private final Map tableMap = new HashMap<>(); - private final Map tableByOwnerMap = new HashMap<>(); - - private final Map typeBindings = new HashMap<>(); - private final Map typeBindersBySuper = new HashMap<>(); - - public BindingStateImpl(MetadataBuildingContext metadataBuildingContext) { - this.metadataBuildingContext = metadataBuildingContext; - this.database = metadataBuildingContext.getMetadataCollector().getDatabase(); - this.jdbcServices = metadataBuildingContext.getBootstrapContext().getServiceRegistry().getService( JdbcServices.class ); - } - - @Override - public MetadataBuildingContext getMetadataBuildingContext() { - return metadataBuildingContext; - } - - @Override - public Database getDatabase() { - return database; - } - - @Override - public JdbcServices getJdbcServices() { - return jdbcServices; - } - - @Override - public int getTableCount() { - return tableMap.size(); - } - - @Override - public void forEachTable(KeyedConsumer consumer) { - //noinspection unchecked - tableMap.forEach( (BiConsumer) consumer ); - } - - @Override - public T getTableByName(String name) { - //noinspection unchecked - return (T) tableMap.get( name ); - } - - @Override - public T getTableByOwner(TableOwner owner) { - //noinspection unchecked - return (T) tableByOwnerMap.get( owner ); - } - - @Override - public void addTable(TableOwner owner, TableReference table) { - tableMap.put( table.logicalName().getCanonicalName(), table ); - tableByOwnerMap.put( owner, table ); - } - - @Override - public void addSecondaryTable(SecondaryTable table) { - tableMap.put( table.logicalName().getCanonicalName(), table ); - } - - private String resolveSchemaName(Identifier explicit) { - if ( explicit != null ) { - return explicit.getCanonicalName(); - } - - var defaultNamespace = metadataBuildingContext.getMetadataCollector() - .getDatabase() - .getDefaultNamespace(); - if ( defaultNamespace != null ) { - final Identifier defaultSchemaName = defaultNamespace.getName().getSchema(); - if ( defaultSchemaName != null ) { - return defaultSchemaName.getCanonicalName(); - } - } - return null; - } - - private String resolveCatalogName(Identifier explicit) { - if ( explicit != null ) { - return explicit.getCanonicalName(); - } - - var defaultNamespace = metadataBuildingContext.getMetadataCollector() - .getDatabase() - .getDefaultNamespace(); - if ( defaultNamespace != null ) { - final Identifier defaultCatalogName = defaultNamespace.getName().getCatalog(); - if ( defaultCatalogName != null ) { - return defaultCatalogName.getCanonicalName(); - } - } - return null; - - } - - @Override - public void registerTypeBinding(ManagedTypeMetadata type, ManagedTypeBinding binding) { - typeBindings.put( type.getClassDetails(), binding ); - - if ( type instanceof IdentifiableTypeMetadata identifiableType ) { - if ( identifiableType.getSuperType() != null ) { - typeBindersBySuper.put( - identifiableType.getSuperType().getClassDetails(), - (IdentifiableTypeBinding) binding - ); - } - } - - if ( binding instanceof EntityBinding entityTypeBinding ) { - metadataBuildingContext.getMetadataCollector().addEntityBinding( entityTypeBinding.getPersistentClass() ); - } - else if ( binding instanceof MappedSuperclassBinding mappedSuperBinding ) { - metadataBuildingContext.getMetadataCollector().addMappedSuperclass( - mappedSuperBinding.typeMetadata.getClassDetails().toJavaClass(), - mappedSuperBinding.getMappedSuperclass() - ); - } - } - - @Override - public ManagedTypeBinding getTypeBinding(ClassDetails type) { - return typeBindings.get( type ); - } - - @Override - public IdentifiableTypeBinding getSuperTypeBinding(ClassDetails type) { - return typeBindersBySuper.get( type ); - } - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Filter def - - @Override - public void apply(FilterDefRegistration registration) { - metadataBuildingContext.getMetadataCollector().addFilterDefinition( registration.toFilterDefinition( metadataBuildingContext ) ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ColumnHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ColumnHelper.java deleted file mode 100644 index 1cf46aa6fe..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ColumnHelper.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.function.Supplier; - -import org.hibernate.annotations.DiscriminatorFormula; -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Formula; -import org.hibernate.models.spi.AnnotationDescriptor; -import org.hibernate.models.spi.AnnotationUsage; - -import jakarta.persistence.DiscriminatorColumn; -import jakarta.persistence.DiscriminatorType; - -import static org.hibernate.internal.util.NullnessHelper.nullif; - -/** - * @author Steve Ebersole - */ -public class ColumnHelper { - public static Column bindColumn( - AnnotationUsage annotationUsage, - Supplier defaultNameSupplier) { - return bindColumn( - annotationUsage, - defaultNameSupplier, - false, - true, - 255, - 0, - 0, - -1 - ); - } - - public static Column bindColumn( - AnnotationUsage annotationUsage, - Supplier defaultNameSupplier, - boolean uniqueByDefault, - boolean nullableByDefault) { - return bindColumn( - annotationUsage, - defaultNameSupplier, - uniqueByDefault, - nullableByDefault, - 255, - 0, - 0, - -1 - ); - } - - public static Column bindColumn( - AnnotationUsage annotationUsage, - Supplier defaultNameSupplier, - boolean uniqueByDefault, - boolean nullableByDefault, - int lengthByDefault, - int precisionByDefault, - int scaleByDefault, - int secondPrecisionByDefault) { - final Column result = new Column(); - result.setName( columnName( annotationUsage, defaultNameSupplier ) ); - - result.setUnique( BindingHelper.getValue( annotationUsage, "unique", uniqueByDefault ) ); - result.setNullable( BindingHelper.getValue( annotationUsage, "nullable", nullableByDefault ) ); - result.setSqlType( BindingHelper.getValue( annotationUsage, "columnDefinition", (String) null ) ); - result.setLength( BindingHelper.getValue( annotationUsage, "length", lengthByDefault ) ); - result.setPrecision( BindingHelper.getValue( annotationUsage, "precision", precisionByDefault ) ); - result.setPrecision( BindingHelper.getValue( annotationUsage, "secondPrecision", secondPrecisionByDefault ) ); - result.setScale( BindingHelper.getValue( annotationUsage, "scale", scaleByDefault ) ); - return result; - } - - - public static String columnName( - AnnotationUsage columnAnnotation, - Supplier defaultNameSupplier) { - if ( columnAnnotation == null ) { - return defaultNameSupplier.get(); - } - - return nullif( columnAnnotation.getAttributeValue( "name" ), defaultNameSupplier ); - } - - private ColumnHelper() { - } - - public static DiscriminatorType bindDiscriminatorColumn( - BindingContext bindingContext, - AnnotationUsage formulaAnn, - BasicValue value, - AnnotationUsage columnAnn, - BindingOptions bindingOptions, - BindingState bindingState) { - final DiscriminatorType discriminatorType; - if ( formulaAnn != null ) { - final Formula formula = new Formula( formulaAnn.getString( "value" ) ); - value.addFormula( formula ); - - discriminatorType = formulaAnn.getEnum( "discriminatorType" ); - } - else { - final Column column = new Column(); - value.addColumn( column, true, false ); - discriminatorType = BindingHelper.getValue( columnAnn, "discriminatorType", DiscriminatorType.STRING ); - - column.setName( columnName( columnAnn, () -> "dtype" ) ); - column.setLength( (Integer) BindingHelper.getValue( - columnAnn, - "length", - () -> { - final AnnotationDescriptor descriptor; - if ( columnAnn != null ) { - descriptor = columnAnn.getAnnotationDescriptor(); - } - else { - descriptor = bindingContext.getAnnotationDescriptorRegistry().getDescriptor( DiscriminatorColumn.class ); - } - return descriptor.getAttribute( "length" ).getAttributeMethod().getDefaultValue(); - } - ) ); - column.setSqlType( BindingHelper.getGloballyQuotedValue( - columnAnn, - "columnDefinition", - () -> { - final AnnotationDescriptor descriptor; - if ( columnAnn != null ) { - descriptor = columnAnn.getAnnotationDescriptor(); - } - else { - descriptor = bindingContext.getAnnotationDescriptorRegistry().getDescriptor( DiscriminatorColumn.class ); - } - return (String) descriptor.getAttribute( "columnDefinition" ).getAttributeMethod().getDefaultValue(); - }, - bindingOptions, - bindingState - ) ); - applyOptions( column, columnAnn ); - } - return discriminatorType; - } - - private static void applyOptions(Column column, AnnotationUsage columnAnn) { - if ( columnAnn != null ) { - final String options = columnAnn.getString( "options" ); - if ( StringHelper.isNotEmpty( options ) ) { - // todo : see https://hibernate.atlassian.net/browse/HHH-17449 -// table.setOptions( options ); - throw new UnsupportedOperationException( "Not yet implemented" ); - } - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/EntityBinding.java deleted file mode 100644 index f68e38b3f7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/EntityBinding.java +++ /dev/null @@ -1,578 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.hibernate.annotations.BatchSize; -import org.hibernate.annotations.DynamicInsert; -import org.hibernate.annotations.DynamicUpdate; -import org.hibernate.annotations.Filter; -import org.hibernate.annotations.ResultCheckStyle; -import org.hibernate.annotations.SQLDelete; -import org.hibernate.annotations.SQLInsert; -import org.hibernate.annotations.SQLUpdate; -import org.hibernate.annotations.Synchronize; -import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; -import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle; -import org.hibernate.boot.models.categorize.spi.MappedSuperclassTypeMetadata; -import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jpa.event.internal.EntityCallback; -import org.hibernate.jpa.event.internal.ListenerCallback; -import org.hibernate.jpa.event.spi.CallbackDefinition; -import org.hibernate.jpa.event.spi.CallbackType; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Table; -import org.hibernate.models.ModelsException; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MethodDetails; - -import jakarta.persistence.Cacheable; -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import jakarta.persistence.SharedCacheMode; - -import static org.hibernate.boot.models.bind.ModelBindingLogging.MODEL_BINDING_MSG_LOGGER; - -/** - * @author Steve Ebersole - */ -public abstract class EntityBinding extends IdentifiableTypeBinding { - - public EntityBinding( - EntityTypeMetadata entityTypeMetadata, - IdentifiableTypeBinding superTypeBinding, - EntityHierarchy.HierarchyRelation hierarchyRelation, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - super( entityTypeMetadata, superTypeBinding, hierarchyRelation, bindingOptions, bindingState, bindingContext ); - } - - public abstract PersistentClass getPersistentClass(); - - @Override - public EntityTypeMetadata getTypeMetadata() { - return (EntityTypeMetadata) super.getTypeMetadata(); - } - - protected static void applyNaming(EntityTypeMetadata source, PersistentClass persistentClass, BindingState bindingState) { - final ClassDetails classDetails = source.getClassDetails(); - final AnnotationUsage entityAnn = classDetails.getAnnotationUsage( Entity.class ); - final String jpaEntityName = BindingHelper.getValue( entityAnn, "name", (String) null ); - final String entityName; - final String importName; - - if ( classDetails.getName() != null - && !classDetails.getName().equals( classDetails.getClassName() ) ) { - // should indicate a dynamic model - entityName = classDetails.getName(); - } - else { - entityName = classDetails.getClassName(); - } - - if ( StringHelper.isNotEmpty( jpaEntityName ) ) { - importName = jpaEntityName; - } - else { - importName = StringHelper.unqualifyEntityName( entityName ); - } - - persistentClass.setClassName( classDetails.getClassName() ); - persistentClass.setEntityName( entityName ); - persistentClass.setJpaEntityName( importName ); - - bindingState.getMetadataBuildingContext().getMetadataCollector().addImport( importName, entityName ); - } - - protected static void applyCommonInformation(EntityTypeMetadata typeMetadata, PersistentClass persistentClass, BindingState bindingState) { - applyCaching( typeMetadata, persistentClass, bindingState ); - applyFilters( typeMetadata, persistentClass ); - applyJpaEventListeners( typeMetadata, persistentClass ); - applyBatchSize( typeMetadata, persistentClass, bindingState ); - applySqlCustomizations( typeMetadata, persistentClass, bindingState ); - applySynchronizedTableNames( typeMetadata, persistentClass, bindingState ); - } - - /** - * @apiNote Not part of {@linkplain #applyCommonInformation} to allow the difference that we - * do not always want this for the root entity - */ - protected static void applyDiscriminatorValue( - EntityTypeMetadata typeMetadata, - PersistentClass persistentClass) { - final BasicValue discriminatorMapping = (BasicValue) persistentClass.getRootClass().getDiscriminator(); - if ( discriminatorMapping == null ) { - return; - } - - final AnnotationUsage ann = typeMetadata.getClassDetails().getAnnotationUsage( DiscriminatorValue.class ); - if ( ann == null ) { - final Type resolvedJavaType = discriminatorMapping.resolve().getRelationalJavaType().getJavaType(); - if ( resolvedJavaType == String.class ) { - persistentClass.setDiscriminatorValue( persistentClass.getEntityName() ); - } - else { - persistentClass.setDiscriminatorValue( Integer.toString( persistentClass.getSubclassId() ) ); - } - } - else { - persistentClass.setDiscriminatorValue( ann.getString( "value" ) ); - } - } - - protected static void applyCaching(EntityTypeMetadata source, PersistentClass persistentClass, BindingState bindingState) { - final ClassDetails classDetails = source.getClassDetails(); - final var cacheableAnn = classDetails.getAnnotationUsage( Cacheable.class ); - if ( cacheableAnn == null ) { - return; - } - - final SharedCacheMode sharedCacheMode = bindingState.getMetadataBuildingContext() - .getBuildingOptions() - .getSharedCacheMode(); - - persistentClass.setCached( isCacheable( sharedCacheMode, cacheableAnn ) ); - } - - private static boolean isCacheable(SharedCacheMode sharedCacheMode, AnnotationUsage explicitCacheableAnn) { - return switch ( sharedCacheMode ) { - // all entities should be cached - case ALL -> true; - // Hibernate defaults to ENABLE_SELECTIVE, the only sensible setting - // only entities with @Cacheable(true) should be cached - case ENABLE_SELECTIVE, UNSPECIFIED -> explicitCacheableAnn != null && explicitCacheableAnn.getBoolean( "value" ); - // only entities with @Cacheable(false) should not be cached - case DISABLE_SELECTIVE -> explicitCacheableAnn == null || explicitCacheableAnn.getBoolean( "value" ); - // treat both NONE and UNSPECIFIED the same - default -> false; - }; - } - - protected static void applyFilters(EntityTypeMetadata source, PersistentClass persistentClass) { - final ClassDetails classDetails = source.getClassDetails(); - final List> filters = classDetails.getRepeatedAnnotationUsages( Filter.class ); - if ( CollectionHelper.isEmpty( filters ) ) { - return; - } - - filters.forEach( (filter) -> { - persistentClass.addFilter( - filter.getString( "name" ), - filter.getString( "condition" ), - filter.getAttributeValue( "deduceAliasInjectionPoints" ), - extractFilterAliasTableMap( filter ), - extractFilterAliasEntityMap( filter ) - ); - } ); - } - - private static Map extractFilterAliasTableMap(AnnotationUsage filter) { - // todo : implement - return null; - } - - private static Map extractFilterAliasEntityMap(AnnotationUsage filter) { - // todo : implement - return null; - } - - protected static void applyJpaEventListeners(EntityTypeMetadata typeMetadata, PersistentClass persistentClass) { - final List listeners = typeMetadata.getCompleteJpaEventListeners(); - if ( CollectionHelper.isEmpty( listeners ) ) { - return; - } - - listeners.forEach( (listener) -> { - if ( listener.getStyle() == JpaEventListenerStyle.CALLBACK ) { - processEntityCallbacks( listener, typeMetadata, persistentClass ); - } - else { - assert listener.getStyle() == JpaEventListenerStyle.LISTENER; - processListenerCallbacks( listener, typeMetadata, persistentClass ); - } - } ); - } - - private static void processEntityCallbacks( - JpaEventListener listener, - EntityTypeMetadata typeMetadata, - PersistentClass persistentClass) { - final Class entityClass = listener.getCallbackClass().toJavaClass(); - processJpaEventCallbacks( - entityClass, - listener, - JpaEventListenerStyle.CALLBACK, - null, - typeMetadata, - persistentClass - ); - } - - private static void processJpaEventCallbacks( - Class listenerClass, - JpaEventListener listener, - JpaEventListenerStyle style, - Class methodArgumentType, - EntityTypeMetadata typeMetadata, - PersistentClass persistentClass) { - assert style == JpaEventListenerStyle.CALLBACK || methodArgumentType != null; - - // todo : would be nicer to allow injecting them one at a time. - // upstream is defined currently to accept a List - final List callbackDefinitions = new ArrayList<>(); - - final MethodDetails prePersistMethod = listener.getPrePersistMethod(); - if ( prePersistMethod != null ) { - final Method callbackMethod = findCallbackMethod( listenerClass, prePersistMethod ); - callbackDefinitions.add( createCallbackDefinition( - listenerClass, - callbackMethod, - style, - CallbackType.PRE_PERSIST - ) ); - } - - final MethodDetails postPersistMethod = listener.getPostPersistMethod(); - if ( postPersistMethod != null ) { - final Method callbackMethod = findCallbackMethod( listenerClass, postPersistMethod ); - callbackDefinitions.add( createCallbackDefinition( - listenerClass, - callbackMethod, - style, - CallbackType.POST_PERSIST - ) ); - } - - final MethodDetails preUpdateMethod = listener.getPreUpdateMethod(); - if ( preUpdateMethod != null ) { - final Method callbackMethod = findCallbackMethod( listenerClass, preUpdateMethod ); - callbackDefinitions.add( createCallbackDefinition( - listenerClass, - callbackMethod, - style, - CallbackType.PRE_UPDATE - ) ); - } - - final MethodDetails postUpdateMethod = listener.getPostUpdateMethod(); - if ( postUpdateMethod != null ) { - final Method callbackMethod = findCallbackMethod( listenerClass, postUpdateMethod ); - callbackDefinitions.add( createCallbackDefinition( - listenerClass, - callbackMethod, - style, - CallbackType.POST_UPDATE - ) ); - } - - final MethodDetails preRemoveMethod = listener.getPreRemoveMethod(); - if ( preRemoveMethod != null ) { - final Method callbackMethod = findCallbackMethod( listenerClass, preRemoveMethod ); - callbackDefinitions.add( createCallbackDefinition( - listenerClass, - callbackMethod, - style, - CallbackType.PRE_REMOVE - ) ); - } - - final MethodDetails postRemoveMethod = listener.getPostRemoveMethod(); - if ( postRemoveMethod != null ) { - final Method callbackMethod = findCallbackMethod( listenerClass, postRemoveMethod ); - callbackDefinitions.add( createCallbackDefinition( - listenerClass, - callbackMethod, - style, - CallbackType.POST_REMOVE - ) ); - } - - final MethodDetails postLoadMethod = listener.getPostLoadMethod(); - if ( postLoadMethod != null ) { - final Method callbackMethod = findCallbackMethod( listenerClass, postLoadMethod ); - callbackDefinitions.add( createCallbackDefinition( - listenerClass, - callbackMethod, - style, - CallbackType.POST_LOAD - ) ); - } - - persistentClass.addCallbackDefinitions( callbackDefinitions ); - } - - private static CallbackDefinition createCallbackDefinition( - Class listenerClass, - Method callbackMethod, - JpaEventListenerStyle style, - CallbackType callbackType) { - final CallbackDefinition callback; - if ( style == JpaEventListenerStyle.CALLBACK ) { - callback = new EntityCallback.Definition( callbackMethod, callbackType ); - } - else { - callback = new ListenerCallback.Definition( listenerClass, callbackMethod, callbackType ); - } - return callback; - } - - private static void processListenerCallbacks( - JpaEventListener listener, - EntityTypeMetadata typeMetadata, - PersistentClass persistentClass) { - final Class listenerClass = listener.getCallbackClass().toJavaClass(); - processJpaEventCallbacks( - listenerClass, - listener, - JpaEventListenerStyle.LISTENER, - typeMetadata.getClassDetails().toJavaClass(), - typeMetadata, - persistentClass - ); - } - - private static Method findCallbackMethod( - Class callbackTarget, - MethodDetails callbackMethod) { - try { - if ( callbackMethod.getArgumentTypes().isEmpty() ) { - return callbackTarget.getDeclaredMethod( callbackMethod.getName() ); - } - else { - final ClassDetails argClassDetails = callbackMethod.getArgumentTypes().get( 0 ); - // we don't - return callbackTarget.getMethod( callbackMethod.getName(), argClassDetails.toJavaClass() ); - } - } - catch (NoSuchMethodException e) { - final ModelsException modelsException = new ModelsException( - String.format( - Locale.ROOT, - "Unable to locate callback method - %s.%s", - callbackTarget.getName(), - callbackMethod.getName() - ) - ); - modelsException.addSuppressed( e ); - throw modelsException; - } - } - - private static void applyBatchSize( - EntityTypeMetadata typeMetadata, - PersistentClass persistentClass, - BindingState bindingState) { - final AnnotationUsage batchSizeAnnotation = typeMetadata - .getClassDetails() - .getAnnotationUsage( HibernateAnnotations.BATCH_SIZE ); - if ( batchSizeAnnotation == null ) { - return; - } - - persistentClass.setBatchSize( batchSizeAnnotation.getInteger( "size" ) ); - } - - private static void applySqlCustomizations( - EntityTypeMetadata typeMetadata, - PersistentClass persistentClass, - BindingState bindingState) { - final AnnotationUsage dynamicInsert = typeMetadata - .getClassDetails() - .getAnnotationUsage( HibernateAnnotations.DYNAMIC_INSERT ); - final AnnotationUsage dynamicUpdate = typeMetadata - .getClassDetails() - .getAnnotationUsage( HibernateAnnotations.DYNAMIC_UPDATE ); - - final List> customInserts = typeMetadata - .getClassDetails() - .getRepeatedAnnotationUsages( HibernateAnnotations.SQL_INSERT ); - final List> customUpdates = typeMetadata - .getClassDetails() - .getRepeatedAnnotationUsages( HibernateAnnotations.SQL_UPDATE ); - final List> customDeletes = typeMetadata - .getClassDetails() - .getRepeatedAnnotationUsages( HibernateAnnotations.SQL_DELETE ); - - if ( dynamicInsert != null ) { - if ( CollectionHelper.isNotEmpty( customInserts ) ) { - MODEL_BINDING_MSG_LOGGER.dynamicAndCustomInsert( persistentClass.getEntityName() ); - } - persistentClass.setDynamicInsert( dynamicInsert.getBoolean( "value" ) ); - } - - if ( dynamicUpdate != null ) { - if ( CollectionHelper.isNotEmpty( customUpdates ) ) { - MODEL_BINDING_MSG_LOGGER.dynamicAndCustomUpdate( persistentClass.getEntityName() ); - } - persistentClass.setDynamicUpdate( dynamicUpdate.getBoolean( "value" ) ); - } - - if ( CollectionHelper.isNotEmpty( customInserts ) - || CollectionHelper.isNotEmpty( customUpdates ) - || CollectionHelper.isNotEmpty( customDeletes ) ) { - final Map joinMap = extractJoinMap( persistentClass ); - applyCustomSql( - customInserts, - persistentClass, - joinMap, - PersistentClass::setCustomSQLInsert, - Join::setCustomSQLInsert - ); - applyCustomSql( - customUpdates, - persistentClass, - joinMap, - PersistentClass::setCustomSQLUpdate, - Join::setCustomSQLUpdate - ); - applyCustomSql( - customDeletes, - persistentClass, - joinMap, - PersistentClass::setCustomSQLDelete, - Join::setCustomSQLDelete - ); - } - } - - private static Map extractJoinMap(PersistentClass persistentClass) { - final List joins = persistentClass.getJoins(); - if ( CollectionHelper.isEmpty( joins ) ) { - return Collections.emptyMap(); - } - - final HashMap joinMap = CollectionHelper.mapOfSize( joins.size() ); - joins.forEach( (join) -> joinMap.put( join.getTable().getName(), join ) ); - return joinMap; - } - - private static void applyCustomSql( - List> annotationUsages, - PersistentClass persistentClass, - Map joinMap, - PrimaryCustomSqlInjector primaryTableInjector, - SecondaryCustomSqlInjector secondaryTableInjector) { - if ( CollectionHelper.isEmpty( annotationUsages ) ) { - return; - } - - annotationUsages.forEach( annotationUsage -> { - final String tableName = annotationUsage.getString( "table" ); - - if ( StringHelper.isEmpty( tableName ) ) { - primaryTableInjector.injectCustomSql( - persistentClass, - annotationUsage.getString( "sql" ), - annotationUsage.getBoolean( "callable" ), - ExecuteUpdateResultCheckStyle.fromResultCheckStyle( annotationUsage.getEnum( "", ResultCheckStyle.class ) ) - ); - } - else { - final Join join = joinMap.get( tableName ); - secondaryTableInjector.injectCustomSql( - join, - annotationUsage.getString( "sql" ), - annotationUsage.getBoolean( "callable" ), - ExecuteUpdateResultCheckStyle.fromResultCheckStyle( annotationUsage.getEnum( "", ResultCheckStyle.class ) ) - ); - } - } ); - } - - public abstract RootEntityBinding getRootEntityBinding(); - - @FunctionalInterface - private interface PrimaryCustomSqlInjector { - void injectCustomSql(PersistentClass persistentClass, String sql, boolean callable, ExecuteUpdateResultCheckStyle checkStyle); - } - - @FunctionalInterface - private interface SecondaryCustomSqlInjector { - void injectCustomSql(Join join, String sql, boolean callable, ExecuteUpdateResultCheckStyle checkStyle); - } - - private static void applySynchronizedTableNames( - EntityTypeMetadata typeMetadata, - PersistentClass persistentClass, - BindingState bindingState) { - final AnnotationUsage usage = typeMetadata - .getClassDetails() - .getAnnotationUsage( HibernateAnnotations.SYNCHRONIZE ); - if ( usage == null ) { - return; - } - - // todo : handle Synchronize#logical - for now assume it is logical - final List names = usage.getList( "value" ); - names.forEach( persistentClass::addSynchronizedTable ); - } - - protected void prepareSubclassBindings() { - getTypeMetadata().forEachSubType( (subType) -> { - if ( subType instanceof EntityTypeMetadata entityTypeMetadata ) { - new SubclassEntityBinding( - entityTypeMetadata, - this, - EntityHierarchy.HierarchyRelation.SUB, - bindingOptions, - bindingState, - bindingContext - ); - } - else { - new MappedSuperclassBinding( - (MappedSuperclassTypeMetadata) subType, - this, - EntityHierarchy.HierarchyRelation.SUB, - bindingOptions, - bindingState, - bindingContext - ); - } - } ); - } - - @Override - protected boolean excludeAttributeFromPreparation(AttributeMetadata attributeMetadata) { - // skip "special" attributes - final EntityHierarchy hierarchy = getTypeMetadata().getHierarchy(); - if ( hierarchy.getIdMapping().contains( attributeMetadata ) - || hierarchy.getVersionAttribute() == attributeMetadata - || hierarchy.getTenantIdAttribute() == attributeMetadata ) { - return true; - } - - return super.excludeAttributeFromPreparation( attributeMetadata ); - } - - @Override - protected AttributeBinding createAttributeBinding(AttributeMetadata attributeMetadata, Table primaryTable) { - return new AttributeBinding( attributeMetadata, getPersistentClass(), primaryTable, bindingOptions, bindingState, bindingContext ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/IdentifiableTypeBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/IdentifiableTypeBinding.java deleted file mode 100644 index 2c64870cd0..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/IdentifiableTypeBinding.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.Map; - -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.mapping.IdentifiableTypeClass; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Table; -import org.hibernate.models.ModelsException; - -/** - * Binding for an {@linkplain jakarta.persistence.metamodel.IdentifiableType identifiable type} - * - * @author Steve Ebersole - */ -public abstract class IdentifiableTypeBinding extends ManagedTypeBinding { - protected final IdentifiableTypeMetadata typeMetadata; - protected final IdentifiableTypeBinding superTypeBinding; - protected final IdentifiableTypeMetadata superTypeMetadata; - - private final Map attributeBindings; - - public IdentifiableTypeBinding( - IdentifiableTypeMetadata typeMetadata, - IdentifiableTypeBinding superTypeBinding, - EntityHierarchy.HierarchyRelation hierarchyRelation, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - super( typeMetadata.getClassDetails(), bindingOptions, bindingState, bindingContext ); - this.typeMetadata = typeMetadata; - this.superTypeBinding = superTypeBinding; - this.superTypeMetadata = superTypeBinding == null ? null : superTypeBinding.getTypeMetadata(); - - // NOTE: slightly over-sized (id, version, ...), but that's ok - this.attributeBindings = CollectionHelper.linkedMapOfSize( typeMetadata.getNumberOfAttributes() ); - } - - public IdentifiableTypeMetadata getTypeMetadata() { - return typeMetadata; - } - - public IdentifiableTypeMetadata getSuperTypeMetadata() { - return superTypeMetadata; - } - - public IdentifiableTypeBinding getSuperTypeBinding() { - return superTypeBinding; - } - - @Override - public abstract IdentifiableTypeClass getBinding(); - - @Override - public Map getAttributeBindings() { - return attributeBindings; - } - - public EntityTypeMetadata findSuperEntityMetadata() { - final EntityBinding superEntityBinder = getSuperEntityBinding(); - if ( superEntityBinder == null ) { - return null; - } - - return superEntityBinder.getTypeMetadata(); - } - - public PersistentClass resolveSuperEntityPersistentClass(IdentifiableTypeClass superTypeBinding) { - if ( superTypeBinding instanceof PersistentClass ) { - return (PersistentClass) superTypeBinding; - } - - if ( superTypeBinding.getSuperType() != null ) { - return resolveSuperEntityPersistentClass( superTypeBinding.getSuperType() ); - } - - throw new ModelsException( "Unable to resolve super PersistentClass for " + superTypeBinding ); - } - - public EntityBinding getSuperEntityBinding() { - IdentifiableTypeBinding check = superTypeBinding; - if ( check == null ) { - return null; - } - - do { - if ( check.getBinding() instanceof PersistentClass ) { - return (EntityBinding) check; - } - check = check.getSuperTypeBinding(); - } while ( check != null ); - - return null; - } - - protected void prepareAttributeBindings(Table primaryTable) { - typeMetadata.forEachAttribute( (index, attributeMetadata) -> { - if ( excludeAttributeFromPreparation( attributeMetadata ) ) { - return; - } - - final var attributeBinding = createAttributeBinding( attributeMetadata, primaryTable ); - attributeBindings.put( attributeMetadata.getName(), attributeBinding ); - getBinding().applyProperty( attributeBinding.getProperty() ); - } ); - } - - - protected boolean excludeAttributeFromPreparation(AttributeMetadata attributeMetadata) { - return false; - } - - protected abstract AttributeBinding createAttributeBinding(AttributeMetadata attributeMetadata, Table primaryTable); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/IdentifierBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/IdentifierBinding.java deleted file mode 100644 index 63314bd27a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/IdentifierBinding.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.categorize.spi.AggregatedKeyMapping; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.BasicKeyMapping; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.KeyMapping; -import org.hibernate.boot.models.categorize.spi.NonAggregatedKeyMapping; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Component; -import org.hibernate.mapping.KeyValue; -import org.hibernate.mapping.PrimaryKey; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.RootClass; -import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.MemberDetails; - -import jakarta.persistence.Column; - -/** - * Binding for an entity identifier - * - * @author Steve Ebersole - */ -public class IdentifierBinding extends Binding implements Observable { - private final KeyValue keyValue; - - private boolean resolved; - private List> resolutionCallbacks; - - public IdentifierBinding( - RootEntityBinding rootEntityBinding, - EntityTypeMetadata entityTypeMetadata, - BindingOptions options, - BindingState state, - BindingContext context) { - super( options, state, context ); - - this.keyValue = prepareMappingValue( rootEntityBinding, entityTypeMetadata, this, options, state, context ); - } - - public KeyValue getValue() { - return keyValue; - } - - @Override - public KeyValue getBinding() { - return getValue(); - } - - private static KeyValue prepareMappingValue( - RootEntityBinding rootEntityBinding, - EntityTypeMetadata entityTypeMetadata, - IdentifierBinding binding, - BindingOptions options, - BindingState state, - BindingContext context) { - final RootClass rootClass = rootEntityBinding.getPersistentClass(); - final EntityHierarchy hierarchy = entityTypeMetadata.getHierarchy(); - final KeyMapping idMapping = hierarchy.getIdMapping(); - final Table table = rootClass.getTable(); - - if ( idMapping instanceof BasicKeyMapping basicKeyMapping ) { - return prepareBasicIdentifier( basicKeyMapping, table, rootClass, binding, options, state, context ); - } - else if ( idMapping instanceof AggregatedKeyMapping aggregatedKeyMapping ) { - return bindAggregatedIdentifier( aggregatedKeyMapping, table, rootClass, options, state, context ); - } - else { - return bindNonAggregatedIdentifier( (NonAggregatedKeyMapping) idMapping, table, rootClass, options, state, context ); - } - } - - private static KeyValue prepareBasicIdentifier( - BasicKeyMapping basicKeyMapping, - Table table, - RootClass rootClass, - IdentifierBinding binding, - BindingOptions options, - BindingState state, - BindingContext context) { - final AttributeMetadata idAttribute = basicKeyMapping.getAttribute(); - final MemberDetails idAttributeMember = idAttribute.getMember(); - - final BasicValue idValue = new BasicValue( state.getMetadataBuildingContext(), table ); - rootClass.setIdentifier( idValue ); - idValue.setTable( table ); - - final Property idProperty = new Property(); - idProperty.setName( idAttribute.getName() ); - idProperty.setValue( idValue ); - idProperty.setPersistentClass( rootClass ); - - rootClass.addProperty( idProperty ); - rootClass.setIdentifierProperty( idProperty ); - - final PrimaryKey primaryKey = table.getPrimaryKey(); - - final AnnotationUsage idColumnAnn = idAttributeMember.getAnnotationUsage( Column.class ); - final org.hibernate.mapping.Column column = ColumnHelper.bindColumn( - idColumnAnn, - () -> "id", - true, - false - ); - idValue.addColumn( column, true, false ); - primaryKey.addColumn( column ); - - BasicValueHelper.bindImplicitJavaType( idAttributeMember, idValue, options, state, context ); - BasicValueHelper.bindJavaType( idAttributeMember, idValue, options, state, context ); - BasicValueHelper.bindJdbcType( idAttributeMember, idValue, options, state, context ); - BasicValueHelper.bindNationalized( idAttributeMember, idValue, options, state, context ); - - binding.resolve(); - - return idValue; - } - - private static KeyValue bindAggregatedIdentifier( - AggregatedKeyMapping aggregatedKeyMapping, - Table table, - RootClass rootClass, - BindingOptions options, - BindingState state, - BindingContext context) { - final Component idValue = new Component( state.getMetadataBuildingContext(), rootClass ); - rootClass.setIdentifier( idValue ); - idValue.setTable( table ); - - final Property idProperty = new Property(); - idProperty.setValue( idValue ); - rootClass.setIdentifierProperty( idProperty ); - - // todo : need an EmbeddableBinding - - return idValue; - } - - private static KeyValue bindNonAggregatedIdentifier( - NonAggregatedKeyMapping idMapping, - Table table, - RootClass rootClass, - BindingOptions options, - BindingState state, - BindingContext context) { - throw new UnsupportedOperationException( "Not yet implemented" ); - } - - - @Override - public void whenResolved(ResolutionCallback callback) { - if ( resolved ) { - callback.handleResolution( keyValue ); - return; - } - - if ( resolutionCallbacks == null ) { - resolutionCallbacks = new ArrayList<>(); - } - resolutionCallbacks.add( callback ); - } - - public void resolve() { - ObservableHelper.processCallbacks( keyValue, resolutionCallbacks ); - resolutionCallbacks = null; - resolved = true; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/InLineView.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/InLineView.java deleted file mode 100644 index 046d9fffc7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/InLineView.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.bind.spi.TableReference; -import org.hibernate.mapping.Table; - -/** - * Models a from-clause sub-query. - * - * @see org.hibernate.annotations.Subselect - * - * @author Steve Ebersole - */ -public record InLineView(Identifier logicalName, Table table) implements TableReference { - @Override - public Identifier logicalName() { - return logicalName; - } - - public String getQuery() { - return table.getSubselect(); - } - - @Override - public boolean exportable() { - return false; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/JoinedSubclassKeyHandler.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/JoinedSubclassKeyHandler.java deleted file mode 100644 index ce2dfe54ee..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/JoinedSubclassKeyHandler.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.List; -import java.util.Locale; - -import org.hibernate.MappingException; -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.DependantValue; -import org.hibernate.mapping.JoinedSubclass; -import org.hibernate.mapping.KeyValue; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; - -import jakarta.persistence.ForeignKey; -import jakarta.persistence.PrimaryKeyJoinColumn; - -/** - * @author Steve Ebersole - */ -public record JoinedSubclassKeyHandler( - ClassDetails subclassDetails, - JoinedSubclass subclass, - MetadataBuildingContext buildingContext) implements ResolutionCallback { - - @Override - public boolean handleResolution(KeyValue targetKeyValue) { - final List> pkJoinColumns = subclassDetails.getRepeatedAnnotationUsages( PrimaryKeyJoinColumn.class ); - final DependantValue fkValue = new DependantValue( buildingContext, subclass.getTable(), targetKeyValue ); - - if ( CollectionHelper.isEmpty( pkJoinColumns ) ) { - handleImplicitJoinColumns( targetKeyValue, fkValue ); - } - else { - handleExplicitJoinColumns( pkJoinColumns, targetKeyValue, fkValue ); - } - - final AnnotationUsage fkAnn = subclassDetails.getAnnotationUsage( ForeignKey.class ); - - final String foreignKeyName = fkAnn == null - // todo : generate the name here - this *is* equiv to legacy second pass - ? "" - : fkAnn.getString( "name" ); - final String foreignKeyDefinition = fkAnn == null - ? "" - : fkAnn.getString( "foreignKeyDefinition" ); - - final org.hibernate.mapping.ForeignKey foreignKey = subclass.getTable().createForeignKey( - foreignKeyName, - fkValue.getColumns(), - subclass.getRootClass().getEntityName(), - foreignKeyDefinition, - targetKeyValue.getColumns() - ); - foreignKey.setReferencedTable( subclass.getRootTable() ); - - return true; - } - - private void handleImplicitJoinColumns(KeyValue targetKeyValue, DependantValue fkValue) { - targetKeyValue.getColumns().forEach( (column) -> { - final Column fkColumn = column.clone(); - subclass.getTable().getPrimaryKey().addColumn( fkColumn ); - fkValue.addColumn( fkColumn ); - } ); - } - - private void handleExplicitJoinColumns( - List> pkJoinColumns, - KeyValue targetKeyValue, - DependantValue fkValue) { - for ( int i = 0; i < targetKeyValue.getColumnSpan(); i++ ) { - final Column targetColumn = targetKeyValue.getColumns().get( i ); - final var joinColumnAnn = resolveMatchingJoinColumnAnn( - targetColumn, - pkJoinColumns, - i - ); - - final Column keyColumn = ColumnHelper.bindColumn( joinColumnAnn, targetColumn::getName, true, false ); - subclass().getTable().getPrimaryKey().addColumn( keyColumn ); - fkValue.addColumn( keyColumn ); - } - } - - private AnnotationUsage resolveMatchingJoinColumnAnn( - Column targetPkColumn, - List> keyJoinColumns, - int pkColumnPosition) { - for ( int j = 0; j < keyJoinColumns.size(); j++ ) { - final var keyJoinColumn = keyJoinColumns.get( j ); - final String name = keyJoinColumn.getString( "name" ); - final String referencedColumnName = keyJoinColumn.getString( "referencedColumnName" ); - if ( StringHelper.isEmpty( name ) && StringHelper.isEmpty( referencedColumnName ) ) { - // assume positional match - // todo : is this correct? the only other option is to throw an exception - if ( j == pkColumnPosition ) { - return keyJoinColumn; - } - } - else if ( StringHelper.isNotEmpty( referencedColumnName ) ) { - if ( targetPkColumn.getName().equals( referencedColumnName ) ) { - return keyJoinColumn; - } - } - else { - assert StringHelper.isNotEmpty( name ); - if ( targetPkColumn.getName().equals( name ) ) { - return keyJoinColumn; - } - } - } - - throw new MappingException( - String.format( - Locale.ROOT, - "Unable to match primary key column [%s] to any PrimaryKeyJoinColumn - %s", - targetPkColumn.getName(), - subclass().getEntityName() - ) - ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ManagedTypeBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ManagedTypeBinding.java deleted file mode 100644 index aa54a57b2a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ManagedTypeBinding.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.Map; - -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.models.spi.ClassDetails; - -/** - * Binding for an {@linkplain jakarta.persistence.metamodel.ManagedType managed type} - * - * @author Steve Ebersole - */ -public abstract class ManagedTypeBinding extends Binding { - protected final ClassDetails classDetails; - - public ManagedTypeBinding( - ClassDetails classDetails, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - super( bindingOptions, bindingState, bindingContext ); - this.classDetails = classDetails; - } - - public ClassDetails getClassDetails() { - return classDetails; - } - - public abstract Map getAttributeBindings(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/MappedSuperclassBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/MappedSuperclassBinding.java deleted file mode 100644 index b3b5070add..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/MappedSuperclassBinding.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.MappedSuperclassTypeMetadata; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.MappedSuperclass; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Table; - -/** - * @author Steve Ebersole - */ -public class MappedSuperclassBinding extends IdentifiableTypeBinding { - private final MappedSuperclass mappedSuperclass; - - public MappedSuperclassBinding( - MappedSuperclassTypeMetadata type, - IdentifiableTypeBinding superTypeBinding, - EntityHierarchy.HierarchyRelation hierarchyRelation, - BindingOptions options, - BindingState state, - BindingContext bindingContext) { - super( type, superTypeBinding, hierarchyRelation, options, state, bindingContext ); - - final EntityBinding superEntityBinding = getSuperEntityBinding(); - final MappedSuperclass superMappedSuper; - final PersistentClass superEntity; - if ( superTypeBinding == superEntityBinding && superTypeBinding != null ) { - superMappedSuper = null; - superEntity = superEntityBinding.getPersistentClass(); - } - else if ( superTypeBinding != null ) { - superMappedSuper = (MappedSuperclass) superTypeBinding.getBinding(); - superEntity = null; - } - else if ( superEntityBinding != null ) { - superMappedSuper = null; - superEntity = superEntityBinding.getPersistentClass(); - } - else { - superMappedSuper = null; - superEntity = null; - } - - this.mappedSuperclass = new MappedSuperclass( superMappedSuper, superEntity, getTable() ); - state.registerTypeBinding( type, this ); - - state.getMetadataBuildingContext().getMetadataCollector().addImport( - StringHelper.unqualify( type.getClassDetails().getClassName() ), - type.getClassDetails().getClassName() - ); - } - - public MappedSuperclass getMappedSuperclass() { - return mappedSuperclass; - } - - @Override - public MappedSuperclass getBinding() { - return getMappedSuperclass(); - } - - @Override - protected AttributeBinding createAttributeBinding(AttributeMetadata attributeMetadata, Table primaryTable) { - throw new UnsupportedOperationException( "Not yet implemented" ); - } - - Table getTable() { - final var superEntityBinder = getSuperEntityBinding(); - if ( superEntityBinder == null ) { - return null; - } - - return superEntityBinder.getPersistentClass().getTable(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ObservableHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ObservableHelper.java deleted file mode 100644 index b2c743c1aa..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ObservableHelper.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.Iterator; -import java.util.List; - -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.ModelsException; - -import static org.hibernate.boot.models.bind.ModelBindingLogging.MODEL_BINDING_LOGGER; - -/** - * @author Steve Ebersole - */ -public class ObservableHelper { - public static void processCallbacks( - T resolvedInstance, - List> callbacks) { - processCallbacks( resolvedInstance, callbacks, false ); - } - - public static void processCallbacks( - T resolvedInstance, - List> callbacks, - boolean allowUnresolved) { - if ( CollectionHelper.isEmpty( callbacks ) ) { - return; - } - - int processedCount = 0; - final Iterator> secondPassItr = callbacks.iterator(); - while ( secondPassItr.hasNext() ) { - final ResolutionCallback callback = secondPassItr.next(); - try { - final boolean success = callback.handleResolution( resolvedInstance ); - if ( success ) { - processedCount++; - secondPassItr.remove(); - } - } - catch (Exception e) { - // todo : handle cases where the caught exception is a non-transient, invariant condition - // indicating to immediately stop the processing and throw an error (either the original - // or a new one. - MODEL_BINDING_LOGGER.debug( "Error processing second pass", e ); - } - } - - if ( !callbacks.isEmpty() ) { - if ( processedCount == 0 ) { - // there are callbacks in the queue, but we were not able to - // successfully process any of them. this is a non-changing - // error condition - throw an exception, unless `allowUnresolved` == true - if ( !allowUnresolved ) { - throw new ModelsException( "Unable to process second-pass list" ); - } - } - - processCallbacks( resolvedInstance, callbacks ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/PhysicalTable.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/PhysicalTable.java deleted file mode 100644 index 101bf176a3..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/PhysicalTable.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.bind.spi.PhysicalTableReference; -import org.hibernate.mapping.Table; - -/** - * Models a physical table from the underlying database schema - * - * @see jakarta.persistence.Table - * @see jakarta.persistence.CollectionTable - * @see jakarta.persistence.JoinTable - * - * @author Steve Ebersole - */ -public record PhysicalTable( - Identifier logicalName, - Identifier logicalCatalogName, - Identifier logicalSchemaName, - Identifier physicalTableName, - Identifier physicalCatalogName, - Identifier physicalSchemaName, - Table table) implements PhysicalTableReference { - - @Override - public Identifier logicalName() { - return logicalName; - } - - @Override - public Identifier getLogicalSchemaName() { - return logicalSchemaName; - } - - @Override - public Identifier getLogicalCatalogName() { - return logicalCatalogName; - } - - @Override - public Identifier getPhysicalTableName() { - return physicalTableName; - } - - @Override - public Identifier getPhysicalSchemaName() { - return physicalSchemaName; - } - - @Override - public Identifier getPhysicalCatalogName() { - return physicalCatalogName; - } - - @Override - public boolean exportable() { - return !table.isAbstract() && table.getExportIdentifier() != null; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/PhysicalView.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/PhysicalView.java deleted file mode 100644 index 992c7537e4..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/PhysicalView.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.bind.spi.PersistentTableReference; -import org.hibernate.mapping.Table; - -/** - * @see org.hibernate.annotations.View - * - * @author Steve Ebersole - */ -public record PhysicalView( - Identifier logicalName, - Identifier logicalCatalogName, - Identifier logicalSchemaName, - Identifier physicalName, - Identifier physicalCatalogName, - Identifier physicalSchemaName, - Table table) implements PersistentTableReference { - @Override - public Identifier logicalName() { - return logicalName; - } - - @Override - public Identifier getPhysicalSchemaName() { - return physicalSchemaName; - } - - @Override - public Identifier getLogicalSchemaName() { - return logicalSchemaName; - } - - @Override - public Identifier getPhysicalCatalogName() { - return physicalCatalogName; - } - - @Override - public Identifier getLogicalCatalogName() { - return logicalCatalogName; - } - - @Override - public boolean exportable() { - return true; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ResolutionCallback.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ResolutionCallback.java deleted file mode 100644 index ca79a447c9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/ResolutionCallback.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -/** - * Provides callback notification when an object of interest is - * fully resolved and all of its state available. - * - * @author Steve Ebersole - */ -@FunctionalInterface -public interface ResolutionCallback { - /** - * Callback to use the fully resolved {@code resolvedThing} - * - * @param resolvedThing The resolved object of interest - * - * @return {@code true} if processing was successful; {@code false} otherwise - */ - boolean handleResolution(T resolvedThing); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/RootEntityBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/RootEntityBinding.java deleted file mode 100644 index a7d1853527..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/RootEntityBinding.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.MappingException; -import org.hibernate.annotations.DiscriminatorFormula; -import org.hibernate.annotations.OptimisticLocking; -import org.hibernate.annotations.SoftDelete; -import org.hibernate.annotations.SoftDeleteType; -import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor; -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.model.naming.PhysicalNamingStrategy; -import org.hibernate.boot.model.relational.Database; -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.bind.spi.TableReference; -import org.hibernate.boot.models.categorize.spi.CacheRegion; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.MappedSuperclassTypeMetadata; -import org.hibernate.boot.models.categorize.spi.NaturalIdCacheRegion; -import org.hibernate.boot.spi.MetadataBuildingOptions; -import org.hibernate.engine.OptimisticLockStyle; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.MappedSuperclass; -import org.hibernate.mapping.RootClass; -import org.hibernate.mapping.Table; -import org.hibernate.models.spi.AnnotationUsage; - -import jakarta.persistence.DiscriminatorColumn; -import jakarta.persistence.DiscriminatorType; -import jakarta.persistence.InheritanceType; - -import static org.hibernate.boot.models.bind.ModelBindingLogging.MODEL_BINDING_LOGGER; -import static org.hibernate.boot.models.bind.internal.BasicValueHelper.bindTenantId; -import static org.hibernate.boot.models.bind.internal.BasicValueHelper.bindVersion; -import static org.hibernate.internal.util.StringHelper.coalesce; - -/** - * Binding for a root {@linkplain jakarta.persistence.metamodel.EntityType entity type} - * - * @author Steve Ebersole - */ -public class RootEntityBinding extends EntityBinding { - private final RootClass rootClass; - private final IdentifierBinding identifierBinding; - private final TableReference tableReference; - - public RootEntityBinding( - EntityTypeMetadata typeMetadata, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - super( - typeMetadata, - resolveSuperTypeBinding( - (MappedSuperclassTypeMetadata) typeMetadata.getSuperType(), - bindingOptions, - bindingState, - bindingContext - ), - EntityHierarchy.HierarchyRelation.ROOT, - bindingOptions, - bindingState, - bindingContext - ); - - this.rootClass = new RootClass( bindingState.getMetadataBuildingContext() ); - applyNaming( typeMetadata, rootClass, bindingState ); - - this.tableReference = TableHelper.bindPrimaryTable( - typeMetadata, - EntityHierarchy.HierarchyRelation.ROOT, - bindingOptions, - bindingState, - bindingContext - ); - rootClass.setTable( tableReference.table() ); - - this.identifierBinding = new IdentifierBinding( this, typeMetadata, bindingOptions, bindingState, bindingContext ); - this.rootClass.setIdentifier( identifierBinding.getValue() ); - - TableHelper.bindSecondaryTables( - this, - bindingOptions, - bindingState, - bindingContext - ); - - bindingState.registerTypeBinding( typeMetadata, this ); - - this.rootClass.setTable( tableReference.table() ); - - if ( getSuperTypeBinding() != null ) { - rootClass.setSuperMappedSuperclass( (MappedSuperclass) getSuperTypeBinding().getBinding() ); - } - - if ( typeMetadata.hasSubTypes() ) { - bindDiscriminator( typeMetadata, rootClass, bindingOptions, bindingState, bindingContext ); - applyDiscriminatorValue( typeMetadata, rootClass ); - } - - bindVersion( typeMetadata, rootClass, bindingOptions, bindingState, bindingContext ); - bindTenantId( typeMetadata, rootClass, bindingOptions, bindingState, bindingContext ); - applyOptimisticLocking( typeMetadata, rootClass ); - applyCacheRegions( typeMetadata, rootClass ); - applySoftDelete( typeMetadata, rootClass, tableReference.table() ); - - applyCommonInformation( typeMetadata, rootClass, bindingState ); - prepareAttributeBindings( tableReference.table() ); - prepareSubclassBindings(); - } - - private static IdentifiableTypeBinding resolveSuperTypeBinding( - MappedSuperclassTypeMetadata superTypeMetadata, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - if ( superTypeMetadata == null ) { - return null; - } - - final IdentifiableTypeBinding superTypeSuperTypeBinding; - if ( superTypeMetadata.getSuperType() == null ) { - superTypeSuperTypeBinding = null; - } - else { - superTypeSuperTypeBinding = resolveSuperTypeBinding( - (MappedSuperclassTypeMetadata) superTypeMetadata.getSuperType(), - bindingOptions, - bindingState, - bindingContext - ); - } - - return new MappedSuperclassBinding( - superTypeMetadata, - superTypeSuperTypeBinding, - EntityHierarchy.HierarchyRelation.SUPER, - bindingOptions, - bindingState, - bindingContext - ); - } - - @Override - public RootClass getPersistentClass() { - return rootClass; - } - - @Override - public RootClass getBinding() { - return getPersistentClass(); - } - - public TableReference getTableReference() { - return tableReference; - } - - public IdentifierBinding getIdentifierBinding() { - return identifierBinding; - } - - @Override - public RootEntityBinding getRootEntityBinding() { - return this; - } - - private void applyCacheRegions(EntityTypeMetadata source, RootClass rootClass) { - final EntityHierarchy hierarchy = source.getHierarchy(); - final CacheRegion cacheRegion = hierarchy.getCacheRegion(); - final NaturalIdCacheRegion naturalIdCacheRegion = hierarchy.getNaturalIdCacheRegion(); - - if ( cacheRegion != null ) { - rootClass.setCacheRegionName( cacheRegion.getRegionName() ); - rootClass.setCacheConcurrencyStrategy( cacheRegion.getAccessType().getExternalName() ); - rootClass.setLazyPropertiesCacheable( cacheRegion.isCacheLazyProperties() ); - } - - if ( naturalIdCacheRegion != null ) { - rootClass.setNaturalIdCacheRegionName( naturalIdCacheRegion.getRegionName() ); - } - } - - private void applyOptimisticLocking(EntityTypeMetadata source, RootClass rootClass) { - final var classDetails = source.getClassDetails(); - final var optimisticLocking = classDetails.getAnnotationUsage( OptimisticLocking.class ); - - if ( optimisticLocking != null ) { - final var optimisticLockingType = optimisticLocking.getEnum( "type" ); - rootClass.setOptimisticLockStyle( OptimisticLockStyle.valueOf( optimisticLockingType.name() ) ); - } - } - - private void applySoftDelete(EntityTypeMetadata source, RootClass rootClass, Table primaryTable) { - final var classDetails = source.getClassDetails(); - final AnnotationUsage softDeleteConfig = classDetails.getAnnotationUsage( SoftDelete.class ); - if ( softDeleteConfig == null ) { - return; - } - - final BasicValue softDeleteIndicatorValue = createSoftDeleteIndicatorValue( softDeleteConfig, primaryTable ); - final Column softDeleteIndicatorColumn = createSoftDeleteIndicatorColumn( softDeleteConfig, softDeleteIndicatorValue ); - primaryTable.addColumn( softDeleteIndicatorColumn ); - rootClass.enableSoftDelete( softDeleteIndicatorColumn ); - } - - private BasicValue createSoftDeleteIndicatorValue( - AnnotationUsage softDeleteAnn, - Table table) { - assert softDeleteAnn != null; - - final var converterClassDetails = softDeleteAnn.getClassDetails( "converter" ); - final ClassBasedConverterDescriptor converterDescriptor = new ClassBasedConverterDescriptor( - converterClassDetails.toJavaClass(), - bindingContext.getBootstrapContext().getClassmateContext() - ); - - final BasicValue softDeleteIndicatorValue = new BasicValue( bindingState.getMetadataBuildingContext(), table ); - softDeleteIndicatorValue.makeSoftDelete( softDeleteAnn.getEnum( "strategy" ) ); - softDeleteIndicatorValue.setJpaAttributeConverterDescriptor( converterDescriptor ); - softDeleteIndicatorValue.setImplicitJavaTypeAccess( (typeConfiguration) -> converterDescriptor.getRelationalValueResolvedType().getErasedType() ); - return softDeleteIndicatorValue; - } - - private Column createSoftDeleteIndicatorColumn( - AnnotationUsage softDeleteConfig, - BasicValue softDeleteIndicatorValue) { - final Column softDeleteColumn = new Column(); - - applyColumnName( softDeleteColumn, softDeleteConfig ); - - softDeleteColumn.setLength( 1 ); - softDeleteColumn.setNullable( false ); - softDeleteColumn.setUnique( false ); - softDeleteColumn.setComment( "Soft-delete indicator" ); - - softDeleteColumn.setValue( softDeleteIndicatorValue ); - softDeleteIndicatorValue.addColumn( softDeleteColumn ); - - return softDeleteColumn; - } - - private void applyColumnName(Column softDeleteColumn, AnnotationUsage softDeleteConfig) { - final Database database = bindingState.getMetadataBuildingContext().getMetadataCollector().getDatabase(); - final PhysicalNamingStrategy namingStrategy = bindingState.getMetadataBuildingContext().getBuildingOptions().getPhysicalNamingStrategy(); - final SoftDeleteType strategy = softDeleteConfig.getEnum( "strategy" ); - final String logicalColumnName = coalesce( - strategy.getDefaultColumnName(), - softDeleteConfig.getString( "columnName" ) - ); - final Identifier physicalColumnName = namingStrategy.toPhysicalColumnName( - database.toIdentifier( logicalColumnName ), - database.getJdbcEnvironment() - ); - softDeleteColumn.setName( physicalColumnName.render( database.getDialect() ) ); - } - public static void bindDiscriminator( - EntityTypeMetadata typeMetadata, - RootClass rootClass, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final InheritanceType inheritanceType = typeMetadata.getHierarchy().getInheritanceType(); - final AnnotationUsage columnAnn = typeMetadata.getClassDetails().getAnnotationUsage( DiscriminatorColumn.class ); - final AnnotationUsage formulaAnn = typeMetadata.getClassDetails().getAnnotationUsage( DiscriminatorFormula.class ); - - if ( columnAnn != null && formulaAnn != null ) { - throw new MappingException( "Entity defined both @DiscriminatorColumn and @DiscriminatorFormula - " + typeMetadata.getEntityName() ); - } - - if ( inheritanceType == InheritanceType.TABLE_PER_CLASS ) { - // UnionSubclass cannot define a discriminator - return; - } - - if ( inheritanceType == InheritanceType.JOINED ) { - // JoinedSubclass can define a discriminator in certain circumstances - final MetadataBuildingOptions buildingOptions = bindingState.getMetadataBuildingContext().getBuildingOptions(); - - if ( buildingOptions.ignoreExplicitDiscriminatorsForJoinedInheritance() ) { - if ( columnAnn != null || formulaAnn != null ) { - MODEL_BINDING_LOGGER.debugf( "Skipping explicit discriminator for JOINED hierarchy due to configuration - " + rootClass.getEntityName() ); - } - return; - } - - if ( !buildingOptions.createImplicitDiscriminatorsForJoinedInheritance() ) { - if ( columnAnn == null && formulaAnn == null ) { - return; - } - } - } - - if ( inheritanceType == InheritanceType.SINGLE_TABLE ) { - if ( !typeMetadata.hasSubTypes() ) { - return; - } - } - - final BasicValue value = new BasicValue( bindingState.getMetadataBuildingContext(), rootClass.getIdentityTable() ); - rootClass.setDiscriminator( value ); - - final DiscriminatorType discriminatorType = ColumnHelper.bindDiscriminatorColumn( - bindingContext, - formulaAnn, - value, - columnAnn, - bindingOptions, - bindingState - ); - - final Class discriminatorJavaType; - switch ( discriminatorType ) { - case STRING -> discriminatorJavaType = String.class; - case CHAR -> discriminatorJavaType = char.class; - case INTEGER -> discriminatorJavaType = int.class; - default -> throw new IllegalStateException( "Unexpected DiscriminatorType - " + discriminatorType ); - } - - value.setImplicitJavaTypeAccess( typeConfiguration -> discriminatorJavaType ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondPass.java deleted file mode 100644 index 237b30f323..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondPass.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -/** - * @author Steve Ebersole - */ -@FunctionalInterface -public interface SecondPass { - boolean process(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondaryTable.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondaryTable.java deleted file mode 100644 index 0610af03ff..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondaryTable.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.bind.spi.PhysicalTableReference; -import org.hibernate.mapping.Table; - -/** - * @see jakarta.persistence.SecondaryTable - * - * @author Steve Ebersole - */ -public record SecondaryTable( - Identifier logicalName, - Identifier logicalCatalogName, - Identifier logicalSchemaName, - Identifier physicalName, - Identifier physicalCatalogName, - Identifier physicalSchemaName, - boolean optional, - boolean owned, - Table table) implements PhysicalTableReference { - @Override - public Identifier logicalName() { - return logicalName; - } - - @Override - public Identifier getLogicalSchemaName() { - return logicalSchemaName; - } - - @Override - public Identifier getLogicalCatalogName() { - return logicalCatalogName; - } - - @Override - public Identifier getPhysicalTableName() { - return physicalName; - } - - @Override - public Identifier getPhysicalSchemaName() { - return physicalSchemaName; - } - - @Override - public Identifier getPhysicalCatalogName() { - return physicalCatalogName; - } - - @Override - public boolean exportable() { - return !table.isAbstract(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondaryTableKeyHandler.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondaryTableKeyHandler.java deleted file mode 100644 index bcea335d3d..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SecondaryTableKeyHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.util.List; - -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.DependantValue; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.KeyValue; -import org.hibernate.models.spi.AnnotationUsage; - -import jakarta.persistence.ForeignKey; -import jakarta.persistence.PrimaryKeyJoinColumn; -import jakarta.persistence.SecondaryTable; - -/** - * Handles binding for {@linkplain PrimaryKeyJoinColumn} references for secondary and joined tables. - * - * @author Steve Ebersole - */ -public record SecondaryTableKeyHandler( - AnnotationUsage annotationUsage, - Join join, - EntityBinding entityBinding, - MetadataBuildingContext buildingContext) implements ResolutionCallback { - - @Override - public boolean handleResolution(KeyValue targetKeyValue) { - final DependantValue fkValue = new DependantValue( buildingContext(), join.getTable(), targetKeyValue ); - join.setKey( fkValue ); - - final List> pkJoinColumns = annotationUsage.getList( "pkJoinColumns" ); - - if ( CollectionHelper.isEmpty( pkJoinColumns ) ) { - handleImplicitJoinColumns( targetKeyValue, fkValue ); - } - else { - throw new UnsupportedOperationException( "Not yet implemented" ); - } - - final AnnotationUsage foreignKeyAnn = annotationUsage.getAttributeValue( "foreignKey" ); - // todo : generate the name here - this *is* equiv to legacy second pass - final String foreignKeyName = foreignKeyAnn == null - ? "" - : foreignKeyAnn.getString( "name" ); - final String foreignKeyDefinition = foreignKeyAnn == null - ? "" - : foreignKeyAnn.getString( "foreignKeyDefinition" ); - - final RootEntityBinding rootEntityBinding = entityBinding.getRootEntityBinding(); - final org.hibernate.mapping.ForeignKey foreignKey = join.getTable().createForeignKey( - foreignKeyName, - targetKeyValue.getColumns(), - rootEntityBinding.getPersistentClass().getEntityName(), - foreignKeyDefinition, - rootEntityBinding.getTableReference().table().getPrimaryKey().getColumns() - ); - foreignKey.setReferencedTable( rootEntityBinding.getTableReference().table() ); - - return true; - } - - private void handleImplicitJoinColumns(KeyValue targetKeyValue, DependantValue fkValue) { - targetKeyValue.getColumns().forEach( (column) -> { - final Column fkColumn = column.clone(); - join.getTable().getPrimaryKey().addColumn( fkColumn ); - fkValue.addColumn( fkColumn ); - } ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SubclassEntityBinding.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SubclassEntityBinding.java deleted file mode 100644 index 4ffaf8f1a0..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/SubclassEntityBinding.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; -import org.hibernate.mapping.IdentifiableTypeClass; -import org.hibernate.mapping.JoinedSubclass; -import org.hibernate.mapping.MappedSuperclass; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.PrimaryKey; -import org.hibernate.mapping.SingleTableSubclass; -import org.hibernate.mapping.Subclass; -import org.hibernate.mapping.UnionSubclass; - -import jakarta.persistence.InheritanceType; - -/** - * @author Steve Ebersole - */ -public class SubclassEntityBinding extends EntityBinding { - private final Subclass subclass; - - public SubclassEntityBinding( - EntityTypeMetadata typeMetadata, - IdentifiableTypeBinding superTypeBinding, - EntityHierarchy.HierarchyRelation hierarchyRelation, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - super( typeMetadata, superTypeBinding, hierarchyRelation, bindingOptions, bindingState, bindingContext ); - - this.subclass = createSubclass(); - applyNaming( typeMetadata, subclass, bindingState ); - bindingState.registerTypeBinding( getTypeMetadata(), this ); - - applyTable( - typeMetadata, - subclass, - bindingOptions, - bindingState, - bindingContext - ); - - TableHelper.bindSecondaryTables( - this, - bindingOptions, - bindingState, - bindingContext - ); - - applyDiscriminatorValue( typeMetadata, subclass ); - - applyCommonInformation( typeMetadata, subclass, bindingState ); - prepareAttributeBindings( subclass.getTable() ); - prepareSubclassBindings(); - } - - @Override - public Subclass getPersistentClass() { - return subclass; - } - - @Override - public RootEntityBinding getRootEntityBinding() { - return getSuperEntityBinding().getRootEntityBinding(); - } - - @Override - public Subclass getBinding() { - return getPersistentClass(); - } - - private Subclass createSubclass() { - final IdentifiableTypeMetadata superType = getSuperTypeMetadata(); - - // we have a few cases to handle here, complicated by how Hibernate has historically modeled - // mapped-superclass in its PersistentClass model (aka, not well) which manifests in some - // craziness over how these PersistentClass instantiations happen - - final InheritanceType inheritanceType = superType.getHierarchy().getInheritanceType(); - if ( inheritanceType == InheritanceType.JOINED ) { - return createJoinedSubclass( superTypeBinding.getBinding() ); - } - - if ( inheritanceType == InheritanceType.TABLE_PER_CLASS ) { - return createUnionSubclass( superTypeBinding.getBinding() ); - } - - assert inheritanceType == null || inheritanceType == InheritanceType.SINGLE_TABLE; - return createSingleTableSubclass( superTypeBinding.getBinding() ); - } - - private UnionSubclass createUnionSubclass(IdentifiableTypeClass superTypeMapping) { - final UnionSubclass unionSubclass; - if ( superTypeMapping instanceof PersistentClass superEntity ) { - unionSubclass = new UnionSubclass( superEntity, bindingState.getMetadataBuildingContext() ); - } - else { - assert superTypeMapping instanceof MappedSuperclass; - - final var superEntity = resolveSuperEntityPersistentClass( superTypeMapping ); - unionSubclass = new UnionSubclass( - superEntity, - bindingState.getMetadataBuildingContext() - ); - unionSubclass.setSuperMappedSuperclass( (MappedSuperclass) superTypeMapping ); - } - - return unionSubclass; - } - - private JoinedSubclass createJoinedSubclass(IdentifiableTypeClass superTypeMapping) { - final JoinedSubclass joinedSubclass; - - final var superTypePersistentClass = getSuperEntityBinding().getPersistentClass(); - if ( superTypeMapping instanceof PersistentClass superEntity ) { - joinedSubclass = new JoinedSubclass( - superEntity, - bindingState.getMetadataBuildingContext() - ); - } - else { - assert superTypeMapping instanceof MappedSuperclass; - - joinedSubclass = new JoinedSubclass( - superTypePersistentClass, - bindingState.getMetadataBuildingContext() - ); - joinedSubclass.setSuperMappedSuperclass( (MappedSuperclass) superTypeMapping ); - } - - final var joinTableReference = TableHelper.bindPrimaryTable( - getTypeMetadata(), - EntityHierarchy.HierarchyRelation.SUB, - bindingOptions, - bindingState, - bindingContext - ); - joinedSubclass.setTable( joinTableReference.table() ); - - final PrimaryKey primaryKey = new PrimaryKey( joinTableReference.table() ); - joinTableReference.table().setPrimaryKey( primaryKey ); - - getRootEntityBinding().getIdentifierBinding().whenResolved( new JoinedSubclassKeyHandler( - getTypeMetadata().getClassDetails(), - joinedSubclass, - bindingState.getMetadataBuildingContext() - ) ); - - return joinedSubclass; - } - - private SingleTableSubclass createSingleTableSubclass(IdentifiableTypeClass superTypeBinding) { - if ( superTypeBinding instanceof PersistentClass superEntity ) { - return new SingleTableSubclass( superEntity, bindingState.getMetadataBuildingContext() ); - } - else { - assert superTypeBinding instanceof MappedSuperclass; - - final PersistentClass superEntity = resolveSuperEntityPersistentClass( superTypeBinding ); - final SingleTableSubclass binding = new SingleTableSubclass( - superEntity, - bindingState.getMetadataBuildingContext() - ); - binding.setSuperMappedSuperclass( (MappedSuperclass) superTypeBinding ); - return binding; - } - } - - protected void applyTable( - EntityTypeMetadata typeMetadata, - Subclass subclass, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - if ( subclass instanceof UnionSubclass unionSubclass ) { - final var unionTableReference = TableHelper.bindPrimaryTable( - getTypeMetadata(), - EntityHierarchy.HierarchyRelation.SUB, - bindingOptions, - bindingState, - bindingContext - ); - unionSubclass.setTable( unionTableReference.table() ); - - final PrimaryKey primaryKey = new PrimaryKey( unionTableReference.table() ); - unionTableReference.table().setPrimaryKey( primaryKey ); - } - else if ( subclass instanceof JoinedSubclass joinedSubclass ) { - - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/TableHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/TableHelper.java deleted file mode 100644 index c8bdf71eb1..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/TableHelper.java +++ /dev/null @@ -1,599 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import java.lang.annotation.Annotation; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.hibernate.annotations.Comment; -import org.hibernate.annotations.SecondaryRow; -import org.hibernate.annotations.Subselect; -import org.hibernate.boot.model.naming.EntityNaming; -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.model.naming.ImplicitEntityNameSource; -import org.hibernate.boot.model.naming.ImplicitNamingStrategy; -import org.hibernate.boot.model.naming.PhysicalNamingStrategy; -import org.hibernate.boot.models.AnnotationPlacementException; -import org.hibernate.boot.models.bind.spi.BindingContext; -import org.hibernate.boot.models.bind.spi.BindingOptions; -import org.hibernate.boot.models.bind.spi.BindingState; -import org.hibernate.boot.models.bind.spi.PhysicalTableReference; -import org.hibernate.boot.models.bind.spi.QuotedIdentifierTarget; -import org.hibernate.boot.models.bind.spi.TableReference; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.spi.InFlightMetadataCollector; -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.mapping.DenormalizedTable; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.PrimaryKey; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; - -import jakarta.persistence.InheritanceType; -import jakarta.persistence.JoinTable; -import jakarta.persistence.Table; - -/** - * @author Steve Ebersole - */ -public class TableHelper { - - public static TableReference bindPrimaryTable( - EntityTypeMetadata entityTypeMetadata, - EntityHierarchy.HierarchyRelation hierarchyRelation, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final ClassDetails typeClassDetails = entityTypeMetadata.getClassDetails(); - final AnnotationUsage
tableAnn = typeClassDetails.getAnnotationUsage( Table.class ); - final AnnotationUsage joinTableAnn = typeClassDetails.getAnnotationUsage( JoinTable.class ); - final AnnotationUsage subselectAnn = typeClassDetails.getAnnotationUsage( Subselect.class ); - - if ( tableAnn != null && joinTableAnn != null ) { - throw new AnnotationPlacementException( "Illegal combination of @Table and @JoinTable on " + typeClassDetails.getName() ); - } - if ( tableAnn != null && subselectAnn != null ) { - throw new AnnotationPlacementException( "Illegal combination of @Table and @Subselect on " + typeClassDetails.getName() ); - } - if ( joinTableAnn != null && subselectAnn != null ) { - throw new AnnotationPlacementException( "Illegal combination of @JoinTable and @Subselect on " + typeClassDetails.getName() ); - } - - final TableReference tableReference; - - if ( entityTypeMetadata.getHierarchy().getInheritanceType() == InheritanceType.TABLE_PER_CLASS ) { - assert subselectAnn == null; - - if ( hierarchyRelation == EntityHierarchy.HierarchyRelation.ROOT ) { - tableReference = bindPhysicalTable( - entityTypeMetadata, - tableAnn, - true, - bindingOptions, - bindingState, - bindingContext - ); - } - else { - tableReference = bindUnionTable( - entityTypeMetadata, - tableAnn, - bindingOptions, - bindingState, - bindingContext - ); - } - } - else if ( entityTypeMetadata.getHierarchy().getInheritanceType() == InheritanceType.SINGLE_TABLE ) { - if ( hierarchyRelation == EntityHierarchy.HierarchyRelation.ROOT ) { - tableReference = normalTableDetermination( - entityTypeMetadata, - subselectAnn, - tableAnn, - Table.class, - typeClassDetails, - bindingOptions, - bindingState, - bindingContext - ); - } - else { - tableReference = null; - } - } - else { - assert entityTypeMetadata.getHierarchy().getInheritanceType() == InheritanceType.JOINED; - tableReference = normalTableDetermination( - entityTypeMetadata, - subselectAnn, - joinTableAnn, - JoinTable.class, - typeClassDetails, - bindingOptions, - bindingState, - bindingContext - ); - } - - if ( tableReference != null ) { - bindingState.addTable( entityTypeMetadata, tableReference ); - - final PrimaryKey primaryKey = new PrimaryKey( tableReference.table() ); - tableReference.table().setPrimaryKey( primaryKey ); - } - - return tableReference; - } - - public static Map bindSecondaryTables( - EntityBinding entityBinding, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final ClassDetails typeClassDetails = entityBinding.getTypeMetadata().getClassDetails(); - final List> annotationUsages = typeClassDetails.getRepeatedAnnotationUsages( jakarta.persistence.SecondaryTable.class ); - - if ( CollectionHelper.isEmpty( annotationUsages ) ) { - return Collections.emptyMap(); - } - - final Map secondaryTableMap = CollectionHelper.mapOfSize( annotationUsages.size() ); - annotationUsages.forEach( (secondaryTableAnn) -> { - final AnnotationUsage secondaryRowAnn = typeClassDetails.getNamedAnnotationUsage( - SecondaryRow.class, - secondaryTableAnn.getString( "name" ), - "table" - ); - final SecondaryTable binding = bindSecondaryTable( - entityBinding, - secondaryTableAnn, - secondaryRowAnn, - bindingOptions, - bindingState, - bindingContext - ); - secondaryTableMap.put( binding.logicalName().getCanonicalName(), binding ); - bindingState.addSecondaryTable( binding ); - } ); - return secondaryTableMap; - } - - public static SecondaryTable bindSecondaryTable( - EntityBinding entityBinding, - AnnotationUsage secondaryTableAnn, - AnnotationUsage secondaryRowAnn, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final Identifier logicalName = determineLogicalName( - entityBinding.getTypeMetadata(), - secondaryTableAnn, - bindingOptions, - bindingState, - bindingContext - ); - final Identifier schemaName = resolveDatabaseIdentifier( - secondaryTableAnn, - "schema", - bindingOptions.getDefaultSchemaName(), - QuotedIdentifierTarget.SCHEMA_NAME, - bindingOptions, - bindingState, - bindingContext - ); - final Identifier catalogName = resolveDatabaseIdentifier( - secondaryTableAnn, - "catalog", - bindingOptions.getDefaultCatalogName(), - QuotedIdentifierTarget.CATALOG_NAME, - bindingOptions, - bindingState, - bindingContext - ); - - final MetadataBuildingContext buildingContext = bindingState.getMetadataBuildingContext(); - final var secondaryTable = buildingContext.getMetadataCollector().addTable( - toCanonicalName( schemaName ), - toCanonicalName( catalogName ), - logicalName.getCanonicalName(), - null, - false, - buildingContext - ); - secondaryTable.setPrimaryKey( new PrimaryKey( secondaryTable ) ); - - applyComment( secondaryTable, secondaryTableAnn, findCommentAnnotation( - entityBinding.getTypeMetadata(), - logicalName, - false - ) ); - applyOptions( secondaryTable, secondaryTableAnn ); - - final Join join = new Join(); - join.setTable( secondaryTable ); - join.setOptional( BindingHelper.getValue( secondaryRowAnn, "optional", true ) ); - join.setInverse( !BindingHelper.getValue( secondaryRowAnn, "owned", true ) ); - join.setPersistentClass( entityBinding.getPersistentClass() ); - entityBinding.getPersistentClass().addJoin( join ); - - entityBinding.getRootEntityBinding().getIdentifierBinding().whenResolved( new SecondaryTableKeyHandler( - secondaryTableAnn, - join, - entityBinding, - buildingContext - ) ); - - // todo : handle @UniqueConstraint - // todo : handle @Index - // todo : handle @CheckConstraint - - final JdbcEnvironment jdbcEnvironment = jdbcEnvironment( bindingContext ); - final PhysicalNamingStrategy physicalNamingStrategy = physicalNamingStrategy( bindingContext ); - return new SecondaryTable( - logicalName, - catalogName, - schemaName, - physicalNamingStrategy.toPhysicalTableName( logicalName, jdbcEnvironment ), - physicalNamingStrategy.toPhysicalCatalogName( catalogName, jdbcEnvironment ), - physicalNamingStrategy.toPhysicalSchemaName( schemaName, jdbcEnvironment ), - BindingHelper.getValue( secondaryRowAnn, "optional", true ), - BindingHelper.getValue( secondaryRowAnn, "owned", true ), - secondaryTable - ); - } - - private static TableReference normalTableDetermination( - EntityTypeMetadata type, - AnnotationUsage subselectAnn, - AnnotationUsage tableAnn, - Class annotationType, - ClassDetails typeClassDetails, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final TableReference tableReference; - if ( subselectAnn != null ) { - tableReference = bindVirtualTable( type, subselectAnn, bindingOptions, bindingState, bindingContext ); - } - else { - // either an explicit or implicit @Table - tableReference = bindPhysicalTable( type, tableAnn, true, bindingOptions, bindingState, bindingContext ); - } - return tableReference; - } - - private static InLineView bindVirtualTable( - EntityTypeMetadata type, - AnnotationUsage subselectAnn, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final MetadataBuildingContext metadataBuildingContext = bindingState.getMetadataBuildingContext(); - final Identifier logicalName = implicitNamingStrategy( bindingContext ).determinePrimaryTableName( - new ImplicitEntityNameSource() { - @Override - public EntityNaming getEntityNaming() { - return type; - } - - @Override - public MetadataBuildingContext getBuildingContext() { - return metadataBuildingContext; - } - } - ); - - // todo : get rid of metadata-collector handling of tables and handle via table-state - final InFlightMetadataCollector metadataCollector = metadataBuildingContext.getMetadataCollector(); - final org.hibernate.mapping.Table table = metadataCollector.addTable( - null, - null, - logicalName.getCanonicalName(), - subselectAnn.getString( "value" ), - true, - metadataBuildingContext - ); - final PrimaryKey primaryKey = new PrimaryKey( table ); - table.setPrimaryKey( primaryKey ); - primaryKey.setTable( table ); - - return new InLineView( logicalName, table ); - } - - private static PhysicalTableReference bindPhysicalTable( - EntityTypeMetadata type, - AnnotationUsage tableAnn, - boolean isPrimary, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - if ( tableAnn != null ) { - return bindExplicitPhysicalTable( type, tableAnn, isPrimary, bindingOptions, bindingState, bindingContext ); - } - else { - return bindImplicitPhysicalTable( type, isPrimary, bindingOptions, bindingState, bindingContext ); - } - } - - private static PhysicalTable bindExplicitPhysicalTable( - EntityTypeMetadata type, - AnnotationUsage tableAnn, - boolean isPrimary, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final Identifier logicalName = determineLogicalName( type, tableAnn, bindingOptions, bindingState, bindingContext ); - final Identifier logicalSchemaName = resolveDatabaseIdentifier( - tableAnn, - "schema", - bindingOptions.getDefaultSchemaName(), - QuotedIdentifierTarget.SCHEMA_NAME, - bindingOptions, - bindingState, - bindingContext - ); - final Identifier logicalCatalogName = resolveDatabaseIdentifier( - tableAnn, - "catalog", - bindingOptions.getDefaultCatalogName(), - QuotedIdentifierTarget.CATALOG_NAME, - bindingOptions, - bindingState, - bindingContext - ); - - final var table = bindingState.getMetadataBuildingContext().getMetadataCollector().addTable( - logicalSchemaName == null ? null : logicalSchemaName.getCanonicalName(), - logicalCatalogName == null ? null : logicalCatalogName.getCanonicalName(), - logicalName.getCanonicalName(), - null, - type.isAbstract(), - bindingState.getMetadataBuildingContext() - ); - final PrimaryKey primaryKey = new PrimaryKey( table ); - table.setPrimaryKey( primaryKey ); - - applyComment( table, tableAnn, findCommentAnnotation( type, logicalName, isPrimary ) ); - applyOptions( table, tableAnn ); - - final JdbcEnvironment jdbcEnvironment = jdbcEnvironment( bindingContext ); - final PhysicalNamingStrategy physicalNamingStrategy = physicalNamingStrategy( bindingContext ); - - return new PhysicalTable( - logicalName, - logicalCatalogName, - logicalSchemaName, - physicalNamingStrategy.toPhysicalTableName( logicalName, jdbcEnvironment ), - logicalCatalogName == null ? null : physicalNamingStrategy.toPhysicalCatalogName( logicalCatalogName, jdbcEnvironment ), - logicalSchemaName == null ? null : physicalNamingStrategy.toPhysicalSchemaName( logicalSchemaName, jdbcEnvironment ), - table - ); - } - - private static PhysicalTable bindImplicitPhysicalTable( - EntityTypeMetadata type, - boolean isPrimary, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - final Identifier logicalName = determineLogicalName( type, null, bindingOptions, bindingState, bindingContext ); - - final org.hibernate.mapping.Table table = bindingState.getMetadataBuildingContext().getMetadataCollector().addTable( - bindingOptions.getDefaultSchemaName() == null ? null : bindingOptions.getDefaultSchemaName().getCanonicalName(), - bindingOptions.getDefaultCatalogName() == null ? null : bindingOptions.getDefaultCatalogName().getCanonicalName(), - logicalName.getCanonicalName(), - null, - type.isAbstract(), - bindingState.getMetadataBuildingContext() - ); - final PrimaryKey primaryKey = new PrimaryKey( table ); - table.setPrimaryKey( primaryKey ); - - applyComment( - table, - null, - findCommentAnnotation( type, logicalName, isPrimary ) - ); - - final JdbcEnvironment jdbcEnvironment = jdbcEnvironment( bindingContext ); - final PhysicalNamingStrategy physicalNamingStrategy = physicalNamingStrategy( bindingContext ); - - return new PhysicalTable( - logicalName, - bindingOptions.getDefaultCatalogName(), - bindingOptions.getDefaultSchemaName(), - physicalNamingStrategy.toPhysicalTableName( logicalName, jdbcEnvironment ), - physicalNamingStrategy.toPhysicalCatalogName( bindingOptions.getDefaultCatalogName(), jdbcEnvironment ), - physicalNamingStrategy.toPhysicalSchemaName( bindingOptions.getDefaultSchemaName(), jdbcEnvironment ), - table - ); - } - - private static TableReference bindUnionTable( - EntityTypeMetadata type, - AnnotationUsage
tableAnn, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - assert type.getSuperType() != null; - - final TableReference superTypeTable = bindingState.getTableByOwner( type.getSuperType() ); - final org.hibernate.mapping.Table unionBaseTable = superTypeTable.table(); - - final Identifier logicalName = determineLogicalName( type, tableAnn, bindingOptions, bindingState, bindingContext ); - final Identifier logicalSchemaName = resolveDatabaseIdentifier( - tableAnn, - "schema", - bindingOptions.getDefaultSchemaName(), - QuotedIdentifierTarget.SCHEMA_NAME, - bindingOptions, - bindingState, - bindingContext - ); - final Identifier logicalCatalogName = resolveDatabaseIdentifier( - tableAnn, - "catalog", - bindingOptions.getDefaultCatalogName(), - QuotedIdentifierTarget.CATALOG_NAME, - bindingOptions, - bindingState, - bindingContext - ); - - final MetadataBuildingContext buildingContext = bindingState.getMetadataBuildingContext(); - final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector(); - final DenormalizedTable table = (DenormalizedTable) metadataCollector.addDenormalizedTable( - logicalSchemaName == null ? null : logicalSchemaName.getCanonicalName(), - logicalCatalogName == null ? null : logicalCatalogName.getCanonicalName(), - logicalName.getCanonicalName(), - type.isAbstract(), - null, - unionBaseTable, - buildingContext - ); - final PrimaryKey primaryKey = new PrimaryKey( table ); - table.setPrimaryKey( primaryKey ); - - return new UnionTable( logicalName, superTypeTable, table, !type.hasSubTypes() ); - } - - - - - - - private static Identifier determineLogicalName( - EntityTypeMetadata type, - AnnotationUsage tableAnn, - BindingOptions bindingOptions, - BindingState bindingState, - BindingContext bindingContext) { - if ( tableAnn != null ) { - final String name = StringHelper.nullIfEmpty( tableAnn.getString( "name" ) ); - if ( name != null ) { - return BindingHelper.toIdentifier( name, QuotedIdentifierTarget.TABLE_NAME, bindingOptions, jdbcEnvironment( bindingContext ) ); - } - } - - return implicitNamingStrategy( bindingContext ).determinePrimaryTableName( - new ImplicitEntityNameSource() { - @Override - public EntityNaming getEntityNaming() { - return type; - } - - @Override - public MetadataBuildingContext getBuildingContext() { - return bindingState.getMetadataBuildingContext(); - } - } - ); - } - - private static String toCanonicalName(Identifier name) { - if ( name == null ) { - return null; - } - return name.getCanonicalName(); - } - - private static Identifier resolveDatabaseIdentifier( - AnnotationUsage annotationUsage, - String attributeName, - Identifier fallback, - QuotedIdentifierTarget target, - BindingOptions bindingOptions, - @SuppressWarnings("unused") BindingState bindingState, - BindingContext bindingContext) { - if ( annotationUsage == null ) { - return fallback; - } - final String explicitValue = annotationUsage.getString( attributeName ); - if ( StringHelper.isEmpty( explicitValue ) ) { - return fallback; - } - return BindingHelper.toIdentifier( - explicitValue, - target, - bindingOptions, - jdbcEnvironment( bindingContext ) - ); - } - - private static AnnotationUsage findCommentAnnotation( - EntityTypeMetadata type, - Identifier logicalTableName, - boolean isPrimary) { - if ( isPrimary ) { - final AnnotationUsage unnamed = type.getClassDetails().getNamedAnnotationUsage( - Comment.class, - "", - "on" - ); - if ( unnamed != null ) { - return unnamed; - } - } - - return type.getClassDetails().getNamedAnnotationUsage( - Comment.class, - logicalTableName.getCanonicalName(), - "on" - ); - } - - private static void applyComment( - org.hibernate.mapping.Table table, - AnnotationUsage tableAnn, - AnnotationUsage commentAnn) { - if ( commentAnn != null ) { - table.setComment( commentAnn.getString( "value" ) ); - } - else if ( tableAnn != null ) { - final String comment = tableAnn.getString( "comment" ); - if ( StringHelper.isNotEmpty( comment ) ) { - table.setComment( comment ); - } - } - } - - private static void applyOptions(org.hibernate.mapping.Table table, AnnotationUsage tableAnn) { - if ( tableAnn != null ) { - final String options = tableAnn.getString( "options" ); - if ( StringHelper.isNotEmpty( options ) ) { - // todo : add this to Table -// table.setOptions( options ); - throw new UnsupportedOperationException( "Not yet implemented" ); - } - } - } - - private static ImplicitNamingStrategy implicitNamingStrategy(BindingContext bindingContext) { - return bindingContext - .getBootstrapContext() - .getMetadataBuildingOptions() - .getImplicitNamingStrategy(); - } - - private static PhysicalNamingStrategy physicalNamingStrategy(BindingContext bindingContext) { - return bindingContext - .getBootstrapContext() - .getMetadataBuildingOptions() - .getPhysicalNamingStrategy(); - } - - private static JdbcEnvironment jdbcEnvironment(BindingContext bindingContext) { - return bindingContext.getServiceRegistry().getService( JdbcEnvironment.class ); - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/UnionTable.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/UnionTable.java deleted file mode 100644 index b2708b8b47..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/internal/UnionTable.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.internal; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.bind.spi.TableReference; -import org.hibernate.mapping.DenormalizedTable; - -/** - * @author Steve Ebersole - */ -public record UnionTable( - Identifier logicalName, - TableReference base, - DenormalizedTable table, - boolean exportable) implements TableReference { -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingContext.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingContext.java deleted file mode 100644 index 61c8f061dc..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingContext.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -import org.hibernate.boot.internal.ClassmateContext; -import org.hibernate.boot.model.naming.ImplicitNamingStrategy; -import org.hibernate.boot.model.naming.PhysicalNamingStrategy; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.boot.spi.BootstrapContext; -import org.hibernate.models.spi.SourceModelContext; -import org.hibernate.service.ServiceRegistry; - -import jakarta.persistence.SharedCacheMode; - -/** - * Contextual information used while {@linkplain BindingCoordinator table} - * {@linkplain org.hibernate.boot.model.process.spi.ManagedResources managed-resources} into - * into Hibernate's {@linkplain org.hibernate.mapping boot-time model}. - * - * @author Steve Ebersole - */ -public interface BindingContext extends SourceModelContext { - - GlobalRegistrations getGlobalRegistrations(); - - ClassmateContext getClassmateContext(); - - SharedCacheMode getSharedCacheMode(); - - ImplicitNamingStrategy getImplicitNamingStrategy(); - PhysicalNamingStrategy getPhysicalNamingStrategy(); - - BootstrapContext getBootstrapContext(); - - default ServiceRegistry getServiceRegistry() { - return getBootstrapContext().getServiceRegistry(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingCoordinator.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingCoordinator.java deleted file mode 100644 index d4150d3cec..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingCoordinator.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -import org.hibernate.annotations.Any; -import org.hibernate.annotations.ManyToAny; -import org.hibernate.boot.models.AnnotationPlacementException; -import org.hibernate.boot.models.bind.internal.RootEntityBinding; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.models.spi.AnnotationUsage; - -import jakarta.persistence.CollectionTable; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.JoinTable; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; - -import static org.hibernate.boot.models.bind.ModelBindingLogging.MODEL_BINDING_LOGGER; - -/** - * Responsible for processing {@linkplain org.hibernate.boot.model.process.spi.ManagedResources managed-resources} - * and table them into Hibernate's {@linkplain org.hibernate.mapping boot-time model}. - * - * @author Steve Ebersole - */ -public class BindingCoordinator { - private final CategorizedDomainModel categorizedDomainModel; - private final BindingState bindingState; - private final BindingOptions bindingOptions; - private final BindingContext bindingContext; - - public BindingCoordinator( - CategorizedDomainModel categorizedDomainModel, - BindingState bindingState, - BindingOptions bindingOptions, - BindingContext bindingContext) { - this.categorizedDomainModel = categorizedDomainModel; - this.bindingOptions = bindingOptions; - this.bindingState = bindingState; - this.bindingContext = bindingContext; - } - - /** - * Main entry point into this table coordination - * - * @param categorizedDomainModel The model to be processed - * @param options Options for the table - * @param bindingContext Access to needed information and delegates - */ - public static void coordinateBinding( - CategorizedDomainModel categorizedDomainModel, - BindingState state, - BindingOptions options, - BindingContext bindingContext) { - final BindingCoordinator coordinator = new BindingCoordinator( - categorizedDomainModel, - state, - options, - bindingContext - ); - - coordinator.coordinateBinding(); - } - - private void coordinateBinding() { - // todo : to really work on these, need to changes to MetadataBuildingContext/InFlightMetadataCollector - - coordinateGlobalBindings(); - coordinateModelBindings(); - } - - private void coordinateModelBindings() { - // process hierarchy - categorizedDomainModel.forEachEntityHierarchy( this::processHierarchy ); - - // complete tables -// modelBinders.getTableBinder().processSecondPasses(); - -// bindingState.forEachType( this::processModelSecondPasses ); - } - -// private void processModelSecondPasses(String typeName, ManagedTypeBinding table) { -// table.processSecondPasses(); -// } - - private void coordinateGlobalBindings() { - processGenerators( categorizedDomainModel.getGlobalRegistrations() ); - processConverters( categorizedDomainModel.getGlobalRegistrations() ); - processJavaTypeRegistrations( categorizedDomainModel.getGlobalRegistrations() ); - processJdbcTypeRegistrations( categorizedDomainModel.getGlobalRegistrations() ); - processCustomTypes( categorizedDomainModel.getGlobalRegistrations() ); - processInstantiators( categorizedDomainModel.getGlobalRegistrations() ); - processEventListeners( categorizedDomainModel.getGlobalRegistrations() ); - processFilterDefinitions( categorizedDomainModel.getGlobalRegistrations() ); - } - - private RootEntityBinding processHierarchy(int index, EntityHierarchy hierarchy) { - final EntityTypeMetadata rootTypeMetadata = hierarchy.getRoot(); - - MODEL_BINDING_LOGGER.tracef( "Creating root entity table - %s", rootTypeMetadata.getEntityName() ); - - return new RootEntityBinding( rootTypeMetadata, bindingOptions, bindingState, bindingContext ); - } - - private void processGenerators(GlobalRegistrations globalRegistrations) { - // todo : process these - globalRegistrations.getSequenceGeneratorRegistrations(); - globalRegistrations.getTableGeneratorRegistrations(); - globalRegistrations.getGenericGeneratorRegistrations(); - } - - private void processConverters(GlobalRegistrations globalRegistrations) { - - // todo : process these - globalRegistrations.getConverterRegistrations(); - } - - private void processJavaTypeRegistrations(GlobalRegistrations globalRegistrations) { - // todo : process these - globalRegistrations.getJavaTypeRegistrations(); - } - - private void processJdbcTypeRegistrations(GlobalRegistrations globalRegistrations) { - // todo : process these - globalRegistrations.getJdbcTypeRegistrations(); - } - - private void processCustomTypes(GlobalRegistrations globalRegistrations) { - // todo : process these - globalRegistrations.getUserTypeRegistrations(); - globalRegistrations.getCompositeUserTypeRegistrations(); - globalRegistrations.getCollectionTypeRegistrations(); - } - - private void processInstantiators(GlobalRegistrations globalRegistrations) { - // todo : process these - globalRegistrations.getEmbeddableInstantiatorRegistrations(); - } - - private void processEventListeners(GlobalRegistrations globalRegistrations) { - // todo : process these - globalRegistrations.getEntityListenerRegistrations(); - } - - private void processFilterDefinitions(GlobalRegistrations globalRegistrations) { - globalRegistrations.getFilterDefRegistrations().forEach( (s, filterDefRegistration) -> { - bindingState.apply( filterDefRegistration ); - } ); - - } - - private void processTables(AttributeMetadata attribute) { - final AnnotationUsage joinTableAnn = attribute.getMember().getAnnotationUsage( JoinTable.class ); - final AnnotationUsage collectionTableAnn = attribute.getMember().getAnnotationUsage( CollectionTable.class ); - - final AnnotationUsage oneToOneAnn = attribute.getMember().getAnnotationUsage( OneToOne.class ); - final AnnotationUsage manyToOneAnn = attribute.getMember().getAnnotationUsage( ManyToOne.class ); - final AnnotationUsage elementCollectionAnn = attribute.getMember().getAnnotationUsage( ElementCollection.class ); - final AnnotationUsage oneToManyAnn = attribute.getMember().getAnnotationUsage( OneToMany.class ); - final AnnotationUsage anyAnn = attribute.getMember().getAnnotationUsage( Any.class ); - final AnnotationUsage manyToAnyAnn = attribute.getMember().getAnnotationUsage( ManyToAny.class ); - - final boolean hasAnyTableAnnotations = joinTableAnn != null - || collectionTableAnn != null; - - final boolean hasAnyAssociationAnnotations = oneToOneAnn != null - || manyToOneAnn != null - || elementCollectionAnn != null - || oneToManyAnn != null - || anyAnn != null - || manyToAnyAnn != null; - - if ( !hasAnyAssociationAnnotations ) { - if ( hasAnyTableAnnotations ) { - throw new AnnotationPlacementException( - "@JoinTable or @CollectionTable used on non-association attribute - " + attribute.getMember() - ); - } - } - - if ( elementCollectionAnn != null ) { - if ( joinTableAnn != null ) { - throw new AnnotationPlacementException( - "@JoinTable should not be used with @ElementCollection; use @CollectionTable instead - " + attribute.getMember() - ); - } - - // an element-collection "owns" the collection table, so create it right away - - } - - // ^^ accounting for owning v. "inverse" side - // - // on the owning side we get/create the reference and configure it - // - // on the inverse side we just get the reference. - // - // a cool idea here for "smarter second-pass"... on the inverse side - - // TableReference mappedTable = bindingState. - // - - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingOptions.java deleted file mode 100644 index a4ce7e04d1..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingOptions.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -import java.util.EnumSet; - -import org.hibernate.boot.model.naming.Identifier; - -/** - * @author Steve Ebersole - */ -public interface BindingOptions { - Identifier getDefaultCatalogName(); - Identifier getDefaultSchemaName(); - - EnumSet getGloballyQuotedIdentifierTargets(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingState.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingState.java deleted file mode 100644 index 8616e80579..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/BindingState.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -import org.hibernate.boot.model.relational.Database; -import org.hibernate.boot.models.bind.internal.IdentifiableTypeBinding; -import org.hibernate.boot.models.bind.internal.ManagedTypeBinding; -import org.hibernate.boot.models.bind.internal.SecondaryTable; -import org.hibernate.boot.models.categorize.spi.FilterDefRegistration; -import org.hibernate.boot.models.categorize.spi.ManagedTypeMetadata; -import org.hibernate.boot.models.categorize.spi.TableOwner; -import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.engine.jdbc.spi.JdbcServices; -import org.hibernate.internal.util.KeyedConsumer; -import org.hibernate.models.spi.ClassDetails; - -/** - * The idea here is mostly the role filled by InFlightMetadataCollector upstream. - * We should incorporate any improvements here into there when we move this upstream. - * - * @author Steve Ebersole - */ -public interface BindingState { - MetadataBuildingContext getMetadataBuildingContext(); - - default Database getDatabase() { - return getMetadataBuildingContext().getMetadataCollector().getDatabase(); - } - - JdbcServices getJdbcServices(); - - void apply(FilterDefRegistration registration); - - int getTableCount(); - void forEachTable(KeyedConsumer consumer); - T getTableByName(String name); - T getTableByOwner(TableOwner owner); - void addTable(TableOwner owner, TableReference table); - void addSecondaryTable(SecondaryTable table); - - - void registerTypeBinding(ManagedTypeMetadata type, ManagedTypeBinding binding); - ManagedTypeBinding getTypeBinding(ClassDetails type); - default ManagedTypeBinding getTypeBinding(ManagedTypeMetadata type) { - return getTypeBinding( type.getClassDetails() ); - } - - IdentifiableTypeBinding getSuperTypeBinding(ClassDetails type); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/PersistentTableReference.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/PersistentTableReference.java deleted file mode 100644 index 7e6c1c6268..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/PersistentTableReference.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -/** - * @author Steve Ebersole - */ -public interface PersistentTableReference extends TableReference, SchemaAware { -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/QuotedIdentifierTarget.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/QuotedIdentifierTarget.java deleted file mode 100644 index 33994f26c5..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/QuotedIdentifierTarget.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -/** - * @author Steve Ebersole - */ -public enum QuotedIdentifierTarget { - CATALOG_NAME, - SCHEMA_NAME, - TABLE_NAME, - SEQUENCE_NAME, - CALLABLE_NAME, - FOREIGN_KEY, - FOREIGN_DEFINITION, - INDEX, - TYPE_NAME, - COLUMN_NAME, - COLUMN_DEFINITION -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/SchemaAware.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/SchemaAware.java deleted file mode 100644 index 562a6d2929..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/SchemaAware.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -import org.hibernate.boot.model.naming.Identifier; - -/** - * @author Steve Ebersole - */ -public interface SchemaAware { - Identifier getPhysicalSchemaName(); - Identifier getLogicalSchemaName(); - - Identifier getPhysicalCatalogName(); - Identifier getLogicalCatalogName(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/TableReference.java b/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/TableReference.java deleted file mode 100644 index cf73ea5f3b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/bind/spi/TableReference.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.bind.spi; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.models.bind.internal.InLineView; -import org.hibernate.boot.models.bind.internal.PhysicalTable; -import org.hibernate.boot.models.bind.internal.PhysicalView; -import org.hibernate.boot.models.bind.internal.SecondaryTable; -import org.hibernate.mapping.Table; - -/** - * Following the ANSI SQL "table reference" rule, will be one of
    - *
  • a {@linkplain PhysicalTable physical table}
  • - *
  • a {@linkplain SecondaryTable secondary table}
  • - *
  • a {@linkplain PhysicalView physical view}
  • - *
  • a {@linkplain InLineView in-line view}
  • - *
- * - * @author Steve Ebersole - */ -public interface TableReference { - /** - * The name used across the metamodel sources (in the annotations, XML, etc...). - * In the case of physical tables and views, the logical name might not be the same - * as the table or view name (through {@linkplain org.hibernate.boot.model.naming.PhysicalNamingStrategy}, e.g.). - */ - Identifier logicalName(); - - /** - * Should this "table" be exposed to schema tooling? - */ - boolean exportable(); - - Table table(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java index c8d918e9c8..de6d10b438 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java @@ -15,12 +15,12 @@ import java.util.function.Consumer; import org.hibernate.boot.models.categorize.spi.ClassAttributeAccessType; import org.hibernate.boot.models.categorize.spi.EntityHierarchy; import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle; import org.hibernate.boot.models.categorize.spi.MappedSuperclassTypeMetadata; import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; @@ -195,7 +195,7 @@ public abstract class AbstractIdentifiableTypeMetadata final List combined = new ArrayList<>(); - if ( classDetails.getAnnotationUsage( ExcludeSuperclassListeners.class ) == null ) { + if ( !classDetails.hasDirectAnnotationUsage( ExcludeSuperclassListeners.class ) ) { final IdentifiableTypeMetadata superType = getSuperType(); if ( superType != null ) { combined.addAll( superType.getHierarchyJpaEventListeners() ); @@ -214,24 +214,27 @@ public abstract class AbstractIdentifiableTypeMetadata private void applyLocalEventListeners(Consumer consumer) { final ClassDetails classDetails = getClassDetails(); - final AnnotationUsage entityListenersAnnotation = classDetails.getAnnotationUsage( EntityListeners.class ); + final EntityListeners entityListenersAnnotation = classDetails.getDirectAnnotationUsage( EntityListeners.class ); if ( entityListenersAnnotation == null ) { return; } - final List entityListenerClasses = entityListenersAnnotation.getAttributeValue( "value" ); + final Class[] entityListenerClasses = entityListenersAnnotation.value(); if ( CollectionHelper.isEmpty( entityListenerClasses ) ) { return; } - entityListenerClasses.forEach( (listenerClass) -> { - consumer.accept( JpaEventListener.from( JpaEventListenerStyle.LISTENER, listenerClass ) ); + ArrayHelper.forEach( entityListenerClasses, (listenerClass) -> { + consumer.accept( JpaEventListener.from( + JpaEventListenerStyle.LISTENER, + getModelContext().getClassDetailsRegistry().findClassDetails( listenerClass.getName() ) + ) ); } ); } protected List collectCompleteEventListeners(ModelCategorizationContext modelContext) { final ClassDetails classDetails = getClassDetails(); - if ( classDetails.getAnnotationUsage( ExcludeDefaultListeners.class ) != null ) { + if ( classDetails.hasDirectAnnotationUsage( ExcludeDefaultListeners.class ) ) { return getHierarchyJpaEventListeners(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java index daa3bfec97..f8a58abffd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java @@ -12,7 +12,6 @@ import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; -import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.categorize.spi.AllMemberConsumer; import org.hibernate.boot.models.categorize.spi.ClassAttributeAccessType; import org.hibernate.boot.models.categorize.spi.PersistentAttributeMemberResolver; @@ -21,6 +20,8 @@ import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.MethodDetails; +import jakarta.persistence.Transient; + /** * "Template" support for writing PersistentAttributeMemberResolver * implementations. @@ -82,7 +83,7 @@ public abstract class AbstractPersistentAttributeMemberResolver implements Persi for ( int i = 0; i < fields.size(); i++ ) { final FieldDetails fieldDetails = fields.get( i ); memberConsumer.acceptMember( fieldDetails ); - if ( fieldDetails.getAnnotationUsage( JpaAnnotations.TRANSIENT ) != null ) { + if ( fieldDetails.hasDirectAnnotationUsage( Transient.class ) ) { transientFieldConsumer.accept( fieldDetails ); } } @@ -91,7 +92,7 @@ public abstract class AbstractPersistentAttributeMemberResolver implements Persi for ( int i = 0; i < methods.size(); i++ ) { final MethodDetails methodDetails = methods.get( i ); memberConsumer.acceptMember( methodDetails ); - if ( methodDetails.getAnnotationUsage( JpaAnnotations.TRANSIENT ) != null ) { + if ( methodDetails.hasDirectAnnotationUsage( Transient.class ) ) { transientMethodConsumer.accept( methodDetails ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java index 8351481dea..2add6b0895 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java @@ -9,28 +9,47 @@ package org.hibernate.boot.models.categorize.internal; import java.util.EnumSet; import org.hibernate.annotations.Any; +import org.hibernate.annotations.AnyDiscriminator; +import org.hibernate.annotations.AnyKeyJavaClass; +import org.hibernate.annotations.AnyKeyJavaType; +import org.hibernate.annotations.AnyKeyJdbcType; +import org.hibernate.annotations.AnyKeyJdbcTypeCode; +import org.hibernate.annotations.CompositeType; +import org.hibernate.annotations.EmbeddableInstantiator; +import org.hibernate.annotations.JavaType; +import org.hibernate.annotations.JdbcType; +import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.annotations.ManyToAny; +import org.hibernate.annotations.Nationalized; import org.hibernate.annotations.TenantId; +import org.hibernate.annotations.TimeZoneColumn; +import org.hibernate.annotations.TimeZoneStorage; +import org.hibernate.annotations.Type; import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.MultipleAttributeNaturesException; import org.hibernate.boot.models.categorize.spi.AttributeMetadata; import org.hibernate.boot.models.categorize.spi.ClassAttributeAccessType; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MemberDetails; import jakarta.persistence.Access; import jakarta.persistence.AccessType; import jakarta.persistence.Basic; import jakarta.persistence.ElementCollection; +import jakarta.persistence.Embeddable; import jakarta.persistence.Embedded; import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Lob; import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; +import jakarta.persistence.MappedSuperclass; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import jakarta.persistence.Temporal; +import jakarta.persistence.Version; import static org.hibernate.boot.models.categorize.ModelCategorizationLogging.MODEL_CATEGORIZATION_LOGGER; import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.BASIC; @@ -44,12 +63,16 @@ import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.Attribu * @author Steve Ebersole */ public class CategorizationHelper { + public static ClassDetails toClassDetails(Class clazz, ClassDetailsRegistry classDetailsRegistry) { + return classDetailsRegistry.resolveClassDetails( clazz.getName() ); + } + public static boolean isMappedSuperclass(ClassDetails classDetails) { - return classDetails.getAnnotationUsage( JpaAnnotations.MAPPED_SUPERCLASS ) != null; + return classDetails.hasDirectAnnotationUsage( MappedSuperclass.class ); } public static boolean isEntity(ClassDetails classDetails) { - return classDetails.getAnnotationUsage( JpaAnnotations.ENTITY ) != null; + return classDetails.getDirectAnnotationUsage( Entity.class ) != null; } public static boolean isIdentifiable(ClassDetails classDetails) { @@ -57,9 +80,9 @@ public class CategorizationHelper { } public static ClassAttributeAccessType determineAccessType(ClassDetails classDetails, AccessType implicitAccessType) { - final AnnotationUsage annotation = classDetails.getAnnotationUsage( JpaAnnotations.ACCESS ); + final Access annotation = classDetails.getDirectAnnotationUsage( Access.class ); if ( annotation != null ) { - final AccessType explicitValue = annotation.getAttributeValue( "value" ); + final AccessType explicitValue = annotation.value(); assert explicitValue != null; return explicitValue == AccessType.FIELD ? ClassAttributeAccessType.EXPLICIT_FIELD @@ -82,16 +105,16 @@ public class CategorizationHelper { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // first, look for explicit nature annotations - final AnnotationUsage any = backingMember.getAnnotationUsage( HibernateAnnotations.ANY ); - final AnnotationUsage basic = backingMember.getAnnotationUsage( JpaAnnotations.BASIC ); - final AnnotationUsage elementCollection = backingMember.getAnnotationUsage( JpaAnnotations.ELEMENT_COLLECTION ); - final AnnotationUsage embedded = backingMember.getAnnotationUsage( JpaAnnotations.EMBEDDED ); - final AnnotationUsage embeddedId = backingMember.getAnnotationUsage( JpaAnnotations.EMBEDDED_ID ); - final AnnotationUsage manyToAny = backingMember.getAnnotationUsage( HibernateAnnotations.MANY_TO_ANY ); - final AnnotationUsage manyToMany = backingMember.getAnnotationUsage( JpaAnnotations.MANY_TO_MANY ); - final AnnotationUsage manyToOne = backingMember.getAnnotationUsage( JpaAnnotations.MANY_TO_ONE ); - final AnnotationUsage oneToMany = backingMember.getAnnotationUsage( JpaAnnotations.ONE_TO_MANY ); - final AnnotationUsage oneToOne = backingMember.getAnnotationUsage( JpaAnnotations.ONE_TO_ONE ); + final Any any = backingMember.getDirectAnnotationUsage( Any.class ); + final Basic basic = backingMember.getDirectAnnotationUsage( Basic.class ); + final ElementCollection elementCollection = backingMember.getDirectAnnotationUsage( ElementCollection.class ); + final Embedded embedded = backingMember.getDirectAnnotationUsage( Embedded.class ); + final EmbeddedId embeddedId = backingMember.getDirectAnnotationUsage( EmbeddedId.class ); + final ManyToAny manyToAny = backingMember.getDirectAnnotationUsage( ManyToAny.class ); + final ManyToMany manyToMany = backingMember.getDirectAnnotationUsage( ManyToMany.class ); + final ManyToOne manyToOne = backingMember.getDirectAnnotationUsage( ManyToOne.class ); + final OneToMany oneToMany = backingMember.getDirectAnnotationUsage( OneToMany.class ); + final OneToOne oneToOne = backingMember.getDirectAnnotationUsage( OneToOne.class ); if ( basic != null ) { natures.add( AttributeMetadata.AttributeNature.BASIC ); @@ -99,7 +122,7 @@ public class CategorizationHelper { if ( embedded != null || embeddedId != null - || ( backingMember.getType() != null && backingMember.getType().determineRawClass().getAnnotationUsage( JpaAnnotations.EMBEDDABLE ) != null ) ) { + || ( backingMember.getType() != null && backingMember.getType().determineRawClass().hasDirectAnnotationUsage( Embeddable.class ) ) ) { natures.add( EMBEDDED ); } @@ -134,30 +157,30 @@ public class CategorizationHelper { || elementCollection != null || manyToAny != null; - final boolean implicitlyBasic = backingMember.getAnnotationUsage( JpaAnnotations.TEMPORAL ) != null - || backingMember.getAnnotationUsage( JpaAnnotations.LOB ) != null - || backingMember.getAnnotationUsage( JpaAnnotations.ENUMERATED ) != null - || backingMember.getAnnotationUsage( JpaAnnotations.VERSION ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.GENERATED ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.NATIONALIZED ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.TZ_COLUMN ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.TZ_STORAGE ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.TYPE ) != null - || backingMember.getAnnotationUsage( TenantId.class ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.JAVA_TYPE ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.JDBC_TYPE_CODE ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.JDBC_TYPE ) != null; + final boolean implicitlyBasic = backingMember.hasDirectAnnotationUsage( Temporal.class ) + || backingMember.hasDirectAnnotationUsage( Lob.class ) + || backingMember.hasDirectAnnotationUsage( Enumerated.class ) + || backingMember.hasDirectAnnotationUsage( Version.class ) + || backingMember.hasDirectAnnotationUsage( HibernateAnnotations.GENERATED.getAnnotationType() ) + || backingMember.hasDirectAnnotationUsage( Nationalized.class ) + || backingMember.hasDirectAnnotationUsage( TimeZoneColumn.class ) + || backingMember.hasDirectAnnotationUsage( TimeZoneStorage.class ) + || backingMember.hasDirectAnnotationUsage( Type.class ) + || backingMember.hasDirectAnnotationUsage( TenantId.class ) + || backingMember.hasDirectAnnotationUsage( JavaType.class ) + || backingMember.hasDirectAnnotationUsage( JdbcType.class ) + || backingMember.hasDirectAnnotationUsage( JdbcTypeCode.class ); - final boolean implicitlyEmbedded = backingMember.getAnnotationUsage( HibernateAnnotations.EMBEDDABLE_INSTANTIATOR ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.COMPOSITE_TYPE ) != null; + final boolean implicitlyEmbedded = backingMember.hasDirectAnnotationUsage( EmbeddableInstantiator.class ) + || backingMember.hasDirectAnnotationUsage( CompositeType.class ); - final boolean implicitlyAny = backingMember.getAnnotationUsage( HibernateAnnotations.ANY_DISCRIMINATOR ) != null - || CollectionHelper.isNotEmpty( backingMember.getRepeatedAnnotationUsages( HibernateAnnotations.ANY_DISCRIMINATOR_VALUE ) ) - || backingMember.getAnnotationUsage( HibernateAnnotations.ANY_DISCRIMINATOR_VALUES ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.ANY_KEY_JAVA_TYPE ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.ANY_KEY_JAVA_CLASS ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.ANY_KEY_JDBC_TYPE ) != null - || backingMember.getAnnotationUsage( HibernateAnnotations.ANY_KEY_JDBC_TYPE_CODE ) != null; + final boolean implicitlyAny = backingMember.hasDirectAnnotationUsage( AnyDiscriminator.class ) +// || CollectionHelper.isNotEmpty( backingMember.getRepeatedAnnotationUsages( HibernateAnnotations.ANY_DISCRIMINATOR_VALUE ) ) +// || backingMember.hasDirectAnnotationUsage( HibernateAnnotations.ANY_DISCRIMINATOR_VALUES ) + || backingMember.hasDirectAnnotationUsage( AnyKeyJavaType.class ) + || backingMember.hasDirectAnnotationUsage( AnyKeyJavaClass.class ) + || backingMember.hasDirectAnnotationUsage( AnyKeyJdbcType.class ) + || backingMember.hasDirectAnnotationUsage( AnyKeyJdbcTypeCode.class ); if ( !plural ) { // first implicit basic nature diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizedDomainModelImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizedDomainModelImpl.java index e9c615e4ff..1a4f301645 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizedDomainModelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizedDomainModelImpl.java @@ -11,7 +11,7 @@ import java.util.Set; import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; +import org.hibernate.boot.models.spi.GlobalRegistrations; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; import org.hibernate.models.spi.AnnotationDescriptorRegistry; import org.hibernate.models.spi.ClassDetails; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyBuilder.java index 98bce176dd..a182983d86 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyBuilder.java @@ -10,13 +10,11 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.categorize.spi.EntityHierarchy; import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.FieldDetails; @@ -24,6 +22,9 @@ import org.hibernate.models.spi.MethodDetails; import jakarta.persistence.Access; import jakarta.persistence.AccessType; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; /** * Builds {@link EntityHierarchy} references from @@ -121,9 +122,9 @@ public class EntityHierarchyBuilder { private AccessType resolveDefaultAccessTypeFromClassAnnotation(ClassDetails rootEntityType) { ClassDetails current = rootEntityType; while ( current != null ) { - final AnnotationUsage accessAnnotation = current.getAnnotationUsage( JpaAnnotations.ACCESS ); + final Access accessAnnotation = current.getDirectAnnotationUsage( Access.class ); if ( accessAnnotation != null ) { - return accessAnnotation.getAttributeValue( "value" ); + return accessAnnotation.value(); } current = current.getSuperClass(); @@ -161,9 +162,9 @@ public class EntityHierarchyBuilder { final List methods = current.getMethods(); for ( int i = 0; i < methods.size(); i++ ) { final MethodDetails methodDetails = methods.get( i ); - if ( methodDetails.getAnnotationUsage( JpaAnnotations.ID ) != null - || methodDetails.getAnnotationUsage( JpaAnnotations.EMBEDDED_ID ) != null ) { - if ( methodDetails.getAnnotationUsage( Access.class ) == null ) { + if ( methodDetails.hasDirectAnnotationUsage( Id.class ) + || methodDetails.hasDirectAnnotationUsage( EmbeddedId.class ) ) { + if ( methodDetails.getDirectAnnotationUsage( Access.class ) == null ) { return methodDetails; } } @@ -172,9 +173,9 @@ public class EntityHierarchyBuilder { final List fields = current.getFields(); for ( int i = 0; i < fields.size(); i++ ) { final FieldDetails fieldDetails = fields.get( i ); - if ( fieldDetails.getAnnotationUsage( JpaAnnotations.ID ) != null - || fieldDetails.getAnnotationUsage( JpaAnnotations.EMBEDDED_ID ) != null ) { - if ( fieldDetails.getAnnotationUsage( Access.class ) == null ) { + if ( fieldDetails.hasDirectAnnotationUsage( Id.class ) + || fieldDetails.hasDirectAnnotationUsage( EmbeddedId.class ) ) { + if ( fieldDetails.getDirectAnnotationUsage( Access.class ) == null ) { return fieldDetails; } } @@ -191,7 +192,7 @@ public class EntityHierarchyBuilder { final Set collectedTypes = new HashSet<>(); classDetailsRegistry.forEachClassDetails( (managedType) -> { - if ( managedType.getAnnotationUsage( JpaAnnotations.ENTITY ) != null + if ( managedType.getDirectAnnotationUsage( Entity.class ) != null && isRoot( managedType ) ) { collectedTypes.add( managedType ); } @@ -213,7 +214,7 @@ public class EntityHierarchyBuilder { ClassDetails current = classInfo.getSuperClass(); while ( current != null ) { - if ( current.getAnnotationUsage( JpaAnnotations.ENTITY ) != null && !current.isAbstract() ) { + if ( current.getDirectAnnotationUsage( Entity.class ) != null && !current.isAbstract() ) { // a non-abstract super type has `@Entity` -> classInfo cannot be a root entity return false; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyImpl.java index 10447ed97b..e63bb2c042 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyImpl.java @@ -12,7 +12,6 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.NaturalIdCache; import org.hibernate.annotations.OptimisticLockType; import org.hibernate.annotations.OptimisticLocking; -import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.categorize.ModelCategorizationLogging; import org.hibernate.boot.models.categorize.spi.AttributeMetadata; import org.hibernate.boot.models.categorize.spi.CacheRegion; @@ -24,7 +23,6 @@ import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; import org.hibernate.boot.models.categorize.spi.NaturalIdCacheRegion; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.engine.OptimisticLockStyle; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import jakarta.persistence.Inheritance; @@ -55,11 +53,16 @@ public class EntityHierarchyImpl implements EntityHierarchy { jakarta.persistence.AccessType defaultAccessType, AccessType defaultCacheAccessType, HierarchyTypeConsumer typeConsumer, - ModelCategorizationContext modelBuildingContext) { + ModelCategorizationContext categorizationContext) { this.defaultAccessType = defaultAccessType; final ClassDetails absoluteRootClassDetails = findRootRoot( rootEntityClassDetails ); - final HierarchyMetadataCollector metadataCollector = new HierarchyMetadataCollector( this, rootEntityClassDetails, typeConsumer ); + final HierarchyMetadataCollector metadataCollector = new HierarchyMetadataCollector( + this, + rootEntityClassDetails, + typeConsumer, + categorizationContext + ); if ( CategorizationHelper.isEntity( absoluteRootClassDetails ) ) { this.rootEntityTypeMetadata = new EntityTypeMetadataImpl( @@ -67,7 +70,7 @@ public class EntityHierarchyImpl implements EntityHierarchy { this, defaultAccessType, metadataCollector, - modelBuildingContext + categorizationContext ); this.absoluteRootTypeMetadata = rootEntityTypeMetadata; } @@ -78,14 +81,14 @@ public class EntityHierarchyImpl implements EntityHierarchy { this, defaultAccessType, metadataCollector, - modelBuildingContext + categorizationContext ); this.rootEntityTypeMetadata = new EntityTypeMetadataImpl( rootEntityClassDetails, this, (AbstractIdentifiableTypeMetadata) absoluteRootTypeMetadata, metadataCollector, - modelBuildingContext + categorizationContext ); } @@ -256,18 +259,18 @@ public class EntityHierarchyImpl implements EntityHierarchy { ensureNoInheritanceAnnotationsOnSubclasses( rootEntityTypeMetadata ); } - final AnnotationUsage inheritanceAnnotation = metadataCollector.getInheritanceAnnotation(); + final Inheritance inheritanceAnnotation = metadataCollector.getInheritanceAnnotation(); if ( inheritanceAnnotation != null ) { - return inheritanceAnnotation.getAttributeValue( "strategy" ); + return inheritanceAnnotation.strategy(); } return InheritanceType.SINGLE_TABLE; } private OptimisticLockStyle determineOptimisticLockStyle(HierarchyMetadataCollector metadataCollector) { - final AnnotationUsage optimisticLockingAnnotation = metadataCollector.getOptimisticLockingAnnotation(); + final OptimisticLocking optimisticLockingAnnotation = metadataCollector.getOptimisticLockingAnnotation(); if ( optimisticLockingAnnotation != null ) { - final OptimisticLockType lockingType = optimisticLockingAnnotation.getEnum( "type" ); + final OptimisticLockType lockingType = optimisticLockingAnnotation.type(); return OptimisticLockStyle.fromLockType( lockingType ); } return DEFAULT_LOCKING_STRATEGY; @@ -276,14 +279,14 @@ public class EntityHierarchyImpl implements EntityHierarchy { private CacheRegion determineCacheRegion( HierarchyMetadataCollector metadataCollector, AccessType defaultCacheAccessType) { - final AnnotationUsage cacheAnnotation = metadataCollector.getCacheAnnotation(); + final Cache cacheAnnotation = metadataCollector.getCacheAnnotation(); return new CacheRegion( cacheAnnotation, defaultCacheAccessType, rootEntityTypeMetadata.getEntityName() ); } private NaturalIdCacheRegion determineNaturalIdCacheRegion( HierarchyMetadataCollector metadataCollector, CacheRegion cacheRegion) { - final AnnotationUsage naturalIdCacheAnnotation = metadataCollector.getNaturalIdCacheAnnotation(); + final NaturalIdCache naturalIdCacheAnnotation = metadataCollector.getNaturalIdCacheAnnotation(); return new NaturalIdCacheRegion( naturalIdCacheAnnotation, cacheRegion ); } @@ -294,12 +297,12 @@ public class EntityHierarchyImpl implements EntityHierarchy { * @apiNote Used when building the {@link EntityHierarchy} */ private static InheritanceType getLocallyDefinedInheritanceType(ClassDetails managedClass) { - final AnnotationUsage localAnnotation = managedClass.getAnnotationUsage( JpaAnnotations.INHERITANCE ); + final Inheritance localAnnotation = managedClass.getDirectAnnotationUsage( Inheritance.class ); if ( localAnnotation == null ) { return null; } - return localAnnotation.getAttributeValue( "strategy" ); + return localAnnotation.strategy(); } private void ensureNoInheritanceAnnotationsOnSubclasses(IdentifiableTypeMetadata type) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityTypeMetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityTypeMetadataImpl.java index 4e47677431..47a9193468 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityTypeMetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityTypeMetadataImpl.java @@ -25,15 +25,15 @@ import org.hibernate.annotations.SelectBeforeUpdate; import org.hibernate.annotations.Synchronize; import org.hibernate.boot.model.CustomSql; import org.hibernate.boot.model.naming.EntityNaming; -import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; import org.hibernate.boot.models.categorize.spi.AttributeMetadata; import org.hibernate.boot.models.categorize.spi.EntityHierarchy; import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import jakarta.persistence.AccessType; @@ -41,6 +41,7 @@ import jakarta.persistence.Cacheable; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; +import static org.hibernate.boot.models.categorize.internal.CategorizationHelper.toClassDetails; import static org.hibernate.internal.util.StringHelper.EMPTY_STRINGS; import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.StringHelper.unqualify; @@ -89,7 +90,7 @@ public class EntityTypeMetadataImpl // `ClassDetails#getName` already handles this all for us this.entityName = getClassDetails().getName(); - final AnnotationUsage entityAnnotation = classDetails.getAnnotationUsage( JpaAnnotations.ENTITY ); + final Entity entityAnnotation = classDetails.getDirectAnnotationUsage( Entity.class ); this.jpaEntityName = determineJpaEntityName( entityAnnotation, entityName ); final LifecycleCallbackCollector lifecycleCallbackCollector = new LifecycleCallbackCollector( classDetails, modelContext ); @@ -109,13 +110,12 @@ public class EntityTypeMetadataImpl this.customDeleteMap = extractCustomSql( classDetails, SQLDelete.class ); //noinspection deprecation - final AnnotationUsage proxyAnnotation = classDetails.getAnnotationUsage( Proxy.class ); + final Proxy proxyAnnotation = classDetails.getDirectAnnotationUsage( Proxy.class ); if ( proxyAnnotation != null ) { - final Boolean lazyValue = proxyAnnotation.getAttributeValue( "lazy" ); - this.isLazy = lazyValue == null || lazyValue; + this.isLazy = proxyAnnotation.lazy(); if ( this.isLazy ) { - final ClassDetails proxyClassDetails = proxyAnnotation.getAttributeValue( "proxyClass" ); + final ClassDetails proxyClassDetails = toClassDetails( proxyAnnotation.proxyClass(), modelContext.getClassDetailsRegistry() ); if ( proxyClassDetails != null ) { this.proxy = proxyClassDetails.getName(); } @@ -133,9 +133,9 @@ public class EntityTypeMetadataImpl this.proxy = getEntityName(); } - final AnnotationUsage discriminatorValueAnn = classDetails.getAnnotationUsage( DiscriminatorValue.class ); + final DiscriminatorValue discriminatorValueAnn = classDetails.getDirectAnnotationUsage( DiscriminatorValue.class ); if ( discriminatorValueAnn != null ) { - this.discriminatorMatchValue = discriminatorValueAnn.getAttributeValue( "value" ); + this.discriminatorMatchValue = discriminatorValueAnn.value(); } else { this.discriminatorMatchValue = null; @@ -160,7 +160,7 @@ public class EntityTypeMetadataImpl // `ClassDetails#getName` already handles this all for us this.entityName = getClassDetails().getName(); - final AnnotationUsage entityAnnotation = classDetails.getAnnotationUsage( JpaAnnotations.ENTITY ); + final Entity entityAnnotation = classDetails.getDirectAnnotationUsage( Entity.class ); this.jpaEntityName = determineJpaEntityName( entityAnnotation, entityName ); final LifecycleCallbackCollector lifecycleCallbackCollector = new LifecycleCallbackCollector( classDetails, modelContext ); @@ -180,13 +180,12 @@ public class EntityTypeMetadataImpl this.customDeleteMap = extractCustomSql( classDetails, SQLDelete.class ); //noinspection deprecation - final AnnotationUsage proxyAnnotation = classDetails.getAnnotationUsage( Proxy.class ); + final Proxy proxyAnnotation = classDetails.getDirectAnnotationUsage( Proxy.class ); if ( proxyAnnotation != null ) { - final Boolean lazyValue = proxyAnnotation.getAttributeValue( "lazy" ); - this.isLazy = lazyValue == null || lazyValue; + this.isLazy = proxyAnnotation.lazy(); if ( this.isLazy ) { - final ClassDetails proxyClassDetails = proxyAnnotation.getAttributeValue( "proxyClass" ); + final ClassDetails proxyClassDetails = toClassDetails( proxyAnnotation.proxyClass(), modelContext.getClassDetailsRegistry() ); if ( proxyClassDetails != null ) { this.proxy = proxyClassDetails.getName(); } @@ -204,9 +203,9 @@ public class EntityTypeMetadataImpl this.proxy = getEntityName(); } - final AnnotationUsage discriminatorValueAnn = classDetails.getAnnotationUsage( DiscriminatorValue.class ); + final DiscriminatorValue discriminatorValueAnn = classDetails.getDirectAnnotationUsage( DiscriminatorValue.class ); if ( discriminatorValueAnn != null ) { - this.discriminatorMatchValue = discriminatorValueAnn.getAttributeValue( "value" ); + this.discriminatorMatchValue = discriminatorValueAnn.value(); } else { this.discriminatorMatchValue = null; @@ -308,8 +307,8 @@ public class EntityTypeMetadataImpl } - private String determineJpaEntityName(AnnotationUsage entityAnnotation, String entityName) { - final String name = entityAnnotation.getAttributeValue( "name" ); + private String determineJpaEntityName(Entity entityAnnotation, String entityName) { + final String name = entityAnnotation.name(); if ( isNotEmpty( name ) ) { return name; } @@ -317,14 +316,14 @@ public class EntityTypeMetadataImpl } private boolean determineMutability(ClassDetails classDetails, ModelCategorizationContext modelContext) { - final AnnotationUsage immutableAnn = classDetails.getAnnotationUsage( Immutable.class ); + final Immutable immutableAnn = classDetails.getDirectAnnotationUsage( Immutable.class ); return immutableAnn == null; } private boolean determineCacheability( ClassDetails classDetails, ModelCategorizationContext modelContext) { - final AnnotationUsage cacheableAnn = classDetails.getAnnotationUsage( Cacheable.class ); + final Cacheable cacheableAnn = classDetails.getDirectAnnotationUsage( Cacheable.class ); switch ( modelContext.getSharedCacheMode() ) { case NONE: { return false; @@ -335,7 +334,7 @@ public class EntityTypeMetadataImpl case DISABLE_SELECTIVE: { // Disable caching for all `@Cacheable(false)`, enabled otherwise (including no annotation) //noinspection RedundantIfStatement - if ( cacheableAnn == null || cacheableAnn.getBoolean( "value" ) ) { + if ( cacheableAnn == null || cacheableAnn.value() ) { // not disabled return true; } @@ -350,7 +349,7 @@ public class EntityTypeMetadataImpl // Enable caching for all `@Cacheable(true)`, disable otherwise (including no annotation) //noinspection RedundantIfStatement - if ( cacheableAnn != null && cacheableAnn.getBoolean( "value" ) ) { + if ( cacheableAnn != null && cacheableAnn.value() ) { // enable, there was an explicit `@Cacheable(true)` return true; } @@ -367,17 +366,18 @@ public class EntityTypeMetadataImpl * or {@link org.hibernate.annotations.SQLDeleteAll} annotations */ public static
Map extractCustomSql(ClassDetails classDetails, Class annotationType) { - final List> annotationUsages = classDetails.getRepeatedAnnotationUsages( annotationType ); + final A[] annotationUsages = classDetails.getRepeatedAnnotationUsages( annotationType, null ); if ( CollectionHelper.isEmpty( annotationUsages ) ) { return Collections.emptyMap(); } final Map result = new HashMap<>(); - annotationUsages.forEach( (customSqlAnnotation) -> { - final String sql = customSqlAnnotation.getAttributeValue( "sql" ); - final boolean isCallable = customSqlAnnotation.getAttributeValue( "callable" ); + ArrayHelper.forEach( annotationUsages, (customSqlAnnotation) -> { + final CustomSqlDetails customSqlDetails = (CustomSqlDetails) customSqlAnnotation; + final String sql = customSqlDetails.sql(); + final boolean isCallable = customSqlDetails.callable(); - final ResultCheckStyle checkValue = customSqlAnnotation.getAttributeValue( "check" ); + final ResultCheckStyle checkValue = customSqlDetails.check(); final ExecuteUpdateResultCheckStyle checkStyle; if ( checkValue == null ) { checkStyle = isCallable @@ -389,7 +389,7 @@ public class EntityTypeMetadataImpl } result.put( - customSqlAnnotation.getString( "table" ), + customSqlDetails.table(), new CustomSql( sql, isCallable, checkStyle ) ); } ); @@ -397,44 +397,44 @@ public class EntityTypeMetadataImpl } private String[] determineSynchronizedTableNames() { - final AnnotationUsage synchronizeAnnotation = getClassDetails().getAnnotationUsage( Synchronize.class ); + final Synchronize synchronizeAnnotation = getClassDetails().getDirectAnnotationUsage( Synchronize.class ); if ( synchronizeAnnotation != null ) { - return synchronizeAnnotation.getList( "value" ).toArray( new String[0] ); + return synchronizeAnnotation.value(); } return EMPTY_STRINGS; } private int determineBatchSize() { - final AnnotationUsage batchSizeAnnotation = getClassDetails().getAnnotationUsage( BatchSize.class ); + final BatchSize batchSizeAnnotation = getClassDetails().getDirectAnnotationUsage( BatchSize.class ); if ( batchSizeAnnotation != null ) { - return batchSizeAnnotation.getAttributeValue( "size" ); + return batchSizeAnnotation.size(); } return -1; } private boolean decodeSelectBeforeUpdate() { //noinspection deprecation - final AnnotationUsage selectBeforeUpdateAnnotation = getClassDetails().getAnnotationUsage( SelectBeforeUpdate.class ); + final SelectBeforeUpdate selectBeforeUpdateAnnotation = getClassDetails().getDirectAnnotationUsage( SelectBeforeUpdate.class ); if ( selectBeforeUpdateAnnotation == null ) { return false; } - return selectBeforeUpdateAnnotation.getBoolean( "value" ); + return selectBeforeUpdateAnnotation.value(); } private boolean decodeDynamicInsert() { - final AnnotationUsage dynamicInsertAnnotation = getClassDetails().getAnnotationUsage( DynamicInsert.class ); + final DynamicInsert dynamicInsertAnnotation = getClassDetails().getDirectAnnotationUsage( DynamicInsert.class ); if ( dynamicInsertAnnotation == null ) { return false; } - return dynamicInsertAnnotation.getBoolean( "value" ); + return dynamicInsertAnnotation.value(); } private boolean decodeDynamicUpdate() { - final AnnotationUsage dynamicUpdateAnnotation = getClassDetails().getAnnotationUsage( DynamicUpdate.class ); + final DynamicUpdate dynamicUpdateAnnotation = getClassDetails().getDirectAnnotationUsage( DynamicUpdate.class ); if ( dynamicUpdateAnnotation == null ) { return false; } - return dynamicUpdateAnnotation.getBoolean( "value" ); + return dynamicUpdateAnnotation.value(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/HierarchyMetadataCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/HierarchyMetadataCollector.java index 62d66b587a..9b2354a5ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/HierarchyMetadataCollector.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/HierarchyMetadataCollector.java @@ -22,8 +22,8 @@ import org.hibernate.boot.models.categorize.spi.EntityHierarchy; import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; import org.hibernate.boot.models.categorize.spi.KeyMapping; +import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; import org.hibernate.models.ModelsException; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; @@ -45,30 +45,33 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { private final EntityHierarchy entityHierarchy; private final ClassDetails rootEntityClassDetails; private final HierarchyTypeConsumer delegateConsumer; + private final ModelCategorizationContext categorizationContext; private boolean belowRootEntity; private EntityTypeMetadata rootEntityMetadata; - private AnnotationUsage inheritanceAnnotation; - private AnnotationUsage optimisticLockingAnnotation; - private AnnotationUsage cacheAnnotation; - private AnnotationUsage naturalIdCacheAnnotation; + private Inheritance inheritanceAnnotation; + private OptimisticLocking optimisticLockingAnnotation; + private Cache cacheAnnotation; + private NaturalIdCache naturalIdCacheAnnotation; private KeyMapping idMapping; private AttributeMetadata versionAttribute; private AttributeMetadata tenantIdAttribute; - private AnnotationUsage idClassAnnotation; + private IdClass idClassAnnotation; private Object collectedIdAttributes; private Object collectedNaturalIdAttributes; public HierarchyMetadataCollector( EntityHierarchy entityHierarchy, ClassDetails rootEntityClassDetails, - HierarchyTypeConsumer delegateConsumer) { + HierarchyTypeConsumer delegateConsumer, + ModelCategorizationContext categorizationContext) { this.entityHierarchy = entityHierarchy; this.rootEntityClassDetails = rootEntityClassDetails; this.delegateConsumer = delegateConsumer; + this.categorizationContext = categorizationContext; } public EntityTypeMetadata getRootEntityMetadata() { @@ -83,7 +86,7 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { return idMapping; } - public AnnotationUsage getInheritanceAnnotation() { + public Inheritance getInheritanceAnnotation() { return inheritanceAnnotation; } @@ -95,15 +98,15 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { return tenantIdAttribute; } - public AnnotationUsage getOptimisticLockingAnnotation() { + public OptimisticLocking getOptimisticLockingAnnotation() { return optimisticLockingAnnotation; } - public AnnotationUsage getCacheAnnotation() { + public Cache getCacheAnnotation() { return cacheAnnotation; } - public AnnotationUsage getNaturalIdCacheAnnotation() { + public NaturalIdCache getNaturalIdCacheAnnotation() { return naturalIdCacheAnnotation; } @@ -120,7 +123,7 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { idClassDetails = null; } else { - idClassDetails = idClassAnnotation.getAttributeValue( "value" ); + idClassDetails = toClassDetails( idClassAnnotation.value() ); } return new NonAggregatedKeyMappingImpl( idAttributes, idClassDetails ); } @@ -142,7 +145,7 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { idClassDetails = null; } else { - idClassDetails = idClassAnnotation.getAttributeValue( "value" ); + idClassDetails = toClassDetails( idClassAnnotation.value() ); } return new NonAggregatedKeyMappingImpl( idAttributes, idClassDetails ); } @@ -157,6 +160,13 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { ); } + private ClassDetails toClassDetails(Class value) { + if ( value == null ) { + return null; + } + return categorizationContext.getClassDetailsRegistry().getClassDetails( value.getName() ); + } + public KeyMapping getNaturalIdMapping() { if ( collectedNaturalIdAttributes == null ) { return null; @@ -222,29 +232,29 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { final MemberDetails attributeMember = attributeMetadata.getMember(); if ( collectIds ) { - final AnnotationUsage eIdAnn = attributeMember.getAnnotationUsage( EmbeddedId.class ); + final EmbeddedId eIdAnn = attributeMember.getDirectAnnotationUsage( EmbeddedId.class ); if ( eIdAnn != null ) { collectIdAttribute( attributeMetadata ); } - final AnnotationUsage idAnn = attributeMember.getAnnotationUsage( Id.class ); + final Id idAnn = attributeMember.getDirectAnnotationUsage( Id.class ); if ( idAnn != null ) { collectIdAttribute( attributeMetadata ); } } - if ( attributeMember.getAnnotationUsage( NaturalId.class ) != null ) { + if ( attributeMember.getDirectAnnotationUsage( NaturalId.class ) != null ) { collectNaturalIdAttribute( attributeMetadata ); } if ( versionAttribute == null ) { - if ( attributeMember.getAnnotationUsage( Version.class ) != null ) { + if ( attributeMember.getDirectAnnotationUsage( Version.class ) != null ) { versionAttribute = attributeMetadata; } } if ( tenantIdAttribute == null ) { - if ( attributeMember.getAnnotationUsage( TenantId.class ) != null ) { + if ( attributeMember.getDirectAnnotationUsage( TenantId.class ) != null ) { tenantIdAttribute = attributeMetadata; } } @@ -252,8 +262,8 @@ public class HierarchyMetadataCollector implements HierarchyTypeConsumer { } } - private AnnotationUsage applyLocalAnnotation(Class annotationType, ClassDetails classDetails, AnnotationUsage currentValue) { - final AnnotationUsage localInheritanceAnnotation = classDetails.getAnnotationUsage( annotationType ); + private A applyLocalAnnotation(Class annotationType, ClassDetails classDetails, A currentValue) { + final A localInheritanceAnnotation = classDetails.getDirectAnnotationUsage( annotationType ); if ( localInheritanceAnnotation != null ) { // the one "closest" to the root-entity should win return localInheritanceAnnotation; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/LifecycleCallbackCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/LifecycleCallbackCollector.java index 98e02c5ce4..72d673ebb1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/LifecycleCallbackCollector.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/LifecycleCallbackCollector.java @@ -10,7 +10,7 @@ import java.lang.annotation.Annotation; import java.util.Locale; import org.hibernate.boot.models.categorize.spi.AllMemberConsumer; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle; import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; import org.hibernate.models.ModelsException; @@ -26,7 +26,7 @@ import jakarta.persistence.PrePersist; import jakarta.persistence.PreRemove; import jakarta.persistence.PreUpdate; -import static org.hibernate.boot.models.categorize.spi.JpaEventListener.matchesSignature; +import static org.hibernate.boot.models.spi.JpaEventListener.matchesSignature; /** * @author Steve Ebersole @@ -56,31 +56,31 @@ public class LifecycleCallbackCollector implements AllMemberConsumer { final MethodDetails methodDetails = (MethodDetails) memberDetails; - if ( methodDetails.getAnnotationUsage( PrePersist.class ) != null + if ( methodDetails.hasDirectAnnotationUsage( PrePersist.class ) && matchesSignature( JpaEventListenerStyle.CALLBACK, methodDetails ) ) { prePersist = apply( methodDetails, PrePersist.class, managedTypeDetails, prePersist ); } - else if ( methodDetails.getAnnotationUsage( PostPersist.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostPersist.class ) && matchesSignature( JpaEventListenerStyle.CALLBACK, methodDetails ) ) { postPersist = apply( methodDetails, PostPersist.class, managedTypeDetails, postPersist ); } - else if ( methodDetails.getAnnotationUsage( PreRemove.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PreRemove.class ) && matchesSignature( JpaEventListenerStyle.CALLBACK, methodDetails ) ) { preRemove = apply( methodDetails, PreRemove.class, managedTypeDetails, preRemove ); } - else if ( methodDetails.getAnnotationUsage( PostRemove.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostRemove.class ) && matchesSignature( JpaEventListenerStyle.CALLBACK, methodDetails ) ) { postRemove = apply( methodDetails, PostRemove.class, managedTypeDetails, postRemove ); } - else if ( methodDetails.getAnnotationUsage( PreUpdate.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PreUpdate.class ) && matchesSignature( JpaEventListenerStyle.CALLBACK, methodDetails ) ) { preUpdate = apply( methodDetails, PreUpdate.class, managedTypeDetails, preUpdate ); } - else if ( methodDetails.getAnnotationUsage( PostUpdate.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostUpdate.class ) && matchesSignature( JpaEventListenerStyle.CALLBACK, methodDetails ) ) { postUpdate = apply( methodDetails, PostUpdate.class, managedTypeDetails, postUpdate ); } - else if ( methodDetails.getAnnotationUsage( PostLoad.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostLoad.class ) && matchesSignature( JpaEventListenerStyle.CALLBACK, methodDetails ) ) { postLoad = apply( methodDetails, PostLoad.class, managedTypeDetails, postLoad ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/MappedSuperclassTypeMetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/MappedSuperclassTypeMetadataImpl.java index 9277fbb179..0cd2c992d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/MappedSuperclassTypeMetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/MappedSuperclassTypeMetadataImpl.java @@ -10,7 +10,7 @@ import java.util.List; import org.hibernate.boot.models.categorize.spi.AttributeMetadata; import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.models.categorize.spi.MappedSuperclassTypeMetadata; import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; import org.hibernate.models.spi.ClassDetails; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/ModelCategorizationContextImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/ModelCategorizationContextImpl.java index 5d99364c3f..e0a5b5abc1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/ModelCategorizationContextImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/ModelCategorizationContextImpl.java @@ -8,8 +8,8 @@ package org.hibernate.boot.models.categorize.internal; import java.util.List; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.spi.GlobalRegistrations; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; import org.hibernate.models.spi.AnnotationDescriptorRegistry; import org.hibernate.models.spi.ClassDetailsRegistry; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/NamedQueryRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/NamedQueryRegistration.java deleted file mode 100644 index 02d4a73c86..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/NamedQueryRegistration.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.categorize.internal; - -import java.lang.annotation.Annotation; - -import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.models.spi.AnnotationUsage; - -/** - * @see JpaAnnotations#NAMED_QUERY - * @see JpaAnnotations#NAMED_NATIVE_QUERY - * @see JpaAnnotations#NAMED_STORED_PROCEDURE_QUERY - * @see HibernateAnnotations#NAMED_QUERY - * @see HibernateAnnotations#NAMED_NATIVE_QUERY - * - * @author Steve Ebersole - */ -public class NamedQueryRegistration { - public enum Kind { - HQL, - NATIVE, - CALLABLE - } - - private final String name; - private final Kind kind; - private final boolean isJpa; - private final AnnotationUsage configuration; - - public NamedQueryRegistration(String name, Kind kind, boolean isJpa, AnnotationUsage configuration) { - this.name = name; - this.kind = kind; - this.isJpa = isJpa; - this.configuration = configuration; - } - - public String getName() { - return name; - } - - public Kind getKind() { - return kind; - } - - public boolean isJpa() { - return isJpa; - } - - public AnnotationUsage getConfiguration() { - return configuration; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/OrmAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/OrmAnnotationHelper.java deleted file mode 100644 index 139bf7e70a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/OrmAnnotationHelper.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.categorize.internal; - -import java.lang.reflect.Field; -import java.util.Locale; -import java.util.function.Consumer; - -import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.models.AnnotationAccessException; -import org.hibernate.models.spi.AnnotationDescriptor; - -/** - * @author Steve Ebersole - */ -public class OrmAnnotationHelper { - - public static void forEachOrmAnnotation(Consumer> consumer) { - JpaAnnotations.forEachAnnotation( consumer ); - HibernateAnnotations.forEachAnnotation( consumer ); - } - - public static void forEachOrmAnnotation(Class declarer, Consumer> consumer) { - for ( Field field : declarer.getFields() ) { - if ( AnnotationDescriptor.class.equals( field.getType() ) ) { - try { - consumer.accept( (AnnotationDescriptor) field.get( null ) ); - } - catch (IllegalAccessException e) { - throw new AnnotationAccessException( - String.format( - Locale.ROOT, - "Unable to access standard annotation descriptor field - %s", - field.getName() - ), - e - ); - } - } - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/StandardPersistentAttributeMemberResolver.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/StandardPersistentAttributeMemberResolver.java index 8dbd274270..3e5d829113 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/StandardPersistentAttributeMemberResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/StandardPersistentAttributeMemberResolver.java @@ -33,10 +33,8 @@ import org.hibernate.annotations.Type; import org.hibernate.boot.internal.AnyKeyType; import org.hibernate.boot.models.AccessTypePlacementException; import org.hibernate.boot.models.AnnotationPlacementException; -import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.categorize.spi.ClassAttributeAccessType; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.MemberDetails; @@ -130,13 +128,13 @@ public class StandardPersistentAttributeMemberResolver extends AbstractPersisten return; } - final AnnotationUsage access = memberDetails.getAnnotationUsage( JpaAnnotations.ACCESS ); + final Access access = memberDetails.getDirectAnnotationUsage( Access.class ); if ( access == null ) { checkForMisplacedAnnotations( classDetails, memberDetails, classLevelAccessType ); return; } - final AccessType attributeAccessType = access.getAttributeValue( "value" ); + final AccessType attributeAccessType = access.value(); validateAttributeLevelAccess( memberDetails, attributeAccessType, classDetails ); memberConsumer.accept( memberDetails.resolveAttributeName(), memberDetails ); @@ -199,39 +197,39 @@ public class StandardPersistentAttributeMemberResolver extends AbstractPersisten private boolean containsMappingAnnotations(M memberDetails) { // todo (jpa32) : better way to do this? - return memberDetails.hasAnnotationUsage( Id.class ) - || memberDetails.hasAnnotationUsage( EmbeddedId.class ) - || memberDetails.hasAnnotationUsage( Version.class ) - || memberDetails.hasAnnotationUsage( Basic.class ) - || memberDetails.hasAnnotationUsage( Embedded.class ) - || memberDetails.hasAnnotationUsage( ManyToOne.class ) - || memberDetails.hasAnnotationUsage( OneToOne.class ) - || memberDetails.hasAnnotationUsage( ElementCollection.class ) - || memberDetails.hasAnnotationUsage( ManyToMany.class ) - || memberDetails.hasAnnotationUsage( OneToMany.class ) - || memberDetails.hasAnnotationUsage( Any.class ) - || memberDetails.hasAnnotationUsage( ManyToAny.class ) - || memberDetails.hasAnnotationUsage( AnyKeyJavaClass.class ) - || memberDetails.hasAnnotationUsage( AnyKeyJavaType.class ) - || memberDetails.hasAnnotationUsage( AnyKeyJdbcType.class ) - || memberDetails.hasAnnotationUsage( AnyKeyJdbcTypeCode.class ) - || memberDetails.hasAnnotationUsage( AnyKeyType.class ) - || memberDetails.hasAnnotationUsage( AnyDiscriminator.class ) - || memberDetails.hasAnnotationUsage( AnyDiscriminatorValue.class ) - || memberDetails.hasAnnotationUsage( AnyDiscriminatorValues.class ) - || memberDetails.hasAnnotationUsage( Column.class ) - || memberDetails.hasAnnotationUsage( Enumerated.class ) - || memberDetails.hasAnnotationUsage( Lob.class ) - || memberDetails.hasAnnotationUsage( Temporal.class ) - || memberDetails.hasAnnotationUsage( Nationalized.class ) - || memberDetails.hasAnnotationUsage( TenantId.class ) - || memberDetails.hasAnnotationUsage( Generated.class ) - || memberDetails.hasAnnotationUsage( TimeZoneColumn.class ) - || memberDetails.hasAnnotationUsage( TimeZoneStorage.class ) - || memberDetails.hasAnnotationUsage( Type.class ) - || memberDetails.hasAnnotationUsage( JavaType.class ) - || memberDetails.hasAnnotationUsage( JdbcType.class ) - || memberDetails.hasAnnotationUsage( JdbcTypeCode.class ); + return memberDetails.hasDirectAnnotationUsage( Id.class ) + || memberDetails.hasDirectAnnotationUsage( EmbeddedId.class ) + || memberDetails.hasDirectAnnotationUsage( Version.class ) + || memberDetails.hasDirectAnnotationUsage( Basic.class ) + || memberDetails.hasDirectAnnotationUsage( Embedded.class ) + || memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) + || memberDetails.hasDirectAnnotationUsage( OneToOne.class ) + || memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) + || memberDetails.hasDirectAnnotationUsage( ManyToMany.class ) + || memberDetails.hasDirectAnnotationUsage( OneToMany.class ) + || memberDetails.hasDirectAnnotationUsage( Any.class ) + || memberDetails.hasDirectAnnotationUsage( ManyToAny.class ) + || memberDetails.hasDirectAnnotationUsage( AnyKeyJavaClass.class ) + || memberDetails.hasDirectAnnotationUsage( AnyKeyJavaType.class ) + || memberDetails.hasDirectAnnotationUsage( AnyKeyJdbcType.class ) + || memberDetails.hasDirectAnnotationUsage( AnyKeyJdbcTypeCode.class ) + || memberDetails.hasDirectAnnotationUsage( AnyKeyType.class ) + || memberDetails.hasDirectAnnotationUsage( AnyDiscriminator.class ) + || memberDetails.hasDirectAnnotationUsage( AnyDiscriminatorValue.class ) + || memberDetails.hasDirectAnnotationUsage( AnyDiscriminatorValues.class ) + || memberDetails.hasDirectAnnotationUsage( Column.class ) + || memberDetails.hasDirectAnnotationUsage( Enumerated.class ) + || memberDetails.hasDirectAnnotationUsage( Lob.class ) + || memberDetails.hasDirectAnnotationUsage( Temporal.class ) + || memberDetails.hasDirectAnnotationUsage( Nationalized.class ) + || memberDetails.hasDirectAnnotationUsage( TenantId.class ) + || memberDetails.hasDirectAnnotationUsage( Generated.class ) + || memberDetails.hasDirectAnnotationUsage( TimeZoneColumn.class ) + || memberDetails.hasDirectAnnotationUsage( TimeZoneStorage.class ) + || memberDetails.hasDirectAnnotationUsage( Type.class ) + || memberDetails.hasDirectAnnotationUsage( JavaType.class ) + || memberDetails.hasDirectAnnotationUsage( JdbcType.class ) + || memberDetails.hasDirectAnnotationUsage( JdbcTypeCode.class ); } private void validateAttributeLevelAccess( diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CacheRegion.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CacheRegion.java index ef1823f626..6f5b128952 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CacheRegion.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CacheRegion.java @@ -12,7 +12,6 @@ import org.hibernate.boot.CacheRegionDefinition; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.internal.util.StringHelper; import org.hibernate.models.ModelsException; -import org.hibernate.models.spi.AnnotationUsage; /** * Models the caching options for an entity, natural-id, or collection. @@ -26,7 +25,7 @@ public class CacheRegion { private boolean cacheLazyProperties; public CacheRegion( - AnnotationUsage cacheAnnotation, + Cache cacheAnnotation, AccessType implicitCacheAccessType, String implicitRegionName) { if ( cacheAnnotation == null ) { @@ -35,20 +34,17 @@ public class CacheRegion { cacheLazyProperties = true; } else { - final String explicitRegionName = cacheAnnotation.getString( "region" ); + final String explicitRegionName = cacheAnnotation.region(); regionName = StringHelper.isEmpty( explicitRegionName ) ? implicitRegionName : explicitRegionName; - accessType = interpretAccessStrategy( cacheAnnotation.getAttributeValue( "usage" ) ); + accessType = interpretAccessStrategy( cacheAnnotation.usage() ); - final Boolean explicitIncludeLazy = cacheAnnotation.getBoolean( "includeLazy" ); - if ( explicitIncludeLazy != null ) { - cacheLazyProperties = explicitIncludeLazy; - } - else { - final String include = cacheAnnotation.getAttributeValue( "include" ); - assert "all".equals( include ) || "non-lazy".equals( include ); - cacheLazyProperties = include.equals( "all" ); - } + // default for includeLazy is true + // default for include is "all" + final boolean includeLazy = cacheAnnotation.includeLazy(); + final String include = cacheAnnotation.include(); + assert "all".equals( include ) || "non-lazy".equals( include ); + cacheLazyProperties = includeLazy && include.equals( "all" ) ; } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CategorizedDomainModel.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CategorizedDomainModel.java index 73310f56fc..7c6eea6eaa 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CategorizedDomainModel.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CategorizedDomainModel.java @@ -9,6 +9,7 @@ package org.hibernate.boot.models.categorize.spi; import java.util.Map; import java.util.Set; +import org.hibernate.boot.models.spi.GlobalRegistrations; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; import org.hibernate.internal.util.IndexedConsumer; import org.hibernate.internal.util.KeyedConsumer; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/IdentifiableTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/IdentifiableTypeMetadata.java index fdc8a2b71a..bc75a4f06e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/IdentifiableTypeMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/IdentifiableTypeMetadata.java @@ -9,6 +9,8 @@ package org.hibernate.boot.models.categorize.spi; import java.util.List; import java.util.function.Consumer; +import org.hibernate.boot.models.spi.JpaEventListener; + /** * Metadata about an {@linkplain jakarta.persistence.metamodel.IdentifiableType identifiable type} * diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedResourcesProcessor.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedResourcesProcessor.java index 07b8e51483..61a7191a61 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedResourcesProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedResourcesProcessor.java @@ -13,16 +13,15 @@ import java.util.Set; import java.util.stream.Collectors; import org.hibernate.Internal; -import org.hibernate.annotations.TenantId; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.internal.RootMappingDefaults; import org.hibernate.boot.model.process.spi.ManagedResources; import org.hibernate.boot.models.categorize.ModelCategorizationLogging; import org.hibernate.boot.models.categorize.internal.ClassLoaderServiceLoading; -import org.hibernate.boot.models.categorize.internal.DomainModelCategorizationCollector; -import org.hibernate.boot.models.categorize.internal.GlobalRegistrationsImpl; +import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; +import org.hibernate.boot.models.internal.GlobalRegistrationsImpl; import org.hibernate.boot.models.categorize.internal.ModelCategorizationContextImpl; -import org.hibernate.boot.models.categorize.internal.OrmAnnotationHelper; +import org.hibernate.boot.models.internal.ModelsHelper; import org.hibernate.boot.models.xml.internal.PersistenceUnitMetadataImpl; import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult; import org.hibernate.boot.models.xml.spi.XmlPreProcessor; @@ -33,17 +32,12 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.models.internal.SourceModelBuildingContextImpl; -import org.hibernate.models.internal.jandex.JandexClassDetails; import org.hibernate.models.internal.jandex.JandexIndexerHelper; -import org.hibernate.models.internal.jdk.JdkBuilders; import org.hibernate.models.spi.AnnotationDescriptorRegistry; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.ClassLoading; -import org.hibernate.models.spi.RegistryPrimer; -import org.hibernate.models.spi.SourceModelBuildingContext; -import org.jboss.jandex.ClassInfo; import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; @@ -112,7 +106,7 @@ public class ManagedResourcesProcessor { final SourceModelBuildingContextImpl sourceModelBuildingContext = new SourceModelBuildingContextImpl( classLoading, jandexIndex, - ManagedResourcesProcessor::preFillRegistries + ModelsHelper::preFillRegistries ); @@ -261,42 +255,6 @@ public class ManagedResourcesProcessor { return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() ); } - public static void preFillRegistries(RegistryPrimer.Contributions contributions, SourceModelBuildingContext buildingContext) { - OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation ); - - buildingContext.getAnnotationDescriptorRegistry().getDescriptor( TenantId.class ); - - final IndexView jandexIndex = buildingContext.getJandexIndex(); - if ( jandexIndex == null ) { - return; - } - - final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry(); - final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry(); - - for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) { - final String className = knownClass.name().toString(); - - if ( knownClass.isAnnotation() ) { - // it is always safe to load the annotation classes - we will never be enhancing them - //noinspection rawtypes - final Class annotationClass = buildingContext - .getClassLoading() - .classForName( className ); - //noinspection unchecked - annotationDescriptorRegistry.resolveDescriptor( - annotationClass, - (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext.getAnnotationDescriptorRegistry() ) - ); - } - - classDetailsRegistry.resolveClassDetails( - className, - (name) -> new JandexClassDetails( knownClass, buildingContext ) - ); - } - } - /** * For testing use only */ diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ModelCategorizationContext.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ModelCategorizationContext.java index ea8a0aedb9..bc183b6dbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ModelCategorizationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ModelCategorizationContext.java @@ -9,6 +9,7 @@ package org.hibernate.boot.models.categorize.spi; import java.util.List; import org.hibernate.boot.models.categorize.internal.StandardPersistentAttributeMemberResolver; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.models.spi.AnnotationDescriptorRegistry; import org.hibernate.models.spi.ClassDetailsRegistry; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NaturalIdCacheRegion.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NaturalIdCacheRegion.java index 5c35073b50..87cf36af93 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NaturalIdCacheRegion.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NaturalIdCacheRegion.java @@ -8,7 +8,6 @@ package org.hibernate.boot.models.categorize.spi; import org.hibernate.annotations.NaturalIdCache; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.AnnotationUsage; /** * Details about caching related to the natural-id of an entity @@ -20,13 +19,13 @@ import org.hibernate.models.spi.AnnotationUsage; public class NaturalIdCacheRegion { private final String regionName; - public NaturalIdCacheRegion(AnnotationUsage cacheAnnotation, CacheRegion cacheRegion) { + public NaturalIdCacheRegion(NaturalIdCache cacheAnnotation, CacheRegion cacheRegion) { this.regionName = determineRegionName( cacheAnnotation, cacheRegion ); } - private static String determineRegionName(AnnotationUsage cacheAnnotation, CacheRegion cacheRegion) { + private static String determineRegionName(NaturalIdCache cacheAnnotation, CacheRegion cacheRegion) { if ( cacheAnnotation != null ) { - final String explicitRegionName = cacheAnnotation.getAttributeValue( "region" ); + final String explicitRegionName = cacheAnnotation.region(); if ( StringHelper.isNotEmpty( explicitRegionName ) ) { return explicitRegionName; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/AnnotationUsageHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/AnnotationUsageHelper.java deleted file mode 100644 index 2206aa525a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/AnnotationUsageHelper.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.internal; - -import java.lang.annotation.Annotation; - -import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; -import org.hibernate.models.spi.MutableAnnotationUsage; - -public class AnnotationUsageHelper { - - public static void applyAttributeIfSpecified( - String attributeName, - Object value, - MutableAnnotationUsage annotationUsage) { - XmlAnnotationHelper.applyOptionalAttribute( annotationUsage, attributeName, value ); - } - - public static void applyStringAttributeIfSpecified( - String attributeName, - String value, - MutableAnnotationUsage annotationUsage) { - XmlAnnotationHelper.applyOptionalAttribute( annotationUsage, attributeName, value ); - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/DomainModelCategorizationCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/DomainModelCategorizationCollector.java similarity index 78% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/DomainModelCategorizationCollector.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/internal/DomainModelCategorizationCollector.java index a41e6ee834..41370cbe6b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/DomainModelCategorizationCollector.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/DomainModelCategorizationCollector.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.internal; +package org.hibernate.boot.models.internal; import java.util.HashMap; import java.util.HashSet; @@ -15,11 +15,12 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerContainerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaultsImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadataImpl; +import org.hibernate.boot.models.categorize.internal.CategorizedDomainModelImpl; import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor; +import org.hibernate.boot.models.spi.GlobalRegistrations; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.models.spi.AnnotationDescriptorRegistry; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; @@ -34,9 +35,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.MappedSuperclass; /** - * In-flight holder for various types of "global" registrations. Also acts as the - * {@linkplain #createResult builder} for {@linkplain CategorizedDomainModel} as returned - * by {@linkplain ManagedResourcesProcessor#processManagedResources} + * In-flight holder for various things as we process metadata sources * * @author Steve Ebersole */ @@ -79,7 +78,7 @@ public class DomainModelCategorizationCollector { return embeddables; } - public void apply(JaxbEntityMappingsImpl jaxbRoot) { + public void apply(JaxbEntityMappingsImpl jaxbRoot, XmlDocumentContext xmlDocumentContext) { getGlobalRegistrations().collectJavaTypeRegistrations( jaxbRoot.getJavaTypeRegistrations() ); getGlobalRegistrations().collectJdbcTypeRegistrations( jaxbRoot.getJdbcTypeRegistrations() ); getGlobalRegistrations().collectConverterRegistrations( jaxbRoot.getConverterRegistrations() ); @@ -103,9 +102,9 @@ public class DomainModelCategorizationCollector { getGlobalRegistrations().collectIdGenerators( jaxbRoot ); - getGlobalRegistrations().collectQueryReferences( jaxbRoot ); + getGlobalRegistrations().collectQueryReferences( jaxbRoot, xmlDocumentContext ); - // todo : named graphs + // todo (7.0) : named graphs? } public void apply(ClassDetails classDetails) { @@ -127,37 +126,52 @@ public class DomainModelCategorizationCollector { // todo : named queries // todo : named graphs - if ( classDetails.getAnnotationUsage( MappedSuperclass.class ) != null ) { + if ( classDetails.getDirectAnnotationUsage( MappedSuperclass.class ) != null ) { if ( classDetails.getClassName() != null ) { mappedSuperclasses.put( classDetails.getClassName(), classDetails ); } } - else if ( classDetails.getAnnotationUsage( Entity.class ) != null ) { - if ( EntityHierarchyBuilder.isRoot( classDetails ) ) { + else if ( classDetails.getDirectAnnotationUsage( Entity.class ) != null ) { + if ( isRootEntity( classDetails ) ) { rootEntities.add( classDetails ); } } - else if ( classDetails.getAnnotationUsage( Embeddable.class ) != null ) { + else if ( classDetails.getDirectAnnotationUsage( Embeddable.class ) != null ) { if ( classDetails.getClassName() != null ) { embeddables.put( classDetails.getClassName(), classDetails ); } } if ( ( classDetails.getClassName() != null && classDetails.isImplementor( AttributeConverter.class ) ) - || classDetails.getAnnotationUsage( Converter.class ) != null ) { + || classDetails.getDirectAnnotationUsage( Converter.class ) != null ) { globalRegistrations.collectConverter( classDetails ); } } - /** - * Builder for {@linkplain CategorizedDomainModel} based on our internal state plus - * the incoming set of managed types. - * - * @param entityHierarchies All entity hierarchies defined in the persistence-unit, built based - * on {@linkplain #getRootEntities()} - * - * @see ManagedResourcesProcessor#processManagedResources - */ + public static boolean isRootEntity(ClassDetails classInfo) { + // perform a series of opt-out checks against the super-type hierarchy + + // an entity is considered a root of the hierarchy if: + // 1) it has no super-types + // 2) its super types contain no entities (MappedSuperclasses are allowed) + + if ( classInfo.getSuperClass() == null ) { + return true; + } + + ClassDetails current = classInfo.getSuperClass(); + while ( current != null ) { + if ( current.hasDirectAnnotationUsage( Entity.class ) && !current.isAbstract() ) { + // a non-abstract super type has `@Entity` -> classInfo cannot be a root entity + return false; + } + current = current.getSuperClass(); + } + + // if we hit no opt-outs we have a root + return true; + } + public CategorizedDomainModel createResult( Set entityHierarchies, PersistenceUnitMetadata persistenceUnitMetadata, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/GlobalRegistrationsImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java similarity index 53% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/GlobalRegistrationsImpl.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java index 31e0b5c281..cb41b6e3d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/GlobalRegistrationsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/GlobalRegistrationsImpl.java @@ -4,9 +4,8 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.internal; +package org.hibernate.boot.models.internal; -import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -14,26 +13,20 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Consumer; import java.util.function.Supplier; -import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Imported; import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.Parameter; import org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionUserTypeRegistrationImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbCompositeUserTypeRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbConfigurationParameterImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbConstructorResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbConverterImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbConverterRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddableInstantiatorRegistrationImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResultImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbFieldResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbFilterDefImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbGenericIdGeneratorImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJavaTypeRegistrationImpl; @@ -45,31 +38,39 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint; import org.hibernate.boot.jaxb.mapping.spi.JaxbSequenceGeneratorImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbSqlResultSetMappingImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameterImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbTableGeneratorImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeRegistrationImpl; -import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.categorize.spi.CollectionTypeRegistration; -import org.hibernate.boot.models.categorize.spi.CompositeUserTypeRegistration; -import org.hibernate.boot.models.categorize.spi.ConversionRegistration; -import org.hibernate.boot.models.categorize.spi.ConverterRegistration; -import org.hibernate.boot.models.categorize.spi.EmbeddableInstantiatorRegistration; -import org.hibernate.boot.models.categorize.spi.FilterDefRegistration; -import org.hibernate.boot.models.categorize.spi.GenericGeneratorRegistration; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.boot.models.categorize.spi.JavaTypeRegistration; -import org.hibernate.boot.models.categorize.spi.JdbcTypeRegistration; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.annotations.internal.GenericGeneratorAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedNativeQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedStoredProcedureQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.QueryHintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SequenceGeneratorJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SqlResultSetMappingJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TableGeneratorJpaAnnotation; +import org.hibernate.boot.models.spi.CollectionTypeRegistration; +import org.hibernate.boot.models.spi.CompositeUserTypeRegistration; +import org.hibernate.boot.models.spi.ConversionRegistration; +import org.hibernate.boot.models.spi.ConverterRegistration; +import org.hibernate.boot.models.spi.EmbeddableInstantiatorRegistration; +import org.hibernate.boot.models.spi.FilterDefRegistration; +import org.hibernate.boot.models.spi.GenericGeneratorRegistration; +import org.hibernate.boot.models.spi.GlobalRegistrations; +import org.hibernate.boot.models.spi.JavaTypeRegistration; +import org.hibernate.boot.models.spi.JdbcTypeRegistration; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle; -import org.hibernate.boot.models.categorize.spi.NamedNativeQueryRegistration; -import org.hibernate.boot.models.categorize.spi.NamedQueryRegistration; -import org.hibernate.boot.models.categorize.spi.NamedStoredProcedureQueryRegistration; -import org.hibernate.boot.models.categorize.spi.SequenceGeneratorRegistration; -import org.hibernate.boot.models.categorize.spi.SqlResultSetMappingRegistration; -import org.hibernate.boot.models.categorize.spi.TableGeneratorRegistration; -import org.hibernate.boot.models.categorize.spi.UserTypeRegistration; +import org.hibernate.boot.models.spi.NamedNativeQueryRegistration; +import org.hibernate.boot.models.spi.NamedQueryRegistration; +import org.hibernate.boot.models.spi.NamedStoredProcedureQueryRegistration; +import org.hibernate.boot.models.spi.SequenceGeneratorRegistration; +import org.hibernate.boot.models.spi.SqlResultSetMappingRegistration; +import org.hibernate.boot.models.spi.TableGeneratorRegistration; +import org.hibernate.boot.models.spi.UserTypeRegistration; +import org.hibernate.boot.models.xml.internal.QueryProcessing; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.cfg.AvailableSettings; import org.hibernate.internal.CoreLogging; @@ -77,41 +78,36 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jpa.AvailableHints; import org.hibernate.metamodel.CollectionClassification; -import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.usertype.CompositeUserType; +import org.hibernate.usertype.UserCollectionType; +import org.hibernate.usertype.UserType; -import jakarta.persistence.ColumnResult; -import jakarta.persistence.ConstructorResult; -import jakarta.persistence.EntityResult; -import jakarta.persistence.FieldResult; -import jakarta.persistence.NamedNativeQuery; -import jakarta.persistence.NamedQuery; -import jakarta.persistence.NamedStoredProcedureQuery; +import jakarta.persistence.AttributeConverter; import jakarta.persistence.QueryHint; import jakarta.persistence.SequenceGenerator; -import jakarta.persistence.SqlResultSetMapping; -import jakarta.persistence.StoredProcedureParameter; import jakarta.persistence.TableGenerator; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; -import static org.hibernate.boot.models.HibernateAnnotations.COLLECTION_TYPE_REG; -import static org.hibernate.boot.models.HibernateAnnotations.COMPOSITE_TYPE_REG; -import static org.hibernate.boot.models.HibernateAnnotations.CONVERTER_REG; -import static org.hibernate.boot.models.HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REG; +import static org.hibernate.boot.models.HibernateAnnotations.COLLECTION_TYPE_REGISTRATION; +import static org.hibernate.boot.models.HibernateAnnotations.COMPOSITE_TYPE_REGISTRATION; +import static org.hibernate.boot.models.HibernateAnnotations.CONVERTER_REGISTRATION; +import static org.hibernate.boot.models.HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REGISTRATION; import static org.hibernate.boot.models.HibernateAnnotations.FILTER_DEF; -import static org.hibernate.boot.models.HibernateAnnotations.JAVA_TYPE_REG; -import static org.hibernate.boot.models.HibernateAnnotations.JDBC_TYPE_REG; -import static org.hibernate.boot.models.HibernateAnnotations.TYPE_REG; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified; +import static org.hibernate.boot.models.HibernateAnnotations.GENERIC_GENERATOR; +import static org.hibernate.boot.models.HibernateAnnotations.JAVA_TYPE_REGISTRATION; +import static org.hibernate.boot.models.HibernateAnnotations.JDBC_TYPE_REGISTRATION; +import static org.hibernate.boot.models.JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY; +import static org.hibernate.boot.models.JpaAnnotations.SEQUENCE_GENERATOR; +import static org.hibernate.boot.models.JpaAnnotations.TABLE_GENERATOR; +import static org.hibernate.boot.models.HibernateAnnotations.TYPE_REGISTRATION; +import static org.hibernate.boot.models.xml.internal.QueryProcessing.collectResultClasses; import static org.hibernate.internal.util.StringHelper.isNotEmpty; -import static org.hibernate.internal.util.collections.CollectionHelper.arrayList; import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; /** @@ -243,9 +239,9 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { // JavaTypeRegistration public void collectJavaTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( JAVA_TYPE_REG, (usage) -> collectJavaTypeRegistration( - usage.getAttributeValue( "javaType" ), - usage.getAttributeValue( "descriptorClass" ) + annotationTarget.forEachAnnotationUsage( JAVA_TYPE_REGISTRATION, sourceModelContext, (usage) -> collectJavaTypeRegistration( + toClassDetails( usage.javaType().getName() ), + toClassDetails( usage.descriptorClass().getName() ) ) ); } @@ -255,8 +251,8 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } registrations.forEach( (reg) -> collectJavaTypeRegistration( - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getClazz() ), - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getDescriptor() ) + toClassDetails( reg.getClazz() ), + toClassDetails( reg.getDescriptor() ) ) ); } @@ -276,9 +272,9 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { // JdbcTypeRegistration public void collectJdbcTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( JDBC_TYPE_REG, (usage) -> collectJdbcTypeRegistration( - usage.getAttributeValue( "registrationCode" ), - usage.getAttributeValue( "value" ) + annotationTarget.forEachAnnotationUsage( JDBC_TYPE_REGISTRATION, sourceModelContext, (usage) -> collectJdbcTypeRegistration( + usage.registrationCode(), + sourceModelContext.getClassDetailsRegistry().resolveClassDetails( usage.value().getName() ) ) ); } @@ -289,7 +285,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { registrations.forEach( (reg) -> collectJdbcTypeRegistration( reg.getCode(), - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getDescriptor() ) + toClassDetails( reg.getDescriptor() ) ) ); } @@ -305,11 +301,13 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { // ConversionRegistration public void collectConverterRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( CONVERTER_REG, (usage) -> { - final ClassDetails domainType = usage.getAttributeValue( "domainType" ); - final ClassDetails converterType = usage.getAttributeValue( "converter" ); - final boolean autoApply = usage.getAttributeValue( "autoApply" ); - collectConverterRegistration( new ConversionRegistration( domainType, converterType, autoApply, CONVERTER_REG ) ); + annotationTarget.forEachAnnotationUsage( CONVERTER_REGISTRATION, sourceModelContext, (usage) -> { + collectConverterRegistration( new ConversionRegistration( + usage.domainType(), + usage.converter(), + usage.autoApply(), + CONVERTER_REGISTRATION + ) ); } ); } @@ -319,17 +317,22 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } registrations.forEach( (registration) -> { - final ClassDetails explicitDomainType; + final Class explicitDomainType; final String explicitDomainTypeName = registration.getClazz(); if ( isNotEmpty( explicitDomainTypeName ) ) { - explicitDomainType = sourceModelContext.getClassDetailsRegistry().resolveClassDetails( explicitDomainTypeName ); + explicitDomainType = sourceModelContext.getClassDetailsRegistry().resolveClassDetails( explicitDomainTypeName ).toJavaClass(); } else { explicitDomainType = null; } - final ClassDetails converterType = sourceModelContext.getClassDetailsRegistry().resolveClassDetails( registration.getConverter() ); + final Class> converterType = sourceModelContext.getClassDetailsRegistry().resolveClassDetails( registration.getConverter() ).toJavaClass(); final boolean autoApply = registration.isAutoApply(); - collectConverterRegistration( new ConversionRegistration( explicitDomainType, converterType, autoApply, CONVERTER_REG ) ); + collectConverterRegistration( new ConversionRegistration( + explicitDomainType, + converterType, + autoApply, + CONVERTER_REGISTRATION + ) ); } ); } @@ -345,9 +348,9 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { // UserTypeRegistration public void collectUserTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( TYPE_REG, (usage) -> collectUserTypeRegistration( - usage.getAttributeValue( "basicClass" ), - usage.getAttributeValue( "userType" ) + annotationTarget.forEachAnnotationUsage( TYPE_REGISTRATION, sourceModelContext, (usage) -> collectUserTypeRegistration( + usage.basicClass(), + usage.userType() ) ); } @@ -357,8 +360,8 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } registrations.forEach( (reg) -> { - final ClassDetails domainTypeDetails = sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getClazz() ); - final ClassDetails descriptorDetails = sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getDescriptor() ); + final ClassDetails domainTypeDetails = toClassDetails( reg.getClazz() ); + final ClassDetails descriptorDetails = toClassDetails( reg.getDescriptor() ); collectUserTypeRegistration( domainTypeDetails, descriptorDetails ); } ); } @@ -370,14 +373,21 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { userTypeRegistrations.add( new UserTypeRegistration( domainClass, userTypeClass ) ); } + public void collectUserTypeRegistration(Class domainClass, Class> userTypeClass) { + collectUserTypeRegistration( + toClassDetails( domainClass.getName() ), + toClassDetails( userTypeClass.getName() ) + ); + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // CompositeUserTypeRegistration public void collectCompositeUserTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( COMPOSITE_TYPE_REG, (usage) -> collectCompositeUserTypeRegistration( - usage.getAttributeValue( "embeddableClass" ), - usage.getAttributeValue( "userType" ) + annotationTarget.forEachAnnotationUsage( COMPOSITE_TYPE_REGISTRATION, sourceModelContext, (usage) -> collectCompositeUserTypeRegistration( + usage.embeddableClass(), + usage.userType() ) ); } @@ -387,8 +397,8 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } registrations.forEach( (reg) -> collectCompositeUserTypeRegistration( - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getClazz() ), - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getDescriptor() ) + toClassDetails( reg.getClazz() ), + toClassDetails( reg.getDescriptor() ) ) ); } @@ -399,27 +409,29 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { compositeUserTypeRegistrations.add( new CompositeUserTypeRegistration( domainClass, userTypeClass ) ); } + public void collectCompositeUserTypeRegistration(Class domainClass, Class> userTypeClass) { + collectCompositeUserTypeRegistration( + toClassDetails( domainClass.getName() ), + toClassDetails( userTypeClass.getName() ) + ); + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // CollectionTypeRegistration public void collectCollectionTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( COLLECTION_TYPE_REG, (usage) -> collectCollectionTypeRegistration( - usage.getAttributeValue( "classification" ), - usage.getAttributeValue( "type" ), - extractParameterMap( usage ) + annotationTarget.forEachAnnotationUsage( COLLECTION_TYPE_REGISTRATION, sourceModelContext, (usage) -> collectCollectionTypeRegistration( + usage.classification(), + usage.type(), + extractParameterMap( usage.parameters() ) ) ); } - private Map extractParameterMap(AnnotationUsage source) { - final List> parameters = source.getAttributeValue( "parameters" ); - + private Map extractParameterMap(Parameter[] parameters) { final Map result = new HashMap<>(); - for ( AnnotationUsage parameter : parameters ) { - result.put( - parameter.getAttributeValue( "name" ), - parameter.getAttributeValue( "value" ) - ); + for ( Parameter parameter : parameters ) { + result.put( parameter.name(), parameter.value() ); } return result; } @@ -431,7 +443,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { registrations.forEach( (reg) -> collectCollectionTypeRegistration( reg.getClassification(), - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( reg.getDescriptor() ), + toClassDetails( reg.getDescriptor() ), extractParameterMap( reg.getParameters() ) ) ); } @@ -456,14 +468,25 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { collectionTypeRegistrations.add( new CollectionTypeRegistration( classification, userTypeClass, parameters ) ); } + public void collectCollectionTypeRegistration( + CollectionClassification classification, + Class userTypeClass, + Map parameters) { + collectCollectionTypeRegistration( + classification, + toClassDetails( userTypeClass.getName() ), + parameters + ); + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // EmbeddableInstantiatorRegistration public void collectEmbeddableInstantiatorRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( EMBEDDABLE_INSTANTIATOR_REG, (usage) -> collectEmbeddableInstantiatorRegistration( - usage.getAttributeValue( "embeddableClass" ), - usage.getAttributeValue( "instantiator" ) + annotationTarget.forEachAnnotationUsage( EMBEDDABLE_INSTANTIATOR_REGISTRATION, sourceModelContext, (usage) -> collectEmbeddableInstantiatorRegistration( + usage.embeddableClass(), + usage.instantiator() ) ); } @@ -485,15 +508,22 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { embeddableInstantiatorRegistrations.add( new EmbeddableInstantiatorRegistration( embeddableClass, instantiator ) ); } + public void collectEmbeddableInstantiatorRegistration(Class embeddableClass, Class instantiator) { + collectEmbeddableInstantiatorRegistration( + toClassDetails( embeddableClass.getName() ), + toClassDetails( instantiator.getName() ) + ); + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Filter-defs public void collectFilterDefinitions(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( FILTER_DEF, (usage) -> { + annotationTarget.forEachAnnotationUsage( FILTER_DEF, sourceModelContext, (usage) -> { final Map paramJdbcMappings; final Map parameterResolvers; - final List> parameters = usage.getList( "parameters" ); + final ParamDef[] parameters = usage.parameters(); if ( CollectionHelper.isEmpty( parameters ) ) { paramJdbcMappings = emptyMap(); parameterResolvers = emptyMap(); @@ -502,36 +532,31 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { paramJdbcMappings = new HashMap<>(); parameterResolvers = new HashMap<>(); - for ( AnnotationUsage parameter : parameters ) { - paramJdbcMappings.put( parameter.getString( "name" ), parameter.getClassDetails( "type" ) ); - final ClassDetails resolverClassDetails = parameter.getClassDetails( "resolver" ); + for ( ParamDef parameter : parameters ) { + paramJdbcMappings.put( parameter.name(), toClassDetails( parameter.type() ) ); + final ClassDetails resolverClassDetails = toClassDetails( parameter.resolver() ); if ( !resolverClassDetails.getName().equals( Supplier.class.getName() ) ) { - parameterResolvers.put( parameter.getString( "name" ), resolverClassDetails ); + parameterResolvers.put( parameter.name(), resolverClassDetails ); } } } collectFilterDefinition( - usage.getString( "name" ), - usage.getString( "defaultCondition" ), - usage.getBoolean( "autoEnabled" ), + usage.name(), + usage.defaultCondition(), + usage.autoEnabled(), paramJdbcMappings, parameterResolvers ); } ); } - private Map extractFilterParameters(AnnotationUsage source) { - final List> parameters = source.getAttributeValue( "parameters" ); - if ( isEmpty( parameters ) ) { - return null; - } + private ClassDetails toClassDetails(Class type) { + return sourceModelContext.getClassDetailsRegistry().resolveClassDetails( type.getName() ); + } - final Map result = new HashMap<>( parameters.size() ); - for ( AnnotationUsage parameter : parameters ) { - result.put( parameter.getAttributeValue( "name" ), parameter.getAttributeValue( "type" ) ); - } - return result; + private ClassDetails toClassDetails(String typeName) { + return sourceModelContext.getClassDetailsRegistry().resolveClassDetails( typeName ); } public void collectFilterDefinitions(List filterDefinitions) { @@ -600,13 +625,13 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } public void collectImportRename(ClassDetails classDetails) { - final AnnotationUsage importedUsage = classDetails.getAnnotationUsage( Imported.class ); + final Imported importedUsage = classDetails.getDirectAnnotationUsage( Imported.class ); if ( importedUsage == null ) { return; } - final String explicitRename = importedUsage.getString( "rename" ); + final String explicitRename = importedUsage.rename(); final String rename = isNotEmpty( explicitRename ) ? explicitRename : StringHelper.unqualify( classDetails.getName() ); @@ -664,9 +689,21 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } public void collectIdGenerators(ClassDetails classDetails) { - classDetails.forEachAnnotationUsage( SequenceGenerator.class, this::collectSequenceGenerator ); - classDetails.forEachAnnotationUsage( TableGenerator.class, this::collectTableGenerator ); - classDetails.forEachAnnotationUsage( GenericGenerator.class, this::collectGenericGenerator ); + classDetails.forEachRepeatedAnnotationUsages( + SEQUENCE_GENERATOR, + sourceModelContext, + this::collectSequenceGenerator + ); + classDetails.forEachAnnotationUsage( + TABLE_GENERATOR, + sourceModelContext, + this::collectTableGenerator + ); + classDetails.forEachAnnotationUsage( + GENERIC_GENERATOR, + sourceModelContext, + this::collectGenericGenerator + ); } @@ -678,26 +715,43 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { return; } - sequenceGenerators.forEach( (generator) -> { - final MutableAnnotationUsage annotationUsage = makeAnnotation( JpaAnnotations.SEQUENCE_GENERATOR ); - applyStringAttributeIfSpecified( "name", generator.getName(), annotationUsage ); - applyStringAttributeIfSpecified( "sequenceName", generator.getSequenceName(), annotationUsage ); - applyStringAttributeIfSpecified( "catalog", generator.getCatalog(), annotationUsage ); - applyStringAttributeIfSpecified( "schema", generator.getSchema(), annotationUsage ); - applyAttributeIfSpecified( "initialValue", generator.getInitialValue(), annotationUsage ); - applyAttributeIfSpecified( "allocationSize", generator.getAllocationSize(), annotationUsage ); - applyStringAttributeIfSpecified( "options", generator.getOptions(), annotationUsage ); + sequenceGenerators.forEach( (jaxbGenerator) -> { + final SequenceGeneratorJpaAnnotation sequenceAnn = SEQUENCE_GENERATOR.createUsage( sourceModelContext ); - collectSequenceGenerator( new SequenceGeneratorRegistration( generator.getName(), annotationUsage ) ); + if ( StringHelper.isNotEmpty( jaxbGenerator.getName() ) ) { + sequenceAnn.name( jaxbGenerator.getName() ); + } + + if ( jaxbGenerator.getSequenceName() != null ) { + sequenceAnn.sequenceName( jaxbGenerator.getSequenceName() ); + } + + if ( StringHelper.isNotEmpty( jaxbGenerator.getCatalog() ) ) { + sequenceAnn.catalog( jaxbGenerator.getCatalog() ); + } + + if ( StringHelper.isNotEmpty( jaxbGenerator.getSchema() ) ) { + sequenceAnn.schema( jaxbGenerator.getSchema() ); + } + + if ( jaxbGenerator.getInitialValue() != null ) { + sequenceAnn.initialValue( jaxbGenerator.getInitialValue() ); + } + + if ( jaxbGenerator.getAllocationSize() != null ) { + sequenceAnn.allocationSize( jaxbGenerator.getAllocationSize() ); + } + + if ( StringHelper.isNotEmpty( jaxbGenerator.getOptions() ) ) { + sequenceAnn.options( jaxbGenerator.getOptions() ); + } + + collectSequenceGenerator( new SequenceGeneratorRegistration( jaxbGenerator.getName(), sequenceAnn ) ); } ); } - private MutableAnnotationUsage makeAnnotation(AnnotationDescriptor annotationDescriptor) { - return annotationDescriptor.createUsage( sourceModelContext ); - } - - public void collectSequenceGenerator(AnnotationUsage usage) { - collectSequenceGenerator( new SequenceGeneratorRegistration( usage.getAttributeValue( "name" ), usage ) ); + public void collectSequenceGenerator(SequenceGenerator usage) { + collectSequenceGenerator( new SequenceGeneratorRegistration( usage.name(), usage ) ); } public void collectSequenceGenerator(SequenceGeneratorRegistration generatorRegistration) { @@ -734,32 +788,60 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Table generator - public void collectTableGenerators(List tableGenerators) { - if ( CollectionHelper.isEmpty( tableGenerators ) ) { + public void collectTableGenerators(List jaxbGenerators) { + if ( CollectionHelper.isEmpty( jaxbGenerators ) ) { return; } - tableGenerators.forEach( (generator) -> { - final MutableAnnotationUsage annotationUsage = makeAnnotation( JpaAnnotations.TABLE_GENERATOR ); - applyStringAttributeIfSpecified( "name", generator.getName(), annotationUsage ); - applyStringAttributeIfSpecified( "table", generator.getTable(), annotationUsage ); - applyStringAttributeIfSpecified( "catalog", generator.getCatalog(), annotationUsage ); - applyStringAttributeIfSpecified( "schema", generator.getSchema(), annotationUsage ); - applyStringAttributeIfSpecified( "pkColumnName", generator.getPkColumnName(), annotationUsage ); - applyStringAttributeIfSpecified( "valueColumnName", generator.getValueColumnName(), annotationUsage ); - applyStringAttributeIfSpecified( "pkColumnValue", generator.getPkColumnValue(), annotationUsage ); - applyAttributeIfSpecified( "initialValue", generator.getInitialValue(), annotationUsage ); - applyAttributeIfSpecified( "allocationSize", generator.getAllocationSize(), annotationUsage ); - applyAttributeIfSpecified( "uniqueConstraints", generator.getUniqueConstraints(), annotationUsage ); - applyAttributeIfSpecified( "indexes", generator.getIndexes(), annotationUsage ); - applyStringAttributeIfSpecified( "options", generator.getOptions(), annotationUsage ); + jaxbGenerators.forEach( (jaxbGenerator) -> { + final TableGeneratorJpaAnnotation annotation = TABLE_GENERATOR.createUsage( sourceModelContext ); + if ( StringHelper.isNotEmpty( jaxbGenerator.getName() ) ) { + annotation.name( jaxbGenerator.getName() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getTable() ) ) { + annotation.table( jaxbGenerator.getTable() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getCatalog() ) ) { + annotation.catalog( jaxbGenerator.getCatalog() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getSchema() ) ) { + annotation.schema( jaxbGenerator.getSchema() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getPkColumnName() ) ) { + annotation.pkColumnName( jaxbGenerator.getPkColumnName() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getPkColumnValue() ) ) { + annotation.pkColumnValue( jaxbGenerator.getPkColumnValue() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getValueColumnName() ) ) { + annotation.valueColumnName( jaxbGenerator.getValueColumnName() ); + } + if ( jaxbGenerator.getInitialValue() != null ) { + annotation.initialValue( jaxbGenerator.getInitialValue() ); + } + if ( jaxbGenerator.getAllocationSize() != null ) { + annotation.allocationSize( jaxbGenerator.getAllocationSize() ); + } + if ( StringHelper.isNotEmpty( jaxbGenerator.getOptions() ) ) { + annotation.options( jaxbGenerator.getOptions() ); + } - collectTableGenerator( new TableGeneratorRegistration( generator.getName(), annotationUsage ) ); + annotation.uniqueConstraints( XmlAnnotationHelper.collectUniqueConstraints( + jaxbGenerator.getUniqueConstraints(), + sourceModelContext + ) ); + + annotation.indexes( XmlAnnotationHelper.collectIndexes( + jaxbGenerator.getIndexes(), + sourceModelContext + ) ); + + collectTableGenerator( new TableGeneratorRegistration( jaxbGenerator.getName(), annotation ) ); } ); } - public void collectTableGenerator(AnnotationUsage usage) { - collectTableGenerator( new TableGeneratorRegistration( usage.getAttributeValue( "name" ), usage ) ); + public void collectTableGenerator(TableGenerator usage) { + collectTableGenerator( new TableGeneratorRegistration( usage.name(), usage ) ); } public void collectTableGenerator(TableGeneratorRegistration generatorRegistration) { @@ -775,26 +857,27 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Generic generators - private void collectGenericGenerators(List genericGenerators) { - if ( CollectionHelper.isEmpty( genericGenerators ) ) { + private void collectGenericGenerators(List jaxbGenerators) { + if ( CollectionHelper.isEmpty( jaxbGenerators ) ) { return; } - genericGenerators.forEach( (generator) -> { - final MutableAnnotationUsage annotationUsage = makeAnnotation( HibernateAnnotations.GENERIC_GENERATOR ); - applyStringAttributeIfSpecified( "name", generator.getName(), annotationUsage ); + jaxbGenerators.forEach( (jaxbGenerator) -> { + final GenericGeneratorAnnotation annotation = GENERIC_GENERATOR.createUsage( sourceModelContext ); + annotation.name( jaxbGenerator.getName() ); + annotation.strategy( jaxbGenerator.getClazz() ); - applyStringAttributeIfSpecified( "strategy", generator.getClazz(), annotationUsage ); + annotation.parameters( XmlAnnotationHelper.collectParameters( + jaxbGenerator.getParameters(), + sourceModelContext + ) ); - // todo : update the mapping.xsd to account for new @GenericGenerator definition - applyAttributeIfSpecified( "parameters", generator.getParameters(), annotationUsage ); -// setValueIfNotNull( "type", generator.getType(), annotationUsage ); - collectGenericGenerator( new GenericGeneratorRegistration( generator.getName(), annotationUsage ) ); + collectGenericGenerator( new GenericGeneratorRegistration( jaxbGenerator.getName(), annotation ) ); } ); } - public void collectGenericGenerator(AnnotationUsage usage) { - collectGenericGenerator( new GenericGeneratorRegistration( usage.getAttributeValue( "name" ), usage ) ); + public void collectGenericGenerator(GenericGenerator usage) { + collectGenericGenerator( new GenericGeneratorRegistration( usage.name(), usage ) ); } public void collectGenericGenerator(GenericGeneratorRegistration generatorRegistration) { @@ -838,14 +921,16 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } ); } - public void collectQueryReferences(JaxbEntityMappingsImpl jaxbRoot) { - collectNamedSqlResultSetMappings( jaxbRoot.getSqlResultSetMappings() ); - collectNamedQueries( jaxbRoot.getNamedQueries() ); - collectNamedNativeQueries( jaxbRoot.getNamedNativeQueries() ); - collectStoredProcedureQueries( jaxbRoot.getNamedProcedureQueries() ); + public void collectQueryReferences(JaxbEntityMappingsImpl jaxbRoot, XmlDocumentContext xmlDocumentContext) { + collectNamedSqlResultSetMappings( jaxbRoot.getSqlResultSetMappings(), xmlDocumentContext ); + collectNamedQueries( jaxbRoot.getNamedQueries(), xmlDocumentContext ); + collectNamedNativeQueries( jaxbRoot.getNamedNativeQueries(), xmlDocumentContext ); + collectStoredProcedureQueries( jaxbRoot.getNamedProcedureQueries(), xmlDocumentContext ); } - private void collectNamedSqlResultSetMappings(List jaxbSqlResultSetMappings) { + private void collectNamedSqlResultSetMappings( + List jaxbSqlResultSetMappings, + XmlDocumentContext xmlDocumentContext) { if ( isEmpty( jaxbSqlResultSetMappings ) ) { return; } @@ -855,117 +940,30 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } jaxbSqlResultSetMappings.forEach( (jaxbMapping) -> { - final MutableAnnotationUsage mappingAnnotation = JpaAnnotations.SQL_RESULT_SET_MAPPING.createUsage( sourceModelContext ); - applyStringAttributeIfSpecified( "name", jaxbMapping.getName(), mappingAnnotation ); + final SqlResultSetMappingJpaAnnotation annotation = JpaAnnotations.SQL_RESULT_SET_MAPPING.createUsage( sourceModelContext ); + annotation.name( jaxbMapping.getName() ); + + annotation.columns( QueryProcessing.extractColumnResults( + jaxbMapping.getColumnResult(), + xmlDocumentContext + ) ); + annotation.classes( QueryProcessing.extractConstructorResults( + jaxbMapping.getConstructorResult(), + xmlDocumentContext + ) ); + annotation.entities( QueryProcessing.extractEntityResults( + jaxbMapping.getEntityResult(), + xmlDocumentContext + ) ); sqlResultSetMappingRegistrations.put( jaxbMapping.getName(), - new SqlResultSetMappingRegistration( jaxbMapping.getName(), mappingAnnotation ) - ); - - applyEntityResults( - jaxbMapping.getEntityResult(), - (results) -> applyAttributeIfSpecified( "entities", results, mappingAnnotation ) - ); - - applyConstructorResults( - jaxbMapping.getConstructorResult(), - (results) -> applyAttributeIfSpecified( "classes", results, mappingAnnotation ) - ); - - applyColumnResults( - jaxbMapping.getColumnResult(), - (columnResults) -> applyAttributeIfSpecified( "columns", columnResults, mappingAnnotation ) + new SqlResultSetMappingRegistration( jaxbMapping.getName(), annotation ) ); } ); } - private void applyEntityResults( - List jaxbEntityResults, - Consumer>> annotationListConsumer) { - if ( jaxbEntityResults.isEmpty() ) { - return; - } - - final List> entityResults = arrayList( jaxbEntityResults.size() ); - - for ( JaxbEntityResultImpl jaxbEntityResult : jaxbEntityResults ) { - final MutableAnnotationUsage entityResultAnnotation = makeAnnotation( JpaAnnotations.ENTITY_RESULT ); - entityResults.add( entityResultAnnotation ); - - entityResultAnnotation.setAttributeValue( - "entityClass", - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( jaxbEntityResult.getEntityClass() ) - ); - - applyAttributeIfSpecified( "lockMode", jaxbEntityResult.getLockMode(), entityResultAnnotation ); - applyStringAttributeIfSpecified( "discriminatorColumn", jaxbEntityResult.getDiscriminatorColumn(), entityResultAnnotation ); - - if ( !jaxbEntityResult.getFieldResult().isEmpty() ) { - final List> fieldResults = arrayList( jaxbEntityResult.getFieldResult().size() ); - entityResultAnnotation.setAttributeValue( "fields", fieldResults ); - - for ( JaxbFieldResultImpl jaxbFieldResult : jaxbEntityResult.getFieldResult() ) { - final MutableAnnotationUsage fieldResultAnnotation = JpaAnnotations.FIELD_RESULT.createUsage( sourceModelContext ); - fieldResults.add( fieldResultAnnotation ); - // both name and column are required - fieldResultAnnotation.setAttributeValue( "name", jaxbFieldResult.getName() ); - fieldResultAnnotation.setAttributeValue( "column", jaxbFieldResult.getColumn() ); - } - } - } - - annotationListConsumer.accept( entityResults ); - } - - private void applyConstructorResults( - List jaxbConstructorResults, - Consumer>> annotationListConsumer) { - if ( isEmpty( jaxbConstructorResults ) ) { - return; - } - - final List> results = arrayList( jaxbConstructorResults.size() ); - for ( JaxbConstructorResultImpl jaxbConstructorResult : jaxbConstructorResults ) { - final MutableAnnotationUsage result = makeAnnotation( JpaAnnotations.CONSTRUCTOR_RESULT ); - results.add( result ); - - result.setAttributeValue( - "targetClass", - sourceModelContext.getClassDetailsRegistry().resolveClassDetails( jaxbConstructorResult.getTargetClass() ) - ); - - if ( !jaxbConstructorResult.getColumns().isEmpty() ) { - applyColumnResults( - jaxbConstructorResult.getColumns(), - (columnResults) -> result.setAttributeValue( "columns", columnResults ) - ); - } - } - - annotationListConsumer.accept( results ); - } - - private void applyColumnResults( - List jaxbColumnResults, - Consumer>> annotationListConsumer) { - if ( isEmpty( jaxbColumnResults ) ) { - return; - } - - final List> columnResults = arrayList( jaxbColumnResults.size() ); - for ( JaxbColumnResultImpl jaxbColumn : jaxbColumnResults ) { - final MutableAnnotationUsage columnResultAnnotation = makeAnnotation( JpaAnnotations.COLUMN_RESULT ); - columnResults.add( columnResultAnnotation ); - - columnResultAnnotation.setAttributeValue( "name", jaxbColumn.getName() ); - applyAttributeIfSpecified( "type", sourceModelContext.getClassDetailsRegistry().resolveClassDetails( jaxbColumn.getClazz() ), columnResultAnnotation ); - } - - annotationListConsumer.accept( columnResults ); - } - - private void collectNamedQueries(List jaxbNamedQueries) { + private void collectNamedQueries(List jaxbNamedQueries, XmlDocumentContext xmlDocumentContext) { if ( isEmpty( jaxbNamedQueries ) ) { return; } @@ -975,71 +973,82 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } for ( JaxbNamedQueryImpl jaxbNamedQuery : jaxbNamedQueries ) { - final MutableAnnotationUsage queryAnnotation = makeAnnotation( JpaAnnotations.NAMED_QUERY ); + final NamedQueryJpaAnnotation queryAnnotation = JpaAnnotations.NAMED_QUERY.createUsage( xmlDocumentContext.getModelBuildingContext() ); namedQueryRegistrations.put( jaxbNamedQuery.getName(), new NamedQueryRegistration( jaxbNamedQuery.getName(), queryAnnotation ) ); - applyStringAttributeIfSpecified( "name", jaxbNamedQuery.getName(), queryAnnotation ); - applyStringAttributeIfSpecified( "query", jaxbNamedQuery.getQuery(), queryAnnotation ); - applyAttributeIfSpecified( "lockMode", jaxbNamedQuery.getLockMode(), queryAnnotation ); + queryAnnotation.name( jaxbNamedQuery.getName() ); + queryAnnotation.query( jaxbNamedQuery.getQuery() ); - final List> hints = extractQueryHints( jaxbNamedQuery ); - applyAttributeIfSpecified( "hints", hints, queryAnnotation ); - - if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) { - final MutableAnnotationUsage cacheableHint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - cacheableHint.setAttributeValue( "name", AvailableHints.HINT_CACHEABLE ); - cacheableHint.setAttributeValue( "value", Boolean.TRUE.toString() ); - hints.add( cacheableHint ); - - if ( jaxbNamedQuery.getCacheMode() != null ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_CACHE_MODE ); - hint.setAttributeValue( "value", jaxbNamedQuery.getCacheMode().name() ); - hints.add( hint ); - } - - if ( isNotEmpty( jaxbNamedQuery.getCacheRegion() ) ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_CACHE_REGION ); - hint.setAttributeValue( "value", jaxbNamedQuery.getCacheRegion() ); - hints.add( hint ); - } + if ( jaxbNamedQuery.getLockMode() != null ) { + queryAnnotation.lockMode( jaxbNamedQuery.getLockMode() ); } - if ( isNotEmpty( jaxbNamedQuery.getComment() ) ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_COMMENT ); - hint.setAttributeValue( "value", jaxbNamedQuery.getComment() ); - hints.add( hint ); - } - - if ( jaxbNamedQuery.getFetchSize() != null ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_FETCH_SIZE ); - hint.setAttributeValue( "value", jaxbNamedQuery.getFetchSize().toString() ); - hints.add( hint ); - } - - if ( jaxbNamedQuery.isReadOnly() == Boolean.TRUE ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_READ_ONLY ); - hint.setAttributeValue( "value", Boolean.TRUE.toString() ); - hints.add( hint ); - } - - if ( jaxbNamedQuery.getFlushMode() != null ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_FLUSH_MODE ); - hint.setAttributeValue( "value", jaxbNamedQuery.getFlushMode().name() ); - hints.add( hint ); - } + queryAnnotation.hints( collectQueryHints( + jaxbNamedQuery, + xmlDocumentContext + ) ); } } - private void collectNamedNativeQueries(List namedNativeQueries) { + private QueryHint[] collectQueryHints(JaxbNamedQueryImpl jaxbNamedQuery, XmlDocumentContext xmlDocumentContext) { + final List hints = extractQueryHints( jaxbNamedQuery ); + + if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) { + final QueryHintJpaAnnotation cacheableHint = JpaAnnotations.QUERY_HINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + cacheableHint.name( AvailableHints.HINT_CACHEABLE ); + cacheableHint.value( Boolean.TRUE.toString() ); + hints.add( cacheableHint ); + + if ( jaxbNamedQuery.getCacheMode() != null ) { + final QueryHintJpaAnnotation cacheModeHint = JpaAnnotations.QUERY_HINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + cacheModeHint.name( AvailableHints.HINT_CACHE_MODE ); + cacheModeHint.value( jaxbNamedQuery.getCacheMode().name() ); + hints.add( cacheModeHint ); + } + + if ( isNotEmpty( jaxbNamedQuery.getCacheRegion() ) ) { + final QueryHintJpaAnnotation cacheRegionHint = JpaAnnotations.QUERY_HINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + cacheRegionHint.name( AvailableHints.HINT_CACHE_REGION ); + cacheRegionHint.value( jaxbNamedQuery.getCacheRegion() ); + hints.add( cacheRegionHint ); + } + } + + if ( isNotEmpty( jaxbNamedQuery.getComment() ) ) { + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + hint.name( AvailableHints.HINT_COMMENT ); + hint.value( jaxbNamedQuery.getComment() ); + hints.add( hint ); + } + + if ( jaxbNamedQuery.getFetchSize() != null ) { + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + hint.name( AvailableHints.HINT_FETCH_SIZE ); + hint.value( jaxbNamedQuery.getFetchSize().toString() ); + hints.add( hint ); + } + + if ( jaxbNamedQuery.isReadOnly() == Boolean.TRUE ) { + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + hint.name( AvailableHints.HINT_READ_ONLY ); + hint.value( Boolean.TRUE.toString() ); + hints.add( hint ); + } + + if ( jaxbNamedQuery.getFlushMode() != null ) { + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + hint.name( AvailableHints.HINT_FLUSH_MODE ); + hint.value( jaxbNamedQuery.getFlushMode().name() ); + hints.add( hint ); + } + + return hints.toArray(QueryHint[]::new); + } + + private void collectNamedNativeQueries(List namedNativeQueries, XmlDocumentContext xmlDocumentContext) { if ( isEmpty( namedNativeQueries ) ) { return; } @@ -1049,72 +1058,93 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } for ( JaxbNamedNativeQueryImpl jaxbNamedQuery : namedNativeQueries ) { - final MutableAnnotationUsage queryAnnotation = makeAnnotation( JpaAnnotations.NAMED_NATIVE_QUERY ); + final NamedNativeQueryJpaAnnotation queryAnnotation = JpaAnnotations.NAMED_NATIVE_QUERY.createUsage( xmlDocumentContext.getModelBuildingContext() ); namedNativeQueryRegistrations.put( jaxbNamedQuery.getName(), new NamedNativeQueryRegistration( jaxbNamedQuery.getName(), queryAnnotation ) ); - queryAnnotation.setAttributeValue( "name", jaxbNamedQuery.getName() ); - queryAnnotation.setAttributeValue( "query", jaxbNamedQuery.getQuery() ); + queryAnnotation.name( jaxbNamedQuery.getName() ); + queryAnnotation.query( jaxbNamedQuery.getQuery() ); if ( isNotEmpty( jaxbNamedQuery.getResultClass() ) ) { - queryAnnotation.setAttributeValue( "resultClass", sourceModelContext.getClassDetailsRegistry().resolveClassDetails( jaxbNamedQuery.getResultClass() ) ); + final ClassDetails resultClassDetails = toClassDetails( jaxbNamedQuery.getResultClass() ); + queryAnnotation.resultClass( resultClassDetails.toJavaClass() ); } - applyStringAttributeIfSpecified( "resultSetMapping", jaxbNamedQuery.getResultSetMapping(), queryAnnotation ); + applyResultSetMapping( jaxbNamedQuery, queryAnnotation, xmlDocumentContext ); - applyEntityResults( - jaxbNamedQuery.getEntityResult(), - (results) -> queryAnnotation.setAttributeValue( "entities", results ) - ); - - applyConstructorResults( - jaxbNamedQuery.getConstructorResult(), - (results) -> queryAnnotation.setAttributeValue( "classes", results ) - ); - - applyColumnResults( - jaxbNamedQuery.getColumnResult(), - (columnResults) -> queryAnnotation.setAttributeValue( "columns", columnResults ) - ); - - final List> hints = extractQueryHints( jaxbNamedQuery ); - queryAnnotation.setAttributeValue( "hints", hints ); - - if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) { - final MutableAnnotationUsage cacheableHint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - cacheableHint.setAttributeValue( "name", AvailableHints.HINT_CACHEABLE ); - cacheableHint.setAttributeValue( "value", Boolean.TRUE.toString() ); - - if ( jaxbNamedQuery.getCacheMode() != null ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_CACHE_MODE ); - hint.setAttributeValue( "value", jaxbNamedQuery.getCacheMode().name() ); - } - - if ( isNotEmpty( jaxbNamedQuery.getCacheRegion() ) ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_CACHE_REGION ); - hint.setAttributeValue( "value", jaxbNamedQuery.getCacheRegion() ); - } - } - - if ( jaxbNamedQuery.isReadOnly() == Boolean.TRUE ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_READ_ONLY ); - hint.setAttributeValue( "value", Boolean.TRUE.toString() ); - } - - if ( isNotEmpty( jaxbNamedQuery.getComment() ) ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", AvailableHints.HINT_COMMENT ); - hint.setAttributeValue( "value", jaxbNamedQuery.getComment() ); - } + queryAnnotation.hints( collectNativeQueryHints( jaxbNamedQuery ) ); } } - private void collectStoredProcedureQueries(List namedProcedureQueries) { + private void applyResultSetMapping( + JaxbNamedNativeQueryImpl jaxbNamedQuery, + NamedNativeQueryJpaAnnotation queryAnnotation, + XmlDocumentContext xmlDocumentContext) { + if ( isNotEmpty( jaxbNamedQuery.getResultSetMapping() ) ) { + queryAnnotation.resultSetMapping( jaxbNamedQuery.getResultSetMapping() ); + return; + } + + queryAnnotation.columns( QueryProcessing.extractColumnResults( + jaxbNamedQuery.getColumnResult(), + xmlDocumentContext + ) ); + queryAnnotation.classes( QueryProcessing.extractConstructorResults( + jaxbNamedQuery.getConstructorResult(), + xmlDocumentContext + ) ); + queryAnnotation.entities( QueryProcessing.extractEntityResults( + jaxbNamedQuery.getEntityResult(), + xmlDocumentContext + ) ); + } + + private QueryHint[] collectNativeQueryHints(JaxbNamedNativeQueryImpl jaxbNamedQuery) { + final List hints = extractQueryHints( jaxbNamedQuery ); + + if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) { + final QueryHintJpaAnnotation cacheableHint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext ); + cacheableHint.name( AvailableHints.HINT_CACHEABLE ); + cacheableHint.value( Boolean.TRUE.toString() ); + hints.add( cacheableHint ); + + if ( jaxbNamedQuery.getCacheMode() != null ) { + final QueryHintJpaAnnotation cacheModeHint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext ); + cacheModeHint.name( AvailableHints.HINT_CACHE_MODE ); + cacheModeHint.value( jaxbNamedQuery.getCacheMode().name() ); + hints.add( cacheModeHint ); + } + + if ( isNotEmpty( jaxbNamedQuery.getCacheRegion() ) ) { + final QueryHintJpaAnnotation cacheRegionHint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext ); + cacheRegionHint.name( AvailableHints.HINT_CACHE_REGION ); + cacheRegionHint.value( jaxbNamedQuery.getCacheRegion() ); + hints.add( cacheRegionHint ); + } + } + + if ( jaxbNamedQuery.isReadOnly() == Boolean.TRUE ) { + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext ); + hint.name( AvailableHints.HINT_READ_ONLY ); + hint.value( Boolean.TRUE.toString() ); + hints.add( hint ); + } + + if ( isNotEmpty( jaxbNamedQuery.getComment() ) ) { + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext ); + hint.name( AvailableHints.HINT_COMMENT ); + hint.value( jaxbNamedQuery.getComment() ); + hints.add( hint ); + } + + return hints.toArray(QueryHint[]::new); + } + + private void collectStoredProcedureQueries( + List namedProcedureQueries, + XmlDocumentContext xmlDocumentContext) { if ( isEmpty( namedProcedureQueries ) ) { return; } @@ -1124,44 +1154,39 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { } for ( JaxbNamedStoredProcedureQueryImpl jaxbQuery : namedProcedureQueries ) { - final MutableAnnotationUsage queryAnnotation = makeAnnotation( JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY ); + final NamedStoredProcedureQueryJpaAnnotation queryAnnotation = NAMED_STORED_PROCEDURE_QUERY.createUsage( sourceModelContext ); namedStoredProcedureQueryRegistrations.put( jaxbQuery.getName(), new NamedStoredProcedureQueryRegistration( jaxbQuery.getName(), queryAnnotation ) ); - queryAnnotation.setAttributeValue( "name", jaxbQuery.getName() ); - queryAnnotation.setAttributeValue( "procedureName", jaxbQuery.getProcedureName() ); + queryAnnotation.name( jaxbQuery.getName() ); + queryAnnotation.procedureName( jaxbQuery.getProcedureName() ); - final ArrayList resultClasses = arrayList( jaxbQuery.getResultClasses().size() ); - applyAttributeIfSpecified( "resultClasses", resultClasses, queryAnnotation ); - for ( String resultClassName : jaxbQuery.getResultClasses() ) { - resultClasses.add( sourceModelContext.getClassDetailsRegistry().resolveClassDetails( resultClassName ) ); + queryAnnotation.resultClasses( collectResultClasses( + jaxbQuery.getResultClasses(), + xmlDocumentContext + ) ); + + if ( CollectionHelper.isNotEmpty( jaxbQuery.getResultSetMappings() ) ) { + queryAnnotation.resultSetMappings( jaxbQuery.getResultSetMappings().toArray(String[]::new) ); } - applyAttributeIfSpecified( "resultSetMappings", jaxbQuery.getResultSetMappings(), queryAnnotation ); + queryAnnotation.hints( extractQueryHints( jaxbQuery ).toArray(QueryHint[]::new) ); - applyAttributeIfSpecified( "hints", extractQueryHints( jaxbQuery ), queryAnnotation ); - - final ArrayList> parameters = arrayList( jaxbQuery.getProcedureParameters().size() ); - applyAttributeIfSpecified( "parameters", parameters, queryAnnotation ); - for ( JaxbStoredProcedureParameterImpl jaxbProcedureParameter : jaxbQuery.getProcedureParameters() ) { - final MutableAnnotationUsage parameterAnnotation = makeAnnotation( JpaAnnotations.STORED_PROCEDURE_PARAMETER ); - parameters.add( parameterAnnotation ); - - applyStringAttributeIfSpecified( "name", jaxbProcedureParameter.getName(), parameterAnnotation ); - applyAttributeIfSpecified( "mode", jaxbProcedureParameter.getMode(), parameterAnnotation ); - applyAttributeIfSpecified( "type", sourceModelContext.getClassDetailsRegistry().resolveClassDetails( jaxbProcedureParameter.getClazz() ), parameterAnnotation ); - } + queryAnnotation.parameters( QueryProcessing.collectParameters( + jaxbQuery.getProcedureParameters(), + xmlDocumentContext + ) ); } } - private List> extractQueryHints(JaxbNamedQueryBase jaxbQuery) { - final List> hints = new ArrayList<>(); + private List extractQueryHints(JaxbNamedQueryBase jaxbQuery) { + final List hints = new ArrayList<>(); for ( JaxbQueryHint jaxbHint : jaxbQuery.getHints() ) { - final MutableAnnotationUsage hint = makeAnnotation( JpaAnnotations.QUERY_HINT ); - hint.setAttributeValue( "name", jaxbHint.getName() ); - hint.setAttributeValue( "value", jaxbHint.getValue() ); + final QueryHintJpaAnnotation hint = JpaAnnotations.QUERY_HINT.createUsage( sourceModelContext ); + hint.name( jaxbHint.getName() ); + hint.value( jaxbHint.getValue() ); } return hints; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/ModelsHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/ModelsHelper.java new file mode 100644 index 0000000000..7c4c96ca27 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/ModelsHelper.java @@ -0,0 +1,59 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.internal; + +import org.hibernate.annotations.TenantId; +import org.hibernate.models.internal.jandex.JandexClassDetails; +import org.hibernate.models.internal.jdk.JdkBuilders; +import org.hibernate.models.spi.AnnotationDescriptorRegistry; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.RegistryPrimer; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.IndexView; + +/** + * @author Steve Ebersole + */ +public class ModelsHelper { + public static void preFillRegistries(RegistryPrimer.Contributions contributions, SourceModelBuildingContext buildingContext) { + OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation ); + + buildingContext.getAnnotationDescriptorRegistry().getDescriptor( TenantId.class ); + + final IndexView jandexIndex = buildingContext.getJandexIndex(); + if ( jandexIndex == null ) { + return; + } + + final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry(); + final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry(); + + for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) { + final String className = knownClass.name().toString(); + + if ( knownClass.isAnnotation() ) { + // it is always safe to load the annotation classes - we will never be enhancing them + //noinspection rawtypes + final Class annotationClass = buildingContext + .getClassLoading() + .classForName( className ); + //noinspection unchecked + annotationDescriptorRegistry.resolveDescriptor( + annotationClass, + (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext ) + ); + } + + classDetailsRegistry.resolveClassDetails( + className, + (name) -> new JandexClassDetails( knownClass, buildingContext ) + ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/internal/OrmAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/OrmAnnotationHelper.java new file mode 100644 index 0000000000..7266dd05e9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/internal/OrmAnnotationHelper.java @@ -0,0 +1,112 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.internal; + +import java.lang.annotation.Annotation; +import java.lang.annotation.Documented; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.function.Consumer; + +import org.hibernate.boot.models.DialectOverrideAnnotations; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.models.AnnotationAccessException; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AttributeDescriptor; +import org.hibernate.models.spi.JandexValueExtractor; +import org.hibernate.models.spi.SourceModelBuildingContext; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +/** + * @author Steve Ebersole + */ +public class OrmAnnotationHelper { + + public static void forEachOrmAnnotation(Consumer> consumer) { + JpaAnnotations.forEachAnnotation( consumer ); + HibernateAnnotations.forEachAnnotation( consumer ); + DialectOverrideAnnotations.forEachAnnotation( consumer ); + XmlAnnotations.forEachAnnotation( consumer ); + } + + public static void forEachOrmAnnotation(Class declarer, Consumer> consumer) { + for ( Field field : declarer.getFields() ) { + if ( AnnotationDescriptor.class.isAssignableFrom( field.getType() ) ) { + try { + consumer.accept( (AnnotationDescriptor) field.get( null ) ); + } + catch (IllegalAccessException e) { + throw new AnnotationAccessException( + String.format( + Locale.ROOT, + "Unable to access standard annotation descriptor field - %s", + field.getName() + ), + e + ); + } + } + } + } + + public static V extractJdkValue(A jdkAnnotation, AttributeDescriptor attributeDescriptor, SourceModelBuildingContext modelContext) { + return attributeDescriptor + .getTypeDescriptor() + .createJdkValueExtractor( modelContext ) + .extractValue( jdkAnnotation, attributeDescriptor, modelContext ); + } + + public static V extractJdkValue(A jdkAnnotation, AnnotationDescriptor annotationDescriptor, String attributeName, SourceModelBuildingContext modelContext) { + final AttributeDescriptor attributeDescriptor = annotationDescriptor.getAttribute( attributeName ); + return extractJdkValue( jdkAnnotation, attributeDescriptor, modelContext ); + } + + public static V extractJandexValue(AnnotationInstance jandexAnnotation, AttributeDescriptor attributeDescriptor, SourceModelBuildingContext modelContext) { + final JandexValueExtractor extractor = attributeDescriptor.getTypeDescriptor().createJandexValueExtractor( modelContext ); + return extractor.extractValue( jandexAnnotation, attributeDescriptor, modelContext ); +// final AnnotationValue value = jandexAnnotation.value( attributeDescriptor.getName() ); +// return attributeDescriptor +// .getTypeDescriptor() +// .createJandexValueConverter( modelContext ) +// .convert( value, modelContext ); + } + + public static V extractJandexValue(AnnotationInstance jandexAnnotation, AnnotationDescriptor annotationDescriptor, String attributeName, SourceModelBuildingContext modelContext) { + final AttributeDescriptor attributeDescriptor = annotationDescriptor.getAttribute( attributeName ); + return extractJandexValue( jandexAnnotation, attributeDescriptor, modelContext ); + } + + public static List extractAnnotationTypeAnnotations(Class annotationType) { + final ArrayList result = new ArrayList<>(); + final Annotation[] annotationTypeAnnotations = annotationType.getAnnotations(); + for ( int i = 0; i < annotationTypeAnnotations.length; i++ ) { + final Annotation annotationTypeAnnotation = annotationTypeAnnotations[i]; + final Class annotationTypeAnnotationType = annotationTypeAnnotation.annotationType(); + + // skip a few well-know ones that are irrelevant + if ( annotationTypeAnnotationType == Repeatable.class + || annotationTypeAnnotationType == Target.class + || annotationTypeAnnotationType == Retention.class + || annotationTypeAnnotationType == Documented.class ) { + continue; + } + + result.add( annotationTypeAnnotation ); + } + return result; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CollectionTypeRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/CollectionTypeRegistration.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CollectionTypeRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/CollectionTypeRegistration.java index 0d110df4df..d499b544b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CollectionTypeRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/CollectionTypeRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import java.util.Map; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CompositeUserTypeRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/CompositeUserTypeRegistration.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CompositeUserTypeRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/CompositeUserTypeRegistration.java index 85f947e134..1e0b7464f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CompositeUserTypeRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/CompositeUserTypeRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import org.hibernate.models.spi.ClassDetails; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ConversionRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/ConversionRegistration.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ConversionRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/ConversionRegistration.java index 195c208582..f1f7079215 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ConversionRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/ConversionRegistration.java @@ -5,7 +5,7 @@ * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import java.lang.annotation.Annotation; import java.util.List; @@ -21,7 +21,6 @@ import org.hibernate.boot.model.convert.spi.JpaAttributeConverterCreationContext import org.hibernate.boot.model.convert.spi.RegisteredConversion; import org.hibernate.boot.models.Copied; import org.hibernate.models.spi.AnnotationDescriptor; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.type.descriptor.converter.internal.JpaAttributeConverterImpl; import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter; @@ -44,14 +43,14 @@ import jakarta.persistence.AttributeConverter; */ @Copied(RegisteredConversion.class) public class ConversionRegistration { - private final ClassDetails explicitDomainType; - private final ClassDetails converterType; + private final Class explicitDomainType; + private final Class> converterType; private final boolean autoApply; private final AnnotationDescriptor source; public ConversionRegistration( - ClassDetails explicitDomainType, - ClassDetails converterType, + Class explicitDomainType, + Class> converterType, boolean autoApply, AnnotationDescriptor source) { assert converterType != null; @@ -81,11 +80,11 @@ public class ConversionRegistration { return Objects.hash( explicitDomainType, converterType ); } - public ClassDetails getExplicitDomainType() { + public Class getExplicitDomainType() { return explicitDomainType; } - public ClassDetails getConverterType() { + public Class> getConverterType() { return converterType; } @@ -99,13 +98,10 @@ public class ConversionRegistration { @Override public String toString() { - return "ConversionRegistration( " + converterType.getClassName() + ", " + source.getAnnotationType().getSimpleName() + ", " + autoApply + ")"; + return "ConversionRegistration( " + converterType.getName() + ", " + source.getAnnotationType().getSimpleName() + ", " + autoApply + ")"; } public ConverterDescriptor makeConverterDescriptor(ClassmateContext classmateContext) { - final Class explicitDomainType = this.explicitDomainType.toJavaClass(); - final Class> converterType = this.converterType.toJavaClass(); - final List resolvedParamTypes = ConverterHelper.resolveConverterClassParamTypes( converterType, classmateContext diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ConverterRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/ConverterRegistration.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ConverterRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/ConverterRegistration.java index a9f5e85ec6..b4416f84ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ConverterRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/ConverterRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import java.util.Objects; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/EmbeddableInstantiatorRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/EmbeddableInstantiatorRegistration.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/EmbeddableInstantiatorRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/EmbeddableInstantiatorRegistration.java index 73bf47e408..35936bdb23 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/EmbeddableInstantiatorRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/EmbeddableInstantiatorRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import org.hibernate.models.spi.ClassDetails; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/FilterDefRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/FilterDefRegistration.java similarity index 98% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/FilterDefRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/FilterDefRegistration.java index 0d8e32b3c2..483e94c50f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/FilterDefRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/FilterDefRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import java.util.Collections; import java.util.HashMap; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/GenericGeneratorRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/GenericGeneratorRegistration.java similarity index 69% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/GenericGeneratorRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/GenericGeneratorRegistration.java index 20351316d2..f70d174497 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/GenericGeneratorRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/GenericGeneratorRegistration.java @@ -4,10 +4,9 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import org.hibernate.annotations.GenericGenerator; -import org.hibernate.models.spi.AnnotationUsage; /** * Global registration of a generic generator @@ -16,5 +15,5 @@ import org.hibernate.models.spi.AnnotationUsage; * @see GenericGenerator * @see org.hibernate.boot.jaxb.mapping.spi.JaxbGenericIdGeneratorImpl */ -public record GenericGeneratorRegistration(String name, AnnotationUsage configuration) { +public record GenericGeneratorRegistration(String name, GenericGenerator configuration) { } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/GlobalRegistrations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/GlobalRegistrations.java similarity index 93% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/GlobalRegistrations.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/GlobalRegistrations.java index 513f6cb577..da721a7ebb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/GlobalRegistrations.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/GlobalRegistrations.java @@ -4,14 +4,12 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import java.util.List; import java.util.Map; import java.util.Set; -import org.hibernate.boot.models.categorize.spi.NamedQueryRegistration; - /** * Registrations which are considered global, collected across annotations diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JavaTypeRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/JavaTypeRegistration.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JavaTypeRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/JavaTypeRegistration.java index f612773564..541dc093b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JavaTypeRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/JavaTypeRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import org.hibernate.models.spi.ClassDetails; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JdbcTypeRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/JdbcTypeRegistration.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JdbcTypeRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/JdbcTypeRegistration.java index 2b5314d4c2..d1a220baba 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JdbcTypeRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/JdbcTypeRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import org.hibernate.models.spi.ClassDetails; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JpaEventListener.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/JpaEventListener.java similarity index 85% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JpaEventListener.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/JpaEventListener.java index 031d54fb8a..07773d833b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JpaEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/JpaEventListener.java @@ -4,11 +4,11 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaultsImpl; -import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle; import org.hibernate.internal.util.MutableObject; import org.hibernate.models.ModelsException; import org.hibernate.models.spi.ClassDetails; @@ -24,6 +24,14 @@ import jakarta.persistence.PrePersist; import jakarta.persistence.PreRemove; import jakarta.persistence.PreUpdate; +import static org.hibernate.boot.models.JpaAnnotations.POST_LOAD; +import static org.hibernate.boot.models.JpaAnnotations.POST_PERSIST; +import static org.hibernate.boot.models.JpaAnnotations.POST_REMOVE; +import static org.hibernate.boot.models.JpaAnnotations.POST_UPDATE; +import static org.hibernate.boot.models.JpaAnnotations.PRE_PERSIST; +import static org.hibernate.boot.models.JpaAnnotations.PRE_REMOVE; +import static org.hibernate.boot.models.JpaAnnotations.PRE_UPDATE; + /** * JPA-style event listener with support for resolving callback methods from * {@linkplain #from(JpaEventListenerStyle, ClassDetails, JaxbEntityListenerImpl, SourceModelBuildingContext) XML} @@ -135,57 +143,48 @@ public class JpaEventListener { } listenerClassDetails.forEachMethod( (index, methodDetails) -> { + final MutableMemberDetails mutableMethodDetails = (MutableMemberDetails) methodDetails; if ( jaxbMapping.getPrePersist() != null && methodDetails.getName().equals( jaxbMapping.getPrePersist().getMethodName() ) && matchesSignature( consumerType, methodDetails ) ) { prePersistMethod.set( methodDetails ); - ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( - JpaAnnotations.PRE_PERSIST.createUsage( modelsContext ) - ); + mutableMethodDetails.addAnnotationUsage( PRE_PERSIST.createUsage( modelsContext ) ); } else if ( jaxbMapping.getPostPersist() != null && methodDetails.getName().equals( jaxbMapping.getPostPersist().getMethodName() ) && matchesSignature( consumerType, methodDetails ) ) { postPersistMethod.set( methodDetails ); - ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( - JpaAnnotations.POST_PERSIST.createUsage( modelsContext ) - ); + mutableMethodDetails.addAnnotationUsage( POST_PERSIST.createUsage( modelsContext ) ); } else if ( jaxbMapping.getPreRemove() != null && methodDetails.getName().equals( jaxbMapping.getPreRemove().getMethodName() ) && matchesSignature( consumerType, methodDetails ) ) { preRemoveMethod.set( methodDetails ); - ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( - JpaAnnotations.PRE_REMOVE.createUsage( modelsContext ) - ); + mutableMethodDetails.addAnnotationUsage( PRE_REMOVE.createUsage( modelsContext ) ); } else if ( jaxbMapping.getPostRemove() != null && methodDetails.getName().equals( jaxbMapping.getPostRemove().getMethodName() ) && matchesSignature( consumerType, methodDetails ) ) { postRemoveMethod.set( methodDetails ); - ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( - JpaAnnotations.POST_REMOVE.createUsage( modelsContext ) - ); + mutableMethodDetails.addAnnotationUsage( POST_REMOVE.createUsage( modelsContext ) ); } else if ( jaxbMapping.getPreUpdate() != null && methodDetails.getName().equals( jaxbMapping.getPreUpdate().getMethodName() ) && matchesSignature( consumerType, methodDetails ) ) { preUpdateMethod.set( methodDetails ); - ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( - JpaAnnotations.PRE_UPDATE.createUsage( modelsContext ) - ); + mutableMethodDetails.addAnnotationUsage( PRE_UPDATE.createUsage( modelsContext ) ); } else if ( jaxbMapping.getPostUpdate() != null && methodDetails.getName().equals( jaxbMapping.getPostUpdate().getMethodName() ) && matchesSignature( consumerType, methodDetails ) ) { postUpdateMethod.set( methodDetails ); - ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( JpaAnnotations.POST_UPDATE.createUsage( modelsContext ) ); + mutableMethodDetails.addAnnotationUsage( POST_UPDATE.createUsage( modelsContext ) ); } else if ( jaxbMapping.getPostLoad() != null && methodDetails.getName().equals( jaxbMapping.getPostLoad().getMethodName() ) && matchesSignature( consumerType, methodDetails ) ) { postLoadMethod.set( methodDetails ); - ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( JpaAnnotations.POST_LOAD.createUsage( modelsContext ) ); + mutableMethodDetails.addAnnotationUsage( POST_LOAD.createUsage( modelsContext ) ); } } ); @@ -244,31 +243,31 @@ public class JpaEventListener { final MutableObject postLoadMethod = new MutableObject<>(); listenerClassDetails.forEachMethod( (index, methodDetails) -> { - if ( methodDetails.getAnnotationUsage( PrePersist.class ) != null + if ( methodDetails.hasDirectAnnotationUsage( PrePersist.class ) && matchesSignature( consumerType, methodDetails ) ) { prePersistMethod.set( methodDetails ); } - else if ( methodDetails.getAnnotationUsage( PostPersist.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostPersist.class ) && matchesSignature( consumerType, methodDetails ) ) { postPersistMethod.set( methodDetails ); } - else if ( methodDetails.getAnnotationUsage( PreRemove.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PreRemove.class ) && matchesSignature( consumerType, methodDetails ) ) { preRemoveMethod.set( methodDetails ); } - else if ( methodDetails.getAnnotationUsage( PostRemove.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostRemove.class ) && matchesSignature( consumerType, methodDetails ) ) { postRemoveMethod.set( methodDetails ); } - else if ( methodDetails.getAnnotationUsage( PreUpdate.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PreUpdate.class ) && matchesSignature( consumerType, methodDetails ) ) { preUpdateMethod.set( methodDetails ); } - else if ( methodDetails.getAnnotationUsage( PostUpdate.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostUpdate.class ) && matchesSignature( consumerType, methodDetails ) ) { postUpdateMethod.set( methodDetails ); } - else if ( methodDetails.getAnnotationUsage( PostLoad.class ) != null + else if ( methodDetails.hasDirectAnnotationUsage( PostLoad.class ) && matchesSignature( consumerType, methodDetails ) ) { postLoadMethod.set( methodDetails ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedNativeQueryRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedNativeQueryRegistration.java similarity index 52% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedNativeQueryRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedNativeQueryRegistration.java index 4116a68705..3af5aa868a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedNativeQueryRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedNativeQueryRegistration.java @@ -4,15 +4,12 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import java.util.Collections; -import java.util.List; import java.util.Map; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import jakarta.persistence.NamedNativeQuery; import jakarta.persistence.QueryHint; @@ -20,28 +17,28 @@ import jakarta.persistence.QueryHint; /** * @author Steve Ebersole */ -public record NamedNativeQueryRegistration(String name, AnnotationUsage configuration) { +public record NamedNativeQueryRegistration(String name, NamedNativeQuery configuration) { public String getQueryString() { - return configuration.getString( "query" ); + return configuration.query(); } - public ClassDetails getResultClass() { - return configuration.getClassDetails( "resultClass" ); + public Class getResultClass() { + return configuration.resultClass(); } public String getResultSetMapping() { - return configuration.getString( "resultSetMapping" ); + return configuration.resultSetMapping(); } public Map getQueryHints() { - final List> hints = configuration.getList( "hints" ); + final QueryHint[] hints = configuration.hints(); if ( CollectionHelper.isEmpty( hints ) ) { return Collections.emptyMap(); } - final Map result = CollectionHelper.linkedMapOfSize( hints.size() ); - for ( AnnotationUsage hint : hints ) { - result.put( hint.getString( "name" ), hint.getString( "value" ) ); + final Map result = CollectionHelper.linkedMapOfSize( hints.length ); + for ( QueryHint hint : hints ) { + result.put( hint.name(), hint.value() ); } return result; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedQueryRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedQueryRegistration.java similarity index 60% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedQueryRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedQueryRegistration.java index 975f8db502..143baf3dad 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedQueryRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedQueryRegistration.java @@ -4,14 +4,12 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import java.util.Collections; -import java.util.List; import java.util.Map; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; import jakarta.persistence.LockModeType; import jakarta.persistence.NamedQuery; @@ -20,24 +18,24 @@ import jakarta.persistence.QueryHint; /** * @author Steve Ebersole */ -public record NamedQueryRegistration(String name, AnnotationUsage configuration) { +public record NamedQueryRegistration(String name, NamedQuery configuration) { public String getQueryString() { - return configuration.getString( "query" ); + return configuration.query(); } public LockModeType getLockModeType() { - return configuration.getEnum( "lockMode" ); + return configuration.lockMode(); } public Map getQueryHints() { - final List> hints = configuration.getList( "hints" ); + final QueryHint[] hints = configuration.hints(); if ( CollectionHelper.isEmpty( hints ) ) { return Collections.emptyMap(); } - final Map result = CollectionHelper.linkedMapOfSize( hints.size() ); - for ( AnnotationUsage hint : hints ) { - result.put( hint.getString( "name" ), hint.getString( "value" ) ); + final Map result = CollectionHelper.linkedMapOfSize( hints.length ); + for ( QueryHint hint : hints ) { + result.put( hint.name(), hint.value() ); } return result; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedStoredProcedureQueryRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedStoredProcedureQueryRegistration.java similarity index 70% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedStoredProcedureQueryRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedStoredProcedureQueryRegistration.java index dc01951169..8044820258 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NamedStoredProcedureQueryRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/NamedStoredProcedureQueryRegistration.java @@ -4,14 +4,12 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; - -import org.hibernate.models.spi.AnnotationUsage; +package org.hibernate.boot.models.spi; import jakarta.persistence.NamedStoredProcedureQuery; /** * @author Steve Ebersole */ -public record NamedStoredProcedureQueryRegistration(String name, AnnotationUsage configuration) { +public record NamedStoredProcedureQueryRegistration(String name, NamedStoredProcedureQuery configuration) { } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/SequenceGeneratorRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/SequenceGeneratorRegistration.java similarity index 63% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/SequenceGeneratorRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/SequenceGeneratorRegistration.java index 592d87e706..29750e853b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/SequenceGeneratorRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/SequenceGeneratorRegistration.java @@ -4,9 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; - -import org.hibernate.models.spi.AnnotationUsage; +package org.hibernate.boot.models.spi; import jakarta.persistence.SequenceGenerator; @@ -15,5 +13,5 @@ import jakarta.persistence.SequenceGenerator; * * @author Steve Ebersole */ -public record SequenceGeneratorRegistration(String name, AnnotationUsage configuration) { +public record SequenceGeneratorRegistration(String name, SequenceGenerator configuration) { } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/SqlResultSetMappingRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/SqlResultSetMappingRegistration.java similarity index 67% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/SqlResultSetMappingRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/SqlResultSetMappingRegistration.java index 2a3b53d720..e14621c788 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/SqlResultSetMappingRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/SqlResultSetMappingRegistration.java @@ -4,9 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; - -import org.hibernate.models.spi.AnnotationUsage; +package org.hibernate.boot.models.spi; import jakarta.persistence.SqlResultSetMapping; @@ -16,5 +14,5 @@ import jakarta.persistence.SqlResultSetMapping; * * @author Steve Ebersole */ -public record SqlResultSetMappingRegistration(String name, AnnotationUsage configuration) { +public record SqlResultSetMappingRegistration(String name, SqlResultSetMapping configuration) { } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/TableGeneratorRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/TableGeneratorRegistration.java similarity index 64% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/TableGeneratorRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/TableGeneratorRegistration.java index 36a0cc6a6a..3f6d4aa31f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/TableGeneratorRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/TableGeneratorRegistration.java @@ -4,9 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; - -import org.hibernate.models.spi.AnnotationUsage; +package org.hibernate.boot.models.spi; import jakarta.persistence.TableGenerator; @@ -15,5 +13,5 @@ import jakarta.persistence.TableGenerator; * * @author Steve Ebersole */ -public record TableGeneratorRegistration(String name, AnnotationUsage configuration) { +public record TableGeneratorRegistration(String name, TableGenerator configuration) { } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/UserTypeRegistration.java b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/UserTypeRegistration.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/UserTypeRegistration.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/spi/UserTypeRegistration.java index 06cb47aa2e..88ca852f09 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/UserTypeRegistration.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/spi/UserTypeRegistration.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models.spi; import org.hibernate.models.spi.ClassDetails; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/EntityGraphProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/EntityGraphProcessing.java index 6df9ea7556..60917eabf2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/EntityGraphProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/EntityGraphProcessing.java @@ -6,7 +6,6 @@ */ package org.hibernate.boot.models.xml.internal; -import java.util.ArrayList; import java.util.List; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityImpl; @@ -14,23 +13,23 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedAttributeNodeImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedEntityGraphImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedSubgraphImpl; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.NamedAttributeNodeJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedEntityGraphJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedEntityGraphsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedSubgraphJpaAnnotation; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.SourceModelBuildingContext; import jakarta.persistence.NamedAttributeNode; import jakarta.persistence.NamedEntityGraph; -import jakarta.persistence.NamedEntityGraphs; import jakarta.persistence.NamedSubgraph; import static org.hibernate.boot.models.JpaAnnotations.NAMED_ATTRIBUTE_NODE; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified; -import static org.hibernate.boot.models.xml.internal.XmlProcessingHelper.applyAttributeIfSpecified; -import static org.hibernate.internal.util.collections.CollectionHelper.arrayList; +import static org.hibernate.boot.models.JpaAnnotations.NAMED_SUBGRAPH; /** * Processing for JPA entity graphs from XML @@ -48,121 +47,127 @@ public class EntityGraphProcessing { } final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); - final MutableAnnotationUsage entityGraphsUsage = classDetails.replaceAnnotationUsage( + final NamedEntityGraphsJpaAnnotation entityGraphsUsage = (NamedEntityGraphsJpaAnnotation) classDetails.replaceAnnotationUsage( JpaAnnotations.NAMED_ENTITY_GRAPH, JpaAnnotations.NAMED_ENTITY_GRAPHS, modelBuildingContext ); - final ArrayList entityGraphList = arrayList( jaxbEntityGraphs.size() ); - entityGraphsUsage.setAttributeValue( "value", entityGraphList ); + final NamedEntityGraph[] graphs = new NamedEntityGraph[jaxbEntityGraphs.size()]; + entityGraphsUsage.value( graphs ); - for ( JaxbNamedEntityGraphImpl namedEntityGraph : jaxbEntityGraphs ) { - final AnnotationUsage graphUsage = extractGraph( namedEntityGraph, classDetails, modelBuildingContext, xmlDocumentContext ); - entityGraphList.add( graphUsage ); + for ( int i = 0; i < jaxbEntityGraphs.size(); i++ ) { + graphs[i] = extractGraph( jaxbEntityGraphs.get( i ), classDetails, modelBuildingContext, xmlDocumentContext ); } } - private static AnnotationUsage extractGraph( + private static NamedEntityGraph extractGraph( JaxbNamedEntityGraphImpl jaxbEntityGraph, ClassDetails classDetails, SourceModelBuildingContext modelBuildingContext, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage graphUsage = JpaAnnotations.NAMED_ENTITY_GRAPH.createUsage( modelBuildingContext ); + final NamedEntityGraphJpaAnnotation graphUsage = JpaAnnotations.NAMED_ENTITY_GRAPH.createUsage( modelBuildingContext ); - applyStringAttributeIfSpecified( "name", jaxbEntityGraph.getName(), graphUsage ); - applyAttributeIfSpecified( "includeAllAttributes", jaxbEntityGraph.isIncludeAllAttributes(), graphUsage ); + if ( StringHelper.isNotEmpty( jaxbEntityGraph.getName() ) ) { + graphUsage.name( jaxbEntityGraph.getName() ); + } + + if ( jaxbEntityGraph.isIncludeAllAttributes() != null ) { + graphUsage.includeAllAttributes( jaxbEntityGraph.isIncludeAllAttributes() ); + } if ( CollectionHelper.isNotEmpty( jaxbEntityGraph.getNamedAttributeNode() ) ) { - final List> attributeNodeList = extractAttributeNodes( + graphUsage.attributeNodes( extractAttributeNodes( jaxbEntityGraph.getNamedAttributeNode(), classDetails, modelBuildingContext, xmlDocumentContext - ); - graphUsage.setAttributeValue( "attributeNodes", attributeNodeList ); + ) ); } if ( CollectionHelper.isNotEmpty( jaxbEntityGraph.getSubgraph() ) ) { - final List> subgraphList = extractSubgraphNodes( + graphUsage.subgraphs( extractSubgraphNodes( jaxbEntityGraph.getSubgraph(), classDetails, modelBuildingContext, xmlDocumentContext - ); - graphUsage.setAttributeValue( "subgraphs", subgraphList ); + ) ); } if ( CollectionHelper.isNotEmpty( jaxbEntityGraph.getSubclassSubgraph() ) ) { - final List> subgraphList = extractSubgraphNodes( + graphUsage.subclassSubgraphs( extractSubgraphNodes( jaxbEntityGraph.getSubclassSubgraph(), classDetails, modelBuildingContext, xmlDocumentContext - ); - graphUsage.setAttributeValue( "subclassSubgraphs", subgraphList ); + ) ); } return graphUsage; } - private static List> extractAttributeNodes( + private static NamedAttributeNode[] extractAttributeNodes( List jaxbAttributeNodes, ClassDetails classDetails, SourceModelBuildingContext modelBuildingContext, XmlDocumentContext xmlDocumentContext) { assert CollectionHelper.isNotEmpty( jaxbAttributeNodes ); - final ArrayList> attributeNodeList = arrayList( jaxbAttributeNodes.size() ); - for ( JaxbNamedAttributeNodeImpl jaxbAttributeNode : jaxbAttributeNodes ) { - final MutableAnnotationUsage namedAttributeNodeAnn = NAMED_ATTRIBUTE_NODE.createUsage( modelBuildingContext ); - attributeNodeList.add( namedAttributeNodeAnn ); + final NamedAttributeNode[] attributeNodes = new NamedAttributeNode[jaxbAttributeNodes.size()]; + for ( int i = 0; i < jaxbAttributeNodes.size(); i++ ) { + final NamedAttributeNodeJpaAnnotation namedAttributeNodeAnn = NAMED_ATTRIBUTE_NODE.createUsage( modelBuildingContext ); + attributeNodes[i] = namedAttributeNodeAnn; - namedAttributeNodeAnn.setAttributeValue( "value", jaxbAttributeNode.getName() ); - applyStringAttributeIfSpecified( "subgraph", jaxbAttributeNode.getSubgraph(), namedAttributeNodeAnn ); - applyStringAttributeIfSpecified( "keySubgraph", jaxbAttributeNode.getKeySubgraph(), namedAttributeNodeAnn ); + final JaxbNamedAttributeNodeImpl jaxbAttributeNode = jaxbAttributeNodes.get( i ); + namedAttributeNodeAnn.value( jaxbAttributeNode.getName() ); + + if ( StringHelper.isNotEmpty( jaxbAttributeNode.getSubgraph() ) ) { + namedAttributeNodeAnn.subgraph( jaxbAttributeNode.getSubgraph() ); + } + if ( StringHelper.isNotEmpty( jaxbAttributeNode.getKeySubgraph() ) ) { + namedAttributeNodeAnn.keySubgraph( jaxbAttributeNode.getKeySubgraph() ); + } } - return attributeNodeList; + return attributeNodes; } - private static List> extractSubgraphNodes( + private static NamedSubgraph[] extractSubgraphNodes( List jaxbSubgraphs, ClassDetails classDetails, SourceModelBuildingContext modelBuildingContext, XmlDocumentContext xmlDocumentContext) { assert CollectionHelper.isNotEmpty( jaxbSubgraphs ); - final List> subgraphAnnotations = arrayList( jaxbSubgraphs.size() ); - for ( JaxbNamedSubgraphImpl jaxbSubgraph : jaxbSubgraphs ) { - final MutableAnnotationUsage namedSubGraphUsage = JpaAnnotations.NAMED_SUB_GRAPH.createUsage( modelBuildingContext ); - subgraphAnnotations.add( namedSubGraphUsage ); + final NamedSubgraph[] subgraphs = new NamedSubgraph[jaxbSubgraphs.size()]; + for ( int i = 0; i < jaxbSubgraphs.size(); i++ ) { + final NamedSubgraphJpaAnnotation namedSubGraphUsage = NAMED_SUBGRAPH.createUsage( modelBuildingContext ); + subgraphs[i] = namedSubGraphUsage; - namedSubGraphUsage.setAttributeValue( "name", jaxbSubgraph.getName() ); + final JaxbNamedSubgraphImpl jaxbSubgraph = jaxbSubgraphs.get( i ); + namedSubGraphUsage.name( jaxbSubgraph.getName() ); - final ClassDetails typeDetails; + Class type; if ( jaxbSubgraph.getClazz() == null ) { - typeDetails = ClassDetails.VOID_CLASS_DETAILS; + type = void.class; } else { - typeDetails = xmlDocumentContext.resolveJavaType( jaxbSubgraph.getClazz() ); + final ClassDetails typeDetails = xmlDocumentContext.resolveJavaType( jaxbSubgraph.getClazz() ); + type = typeDetails.toJavaClass(); } - namedSubGraphUsage.setAttributeValue( "type", typeDetails ); + namedSubGraphUsage.type( type ); if ( CollectionHelper.isNotEmpty( jaxbSubgraph.getNamedAttributeNode() ) ) { - namedSubGraphUsage.setAttributeValue( - "attributeNodes", - extractAttributeNodes( - jaxbSubgraph.getNamedAttributeNode(), - classDetails, - modelBuildingContext, - xmlDocumentContext - ) - ); + namedSubGraphUsage.attributeNodes( extractAttributeNodes( + jaxbSubgraph.getNamedAttributeNode(), + classDetails, + modelBuildingContext, + xmlDocumentContext + ) ); } } - return subgraphAnnotations; + return subgraphs; } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/FilterProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/FilterProcessing.java new file mode 100644 index 0000000000..9b3ace6567 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/FilterProcessing.java @@ -0,0 +1,54 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.boot.models.xml.internal; + +import java.util.List; + +import org.hibernate.annotations.SqlFragmentAlias; +import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.annotations.internal.SqlFragmentAliasAnnotation; +import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.models.spi.ClassDetails; + +/** + * @author Steve Ebersole + */ +public class FilterProcessing { + private static final SqlFragmentAlias[] NO_ALIASES = new SqlFragmentAlias[0]; + + public static SqlFragmentAlias[] collectSqlFragmentAliases( + List jaxbAliases, + XmlDocumentContext xmlDocumentContext) { + if ( CollectionHelper.isEmpty( jaxbAliases ) ) { + return NO_ALIASES; + } + + final SqlFragmentAlias[] result = new SqlFragmentAlias[jaxbAliases.size()]; + for ( int i = 0; i < jaxbAliases.size(); i++ ) { + final SqlFragmentAliasAnnotation alias = (SqlFragmentAliasAnnotation) HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage( + xmlDocumentContext.getModelBuildingContext() + ); + result[i] = alias; + + final JaxbHbmFilterImpl.JaxbAliasesImpl jaxbAlias = jaxbAliases.get( i ); + alias.alias( jaxbAlias.getAlias() ); + if ( StringHelper.isNotEmpty( jaxbAlias.getTable() ) ) { + alias.table( jaxbAlias.getTable() ); + } + if ( StringHelper.isNotEmpty( jaxbAlias.getEntity() ) ) { + final ClassDetails classDetails = xmlDocumentContext.getModelBuildingContext() + .getClassDetailsRegistry() + .resolveClassDetails( jaxbAlias.getEntity() ); + alias.entity( classDetails.toJavaClass() ); + } + } + return result; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/ManagedTypeProcessor.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/ManagedTypeProcessor.java index fdee599be2..cd29e2d8f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/ManagedTypeProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/ManagedTypeProcessor.java @@ -10,10 +10,7 @@ import java.lang.reflect.Modifier; import java.util.List; import java.util.function.Supplier; -import org.hibernate.annotations.AttributeAccessor; -import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.boot.internal.Extends; import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainer; import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbCachingImpl; @@ -29,6 +26,12 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistentAttribute; import org.hibernate.boot.jaxb.mapping.spi.JaxbTenantIdImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.AccessJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AttributeAccessorAnnotation; +import org.hibernate.boot.models.annotations.internal.CacheAnnotation; +import org.hibernate.boot.models.annotations.internal.CacheableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ExtendsXmlAnnotation; import org.hibernate.boot.models.xml.internal.attr.BasicAttributeProcessing; import org.hibernate.boot.models.xml.internal.attr.BasicIdAttributeProcessing; import org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing; @@ -43,12 +46,10 @@ import org.hibernate.models.internal.ModelsClassLogging; import org.hibernate.models.internal.RenderingCollectorImpl; import org.hibernate.models.internal.dynamic.DynamicClassDetails; import org.hibernate.models.internal.dynamic.DynamicFieldDetails; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.MethodDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import org.hibernate.models.spi.SourceModelBuildingContext; @@ -57,7 +58,6 @@ import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies; import jakarta.persistence.Access; import jakarta.persistence.AccessType; -import jakarta.persistence.Cacheable; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Id; @@ -485,12 +485,12 @@ public class ManagedTypeProcessor { MutableMemberDetails memberDetails, JaxbPersistentAttribute jaxbAttribute, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage annotationUsage = memberDetails.applyAnnotationUsage( + final AttributeAccessorAnnotation annotationUsage = (AttributeAccessorAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.ATTRIBUTE_ACCESSOR, xmlDocumentContext.getModelBuildingContext() ); // todo (7.0) : this is the old String-based, deprecated form - annotationUsage.setAttributeValue( "value", BuiltInPropertyAccessStrategies.MAP.getExternalName() ); + annotationUsage.value( BuiltInPropertyAccessStrategies.MAP.getExternalName() ); } private static void processEntityMetadata( @@ -506,12 +506,12 @@ public class ManagedTypeProcessor { applyCaching( jaxbEntity, classDetails, xmlDocumentContext ); if ( jaxbEntity.isAbstract() != null ) { - classDetails.applyAnnotationUsage( HibernateAnnotations.ABSTRACT, xmlDocumentContext.getModelBuildingContext() ); + classDetails.applyAnnotationUsage( XmlAnnotations.ABSTRACT, xmlDocumentContext.getModelBuildingContext() ); } if ( isNotEmpty( jaxbEntity.getExtends() ) ) { - final MutableAnnotationUsage extendsAnn = HibernateAnnotations.EXTENDS.createUsage( xmlDocumentContext.getModelBuildingContext() ); - extendsAnn.setAttributeValue( "superType", jaxbEntity.getExtends() ); + final ExtendsXmlAnnotation extendsAnn = XmlAnnotations.EXTENDS.createUsage( xmlDocumentContext.getModelBuildingContext() ); + extendsAnn.superType( jaxbEntity.getExtends() ); } XmlAnnotationHelper.applyTable( jaxbEntity.getTable(), classDetails, xmlDocumentContext ); @@ -591,10 +591,16 @@ public class ManagedTypeProcessor { ); XmlAnnotationHelper.applyPrimaryKeyJoinColumns( - jaxbEntity, classDetails, xmlDocumentContext + jaxbEntity, + classDetails, + xmlDocumentContext ); - XmlAnnotationHelper.applyTableGenerator( jaxbEntity.getTableGenerators(), classDetails, xmlDocumentContext ); + XmlAnnotationHelper.applyTableGenerator( + jaxbEntity.getTableGenerators(), + classDetails, + xmlDocumentContext + ); XmlAnnotationHelper.applySequenceGenerator( jaxbEntity.getSequenceGenerators(), @@ -611,7 +617,7 @@ public class ManagedTypeProcessor { } final RenderingCollectorImpl renderingCollector = new RenderingCollectorImpl(); - classDetails.render( renderingCollector ); + classDetails.render( renderingCollector, xmlDocumentContext.getModelBuildingContext() ); XML_PROCESS_LOGGER.debugf( "Class annotations from XML for %s:\n%s", classDetails.getName(), renderingCollector.toString() ); } @@ -619,8 +625,8 @@ public class ManagedTypeProcessor { AccessType accessType, MutableClassDetails target, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage annotationUsage = target.applyAnnotationUsage( JpaAnnotations.ACCESS, xmlDocumentContext.getModelBuildingContext() ); - annotationUsage.setAttributeValue( "value", accessType ); + final AccessJpaAnnotation annotationUsage = (AccessJpaAnnotation) target.applyAnnotationUsage( JpaAnnotations.ACCESS, xmlDocumentContext.getModelBuildingContext() ); + annotationUsage.value( accessType ); target.addAnnotationUsage( annotationUsage ); } @@ -629,28 +635,30 @@ public class ManagedTypeProcessor { MutableClassDetails classDetails, XmlDocumentContext xmlDocumentContext) { if ( jaxbEntity.isCacheable() != null ) { - final MutableAnnotationUsage cacheableUsage = classDetails.applyAnnotationUsage( + final CacheableJpaAnnotation cacheableUsage = (CacheableJpaAnnotation) classDetails.applyAnnotationUsage( JpaAnnotations.CACHEABLE, xmlDocumentContext.getModelBuildingContext() ); - cacheableUsage.setAttributeValue( "value", jaxbEntity.isCacheable() ); + cacheableUsage.value( jaxbEntity.isCacheable() ); classDetails.addAnnotationUsage( cacheableUsage ); } final JaxbCachingImpl jaxbCaching = jaxbEntity.getCaching(); if ( jaxbCaching != null ) { - final MutableAnnotationUsage cacheUsage = classDetails.applyAnnotationUsage( + final CacheAnnotation cacheUsage = (CacheAnnotation) classDetails.replaceAnnotationUsage( HibernateAnnotations.CACHE, xmlDocumentContext.getModelBuildingContext() ); - classDetails.addAnnotationUsage( cacheUsage ); - XmlProcessingHelper.applyAttributeIfSpecified( "region", jaxbCaching.getRegion(), cacheUsage ); - XmlProcessingHelper.applyAttributeIfSpecified( - "usage", - convertCacheAccessType( jaxbCaching.getAccess() ), - cacheUsage - ); + if ( StringHelper.isNotEmpty( jaxbCaching.getRegion() ) ) { + cacheUsage.region( jaxbCaching.getRegion() ); + } + if ( jaxbCaching.getAccess() != null ) { + final CacheConcurrencyStrategy strategy = convertCacheAccessType( jaxbCaching.getAccess() ); + if ( strategy != null ) { + cacheUsage.usage( strategy ); + } + } } } @@ -736,9 +744,9 @@ public class ManagedTypeProcessor { } private static AccessType determineAccessTypeFromClassAnnotations(ClassDetails classDetails) { - final AnnotationUsage accessUsage = classDetails.getAnnotationUsage( Access.class ); + final Access accessUsage = classDetails.getDirectAnnotationUsage( Access.class ); if ( accessUsage != null ) { - return accessUsage.getAttributeValue( "value" ); + return accessUsage.value(); } return null; @@ -746,15 +754,15 @@ public class ManagedTypeProcessor { private static AccessType determineAccessTypeFromClassMembers(ClassDetails classDetails) { for ( FieldDetails field : classDetails.getFields() ) { - if ( field.getAnnotationUsage( Id.class ) != null - || field.getAnnotationUsage( EmbeddedId.class ) != null ) { + if ( field.hasDirectAnnotationUsage( Id.class ) + || field.hasDirectAnnotationUsage( EmbeddedId.class ) ) { return AccessType.FIELD; } } for ( MethodDetails method : classDetails.getMethods() ) { - if ( method.getAnnotationUsage( Id.class ) != null - || method.getAnnotationUsage( EmbeddedId.class ) != null ) { + if ( method.hasDirectAnnotationUsage( Id.class ) + || method.hasDirectAnnotationUsage( EmbeddedId.class ) ) { assert method.getMethodKind() == MethodDetails.MethodKind.GETTER; return AccessType.PROPERTY; } @@ -848,11 +856,11 @@ public class ManagedTypeProcessor { xmlDocumentContext.getEffectiveDefaults().getDefaultPropertyAccessType() ); if ( classAccessType != null ) { - final MutableAnnotationUsage accessUsage = classDetails.applyAnnotationUsage( + final AccessJpaAnnotation accessUsage = (AccessJpaAnnotation) classDetails.applyAnnotationUsage( JpaAnnotations.ACCESS, modelBuildingContext ); - accessUsage.setAttributeValue( "value", classAccessType ); + accessUsage.value( classAccessType ); } final JaxbAttributesContainerImpl attributes = jaxbMappedSuperclass.getAttributes(); @@ -951,11 +959,11 @@ public class ManagedTypeProcessor { classDetails.applyAnnotationUsage( JpaAnnotations.EMBEDDABLE, xmlDocumentContext.getModelBuildingContext() ); if ( classAccessType != null ) { - final MutableAnnotationUsage accessUsage = classDetails.applyAnnotationUsage( + final AccessJpaAnnotation accessUsage = (AccessJpaAnnotation) classDetails.applyAnnotationUsage( JpaAnnotations.ACCESS, xmlDocumentContext.getModelBuildingContext() ); - accessUsage.setAttributeValue( "value", classAccessType ); + accessUsage.value( classAccessType ); } if ( jaxbEmbeddable.getAttributes() != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/QueryProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/QueryProcessing.java index 27327a4855..966699ea5e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/QueryProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/QueryProcessing.java @@ -9,10 +9,9 @@ package org.hibernate.boot.models.xml.internal; import java.util.ArrayList; import java.util.List; -import org.hibernate.CacheMode; -import org.hibernate.annotations.NamedNativeQueries; +import org.hibernate.FlushMode; +import org.hibernate.annotations.FlushModeType; import org.hibernate.annotations.NamedNativeQuery; -import org.hibernate.annotations.NamedQueries; import org.hibernate.annotations.NamedQuery; import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbConstructorResultImpl; @@ -21,21 +20,33 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbFieldResultImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedNativeQueryImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryBase; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQueryImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint; +import org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHintImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameterImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbSynchronizedTableImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.internal.AnnotationUsageHelper; +import org.hibernate.boot.models.annotations.internal.ColumnResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ConstructorResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EntityResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.FieldResultJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedNativeQueriesAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedNativeQueriesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedNativeQueryAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedNativeQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedQueriesAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedQueriesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedQueryAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedStoredProcedureQueriesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.NamedStoredProcedureQueryJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.QueryHintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.StoredProcedureParameterJpaAnnotation; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.SourceModelBuildingContext; @@ -43,14 +54,11 @@ import jakarta.persistence.ColumnResult; import jakarta.persistence.ConstructorResult; import jakarta.persistence.EntityResult; import jakarta.persistence.FieldResult; -import jakarta.persistence.NamedStoredProcedureQueries; import jakarta.persistence.NamedStoredProcedureQuery; import jakarta.persistence.QueryHint; import jakarta.persistence.StoredProcedureParameter; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyAttributeIfSpecified; -import static org.hibernate.boot.models.internal.AnnotationUsageHelper.applyStringAttributeIfSpecified; -import static org.hibernate.internal.util.StringHelper.isEmpty; +import static org.hibernate.boot.models.JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY; import static org.hibernate.internal.util.StringHelper.isNotEmpty; /** @@ -68,110 +76,75 @@ public class QueryProcessing { } final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); - List> namedHqlQueryList = null; - List> namedJpqlQueryList = null; - + List namedHqlQueryList = null; + List namedJpqlQueryList = null; + for ( int i = 0; i < jaxbEntity.getNamedQueries().size(); i++ ) { final JaxbNamedQueryImpl jaxbNamedQuery = jaxbEntity.getNamedQueries().get( i ); if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getHints() ) ) { // treat this as a Jakarta Persistence named-query if ( namedJpqlQueryList == null ) { - final MutableAnnotationUsage namedJpqlQueriesUsage = classDetails.replaceAnnotationUsage( - JpaAnnotations.NAMED_QUERY, - JpaAnnotations.NAMED_QUERIES, - modelBuildingContext - ); - classDetails.addAnnotationUsage( namedJpqlQueriesUsage ); - namedJpqlQueryList = new ArrayList<>(); - namedJpqlQueriesUsage.setAttributeValue( "value", namedJpqlQueryList ); } - applyNamedJpqlQuery( jaxbNamedQuery, classDetails, namedJpqlQueryList, modelBuildingContext ); + final NamedQueryJpaAnnotation namedJpqlQuery = JpaAnnotations.NAMED_QUERY.createUsage( modelBuildingContext ); + namedJpqlQueryList.add( namedJpqlQuery ); + namedJpqlQuery.apply( jaxbNamedQuery, xmlDocumentContext ); } else { // treat this as a named HQL query if ( namedHqlQueryList == null ) { - final MutableAnnotationUsage namedHqlQueriesUsage = classDetails.replaceAnnotationUsage( - HibernateAnnotations.NAMED_QUERY, - HibernateAnnotations.NAMED_QUERIES, - modelBuildingContext - ); - classDetails.addAnnotationUsage( namedHqlQueriesUsage ); - namedHqlQueryList = new ArrayList<>(); - namedHqlQueriesUsage.setAttributeValue( "value", namedHqlQueryList ); } - applyNamedHqlQuery( jaxbNamedQuery, classDetails, namedHqlQueryList, modelBuildingContext ); + final NamedQueryAnnotation namedQuery = HibernateAnnotations.NAMED_QUERY.createUsage( xmlDocumentContext.getModelBuildingContext() ); + namedHqlQueryList.add( namedQuery ); + namedQuery.apply( jaxbNamedQuery, xmlDocumentContext ); } } + + if ( namedJpqlQueryList != null ) { + final NamedQueriesJpaAnnotation namedJpqlQueries = (NamedQueriesJpaAnnotation) classDetails.replaceAnnotationUsage( + JpaAnnotations.NAMED_QUERY, + JpaAnnotations.NAMED_QUERIES, + modelBuildingContext + ); + namedJpqlQueries.value( namedJpqlQueryList.toArray( jakarta.persistence.NamedQuery[]::new ) ); + } + if ( namedHqlQueryList != null ) { + final NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) classDetails.replaceAnnotationUsage( + HibernateAnnotations.NAMED_QUERY, + HibernateAnnotations.NAMED_QUERIES, + modelBuildingContext + ); + namedQueries.value( namedHqlQueryList.toArray( NamedQuery[]::new ) ); + } } - public static void applyNamedHqlQuery( - JaxbNamedQueryImpl jaxbNamedQuery, - MutableClassDetails classDetails, - List> namedQueryList, - SourceModelBuildingContext modelBuildingContext) { - final MutableAnnotationUsage namedQueryUsage = HibernateAnnotations.NAMED_QUERY.createUsage( modelBuildingContext ); - namedQueryList.add( namedQueryUsage ); - - namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); - namedQueryUsage.setAttributeValue( "query", jaxbNamedQuery.getQuery() ); - - AnnotationUsageHelper.applyAttributeIfSpecified( "comment", jaxbNamedQuery.getComment(), namedQueryUsage ); - - AnnotationUsageHelper.applyAttributeIfSpecified( "readOnly", jaxbNamedQuery.isReadOnly(), namedQueryUsage ); - AnnotationUsageHelper.applyAttributeIfSpecified( "flushMode", jaxbNamedQuery.getFlushMode(), namedQueryUsage ); - if ( jaxbNamedQuery.isCacheable() == Boolean.TRUE ) { - namedQueryUsage.setAttributeValue( "cacheable", true ); - AnnotationUsageHelper.applyAttributeIfSpecified( "cacheRegion", jaxbNamedQuery.getCacheRegion(), namedQueryUsage ); - AnnotationUsageHelper.applyAttributeIfSpecified( "cacheMode", jaxbNamedQuery.getCacheMode(), namedQueryUsage ); - - final CacheMode cacheMode = jaxbNamedQuery.getCacheMode(); - if ( cacheMode != null && cacheMode != CacheMode.IGNORE ) { - if ( cacheMode == CacheMode.GET ) { - applyAttributeIfSpecified( "cacheRegion", cacheMode, namedQueryUsage ); - applyAttributeIfSpecified( "cacheRegion", cacheMode, namedQueryUsage ); - } - AnnotationUsageHelper.applyAttributeIfSpecified( "cacheRegion", cacheMode, namedQueryUsage ); - AnnotationUsageHelper.applyAttributeIfSpecified( "cacheRegion", cacheMode, namedQueryUsage ); - } - } - AnnotationUsageHelper.applyAttributeIfSpecified( "fetchSize", jaxbNamedQuery.getFetchSize(), namedQueryUsage ); - AnnotationUsageHelper.applyAttributeIfSpecified( "timeout", jaxbNamedQuery.getTimeout(), namedQueryUsage ); - - AnnotationUsageHelper.applyAttributeIfSpecified( "timeout", jaxbNamedQuery.getTimeout(), namedQueryUsage ); + public static FlushModeType interpretFlushMode(FlushMode flushMode) { + return switch ( flushMode ) { + case AUTO -> FlushModeType.AUTO; + case ALWAYS -> FlushModeType.ALWAYS; + case COMMIT -> FlushModeType.COMMIT; + case MANUAL -> FlushModeType.MANUAL; + }; } - private static void applyNamedJpqlQuery( - JaxbNamedQueryImpl jaxbNamedQuery, - ClassDetails classDetails, - List> namedQueryList, - SourceModelBuildingContext modelBuildingContext) { - final MutableAnnotationUsage namedQueryUsage = JpaAnnotations.NAMED_QUERY.createUsage( modelBuildingContext ); - namedQueryList.add( namedQueryUsage ); - - namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); - namedQueryUsage.setAttributeValue( "query", jaxbNamedQuery.getQuery() ); - - applyQueryHints( jaxbNamedQuery, classDetails, namedQueryUsage, modelBuildingContext ); - } - - private static void applyQueryHints( - JaxbNamedQueryBase jaxbNamedQuery, - ClassDetails classDetails, - MutableAnnotationUsage namedQueryUsage, - SourceModelBuildingContext modelBuildingContext) { - if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getHints() ) ) { - final ArrayList> hints = CollectionHelper.arrayList( jaxbNamedQuery.getHints().size() ); - namedQueryUsage.setAttributeValue( "hints", hints ); - - for ( JaxbQueryHint jaxbHint : jaxbNamedQuery.getHints() ) { - final MutableAnnotationUsage queryHintUsage = JpaAnnotations.QUERY_HINT.createUsage( modelBuildingContext ); - queryHintUsage.setAttributeValue( "name", jaxbHint.getName() ); - queryHintUsage.setAttributeValue( "value", jaxbHint.getValue() ); - } + public static final QueryHint[] NO_HINTS = new QueryHint[0]; + public static QueryHint[] collectQueryHints(List jaxbHints, XmlDocumentContext xmlDocumentContext) { + if ( CollectionHelper.isEmpty( jaxbHints ) ) { + return NO_HINTS; } + + final QueryHint[] hints = new QueryHint[jaxbHints.size()]; + final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); + for ( int i = 0; i < jaxbHints.size(); i++ ) { + final QueryHintJpaAnnotation queryHintUsage = JpaAnnotations.QUERY_HINT.createUsage( modelBuildingContext ); + hints[i] = queryHintUsage; + final JaxbQueryHint jaxbHint = jaxbHints.get(i); + queryHintUsage.name( jaxbHint.getName() ); + queryHintUsage.value( jaxbHint.getValue() ); + } + return hints; } public static void applyNamedNativeQueries( @@ -183,10 +156,9 @@ public class QueryProcessing { return; } - final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); - List> namedHibernateQueryList = null; - List> namedJpaQueryList = null; + List namedQueryList = null; + List namedJpaQueryList = null; for ( int i = 0; i < jaxbEntity.getNamedNativeQueries().size(); i++ ) { final JaxbNamedNativeQueryImpl jaxbNamedQuery = jaxbEntity.getNamedNativeQueries().get( i ); @@ -194,36 +166,39 @@ public class QueryProcessing { if ( needsJpaNativeQuery( jaxbNamedQuery ) ) { // @jakarta.persistence.NamedNativeQuery if ( namedJpaQueryList == null ) { - final MutableAnnotationUsage namedQueriesUsage = classDetails.replaceAnnotationUsage( - JpaAnnotations.NAMED_NATIVE_QUERY, - JpaAnnotations.NAMED_NATIVE_QUERIES, - modelBuildingContext - ); - classDetails.addAnnotationUsage( namedQueriesUsage ); - namedJpaQueryList = new ArrayList<>(); - namedQueriesUsage.setAttributeValue( "value", namedQueriesUsage ); } - - applyJpaNativeQuery( jaxbNamedQuery, classDetails, namedJpaQueryList, modelBuildingContext, xmlDocumentContext ); + final NamedNativeQueryJpaAnnotation namedQuery = JpaAnnotations.NAMED_NATIVE_QUERY.createUsage( modelBuildingContext ); + namedJpaQueryList.add( namedQuery ); + namedQuery.apply( jaxbNamedQuery, xmlDocumentContext ); } else { // @org.hibernate.annotations.NamedNativeQuery - if ( namedHibernateQueryList == null ) { - final MutableAnnotationUsage namedQueriesUsage = classDetails.replaceAnnotationUsage( - HibernateAnnotations.NAMED_NATIVE_QUERY, - HibernateAnnotations.NAMED_NATIVE_QUERIES, - modelBuildingContext - ); - classDetails.addAnnotationUsage( namedQueriesUsage ); - - namedHibernateQueryList = new ArrayList<>(); - namedQueriesUsage.setAttributeValue( "value", namedHibernateQueryList ); + if ( namedQueryList == null ) { + namedQueryList = new ArrayList<>(); } - - applyHibernateNativeQuery( jaxbNamedQuery, classDetails, namedHibernateQueryList, modelBuildingContext, xmlDocumentContext ); + final NamedNativeQueryAnnotation namedQuery = HibernateAnnotations.NAMED_NATIVE_QUERY.createUsage( modelBuildingContext ); + namedQueryList.add( namedQuery ); + namedQuery.apply( jaxbNamedQuery, xmlDocumentContext ); } } + + if ( namedJpaQueryList != null ) { + final NamedNativeQueriesJpaAnnotation namedQueriesUsage = (NamedNativeQueriesJpaAnnotation) classDetails.replaceAnnotationUsage( + JpaAnnotations.NAMED_NATIVE_QUERY, + JpaAnnotations.NAMED_NATIVE_QUERIES, + modelBuildingContext + ); + namedQueriesUsage.value( namedJpaQueryList.toArray( jakarta.persistence.NamedNativeQuery[]::new ) ); + } + if ( namedQueryList != null ) { + final NamedNativeQueriesAnnotation namedQueriesUsage = (NamedNativeQueriesAnnotation) classDetails.replaceAnnotationUsage( + HibernateAnnotations.NAMED_NATIVE_QUERY, + HibernateAnnotations.NAMED_NATIVE_QUERIES, + modelBuildingContext + ); + namedQueriesUsage.value( namedQueryList.toArray(NamedNativeQuery[]::new ) ); + } } private static boolean needsJpaNativeQuery(JaxbNamedNativeQueryImpl jaxbNamedQuery) { @@ -233,290 +208,177 @@ public class QueryProcessing { || CollectionHelper.isNotEmpty( jaxbNamedQuery.getEntityResult() ); } - private static void applyJpaNativeQuery( - JaxbNamedNativeQueryImpl jaxbNamedQuery, - MutableClassDetails classDetails, - List> namedQueryUsageList, - SourceModelBuildingContext modelBuildingContext, - XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage namedQueryUsage = JpaAnnotations.NAMED_NATIVE_QUERY.createUsage( modelBuildingContext ); - namedQueryUsageList.add( namedQueryUsage ); - namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); - namedQueryUsage.setAttributeValue( "query", jaxbNamedQuery.getQuery() ); - applyQueryHints( jaxbNamedQuery, classDetails, namedQueryUsage, modelBuildingContext ); - - applyResultClassAndSynchronizations( jaxbNamedQuery, namedQueryUsage, modelBuildingContext, xmlDocumentContext ); - applyResultSetMappings( jaxbNamedQuery, namedQueryUsage, xmlDocumentContext ); - applyResults( jaxbNamedQuery, namedQueryUsage, classDetails, modelBuildingContext, xmlDocumentContext ); - } - - private static void applyResultClassAndSynchronizations( - JaxbNamedNativeQueryImpl jaxbNamedQuery, - MutableAnnotationUsage namedQueryUsage, - SourceModelBuildingContext modelBuildingContext, - XmlDocumentContext xmlDocumentContext) { - final List syncSpaces = new ArrayList<>(); - - if ( jaxbNamedQuery.getResultClass() != null ) { - final String resultClassName = xmlDocumentContext.resolveClassName( jaxbNamedQuery.getResultClass() ); - syncSpaces.add( resultClassName ); - namedQueryUsage.setAttributeValue( - "resultClass", - modelBuildingContext.getClassDetailsRegistry().getClassDetails( resultClassName ) - ); - } - - for ( JaxbSynchronizedTableImpl synchronization : jaxbNamedQuery.getSynchronizations() ) { - syncSpaces.add( synchronization.getTable() ); - } - - if ( CollectionHelper.isNotEmpty( syncSpaces ) ) { - namedQueryUsage.setAttributeValue( "querySpaces", syncSpaces ); - } - } - - private static void applyResultSetMappings( - JaxbNamedNativeQueryImpl jaxbNamedQuery, - MutableAnnotationUsage namedQueryUsage, - XmlDocumentContext xmlDocumentContext) { - if ( isEmpty( jaxbNamedQuery.getResultSetMapping() ) ) { - return; - } - - namedQueryUsage.setAttributeValue( "resultSetMapping", jaxbNamedQuery.getResultSetMapping() ); - } - - private static void applyResults( - JaxbNamedNativeQueryImpl jaxbNamedQuery, - MutableAnnotationUsage namedQueryUsage, - AnnotationTarget annotationTarget, - SourceModelBuildingContext modelBuildingContext, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getColumnResult() ) ) { - final ArrayList> columnResultList = extractColumnResults( - jaxbNamedQuery.getColumnResult(), - annotationTarget, - modelBuildingContext, - xmlDocumentContext - ); - namedQueryUsage.setAttributeValue( "columns", columnResultList ); - } - - if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getConstructorResult() ) ) { - final ArrayList> constructorResultList = extractConstructorResults( - jaxbNamedQuery.getConstructorResult(), - annotationTarget, - modelBuildingContext, - xmlDocumentContext - ); - namedQueryUsage.setAttributeValue( "classes", constructorResultList ); - } - - if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getEntityResult() ) ) { - final ArrayList> entityResultList = extractEntityResults( - jaxbNamedQuery.getEntityResult(), - annotationTarget, - modelBuildingContext, - xmlDocumentContext - ); - namedQueryUsage.setAttributeValue( "entities", entityResultList ); - } - } - - private static ArrayList> extractColumnResults( + private static final ColumnResult[] NO_COLUMN_RESULTS = new ColumnResult[0]; + public static ColumnResult[] extractColumnResults( List jaxbColumnResultList, - AnnotationTarget annotationTarget, - SourceModelBuildingContext modelBuildingContext, XmlDocumentContext xmlDocumentContext) { - assert CollectionHelper.isNotEmpty( jaxbColumnResultList ); + if ( CollectionHelper.isEmpty( jaxbColumnResultList ) ) { + return NO_COLUMN_RESULTS; + } - final ArrayList> columnResultList = CollectionHelper.arrayList( jaxbColumnResultList.size() ); - for ( JaxbColumnResultImpl jaxbColumnResult : jaxbColumnResultList ) { - final MutableAnnotationUsage columnResultUsage = JpaAnnotations.COLUMN_RESULT.createUsage( modelBuildingContext ); - columnResultList.add( columnResultUsage ); - columnResultUsage.setAttributeValue( "name", jaxbColumnResult.getName() ); + final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); + final ColumnResult[] columnResults = new ColumnResult[jaxbColumnResultList.size()]; + for ( int i = 0; i < jaxbColumnResultList.size(); i++ ) { + final ColumnResultJpaAnnotation columnResult = JpaAnnotations.COLUMN_RESULT.createUsage( modelBuildingContext ); + columnResults[i] = columnResult; + + final JaxbColumnResultImpl jaxbColumnResult = jaxbColumnResultList.get( i ); + columnResult.name( jaxbColumnResult.getName() ); if ( isNotEmpty( jaxbColumnResult.getClazz() ) ) { - columnResultUsage.setAttributeValue( "type", xmlDocumentContext.resolveJavaType( jaxbColumnResult.getClazz() ) ); + columnResult.type( xmlDocumentContext.resolveJavaType( jaxbColumnResult.getClazz() ).toJavaClass() ); } } - return columnResultList; + return columnResults; } - private static ArrayList> extractConstructorResults( + private final static ConstructorResult[] NO_CONSTRUCTOR_RESULTS = new ConstructorResult[0]; + public static ConstructorResult[] extractConstructorResults( List jaxbConstructorResultList, - AnnotationTarget annotationTarget, - SourceModelBuildingContext modelBuildingContext, XmlDocumentContext xmlDocumentContext) { - assert CollectionHelper.isNotEmpty( jaxbConstructorResultList ); + if ( CollectionHelper.isEmpty( jaxbConstructorResultList ) ) { + return NO_CONSTRUCTOR_RESULTS; + } - final ArrayList> constructorResultList = CollectionHelper.arrayList( jaxbConstructorResultList.size() ); - for ( JaxbConstructorResultImpl jaxbConstructorResult : jaxbConstructorResultList ) { - final MutableAnnotationUsage constructorResultUsage = JpaAnnotations.CONSTRUCTOR_RESULT.createUsage( modelBuildingContext ); - constructorResultList.add( constructorResultUsage ); - - constructorResultUsage.setAttributeValue( "targetClass", xmlDocumentContext.resolveJavaType( jaxbConstructorResult.getTargetClass() ) ); + final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); + final ConstructorResult[] constructorResults = new ConstructorResult[jaxbConstructorResultList.size()]; + for ( int i = 0; i < jaxbConstructorResultList.size(); i++ ) { + final ConstructorResultJpaAnnotation constructorResult = JpaAnnotations.CONSTRUCTOR_RESULT.createUsage( modelBuildingContext ); + constructorResults[i] = constructorResult; + final JaxbConstructorResultImpl jaxbConstructorResult = jaxbConstructorResultList.get( i ); + constructorResult.targetClass( xmlDocumentContext.resolveJavaType( jaxbConstructorResult.getTargetClass() ).toJavaClass() ); if ( CollectionHelper.isNotEmpty( jaxbConstructorResult.getColumns() ) ) { - final ArrayList> columnResultList = extractColumnResults( + final ColumnResult[] columnResults = extractColumnResults( jaxbConstructorResult.getColumns(), - annotationTarget, - modelBuildingContext, xmlDocumentContext ); - constructorResultUsage.setAttributeValue( "columns", columnResultList ); + if ( columnResults != null ) { + constructorResult.columns( columnResults ); + } } } - return constructorResultList; + return constructorResults; } - private static ArrayList> extractEntityResults( + private static final EntityResult[] NO_ENTITY_RESULTS = new EntityResult[0]; + public static EntityResult[] extractEntityResults( List jaxbEntityResults, - AnnotationTarget annotationTarget, - SourceModelBuildingContext modelBuildingContext, XmlDocumentContext xmlDocumentContext) { - assert CollectionHelper.isNotEmpty( jaxbEntityResults ); + if ( CollectionHelper.isEmpty( jaxbEntityResults ) ) { + return NO_ENTITY_RESULTS; + } - final ArrayList> entityResultList = CollectionHelper.arrayList( jaxbEntityResults.size() ); - for ( JaxbEntityResultImpl jaxbEntityResult : jaxbEntityResults ) { - final MutableAnnotationUsage entityResultUsage = JpaAnnotations.ENTITY_RESULT.createUsage( modelBuildingContext ); - entityResultList.add( entityResultUsage ); + final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); + final EntityResult[] entityResults = new EntityResult[jaxbEntityResults.size()]; + for ( int i = 0; i < jaxbEntityResults.size(); i++ ) { + final EntityResultJpaAnnotation entityResult = JpaAnnotations.ENTITY_RESULT.createUsage( modelBuildingContext ); + entityResults[i] = entityResult; - entityResultUsage.setAttributeValue( "entityClass", xmlDocumentContext.resolveJavaType( jaxbEntityResult.getEntityClass() ) ); - applyAttributeIfSpecified( "lockMode", jaxbEntityResult.getLockMode(), entityResultUsage ); - applyStringAttributeIfSpecified( "discriminatorColumn", jaxbEntityResult.getDiscriminatorColumn(), entityResultUsage ); + final JaxbEntityResultImpl jaxbEntityResult = jaxbEntityResults.get( i ); + entityResult.entityClass( xmlDocumentContext.resolveJavaType( jaxbEntityResult.getEntityClass() ).toJavaClass() ); + if ( StringHelper.isNotEmpty( jaxbEntityResult.getDiscriminatorColumn() ) ) { + entityResult.discriminatorColumn( jaxbEntityResult.getDiscriminatorColumn() ); + } + if ( jaxbEntityResult.getLockMode() != null ) { + entityResult.lockMode( jaxbEntityResult.getLockMode() ); + } - if ( CollectionHelper.isNotEmpty( jaxbEntityResult.getFieldResult() ) ) { - final ArrayList> fieldResultList = extractFieldResults( - jaxbEntityResult.getFieldResult(), - annotationTarget, - modelBuildingContext, - xmlDocumentContext - ); - entityResultUsage.setAttributeValue( "fields", fieldResultList ); + final FieldResult[] fieldResults = extractFieldResults( + jaxbEntityResult.getFieldResult(), + xmlDocumentContext + ); + if ( fieldResults != null ) { + entityResult.fields( fieldResults ); } } - - return entityResultList; + return entityResults; } - private static ArrayList> extractFieldResults( + private static FieldResult[] extractFieldResults( List jaxbFieldResults, - AnnotationTarget annotationTarget, - SourceModelBuildingContext modelBuildingContext, XmlDocumentContext xmlDocumentContext) { - assert CollectionHelper.isNotEmpty( jaxbFieldResults ); - - final ArrayList> fieldResultList = CollectionHelper.arrayList( jaxbFieldResults.size() ); - for ( JaxbFieldResultImpl jaxbFieldResult : jaxbFieldResults ) { - final MutableAnnotationUsage fieldResultUsage = JpaAnnotations.FIELD_RESULT.createUsage( modelBuildingContext ); - fieldResultList.add( fieldResultUsage ); - - fieldResultUsage.setAttributeValue( "name", jaxbFieldResult.getName() ); - fieldResultUsage.setAttributeValue( "column", jaxbFieldResult.getColumn() ); + if ( CollectionHelper.isEmpty( jaxbFieldResults ) ) { + return null; } - return fieldResultList; - } + final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); + final FieldResult[] fieldResults = new FieldResult[jaxbFieldResults.size()]; + for ( int i = 0; i < jaxbFieldResults.size(); i++ ) { + final FieldResultJpaAnnotation fieldResult = JpaAnnotations.FIELD_RESULT.createUsage( modelBuildingContext ); + fieldResults[i] = fieldResult; - private static void applyHibernateNativeQuery( - JaxbNamedNativeQueryImpl jaxbNamedQuery, - MutableClassDetails classDetails, - List> namedQueryUsageList, - SourceModelBuildingContext modelBuildingContext, - XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage namedQueryUsage = HibernateAnnotations.NAMED_NATIVE_QUERY.createUsage( modelBuildingContext ); - namedQueryUsageList.add( namedQueryUsage ); - - namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); - namedQueryUsage.setAttributeValue( "query", jaxbNamedQuery.getQuery() ); - - applyResultClassAndSynchronizations( jaxbNamedQuery, namedQueryUsage, modelBuildingContext, xmlDocumentContext ); - applyResultSetMappings( jaxbNamedQuery, namedQueryUsage, xmlDocumentContext ); + final JaxbFieldResultImpl jaxbFieldResult = jaxbFieldResults.get( i ); + fieldResult.name( jaxbFieldResult.getName() ); + fieldResult.column( jaxbFieldResult.getColumn() ); + } + return fieldResults; } public static void applyNamedProcedureQueries( JaxbEntityImpl jaxbEntity, MutableClassDetails classDetails, XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbEntity.getNamedStoredProcedureQueries() ) ) { + final List jaxbQueries = jaxbEntity.getNamedStoredProcedureQueries(); + if ( CollectionHelper.isEmpty( jaxbQueries ) ) { return; } final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); - final MutableAnnotationUsage namedQueriesUsage = classDetails.replaceAnnotationUsage( - JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY, + final NamedStoredProcedureQueriesJpaAnnotation namedQueriesUsage = (NamedStoredProcedureQueriesJpaAnnotation) classDetails.replaceAnnotationUsage( + NAMED_STORED_PROCEDURE_QUERY, JpaAnnotations.NAMED_STORED_PROCEDURE_QUERIES, modelBuildingContext ); - final List> namedQueryList = CollectionHelper.arrayList( jaxbEntity.getNamedStoredProcedureQueries().size() ); - namedQueriesUsage.setAttributeValue( "value", namedQueryList ); - for ( JaxbNamedStoredProcedureQueryImpl jaxbQuery : jaxbEntity.getNamedStoredProcedureQueries() ) { - final MutableAnnotationUsage namedQueryUsage = JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY.createUsage( modelBuildingContext ); - namedQueryList.add( namedQueryUsage ); + final NamedStoredProcedureQuery[] namedQueries = new NamedStoredProcedureQuery[jaxbQueries.size()]; + namedQueriesUsage.value( namedQueries ); - namedQueryUsage.setAttributeValue( "name", jaxbQuery.getName() ); - namedQueryUsage.setAttributeValue( "procedureName", jaxbQuery.getProcedureName() ); + for ( int i = 0; i < jaxbQueries.size(); i++ ) { + final NamedStoredProcedureQueryJpaAnnotation namedQuery = NAMED_STORED_PROCEDURE_QUERY.createUsage( modelBuildingContext ); + namedQueries[i] = namedQuery; - applyQueryHints( jaxbQuery, classDetails, namedQueryUsage, modelBuildingContext ); - applyQueryParameters( jaxbQuery, classDetails, namedQueryUsage, xmlDocumentContext ); - applyResultSetMappings( jaxbQuery, namedQueryUsage, xmlDocumentContext ); - applyResultClasses( jaxbQuery, namedQueryUsage, xmlDocumentContext ); + final JaxbNamedStoredProcedureQueryImpl jaxbQuery = jaxbQueries.get( i ); + namedQuery.apply( jaxbQuery, xmlDocumentContext ); } } - private static void applyQueryParameters( - JaxbNamedStoredProcedureQueryImpl jaxbQuery, - MutableClassDetails classDetails, - MutableAnnotationUsage queryUsage, + private static final StoredProcedureParameter[] NO_PARAMS = new StoredProcedureParameter[0]; + public static StoredProcedureParameter[] collectParameters( + List jaxbParameters, XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbQuery.getProcedureParameters() ) ) { - return; + if ( CollectionHelper.isEmpty( jaxbParameters ) ) { + return NO_PARAMS; } final SourceModelBuildingContext sourceModelBuildingContext = xmlDocumentContext.getModelBuildingContext(); + final StoredProcedureParameter[] result = new StoredProcedureParameter[jaxbParameters.size()]; + for ( int i = 0; i < jaxbParameters.size(); i++ ) { + final StoredProcedureParameterJpaAnnotation param = JpaAnnotations.STORED_PROCEDURE_PARAMETER.createUsage( sourceModelBuildingContext ); + result[i] = param; - final ArrayList> parameterList = CollectionHelper.arrayList( jaxbQuery.getProcedureParameters().size() ); - queryUsage.setAttributeValue( "parameters", parameterList ); - - for ( JaxbStoredProcedureParameterImpl jaxbParameter : jaxbQuery.getProcedureParameters() ) { - final MutableAnnotationUsage parameterUsage = JpaAnnotations.STORED_PROCEDURE_PARAMETER.createUsage( sourceModelBuildingContext ); - parameterList.add( parameterUsage ); - - applyStringAttributeIfSpecified( "name", jaxbParameter.getName(), parameterUsage ); - applyAttributeIfSpecified( "mode", jaxbParameter.getMode(), parameterUsage ); - - parameterUsage.setAttributeValue( "type", xmlDocumentContext.resolveJavaType( jaxbParameter.getClazz() ) ); + final JaxbStoredProcedureParameterImpl jaxbParam = jaxbParameters.get( i ); + param.apply( jaxbParam, xmlDocumentContext ); } + return result; } - private static void applyResultSetMappings( - JaxbNamedStoredProcedureQueryImpl jaxbQuery, - MutableAnnotationUsage namedQueryUsage, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbQuery.getResultSetMappings() ) ) { - return; + private static final Class[] NO_CLASSES = new Class[0]; + public static Class[] collectResultClasses(List resultClasses, XmlDocumentContext xmlDocumentContext) { + if ( CollectionHelper.isEmpty( resultClasses ) ) { + return NO_CLASSES; } - - namedQueryUsage.setAttributeValue( "resultSetMappings", jaxbQuery.getResultSetMappings() ); + final Class[] result = new Class[resultClasses.size()]; + for ( int i = 0; i < resultClasses.size(); i++ ) { + result[i] = xmlDocumentContext.resolveJavaType( resultClasses.get( i ) ).toJavaClass(); + } + return result; } - private static void applyResultClasses( - JaxbNamedStoredProcedureQueryImpl jaxbQuery, - MutableAnnotationUsage namedQueryUsage, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbQuery.getResultClasses() ) ) { - return; - } - - final ArrayList resultClasses = CollectionHelper.arrayList( jaxbQuery.getResultClasses().size() ); - namedQueryUsage.setAttributeValue( "resultClasses", resultClasses ); - - for ( String resultClass : jaxbQuery.getResultClasses() ) { - final MutableClassDetails resultClassDetails = xmlDocumentContext.resolveJavaType( resultClass ); - resultClasses.add( resultClassDetails ); + public static String[] collectResultMappings(List resultClasses, XmlDocumentContext xmlDocumentContext) { + if ( CollectionHelper.isEmpty( resultClasses ) ) { + return ArrayHelper.EMPTY_STRING_ARRAY; } + return resultClasses.toArray( String[]::new ); } - } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java index b170f095b5..08f0ae5d0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java @@ -13,29 +13,13 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.function.Function; -import java.util.function.Supplier; +import java.util.function.Consumer; import org.hibernate.AnnotationException; -import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; -import org.hibernate.annotations.CollectionId; -import org.hibernate.annotations.CollectionType; -import org.hibernate.annotations.DiscriminatorFormula; -import org.hibernate.annotations.DiscriminatorOptions; -import org.hibernate.annotations.JavaType; -import org.hibernate.annotations.JdbcType; -import org.hibernate.annotations.JdbcTypeCode; -import org.hibernate.annotations.NaturalIdCache; -import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.Parameter; import org.hibernate.annotations.ResultCheckStyle; -import org.hibernate.annotations.RowId; -import org.hibernate.annotations.SqlFragmentAlias; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.UuidGenerator; -import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverrideImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributeOverrideImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicMapping; @@ -54,6 +38,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollectionImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerContainerImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityOrMappedSuperclass; import org.hibernate.boot.jaxb.mapping.spi.JaxbGeneratedValueImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl; @@ -76,69 +61,110 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbTableImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbUniqueConstraintImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbUuidGeneratorImpl; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCheckable; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbTableMapping; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.AssociationOverrideJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AssociationOverridesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AttributeOverrideJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AttributeOverridesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.CascadeAnnotation; +import org.hibernate.boot.models.annotations.internal.CheckConstraintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.CollectionIdAnnotation; +import org.hibernate.boot.models.annotations.internal.CollectionTypeAnnotation; +import org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ConvertJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ConvertsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.DiscriminatorColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.DiscriminatorFormulaAnnotation; +import org.hibernate.boot.models.annotations.internal.DiscriminatorOptionsAnnotation; +import org.hibernate.boot.models.annotations.internal.DiscriminatorValueJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EntityJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EntityListenersJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.EnumeratedJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.FilterAnnotation; +import org.hibernate.boot.models.annotations.internal.FilterJoinTableAnnotation; +import org.hibernate.boot.models.annotations.internal.FilterJoinTablesAnnotation; +import org.hibernate.boot.models.annotations.internal.FiltersAnnotation; +import org.hibernate.boot.models.annotations.internal.GeneratedValueJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.IdClassJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.IndexJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.InheritanceJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.JavaTypeAnnotation; +import org.hibernate.boot.models.annotations.internal.JdbcTypeAnnotation; +import org.hibernate.boot.models.annotations.internal.JdbcTypeCodeAnnotation; +import org.hibernate.boot.models.annotations.internal.NaturalIdCacheAnnotation; +import org.hibernate.boot.models.annotations.internal.NotFoundAnnotation; +import org.hibernate.boot.models.annotations.internal.ParameterAnnotation; +import org.hibernate.boot.models.annotations.internal.PrimaryKeyJoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PrimaryKeyJoinColumnsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.RowIdAnnotation; +import org.hibernate.boot.models.annotations.internal.SQLJoinTableRestrictionAnnotation; +import org.hibernate.boot.models.annotations.internal.SQLRestrictionAnnotation; +import org.hibernate.boot.models.annotations.internal.SecondaryTableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SecondaryTablesJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SequenceGeneratorJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TableGeneratorJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; +import org.hibernate.boot.models.annotations.internal.TemporalJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TypeAnnotation; +import org.hibernate.boot.models.annotations.internal.UniqueConstraintJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.UuidGeneratorAnnotation; +import org.hibernate.boot.models.annotations.spi.CustomSqlDetails; +import org.hibernate.boot.models.annotations.spi.DatabaseObjectDetails; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle; -import org.hibernate.boot.models.internal.AnnotationUsageHelper; -import org.hibernate.boot.models.xml.internal.db.ColumnProcessing; import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocument; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; -import org.hibernate.internal.util.KeyedConsumer; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.ModelsException; import org.hibernate.models.spi.AnnotationDescriptor; -import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MethodDetails; import org.hibernate.models.spi.MutableAnnotationTarget; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.type.SqlTypes; import jakarta.persistence.AssociationOverride; -import jakarta.persistence.AssociationOverrides; import jakarta.persistence.AttributeOverride; -import jakarta.persistence.AttributeOverrides; import jakarta.persistence.CheckConstraint; -import jakarta.persistence.Column; import jakarta.persistence.Convert; -import jakarta.persistence.Converts; -import jakarta.persistence.DiscriminatorColumn; -import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; -import jakarta.persistence.EntityListeners; import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.IdClass; import jakarta.persistence.Index; -import jakarta.persistence.Inheritance; -import jakarta.persistence.PrimaryKeyJoinColumns; +import jakarta.persistence.PrimaryKeyJoinColumn; import jakarta.persistence.SecondaryTable; -import jakarta.persistence.SecondaryTables; -import jakarta.persistence.SequenceGenerator; -import jakarta.persistence.Table; -import jakarta.persistence.TableGenerator; -import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; import jakarta.persistence.UniqueConstraint; import org.checkerframework.checker.nullness.qual.Nullable; import static java.lang.Boolean.FALSE; import static java.util.Collections.emptyList; -import static org.hibernate.internal.util.collections.CollectionHelper.arrayList; +import static org.hibernate.boot.models.JpaAnnotations.ASSOCIATION_OVERRIDE; +import static org.hibernate.boot.models.JpaAnnotations.ASSOCIATION_OVERRIDES; +import static org.hibernate.boot.models.JpaAnnotations.ATTRIBUTE_OVERRIDE; +import static org.hibernate.boot.models.JpaAnnotations.ATTRIBUTE_OVERRIDES; +import static org.hibernate.boot.models.JpaAnnotations.CHECK_CONSTRAINT; +import static org.hibernate.boot.models.JpaAnnotations.COLUMN; +import static org.hibernate.boot.models.JpaAnnotations.CONVERT; +import static org.hibernate.boot.models.JpaAnnotations.EXCLUDE_DEFAULT_LISTENERS; +import static org.hibernate.boot.models.JpaAnnotations.EXCLUDE_SUPERCLASS_LISTENERS; +import static org.hibernate.boot.models.HibernateAnnotations.FILTER; +import static org.hibernate.boot.models.HibernateAnnotations.FILTER_JOIN_TABLE; +import static org.hibernate.boot.models.JpaAnnotations.INDEX; +import static org.hibernate.boot.models.HibernateAnnotations.PARAMETER; +import static org.hibernate.boot.models.HibernateAnnotations.SQL_RESTRICTION; +import static org.hibernate.boot.models.JpaAnnotations.SECONDARY_TABLE; +import static org.hibernate.boot.models.JpaAnnotations.UNIQUE_CONSTRAINT; /** * Helper for creating annotation from equivalent JAXB @@ -146,19 +172,6 @@ import static org.hibernate.internal.util.collections.CollectionHelper.arrayList * @author Steve Ebersole */ public class XmlAnnotationHelper { - - public static void applyOptionalAttribute(MutableAnnotationUsage annotationUsage, String attributeName, Object value) { - if ( value != null ) { - annotationUsage.setAttributeValue( attributeName, value ); - } - } - - public static void applyOptionalAttribute(MutableAnnotationUsage annotationUsage, String attributeName, String value) { - if ( StringHelper.isNotEmpty( value ) ) { - annotationUsage.setAttributeValue( attributeName, value ); - } - } - /** * Handle creating {@linkplain Entity @Entity} from an {@code } element. * Used in both complete and override modes. @@ -167,11 +180,13 @@ public class XmlAnnotationHelper { JaxbEntity jaxbEntity, MutableClassDetails classDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage entityAnn = classDetails.applyAnnotationUsage( + final EntityJpaAnnotation entityAnn = (EntityJpaAnnotation) classDetails.applyAnnotationUsage( JpaAnnotations.ENTITY, xmlDocumentContext.getModelBuildingContext() ); - XmlProcessingHelper.applyAttributeIfSpecified( "name", jaxbEntity.getName(), entityAnn ); + if ( StringHelper.isNotEmpty( jaxbEntity.getName() ) ) { + entityAnn.name( jaxbEntity.getName() ); + } } public static void applyColumn( @@ -185,60 +200,18 @@ public class XmlAnnotationHelper { createColumnAnnotation( jaxbColumn, memberDetails, xmlDocumentContext ); } - private static MutableAnnotationUsage createColumnAnnotation( + private static ColumnJpaAnnotation createColumnAnnotation( JaxbColumnImpl jaxbColumn, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage columnAnnotationUsage = target.applyAnnotationUsage( - JpaAnnotations.COLUMN, + final ColumnJpaAnnotation columnAnnotationUsage = (ColumnJpaAnnotation) target.applyAnnotationUsage( + COLUMN, xmlDocumentContext.getModelBuildingContext() ); - - ColumnProcessing.applyColumnDetails( jaxbColumn, target, columnAnnotationUsage, xmlDocumentContext ); - + columnAnnotationUsage.apply( jaxbColumn, xmlDocumentContext ); return columnAnnotationUsage; } - - public static void applyOr( - N jaxbNode, - Function jaxbValueAccess, - String name, - KeyedConsumer valueConsumer, - Supplier defaultValueProvider) { - if ( jaxbNode != null ) { - final T value = jaxbValueAccess.apply( jaxbNode ); - if ( value != null ) { - valueConsumer.accept( name, value ); - return; - } - } - - valueConsumer.accept( name, defaultValueProvider.get() ); - } - - public static void applyOr( - N jaxbNode, - Function jaxbValueAccess, - String name, - MutableAnnotationUsage annotationUsage, - AnnotationDescriptor annotationDescriptor) { - //noinspection unchecked - applyOr( - jaxbNode, - jaxbValueAccess, - name, - (key, value) -> annotationUsage.setAttributeValue( name, value ), - () -> (T) annotationDescriptor.getAttribute( name ).getAttributeMethod().getDefaultValue() - ); - } - - - - - - - public static void applyUserType( JaxbUserTypeImpl jaxbType, MutableMemberDetails memberDetails, @@ -247,33 +220,40 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage typeAnn = memberDetails.applyAnnotationUsage( + final TypeAnnotation typeAnn = (TypeAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.TYPE, xmlDocumentContext.getModelBuildingContext() ); final ClassDetails userTypeImpl = resolveJavaType( jaxbType.getValue(), xmlDocumentContext ); - typeAnn.setAttributeValue( "value", userTypeImpl ); - typeAnn.setAttributeValue( "parameters", collectParameters( jaxbType.getParameters(), memberDetails, xmlDocumentContext ) ); + typeAnn.value( userTypeImpl.toJavaClass() ); + typeAnn.parameters( collectParameters( jaxbType.getParameters(), xmlDocumentContext ) ); } - public static List> collectParameters( + private static final Parameter[] NO_PARAMETERS = new Parameter[0]; + + public static Parameter[] collectParameters( List jaxbParameters, - MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { + return collectParameters( jaxbParameters, xmlDocumentContext.getModelBuildingContext() ); + } + + public static Parameter[] collectParameters( + List jaxbParameters, + SourceModelBuildingContext sourceModelContext) { if ( CollectionHelper.isEmpty( jaxbParameters ) ) { - return emptyList(); + return NO_PARAMETERS; } - List> parameterAnnList = new ArrayList<>( jaxbParameters.size() ); - jaxbParameters.forEach( (jaxbParam) -> { - final MutableAnnotationUsage parameterUsage = - HibernateAnnotations.PARAMETER.createUsage( xmlDocumentContext.getModelBuildingContext() ); - parameterAnnList.add( parameterUsage ); - parameterUsage.setAttributeValue( "name", jaxbParam.getName() ); - parameterUsage.setAttributeValue( "value", jaxbParam.getValue() ); - } ); - return parameterAnnList; + final Parameter[] parameters = new Parameter[jaxbParameters.size()]; + for ( int i = 0; i < jaxbParameters.size(); i++ ) { + final JaxbConfigurationParameterImpl jaxbParameter = jaxbParameters.get( i ); + final ParameterAnnotation usage = PARAMETER.createUsage( sourceModelContext ); + parameters[i] = usage; + usage.name( jaxbParameter.getName() ); + usage.value( jaxbParameter.getValue() ); + } + return parameters; } public static void applyCollectionUserType( @@ -284,13 +264,13 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage typeAnn = memberDetails.applyAnnotationUsage( + final CollectionTypeAnnotation typeAnn = (CollectionTypeAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.COLLECTION_TYPE, xmlDocumentContext.getModelBuildingContext() ); final ClassDetails userTypeImpl = resolveJavaType( jaxbType.getType(), xmlDocumentContext ); - typeAnn.setAttributeValue( "type", userTypeImpl ); - typeAnn.setAttributeValue( "parameters", collectParameters( jaxbType.getParameters(), memberDetails, xmlDocumentContext ) ); + typeAnn.type( userTypeImpl.toJavaClass() ); + typeAnn.parameters( collectParameters( jaxbType.getParameters(), xmlDocumentContext ) ); } public static void applyCollectionId( @@ -301,14 +281,14 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage collectionIdAnn = memberDetails.applyAnnotationUsage( + final CollectionIdAnnotation collectionIdAnn = (CollectionIdAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.COLLECTION_ID, xmlDocumentContext.getModelBuildingContext() ); final JaxbColumnImpl jaxbColumn = jaxbCollectionId.getColumn(); if ( jaxbColumn != null ) { - collectionIdAnn.setAttributeValue( "column", createColumnAnnotation( + collectionIdAnn.column( createColumnAnnotation( jaxbColumn, memberDetails, xmlDocumentContext @@ -317,7 +297,7 @@ public class XmlAnnotationHelper { final JaxbGeneratedValueImpl generator = jaxbCollectionId.getGenerator(); if ( generator != null && StringHelper.isNotEmpty( generator.getGenerator() ) ) { - collectionIdAnn.setAttributeValue( "generator", generator.getGenerator() ); + collectionIdAnn.generator( generator.getGenerator() ); } } @@ -359,117 +339,11 @@ public class XmlAnnotationHelper { } if ( !cascadeTypes.isEmpty() ) { - final MutableAnnotationUsage cascadeAnn = memberDetails.applyAnnotationUsage( + final CascadeAnnotation cascadeAnn = (CascadeAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.CASCADE, xmlDocumentContext.getModelBuildingContext() ); - cascadeAnn.setAttributeValue( "value", cascadeTypes ); - } - } - - public static void applyUniqueConstraints( - List jaxbUniqueConstraints, - AnnotationTarget target, - MutableAnnotationUsage annotationUsage, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbUniqueConstraints ) ) { - return; - } - - final List> uniqueConstraintUsages = new ArrayList<>( jaxbUniqueConstraints.size() ); - annotationUsage.setAttributeValue( "uniqueConstraints", uniqueConstraintUsages ); - - jaxbUniqueConstraints.forEach( (jaxbUniqueConstraint) -> { - final MutableAnnotationUsage ucUsage = - JpaAnnotations.UNIQUE_CONSTRAINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); - XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "name", jaxbUniqueConstraint.getName() ); - XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "options", jaxbUniqueConstraint.getOptions() ); - ucUsage.setAttributeValue( "columnNames", jaxbUniqueConstraint.getColumnName() ); - uniqueConstraintUsages.add( ucUsage ); - } ); - } - - public static void applyUniqueConstraints( - List jaxbUniqueConstraints, - MutableAnnotationUsage annotationUsage, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbUniqueConstraints ) ) { - return; - } - - final List> uniqueConstraintUsages = new ArrayList<>( jaxbUniqueConstraints.size() ); - annotationUsage.setAttributeValue( "uniqueConstraints", uniqueConstraintUsages ); - - jaxbUniqueConstraints.forEach( (jaxbUniqueConstraint) -> { - final MutableAnnotationUsage ucUsage = - JpaAnnotations.UNIQUE_CONSTRAINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); - XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "name", jaxbUniqueConstraint.getName() ); - XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "options", jaxbUniqueConstraint.getOptions() ); - ucUsage.setAttributeValue( "columnNames", jaxbUniqueConstraint.getColumnName() ); - uniqueConstraintUsages.add( ucUsage ); - } ); - } - - public static void applyIndexes( - List jaxbIndexes, - AnnotationTarget target, - MutableAnnotationUsage annotationUsage, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbIndexes ) ) { - return; - } - - final List> indexes = new ArrayList<>( jaxbIndexes.size() ); - jaxbIndexes.forEach( jaxbIndex -> { - final MutableAnnotationUsage indexAnn = - JpaAnnotations.INDEX.createUsage( xmlDocumentContext.getModelBuildingContext() ); - applyOr( jaxbIndex, JaxbIndexImpl::getName, "name", indexAnn, JpaAnnotations.INDEX ); - applyOr( jaxbIndex, JaxbIndexImpl::getColumnList, "columnList", indexAnn, JpaAnnotations.INDEX ); - applyOr( jaxbIndex, JaxbIndexImpl::isUnique, "unique", indexAnn, JpaAnnotations.INDEX ); - applyOr( jaxbIndex, JaxbIndexImpl::getOptions, "options", indexAnn, JpaAnnotations.INDEX ); - indexes.add( indexAnn ); - } ); - - annotationUsage.setAttributeValue( "indexes", indexes ); - } - - public static void applyIndexes( - List jaxbIndexes, - MutableAnnotationUsage annotationUsage, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbIndexes ) ) { - return; - } - - final List> indexes = new ArrayList<>( jaxbIndexes.size() ); - jaxbIndexes.forEach( jaxbIndex -> { - final MutableAnnotationUsage indexAnn = - JpaAnnotations.INDEX.createUsage( xmlDocumentContext.getModelBuildingContext() ); - applyOr( jaxbIndex, JaxbIndexImpl::getName, "name", indexAnn, JpaAnnotations.INDEX ); - applyOr( jaxbIndex, JaxbIndexImpl::getColumnList, "columnList", indexAnn, JpaAnnotations.INDEX ); - applyOr( jaxbIndex, JaxbIndexImpl::isUnique, "unique", indexAnn, JpaAnnotations.INDEX ); - applyOr( jaxbIndex, JaxbIndexImpl::getOptions, "options", indexAnn, JpaAnnotations.INDEX ); - indexes.add( indexAnn ); - } ); - - annotationUsage.setAttributeValue( "indexes", indexes ); - } - - public static void applyCheckConstraints( - JaxbCheckable jaxbCheckable, - AnnotationTarget target, - MutableAnnotationUsage annotationUsage, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbCheckable!= null && CollectionHelper.isNotEmpty( jaxbCheckable.getCheckConstraints() ) ) { - final List> checks = new ArrayList<>( jaxbCheckable.getCheckConstraints().size() ); - for ( JaxbCheckConstraintImpl jaxbCheck : jaxbCheckable.getCheckConstraints() ) { - final MutableAnnotationUsage checkAnn = JpaAnnotations.CHECK_CONSTRAINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); - checkAnn.setAttributeValue( "constraint", jaxbCheck.getConstraint() ); - applyOptionalAttribute( checkAnn, "name", jaxbCheck.getName() ); - applyOptionalAttribute( checkAnn, "options", jaxbCheck.getOptions() ); - checks.add( checkAnn ); - } - annotationUsage.setAttributeValue( "check", checks ); + cascadeAnn.value( cascadeTypes.toArray(CascadeType[]::new) ); } } @@ -477,12 +351,11 @@ public class XmlAnnotationHelper { String name, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final ClassDetails classDetails = resolveJavaType( name, xmlDocumentContext ); - final MutableAnnotationUsage targetAnn = memberDetails.applyAnnotationUsage( - HibernateAnnotations.TARGET, + final TargetXmlAnnotation targetAnn = (TargetXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.TARGET, xmlDocumentContext.getModelBuildingContext() ); - targetAnn.setAttributeValue( "value", classDetails ); + targetAnn.value( name ); } @SuppressWarnings("deprecation") @@ -494,11 +367,11 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage temporalAnn = memberDetails.applyAnnotationUsage( + final TemporalJpaAnnotation temporalAnn = (TemporalJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.TEMPORAL, xmlDocumentContext.getModelBuildingContext() ); - temporalAnn.setAttributeValue( "value", temporalType ); + temporalAnn.value( temporalType ); } public static void applyLob(JaxbLobImpl jaxbLob, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { @@ -514,12 +387,12 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage annotationUsage = memberDetails.applyAnnotationUsage( + final EnumeratedJpaAnnotation annotationUsage = (EnumeratedJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.ENUMERATED, xmlDocumentContext.getModelBuildingContext() ); - annotationUsage.setAttributeValue( "value", enumType ); + annotationUsage.value( enumType ); } public static void applyNationalized( @@ -541,105 +414,72 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage generatedValueAnn = memberDetails.applyAnnotationUsage( + final GeneratedValueJpaAnnotation generatedValueAnn = (GeneratedValueJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.GENERATED_VALUE, xmlDocumentContext.getModelBuildingContext() ); - memberDetails.addAnnotationUsage( generatedValueAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "strategy", jaxbGeneratedValue.getStrategy(), generatedValueAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "generator", jaxbGeneratedValue.getGenerator(), generatedValueAnn ); + + if ( jaxbGeneratedValue.getStrategy() != null ) { + generatedValueAnn.strategy( jaxbGeneratedValue.getStrategy() ); + } + + if ( StringHelper.isNotEmpty( jaxbGeneratedValue.getGenerator() ) ) { + generatedValueAnn.generator( jaxbGeneratedValue.getGenerator() ); + } } public static void applySequenceGenerator( JaxbSequenceGeneratorImpl jaxbGenerator, - MutableMemberDetails memberDetails, + MutableAnnotationTarget generatorTarget, XmlDocumentContext xmlDocumentContext) { if ( jaxbGenerator == null ) { return; } - final MutableAnnotationUsage sequenceAnn = memberDetails.applyAnnotationUsage( + final SequenceGeneratorJpaAnnotation sequenceAnn = (SequenceGeneratorJpaAnnotation) generatorTarget.applyAnnotationUsage( JpaAnnotations.SEQUENCE_GENERATOR, xmlDocumentContext.getModelBuildingContext() ); - applySequenceGeneratorAttributes( jaxbGenerator, sequenceAnn ); - } - - public static void applySequenceGenerator( - JaxbSequenceGeneratorImpl jaxbGenerator, - MutableClassDetails classDetails, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbGenerator == null ) { - return; + if ( StringHelper.isNotEmpty( jaxbGenerator.getName() ) ) { + sequenceAnn.name( jaxbGenerator.getName() ); } - final MutableAnnotationUsage sequenceAnn = classDetails.replaceAnnotationUsage( - JpaAnnotations.SEQUENCE_GENERATOR, - xmlDocumentContext.getModelBuildingContext() - ); + if ( jaxbGenerator.getSequenceName() != null ) { + sequenceAnn.sequenceName( jaxbGenerator.getSequenceName() ); + } - applySequenceGeneratorAttributes( jaxbGenerator, sequenceAnn ); - } + if ( StringHelper.isNotEmpty( jaxbGenerator.getCatalog() ) ) { + sequenceAnn.catalog( jaxbGenerator.getCatalog() ); + } - private static void applySequenceGeneratorAttributes( - JaxbSequenceGeneratorImpl jaxbGenerator, - MutableAnnotationUsage sequenceAnn) { - XmlProcessingHelper.applyAttributeIfSpecified( "name", jaxbGenerator.getName(), sequenceAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "sequenceName", jaxbGenerator.getSequenceName(), sequenceAnn ); + if ( StringHelper.isNotEmpty( jaxbGenerator.getSchema() ) ) { + sequenceAnn.schema( jaxbGenerator.getSchema() ); + } - XmlProcessingHelper.applyAttributeIfSpecified( "catalog", jaxbGenerator.getCatalog(), sequenceAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "schema", jaxbGenerator.getSchema(), sequenceAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "initialValue", jaxbGenerator.getInitialValue(), sequenceAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "allocationSize", jaxbGenerator.getInitialValue(), sequenceAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "options", jaxbGenerator.getOptions(), sequenceAnn ); + if ( jaxbGenerator.getInitialValue() != null ) { + sequenceAnn.initialValue( jaxbGenerator.getInitialValue() ); + } + + if ( jaxbGenerator.getAllocationSize() != null ) { + sequenceAnn.allocationSize( jaxbGenerator.getAllocationSize() ); + } + + if ( StringHelper.isNotEmpty( jaxbGenerator.getOptions() ) ) { + sequenceAnn.options( jaxbGenerator.getOptions() ); + } } public static void applyTableGenerator( JaxbTableGeneratorImpl jaxbGenerator, - MutableClassDetails classDetails, + MutableAnnotationTarget generatorTarget, XmlDocumentContext xmlDocumentContext) { if ( jaxbGenerator == null ) { return; } - final MutableAnnotationUsage tableAnn = classDetails.replaceAnnotationUsage( - JpaAnnotations.TABLE_GENERATOR, - xmlDocumentContext.getModelBuildingContext() - ); - - applyTableGeneratorAttributes( jaxbGenerator, tableAnn ); - applyUniqueConstraints( jaxbGenerator.getUniqueConstraints(), tableAnn, xmlDocumentContext ); - applyIndexes( jaxbGenerator.getIndexes(), tableAnn, xmlDocumentContext ); - } - - public static void applyTableGenerator( - JaxbTableGeneratorImpl jaxbGenerator, - MutableMemberDetails memberDetails, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbGenerator == null ) { - return; - } - - final MutableAnnotationUsage tableAnn = memberDetails.applyAnnotationUsage( JpaAnnotations.TABLE_GENERATOR, xmlDocumentContext.getModelBuildingContext() ); - applyTableGeneratorAttributes( jaxbGenerator, tableAnn ); - applyUniqueConstraints( jaxbGenerator.getUniqueConstraints(), memberDetails, tableAnn, xmlDocumentContext ); - applyIndexes( jaxbGenerator.getIndexes(), memberDetails, tableAnn, xmlDocumentContext ); - } - - private static void applyTableGeneratorAttributes( - JaxbTableGeneratorImpl jaxbGenerator, - MutableAnnotationUsage tableAnn) { - XmlProcessingHelper.applyAttributeIfSpecified( "name", jaxbGenerator.getName(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "table", jaxbGenerator.getTable(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "catalog", jaxbGenerator.getCatalog(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "schema", jaxbGenerator.getSchema(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "pkColumnName", jaxbGenerator.getPkColumnName(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "valueColumnName", jaxbGenerator.getValueColumnName(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "pkColumnValue", jaxbGenerator.getPkColumnValue(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "initialValue", jaxbGenerator.getInitialValue(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "allocationSize", jaxbGenerator.getInitialValue(), tableAnn ); - XmlProcessingHelper.applyAttributeIfSpecified( "options", jaxbGenerator.getOptions(), tableAnn ); + final TableGeneratorJpaAnnotation tableAnn = (TableGeneratorJpaAnnotation) generatorTarget.applyAnnotationUsage( JpaAnnotations.TABLE_GENERATOR, xmlDocumentContext.getModelBuildingContext() ); + tableAnn.apply( jaxbGenerator, xmlDocumentContext ); } public static void applyUuidGenerator( @@ -650,12 +490,12 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage uuidGenAnn = memberDetails.applyAnnotationUsage( + final UuidGeneratorAnnotation uuidGenAnn = (UuidGeneratorAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.UUID_GENERATOR, xmlDocumentContext.getModelBuildingContext() ); - uuidGenAnn.setAttributeValue( "style", jaxbGenerator.getStyle() ); + uuidGenAnn.style( jaxbGenerator.getStyle() ); } public static void applyAttributeOverrides( @@ -671,63 +511,63 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage overridesUsage = memberDetails.applyAnnotationUsage( - JpaAnnotations.ATTRIBUTE_OVERRIDES, + final AttributeOverridesJpaAnnotation overridesUsage = (AttributeOverridesJpaAnnotation) memberDetails.applyAnnotationUsage( + ATTRIBUTE_OVERRIDES, xmlDocumentContext.getModelBuildingContext() ); final int numberOfOverrides = jaxbMapKeyOverrides.size() + jaxbElementOverrides.size(); - final List> overrideUsages = arrayList( numberOfOverrides ); - overridesUsage.setAttributeValue( "value", overrideUsages ); + final AttributeOverride[] overrideUsages = new AttributeOverride[numberOfOverrides]; + overridesUsage.value( overrideUsages ); // We need to handle overrides for maps specially... if ( memberDetails.getMapKeyType() != null ) { - jaxbMapKeyOverrides.forEach( (jaxbOverride) -> { - overrideUsages.add( createAttributeOverrideUsage( + int position = 0; + for ( JaxbAttributeOverrideImpl jaxbOverride : jaxbMapKeyOverrides ) { + overrideUsages[position++] = createAttributeOverrideUsage( jaxbOverride, "key", memberDetails, xmlDocumentContext - ) ); - } ); - jaxbElementOverrides.forEach( (jaxbOverride) -> { - overrideUsages.add( createAttributeOverrideUsage( + ); + } + for ( JaxbAttributeOverrideImpl jaxbOverride : jaxbElementOverrides ) { + overrideUsages[position++] = createAttributeOverrideUsage( jaxbOverride, "value", memberDetails, xmlDocumentContext - ) ); - } ); + ); + } } else { assert CollectionHelper.isEmpty( jaxbMapKeyOverrides ); - jaxbElementOverrides.forEach( (jaxbOverride) -> { - overrideUsages.add( createAttributeOverrideUsage( - jaxbOverride, - null, + for ( int i = 0; i < jaxbElementOverrides.size(); i++ ) { + overrideUsages[i] = createAttributeOverrideUsage( + jaxbElementOverrides.get(i), + "value", memberDetails, xmlDocumentContext - ) ); - } ); + ); + } } } - private static MutableAnnotationUsage createAttributeOverrideUsage( + private static AttributeOverrideJpaAnnotation createAttributeOverrideUsage( JaxbAttributeOverrideImpl jaxbOverride, String namePrefix, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); - final MutableAnnotationUsage overrideUsage = JpaAnnotations.ATTRIBUTE_OVERRIDE.createUsage( modelBuildingContext ); + final AttributeOverrideJpaAnnotation overrideUsage = ATTRIBUTE_OVERRIDE.createUsage( modelBuildingContext ); final String name = StringHelper.qualifyConditionally( namePrefix, jaxbOverride.getName() ); - overrideUsage.setAttributeValue( "name", name ); - - final MutableAnnotationUsage columnAnn = JpaAnnotations.COLUMN.createUsage( modelBuildingContext ); - overrideUsage.setAttributeValue( "column", columnAnn ); - ColumnProcessing.applyColumnDetails( jaxbOverride.getColumn(), target, columnAnn, xmlDocumentContext ); + overrideUsage.name( name ); + final ColumnJpaAnnotation columnAnn = COLUMN.createUsage( modelBuildingContext ); + overrideUsage.column( columnAnn ); + columnAnn.apply( jaxbOverride.getColumn(), xmlDocumentContext ); return overrideUsage; } @@ -747,22 +587,23 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage overridesUsage = target.replaceAnnotationUsage( - JpaAnnotations.ATTRIBUTE_OVERRIDE, - JpaAnnotations.ATTRIBUTE_OVERRIDES, + final AttributeOverridesJpaAnnotation overridesUsage = (AttributeOverridesJpaAnnotation) target.replaceAnnotationUsage( + ATTRIBUTE_OVERRIDE, + ATTRIBUTE_OVERRIDES, xmlDocumentContext.getModelBuildingContext() ); - final ArrayList> overrideUsages = arrayList( jaxbOverrides.size() ); - overridesUsage.setAttributeValue( "value", overrideUsages ); - jaxbOverrides.forEach( (jaxbOverride) -> { - overrideUsages.add( createAttributeOverrideUsage( - jaxbOverride, + final AttributeOverride[] overrideUsages = new AttributeOverride[jaxbOverrides.size()]; + overridesUsage.value( overrideUsages ); + + for ( int i = 0; i < jaxbOverrides.size(); i++ ) { + overrideUsages[i] = createAttributeOverrideUsage( + jaxbOverrides.get( i ), namePrefix, target, xmlDocumentContext - ) ); - } ); + ); + } } public static void applyAssociationOverrides( @@ -773,49 +614,65 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage overridesUsage = target.replaceAnnotationUsage( - JpaAnnotations.ASSOCIATION_OVERRIDE, - JpaAnnotations.ASSOCIATION_OVERRIDES, + final AssociationOverridesJpaAnnotation overridesUsage = (AssociationOverridesJpaAnnotation) target.replaceAnnotationUsage( + ASSOCIATION_OVERRIDE, + ASSOCIATION_OVERRIDES, xmlDocumentContext.getModelBuildingContext() ); - final ArrayList> overrideUsages = arrayList( jaxbOverrides.size() ); - overridesUsage.setAttributeValue( "value", overrideUsages ); - jaxbOverrides.forEach( (jaxbOverride) -> { - final MutableAnnotationUsage overrideUsage = - JpaAnnotations.ASSOCIATION_OVERRIDE.createUsage( xmlDocumentContext.getModelBuildingContext() ); - transferAssociationOverride( jaxbOverride, overrideUsage, target, xmlDocumentContext ); - overrideUsages.add( overrideUsage ); - } ); + final AssociationOverride[] overrideUsages = new AssociationOverride[jaxbOverrides.size()]; + overridesUsage.value( overrideUsages ); + + for ( int i = 0; i < jaxbOverrides.size(); i++ ) { + final AssociationOverrideJpaAnnotation override = ASSOCIATION_OVERRIDE.createUsage( xmlDocumentContext.getModelBuildingContext() ); + overrideUsages[i] = override; + transferAssociationOverride( jaxbOverrides.get(i), override, target, xmlDocumentContext ); + } } private static void transferAssociationOverride( JaxbAssociationOverrideImpl jaxbOverride, - MutableAnnotationUsage overrideUsage, + AssociationOverrideJpaAnnotation overrideUsage, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - overrideUsage.setAttributeValue( "name", jaxbOverride.getName() ); + overrideUsage.name( jaxbOverride.getName() ); final List joinColumns = jaxbOverride.getJoinColumns(); if ( CollectionHelper.isNotEmpty( joinColumns ) ) { - overrideUsage.setAttributeValue( - "joinColumns", - JoinColumnProcessing.transformJoinColumnList( joinColumns, target, xmlDocumentContext ) - ); + overrideUsage.joinColumns( JoinColumnProcessing.transformJoinColumnList( + joinColumns, + xmlDocumentContext + ) ); } if ( jaxbOverride.getJoinTable() != null ) { - overrideUsage.setAttributeValue( - "joinTable", - TableProcessing.transformJoinTable( jaxbOverride.getJoinTable(), target, xmlDocumentContext ) - ); + overrideUsage.joinTable( TableProcessing.transformJoinTable( + jaxbOverride.getJoinTable(), + target, + xmlDocumentContext + ) ); } if ( jaxbOverride.getForeignKeys() != null ) { - overrideUsage.setAttributeValue( - "foreignKey", - ForeignKeyProcessing.createNestedForeignKeyAnnotation( jaxbOverride.getForeignKeys(), target, xmlDocumentContext ) - ); + overrideUsage.foreignKey( ForeignKeyProcessing.createNestedForeignKeyAnnotation( + jaxbOverride.getForeignKeys(), + xmlDocumentContext + ) ); } - + + } + + public static void applyConvert( + JaxbConvertImpl jaxbConvert, + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbConvert == null ) { + return; + } + + final ConvertJpaAnnotation annotation = (ConvertJpaAnnotation) memberDetails.replaceAnnotationUsage( + CONVERT, + xmlDocumentContext.getModelBuildingContext() + ); + transferConvertDetails( jaxbConvert, annotation, null, xmlDocumentContext ); } public static void applyConverts( @@ -827,68 +684,52 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage convertsUsage = memberDetails.replaceAnnotationUsage( - JpaAnnotations.CONVERT, + final ConvertsJpaAnnotation convertsUsage = (ConvertsJpaAnnotation) memberDetails.replaceAnnotationUsage( + CONVERT, JpaAnnotations.CONVERTS, xmlDocumentContext.getModelBuildingContext() ); - final ArrayList> convertUsages = arrayList( jaxbConverts.size() ); - convertsUsage.setAttributeValue( "value", convertUsages ); + final Convert[] convertUsages = new Convert[jaxbConverts.size()]; + convertsUsage.value( convertUsages ); - for ( JaxbConvertImpl jaxbConvert : jaxbConverts ) { - final MutableAnnotationUsage convertUsage = JpaAnnotations.CONVERT.createUsage( xmlDocumentContext.getModelBuildingContext() ); - convertUsages.add( convertUsage ); - - final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry(); - final ClassDetails converter; - if ( StringHelper.isNotEmpty( jaxbConvert.getConverter() ) ) { - converter = classDetailsRegistry.resolveClassDetails( jaxbConvert.getConverter() ); - convertUsage.setAttributeValue( "converter", converter ); - } - - XmlProcessingHelper.applyAttributeIfSpecified( - "attributeName", - prefixIfNotAlready( jaxbConvert.getAttributeName(), namePrefix ), - convertUsage + for ( int i = 0; i < jaxbConverts.size(); i++ ) { + convertUsages[i] = transformConvert( + jaxbConverts.get( i ), + namePrefix, + xmlDocumentContext ); - XmlProcessingHelper.applyAttributeIfSpecified( "disableConversion", jaxbConvert.isDisableConversion(), convertUsage ); } } - public static void applyConvert( + public static Convert transformConvert( JaxbConvertImpl jaxbConvert, - MutableMemberDetails memberDetails, - XmlDocumentContext xmlDocumentContext) { - applyConvert( jaxbConvert, memberDetails, null, xmlDocumentContext ); - } - - public static void applyConvert( - JaxbConvertImpl jaxbConvert, - MutableMemberDetails memberDetails, String namePrefix, XmlDocumentContext xmlDocumentContext) { if ( jaxbConvert == null ) { - return; + return null; } - final MutableAnnotationUsage convertUsage = memberDetails.applyAnnotationUsage( - JpaAnnotations.CONVERT, - xmlDocumentContext.getModelBuildingContext() - ); + final ConvertJpaAnnotation convert = CONVERT.createUsage( xmlDocumentContext.getModelBuildingContext() ); - final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry(); - final ClassDetails converter; + transferConvertDetails( jaxbConvert, convert, namePrefix, xmlDocumentContext ); + + return convert; + } + + private static void transferConvertDetails( + JaxbConvertImpl jaxbConvert, + ConvertJpaAnnotation convert, + String namePrefix, + XmlDocumentContext xmlDocumentContext) { if ( StringHelper.isNotEmpty( jaxbConvert.getConverter() ) ) { - converter = classDetailsRegistry.resolveClassDetails( jaxbConvert.getConverter() ); - convertUsage.setAttributeValue( "converter", converter ); + convert.converter( xmlDocumentContext.resolveJavaType( jaxbConvert.getConverter() ).toJavaClass() ); + } + if ( StringHelper.isNotEmpty( jaxbConvert.getAttributeName() ) ) { + convert.attributeName( prefixIfNotAlready( jaxbConvert.getAttributeName(), namePrefix ) ); + } + if ( jaxbConvert.isDisableConversion() != null ) { + convert.disableConversion( jaxbConvert.isDisableConversion() ); } - - XmlProcessingHelper.applyAttributeIfSpecified( - "attributeName", - prefixIfNotAlready( jaxbConvert.getAttributeName(), namePrefix ), - convertUsage - ); - XmlProcessingHelper.applyAttributeIfSpecified( "disableConversion", jaxbConvert.isDisableConversion(), convertUsage ); } public static void applyTable( @@ -900,42 +741,32 @@ public class XmlAnnotationHelper { final String catalog = defaults.getCatalog(); final String schema = defaults.getSchema(); if ( StringHelper.isNotEmpty( catalog ) || StringHelper.isNotEmpty( schema ) ) { - final MutableAnnotationUsage
tableAnn = target.applyAnnotationUsage( + final TableJpaAnnotation tableAnn = (TableJpaAnnotation) target.applyAnnotationUsage( JpaAnnotations.TABLE, xmlDocumentContext.getModelBuildingContext() ); if ( StringHelper.isNotEmpty( catalog ) ) { - tableAnn.setAttributeValue( "catalog", catalog ); + tableAnn.catalog( catalog ); } if ( StringHelper.isNotEmpty( schema ) ) { - tableAnn.setAttributeValue( "schema", schema ); + tableAnn.schema( schema ); } } } else { - final MutableAnnotationUsage
tableAnn = target.applyAnnotationUsage( + final TableJpaAnnotation tableAnn = (TableJpaAnnotation) target.applyAnnotationUsage( JpaAnnotations.TABLE, xmlDocumentContext.getModelBuildingContext() ); - applyOr( jaxbTable, JaxbTableImpl::getName, "name", tableAnn, JpaAnnotations.TABLE ); - applyTableAttributes( jaxbTable, target, tableAnn, JpaAnnotations.TABLE, xmlDocumentContext ); + tableAnn.apply( jaxbTable, xmlDocumentContext ); } } - public static void applyTableAttributes( - JaxbTableMapping jaxbTable, - AnnotationTarget target, - MutableAnnotationUsage tableAnn, - AnnotationDescriptor annotationDescriptor, - XmlDocumentContext xmlDocumentContext) { - applyOrCatalog( jaxbTable, tableAnn, annotationDescriptor, xmlDocumentContext ); - applyOrSchema( jaxbTable, tableAnn, annotationDescriptor, xmlDocumentContext); - applyOr( jaxbTable, JaxbTableMapping::getOptions, "options", tableAnn, annotationDescriptor ); - applyOr( jaxbTable, JaxbTableMapping::getComment, "comment", tableAnn, annotationDescriptor ); - applyCheckConstraints( jaxbTable, target, tableAnn, xmlDocumentContext ); - applyUniqueConstraints( jaxbTable.getUniqueConstraints(), target, tableAnn, xmlDocumentContext ); - applyIndexes( jaxbTable.getIndexes(), target, tableAnn, xmlDocumentContext ); + public static void applyOptionalString(String value, Consumer target) { + if ( StringHelper.isNotEmpty( value ) ) { + target.accept( value ); + } } public static void applyNaturalIdCache( @@ -946,13 +777,15 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage naturalIdCacheUsage = classDetails.applyAnnotationUsage( + final NaturalIdCacheAnnotation naturalIdCacheUsage = (NaturalIdCacheAnnotation) classDetails.applyAnnotationUsage( HibernateAnnotations.NATURAL_ID_CACHE, xmlDocumentContext.getModelBuildingContext() ); final JaxbCachingImpl jaxbCaching = jaxbNaturalId.getCaching(); - XmlProcessingHelper.applyAttributeIfSpecified( "region", jaxbCaching.getRegion(), naturalIdCacheUsage ); + if ( StringHelper.isNotEmpty( jaxbCaching.getRegion() ) ) { + naturalIdCacheUsage.region( jaxbCaching.getRegion() ); + } } static void applyInheritance( @@ -963,11 +796,13 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage inheritanceUsage = classDetails.applyAnnotationUsage( + final InheritanceJpaAnnotation inheritanceUsage = (InheritanceJpaAnnotation) classDetails.applyAnnotationUsage( JpaAnnotations.INHERITANCE, xmlDocumentContext.getModelBuildingContext() ); - XmlProcessingHelper.applyAttributeIfSpecified( "strategy", jaxbEntity.getInheritance().getStrategy(), inheritanceUsage ); + if ( jaxbEntity.getInheritance().getStrategy() != null ) { + inheritanceUsage.strategy( jaxbEntity.getInheritance().getStrategy() ); + } } public static ClassDetails resolveJavaType(String value, XmlDocumentContext xmlDocumentContext) { @@ -1081,7 +916,7 @@ public class XmlAnnotationHelper { String descriptorClassName, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage typeAnn = memberDetails.applyAnnotationUsage( + final JavaTypeAnnotation typeAnn = (JavaTypeAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.JAVA_TYPE, xmlDocumentContext.getModelBuildingContext() ); @@ -1090,7 +925,7 @@ public class XmlAnnotationHelper { .getModelBuildingContext() .getClassDetailsRegistry() .resolveClassDetails( descriptorClassName ); - typeAnn.setAttributeValue( "value", descriptorClass ); + typeAnn.value( descriptorClass.toJavaClass() ); } @@ -1102,11 +937,11 @@ public class XmlAnnotationHelper { .getModelBuildingContext() .getClassDetailsRegistry() .resolveClassDetails( descriptorClassName ); - final MutableAnnotationUsage jdbcTypeAnn = memberDetails.applyAnnotationUsage( + final JdbcTypeAnnotation jdbcTypeAnn = (JdbcTypeAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.JDBC_TYPE, xmlDocumentContext.getModelBuildingContext() ); - jdbcTypeAnn.setAttributeValue( "value", descriptorClassDetails ); + jdbcTypeAnn.value( descriptorClassDetails.toJavaClass() ); } @@ -1118,147 +953,134 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage typeCodeAnn = memberDetails.applyAnnotationUsage( + final JdbcTypeCodeAnnotation typeCodeAnn = (JdbcTypeCodeAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.JDBC_TYPE_CODE, xmlDocumentContext.getModelBuildingContext() ); - typeCodeAnn.setAttributeValue( "value", jdbcTypeCode ); + typeCodeAnn.value( jdbcTypeCode ); } public static void applyFilters( - List filters, + List jaxbFilters, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - applyFilters( filters, target, HibernateAnnotations.FILTER, xmlDocumentContext ); - } - - public static void applyJoinTableFilters( - List filters, - MutableAnnotationTarget target, - XmlDocumentContext xmlDocumentContext) { - applyFilters( filters, target, HibernateAnnotations.FILTER_JOIN_TABLE, xmlDocumentContext ); - } - - public static void applyFilters( - List filters, - MutableAnnotationTarget target, - AnnotationDescriptor filterAnnotationDescriptor, - XmlDocumentContext xmlDocumentContext) { - assert filterAnnotationDescriptor.getRepeatableContainer() != null; - - if ( filters.isEmpty() ) { + if ( CollectionHelper.isEmpty( jaxbFilters ) ) { return; } - // replaces existing - final MutableAnnotationUsage containerUsage = target.replaceAnnotationUsage( - filterAnnotationDescriptor, - filterAnnotationDescriptor.getRepeatableContainer(), + final FiltersAnnotation filters = (FiltersAnnotation) target.replaceAnnotationUsage( + FILTER, + HibernateAnnotations.FILTERS, xmlDocumentContext.getModelBuildingContext() ); - final ArrayList filterUsages = arrayList( filters.size() ); - containerUsage.setAttributeValue( "value", filterUsages ); + final FilterAnnotation[] filterUsages = new FilterAnnotation[jaxbFilters.size()]; + filters.value( filterUsages ); - filters.forEach( (jaxbFilter) -> { - final MutableAnnotationUsage filterUsage = filterAnnotationDescriptor.createUsage( xmlDocumentContext.getModelBuildingContext() ); - filterUsages.add( filterUsage ); - - filterUsage.setAttributeValue( "name", jaxbFilter.getName() ); - XmlProcessingHelper.applyAttributeIfSpecified( "condition", jaxbFilter.getCondition(), filterUsage ); - XmlProcessingHelper.applyAttributeIfSpecified( "deduceAliasInjectionPoints", jaxbFilter.isAutoAliasInjection(), filterUsage ); - - final List aliases = jaxbFilter.getAliases(); - if ( !CollectionHelper.isEmpty( aliases ) ) { - filterUsage.setAttributeValue( "aliases", getSqlFragmentAliases( aliases, target, xmlDocumentContext ) ); - } - } ); + for ( int i = 0; i < jaxbFilters.size(); i++ ) { + final FilterAnnotation filterUsage = FILTER.createUsage( xmlDocumentContext.getModelBuildingContext() ); + filterUsages[i] = filterUsage; + filterUsage.apply( jaxbFilters.get(i), xmlDocumentContext ); + } } - private static List> getSqlFragmentAliases( - List aliases, + public static void applyJoinTableFilters( + List jaxbFilters, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - final List> sqlFragmentAliases = new ArrayList<>( aliases.size() ); - for ( JaxbHbmFilterImpl.JaxbAliasesImpl alias : aliases ) { - final MutableAnnotationUsage aliasAnn = - HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage( xmlDocumentContext.getModelBuildingContext() ); - - aliasAnn.setAttributeValue( "alias", alias.getAlias() ); - XmlProcessingHelper.applyAttributeIfSpecified( "table", alias.getTable(), aliasAnn ); - if ( StringHelper.isNotEmpty( alias.getEntity() ) ) { - aliasAnn.setAttributeValue( - "entity", - xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry().resolveClassDetails( alias.getEntity() ) - ); - } - sqlFragmentAliases.add( aliasAnn ); + if ( CollectionHelper.isEmpty( jaxbFilters ) ) { + return; + } + + final FilterJoinTablesAnnotation filters = (FilterJoinTablesAnnotation) target.replaceAnnotationUsage( + FILTER_JOIN_TABLE, + HibernateAnnotations.FILTER_JOIN_TABLES, + xmlDocumentContext.getModelBuildingContext() + ); + + final FilterJoinTableAnnotation[] filterUsages = new FilterJoinTableAnnotation[jaxbFilters.size()]; + filters.value( filterUsages ); + + for ( int i = 0; i < jaxbFilters.size(); i++ ) { + final FilterJoinTableAnnotation filterUsage = FILTER_JOIN_TABLE.createUsage( xmlDocumentContext.getModelBuildingContext() ); + filterUsages[i] = filterUsage; + + filterUsage.apply( jaxbFilters.get(i), xmlDocumentContext ); } - return sqlFragmentAliases; } public static void applySqlRestriction( String sqlRestriction, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - applySqlRestriction( sqlRestriction, target, HibernateAnnotations.SQL_RESTRICTION, xmlDocumentContext ); + if ( StringHelper.isEmpty( sqlRestriction ) ) { + return; + } + + final SQLRestrictionAnnotation sqlRestrictionAnn = (SQLRestrictionAnnotation) target.applyAnnotationUsage( + SQL_RESTRICTION, + xmlDocumentContext.getModelBuildingContext() + ); + sqlRestrictionAnn.value( sqlRestriction ); } public static void applySqlJoinTableRestriction( - String sqlJoinTableRestriction, - MutableAnnotationTarget target, - XmlDocumentContext xmlDocumentContext) { - applySqlRestriction( sqlJoinTableRestriction, target, HibernateAnnotations.SQL_RESTRICTION_JOIN_TABLE, xmlDocumentContext ); - } - - private static void applySqlRestriction( String sqlRestriction, MutableAnnotationTarget target, - AnnotationDescriptor annotationDescriptor, XmlDocumentContext xmlDocumentContext) { - if ( StringHelper.isNotEmpty( sqlRestriction ) ) { - final MutableAnnotationUsage restrictionUsage = target.applyAnnotationUsage( - annotationDescriptor, - xmlDocumentContext.getModelBuildingContext() - ); - restrictionUsage.setAttributeValue( "value", sqlRestriction ); + if ( StringHelper.isEmpty( sqlRestriction ) ) { + return; } + final SQLJoinTableRestrictionAnnotation sqlRestrictionAnn = (SQLJoinTableRestrictionAnnotation) target.applyAnnotationUsage( + HibernateAnnotations.SQL_JOIN_TABLE_RESTRICTION, + xmlDocumentContext.getModelBuildingContext() + ); + sqlRestrictionAnn.value( sqlRestriction ); } - public static void applyCustomSql( + public static void applyCustomSql( JaxbCustomSqlImpl jaxbCustomSql, MutableAnnotationTarget target, - AnnotationDescriptor annotationDescriptor, + AnnotationDescriptor descriptor, XmlDocumentContext xmlDocumentContext) { - // todo (7.0) : account for secondary-table custom SQL if ( jaxbCustomSql == null ) { return; } - final MutableAnnotationUsage annotationUsage = target.applyAnnotationUsage( - annotationDescriptor, + final CustomSqlDetails annotation = (CustomSqlDetails) target.applyAnnotationUsage( + descriptor, xmlDocumentContext.getModelBuildingContext() ); - annotationUsage.setAttributeValue( "sql", jaxbCustomSql.getValue() ); - annotationUsage.setAttributeValue( "callable", jaxbCustomSql.isCallable() ); - XmlProcessingHelper.applyAttributeIfSpecified( "table", jaxbCustomSql.getTable(), annotationUsage ); + + applyCustomSql( jaxbCustomSql, annotation ); + } + + public static void applyCustomSql( + JaxbCustomSqlImpl jaxbCustomSql, + CustomSqlDetails annotation) { + if ( jaxbCustomSql == null ) { + return; + } + + annotation.sql( jaxbCustomSql.getValue() ); + annotation.callable( jaxbCustomSql.isCallable() ); + + if ( StringHelper.isNotEmpty( jaxbCustomSql.getTable() ) ) { + annotation.table( jaxbCustomSql.getTable() ); + } + if ( jaxbCustomSql.getResultCheck() != null ) { - annotationUsage.setAttributeValue( "check", getResultCheckStyle( jaxbCustomSql.getResultCheck() ) ); + annotation.check( interpretResultCheckStyle( jaxbCustomSql.getResultCheck() ) ); } } @SuppressWarnings({ "deprecation", "removal" }) - private static ResultCheckStyle getResultCheckStyle(ExecuteUpdateResultCheckStyle style) { - switch ( style ) { - case NONE: - return ResultCheckStyle.NONE; - case COUNT: - return ResultCheckStyle.COUNT; - case PARAM: - return ResultCheckStyle.PARAM; - default: - return null; - } + private static ResultCheckStyle interpretResultCheckStyle(ExecuteUpdateResultCheckStyle style) { + return switch ( style ) { + case NONE -> ResultCheckStyle.NONE; + case COUNT -> ResultCheckStyle.COUNT; + case PARAM -> ResultCheckStyle.PARAM; + }; } static void applyIdClass( @@ -1269,7 +1091,7 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage idClassAnn = target.applyAnnotationUsage( + final IdClassJpaAnnotation idClassAnn = (IdClassJpaAnnotation) target.applyAnnotationUsage( JpaAnnotations.ID_CLASS, xmlDocumentContext.getModelBuildingContext() ); @@ -1277,7 +1099,7 @@ public class XmlAnnotationHelper { final ClassDetails idClassImpl = xmlDocumentContext.getModelBuildingContext() .getClassDetailsRegistry() .resolveClassDetails( jaxbIdClass.getClazz() ); - idClassAnn.setAttributeValue( "value", idClassImpl ); + idClassAnn.value( idClassImpl.toJavaClass() ); } public static void applyLifecycleCallbacks( @@ -1287,11 +1109,11 @@ public class XmlAnnotationHelper { final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); if ( jaxbClass.getExcludeDefaultListeners() != null ) { - classDetails.applyAnnotationUsage( JpaAnnotations.EXCLUDE_DEFAULT_LISTENERS, modelBuildingContext ); + classDetails.applyAnnotationUsage( EXCLUDE_DEFAULT_LISTENERS, modelBuildingContext ); } if ( jaxbClass.getExcludeSuperclassListeners() != null ) { - classDetails.applyAnnotationUsage( JpaAnnotations.EXCLUDE_SUPERCLASS_LISTENERS, modelBuildingContext ); + classDetails.applyAnnotationUsage( EXCLUDE_SUPERCLASS_LISTENERS, modelBuildingContext ); } applyLifecycleCallbacks( jaxbClass, JpaEventListenerStyle.CALLBACK, classDetails, xmlDocumentContext ); @@ -1307,14 +1129,16 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage listenersUsage = classDetails.replaceAnnotationUsage( + final EntityListenersJpaAnnotation listenersUsage = (EntityListenersJpaAnnotation) classDetails.replaceAnnotationUsage( JpaAnnotations.ENTITY_LISTENERS, xmlDocumentContext.getModelBuildingContext() ); - final List values = arrayList( entityListenerContainer.getEntityListeners().size() ); - listenersUsage.setAttributeValue( "value", values ); - entityListenerContainer.getEntityListeners().forEach( (jaxbEntityListener) -> { + final Class[] listeners = new Class[entityListenerContainer.getEntityListeners().size()]; + listenersUsage.value( listeners ); + + for ( int i = 0; i < entityListenerContainer.getEntityListeners().size(); i++ ) { + final JaxbEntityListenerImpl jaxbEntityListener = entityListenerContainer.getEntityListeners().get( i ); final MutableClassDetails entityListenerClass = xmlDocumentContext.resolveJavaType( jaxbEntityListener.getClazz() ); applyLifecycleCallbacks( jaxbEntityListener, @@ -1322,9 +1146,10 @@ public class XmlAnnotationHelper { entityListenerClass, xmlDocumentContext ); - values.add( entityListenerClass ); - } ); + // todo (7.0) : need to make sure we look up the ClassDetails later when applying listeners; the *Class* won't be correct + listeners[i] = entityListenerClass.toJavaClass(); + } } static void applyLifecycleCallbacks( @@ -1385,11 +1210,13 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage rowIdAnn = target.applyAnnotationUsage( + final RowIdAnnotation rowIdAnn = (RowIdAnnotation) target.applyAnnotationUsage( HibernateAnnotations.ROW_ID, xmlDocumentContext.getModelBuildingContext() ); - XmlProcessingHelper.applyAttributeIfSpecified( "value", rowId, rowIdAnn ); + if ( StringHelper.isNotEmpty( rowId ) ) { + rowIdAnn.value( rowId ); + } } private static String prefixIfNotAlready(String value, String prefix) { @@ -1410,11 +1237,11 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage valueAnn = target.applyAnnotationUsage( + final DiscriminatorValueJpaAnnotation valueAnn = (DiscriminatorValueJpaAnnotation) target.applyAnnotationUsage( JpaAnnotations.DISCRIMINATOR_VALUE, xmlDocumentContext.getModelBuildingContext() ); - valueAnn.setAttributeValue( "value", discriminatorValue ); + valueAnn.value( discriminatorValue ); } static void applyDiscriminatorColumn( @@ -1425,56 +1252,22 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage discriminatorColumnAnn = target.applyAnnotationUsage( + final DiscriminatorColumnJpaAnnotation discriminatorColumnAnn = (DiscriminatorColumnJpaAnnotation) target.applyAnnotationUsage( JpaAnnotations.DISCRIMINATOR_COLUMN, xmlDocumentContext.getModelBuildingContext() ); - - AnnotationUsageHelper.applyStringAttributeIfSpecified( - "name", - jaxbDiscriminatorColumn.getName(), - discriminatorColumnAnn - ); - AnnotationUsageHelper.applyAttributeIfSpecified( - "discriminatorType", - jaxbDiscriminatorColumn.getDiscriminatorType(), - discriminatorColumnAnn - ); - - applyOr( - jaxbDiscriminatorColumn, - JaxbDiscriminatorColumnImpl::getColumnDefinition, - "columnDefinition", - discriminatorColumnAnn, - JpaAnnotations.DISCRIMINATOR_COLUMN - ); - applyOr( - jaxbDiscriminatorColumn, - JaxbDiscriminatorColumnImpl::getOptions, - "options", - discriminatorColumnAnn, - JpaAnnotations.DISCRIMINATOR_COLUMN - ); - applyOr( - jaxbDiscriminatorColumn, - JaxbDiscriminatorColumnImpl::getLength, - "length", - discriminatorColumnAnn, - JpaAnnotations.DISCRIMINATOR_COLUMN - ); + discriminatorColumnAnn.apply( jaxbDiscriminatorColumn, xmlDocumentContext ); if ( jaxbDiscriminatorColumn.isForceSelection() || jaxbDiscriminatorColumn.isInsertable() == FALSE ) { - final MutableAnnotationUsage optionsAnn = target.applyAnnotationUsage( + final DiscriminatorOptionsAnnotation optionsAnn = (DiscriminatorOptionsAnnotation) target.applyAnnotationUsage( HibernateAnnotations.DISCRIMINATOR_OPTIONS, xmlDocumentContext.getModelBuildingContext() ); - optionsAnn.setAttributeValue( "force", true ); + optionsAnn.force( true ); - AnnotationUsageHelper.applyAttributeIfSpecified( - "insert", - jaxbDiscriminatorColumn.isInsertable(), - discriminatorColumnAnn - ); + if ( jaxbDiscriminatorColumn.isInsertable() != null ) { + optionsAnn.insert( jaxbDiscriminatorColumn.isInsertable() ); + } } } @@ -1489,21 +1282,22 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage discriminatorFormulaAnn = target.applyAnnotationUsage( + final DiscriminatorFormulaAnnotation discriminatorFormulaAnn = (DiscriminatorFormulaAnnotation) target.applyAnnotationUsage( HibernateAnnotations.DISCRIMINATOR_FORMULA, xmlDocumentContext.getModelBuildingContext() ); - discriminatorFormulaAnn.setAttributeValue( "value", jaxbDiscriminatorFormula.getFragment() ); - XmlProcessingHelper.applyAttributeIfSpecified( "discriminatorType", jaxbDiscriminatorFormula.getDiscriminatorType(), discriminatorFormulaAnn ); - + discriminatorFormulaAnn.value( jaxbDiscriminatorFormula.getFragment() ); + if ( jaxbDiscriminatorFormula.getDiscriminatorType() != null ) { + discriminatorFormulaAnn.discriminatorType( jaxbDiscriminatorFormula.getDiscriminatorType() ); + } if ( jaxbDiscriminatorFormula.isForceSelection() ) { - final MutableAnnotationUsage optionsAnn = target.applyAnnotationUsage( + final DiscriminatorOptionsAnnotation optionsAnn = (DiscriminatorOptionsAnnotation) target.applyAnnotationUsage( HibernateAnnotations.DISCRIMINATOR_OPTIONS, xmlDocumentContext.getModelBuildingContext() ); - optionsAnn.setAttributeValue( "force", true ); + optionsAnn.force( true ); } } @@ -1522,57 +1316,74 @@ public class XmlAnnotationHelper { return explicitName; } - public static void applyOrSchema( + + /** + * Applies the schema defined either
    + *
  1. The JAXB node directly
  2. + *
  3. The XML document's {@code } element
  4. + *
+ * + * @apiNote The schema defined in {@code }, if any, + * is NOT handled here + */ + public static void applySchema( JaxbSchemaAware jaxbNode, - MutableAnnotationUsage
annotationUsage, - AnnotationDescriptor annotationDescriptor, + DatabaseObjectDetails annotationUsage, XmlDocumentContext xmlDocumentContext) { - applyOr( - jaxbNode, - (table) -> { - if ( StringHelper.isNotEmpty( table.getSchema() ) ) { - return table.getSchema(); - } - else if ( StringHelper.isNotEmpty( defaultSchema( xmlDocumentContext ) ) ) { - return defaultSchema( xmlDocumentContext ); - } - return null; - }, - "schema", - annotationUsage, - annotationDescriptor - ); + if ( jaxbNode == null ) { + return; + } + + if ( StringHelper.isNotEmpty( jaxbNode.getSchema() ) ) { + annotationUsage.schema( jaxbNode.getSchema() ); + } + else if ( StringHelper.isNotEmpty( documentSchema( xmlDocumentContext ) ) ) { + annotationUsage.schema( documentSchema( xmlDocumentContext ) ); + } } - private static String defaultSchema(XmlDocumentContext xmlDocumentContext) { + /** + * Returns the XML document's {@code } element value, if one + * + * @apiNote This is NOT the same as a {@code } defined in {@code } + */ + private static String documentSchema(XmlDocumentContext xmlDocumentContext) { return xmlDocumentContext.getXmlDocument() .getDefaults() .getSchema(); } - public static void applyOrCatalog( + /** + * Applies the catalog defined either
    + *
  1. The JAXB node directly
  2. + *
  3. The XML document's {@code } element
  4. + *
+ * + * @apiNote The catalog defined in {@code }, if any, + * is NOT handled here + */ + public static void applyCatalog( JaxbSchemaAware jaxbNode, - MutableAnnotationUsage
annotationUsage, - AnnotationDescriptor annotationDescriptor, + DatabaseObjectDetails annotationUsage, XmlDocumentContext xmlDocumentContext) { - applyOr( - jaxbNode, - (table) -> { - if ( StringHelper.isNotEmpty( table.getCatalog() ) ) { - return table.getCatalog(); - } - else if ( StringHelper.isNotEmpty( defaultCatalog( xmlDocumentContext ) ) ) { - return defaultCatalog( xmlDocumentContext ); - } - return null; - }, - "catalog", - annotationUsage, - annotationDescriptor - ); + if ( jaxbNode == null ) { + return; + } + + if ( StringHelper.isNotEmpty( jaxbNode.getCatalog() ) ) { + annotationUsage.catalog( jaxbNode.getCatalog() ); + } + else if ( StringHelper.isNotEmpty( documentCatalog( xmlDocumentContext ) ) ) { + annotationUsage.catalog( documentCatalog( xmlDocumentContext ) ); + } } - private static String defaultCatalog(XmlDocumentContext xmlDocumentContext) { + /** + * Returns the XML document's {@code } element value, if one + * + * @apiNote This is NOT the same as a {@code } defined in {@code } + */ + private static String documentCatalog(XmlDocumentContext xmlDocumentContext) { return xmlDocumentContext.getXmlDocument() .getDefaults() .getCatalog(); @@ -1589,75 +1400,137 @@ public class XmlAnnotationHelper { return; } - final MutableAnnotationUsage notFoundAnn = memberDetails.applyAnnotationUsage( + final NotFoundAnnotation notFoundAnn = (NotFoundAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.NOT_FOUND, xmlDocumentContext.getModelBuildingContext() ); - notFoundAnn.setAttributeValue( "action", notFoundAction ); + notFoundAnn.action( notFoundAction ); } - public static void applySecondaryTables(List secondaryTables, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - if ( secondaryTables == null || secondaryTables.isEmpty() ) { + public static void applySecondaryTables(List jaxbSecondaryTables, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { + if ( jaxbSecondaryTables == null || jaxbSecondaryTables.isEmpty() ) { return; } - final MutableAnnotationUsage listenersUsage = target.replaceAnnotationUsage( - JpaAnnotations.SECONDARY_TABLE, + final SecondaryTablesJpaAnnotation tablesUsage = (SecondaryTablesJpaAnnotation) target.replaceAnnotationUsage( + SECONDARY_TABLE, JpaAnnotations.SECONDARY_TABLES, xmlDocumentContext.getModelBuildingContext() ); - final List> values = arrayList( secondaryTables.size() ); - listenersUsage.setAttributeValue( "value", values ); + final SecondaryTable[] tableUsages = new SecondaryTable[jaxbSecondaryTables.size()]; + tablesUsage.value( tableUsages ); - for ( JaxbSecondaryTableImpl secondaryTable : secondaryTables ) { - final MutableAnnotationUsage tableAnn = JpaAnnotations.SECONDARY_TABLE - .createUsage( xmlDocumentContext.getModelBuildingContext() ); - tableAnn.setAttributeValue( "name", secondaryTable.getName() ); + for ( int i = 0; i < jaxbSecondaryTables.size(); i++ ) { + final SecondaryTableJpaAnnotation tableUsage = SECONDARY_TABLE.createUsage( xmlDocumentContext.getModelBuildingContext() ); + tableUsages[i] = tableUsage; - ForeignKeyProcessing.applyForeignKey( secondaryTable.getForeignKey(), tableAnn, xmlDocumentContext ); - - JoinColumnProcessing.applyPrimaryKeyJoinColumns( - secondaryTable.getPrimaryKeyJoinColumn(), - tableAnn, - xmlDocumentContext - ); - - applyTableAttributes( - secondaryTable, - target, - tableAnn, - JpaAnnotations.SECONDARY_TABLE, - xmlDocumentContext - ); - - values.add( tableAnn ); + final JaxbSecondaryTableImpl jaxbSecondaryTable = jaxbSecondaryTables.get( i ); + tableUsage.apply( jaxbSecondaryTable, xmlDocumentContext ); } } + private static final CheckConstraint[] NO_CHECK_CONSTRAINTS = new CheckConstraint[0]; + public static CheckConstraint[] collectCheckConstraints( + List jaxbChecks, + XmlDocumentContext xmlDocumentContext) { + if ( CollectionHelper.isEmpty( jaxbChecks ) ) { + return NO_CHECK_CONSTRAINTS; + } + + final CheckConstraint[] checks = new CheckConstraint[jaxbChecks.size()]; + for ( int i = 0; i < jaxbChecks.size(); i++ ) { + final JaxbCheckConstraintImpl jaxbCheck = jaxbChecks.get( i ); + final CheckConstraintJpaAnnotation annotation = CHECK_CONSTRAINT.createUsage( xmlDocumentContext.getModelBuildingContext() ); + checks[i] = annotation; + annotation.constraint( jaxbCheck.getConstraint() ); + applyOptionalString( jaxbCheck.getName(), annotation::name ); + applyOptionalString( jaxbCheck.getOptions(), annotation::options ); + } + return checks; + } + + private static final UniqueConstraint[] NO_UNIQUE_CONSTRAINTS = new UniqueConstraint[0]; + public static UniqueConstraint[] collectUniqueConstraints( + List jaxbUniqueConstraints, + XmlDocumentContext xmlDocumentContext) { + return collectUniqueConstraints( jaxbUniqueConstraints, xmlDocumentContext.getModelBuildingContext() ); + } + + public static UniqueConstraint[] collectUniqueConstraints( + List jaxbUniqueConstraints, + SourceModelBuildingContext modelContext) { + if ( CollectionHelper.isEmpty( jaxbUniqueConstraints ) ) { + return NO_UNIQUE_CONSTRAINTS; + } + + final UniqueConstraint[] constraints = new UniqueConstraint[jaxbUniqueConstraints.size()]; + for ( int i = 0; i < jaxbUniqueConstraints.size(); i++ ) { + final UniqueConstraintJpaAnnotation uniqueConstraint = UNIQUE_CONSTRAINT.createUsage( modelContext ); + constraints[i] = uniqueConstraint; + + final JaxbUniqueConstraintImpl jaxbUniqueConstraint = jaxbUniqueConstraints.get( i ); + uniqueConstraint.columnNames( jaxbUniqueConstraint.getColumnName().toArray(String[]::new) ); + applyOptionalString( jaxbUniqueConstraint.getName(), uniqueConstraint::name ); + applyOptionalString( jaxbUniqueConstraint.getOptions(), uniqueConstraint::options ); + } + return constraints; + } + + private static final Index[] NO_INDICES = new Index[0]; + public static Index[] collectIndexes( + List jaxbIndexes, + XmlDocumentContext xmlDocumentContext) { + return collectIndexes( jaxbIndexes, xmlDocumentContext.getModelBuildingContext() ); + } + + public static Index[] collectIndexes( + List jaxbIndexes, + SourceModelBuildingContext sourceModelContext) { + if ( CollectionHelper.isEmpty( jaxbIndexes ) ) { + return NO_INDICES; + } + + final Index[] indexes = new Index[jaxbIndexes.size()]; + for ( int i = 0; i < jaxbIndexes.size(); i++ ) { + final IndexJpaAnnotation index = INDEX.createUsage( sourceModelContext ); + indexes[i] = index; + + final JaxbIndexImpl jaxbIndex = jaxbIndexes.get( i ); + index.columnList( jaxbIndex.getColumnList() ); + applyOptionalString( jaxbIndex.getName(), index::name ); + if ( jaxbIndex.isUnique() != null ) { + index.unique( jaxbIndex.isUnique() ); + } + } + return indexes; + } + + + public static void applyPrimaryKeyJoinColumns( JaxbEntityImpl jaxbEntity, MutableClassDetails classDetails, XmlDocumentContext xmlDocumentContext) { - List primaryKeyJoinColumns = jaxbEntity.getPrimaryKeyJoinColumns(); - if ( CollectionHelper.isEmpty( primaryKeyJoinColumns ) ) { + List jaxbColumns = jaxbEntity.getPrimaryKeyJoinColumns(); + if ( CollectionHelper.isEmpty( jaxbColumns ) ) { return; } final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); - final MutableAnnotationUsage primaryKeyJoinColumnsAnnotationUsage = classDetails.replaceAnnotationUsage( + final PrimaryKeyJoinColumnsJpaAnnotation columnsAnn = (PrimaryKeyJoinColumnsJpaAnnotation) classDetails.replaceAnnotationUsage( JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS, modelBuildingContext ); - final ArrayList primaryKeyJoinColumnList = arrayList( primaryKeyJoinColumns.size() ); - primaryKeyJoinColumnsAnnotationUsage.setAttributeValue( "value", primaryKeyJoinColumnList ); - - for ( JaxbPrimaryKeyJoinColumnImpl primaryKeyJoinColumn : primaryKeyJoinColumns ) { - primaryKeyJoinColumnList.add( - JoinColumnProcessing.createPrimaryKeyJoinColumnUsage( primaryKeyJoinColumn, xmlDocumentContext ) - ); + final PrimaryKeyJoinColumn[] columns = new PrimaryKeyJoinColumn[jaxbColumns.size()]; + for ( int i = 0; i < jaxbColumns.size(); i++ ) { + final PrimaryKeyJoinColumnJpaAnnotation column = JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage( modelBuildingContext ); + final JaxbPrimaryKeyJoinColumnImpl jaxbColumn = jaxbColumns.get( i ); + column.apply( jaxbColumn, xmlDocumentContext ); + columns[i] = column; } + columnsAnn.value( columns ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java index b02e629302..179b846a69 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java @@ -7,16 +7,13 @@ package org.hibernate.boot.models.xml.internal; import java.beans.Introspector; -import java.lang.annotation.Annotation; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbManagedType; import org.hibernate.boot.models.MemberResolutionException; -import org.hibernate.boot.models.internal.AnnotationUsageHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.MethodDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; @@ -105,19 +102,4 @@ public class XmlProcessingHelper { return null; } - - - public static void applyAttributeIfSpecified( - String attributeName, - String value, - MutableAnnotationUsage annotationUsage) { - AnnotationUsageHelper.applyStringAttributeIfSpecified( attributeName, value, annotationUsage ); - } - - public static void applyAttributeIfSpecified( - String attributeName, - Object value, - MutableAnnotationUsage annotationUsage) { - AnnotationUsageHelper.applyAttributeIfSpecified( attributeName, value, annotationUsage ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java index fef8b039f0..73a236dae0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java @@ -6,14 +6,9 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import java.util.ArrayList; import java.util.List; -import org.hibernate.annotations.Any; -import org.hibernate.annotations.AnyDiscriminator; import org.hibernate.annotations.AnyDiscriminatorValue; -import org.hibernate.annotations.AnyDiscriminatorValues; -import org.hibernate.boot.internal.AnyKeyType; import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyDiscriminatorValueMappingImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingDiscriminatorImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl; @@ -21,24 +16,32 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingKeyImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.AnyAnnotation; +import org.hibernate.boot.models.annotations.internal.AnyDiscriminatorAnnotation; +import org.hibernate.boot.models.annotations.internal.AnyDiscriminatorValueAnnotation; +import org.hibernate.boot.models.annotations.internal.AnyDiscriminatorValuesAnnotation; +import org.hibernate.boot.models.annotations.internal.AnyKeTypeAnnotation; +import org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.JoinColumnsJpaAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; -import org.hibernate.boot.models.xml.internal.db.ColumnProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.ClassDetailsRegistry; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorType; import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinColumns; +import static org.hibernate.boot.models.HibernateAnnotations.ANY_DISCRIMINATOR_VALUE; +import static org.hibernate.boot.models.JpaAnnotations.JOIN_COLUMN; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.*; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -58,15 +61,19 @@ public class AnyMappingAttributeProcessing { declarer ); - final MutableAnnotationUsage anyAnn = memberDetails.applyAnnotationUsage( + final AnyAnnotation anyAnn = (AnyAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.ANY, xmlDocumentContext.getModelBuildingContext() ); - CommonAttributeProcessing.applyAttributeBasics( jaxbHbmAnyMapping, memberDetails, anyAnn, accessType, xmlDocumentContext ); + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbHbmAnyMapping, memberDetails, xmlDocumentContext ); + applyFetching( jaxbHbmAnyMapping, memberDetails, anyAnn, xmlDocumentContext ); + applyOptionality( jaxbHbmAnyMapping, anyAnn, xmlDocumentContext ); + applyOptimisticLock( jaxbHbmAnyMapping, memberDetails, xmlDocumentContext ); - applyDiscriminator( memberDetails, jaxbHbmAnyMapping, anyAnn, xmlDocumentContext ); - applyKey( memberDetails, jaxbHbmAnyMapping, anyAnn, xmlDocumentContext ); + applyDiscriminator( memberDetails, jaxbHbmAnyMapping, xmlDocumentContext ); + applyKey( memberDetails, jaxbHbmAnyMapping, xmlDocumentContext ); XmlAnnotationHelper.applyCascading( jaxbHbmAnyMapping.getCascade(), memberDetails, xmlDocumentContext ); return memberDetails; @@ -75,10 +82,9 @@ public class AnyMappingAttributeProcessing { private static void applyDiscriminator( MutableMemberDetails memberDetails, JaxbAnyMappingImpl jaxbHbmAnyMapping, - MutableAnnotationUsage anyAnn, XmlDocumentContext xmlDocumentContext) { final JaxbAnyMappingDiscriminatorImpl jaxbDiscriminator = jaxbHbmAnyMapping.getDiscriminator(); - final MutableAnnotationUsage anyDiscriminatorAnn = memberDetails.applyAnnotationUsage( + final AnyDiscriminatorAnnotation anyDiscriminatorAnn = (AnyDiscriminatorAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.ANY_DISCRIMINATOR, xmlDocumentContext.getModelBuildingContext() ); @@ -88,76 +94,88 @@ public class AnyMappingAttributeProcessing { } final DiscriminatorType discriminatorType = jaxbDiscriminator.getType(); - XmlProcessingHelper.applyAttributeIfSpecified( "value", discriminatorType, anyDiscriminatorAnn ); + if ( discriminatorType != null ) { + anyDiscriminatorAnn.value( discriminatorType ); + } final JaxbColumnImpl jaxbColumn = jaxbDiscriminator.getColumn(); - final MutableAnnotationUsage columnAnn = memberDetails.applyAnnotationUsage( + final ColumnJpaAnnotation columnAnn = (ColumnJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.COLUMN, xmlDocumentContext.getModelBuildingContext() ); if ( jaxbColumn != null ) { - ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, columnAnn, xmlDocumentContext ); + columnAnn.apply( jaxbColumn, xmlDocumentContext ); } - final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry(); - final List valueMappings = jaxbDiscriminator.getValueMappings(); - if ( CollectionHelper.isNotEmpty( valueMappings ) ) { - final MutableAnnotationUsage discriminatorValuesUsage = memberDetails.replaceAnnotationUsage( - HibernateAnnotations.ANY_DISCRIMINATOR_VALUE, + final List jaxbValueMappings = jaxbDiscriminator.getValueMappings(); + if ( CollectionHelper.isNotEmpty( jaxbValueMappings ) ) { + final AnyDiscriminatorValuesAnnotation discriminatorValuesUsage = (AnyDiscriminatorValuesAnnotation) memberDetails.replaceAnnotationUsage( + ANY_DISCRIMINATOR_VALUE, HibernateAnnotations.ANY_DISCRIMINATOR_VALUES, xmlDocumentContext.getModelBuildingContext() ); - final List> valueList = CollectionHelper.arrayList( valueMappings.size() ); - discriminatorValuesUsage.setAttributeValue( "value", valueList ); - - valueMappings.forEach( (valueMapping) -> { - final MutableAnnotationUsage discriminatorValueUsage = - HibernateAnnotations.ANY_DISCRIMINATOR_VALUE.createUsage( xmlDocumentContext.getModelBuildingContext() ); - valueList.add( discriminatorValueUsage ); - - discriminatorValueUsage.setAttributeValue( "discriminator", valueMapping.getDiscriminatorValue() ); - - final String name = StringHelper.qualifyConditionally( - xmlDocumentContext.getXmlDocument().getDefaults().getPackage(), - valueMapping.getCorrespondingEntityName() - ); - final ClassDetails entityClassDetails = classDetailsRegistry.resolveClassDetails( name ); - discriminatorValueUsage.setAttributeValue( "entity", entityClassDetails ); - } ); + discriminatorValuesUsage.value( collectDiscriminatorValues( + jaxbValueMappings, + xmlDocumentContext + ) ); } } + private static AnyDiscriminatorValue[] collectDiscriminatorValues( + List jaxbValueMappings, + XmlDocumentContext xmlDocumentContext) { + final AnyDiscriminatorValue[] values = new AnyDiscriminatorValue[jaxbValueMappings.size()]; + for ( int i = 0; i < jaxbValueMappings.size(); i++ ) { + final AnyDiscriminatorValueAnnotation valueAnn = ANY_DISCRIMINATOR_VALUE.createUsage( xmlDocumentContext.getModelBuildingContext() ); + values[i] = valueAnn; + + final JaxbAnyDiscriminatorValueMappingImpl jaxbValue = jaxbValueMappings.get( i ); + + valueAnn.discriminator( jaxbValue.getDiscriminatorValue() ); + + final String name = StringHelper.qualifyConditionally( + xmlDocumentContext.getXmlDocument().getDefaults().getPackage(), + jaxbValue.getCorrespondingEntityName() + ); + final ClassDetails entityClassDetails = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry().resolveClassDetails( name ); + valueAnn.entity( entityClassDetails.toJavaClass() ); + } + return values; + } + private static void applyKey( MutableMemberDetails memberDetails, JaxbAnyMappingImpl jaxbHbmAnyMapping, - MutableAnnotationUsage anyAnn, XmlDocumentContext xmlDocumentContext) { final JaxbAnyMappingKeyImpl jaxbKey = jaxbHbmAnyMapping.getKey(); if ( StringHelper.isNotEmpty( jaxbKey.getType() ) ) { - final MutableAnnotationUsage keyTypeUsage = memberDetails.applyAnnotationUsage( + final AnyKeTypeAnnotation keyTypeUsage = (AnyKeTypeAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.ANY_KEY_TYPE, xmlDocumentContext.getModelBuildingContext() ); - keyTypeUsage.setAttributeValue( "value", jaxbKey.getType() ); + keyTypeUsage.value( jaxbKey.getType() ); } if ( jaxbKey.getColumns().isEmpty() ) { memberDetails.applyAnnotationUsage( JpaAnnotations.JOIN_COLUMN, xmlDocumentContext.getModelBuildingContext() ); } else { - final MutableAnnotationUsage joinColumnsUsage = memberDetails.applyAnnotationUsage( + final JoinColumnsJpaAnnotation joinColumnsUsage = (JoinColumnsJpaAnnotation) memberDetails.replaceAnnotationUsage( + JOIN_COLUMN, JpaAnnotations.JOIN_COLUMNS, xmlDocumentContext.getModelBuildingContext() ); - final ArrayList> columnAnnList = CollectionHelper.arrayList( jaxbKey.getColumns().size() ); - joinColumnsUsage.setAttributeValue( "value", columnAnnList ); - jaxbKey.getColumns().forEach( (jaxbColumn) -> { - final MutableAnnotationUsage joinColumnUsage = - JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); - columnAnnList.add( joinColumnUsage ); - ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, joinColumnUsage, xmlDocumentContext ); - } ); + final JoinColumn[] joinColumns = new JoinColumn[jaxbKey.getColumns().size()]; + joinColumnsUsage.value( joinColumns ); + + for ( int i = 0; i < jaxbKey.getColumns().size(); i++ ) { + final JoinColumnJpaAnnotation joinColumn = JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); + joinColumns[i] = joinColumn; + + final JaxbColumnImpl jaxbJoinColumn = jaxbKey.getColumns().get( i ); + joinColumn.apply( jaxbJoinColumn, xmlDocumentContext ); + } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java index 8102c6ba85..375f270efc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java @@ -6,23 +6,26 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.annotations.Formula; import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.BasicJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.FormulaAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; -import org.hibernate.boot.models.xml.internal.db.ColumnProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.Basic; -import jakarta.persistence.Column; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyFetching; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptimisticLock; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptionality; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -42,26 +45,31 @@ public class BasicAttributeProcessing { declarer ); - final MutableAnnotationUsage basicAnn = memberDetails.applyAnnotationUsage( + final BasicJpaAnnotation basicAnn = (BasicJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.BASIC, xmlDocumentContext.getModelBuildingContext() ); - CommonAttributeProcessing.applyAttributeBasics( jaxbBasic, memberDetails, basicAnn, accessType, xmlDocumentContext ); + + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbBasic, memberDetails, xmlDocumentContext ); + applyFetching( jaxbBasic, memberDetails, basicAnn, xmlDocumentContext ); + applyOptionality( jaxbBasic, basicAnn, xmlDocumentContext ); + applyOptimisticLock( jaxbBasic, memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbBasic.getFormula() ) ) { assert jaxbBasic.getColumn() == null; - final MutableAnnotationUsage formulaAnn = memberDetails.applyAnnotationUsage( + final FormulaAnnotation formulaAnn = (FormulaAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.FORMULA, xmlDocumentContext.getModelBuildingContext() ); - formulaAnn.setAttributeValue( "value", jaxbBasic.getFormula() ); + formulaAnn.value( jaxbBasic.getFormula() ); } else if ( jaxbBasic.getColumn() != null ) { - final MutableAnnotationUsage columnAnn = memberDetails.applyAnnotationUsage( + final ColumnJpaAnnotation columnAnn = (ColumnJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.COLUMN, xmlDocumentContext.getModelBuildingContext() ); - ColumnProcessing.applyColumnDetails( jaxbBasic.getColumn(), memberDetails, columnAnn, xmlDocumentContext ); + columnAnn.apply( jaxbBasic.getColumn(), xmlDocumentContext ); } XmlAnnotationHelper.applyConvert( jaxbBasic.getConvert(), memberDetails, xmlDocumentContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java index a16053af56..5560954a54 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java @@ -8,16 +8,18 @@ package org.hibernate.boot.models.xml.internal.attr; import org.hibernate.boot.jaxb.mapping.spi.JaxbIdImpl; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.BasicJpaAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.Basic; +import jakarta.persistence.FetchType; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -38,9 +40,12 @@ public class BasicIdAttributeProcessing { ); memberDetails.applyAnnotationUsage( JpaAnnotations.ID, xmlDocumentContext.getModelBuildingContext() ); - final MutableAnnotationUsage basicAnn = memberDetails.applyAnnotationUsage( JpaAnnotations.BASIC, xmlDocumentContext.getModelBuildingContext() ); + final BasicJpaAnnotation basicAnn = (BasicJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.BASIC, xmlDocumentContext.getModelBuildingContext() ); + basicAnn.fetch( FetchType.EAGER ); + basicAnn.optional( false ); - CommonAttributeProcessing.applyAttributeBasics( jaxbId, memberDetails, basicAnn, accessType, xmlDocumentContext ); + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbId, memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyColumn( jaxbId.getColumn(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyBasicTypeComposition( jaxbId, memberDetails, xmlDocumentContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java index aec7b1b87e..0746949e6c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java @@ -6,12 +6,8 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import java.lang.annotation.Annotation; - -import org.hibernate.annotations.AttributeAccessor; -import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; -import org.hibernate.annotations.OptimisticLock; +import org.hibernate.annotations.OnDeleteAction; import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbLockableAttribute; import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistentAttribute; @@ -21,15 +17,20 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbStandardAttribute; import org.hibernate.boot.jaxb.mapping.spi.JaxbTransientImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; +import org.hibernate.boot.models.annotations.internal.AccessJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.AttributeAccessorAnnotation; +import org.hibernate.boot.models.annotations.internal.FetchAnnotation; +import org.hibernate.boot.models.annotations.internal.MapsIdJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.OnDeleteAnnotation; +import org.hibernate.boot.models.annotations.internal.OptimisticLockAnnotation; +import org.hibernate.boot.models.annotations.spi.AttributeMarker; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; -import jakarta.persistence.Access; import jakarta.persistence.AccessType; import jakarta.persistence.FetchType; @@ -38,37 +39,18 @@ import jakarta.persistence.FetchType; */ public class CommonAttributeProcessing { - public static void applyAttributeBasics( - JaxbPersistentAttribute jaxbAttribute, - MutableMemberDetails memberDetails, - MutableAnnotationUsage attributeAnn, - AccessType accessType, - XmlDocumentContext xmlDocumentContext) { - applyAccess( accessType, memberDetails, xmlDocumentContext ); - applyAttributeAccessor( jaxbAttribute, memberDetails, xmlDocumentContext ); - - if ( jaxbAttribute instanceof JaxbStandardAttribute jaxbStandardAttribute ) { - applyFetching( jaxbStandardAttribute, memberDetails, attributeAnn, xmlDocumentContext ); - applyOptionality( jaxbStandardAttribute, memberDetails, attributeAnn, xmlDocumentContext ); - } - - if ( jaxbAttribute instanceof JaxbLockableAttribute jaxbLockableAttribute ) { - applyOptimisticLock( jaxbLockableAttribute, memberDetails, xmlDocumentContext ); - } - } - public static void applyAccess( AccessType accessType, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage accessAnn = memberDetails.applyAnnotationUsage( + final AccessJpaAnnotation accessAnn = (AccessJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.ACCESS, xmlDocumentContext.getModelBuildingContext() ); - accessAnn.setAttributeValue( "value", accessType ); + accessAnn.value( accessType ); } - public static void applyAttributeAccessor( + public static void applyAttributeAccessor( JaxbPersistentAttribute jaxbAttribute, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { @@ -77,7 +59,7 @@ public class CommonAttributeProcessing { return; } - final MutableAnnotationUsage accessorAnn = memberDetails.applyAnnotationUsage( + final AttributeAccessorAnnotation accessorAnn = (AttributeAccessorAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.ATTRIBUTE_ACCESSOR, xmlDocumentContext.getModelBuildingContext() ); @@ -86,41 +68,41 @@ public class CommonAttributeProcessing { .getModelBuildingContext() .getClassDetailsRegistry() .getClassDetails( attributeAccessor ); - XmlAnnotationHelper.applyOptionalAttribute( accessorAnn, "strategy", strategyClassDetails ); + accessorAnn.strategy( strategyClassDetails.toJavaClass() ); } - public static void applyOptionality( + public static void applyOptionality( JaxbStandardAttribute jaxbAttribute, - MutableMemberDetails memberDetails, - MutableAnnotationUsage attributeAnn, + AttributeMarker.Optionalable attributeAnn, XmlDocumentContext xmlDocumentContext) { - // todo : fix this in jpa32 if ( jaxbAttribute.isOptional() == null ) { return; } - attributeAnn.setAttributeValue( "optional", jaxbAttribute.isOptional() ); + attributeAnn.optional( jaxbAttribute.isOptional() ); } - public static void applyOptimisticLock( + public static void applyOptimisticLock( JaxbLockableAttribute jaxbAttribute, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { final boolean includeInOptimisticLock = jaxbAttribute.isOptimisticLock(); - final MutableAnnotationUsage optLockAnn = memberDetails.applyAnnotationUsage( + final OptimisticLockAnnotation optLockAnn = (OptimisticLockAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.OPTIMISTIC_LOCK, xmlDocumentContext.getModelBuildingContext() ); - optLockAnn.setAttributeValue( "excluded", !includeInOptimisticLock ); + optLockAnn.excluded( !includeInOptimisticLock ); } - public static void applyFetching( + public static void applyFetching( JaxbStandardAttribute jaxbAttribute, MutableMemberDetails memberDetails, - MutableAnnotationUsage attributeAnn, + AttributeMarker.Fetchable attributeAnn, XmlDocumentContext xmlDocumentContext) { final FetchType fetchType = jaxbAttribute.getFetch(); - XmlProcessingHelper.applyAttributeIfSpecified( "fetch", fetchType, attributeAnn ); + if ( fetchType != null ) { + attributeAnn.fetch( fetchType ); + } if ( jaxbAttribute instanceof JaxbSingularAssociationAttribute jaxbSingularAttribute ) { final JaxbSingularFetchModeImpl jaxbFetchMode = jaxbSingularAttribute.getFetchMode(); @@ -138,11 +120,11 @@ public class CommonAttributeProcessing { XmlDocumentContext xmlDocumentContext) { if ( jaxbFetchMode != null ) { final FetchMode fetchMode = FetchMode.valueOf( jaxbFetchMode.value() ); - final MutableAnnotationUsage fetchAnn = memberDetails.applyAnnotationUsage( + final FetchAnnotation fetchAnn = (FetchAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.FETCH, xmlDocumentContext.getModelBuildingContext() ); - fetchAnn.setAttributeValue( "value", fetchMode ); + fetchAnn.value( fetchMode ); } } @@ -158,4 +140,42 @@ public class CommonAttributeProcessing { ); memberDetails.applyAnnotationUsage( JpaAnnotations.TRANSIENT, xmlDocumentContext.getModelBuildingContext() ); } + + public static void applyMappedBy( + String mappedBy, + AttributeMarker.Mappable mappable, + XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( mappedBy ) ) { + mappable.mappedBy( mappedBy ); + } + } + + public static void applyMapsId( + String mapsId, + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( mapsId ) ) { + final MapsIdJpaAnnotation mapsIdUsage = (MapsIdJpaAnnotation) memberDetails.applyAnnotationUsage( + JpaAnnotations.MAPS_ID, + xmlDocumentContext.getModelBuildingContext() + ); + mapsIdUsage.value( mapsId ); + } + + } + + public static void applyOnDelete( + OnDeleteAction action, + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { + if ( action == null ) { + return; + } + + final OnDeleteAnnotation notFoundAnn = (OnDeleteAnnotation) memberDetails.applyAnnotationUsage( + HibernateAnnotations.ON_DELETE, + xmlDocumentContext.getModelBuildingContext() + ); + notFoundAnn.action( action ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java index 7722a82a94..7cc19f58b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java @@ -6,33 +6,34 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.SortComparator; -import org.hibernate.boot.internal.CollectionClassification; +import org.hibernate.annotations.FetchMode; import org.hibernate.boot.internal.LimitedCollectionClassification; import org.hibernate.boot.jaxb.mapping.spi.JaxbOrderColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbPluralAttribute; +import org.hibernate.boot.jaxb.mapping.spi.JaxbPluralFetchModeImpl; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.CollectionClassificationXmlAnnotation; +import org.hibernate.boot.models.annotations.internal.FetchAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyClassJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyEnumeratedJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyTemporalJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.OrderByJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.OrderColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.SortComparatorAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; -import org.hibernate.boot.models.xml.internal.db.ColumnProcessing; import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableMemberDetails; import org.hibernate.models.spi.SourceModelBuildingContext; -import jakarta.persistence.MapKey; -import jakarta.persistence.MapKeyClass; -import jakarta.persistence.MapKeyEnumerated; -import jakarta.persistence.MapKeyTemporal; -import jakarta.persistence.OrderBy; -import jakarta.persistence.OrderColumn; - /** * @author Marco Belladelli */ @@ -45,11 +46,11 @@ public class CommonPluralAttributeProcessing { final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry(); if ( jaxbPluralAttribute.getFetchMode() != null ) { - final MutableAnnotationUsage fetchAnn = memberDetails.applyAnnotationUsage( + final FetchAnnotation fetchAnn = (FetchAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.FETCH, buildingContext ); - fetchAnn.setAttributeValue( "value", jaxbPluralAttribute.getFetchMode() ); + fetchAnn.value( interpretFetchMode( jaxbPluralAttribute.getFetchMode() ) ); } if ( jaxbPluralAttribute.getClassification() != null ) { @@ -57,11 +58,11 @@ public class CommonPluralAttributeProcessing { memberDetails.applyAnnotationUsage( HibernateAnnotations.BAG, buildingContext ); } else { - final MutableAnnotationUsage collectionClassificationAnn = memberDetails.applyAnnotationUsage( - HibernateAnnotations.COLLECTION_CLASSIFICATION, + final CollectionClassificationXmlAnnotation collectionClassificationAnn = (CollectionClassificationXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.COLLECTION_CLASSIFICATION, buildingContext ); - collectionClassificationAnn.setAttributeValue( "value", jaxbPluralAttribute.getClassification() ); + collectionClassificationAnn.value( jaxbPluralAttribute.getClassification() ); } } @@ -73,22 +74,22 @@ public class CommonPluralAttributeProcessing { XmlAnnotationHelper.applyCollectionId( jaxbPluralAttribute.getCollectionId(), memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbPluralAttribute.getOrderBy() ) ) { - final MutableAnnotationUsage orderByAnn = memberDetails.applyAnnotationUsage( + final OrderByJpaAnnotation orderByAnn = (OrderByJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.ORDER_BY, buildingContext ); - orderByAnn.setAttributeValue( "value", jaxbPluralAttribute.getOrderBy() ); + orderByAnn.value( jaxbPluralAttribute.getOrderBy() ); } applyOrderColumn( jaxbPluralAttribute, memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbPluralAttribute.getSort() ) ) { - final MutableAnnotationUsage sortAnn = memberDetails.applyAnnotationUsage( + final SortComparatorAnnotation sortAnn = (SortComparatorAnnotation) memberDetails.applyAnnotationUsage( HibernateAnnotations.SORT_COMPARATOR, buildingContext ); final ClassDetails comparatorClassDetails = classDetailsRegistry.resolveClassDetails( jaxbPluralAttribute.getSort() ); - sortAnn.setAttributeValue( "value", comparatorClassDetails ); + sortAnn.value( comparatorClassDetails.toJavaClass() ); } if ( jaxbPluralAttribute.getSortNatural() != null ) { @@ -99,46 +100,55 @@ public class CommonPluralAttributeProcessing { // map-key if ( jaxbPluralAttribute.getMapKey() != null ) { - final MutableAnnotationUsage mapKeyAnn = memberDetails.applyAnnotationUsage( + final MapKeyJpaAnnotation mapKeyAnn = (MapKeyJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.MAP_KEY, buildingContext ); - if ( jaxbPluralAttribute.getMapKey() != null ) { - XmlAnnotationHelper.applyOptionalAttribute( mapKeyAnn, "name", jaxbPluralAttribute.getMapKey().getName() ); + if ( jaxbPluralAttribute.getMapKey() != null && StringHelper.isNotEmpty( jaxbPluralAttribute.getMapKey().getName() ) ) { + mapKeyAnn.name( jaxbPluralAttribute.getMapKey().getName() ); } } if ( jaxbPluralAttribute.getMapKeyClass() != null ) { final String className = xmlDocumentContext.resolveClassName( jaxbPluralAttribute.getMapKeyClass().getClazz() ); final ClassDetails mapKeyClass = classDetailsRegistry.resolveClassDetails( className ); - final MutableAnnotationUsage mapKeyClassAnn = memberDetails.applyAnnotationUsage( + final MapKeyClassJpaAnnotation mapKeyClassAnn = (MapKeyClassJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.MAP_KEY_CLASS, buildingContext ); - mapKeyClassAnn.setAttributeValue( "value", mapKeyClass ); + mapKeyClassAnn.value( mapKeyClass.toJavaClass() ); } if ( jaxbPluralAttribute.getMapKeyTemporal() != null ) { - final MutableAnnotationUsage mapKeyTemporalAnn = memberDetails.applyAnnotationUsage( + final MapKeyTemporalJpaAnnotation mapKeyTemporalAnn = (MapKeyTemporalJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.MAP_KEY_TEMPORAL, buildingContext ); - mapKeyTemporalAnn.setAttributeValue( "value", jaxbPluralAttribute.getMapKeyTemporal() ); + mapKeyTemporalAnn.value( jaxbPluralAttribute.getMapKeyTemporal() ); } if ( jaxbPluralAttribute.getMapKeyEnumerated() != null ) { - final MutableAnnotationUsage mapKeyEnumeratedAnn = memberDetails.applyAnnotationUsage( + final MapKeyEnumeratedJpaAnnotation mapKeyEnumeratedAnn = (MapKeyEnumeratedJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.MAP_KEY_ENUMERATED, buildingContext ); - mapKeyEnumeratedAnn.setAttributeValue( "value", jaxbPluralAttribute.getMapKeyEnumerated() ); + mapKeyEnumeratedAnn.value( jaxbPluralAttribute.getMapKeyEnumerated() ); } - jaxbPluralAttribute.getMapKeyConverts().forEach( (jaxbConvert) -> { - XmlAnnotationHelper.applyConvert( jaxbConvert, memberDetails, "key", xmlDocumentContext ); - } ); + XmlAnnotationHelper.applyConverts( + jaxbPluralAttribute.getMapKeyConverts(), + "key", + memberDetails, + xmlDocumentContext + ); - ColumnProcessing.applyMapKeyColumn( jaxbPluralAttribute.getMapKeyColumn(), memberDetails, xmlDocumentContext ); + if ( jaxbPluralAttribute.getMapKeyColumn() != null ) { + final MapKeyColumnJpaAnnotation columnAnn = (MapKeyColumnJpaAnnotation) memberDetails.applyAnnotationUsage( + JpaAnnotations.MAP_KEY_COLUMN, + xmlDocumentContext.getModelBuildingContext() + ); + columnAnn.apply( jaxbPluralAttribute.getMapKeyColumn(), xmlDocumentContext ); + } JoinColumnProcessing.applyMapKeyJoinColumns( jaxbPluralAttribute.getMapKeyJoinColumns(), @@ -153,10 +163,38 @@ public class CommonPluralAttributeProcessing { XmlAnnotationHelper.applyFilters( jaxbPluralAttribute.getFilters(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applySqlRestriction( jaxbPluralAttribute.getSqlRestriction(), memberDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlInsert(), memberDetails, HibernateAnnotations.SQL_INSERT, xmlDocumentContext ); - XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlUpdate(), memberDetails, HibernateAnnotations.SQL_UPDATE, xmlDocumentContext ); - XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlDelete(), memberDetails, HibernateAnnotations.SQL_DELETE, xmlDocumentContext ); - XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlDeleteAll(), memberDetails, HibernateAnnotations.SQL_DELETE_ALL, xmlDocumentContext ); + XmlAnnotationHelper.applyCustomSql( + jaxbPluralAttribute.getSqlInsert(), + memberDetails, + HibernateAnnotations.SQL_INSERT, + xmlDocumentContext + ); + XmlAnnotationHelper.applyCustomSql( + jaxbPluralAttribute.getSqlUpdate(), + memberDetails, + HibernateAnnotations.SQL_UPDATE, + xmlDocumentContext + ); + XmlAnnotationHelper.applyCustomSql( + jaxbPluralAttribute.getSqlDelete(), + memberDetails, + HibernateAnnotations.SQL_DELETE, + xmlDocumentContext + ); + XmlAnnotationHelper.applyCustomSql( + jaxbPluralAttribute.getSqlDeleteAll(), + memberDetails, + HibernateAnnotations.SQL_DELETE_ALL, + xmlDocumentContext + ); + } + + private static FetchMode interpretFetchMode(JaxbPluralFetchModeImpl fetchMode) { + return switch ( fetchMode ) { + case JOIN -> FetchMode.JOIN; + case SELECT -> FetchMode.SELECT; + case SUBSELECT -> FetchMode.SELECT; + }; } private static void applyOrderColumn( @@ -168,16 +206,11 @@ public class CommonPluralAttributeProcessing { return; } - final MutableAnnotationUsage orderColumnAnn = memberDetails.applyAnnotationUsage( + final OrderColumnJpaAnnotation orderColumnAnn = (OrderColumnJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.ORDER_COLUMN, xmlDocumentContext.getModelBuildingContext() ); - XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "name", jaxbOrderColumn.getName() ); - XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "nullable", jaxbOrderColumn.isNullable() ); - XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "insertable", jaxbOrderColumn.isInsertable() ); - XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "updatable", jaxbOrderColumn.isUpdatable() ); - XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "columnDefinition", jaxbOrderColumn.getColumnDefinition() ); - XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "options", jaxbOrderColumn.getOptions() ); + orderColumnAnn.apply( jaxbOrderColumn, xmlDocumentContext ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java index 3b71f93f59..ffbcfa8031 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java @@ -6,25 +6,26 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionTableImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollectionImpl; -import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.CollectionTableJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.ElementCollectionJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; -import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing; -import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; -import org.hibernate.models.spi.AnnotationDescriptor; -import org.hibernate.models.spi.MutableAnnotationUsage; +import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.CollectionTable; -import jakarta.persistence.ElementCollection; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyFetching; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptimisticLock; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -45,25 +46,17 @@ public class ElementCollectionAttributeProcessing { declarer ); - final MutableAnnotationUsage elementCollectionUsage = memberDetails.applyAnnotationUsage( + final ElementCollectionJpaAnnotation elementCollectionUsage = (ElementCollectionJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.ELEMENT_COLLECTION, xmlDocumentContext.getModelBuildingContext() ); - XmlProcessingHelper.applyAttributeIfSpecified( - "fetch", - jaxbElementCollection.getFetch(), - elementCollectionUsage - ); - final String targetClass = jaxbElementCollection.getTargetClass(); - if ( targetClass != null ) { - final MutableAnnotationUsage targetUsage = memberDetails.applyAnnotationUsage( - HibernateAnnotations.TARGET, - xmlDocumentContext.getModelBuildingContext() - ); - targetUsage.setAttributeValue( "value", xmlDocumentContext.resolveClassName( targetClass ) ); + if ( jaxbElementCollection.getFetch() != null ) { + elementCollectionUsage.fetch( jaxbElementCollection.getFetch() ); } + applyTarget( jaxbElementCollection, xmlDocumentContext, memberDetails ); + // NOTE: it is important that this happens before the `CommonPluralAttributeProcessing#applyPluralAttributeStructure` // call below XmlAnnotationHelper.applyConverts( @@ -73,7 +66,10 @@ public class ElementCollectionAttributeProcessing { xmlDocumentContext ); - CommonAttributeProcessing.applyAttributeBasics( jaxbElementCollection, memberDetails, elementCollectionUsage, accessType, xmlDocumentContext ); + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbElementCollection, memberDetails, xmlDocumentContext ); + applyFetching( jaxbElementCollection, memberDetails, elementCollectionUsage, xmlDocumentContext ); + applyOptimisticLock( jaxbElementCollection, memberDetails, xmlDocumentContext ); CommonPluralAttributeProcessing.applyPluralAttributeStructure( jaxbElementCollection, memberDetails, xmlDocumentContext ); @@ -97,6 +93,23 @@ public class ElementCollectionAttributeProcessing { return memberDetails; } + private static void applyTarget( + JaxbElementCollectionImpl jaxbElementCollection, + XmlDocumentContext xmlDocumentContext, + MutableMemberDetails memberDetails) { + // todo (7.0) : we need a distinction here between hbm.xml target and orm.xml target-entity + // - for orm.xml target-entity we should apply the package name, if one + // - for hbm.xml target we should not since it could refer to a dynamic mapping + final String targetClass = jaxbElementCollection.getTargetClass(); + if ( StringHelper.isNotEmpty( targetClass ) ) { + final TargetXmlAnnotation targetUsage = (TargetXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.TARGET, + xmlDocumentContext.getModelBuildingContext() + ); + targetUsage.value( xmlDocumentContext.resolveClassName( targetClass ) ); + } + } + public static void applyCollectionTable( JaxbCollectionTableImpl jaxbCollectionTable, MutableMemberDetails memberDetails, @@ -105,45 +118,11 @@ public class ElementCollectionAttributeProcessing { return; } - final MutableAnnotationUsage collectionTableAnn = memberDetails.applyAnnotationUsage( + final CollectionTableJpaAnnotation collectionTableAnn = (CollectionTableJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.COLLECTION_TABLE, xmlDocumentContext.getModelBuildingContext() ); - final AnnotationDescriptor collectionTableDescriptor = xmlDocumentContext.getModelBuildingContext() - .getAnnotationDescriptorRegistry() - .getDescriptor( CollectionTable.class ); - XmlAnnotationHelper.applyOr( jaxbCollectionTable, JaxbCollectionTableImpl::getName, "name", collectionTableAnn, collectionTableDescriptor ); - XmlAnnotationHelper.applyOrSchema( - jaxbCollectionTable, - collectionTableAnn, - collectionTableDescriptor, - xmlDocumentContext - ); - - XmlAnnotationHelper.applyOrCatalog( - jaxbCollectionTable, - collectionTableAnn, - collectionTableDescriptor, - xmlDocumentContext - ); - XmlAnnotationHelper.applyOr( jaxbCollectionTable, JaxbCollectionTableImpl::getOptions, "options", collectionTableAnn, collectionTableDescriptor ); - - collectionTableAnn.setAttributeValue( "joinColumns", JoinColumnProcessing.transformJoinColumnList( - jaxbCollectionTable.getJoinColumns(), - memberDetails, - xmlDocumentContext - ) ); - - if ( jaxbCollectionTable.getForeignKeys() != null ) { - collectionTableAnn.setAttributeValue( - "foreignKey", - ForeignKeyProcessing.createNestedForeignKeyAnnotation( jaxbCollectionTable.getForeignKeys(), memberDetails, xmlDocumentContext ) - ); - } - - XmlAnnotationHelper.applyUniqueConstraints( jaxbCollectionTable.getUniqueConstraints(), memberDetails, collectionTableAnn, xmlDocumentContext ); - - XmlAnnotationHelper.applyIndexes( jaxbCollectionTable.getIndexes(), memberDetails, collectionTableAnn, xmlDocumentContext ); + collectionTableAnn.apply( jaxbCollectionTable, xmlDocumentContext ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java index e283e88f2d..f372d5c4c4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java @@ -6,23 +6,24 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedImpl; -import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.EmbeddedJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import jakarta.persistence.AccessType; -import jakarta.persistence.Embedded; import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.determineTargetName; -import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeBasics; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptimisticLock; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -41,20 +42,23 @@ public class EmbeddedAttributeProcessing { declarer ); - final MutableAnnotationUsage embeddedAnn = memberDetails.applyAnnotationUsage( + final EmbeddedJpaAnnotation embeddedAnn = (EmbeddedJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.EMBEDDED, xmlDocumentContext.getModelBuildingContext() ); if ( StringHelper.isNotEmpty( jaxbEmbedded.getTarget() ) ) { - final MutableAnnotationUsage targetAnn = memberDetails.applyAnnotationUsage( - HibernateAnnotations.TARGET, + final TargetXmlAnnotation targetAnn = (TargetXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.TARGET, xmlDocumentContext.getModelBuildingContext() ); - targetAnn.setAttributeValue( "value", determineTargetName( jaxbEmbedded.getTarget(), xmlDocumentContext ) ); + targetAnn.value( determineTargetName( jaxbEmbedded.getTarget(), xmlDocumentContext ) ); } - applyAttributeBasics( jaxbEmbedded, memberDetails, embeddedAnn, accessType, xmlDocumentContext ); + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbEmbedded, memberDetails, xmlDocumentContext ); + applyOptimisticLock( jaxbEmbedded, memberDetails, xmlDocumentContext ); + XmlAnnotationHelper.applyAttributeOverrides( jaxbEmbedded.getAttributeOverrides(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyAssociationOverrides( jaxbEmbedded.getAssociationOverrides(), memberDetails, xmlDocumentContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java index b2605ba5c2..000a8837bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java @@ -6,22 +6,23 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedIdImpl; -import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.EmbeddedIdJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.EmbeddedId; import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.determineTargetName; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -41,18 +42,20 @@ public class EmbeddedIdAttributeProcessing { classDetails ); - final MutableAnnotationUsage idAnn = memberDetails.applyAnnotationUsage( + final EmbeddedIdJpaAnnotation idAnn = (EmbeddedIdJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.EMBEDDED_ID, xmlDocumentContext.getModelBuildingContext() ); - CommonAttributeProcessing.applyAttributeBasics( jaxbEmbeddedId, memberDetails, idAnn, accessType, xmlDocumentContext ); + + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbEmbeddedId, memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbEmbeddedId.getTarget() ) ) { - final MutableAnnotationUsage targetAnn = memberDetails.applyAnnotationUsage( - HibernateAnnotations.TARGET, + final TargetXmlAnnotation targetAnn = (TargetXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.TARGET, xmlDocumentContext.getModelBuildingContext() ); - targetAnn.setAttributeValue( "value", determineTargetName( jaxbEmbeddedId.getTarget(), xmlDocumentContext ) ); + targetAnn.value( determineTargetName( jaxbEmbeddedId.getTarget(), xmlDocumentContext ) ); } XmlAnnotationHelper.applyAttributeOverrides( jaxbEmbeddedId.getAttributeOverrides(), memberDetails, xmlDocumentContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java index cd1b0d91c5..ea7ddcfda8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java @@ -8,18 +8,23 @@ package org.hibernate.boot.models.xml.internal.attr; import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToManyImpl; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.ManyToManyJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.ManyToMany; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyFetching; +import static org.hibernate.boot.models.xml.internal.attr.CommonPluralAttributeProcessing.applyPluralAttributeStructure; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -40,18 +45,21 @@ public class ManyToManyAttributeProcessing { declarer ); - final MutableAnnotationUsage manyToManyAnn = applyManyToMany( + final ManyToManyJpaAnnotation manyToManyAnn = applyManyToMany( jaxbManyToMany, memberDetails, xmlDocumentContext ); - applyTargetEntity( jaxbManyToMany, manyToManyAnn, xmlDocumentContext ); + applyTarget( jaxbManyToMany, xmlDocumentContext, memberDetails ); XmlAnnotationHelper.applyCascading( jaxbManyToMany.getCascade(), memberDetails, xmlDocumentContext ); - CommonAttributeProcessing.applyAttributeBasics( jaxbManyToMany, memberDetails, manyToManyAnn, accessType, xmlDocumentContext ); - CommonPluralAttributeProcessing.applyPluralAttributeStructure( jaxbManyToMany, memberDetails, xmlDocumentContext ); + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbManyToMany, memberDetails, xmlDocumentContext ); + applyFetching( jaxbManyToMany, memberDetails, manyToManyAnn, xmlDocumentContext ); + + applyPluralAttributeStructure( jaxbManyToMany, memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyAttributeOverrides( jaxbManyToMany.getMapKeyAttributeOverrides(), @@ -71,35 +79,36 @@ public class ManyToManyAttributeProcessing { return memberDetails; } - private static MutableAnnotationUsage applyManyToMany( + private static void applyTarget( + JaxbManyToManyImpl jaxbManyToMany, + XmlDocumentContext xmlDocumentContext, + MutableMemberDetails memberDetails) { + // todo (7.0) : we need a distinction here between hbm.xml target and orm.xml target-entity + // - for orm.xml target-entity we should apply the package name, if one + // - for hbm.xml target we should not since it could refer to a dynamic mapping + if ( StringHelper.isEmpty( jaxbManyToMany.getTargetEntity() ) ) { + return; + } + final TargetXmlAnnotation targetAnn = (TargetXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.TARGET, + xmlDocumentContext.getModelBuildingContext() + ); + targetAnn.value( xmlDocumentContext.resolveClassName( jaxbManyToMany.getTargetEntity() ) ); + } + + private static ManyToManyJpaAnnotation applyManyToMany( JaxbManyToManyImpl jaxbManyToMany, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage manyToManyAnn = memberDetails.applyAnnotationUsage( + final ManyToManyJpaAnnotation manyToManyAnn = (ManyToManyJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.MANY_TO_MANY, xmlDocumentContext.getModelBuildingContext() ); - if ( jaxbManyToMany != null ) { - XmlAnnotationHelper.applyOptionalAttribute( manyToManyAnn, "fetch", jaxbManyToMany.getFetch() ); - XmlAnnotationHelper.applyOptionalAttribute( manyToManyAnn, "mappedBy", jaxbManyToMany.getMappedBy() ); - } + CommonAttributeProcessing.applyFetching( jaxbManyToMany, memberDetails, manyToManyAnn, xmlDocumentContext ); + CommonAttributeProcessing.applyMappedBy( jaxbManyToMany.getMappedBy(), manyToManyAnn, xmlDocumentContext ); return manyToManyAnn; } - private static void applyTargetEntity( - JaxbManyToManyImpl jaxbManyToMany, - MutableAnnotationUsage manyToManyAnn, - XmlDocumentContext xmlDocumentContext) { - final String targetEntity = jaxbManyToMany.getTargetEntity(); - if ( StringHelper.isNotEmpty( targetEntity ) ) { - manyToManyAnn.setAttributeValue( - "targetEntity", - xmlDocumentContext.getModelBuildingContext() - .getClassDetailsRegistry() - .resolveClassDetails( xmlDocumentContext.resolveClassName( targetEntity ) ) - ); - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java index 12215d968c..f9747572e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java @@ -6,30 +6,28 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.annotations.NotFound; -import org.hibernate.annotations.NotFoundAction; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; -import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToOneImpl; -import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.ManyToOneJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.MapsId; import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyNotFound; -import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.determineTargetName; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyFetching; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptimisticLock; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptionality; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -49,13 +47,19 @@ public class ManyToOneAttributeProcessing { declarer ); - final MutableAnnotationUsage manyToOneAnn = applyManyToOne( + final ManyToOneJpaAnnotation manyToOneAnn = applyManyToOne( memberDetails, jaxbManyToOne, xmlDocumentContext ); - CommonAttributeProcessing.applyAttributeBasics( jaxbManyToOne, memberDetails, manyToOneAnn, accessType, xmlDocumentContext ); + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbManyToOne, memberDetails, xmlDocumentContext ); + applyFetching( jaxbManyToOne, memberDetails, manyToOneAnn, xmlDocumentContext ); + applyOptionality( jaxbManyToOne, manyToOneAnn, xmlDocumentContext ); + applyOptimisticLock( jaxbManyToOne, memberDetails, xmlDocumentContext ); + + // todo (7.0) : cascades? TableProcessing.transformJoinTable( jaxbManyToOne.getJoinTable(), memberDetails, xmlDocumentContext ); JoinColumnProcessing.applyJoinColumns( jaxbManyToOne.getJoinColumns(), memberDetails, xmlDocumentContext ); @@ -68,28 +72,20 @@ public class ManyToOneAttributeProcessing { return memberDetails; } - private static MutableAnnotationUsage applyManyToOne( + private static ManyToOneJpaAnnotation applyManyToOne( MutableMemberDetails memberDetails, JaxbManyToOneImpl jaxbManyToOne, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage manyToOneUsage = memberDetails.applyAnnotationUsage( + final ManyToOneJpaAnnotation manyToOneUsage = (ManyToOneJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.MANY_TO_ONE, xmlDocumentContext.getModelBuildingContext() ); - XmlAnnotationHelper.applyOptionalAttribute( manyToOneUsage, "fetch", jaxbManyToOne.getFetch() ); - if ( jaxbManyToOne.isId() == Boolean.TRUE ) { memberDetails.applyAnnotationUsage( JpaAnnotations.ID, xmlDocumentContext.getModelBuildingContext() ); } - if ( StringHelper.isNotEmpty( jaxbManyToOne.getMapsId() ) ) { - final MutableAnnotationUsage mapsIdUsage = memberDetails.applyAnnotationUsage( - JpaAnnotations.MAPS_ID, - xmlDocumentContext.getModelBuildingContext() - ); - mapsIdUsage.setAttributeValue( "value", jaxbManyToOne.getMapsId() ); - } + CommonAttributeProcessing.applyMapsId( jaxbManyToOne.getMapsId(), memberDetails, xmlDocumentContext ); return manyToOneUsage; } @@ -98,35 +94,29 @@ public class ManyToOneAttributeProcessing { private static void applyOnDelete( MutableMemberDetails memberDetails, JaxbManyToOneImpl jaxbManyToOne, - MutableAnnotationUsage manyToOneAnn, + ManyToOneJpaAnnotation manyToOneAnn, XmlDocumentContext xmlDocumentContext) { - final OnDeleteAction action = jaxbManyToOne.getOnDelete(); - if ( action == null ) { - return; - } - - final MutableAnnotationUsage notFoundAnn = memberDetails.applyAnnotationUsage( - HibernateAnnotations.ON_DELETE, - xmlDocumentContext.getModelBuildingContext() - ); - notFoundAnn.setAttributeValue( "action", action ); + CommonAttributeProcessing.applyOnDelete( jaxbManyToOne.getOnDelete(), memberDetails, xmlDocumentContext ); } @SuppressWarnings("unused") private static void applyTarget( MutableMemberDetails memberDetails, JaxbManyToOneImpl jaxbManyToOne, - MutableAnnotationUsage manyToOneAnn, + ManyToOneJpaAnnotation manyToOneAnn, XmlDocumentContext xmlDocumentContext) { + // todo (7.0) : we need a distinction here between hbm.xml target and orm.xml target-entity + // - for orm.xml target-entity we should apply the package name, if one + // - for hbm.xml target we should not since it could refer to a dynamic mapping final String targetEntityName = jaxbManyToOne.getTargetEntity(); if ( StringHelper.isEmpty( targetEntityName ) ) { return; } - final MutableAnnotationUsage targetAnn = memberDetails.applyAnnotationUsage( - HibernateAnnotations.TARGET, + final TargetXmlAnnotation targetAnn = (TargetXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.TARGET, xmlDocumentContext.getModelBuildingContext() ); - targetAnn.setAttributeValue( "value", determineTargetName( targetEntityName, xmlDocumentContext ) ); + targetAnn.value( xmlDocumentContext.resolveClassName( targetEntityName ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java index c26243232b..074b021b4c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java @@ -6,25 +6,27 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.annotations.NotFound; -import org.hibernate.annotations.NotFoundAction; -import org.hibernate.annotations.OnDelete; import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToManyImpl; -import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.OneToManyJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.MutableAnnotationUsage; +import org.hibernate.models.spi.MutableAnnotationTarget; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.OneToMany; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyFetching; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptimisticLock; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -43,15 +45,15 @@ public class OneToManyAttributeProcessing { declarer ); - final MutableAnnotationUsage oneToManyAnn = applyOneToMany( + final OneToManyJpaAnnotation oneToManyAnn = applyOneToMany( jaxbOneToMany, memberDetails, + accessType, xmlDocumentContext ); - applyTargetEntity( jaxbOneToMany, oneToManyAnn, xmlDocumentContext ); + applyTargetEntity( jaxbOneToMany, memberDetails, xmlDocumentContext ); - CommonAttributeProcessing.applyAttributeBasics( jaxbOneToMany, memberDetails, oneToManyAnn, accessType, xmlDocumentContext ); CommonPluralAttributeProcessing.applyPluralAttributeStructure( jaxbOneToMany, memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyCascading( jaxbOneToMany.getCascade(), memberDetails, xmlDocumentContext ); @@ -76,32 +78,36 @@ public class OneToManyAttributeProcessing { JoinColumnProcessing.applyJoinColumns( jaxbOneToMany.getJoinColumn(), memberDetails, xmlDocumentContext ); - if ( jaxbOneToMany.getOnDelete() != null ) { - final MutableAnnotationUsage onDeleteAnn = memberDetails.applyAnnotationUsage( - HibernateAnnotations.ON_DELETE, - xmlDocumentContext.getModelBuildingContext() - ); - onDeleteAnn.setAttributeValue( "action", jaxbOneToMany.getOnDelete() ); - } + CommonAttributeProcessing.applyOnDelete( jaxbOneToMany.getOnDelete(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyNotFound( jaxbOneToMany, memberDetails, xmlDocumentContext ); return memberDetails; } - private static MutableAnnotationUsage applyOneToMany( + private static OneToManyJpaAnnotation applyOneToMany( JaxbOneToManyImpl jaxbOneToMany, MutableMemberDetails memberDetails, + AccessType accessType, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage oneToManyAnn = memberDetails.applyAnnotationUsage( + final OneToManyJpaAnnotation oneToManyAnn = (OneToManyJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.ONE_TO_MANY, xmlDocumentContext.getModelBuildingContext() ); if ( jaxbOneToMany != null ) { - XmlAnnotationHelper.applyOptionalAttribute( oneToManyAnn, "fetch", jaxbOneToMany.getFetch() ); - XmlAnnotationHelper.applyOptionalAttribute( oneToManyAnn, "mappedBy", jaxbOneToMany.getMappedBy() ); - XmlAnnotationHelper.applyOptionalAttribute( oneToManyAnn, "orphanRemoval", jaxbOneToMany.isOrphanRemoval() ); + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbOneToMany, memberDetails, xmlDocumentContext ); + applyFetching( jaxbOneToMany, memberDetails, oneToManyAnn, xmlDocumentContext ); + applyOptimisticLock( jaxbOneToMany, memberDetails, xmlDocumentContext ); + + if ( StringHelper.isNotEmpty( jaxbOneToMany.getMappedBy() ) ) { + oneToManyAnn.mappedBy( jaxbOneToMany.getMappedBy() ); + } + + if ( jaxbOneToMany.isOrphanRemoval() != null ) { + oneToManyAnn.orphanRemoval( jaxbOneToMany.isOrphanRemoval() ); + } } return oneToManyAnn; @@ -109,14 +115,19 @@ public class OneToManyAttributeProcessing { private static void applyTargetEntity( JaxbOneToManyImpl jaxbOneToMany, - MutableAnnotationUsage oneToManyAnn, + MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - final String targetEntity = jaxbOneToMany.getTargetEntity(); - if ( StringHelper.isNotEmpty( targetEntity ) ) { - oneToManyAnn.setAttributeValue( - "targetEntity", - xmlDocumentContext.resolveJavaType( targetEntity ) - ); + // todo (7.0) : we need a distinction here between hbm.xml target and orm.xml target-entity + // - for orm.xml target-entity we should apply the package name, if one + // - for hbm.xml target we should not since it could refer to a dynamic mapping + final String targetEntityName = jaxbOneToMany.getTargetEntity(); + if ( StringHelper.isEmpty( targetEntityName ) ) { + return; } + final TargetXmlAnnotation annotation = (TargetXmlAnnotation) target.applyAnnotationUsage( + XmlAnnotations.TARGET, + xmlDocumentContext.getModelBuildingContext() + ); + annotation.value( xmlDocumentContext.resolveClassName( targetEntityName ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java index 14d4ec759d..2705953ba1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToOneAttributeProcessing.java @@ -6,26 +6,27 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToOneImpl; -import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.XmlAnnotations; +import org.hibernate.boot.models.annotations.internal.OneToOneJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.TargetXmlAnnotation; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.AccessType; -import jakarta.persistence.MapsId; -import jakarta.persistence.OneToOne; import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyCascading; -import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.determineTargetName; -import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeBasics; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAccess; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyAttributeAccessor; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyFetching; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptimisticLock; +import static org.hibernate.boot.models.xml.internal.attr.CommonAttributeProcessing.applyOptionality; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -46,13 +47,14 @@ public class OneToOneAttributeProcessing { declarer ); - final MutableAnnotationUsage oneToOneAnn = applyOneToOne( + final OneToOneJpaAnnotation oneToOneAnn = applyOneToOne( memberDetails, + accessType, jaxbOneToOne, xmlDocumentContext ); - applyAttributeBasics( jaxbOneToOne, memberDetails, oneToOneAnn, accessType, xmlDocumentContext ); + applyMappedBy( memberDetails, jaxbOneToOne, oneToOneAnn, xmlDocumentContext ); applyTarget( memberDetails, jaxbOneToOne, oneToOneAnn, xmlDocumentContext ); applyCascading( jaxbOneToOne.getCascade(), memberDetails, xmlDocumentContext ); @@ -67,54 +69,62 @@ public class OneToOneAttributeProcessing { ); } - if ( StringHelper.isNotEmpty( jaxbOneToOne.getMapsId() ) ) { - final MutableAnnotationUsage mapsIdAnn = memberDetails.applyAnnotationUsage( - JpaAnnotations.MAPS_ID, - xmlDocumentContext.getModelBuildingContext() - ); - mapsIdAnn.setAttributeValue( "value", jaxbOneToOne.getMapsId() ); - } + CommonAttributeProcessing.applyMapsId( jaxbOneToOne.getMapsId(), memberDetails, xmlDocumentContext ); return memberDetails; } - private static MutableAnnotationUsage applyOneToOne( + private static OneToOneJpaAnnotation applyOneToOne( MutableMemberDetails memberDetails, + AccessType accessType, JaxbOneToOneImpl jaxbOneToOne, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage usage = memberDetails.applyAnnotationUsage( JpaAnnotations.ONE_TO_ONE, xmlDocumentContext.getModelBuildingContext() ); - if ( jaxbOneToOne.getFetch() != null ) { - usage.setAttributeValue( "fetch", jaxbOneToOne.getFetch() ); - } - if ( jaxbOneToOne.isOptional() != null ) { - usage.setAttributeValue( "optional", jaxbOneToOne.isOptional() ); - } - if ( StringHelper.isNotEmpty( jaxbOneToOne.getMappedBy() ) ) { - usage.setAttributeValue( "mappedBy", jaxbOneToOne.getMappedBy() ); - } + final OneToOneJpaAnnotation annotation = (OneToOneJpaAnnotation) memberDetails.applyAnnotationUsage( + JpaAnnotations.ONE_TO_ONE, + xmlDocumentContext.getModelBuildingContext() + ); + + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbOneToOne, memberDetails, xmlDocumentContext ); + applyFetching( jaxbOneToOne, memberDetails, annotation, xmlDocumentContext ); + applyOptionality( jaxbOneToOne, annotation, xmlDocumentContext ); + applyOptimisticLock( jaxbOneToOne, memberDetails, xmlDocumentContext ); + if ( jaxbOneToOne.isOrphanRemoval() != null ) { - usage.setAttributeValue( "orphanRemoval", jaxbOneToOne.isOrphanRemoval() ); + annotation.orphanRemoval( jaxbOneToOne.isOrphanRemoval() ); + } + + return annotation; + } + + private static void applyMappedBy( + MutableMemberDetails memberDetails, + JaxbOneToOneImpl jaxbOneToOne, + OneToOneJpaAnnotation oneToOneAnn, + XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbOneToOne.getMappedBy() ) ) { + oneToOneAnn.mappedBy( jaxbOneToOne.getMappedBy() ); } - return usage; } - @SuppressWarnings("unused") private static void applyTarget( MutableMemberDetails memberDetails, JaxbOneToOneImpl jaxbOneToOne, - MutableAnnotationUsage oneToOneAnn, + OneToOneJpaAnnotation oneToOneAnn, XmlDocumentContext xmlDocumentContext) { + // todo (7.0) : we need a distinction here between hbm.xml target and orm.xml target-entity + // - for orm.xml target-entity we should apply the package name, if one + // - for hbm.xml target we should not since it could refer to a dynamic mapping final String targetEntityName = jaxbOneToOne.getTargetEntity(); if ( StringHelper.isEmpty( targetEntityName ) ) { return; } - final MutableAnnotationUsage targetUsage = memberDetails.applyAnnotationUsage( - HibernateAnnotations.TARGET, + final TargetXmlAnnotation annotation = (TargetXmlAnnotation) memberDetails.applyAnnotationUsage( + XmlAnnotations.TARGET, xmlDocumentContext.getModelBuildingContext() ); - final String targetName = determineTargetName( targetEntityName, xmlDocumentContext ); - targetUsage.setAttributeValue( "value", targetName ); + annotation.value( xmlDocumentContext.resolveClassName( targetEntityName ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ColumnProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ColumnProcessing.java deleted file mode 100644 index ff0b021eef..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ColumnProcessing.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.xml.internal.db; - -import java.lang.annotation.Annotation; - -import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyColumnImpl; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCheckable; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumn; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnCommon; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnDefinable; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnMutable; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnNullable; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnSizable; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnStandard; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnUniqueable; -import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCommentable; -import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.internal.AnnotationUsageHelper; -import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; -import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; -import org.hibernate.boot.models.xml.spi.XmlDocumentContext; -import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.MutableAnnotationUsage; -import org.hibernate.models.spi.MutableMemberDetails; - -import jakarta.persistence.MapKeyColumn; - -/** - * @author Steve Ebersole - */ -public class ColumnProcessing { - - public static void applyColumnDetails( - JaxbColumnCommon jaxbColumn, - AnnotationTarget target, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbColumn == null ) { - return; - } - - applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnNullness( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnMutability( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnDefinition( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext ); - XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, target, columnAnn, xmlDocumentContext ); - - if ( jaxbColumn instanceof JaxbColumnSizable sizable ) { - applyColumnSizing( sizable, columnAnn, xmlDocumentContext ); - } - - } - - public static void applyColumnDetails( - JaxbColumnCommon jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbColumn == null ) { - return; - } - - applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnNullness( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnMutability( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnDefinition( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext ); - XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, null, columnAnn, xmlDocumentContext ); - - if ( jaxbColumn instanceof JaxbColumnSizable sizable ) { - applyColumnSizing( sizable, columnAnn, xmlDocumentContext ); - } - } - - public static void applyColumnDetails( - JaxbColumnStandard jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbColumn == null ) { - return; - } - - applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnNullness( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnMutability( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnDefinition( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnSizing( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext ); - applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext ); - XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, null, columnAnn, xmlDocumentContext ); - } - - public static void applyColumnDetails( - JaxbColumn jaxbColumn, - AnnotationTarget target, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbColumn == null ) { - return; - } - - applyColumnBasics( jaxbColumn, columnAnn, xmlDocumentContext ); - - if ( jaxbColumn instanceof JaxbColumnNullable nullable ) { - applyColumnNullness( nullable, columnAnn, xmlDocumentContext ); - } - - if ( jaxbColumn instanceof JaxbColumnMutable mutable ) { - applyColumnMutability( mutable, columnAnn, xmlDocumentContext ); - } - - if ( jaxbColumn instanceof JaxbColumnDefinable definable ) { - applyColumnDefinition( definable, columnAnn, xmlDocumentContext ); - } - - if ( jaxbColumn instanceof JaxbColumnSizable sizable ) { - applyColumnSizing( sizable, columnAnn, xmlDocumentContext ); - } - - if ( jaxbColumn instanceof JaxbColumnUniqueable uniqueable ) { - applyColumnUniqueness( uniqueable, columnAnn, xmlDocumentContext ); - } - - if ( jaxbColumn instanceof JaxbCommentable commentable ) { - applyColumnComment( commentable, columnAnn, xmlDocumentContext ); - } - - if ( jaxbColumn instanceof JaxbCheckable checkable ) { - XmlAnnotationHelper.applyCheckConstraints( checkable, target, columnAnn, xmlDocumentContext ); - } - } - - private static void applyColumnBasics( - JaxbColumn jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", jaxbColumn.getName(), columnAnn ); - - AnnotationUsageHelper.applyStringAttributeIfSpecified( "table", jaxbColumn.getTable(), columnAnn ); - } - - private static void applyColumnNullness( - JaxbColumnNullable jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.applyAttributeIfSpecified( "nullable", jaxbColumn.isNullable(), columnAnn ); - } - - private static void applyColumnMutability( - JaxbColumnMutable jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.applyAttributeIfSpecified( "insertable", jaxbColumn.isInsertable(), columnAnn ); - - XmlProcessingHelper.applyAttributeIfSpecified( "updatable", jaxbColumn.isUpdatable(), columnAnn ); - } - - private static void applyColumnSizing( - JaxbColumnSizable jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.applyAttributeIfSpecified( "length", jaxbColumn.getLength(), columnAnn ); - - XmlProcessingHelper.applyAttributeIfSpecified( "precision", jaxbColumn.getPrecision(), columnAnn ); - - XmlProcessingHelper.applyAttributeIfSpecified( "scale", jaxbColumn.getScale(), columnAnn ); - - XmlProcessingHelper.applyAttributeIfSpecified( "secondPrecision", jaxbColumn.getSecondPrecision(), columnAnn ); - } - - private static void applyColumnUniqueness( - JaxbColumnUniqueable jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.applyAttributeIfSpecified( "unique", jaxbColumn.isUnique(), columnAnn ); - } - - private static void applyColumnDefinition( - JaxbColumnDefinable jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.applyAttributeIfSpecified( - "columnDefinition", - jaxbColumn.getColumnDefinition(), - columnAnn - ); - - XmlProcessingHelper.applyAttributeIfSpecified( "options", jaxbColumn.getOptions(), columnAnn ); - } - - private static void applyColumnComment( - JaxbCommentable jaxbColumn, - MutableAnnotationUsage columnAnn, - XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.applyAttributeIfSpecified( "comment", jaxbColumn.getComment(), columnAnn ); - } - - public static void applyMapKeyColumn( - JaxbMapKeyColumnImpl jaxbMapKeyColumn, - MutableMemberDetails memberDetails, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbMapKeyColumn == null ) { - return; - } - - final MutableAnnotationUsage columnAnn = memberDetails.applyAnnotationUsage( - JpaAnnotations.MAP_KEY_COLUMN, - xmlDocumentContext.getModelBuildingContext() - ); - applyColumnDetails( jaxbMapKeyColumn, memberDetails, columnAnn, xmlDocumentContext ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ForeignKeyProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ForeignKeyProcessing.java index 2f085980c5..a69c165bf7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ForeignKeyProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ForeignKeyProcessing.java @@ -6,14 +6,11 @@ */ package org.hibernate.boot.models.xml.internal.db; -import java.lang.annotation.Annotation; - import org.hibernate.boot.jaxb.mapping.spi.JaxbForeignKeyImpl; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; +import org.hibernate.boot.models.annotations.internal.ForeignKeyJpaAnnotation; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; -import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.MutableAnnotationUsage; +import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.ForeignKey; @@ -34,85 +31,50 @@ public class ForeignKeyProcessing { createForeignKeyAnnotation( jaxbForeignKey, memberDetails, xmlDocumentContext ); } - public static MutableAnnotationUsage createForeignKeyAnnotation( + public static ForeignKey createForeignKeyAnnotation( JaxbForeignKeyImpl jaxbForeignKey, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { if ( jaxbForeignKey == null ) { return null; } - final MutableAnnotationUsage foreignKeyUsage = memberDetails.applyAnnotationUsage( + final ForeignKeyJpaAnnotation foreignKeyUsage = (ForeignKeyJpaAnnotation) memberDetails.applyAnnotationUsage( JpaAnnotations.FOREIGN_KEY, xmlDocumentContext.getModelBuildingContext() ); - - XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() ); - XmlAnnotationHelper.applyOptionalAttribute( - foreignKeyUsage, - "value", - jaxbForeignKey.getConstraintMode() - ); - XmlAnnotationHelper.applyOptionalAttribute( - foreignKeyUsage, - "foreignKeyDefinition", - jaxbForeignKey.getForeignKeyDefinition() - ); - XmlAnnotationHelper.applyOptionalAttribute( - foreignKeyUsage, - "options", - jaxbForeignKey.getOptions() - ); - + transferFkDetails( jaxbForeignKey, foreignKeyUsage, xmlDocumentContext ); return foreignKeyUsage; } - public static MutableAnnotationUsage createNestedForeignKeyAnnotation( + private static void transferFkDetails( JaxbForeignKeyImpl jaxbForeignKey, - AnnotationTarget annotationTarget, + ForeignKeyJpaAnnotation foreignKeyUsage, XmlDocumentContext xmlDocumentContext) { - assert jaxbForeignKey != null; - - final MutableAnnotationUsage foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage( xmlDocumentContext.getModelBuildingContext() ); - - XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() ); - XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "value", jaxbForeignKey.getConstraintMode() ); - XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "foreignKeyDefinition", jaxbForeignKey.getForeignKeyDefinition() ); - XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "options", jaxbForeignKey.getOptions() ); - - return foreignKeyUsage; - } - - public static void applyForeignKey( - JaxbForeignKeyImpl jaxbForeignKey, - MutableAnnotationUsage tableAnn, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbForeignKey == null ) { - return; + if ( StringHelper.isNotEmpty( jaxbForeignKey.getName() ) ) { + foreignKeyUsage.name( jaxbForeignKey.getName() ); } - final MutableAnnotationUsage foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage( - xmlDocumentContext.getModelBuildingContext() - ); - XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() ); - XmlAnnotationHelper.applyOptionalAttribute( - foreignKeyUsage, - "value", - jaxbForeignKey.getConstraintMode() - ); - XmlAnnotationHelper.applyOptionalAttribute( - foreignKeyUsage, - "foreignKeyDefinition", - jaxbForeignKey.getForeignKeyDefinition() - ); - XmlAnnotationHelper.applyOptionalAttribute( - foreignKeyUsage, - "options", - jaxbForeignKey.getOptions() - ); + if ( jaxbForeignKey.getConstraintMode() != null ) { + foreignKeyUsage.value( jaxbForeignKey.getConstraintMode() ); + } - tableAnn.setAttributeValue( - "foreignkey", - foreignKeyUsage - );; + if ( StringHelper.isNotEmpty( jaxbForeignKey.getForeignKeyDefinition() ) ) { + foreignKeyUsage.foreignKeyDefinition( jaxbForeignKey.getForeignKeyDefinition() ); + } + if ( StringHelper.isNotEmpty( jaxbForeignKey.getOptions() ) ) { + foreignKeyUsage.options( jaxbForeignKey.getOptions() ); + } } + + public static ForeignKeyJpaAnnotation createNestedForeignKeyAnnotation( + JaxbForeignKeyImpl jaxbForeignKey, + XmlDocumentContext xmlDocumentContext) { + final ForeignKeyJpaAnnotation foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage( xmlDocumentContext.getModelBuildingContext() ); + if ( jaxbForeignKey != null ) { + transferFkDetails( jaxbForeignKey, foreignKeyUsage, xmlDocumentContext ); + } + + return foreignKeyUsage; + } + } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java index c3d04f9a14..a40fb946fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java @@ -6,31 +6,25 @@ */ package org.hibernate.boot.models.xml.internal.db; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import org.hibernate.boot.jaxb.mapping.spi.JaxbForeignKeyImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyJoinColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnJoined; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; +import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.JoinColumnsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyJoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.MapKeyJoinColumnsJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PrimaryKeyJoinColumnJpaAnnotation; +import org.hibernate.boot.models.annotations.internal.PrimaryKeyJoinColumnsJpaAnnotation; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableMemberDetails; -import jakarta.persistence.CollectionTable; import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinColumns; -import jakarta.persistence.JoinTable; import jakarta.persistence.MapKeyJoinColumn; -import jakarta.persistence.MapKeyJoinColumns; import jakarta.persistence.PrimaryKeyJoinColumn; import jakarta.persistence.PrimaryKeyJoinColumns; @@ -45,27 +39,41 @@ import jakarta.persistence.PrimaryKeyJoinColumns; */ public class JoinColumnProcessing { - public static void applyMapKeyJoinColumns( - List jaxbJoinColumns, + public static void applyJoinColumns( + List jaxbJoinColumns, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbJoinColumns ) ) { return; } - final MutableAnnotationUsage joinColumnsUsage = memberDetails.replaceAnnotationUsage( - JpaAnnotations.MAP_KEY_JOIN_COLUMN, - JpaAnnotations.MAP_KEY_JOIN_COLUMNS, + final JoinColumnsJpaAnnotation columnsAnn = (JoinColumnsJpaAnnotation) memberDetails.replaceAnnotationUsage( + JpaAnnotations.JOIN_COLUMN, + JpaAnnotations.JOIN_COLUMNS, xmlDocumentContext.getModelBuildingContext() ); - final ArrayList> joinColumnUsages = CollectionHelper.arrayList( jaxbJoinColumns.size() ); - joinColumnsUsage.setAttributeValue( "value", joinColumnUsages ); - jaxbJoinColumns.forEach( (jaxbJoinColumn) -> { - final MutableAnnotationUsage joinColumnUsage = - JpaAnnotations.MAP_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); - joinColumnUsages.add( joinColumnUsage ); - transferJoinColumn( jaxbJoinColumn, joinColumnUsage, memberDetails, xmlDocumentContext ); - } ); + columnsAnn.value( transformJoinColumnList( + jaxbJoinColumns, + xmlDocumentContext + ) ); + } + + private static final JoinColumn[] NO_JOIN_COLUMNS = new JoinColumn[0]; + + public static JoinColumn[] transformJoinColumnList( + List jaxbJoinColumns, + XmlDocumentContext xmlDocumentContext) { + if ( CollectionHelper.isEmpty( jaxbJoinColumns ) ) { + return NO_JOIN_COLUMNS; + } + + final JoinColumn[] joinColumns = new JoinColumn[jaxbJoinColumns.size()]; + for ( int i = 0; i < jaxbJoinColumns.size(); i++ ) { + final JoinColumnJpaAnnotation joinColumn = JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); + joinColumns[i] = joinColumn; + joinColumn.apply( jaxbJoinColumns.get( i ), xmlDocumentContext ); + } + return joinColumns; } /** @@ -81,154 +89,66 @@ public class JoinColumnProcessing { return; } - final MutableAnnotationUsage columnsUsage = memberDetails.replaceAnnotationUsage( + final PrimaryKeyJoinColumnsJpaAnnotation columnsUsage = (PrimaryKeyJoinColumnsJpaAnnotation) memberDetails.replaceAnnotationUsage( JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS, xmlDocumentContext.getModelBuildingContext() ); - final List> columnUsages = CollectionHelper.arrayList( jaxbJoinColumns.size() ); - columnsUsage.setAttributeValue( "value", columnUsages ); - jaxbJoinColumns.forEach( (jaxbJoinColumn) -> { - final MutableAnnotationUsage columnUsage = - JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); - columnUsages.add( columnUsage ); - - transferJoinColumn( - jaxbJoinColumn, - columnUsage, - memberDetails, - xmlDocumentContext - ); - } ); + columnsUsage.value( transformPrimaryKeyJoinColumns( + jaxbJoinColumns, + xmlDocumentContext + ) ); } - public static void transferJoinColumn( - JaxbColumnJoined jaxbJoinColumn, - MutableAnnotationUsage joinColumnUsage, - AnnotationTarget annotationTarget, - XmlDocumentContext xmlDocumentContext) { - ColumnProcessing.applyColumnDetails( jaxbJoinColumn, annotationTarget, joinColumnUsage, xmlDocumentContext ); - XmlAnnotationHelper.applyOptionalAttribute( - joinColumnUsage, - "referencedColumnName", - jaxbJoinColumn.getReferencedColumnName() - ); - - final JaxbForeignKeyImpl jaxbForeignKey = jaxbJoinColumn.getForeignKey(); - if ( jaxbForeignKey != null ) { - joinColumnUsage.setAttributeValue( - "foreignKey", - ForeignKeyProcessing.createNestedForeignKeyAnnotation( jaxbForeignKey, annotationTarget, xmlDocumentContext ) - ); - } - } - - /** - * Support for {@linkplain JaxbJoinColumnImpl} to {@linkplain JoinColumn} transformation. - * Used when the List is the value of an annotation attribute other than its repetition container. - * For example, {@linkplain CollectionTable#joinColumns()}, {@linkplain JoinTable#joinColumns()} and - * {@linkplain JoinTable#inverseJoinColumns()} - */ - public static List> transformJoinColumnList( - List jaxbJoinColumns, - AnnotationTarget annotationTarget, + private static final PrimaryKeyJoinColumn[] NO_PRIMARY_KEY_JOIN_COLUMNS = new PrimaryKeyJoinColumn[0]; + public static PrimaryKeyJoinColumn[] transformPrimaryKeyJoinColumns( + List jaxbJoinColumns, XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbJoinColumns ) ) { - return Collections.emptyList(); + return NO_PRIMARY_KEY_JOIN_COLUMNS; } - final List> joinColumns = new ArrayList<>( jaxbJoinColumns.size() ); - jaxbJoinColumns.forEach( jaxbJoinColumn -> { - final MutableAnnotationUsage joinColumnAnn = - JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); - transferJoinColumn( jaxbJoinColumn, joinColumnAnn, null, xmlDocumentContext ); - joinColumns.add( joinColumnAnn ); - } ); - return joinColumns; + + final PrimaryKeyJoinColumn[] result = new PrimaryKeyJoinColumn[jaxbJoinColumns.size()]; + for ( int i = 0; i < jaxbJoinColumns.size(); i++ ) { + final PrimaryKeyJoinColumnJpaAnnotation joinColumn = JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); + result[i] = joinColumn; + + joinColumn.apply( jaxbJoinColumns.get(i), xmlDocumentContext ); + } + return result; } - public static List> createJoinColumns( - List jaxbJoinColumns, - AnnotationTarget annotationTarget, - XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isEmpty( jaxbJoinColumns ) ) { - return Collections.emptyList(); - } - final List> joinColumns = new ArrayList<>( jaxbJoinColumns.size() ); - jaxbJoinColumns.forEach( jaxbJoinColumn -> { - final MutableAnnotationUsage joinColumnUsage = JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); - transferJoinColumn( - jaxbJoinColumn, - joinColumnUsage, - annotationTarget, - xmlDocumentContext - ); - joinColumns.add( joinColumnUsage ); - } ); - return joinColumns; - } - - public static void applyJoinColumns( - List jaxbJoinColumns, + public static void applyMapKeyJoinColumns( + List jaxbJoinColumns, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbJoinColumns ) ) { return; } - final MutableAnnotationUsage columnsAnn = memberDetails.replaceAnnotationUsage( - JpaAnnotations.JOIN_COLUMN, - JpaAnnotations.JOIN_COLUMNS, + final MapKeyJoinColumnsJpaAnnotation joinColumnsUsage = (MapKeyJoinColumnsJpaAnnotation) memberDetails.replaceAnnotationUsage( + JpaAnnotations.MAP_KEY_JOIN_COLUMN, + JpaAnnotations.MAP_KEY_JOIN_COLUMNS, xmlDocumentContext.getModelBuildingContext() ); - columnsAnn.setAttributeValue( "value", createJoinColumns( jaxbJoinColumns, memberDetails, xmlDocumentContext ) ); + joinColumnsUsage.value( transformMapKeyJoinColumns( jaxbJoinColumns, xmlDocumentContext ) ); } - public static void applyPrimaryKeyJoinColumns( - List jaxbJoinColumns, - MutableAnnotationUsage tableAnn, + private static final MapKeyJoinColumn[] NO_KEY_JOIN_COLUMNS = new MapKeyJoinColumn[0]; + private static MapKeyJoinColumn[] transformMapKeyJoinColumns( + List jaxbJoinColumns, XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbJoinColumns ) ) { - return; + return NO_KEY_JOIN_COLUMNS; } - final List> columnUsages = CollectionHelper.arrayList( jaxbJoinColumns.size() ); - - jaxbJoinColumns.forEach( - (jaxbJoinColumn) -> - columnUsages.add( createPrimaryKeyJoinColumnUsage( jaxbJoinColumn, xmlDocumentContext ) ) - ); - - tableAnn.setAttributeValue( - "pkJoinColumns", - columnUsages - ); + final MapKeyJoinColumn[] joinColumns = new MapKeyJoinColumn[jaxbJoinColumns.size()]; + for ( int i = 0; i < jaxbJoinColumns.size(); i++ ) { + final MapKeyJoinColumnJpaAnnotation annotation = JpaAnnotations.MAP_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); + joinColumns[i] = annotation; + annotation.apply( jaxbJoinColumns.get(i), xmlDocumentContext ); + } + return joinColumns; } - - public static MutableAnnotationUsage createPrimaryKeyJoinColumnUsage( - JaxbPrimaryKeyJoinColumnImpl jaxbJoinColumn, - XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage columnUsage = - JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() ); - - ColumnProcessing.applyColumnDetails( - jaxbJoinColumn, - (MutableAnnotationUsage) columnUsage, - xmlDocumentContext - ); - - XmlAnnotationHelper.applyOptionalAttribute( - columnUsage, - "referencedColumnName", - ((JaxbColumnJoined) jaxbJoinColumn ).getReferencedColumnName() - ); - - ForeignKeyProcessing.applyForeignKey( - ( (JaxbColumnJoined) jaxbJoinColumn ).getForeignKey(), - (MutableAnnotationUsage) columnUsage, - xmlDocumentContext - ); - return columnUsage; - } - } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java index 6b33ea745c..50d66966c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java @@ -6,25 +6,17 @@ */ package org.hibernate.boot.models.xml.internal.db; -import java.util.List; - -import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTableImpl; import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; +import org.hibernate.boot.models.annotations.internal.JoinTableJpaAnnotation; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.MutableAnnotationTarget; -import org.hibernate.models.spi.MutableAnnotationUsage; - -import jakarta.persistence.JoinTable; /** * @author Steve Ebersole */ public class TableProcessing { - public static MutableAnnotationUsage transformJoinTable( + public static JoinTableJpaAnnotation transformJoinTable( JaxbJoinTableImpl jaxbJoinTable, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { @@ -32,51 +24,12 @@ public class TableProcessing { return null; } - final MutableAnnotationUsage joinTableUsage = target.applyAnnotationUsage( + final JoinTableJpaAnnotation joinTableUsage = (JoinTableJpaAnnotation) target.applyAnnotationUsage( JpaAnnotations.JOIN_TABLE, xmlDocumentContext.getModelBuildingContext() ); - applyJoinTable( jaxbJoinTable, joinTableUsage, target, xmlDocumentContext ); + joinTableUsage.apply( jaxbJoinTable, xmlDocumentContext ); return joinTableUsage; } - private static void applyJoinTable( - JaxbJoinTableImpl jaxbJoinTable, - MutableAnnotationUsage joinTableUsage, - AnnotationTarget annotationTarget, - XmlDocumentContext xmlDocumentContext) { - - XmlAnnotationHelper.applyOptionalAttribute( joinTableUsage, "name", jaxbJoinTable.getName() ); - XmlAnnotationHelper.applyTableAttributes( jaxbJoinTable, annotationTarget, joinTableUsage, JpaAnnotations.JOIN_TABLE, xmlDocumentContext ); - - final List joinColumns = jaxbJoinTable.getJoinColumn(); - if ( CollectionHelper.isNotEmpty( joinColumns ) ) { - joinTableUsage.setAttributeValue( "joinColumns", JoinColumnProcessing.transformJoinColumnList( - joinColumns, - annotationTarget, - xmlDocumentContext - ) ); - } - final List inverseJoinColumns = jaxbJoinTable.getInverseJoinColumn(); - if ( CollectionHelper.isNotEmpty( inverseJoinColumns ) ) { - joinTableUsage.setAttributeValue( "inverseJoinColumns", JoinColumnProcessing.transformJoinColumnList( - inverseJoinColumns, - annotationTarget, - xmlDocumentContext - ) ); - } - - if ( jaxbJoinTable.getForeignKey() != null ) { - joinTableUsage.setAttributeValue( - "foreignKey", - ForeignKeyProcessing.createNestedForeignKeyAnnotation( jaxbJoinTable.getForeignKey(), annotationTarget, xmlDocumentContext ) - ); - } - if ( jaxbJoinTable.getInverseForeignKey() != null ) { - joinTableUsage.setAttributeValue( - "inverseForeignKey", - ForeignKeyProcessing.createNestedForeignKeyAnnotation( jaxbJoinTable.getInverseForeignKey(), annotationTarget, xmlDocumentContext ) - ); - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/spi/XmlProcessor.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/spi/XmlProcessor.java index 4d2c97f07b..ce977e9093 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/spi/XmlProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/spi/XmlProcessor.java @@ -7,13 +7,12 @@ package org.hibernate.boot.models.xml.spi; import org.hibernate.boot.internal.RootMappingDefaults; -import org.hibernate.boot.models.categorize.internal.DomainModelCategorizationCollector; +import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; import org.hibernate.boot.models.xml.internal.ManagedTypeProcessor; import org.hibernate.boot.models.xml.internal.XmlDocumentContextImpl; import org.hibernate.boot.models.xml.internal.XmlDocumentImpl; import org.hibernate.boot.models.xml.internal.XmlProcessingResultImpl; import org.hibernate.boot.spi.BootstrapContext; -import org.hibernate.boot.spi.EffectiveMappingDefaults; import org.hibernate.models.spi.SourceModelBuildingContext; /** @@ -33,7 +32,6 @@ public class XmlProcessor { final XmlProcessingResultImpl xmlOverlay = new XmlProcessingResultImpl(); xmlPreProcessingResult.getDocuments().forEach( (jaxbRoot) -> { - modelCategorizationCollector.apply( jaxbRoot ); final XmlDocumentImpl xmlDocument = XmlDocumentImpl.consume( jaxbRoot, xmlPreProcessingResult.getPersistenceUnitMetadata() @@ -44,6 +42,7 @@ public class XmlProcessor { sourceModelBuildingContext, bootstrapContext ); + modelCategorizationCollector.apply( jaxbRoot, xmlDocumentContext ); jaxbRoot.getEmbeddables().forEach( (jaxbEmbeddable) -> { if ( xmlMappingsGloballyComplete || jaxbEmbeddable.isMetadataComplete() == Boolean.TRUE ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/query/AbstractNamedQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/query/AbstractNamedQueryBuilder.java index ba3e1db9bb..c5d9f99a05 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/query/AbstractNamedQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/query/AbstractNamedQueryBuilder.java @@ -49,7 +49,9 @@ public abstract class AbstractNamedQueryBuilder resultClass) { - this.resultClass = resultClass; + if ( resultClass != void.class ) { + this.resultClass = resultClass; + } return getThis(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/query/SqlResultSetMappingDescriptor.java b/hibernate-core/src/main/java/org/hibernate/boot/query/SqlResultSetMappingDescriptor.java index 6922732550..ba7f304945 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/query/SqlResultSetMappingDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/query/SqlResultSetMappingDescriptor.java @@ -15,6 +15,7 @@ import java.util.Map; import org.hibernate.LockMode; import org.hibernate.MappingException; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.metamodel.RuntimeMetamodels; import org.hibernate.metamodel.mapping.BasicValuedModelPart; import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping; @@ -22,8 +23,6 @@ import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.query.internal.FetchMementoBasicStandard; import org.hibernate.query.internal.FetchMementoEntityStandard; import org.hibernate.query.internal.ModelPartResultMementoBasicImpl; @@ -71,24 +70,24 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr // (`org.hibernate.query.results.ResultBuilder`) as part of the // memento for its resolution - public static SqlResultSetMappingDescriptor from(AnnotationUsage mappingAnnotation, String name) { - final List> entityResults = mappingAnnotation.getList( "entities" ); - final List> constructorResults = mappingAnnotation.getList( "classes" ); - final List> columnResults = mappingAnnotation.getList( "columns" ); + public static SqlResultSetMappingDescriptor from(SqlResultSetMapping mappingAnnotation, String name) { + final EntityResult[] entityResults = mappingAnnotation.entities(); + final ConstructorResult[] constructorResults = mappingAnnotation.classes(); + final ColumnResult[] columnResults = mappingAnnotation.columns(); final List resultDescriptors = arrayList( - entityResults.size() + columnResults.size() + columnResults.size() + entityResults.length + columnResults.length + columnResults.length ); - for ( final AnnotationUsage entityResult : entityResults ) { + for ( final EntityResult entityResult : entityResults ) { resultDescriptors.add( new EntityResultDescriptor( entityResult ) ); } - for ( final AnnotationUsage constructorResult : constructorResults ) { + for ( final ConstructorResult constructorResult : constructorResults ) { resultDescriptors.add( new ConstructorResultDescriptor( constructorResult, mappingAnnotation ) ); } - for ( final AnnotationUsage columnResult : columnResults ) { + for ( final ColumnResult columnResult : columnResults ) { resultDescriptors.add( new JpaColumnResultDescriptor( columnResult, mappingAnnotation ) ); @@ -97,8 +96,8 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr return new SqlResultSetMappingDescriptor( name, resultDescriptors ); } - public static SqlResultSetMappingDescriptor from(AnnotationUsage mappingAnnotation) { - return from( mappingAnnotation, mappingAnnotation.getString( "name" ) ); + public static SqlResultSetMappingDescriptor from(SqlResultSetMapping mappingAnnotation) { + return from( mappingAnnotation, mappingAnnotation.name() ); } private final String mappingName; @@ -130,21 +129,21 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr * @see jakarta.persistence.ColumnResult */ private static class JpaColumnResultDescriptor implements ResultDescriptor { - private final AnnotationUsage columnResult; + private final ColumnResult columnResult; private final String mappingName; public JpaColumnResultDescriptor( - AnnotationUsage columnResult, - AnnotationUsage mappingAnnotation) { + ColumnResult columnResult, + SqlResultSetMapping mappingAnnotation) { this.columnResult = columnResult; - this.mappingName = mappingAnnotation.getString( "name" ); + this.mappingName = mappingAnnotation.name(); } @Override public ResultMemento resolve(ResultSetMappingResolutionContext resolutionContext) { BootQueryLogging.BOOT_QUERY_LOGGER.debugf( "Generating ScalarResultMappingMemento for JPA ColumnResult(%s) for ResultSet mapping `%s`", - columnResult.getString( "name" ), + columnResult.name(), mappingName ); @@ -174,24 +173,24 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr private final List argumentResultDescriptors; public ConstructorResultDescriptor( - AnnotationUsage constructorResult, - AnnotationUsage mappingAnnotation) { - this.mappingName = mappingAnnotation.getString( "name" ); - this.targetJavaType = constructorResult.getClassDetails( "targetClass" ).toJavaClass(); + ConstructorResult constructorResult, + SqlResultSetMapping mappingAnnotation) { + this.mappingName = mappingAnnotation.name(); + this.targetJavaType = constructorResult.targetClass(); argumentResultDescriptors = interpretArguments( constructorResult, mappingAnnotation ); } private static List interpretArguments( - AnnotationUsage constructorResult, - AnnotationUsage mappingAnnotation) { - final List> columnResults = constructorResult.getList( "columns" ); - if ( columnResults.isEmpty() ) { + ConstructorResult constructorResult, + SqlResultSetMapping mappingAnnotation) { + final ColumnResult[] columnResults = constructorResult.columns(); + if ( ArrayHelper.isEmpty( columnResults ) ) { throw new IllegalArgumentException( "ConstructorResult did not define any ColumnResults" ); } - final List argumentResultDescriptors = arrayList( columnResults.size() ); - for ( AnnotationUsage columnResult : columnResults ) { + final List argumentResultDescriptors = arrayList( columnResults.length ); + for ( ColumnResult columnResult : columnResults ) { final JpaColumnResultDescriptor argumentResultDescriptor = new JpaColumnResultDescriptor( columnResult, mappingAnnotation @@ -234,25 +233,24 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr private final Map explicitFetchMappings; - public EntityResultDescriptor(AnnotationUsage entityResult) { - final ClassDetails classDetails = entityResult.getClassDetails( "entityClass" ); - this.entityName = classDetails.getName(); + public EntityResultDescriptor(EntityResult entityResult) { + this.entityName = entityResult.entityClass().getName(); this.navigablePath = new NavigablePath( entityName ); - this.discriminatorColumn = entityResult.getString( "discriminatorColumn" ); + this.discriminatorColumn = entityResult.discriminatorColumn(); this.explicitFetchMappings = extractFetchMappings( navigablePath, entityResult ); } private static Map extractFetchMappings( NavigablePath navigablePath, - AnnotationUsage entityResult) { - final List> fields = entityResult.getList( "fields" ); - final Map explicitFetchMappings = mapOfSize( fields.size() ); + EntityResult entityResult) { + final FieldResult[] fields = entityResult.fields(); + final Map explicitFetchMappings = mapOfSize( fields.length ); - for ( int i = 0; i < fields.size(); i++ ) { - final AnnotationUsage fieldResult = fields.get( i ); - final String fieldName = fieldResult.getString("name" ); + for ( int i = 0; i < fields.length; i++ ) { + final FieldResult fieldResult = fields[i]; + final String fieldName = fieldResult.name(); final AttributeFetchDescriptor existing = explicitFetchMappings.get( fieldName ); if ( existing != null ) { existing.addColumn( fieldResult ); @@ -326,18 +324,6 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr ); } - private static AttributeFetchDescriptor from( - NavigablePath entityPath, - String entityName, - AnnotationUsage fieldResult) { - return new AttributeFetchDescriptor( - entityPath, - entityName, - fieldResult.getString( "name" ), - fieldResult.getString( "column" ) - ); - } - private final NavigablePath navigablePath; private final String entityName; @@ -374,25 +360,6 @@ public class SqlResultSetMappingDescriptor implements NamedResultSetMappingDescr columnNames.add( fieldResult.column() ); } - private void addColumn(AnnotationUsage fieldResult) { - final String name = fieldResult.getString( "name" ); - final String column = fieldResult.getString( "column" ); - - if ( ! propertyPath.equals( name ) ) { - throw new IllegalArgumentException( - String.format( - Locale.ROOT, - "Passed FieldResult [%s, %s] does not match AttributeFetchMapping [%s]", - name, - column, - propertyPath - ) - ); - } - - columnNames.add( column ); - } - @Override public ResultMemento asResultMemento(NavigablePath path, ResultSetMappingResolutionContext resolutionContext) { final RuntimeMetamodels runtimeMetamodels = resolutionContext.getSessionFactory().getRuntimeMetamodels(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/InFlightMetadataCollector.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/InFlightMetadataCollector.java index 52884099f3..7c17817b3b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/InFlightMetadataCollector.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/InFlightMetadataCollector.java @@ -30,7 +30,7 @@ import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject; import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; +import org.hibernate.boot.models.spi.GlobalRegistrations; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; import org.hibernate.boot.query.NamedHqlQueryDefinition; import org.hibernate.boot.query.NamedNativeQueryDefinition; @@ -48,7 +48,6 @@ import org.hibernate.mapping.Table; import org.hibernate.metamodel.CollectionClassification; import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.models.spi.AnnotationDescriptorRegistry; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.SourceModelBuildingContext; @@ -357,7 +356,7 @@ public interface InFlightMetadataCollector extends MetadataImplementor { void registerUserType(Class embeddableType, Class> userType); Class> findRegisteredUserType(Class basicType); - void addCollectionTypeRegistration(AnnotationUsage registrationAnnotation); + void addCollectionTypeRegistration(CollectionTypeRegistration registrationAnnotation); void addCollectionTypeRegistration(CollectionClassification classification, CollectionTypeRegistrationDescriptor descriptor); CollectionTypeRegistrationDescriptor findCollectionTypeRegistration(CollectionClassification classification); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java index 2fd2ec716c..a49d3bc637 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java @@ -493,6 +493,14 @@ public final class CollectionHelper { return combined; } + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static List combineUntyped(List list1, List list2) { + final ArrayList combined = arrayList( list1.size() + list2.size() ); + combined.addAll( list1 ); + combined.addAll( list2 ); + return combined; + } + public static List combine(List... lists) { final ArrayList combined = new ArrayList<>(); for ( int i = 0; i < lists.length; i++ ) { diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java index daea8dec31..24e69b6f8d 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackDefinitionResolver.java @@ -6,21 +6,23 @@ */ package org.hibernate.jpa.event.internal; +import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.hibernate.boot.models.categorize.spi.GlobalRegistrations; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.spi.GlobalRegistrations; +import org.hibernate.boot.models.spi.JpaEventListener; +import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jpa.event.spi.CallbackDefinition; import org.hibernate.jpa.event.spi.CallbackType; import org.hibernate.mapping.Property; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.AnnotationDescriptor; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MethodDetails; @@ -48,8 +50,10 @@ public final class CallbackDefinitionResolver { MetadataBuildingContext metadataBuildingContext, ClassDetails entityClass, CallbackType callbackType) { - final GlobalRegistrations globalRegistrations = metadataBuildingContext.getMetadataCollector().getGlobalRegistrations(); + final InFlightMetadataCollector metadataCollector = metadataBuildingContext.getMetadataCollector(); + final GlobalRegistrations globalRegistrations = metadataCollector.getGlobalRegistrations(); final List globalListenerRegistrations = globalRegistrations.getEntityListenerRegistrations(); + final SourceModelBuildingContext sourceModelContext = metadataCollector.getSourceModelBuildingContext(); List callbackDefinitions = new ArrayList<>(); List callbacksMethodNames = new ArrayList<>(); @@ -63,7 +67,7 @@ public final class CallbackDefinitionResolver { CallbackDefinition callbackDefinition = null; final List methodsDetailsList = currentClazz.getMethods(); for ( MethodDetails methodDetails : methodsDetailsList ) { - if ( !methodDetails.hasAnnotationUsage( callbackType.getCallbackAnnotation() ) ) { + if ( !methodDetails.hasDirectAnnotationUsage( callbackType.getCallbackAnnotation() ) ) { continue; } if ( callbacksMethodNames.contains( methodDetails.getName() ) ) { @@ -102,17 +106,17 @@ public final class CallbackDefinitionResolver { } } if ( !stopListeners ) { - applyListeners( currentClazz, orderedListeners ); - stopListeners = currentClazz.hasAnnotationUsage( ExcludeSuperclassListeners.class ); - stopDefaultListeners = currentClazz.hasAnnotationUsage( ExcludeDefaultListeners.class ); + applyListeners( currentClazz, orderedListeners, sourceModelContext ); + stopListeners = currentClazz.hasDirectAnnotationUsage( ExcludeSuperclassListeners.class ); + stopDefaultListeners = currentClazz.hasDirectAnnotationUsage( ExcludeDefaultListeners.class ); } do { currentClazz = currentClazz.getSuperClass(); } while ( currentClazz != null - && !( currentClazz.hasAnnotationUsage( Entity.class ) - || currentClazz.hasAnnotationUsage( MappedSuperclass.class ) ) + && !( currentClazz.hasDirectAnnotationUsage( Entity.class ) + || currentClazz.hasDirectAnnotationUsage( MappedSuperclass.class ) ) ); } while ( currentClazz != null ); @@ -131,7 +135,7 @@ public final class CallbackDefinitionResolver { CallbackDefinition callbackDefinition = null; if ( listenerClassDetails != null ) { for ( MethodDetails methodDetails : listenerClassDetails.getMethods() ) { - if ( methodDetails.hasAnnotationUsage( callbackType.getCallbackAnnotation() ) ) { + if ( methodDetails.hasDirectAnnotationUsage( callbackType.getCallbackAnnotation() ) ) { final String methodName = methodDetails.getName(); //overridden method, remove the superclass overridden method if ( callbackDefinition == null ) { @@ -195,7 +199,7 @@ public final class CallbackDefinitionResolver { CallbackDefinition callbackDefinition = null; final List methodsDetailsList = currentClazz.getMethods(); for ( MethodDetails methodDetails : methodsDetailsList ) { - if ( !methodDetails.hasAnnotationUsage( callbackType.getCallbackAnnotation() ) ) { + if ( !methodDetails.hasDirectAnnotationUsage( callbackType.getCallbackAnnotation() ) ) { continue; } @@ -237,7 +241,7 @@ public final class CallbackDefinitionResolver { do { currentClazz = currentClazz.getSuperClass(); } - while ( currentClazz != null && !currentClazz.hasAnnotationUsage( MappedSuperclass.class ) ); + while ( currentClazz != null && !currentClazz.hasDirectAnnotationUsage( MappedSuperclass.class ) ); } while ( currentClazz != null ); @@ -260,24 +264,32 @@ public final class CallbackDefinitionResolver { } } - private static void applyListeners(ClassDetails currentClazz, List listOfListeners) { - final AnnotationUsage entityListeners = currentClazz.getAnnotationUsage( EntityListeners.class ); + private static void applyListeners( + ClassDetails currentClazz, + List listOfListeners, + SourceModelBuildingContext sourceModelContext) { + final ClassDetailsRegistry classDetailsRegistry = sourceModelContext.getClassDetailsRegistry(); + + final EntityListeners entityListeners = currentClazz.getDirectAnnotationUsage( EntityListeners.class ); if ( entityListeners != null ) { - final List listeners = entityListeners.getList( "value" ); - int size = listeners.size(); + final Class[] listeners = entityListeners.value(); + int size = listeners.length; for ( int index = size - 1; index >= 0; index-- ) { - listOfListeners.add( listeners.get( index ) ); + listOfListeners.add( classDetailsRegistry.resolveClassDetails( listeners[index].getName() ) ); } } if ( useAnnotationAnnotatedByListener ) { - final List> metaAnnotatedUsageList = currentClazz.getMetaAnnotated( EntityListeners.class ); - for ( AnnotationUsage metaAnnotatedUsage : metaAnnotatedUsageList ) { - final AnnotationUsage metaAnnotatedListeners = metaAnnotatedUsage.getAnnotationDescriptor().getAnnotationUsage( EntityListeners.class ); - final List listeners = metaAnnotatedListeners.getList( "value" ); - int size = listeners.size(); - for ( int index = size - 1; index >= 0; index-- ) { - listOfListeners.add( listeners.get( index ) ); + final List metaAnnotatedUsageList = currentClazz.getMetaAnnotated( EntityListeners.class, sourceModelContext ); + for ( Annotation metaAnnotatedUsage : metaAnnotatedUsageList ) { + final AnnotationDescriptor descriptor = sourceModelContext.getAnnotationDescriptorRegistry() + .getDescriptor( metaAnnotatedUsage.getClass() ); + final EntityListeners metaAnnotatedListeners = descriptor.getDirectAnnotationUsage( EntityListeners.class ); + final Class[] listeners = metaAnnotatedListeners.value(); + for ( int index = listeners.length - 1; index >= 0; index-- ) { + listOfListeners.add( + sourceModelContext.getClassDetailsRegistry().resolveClassDetails( listeners[index].getName() ) + ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java index df08beb17e..015778330f 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java @@ -41,7 +41,6 @@ import org.hibernate.generator.CustomIdGeneratorCreationContext; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.TypeDetails; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; @@ -884,22 +883,14 @@ public abstract class SimpleValue implements KeyValue { } } + private static final Annotation[] NO_ANNOTATIONS = new Annotation[0]; private static Annotation[] getAnnotations(MemberDetails memberDetails) { - final Annotation[] annotations; - final Collection> allAnnotationUsages = memberDetails != null - ? memberDetails.getAllAnnotationUsages() : - null; - if ( allAnnotationUsages == null ) { - annotations = new Annotation[0]; - } - else { - annotations = new Annotation[allAnnotationUsages.size()]; - int index = 0; - for ( AnnotationUsage annotationUsage : allAnnotationUsages ) { - annotations[ index++ ] = annotationUsage.toAnnotation(); - } - } - return annotations; + final Collection directAnnotationUsages = memberDetails == null + ? null + : memberDetails.getDirectAnnotationUsages(); + return directAnnotationUsages == null + ? NO_ANNOTATIONS + : directAnnotationUsages.toArray( Annotation[]::new ); } public DynamicParameterizedType.ParameterType makeParameterImpl() { diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java b/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java index fb4d7b126b..62d3d21553 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/ResultMementoBasicStandard.java @@ -12,8 +12,6 @@ import java.util.function.Consumer; import org.hibernate.boot.model.convert.internal.ConverterHelper; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.BasicValuedMapping; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.query.named.ResultMementoBasic; import org.hibernate.query.results.ResultBuilderBasicValued; import org.hibernate.query.results.complete.CompleteResultBuilderBasicValuedConverted; @@ -71,15 +69,14 @@ public class ResultMementoBasicStandard implements ResultMementoBasic { * Creation for JPA descriptor */ public ResultMementoBasicStandard( - AnnotationUsage definition, + ColumnResult definition, ResultSetMappingResolutionContext context) { - this.explicitColumnName = definition.getString( "name" ); + this.explicitColumnName = definition.name(); final SessionFactoryImplementor sessionFactory = context.getSessionFactory(); final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration(); - final ClassDetails definedTypeDetails = definition.getClassDetails( "type" ); - final Class definedType = definedTypeDetails.toJavaClass(); + final Class definedType = definition.type(); if ( void.class == definedType ) { builder = new CompleteResultBuilderBasicValuedStandard( explicitColumnName, null, null ); @@ -109,7 +106,7 @@ public class ResultMementoBasicStandard implements ResultMementoBasic { final JavaType explicitJavaType; // see if this is a registered BasicType... - final BasicType registeredBasicType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( definedTypeDetails.getName() ); + final BasicType registeredBasicType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( definedType.getName() ); if ( registeredBasicType != null ) { explicitType = registeredBasicType; explicitJavaType = registeredBasicType.getJavaTypeDescriptor(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlElementCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlElementCollectionTest.java index 5615483bf9..e1954c9639 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlElementCollectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlElementCollectionTest.java @@ -6,12 +6,7 @@ */ package org.hibernate.orm.test.annotations.xml.ejb3; -import java.lang.annotation.Annotation; -import java.util.List; - import org.hibernate.boot.internal.Target; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.testing.orm.junit.JiraKey; @@ -30,7 +25,7 @@ import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinColumns; +import jakarta.persistence.JoinTable; import jakarta.persistence.Lob; import jakarta.persistence.MapKey; import jakarta.persistence.MapKeyClass; @@ -53,157 +48,157 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase { @Test public void testNoChildren() { final MemberDetails memberDetails = getAttributeMember( Entity2.class, "field1", "element-collection.orm1.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( OrderBy.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( OrderColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Column.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Temporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Enumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Lob.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AssociationOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AssociationOverrides.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( CollectionTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderBy.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Column.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Temporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Enumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Lob.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverrides.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AssociationOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AssociationOverrides.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( CollectionTable.class ) ).isFalse(); - final AnnotationUsage elementCollectionUsage = memberDetails.getAnnotationUsage( ElementCollection.class ); - assertThat( elementCollectionUsage.getEnum( "fetch", FetchType.class ) ).isEqualTo( FetchType.LAZY ); - assertThat( elementCollectionUsage.getClassDetails( "targetClass" ) ).isEqualTo( ClassDetails.VOID_CLASS_DETAILS ); + final ElementCollection elementCollectionUsage = memberDetails.getDirectAnnotationUsage( ElementCollection.class ); + assertThat( elementCollectionUsage.fetch() ).isEqualTo( FetchType.LAZY ); + assertThat( elementCollectionUsage.targetClass() ).isEqualTo( void.class ); } @Test public void testOrderBy() { final MemberDetails memberDetails = getAttributeMember( Entity2.class, "field1", "element-collection.orm2.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( OrderBy.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( OrderColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderBy.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderColumn.class ) ).isFalse(); - final AnnotationUsage orderByUsage = memberDetails.getAnnotationUsage( OrderBy.class ); - assertThat( orderByUsage.getString( "value" ) ).isEqualTo( "col1 ASC, col2 DESC" ); + final OrderBy orderByUsage = memberDetails.getDirectAnnotationUsage( OrderBy.class ); + assertThat( orderByUsage.value() ).isEqualTo( "col1 ASC, col2 DESC" ); } @Test public void testOrderColumnNoAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity2.class, "field1", "element-collection.orm3.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( OrderColumn.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( OrderBy.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderColumn.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderBy.class ) ).isFalse(); - final AnnotationUsage orderColumnUsage = memberDetails.getAnnotationUsage( OrderColumn.class ); - assertThat( orderColumnUsage.getString( "name" ) ).isEmpty(); - assertThat( orderColumnUsage.getString( "columnDefinition" ) ).isEmpty(); - assertThat( orderColumnUsage.getBoolean( "insertable" ) ).isTrue(); - assertThat( orderColumnUsage.getBoolean( "updatable" ) ).isTrue(); - assertThat( orderColumnUsage.getBoolean( "nullable" ) ).isTrue(); + final OrderColumn orderColumnUsage = memberDetails.getDirectAnnotationUsage( OrderColumn.class ); + assertThat( orderColumnUsage.name() ).isEmpty(); + assertThat( orderColumnUsage.columnDefinition() ).isEmpty(); + assertThat( orderColumnUsage.insertable() ).isTrue(); + assertThat( orderColumnUsage.updatable() ).isTrue(); + assertThat( orderColumnUsage.nullable() ).isTrue(); } @Test public void testOrderColumnAllAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity2.class, "field1", "element-collection.orm4.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( OrderColumn.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( OrderBy.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderColumn.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OrderBy.class ) ).isFalse(); - final AnnotationUsage orderColumnUsage = memberDetails.getAnnotationUsage( OrderColumn.class ); + final OrderColumn orderColumnUsage = memberDetails.getDirectAnnotationUsage( OrderColumn.class ); - assertThat( orderColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( orderColumnUsage.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( orderColumnUsage.getBoolean( "insertable" ) ).isFalse(); - assertThat( orderColumnUsage.getBoolean( "updatable" ) ).isFalse(); - assertThat( orderColumnUsage.getBoolean( "nullable" ) ).isFalse(); + assertThat( orderColumnUsage.name() ).isEqualTo( "col1" ); + assertThat( orderColumnUsage.columnDefinition() ).isEqualTo( "int" ); + assertThat( orderColumnUsage.insertable() ).isFalse(); + assertThat( orderColumnUsage.updatable() ).isFalse(); + assertThat( orderColumnUsage.nullable() ).isFalse(); } @Test public void testMapKeyNoAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm5.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - final AnnotationUsage mapKeyUsage = memberDetails.getAnnotationUsage( MapKey.class ); - assertThat( mapKeyUsage.getString( "name" ) ).isEmpty(); + final MapKey mapKeyUsage = memberDetails.getDirectAnnotationUsage( MapKey.class ); + assertThat( mapKeyUsage.name() ).isEmpty(); } @Test public void testMapKeyAllAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm6.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - final AnnotationUsage mapKeyUsage = memberDetails.getAnnotationUsage( MapKey.class ); - assertThat( mapKeyUsage.getString( "name" ) ).isEqualTo( "field2" ); + final MapKey mapKeyUsage = memberDetails.getDirectAnnotationUsage( MapKey.class ); + assertThat( mapKeyUsage.name() ).isEqualTo( "field2" ); } @Test public void testMapKeyClass() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm7.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - final AnnotationUsage mapKeyClassUsage = memberDetails.getAnnotationUsage( MapKeyClass.class ); - assertThat( mapKeyClassUsage.getClassDetails( "value" ).toJavaClass() ).isEqualTo( Entity2.class ); + final MapKeyClass mapKeyClassUsage = memberDetails.getDirectAnnotationUsage( MapKeyClass.class ); + assertThat( mapKeyClassUsage.value() ).isEqualTo( Entity2.class ); } @Test public void testMapKeyTemporal() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm8.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - final AnnotationUsage mapKeyTemporalUsage = memberDetails.getAnnotationUsage( MapKeyTemporal.class ); - assertThat( mapKeyTemporalUsage.getEnum( "value", TemporalType.class ) ).isEqualTo( TemporalType.DATE ); + final MapKeyTemporal mapKeyTemporalUsage = memberDetails.getDirectAnnotationUsage( MapKeyTemporal.class ); + assertThat( mapKeyTemporalUsage.value() ).isEqualTo( TemporalType.DATE ); } @Test public void testMapKeyEnumerated() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm9.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - final AnnotationUsage mapKeyEnumeratedUsage = memberDetails.getAnnotationUsage( MapKeyEnumerated.class ); - assertThat( mapKeyEnumeratedUsage.getEnum( "value", EnumType.class ) ).isEqualTo( EnumType.STRING ); + final MapKeyEnumerated mapKeyEnumeratedUsage = memberDetails.getDirectAnnotationUsage( MapKeyEnumerated.class ); + assertThat( mapKeyEnumeratedUsage.value() ).isEqualTo( EnumType.STRING ); } /** @@ -213,93 +208,95 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase { @Test public void testSingleMapKeyAttributeOverride() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm10.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverrides.class ) ).isTrue(); - final AnnotationUsage attributeOverrideUsage = memberDetails.getAnnotationUsage( AttributeOverride.class ); - assertThat( attributeOverrideUsage.getString( "name" ) ).isEqualTo( "key.field1" ); - final AnnotationUsage nestedColumnUsage = attributeOverrideUsage.getNestedUsage( "column" ); - assertThat( nestedColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); + final AttributeOverrides overridesUsage = memberDetails.getDirectAnnotationUsage( AttributeOverrides.class ); + final AttributeOverride overrideUsage = overridesUsage.value()[0]; + assertThat( overrideUsage.name() ).isEqualTo( "key.field1" ); + + final Column nestedColumnUsage = overrideUsage.column(); + assertThat( nestedColumnUsage.name() ).isEqualTo( "col1" ); } @Test public void testMultipleMapKeyAttributeOverrides() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm11.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverrides.class ) ).isTrue(); - final AnnotationUsage attributeOverridesUsage = memberDetails.getAnnotationUsage( AttributeOverrides.class ); - final List> attributeOverrideUsages = attributeOverridesUsage.getList( "value" ); + final AttributeOverrides attributeOverridesUsage = memberDetails.getDirectAnnotationUsage( AttributeOverrides.class ); + final AttributeOverride[] attributeOverrideUsages = attributeOverridesUsage.value(); assertThat( attributeOverrideUsages ).hasSize( 2 ); - final AnnotationUsage attributeOverrideUsage0 = attributeOverrideUsages.get( 0 ); - assertThat( attributeOverrideUsage0.getString( "name" ) ).isEqualTo( "key.field1" ); - final AnnotationUsage nestedColumnUsage0 = attributeOverrideUsage0.getNestedUsage( "column" ); - assertThat( nestedColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( nestedColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( nestedColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( nestedColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( nestedColumnUsage0.getBoolean( "unique" ) ).isFalse(); - assertThat( nestedColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( nestedColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( nestedColumnUsage0.getInteger( "length" ) ).isEqualTo( 255 ); - assertThat( nestedColumnUsage0.getInteger( "precision" ) ).isEqualTo( 0 ); - assertThat( nestedColumnUsage0.getInteger( "scale" ) ).isEqualTo( 0 ); + final AttributeOverride attributeOverrideUsage0 = attributeOverrideUsages[0]; + assertThat( attributeOverrideUsage0.name() ).isEqualTo( "key.field1" ); + final Column nestedColumnUsage0 = attributeOverrideUsage0.column(); + assertThat( nestedColumnUsage0.name() ).isEmpty(); + assertThat( nestedColumnUsage0.insertable() ).isTrue(); + assertThat( nestedColumnUsage0.updatable() ).isTrue(); + assertThat( nestedColumnUsage0.nullable() ).isTrue(); + assertThat( nestedColumnUsage0.unique() ).isFalse(); + assertThat( nestedColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( nestedColumnUsage0.table() ).isEmpty(); + assertThat( nestedColumnUsage0.length() ).isEqualTo( 255 ); + assertThat( nestedColumnUsage0.precision() ).isEqualTo( 0 ); + assertThat( nestedColumnUsage0.scale() ).isEqualTo( 0 ); - final AnnotationUsage attributeOverrideUsage1 = attributeOverrideUsages.get( 1 ); - assertThat( attributeOverrideUsage1.getString( "name" ) ).isEqualTo( "key.field2" ); - final AnnotationUsage nestedColumnUsage1 = attributeOverrideUsage1.getNestedUsage( "column" ); - assertThat( nestedColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( nestedColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( nestedColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( nestedColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( nestedColumnUsage1.getBoolean( "unique" ) ).isTrue(); - assertThat( nestedColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( nestedColumnUsage1.getString( "table" ) ).isEqualTo( "table1" ); - assertThat( nestedColumnUsage1.getInteger( "length" ) ).isEqualTo( 50 ); - assertThat( nestedColumnUsage1.getInteger( "precision" ) ).isEqualTo( 2 ); - assertThat( nestedColumnUsage1.getInteger( "scale" ) ).isEqualTo( 1 ); + final AttributeOverride attributeOverrideUsage1 = attributeOverrideUsages[1]; + assertThat( attributeOverrideUsage1.name() ).isEqualTo( "key.field2" ); + final Column nestedColumnUsage1 = attributeOverrideUsage1.column(); + assertThat( nestedColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( nestedColumnUsage1.insertable() ).isFalse(); + assertThat( nestedColumnUsage1.updatable() ).isFalse(); + assertThat( nestedColumnUsage1.nullable() ).isFalse(); + assertThat( nestedColumnUsage1.unique() ).isTrue(); + assertThat( nestedColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( nestedColumnUsage1.table() ).isEqualTo( "table1" ); + assertThat( nestedColumnUsage1.length() ).isEqualTo( 50 ); + assertThat( nestedColumnUsage1.precision() ).isEqualTo( 2 ); + assertThat( nestedColumnUsage1.scale() ).isEqualTo( 1 ); } @Test public void testMapKeyColumnNoAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm12.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isTrue(); - final AnnotationUsage mapKeyColumnUsage = memberDetails.getAnnotationUsage( MapKeyColumn.class ); - assertThat( mapKeyColumnUsage.getString( "name" ) ).isEmpty(); - assertThat( mapKeyColumnUsage.getString( "table" ) ).isEmpty(); - assertThat( mapKeyColumnUsage.getString( "columnDefinition" ) ).isEmpty(); - assertThat( mapKeyColumnUsage.getBoolean( "nullable" ) ).isFalse(); - assertThat( mapKeyColumnUsage.getBoolean( "insertable" ) ).isTrue(); - assertThat( mapKeyColumnUsage.getBoolean( "updatable" ) ).isTrue(); - assertThat( mapKeyColumnUsage.getBoolean( "unique" ) ).isFalse(); - assertThat( mapKeyColumnUsage.getInteger( "length" ) ).isEqualTo( 255 ); - assertThat( mapKeyColumnUsage.getInteger( "precision" ) ).isEqualTo( 0 ); - assertThat( mapKeyColumnUsage.getInteger( "scale" ) ).isEqualTo( 0 ); + final MapKeyColumn mapKeyColumnUsage = memberDetails.getDirectAnnotationUsage( MapKeyColumn.class ); + assertThat( mapKeyColumnUsage.name() ).isEmpty(); + assertThat( mapKeyColumnUsage.table() ).isEmpty(); + assertThat( mapKeyColumnUsage.columnDefinition() ).isEmpty(); + assertThat( mapKeyColumnUsage.nullable() ).isFalse(); + assertThat( mapKeyColumnUsage.insertable() ).isTrue(); + assertThat( mapKeyColumnUsage.updatable() ).isTrue(); + assertThat( mapKeyColumnUsage.unique() ).isFalse(); + assertThat( mapKeyColumnUsage.length() ).isEqualTo( 255 ); + assertThat( mapKeyColumnUsage.precision() ).isEqualTo( 0 ); + assertThat( mapKeyColumnUsage.scale() ).isEqualTo( 0 ); } @Test public void testMapKeyColumnAllAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm13.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isTrue(); - final AnnotationUsage mapKeyColumnUsage = memberDetails.getAnnotationUsage( MapKeyColumn.class ); - assertThat( mapKeyColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( mapKeyColumnUsage.getString( "table" ) ).isEqualTo( "table1" ); - assertThat( mapKeyColumnUsage.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( mapKeyColumnUsage.getBoolean( "nullable" ) ).isTrue(); - assertThat( mapKeyColumnUsage.getBoolean( "insertable" ) ).isFalse(); - assertThat( mapKeyColumnUsage.getBoolean( "updatable" ) ).isFalse(); - assertThat( mapKeyColumnUsage.getBoolean( "unique" ) ).isTrue(); - assertThat( mapKeyColumnUsage.getInteger( "length" ) ).isEqualTo( 50 ); - assertThat( mapKeyColumnUsage.getInteger( "precision" ) ).isEqualTo( 2 ); - assertThat( mapKeyColumnUsage.getInteger( "scale" ) ).isEqualTo( 1 ); + final MapKeyColumn mapKeyColumnUsage = memberDetails.getDirectAnnotationUsage( MapKeyColumn.class ); + assertThat( mapKeyColumnUsage.name() ).isEqualTo( "col1" ); + assertThat( mapKeyColumnUsage.table() ).isEqualTo( "table1" ); + assertThat( mapKeyColumnUsage.columnDefinition() ).isEqualTo( "int" ); + assertThat( mapKeyColumnUsage.nullable() ).isTrue(); + assertThat( mapKeyColumnUsage.insertable() ).isFalse(); + assertThat( mapKeyColumnUsage.updatable() ).isFalse(); + assertThat( mapKeyColumnUsage.unique() ).isTrue(); + assertThat( mapKeyColumnUsage.length() ).isEqualTo( 50 ); + assertThat( mapKeyColumnUsage.precision() ).isEqualTo( 2 ); + assertThat( mapKeyColumnUsage.scale() ).isEqualTo( 1 ); } /** @@ -309,126 +306,127 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase { @Test public void testSingleMapKeyJoinColumn() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm14.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - final AnnotationUsage joinColumnUsage = memberDetails.getAnnotationUsage( MapKeyJoinColumn.class ); - assertThat( joinColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); + final MapKeyJoinColumns joinColumnsUsage = memberDetails.getDirectAnnotationUsage( MapKeyJoinColumns.class ); + final MapKeyJoinColumn joinColumnUsage = joinColumnsUsage.value()[0]; + assertThat( joinColumnUsage.name() ).isEqualTo( "col1" ); } @Test public void testMultipleMapKeyJoinColumns() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm15.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyJoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKey.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyClass.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyTemporal.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapKeyColumn.class ) ).isFalse(); - final AnnotationUsage joinColumnsUsage = memberDetails.getAnnotationUsage( MapKeyJoinColumns.class ); - final List> joinColumnUsages = joinColumnsUsage.getList( "value" ); + final MapKeyJoinColumns joinColumnsUsage = memberDetails.getDirectAnnotationUsage( MapKeyJoinColumns.class ); + final MapKeyJoinColumn[] joinColumnUsages = joinColumnsUsage.value(); assertThat( joinColumnUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumnUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); + final MapKeyJoinColumn joinColumnUsage0 = joinColumnUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.unique() ).isFalse(); + assertThat( joinColumnUsage0.nullable() ).isFalse(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); - final AnnotationUsage joinColumnUsage1 = joinColumnUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table1" ); + final MapKeyJoinColumn joinColumnUsage1 = joinColumnUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage1.unique() ).isTrue(); + assertThat( joinColumnUsage1.nullable() ).isTrue(); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table1" ); } @Test public void testColumnNoAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm16.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Column.class ) ).isTrue(); - final AnnotationUsage columnUsage = memberDetails.getAnnotationUsage( Column.class ); - assertThat( columnUsage.getString( "name" ) ).isEmpty(); - assertThat( columnUsage.getBoolean( "unique" ) ).isFalse(); - assertThat( columnUsage.getBoolean( "nullable" ) ).isTrue(); - assertThat( columnUsage.getBoolean( "insertable" ) ).isTrue(); - assertThat( columnUsage.getBoolean( "updatable" ) ).isTrue(); - assertThat( columnUsage.getString( "columnDefinition" ) ).isEmpty(); - assertThat( columnUsage.getString( "table" ) ).isEmpty(); - assertThat( columnUsage.getInteger( "length" ) ).isEqualTo( 255 ); - assertThat( columnUsage.getInteger( "precision" ) ).isEqualTo( 0 ); - assertThat( columnUsage.getInteger( "scale" ) ).isEqualTo( 0 ); + assertThat( memberDetails.hasDirectAnnotationUsage( Column.class ) ).isTrue(); + final Column columnUsage = memberDetails.getDirectAnnotationUsage( Column.class ); + assertThat( columnUsage.name() ).isEmpty(); + assertThat( columnUsage.unique() ).isFalse(); + assertThat( columnUsage.nullable() ).isTrue(); + assertThat( columnUsage.insertable() ).isTrue(); + assertThat( columnUsage.updatable() ).isTrue(); + assertThat( columnUsage.columnDefinition() ).isEmpty(); + assertThat( columnUsage.table() ).isEmpty(); + assertThat( columnUsage.length() ).isEqualTo( 255 ); + assertThat( columnUsage.precision() ).isEqualTo( 0 ); + assertThat( columnUsage.scale() ).isEqualTo( 0 ); } @Test public void testColumnAllAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm17.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Column.class ) ).isTrue(); - final AnnotationUsage columnUsage = memberDetails.getAnnotationUsage( Column.class ); - assertThat( columnUsage.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( columnUsage.getBoolean( "unique" ) ).isTrue(); - assertThat( columnUsage.getBoolean( "nullable" ) ).isFalse(); - assertThat( columnUsage.getBoolean( "insertable" ) ).isFalse(); - assertThat( columnUsage.getBoolean( "updatable" ) ).isFalse(); - assertThat( columnUsage.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( columnUsage.getString( "table" ) ).isEqualTo( "table1" ); - assertThat( columnUsage.getInteger( "length" ) ).isEqualTo( 50 ); - assertThat( columnUsage.getInteger( "precision" ) ).isEqualTo( 2 ); - assertThat( columnUsage.getInteger( "scale" ) ).isEqualTo( 1 ); + assertThat( memberDetails.hasDirectAnnotationUsage( Column.class ) ).isTrue(); + final Column columnUsage = memberDetails.getDirectAnnotationUsage( Column.class ); + assertThat( columnUsage.name() ).isEqualTo( "col1" ); + assertThat( columnUsage.unique() ).isTrue(); + assertThat( columnUsage.nullable() ).isFalse(); + assertThat( columnUsage.insertable() ).isFalse(); + assertThat( columnUsage.updatable() ).isFalse(); + assertThat( columnUsage.columnDefinition() ).isEqualTo( "int" ); + assertThat( columnUsage.table() ).isEqualTo( "table1" ); + assertThat( columnUsage.length() ).isEqualTo( 50 ); + assertThat( columnUsage.precision() ).isEqualTo( 2 ); + assertThat( columnUsage.scale() ).isEqualTo( 1 ); } @Test public void testTemporal() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm18.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Temporal.class ) ).isTrue(); - final AnnotationUsage temporalUsage = memberDetails.getAnnotationUsage( Temporal.class ); - assertThat( temporalUsage.getEnum( "value", TemporalType.class ) ).isEqualTo( TemporalType.DATE ); + assertThat( memberDetails.hasDirectAnnotationUsage( Temporal.class ) ).isTrue(); + final Temporal temporalUsage = memberDetails.getDirectAnnotationUsage( Temporal.class ); + assertThat( temporalUsage.value() ).isEqualTo( TemporalType.DATE ); } @Test public void testEnumerated() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm19.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Enumerated.class ) ).isTrue(); - final AnnotationUsage enumeratedUsage = memberDetails.getAnnotationUsage( Enumerated.class ); - assertThat( enumeratedUsage.getEnum( "value", EnumType.class ) ).isEqualTo( EnumType.STRING ); + assertThat( memberDetails.hasDirectAnnotationUsage( Enumerated.class ) ).isTrue(); + final Enumerated enumeratedUsage = memberDetails.getDirectAnnotationUsage( Enumerated.class ); + assertThat( enumeratedUsage.value() ).isEqualTo( EnumType.STRING ); } @Test public void testLob() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm20.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Lob.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( Lob.class ) ).isTrue(); } /** @@ -438,57 +436,58 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase { @Test public void testSingleAttributeOverride() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm21.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverrides.class ) ).isTrue(); - final AnnotationUsage overrideUsage = memberDetails.getAnnotationUsage( AttributeOverride.class ); - assertThat( overrideUsage.getString( "name" ) ).isEqualTo( "value.field1" ); + final AttributeOverrides overridesUsage = memberDetails.getDirectAnnotationUsage( AttributeOverrides.class ); + final AttributeOverride overrideUsage = overridesUsage.value()[0]; + assertThat( overrideUsage.name() ).isEqualTo( "value.field1" ); - final AnnotationUsage overrideColumnUsage = overrideUsage.getNestedUsage( "column" ); - assertThat( overrideColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); + final Column overrideColumnUsage = overrideUsage.column(); + assertThat( overrideColumnUsage.name() ).isEqualTo( "col1" ); } @Test public void testMultipleAttributeOverrides() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm22.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverrides.class ) ).isTrue(); - final AnnotationUsage overridesUsage = memberDetails.getAnnotationUsage( AttributeOverrides.class ); - final List> overrideUsages = overridesUsage.getList( "value" ); + final AttributeOverrides overridesUsage = memberDetails.getDirectAnnotationUsage( AttributeOverrides.class ); + final AttributeOverride[] overrideUsages = overridesUsage.value(); assertThat( overrideUsages ).hasSize( 2 ); - final AnnotationUsage overrideUsage0 = overrideUsages.get( 0 ); - assertThat( overrideUsage0.getString( "name" ) ).isEqualTo( "value.field1" ); - final AnnotationUsage overrideColumnUsage0 = overrideUsage0.getNestedUsage( "column" ); - assertThat( overrideColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( overrideColumnUsage0.getBoolean( "unique" ) ).isFalse(); - assertThat( overrideColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( overrideColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( overrideColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( overrideColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( overrideColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( overrideColumnUsage0.getInteger( "length" ) ).isEqualTo( 255 ); - assertThat( overrideColumnUsage0.getInteger( "precision" ) ).isEqualTo( 0 ); - assertThat( overrideColumnUsage0.getInteger( "scale" ) ).isEqualTo( 0 ); + final AttributeOverride overrideUsage0 = overrideUsages[0]; + assertThat( overrideUsage0.name() ).isEqualTo( "value.field1" ); + final Column overrideColumnUsage0 = overrideUsage0.column(); + assertThat( overrideColumnUsage0.name() ).isEmpty(); + assertThat( overrideColumnUsage0.unique() ).isFalse(); + assertThat( overrideColumnUsage0.nullable() ).isTrue(); + assertThat( overrideColumnUsage0.insertable() ).isTrue(); + assertThat( overrideColumnUsage0.updatable() ).isTrue(); + assertThat( overrideColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( overrideColumnUsage0.table() ).isEmpty(); + assertThat( overrideColumnUsage0.length() ).isEqualTo( 255 ); + assertThat( overrideColumnUsage0.precision() ).isEqualTo( 0 ); + assertThat( overrideColumnUsage0.scale() ).isEqualTo( 0 ); - final AnnotationUsage overrideUsage1 = overrideUsages.get( 1 ); - assertThat( overrideUsage1.getString( "name" ) ).isEqualTo( "value.field2" ); - final AnnotationUsage overrideColumnUsage1 = overrideUsage1.getNestedUsage( "column" ); - assertThat( overrideColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( overrideColumnUsage1.getBoolean( "unique" ) ).isTrue(); - assertThat( overrideColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( overrideColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( overrideColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( overrideColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( overrideColumnUsage1.getString( "table" ) ).isEqualTo( "table1" ); - assertThat( overrideColumnUsage1.getInteger( "length" ) ).isEqualTo( 50 ); - assertThat( overrideColumnUsage1.getInteger( "precision" ) ).isEqualTo( 2 ); - assertThat( overrideColumnUsage1.getInteger( "scale" ) ).isEqualTo( 1 ); + final AttributeOverride overrideUsage1 = overrideUsages[1]; + assertThat( overrideUsage1.name() ).isEqualTo( "value.field2" ); + final Column overrideColumnUsage1 = overrideUsage1.column(); + assertThat( overrideColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( overrideColumnUsage1.unique() ).isTrue(); + assertThat( overrideColumnUsage1.nullable() ).isFalse(); + assertThat( overrideColumnUsage1.insertable() ).isFalse(); + assertThat( overrideColumnUsage1.updatable() ).isFalse(); + assertThat( overrideColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( overrideColumnUsage1.table() ).isEqualTo( "table1" ); + assertThat( overrideColumnUsage1.length() ).isEqualTo( 50 ); + assertThat( overrideColumnUsage1.precision() ).isEqualTo( 2 ); + assertThat( overrideColumnUsage1.scale() ).isEqualTo( 1 ); } /** @@ -498,24 +497,24 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase { @Test public void testMixedAttributeOverrides() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm23.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AttributeOverrides.class ) ).isTrue(); - final AnnotationUsage overridesUsage = memberDetails.getAnnotationUsage( AttributeOverrides.class ); - final List> overrideUsages = overridesUsage.getList( "value" ); + final AttributeOverrides overridesUsage = memberDetails.getDirectAnnotationUsage( AttributeOverrides.class ); + final AttributeOverride[] overrideUsages = overridesUsage.value(); assertThat( overrideUsages ).hasSize( 2 ); - final AnnotationUsage overrideUsage0 = overrideUsages.get( 0 ); - assertThat( overrideUsage0.getString( "name" ) ).isEqualTo( "key.field1" ); - final AnnotationUsage overrideColumnUsage0 = overrideUsage0.getNestedUsage( "column" ); - assertThat( overrideColumnUsage0.getString( "name" ) ).isEqualTo( "col1" ); + final AttributeOverride overrideUsage0 = overrideUsages[0]; + assertThat( overrideUsage0.name() ).isEqualTo( "key.field1" ); + final Column overrideColumnUsage0 = overrideUsage0.column(); + assertThat( overrideColumnUsage0.name() ).isEqualTo( "col1" ); - final AnnotationUsage overrideUsage1 = overrideUsages.get( 1 ); - assertThat( overrideUsage1.getString( "name" ) ).isEqualTo( "value.field2" ); - final AnnotationUsage overrideColumnUsage1 = overrideUsage1.getNestedUsage( "column" ); - assertThat( overrideColumnUsage1.getString( "name" ) ).isEqualTo( "col2" ); + final AttributeOverride overrideUsage1 = overrideUsages[1]; + assertThat( overrideUsage1.name() ).isEqualTo( "value.field2" ); + final Column overrideColumnUsage1 = overrideUsage1.column(); + assertThat( overrideColumnUsage1.name() ).isEqualTo( "col2" ); } /** @@ -525,210 +524,211 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase { @Test public void testSingleAssociationOverride() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm24.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( AssociationOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AssociationOverrides.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( AssociationOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AssociationOverrides.class ) ).isTrue(); - final AnnotationUsage overrideUsage = memberDetails.getAnnotationUsage( AssociationOverride.class ); - assertThat( overrideUsage.getString( "name" ) ).isEqualTo( "association1" ); - assertThat( overrideUsage.getList( "joinColumns" ) ).isEmpty(); - final AnnotationUsage joinTableUsage = overrideUsage.getNestedUsage( "joinTable" ); - assertThat( joinTableUsage.getString( "name" ) ).isEmpty(); + final AssociationOverrides overridesUsage = memberDetails.getDirectAnnotationUsage( AssociationOverrides.class ); + final AssociationOverride overrideUsage = overridesUsage.value()[0]; + assertThat( overrideUsage.name() ).isEqualTo( "association1" ); + assertThat( overrideUsage.joinColumns() ).isEmpty(); + final JoinTable joinTableUsage = overrideUsage.joinTable(); + assertThat( joinTableUsage.name() ).isEmpty(); } @Test public void testMultipleAssociationOverridesJoinColumns() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm25.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( AssociationOverride.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( AssociationOverrides.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( AssociationOverride.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( AssociationOverrides.class ) ).isTrue(); - final AnnotationUsage overridesUsage = memberDetails.getAnnotationUsage( AssociationOverrides.class ); - final List> overrideUsages = overridesUsage.getList( "value" ); + final AssociationOverrides overridesUsage = memberDetails.getDirectAnnotationUsage( AssociationOverrides.class ); + final AssociationOverride[] overrideUsages = overridesUsage.value(); assertThat( overrideUsages ).hasSize( 2 ); { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // First, an association using join table - final AnnotationUsage overrideUsage = overrideUsages.get( 0 ); - assertThat( overrideUsage.getString( "name" ) ).isEqualTo( "association1" ); - assertThat( overrideUsage.getList( "joinColumns" ) ).isEmpty(); + final AssociationOverride overrideUsage = overrideUsages[0]; + assertThat( overrideUsage.name() ).isEqualTo( "association1" ); + assertThat( overrideUsage.joinColumns() ).isEmpty(); - AnnotationUsage joinTableUsage = overrideUsage.getNestedUsage( "joinTable" ); - assertThat( joinTableUsage.getString( "catalog" ) ).isEqualTo( "catalog1" ); - assertThat( joinTableUsage.getString( "name" ) ).isEqualTo( "table1" ); - assertThat( joinTableUsage.getString( "schema" ) ).isEqualTo( "schema1" ); + JoinTable joinTableUsage = overrideUsage.joinTable(); + assertThat( joinTableUsage.name() ).isEqualTo( "table1" ); + assertThat( joinTableUsage.catalog() ).isEqualTo( "catalog1" ); + assertThat( joinTableUsage.schema() ).isEqualTo( "schema1" ); //JoinColumns - final List> joinColumUsages = joinTableUsage.getList( "joinColumns" ); + final JoinColumn[] joinColumUsages = joinTableUsage.joinColumns(); assertThat( joinColumUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn joinColumnUsage0 = joinColumUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.nullable() ).isTrue(); + assertThat( joinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage joinColumnUsage1 = joinColumUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table2" ); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn joinColumnUsage1 = joinColumUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table2" ); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.nullable() ).isFalse(); + assertThat( joinColumnUsage1.unique() ).isTrue(); //InverseJoinColumns - final List> inverseJoinColumnUsages = joinTableUsage.getList( "inverseJoinColumns" ); + final JoinColumn[] inverseJoinColumnUsages = joinTableUsage.inverseJoinColumns(); assertThat( inverseJoinColumnUsages ).hasSize( 2 ); - final AnnotationUsage inverseJoinColumnUsage0 = inverseJoinColumnUsages.get( 0 ); - assertThat( inverseJoinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn inverseJoinColumnUsage0 = inverseJoinColumnUsages[0]; + assertThat( inverseJoinColumnUsage0.name() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.table() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.insertable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.updatable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.nullable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage inverseJoinColumnUsage1 = inverseJoinColumnUsages.get( 1 ); - assertThat( inverseJoinColumnUsage1.getString( "name" ) ).isEqualTo( "col3" ); - assertThat( inverseJoinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col4" ); - assertThat( inverseJoinColumnUsage1.getString( "table" ) ).isEqualTo( "table3" ); - assertThat( inverseJoinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( inverseJoinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn inverseJoinColumnUsage1 = inverseJoinColumnUsages[1]; + assertThat( inverseJoinColumnUsage1.name() ).isEqualTo( "col3" ); + assertThat( inverseJoinColumnUsage1.referencedColumnName() ).isEqualTo( "col4" ); + assertThat( inverseJoinColumnUsage1.table() ).isEqualTo( "table3" ); + assertThat( inverseJoinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( inverseJoinColumnUsage1.insertable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.updatable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.nullable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.unique() ).isTrue(); //UniqueConstraints - final List> uniqueConstraintUsages = joinTableUsage.getList( "uniqueConstraints" ); + final UniqueConstraint[] uniqueConstraintUsages = joinTableUsage.uniqueConstraints(); assertThat( uniqueConstraintUsages ).hasSize( 2 ); - final AnnotationUsage uniqueConstraintUsage0 = uniqueConstraintUsages.get( 0 ); - assertThat( uniqueConstraintUsage0.getString( "name" ) ).isEmpty(); - assertThat( uniqueConstraintUsage0.getList( "columnNames" ) ).containsOnly( "col5" ); + final UniqueConstraint uniqueConstraintUsage0 = uniqueConstraintUsages[0]; + assertThat( uniqueConstraintUsage0.name() ).isEmpty(); + assertThat( uniqueConstraintUsage0.columnNames() ).containsOnly( "col5" ); - final AnnotationUsage uniqueConstraintUsage1 = uniqueConstraintUsages.get( 1 ); - assertThat( uniqueConstraintUsage1.getString( "name" ) ).isEqualTo( "uq1" ); - assertThat( uniqueConstraintUsage1.getList( "columnNames" ) ).containsOnly( "col6", "col7" ); + final UniqueConstraint uniqueConstraintUsage1 = uniqueConstraintUsages[1]; + assertThat( uniqueConstraintUsage1.name() ).isEqualTo( "uq1" ); + assertThat( uniqueConstraintUsage1.columnNames() ).containsOnly( "col6", "col7" ); } { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Second, an association using join columns - final AnnotationUsage overrideUsage = overrideUsages.get( 1 ); - assertThat( overrideUsage.getString( "name" ) ).isEqualTo( "association2" ); + final AssociationOverride overrideUsage = overrideUsages[1]; + assertThat( overrideUsage.name() ).isEqualTo( "association2" ); //JoinColumns - final List> joinColumUsages = overrideUsage.getList( "joinColumns" ); + final JoinColumn[] joinColumUsages = overrideUsage.joinColumns(); assertThat( joinColumUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn joinColumnUsage0 = joinColumUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.nullable() ).isTrue(); + assertThat( joinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage joinColumnUsage1 = joinColumUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col8" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col9" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table4" ); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn joinColumnUsage1 = joinColumUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col8" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col9" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table4" ); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.nullable() ).isFalse(); + assertThat( joinColumnUsage1.unique() ).isTrue(); } } @Test public void testCollectionTableNoChildren() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm26.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( CollectionTable.class ) ).isTrue(); - final AnnotationUsage collectionTableUsage = memberDetails.getAnnotationUsage( CollectionTable.class ); - assertThat( collectionTableUsage.getString( "name" ) ).isEmpty(); - assertThat( collectionTableUsage.getString( "catalog" ) ).isEmpty(); - assertThat( collectionTableUsage.getString( "schema" ) ).isEmpty(); - assertThat( collectionTableUsage.getList( "joinColumns" ) ).isEmpty(); - assertThat( collectionTableUsage.getList( "uniqueConstraints" ) ).isEmpty(); + assertThat( memberDetails.hasDirectAnnotationUsage( CollectionTable.class ) ).isTrue(); + final CollectionTable collectionTableUsage = memberDetails.getDirectAnnotationUsage( CollectionTable.class ); + assertThat( collectionTableUsage.name() ).isEmpty(); + assertThat( collectionTableUsage.catalog() ).isEmpty(); + assertThat( collectionTableUsage.schema() ).isEmpty(); + assertThat( collectionTableUsage.joinColumns() ).isEmpty(); + assertThat( collectionTableUsage.uniqueConstraints() ).isEmpty(); } @Test public void testCollectionTableAllChildren() { final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm27.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( CollectionTable.class ) ).isTrue(); - final AnnotationUsage collectionTableUsage = memberDetails.getAnnotationUsage( CollectionTable.class ); - assertThat( collectionTableUsage.getString( "name" ) ).isEqualTo( "table1" ); - assertThat( collectionTableUsage.getString( "catalog" ) ).isEqualTo( "catalog1" ); - assertThat( collectionTableUsage.getString( "schema" ) ).isEqualTo( "schema1" ); + assertThat( memberDetails.hasDirectAnnotationUsage( CollectionTable.class ) ).isTrue(); + final CollectionTable collectionTableUsage = memberDetails.getDirectAnnotationUsage( CollectionTable.class ); + assertThat( collectionTableUsage.name() ).isEqualTo( "table1" ); + assertThat( collectionTableUsage.catalog() ).isEqualTo( "catalog1" ); + assertThat( collectionTableUsage.schema() ).isEqualTo( "schema1" ); //JoinColumns - final List> joinColumnUsages = collectionTableUsage.getList( "joinColumns" ); + final JoinColumn[] joinColumnUsages = collectionTableUsage.joinColumns(); assertThat( joinColumnUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumnUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn joinColumnUsage0 = joinColumnUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.nullable() ).isTrue(); + assertThat( joinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage joinColumnUsage1 = joinColumnUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table2" ); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn joinColumnUsage1 = joinColumnUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table2" ); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.nullable() ).isFalse(); + assertThat( joinColumnUsage1.unique() ).isTrue(); //UniqueConstraints - final List> uniqueConstraintUsages = collectionTableUsage.getList( "uniqueConstraints" ); + final UniqueConstraint[] uniqueConstraintUsages = collectionTableUsage.uniqueConstraints(); assertThat( uniqueConstraintUsages ).hasSize( 2 ); - final AnnotationUsage uniqueConstraintUsage0 = uniqueConstraintUsages.get( 0 ); - assertThat( uniqueConstraintUsage0.getString( "name" ) ).isEmpty(); - assertThat( uniqueConstraintUsage0.getList( "columnNames" ) ).containsOnly( "col3" ); + final UniqueConstraint uniqueConstraintUsage0 = uniqueConstraintUsages[0]; + assertThat( uniqueConstraintUsage0.name() ).isEmpty(); + assertThat( uniqueConstraintUsage0.columnNames() ).containsOnly( "col3" ); - final AnnotationUsage uniqueConstraintUsage1 = uniqueConstraintUsages.get( 1 ); - assertThat( uniqueConstraintUsage1.getString( "name" ) ).isEqualTo( "uq1" ); - assertThat( uniqueConstraintUsage1.getList( "columnNames" ) ).containsOnly( "col4", "col5" ); + final UniqueConstraint uniqueConstraintUsage1 = uniqueConstraintUsages[1]; + assertThat( uniqueConstraintUsage1.name() ).isEqualTo( "uq1" ); + assertThat( uniqueConstraintUsage1.columnNames() ).containsOnly( "col4", "col5" ); } @Test public void testAllAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity2.class, "field1", "element-collection.orm28.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ElementCollection.class ) ).isTrue(); - final AnnotationUsage elementCollectionUsage = memberDetails.getAnnotationUsage( ElementCollection.class ); - assertThat( elementCollectionUsage.getEnum( "fetch", FetchType.class ) ).isEqualTo( FetchType.EAGER ); + final ElementCollection elementCollectionUsage = memberDetails.getDirectAnnotationUsage( ElementCollection.class ); + assertThat( elementCollectionUsage.fetch() ).isEqualTo( FetchType.EAGER ); - final AnnotationUsage accessUsage = memberDetails.getAnnotationUsage( Access.class ); - assertThat( accessUsage.getEnum( "value", AccessType.class ) ).isEqualTo( AccessType.PROPERTY ); + final Access accessUsage = memberDetails.getDirectAnnotationUsage( Access.class ); + assertThat( accessUsage.value() ).isEqualTo( AccessType.PROPERTY ); - final AnnotationUsage targetUsage = memberDetails.getAnnotationUsage( Target.class ); - assertThat( targetUsage.getString( "value" ) ).isEqualTo( Entity3.class.getName() ); + final Target targetUsage = memberDetails.getDirectAnnotationUsage( Target.class ); + assertThat( targetUsage.value() ).isEqualTo( Entity3.class.getName() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlManyToOneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlManyToOneTest.java index 36472f624d..875c5a87a8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlManyToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlManyToOneTest.java @@ -6,13 +6,9 @@ */ package org.hibernate.orm.test.annotations.xml.ejb3; -import java.util.List; - import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; import org.hibernate.boot.internal.Target; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.testing.orm.junit.JiraKey; @@ -36,19 +32,19 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase { @Test public void testNoJoins() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm1.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); - final AnnotationUsage manyToOneUsage = memberDetails.getAnnotationUsage( ManyToOne.class ); - assertThat( manyToOneUsage.getList( "cascade" ) ).isEmpty(); - assertThat( manyToOneUsage.getEnum( "fetch", FetchType.class ) ).isEqualTo( FetchType.EAGER ); - assertThat( manyToOneUsage.getBoolean( "optional" ) ).isTrue(); - assertThat( manyToOneUsage.getClassDetails( "targetEntity" ) ).isEqualTo( ClassDetails.VOID_CLASS_DETAILS ); + final ManyToOne manyToOneUsage = memberDetails.getDirectAnnotationUsage( ManyToOne.class ); + assertThat( manyToOneUsage.cascade() ).isEmpty(); + assertThat( manyToOneUsage.fetch() ).isEqualTo( FetchType.EAGER ); + assertThat( manyToOneUsage.optional() ).isTrue(); + assertThat( manyToOneUsage.targetEntity() ).isEqualTo( void.class ); } /** @@ -58,201 +54,202 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase { @Test public void testSingleJoinColumn() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm2.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); - final AnnotationUsage joinColumnUsage = memberDetails.getAnnotationUsage( JoinColumn.class ); - assertThat( joinColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage.getString( "table" ) ).isEqualTo( "table1" ); + final JoinColumns joinColumnsUsage = memberDetails.getDirectAnnotationUsage( JoinColumns.class ); + final JoinColumn joinColumnUsage = joinColumnsUsage.value()[0]; + assertThat( joinColumnUsage.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage.table() ).isEqualTo( "table1" ); } @Test public void testMultipleJoinColumns() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm3.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); - final AnnotationUsage joinColumnsUsage = memberDetails.getAnnotationUsage( JoinColumns.class ); - final List> joinColumnUsages = joinColumnsUsage.getList( "value" ); + final JoinColumns joinColumnsUsage = memberDetails.getDirectAnnotationUsage( JoinColumns.class ); + final JoinColumn[] joinColumnUsages = joinColumnsUsage.value(); assertThat( joinColumnUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumnUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn joinColumnUsage0 = joinColumnUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.nullable() ).isTrue(); + assertThat( joinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage joinColumnUsage1 = joinColumnUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table1" ); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn joinColumnUsage1 = joinColumnUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table1" ); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.nullable() ).isFalse(); + assertThat( joinColumnUsage1.unique() ).isTrue(); } @Test public void testJoinTableNoChildren() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm4.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); - final AnnotationUsage joinTableUsage = memberDetails.getAnnotationUsage( JoinTable.class ); - assertThat( joinTableUsage.getString( "catalog" ) ).isEmpty(); - assertThat( joinTableUsage.getString( "schema" ) ).isEmpty(); - assertThat( joinTableUsage.getString( "name" ) ).isEmpty(); - assertThat( joinTableUsage.getList( "joinColumns" ) ).isEmpty(); - assertThat( joinTableUsage.getList( "inverseJoinColumns" ) ).isEmpty(); - assertThat( joinTableUsage.getList( "uniqueConstraints" ) ).isEmpty(); + final JoinTable joinTableUsage = memberDetails.getDirectAnnotationUsage( JoinTable.class ); + assertThat( joinTableUsage.catalog() ).isEmpty(); + assertThat( joinTableUsage.schema() ).isEmpty(); + assertThat( joinTableUsage.name() ).isEmpty(); + assertThat( joinTableUsage.joinColumns() ).isEmpty(); + assertThat( joinTableUsage.inverseJoinColumns() ).isEmpty(); + assertThat( joinTableUsage.uniqueConstraints() ).isEmpty(); } @Test public void testJoinTableAllChildren() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm5.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); - final AnnotationUsage joinTableUsage = memberDetails.getAnnotationUsage( JoinTable.class ); - assertThat( joinTableUsage.getString( "catalog" ) ).isEqualTo( "cat1" ); - assertThat( joinTableUsage.getString( "schema" ) ).isEqualTo( "schema1" ); - assertThat( joinTableUsage.getString( "name" ) ).isEqualTo( "table1" ); + final JoinTable joinTableUsage = memberDetails.getDirectAnnotationUsage( JoinTable.class ); + assertThat( joinTableUsage.catalog() ).isEqualTo( "cat1" ); + assertThat( joinTableUsage.schema() ).isEqualTo( "schema1" ); + assertThat( joinTableUsage.name() ).isEqualTo( "table1" ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // JoinColumns - final List> joinColumnUsages = joinTableUsage.getList( "joinColumns" ); + final JoinColumn[] joinColumnUsages = joinTableUsage.joinColumns(); assertThat( joinColumnUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumnUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn joinColumnUsage0 = joinColumnUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.nullable() ).isTrue(); + assertThat( joinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage joinColumnUsage1 = joinColumnUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table2" ); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn joinColumnUsage1 = joinColumnUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table2" ); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.nullable() ).isFalse(); + assertThat( joinColumnUsage1.unique() ).isTrue(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // InverseJoinColumns - final List> inverseJoinColumnUsages = joinTableUsage.getList( "inverseJoinColumns" ); + final JoinColumn[] inverseJoinColumnUsages = joinTableUsage.inverseJoinColumns(); assertThat( inverseJoinColumnUsages ).hasSize( 2 ); - final AnnotationUsage inverseJoinColumnUsage0 = inverseJoinColumnUsages.get( 0 ); - assertThat( inverseJoinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn inverseJoinColumnUsage0 = inverseJoinColumnUsages[0]; + assertThat( inverseJoinColumnUsage0.name() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.table() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.insertable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.updatable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.nullable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage inverseJoinColumnUsage1 = inverseJoinColumnUsages.get( 1 ); - assertThat( inverseJoinColumnUsage1.getString( "name" ) ).isEqualTo( "col3" ); - assertThat( inverseJoinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col4" ); - assertThat( inverseJoinColumnUsage1.getString( "table" ) ).isEqualTo( "table3" ); - assertThat( inverseJoinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( inverseJoinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn inverseJoinColumnUsage1 = inverseJoinColumnUsages[1]; + assertThat( inverseJoinColumnUsage1.name() ).isEqualTo( "col3" ); + assertThat( inverseJoinColumnUsage1.referencedColumnName() ).isEqualTo( "col4" ); + assertThat( inverseJoinColumnUsage1.table() ).isEqualTo( "table3" ); + assertThat( inverseJoinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( inverseJoinColumnUsage1.insertable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.updatable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.nullable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.unique() ).isTrue(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // UniqueConstraints - final List> uniqueConstraintUsages = joinTableUsage.getList( "uniqueConstraints" ); + final UniqueConstraint[] uniqueConstraintUsages = joinTableUsage.uniqueConstraints(); assertThat( uniqueConstraintUsages ).hasSize( 2 ); - final AnnotationUsage uniqueConstraintUsage0 = uniqueConstraintUsages.get( 0 ); - assertThat( uniqueConstraintUsage0.getString( "name" ) ).isEmpty(); - assertThat( uniqueConstraintUsage0.getList( "columnNames" ) ).containsExactly( "col5" ); + final UniqueConstraint uniqueConstraintUsage0 = uniqueConstraintUsages[0]; + assertThat( uniqueConstraintUsage0.name() ).isEmpty(); + assertThat( uniqueConstraintUsage0.columnNames() ).containsExactly( "col5" ); - final AnnotationUsage uniqueConstraintUsage1 = uniqueConstraintUsages.get( 1 ); - assertThat( uniqueConstraintUsage1.getString( "name" ) ).isEqualTo( "uq1" ); - assertThat( uniqueConstraintUsage1.getList( "columnNames" ) ).containsExactly( "col6", "col7" ); + final UniqueConstraint uniqueConstraintUsage1 = uniqueConstraintUsages[1]; + assertThat( uniqueConstraintUsage1.name() ).isEqualTo( "uq1" ); + assertThat( uniqueConstraintUsage1.columnNames() ).containsExactly( "col6", "col7" ); } @Test public void testAllAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm6.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Access.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( Access.class ) ).isTrue(); - final AnnotationUsage manyToOneUsage = memberDetails.getAnnotationUsage( ManyToOne.class ); - assertThat( manyToOneUsage.getList( "cascade" ) ).isEmpty(); - assertThat( manyToOneUsage.getEnum( "fetch", FetchType.class ) ).isEqualTo( FetchType.LAZY ); - assertThat( manyToOneUsage.getBoolean( "optional" ) ).isFalse(); - assertThat( manyToOneUsage.getClassDetails( "targetEntity" ) ).isEqualTo( ClassDetails.VOID_CLASS_DETAILS ); + final ManyToOne manyToOneUsage = memberDetails.getDirectAnnotationUsage( ManyToOne.class ); + assertThat( manyToOneUsage.cascade() ).isEmpty(); + assertThat( manyToOneUsage.fetch() ).isEqualTo( FetchType.LAZY ); + assertThat( manyToOneUsage.optional() ).isFalse(); + assertThat( manyToOneUsage.targetEntity() ).isEqualTo( void.class ); - final AnnotationUsage targetUsage = memberDetails.getAnnotationUsage( Target.class ); - assertThat( targetUsage.getString( "value" ) ).isEqualTo( Entity3.class.getName() ); + final Target targetUsage = memberDetails.getDirectAnnotationUsage( Target.class ); + assertThat( targetUsage.value() ).isEqualTo( Entity3.class.getName() ); - final AnnotationUsage mapsIdUsage = memberDetails.getAnnotationUsage( MapsId.class ); - assertThat( mapsIdUsage.getString( "value" ) ).isEqualTo( "col1" ); + final MapsId mapsIdUsage = memberDetails.getDirectAnnotationUsage( MapsId.class ); + assertThat( mapsIdUsage.value() ).isEqualTo( "col1" ); - final AnnotationUsage accessUsage = memberDetails.getAnnotationUsage( Access.class ); - assertThat( accessUsage.getEnum( "value", AccessType.class ) ).isEqualTo( AccessType.PROPERTY ); + final Access accessUsage = memberDetails.getDirectAnnotationUsage( Access.class ); + assertThat( accessUsage.value() ).isEqualTo( AccessType.PROPERTY ); } @Test public void testCascadeAll() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm7.xml" ); - assertThat( memberDetails.hasAnnotationUsage( ManyToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( ManyToOne.class ) ).isTrue(); - final AnnotationUsage manyToOneUsage = memberDetails.getAnnotationUsage( ManyToOne.class ); - assertThat( manyToOneUsage.getList( "cascade" ) ).isEmpty(); + final ManyToOne manyToOneUsage = memberDetails.getDirectAnnotationUsage( ManyToOne.class ); + assertThat( manyToOneUsage.cascade() ).isEmpty(); - final AnnotationUsage cascadeUsage = memberDetails.getAnnotationUsage( Cascade.class ); - assertThat( cascadeUsage.getList( "value" ) ).containsExactly( CascadeType.ALL ); + final Cascade cascadeUsage = memberDetails.getDirectAnnotationUsage( Cascade.class ); + assertThat( cascadeUsage.value() ).containsExactly( CascadeType.ALL ); } @Test public void testCascadeSomeWithDefaultPersist() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm8.xml" ); - final AnnotationUsage manyToOneUsage = memberDetails.getAnnotationUsage( ManyToOne.class ); - assertThat( manyToOneUsage.getList( "cascade" ) ).isEmpty(); + final ManyToOne manyToOneUsage = memberDetails.getDirectAnnotationUsage( ManyToOne.class ); + assertThat( manyToOneUsage.cascade() ).isEmpty(); - final AnnotationUsage cascadeUsage = memberDetails.getAnnotationUsage( Cascade.class ); - assertThat( cascadeUsage.getList( "value" ) ).containsOnly( + final Cascade cascadeUsage = memberDetails.getDirectAnnotationUsage( Cascade.class ); + assertThat( cascadeUsage.value() ).containsOnly( CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH, @@ -268,11 +265,11 @@ public class Ejb3XmlManyToOneTest extends Ejb3XmlTestCase { @Test public void testCascadeAllPlusMore() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "many-to-one.orm9.xml" ); - final AnnotationUsage manyToOneUsage = memberDetails.getAnnotationUsage( ManyToOne.class ); - assertThat( manyToOneUsage.getList( "cascade" ) ).isEmpty(); + final ManyToOne manyToOneUsage = memberDetails.getDirectAnnotationUsage( ManyToOne.class ); + assertThat( manyToOneUsage.cascade() ).isEmpty(); - final AnnotationUsage cascadeUsage = memberDetails.getAnnotationUsage( Cascade.class ); - assertThat( cascadeUsage.getList( "value" ) ).containsOnly( + final Cascade cascadeUsage = memberDetails.getDirectAnnotationUsage( Cascade.class ); + assertThat( cascadeUsage.value() ).containsOnly( CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlOneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlOneToOneTest.java index a4d3a2a65f..79fb09b9fe 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlOneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlOneToOneTest.java @@ -6,13 +6,9 @@ */ package org.hibernate.orm.test.annotations.xml.ejb3; -import java.util.List; - import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; import org.hibernate.boot.internal.Target; -import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; import org.hibernate.testing.orm.junit.JiraKey; @@ -38,23 +34,23 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase { @Test public void testNoChildren() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm1.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); - final AnnotationUsage oneToOneUsage = memberDetails.getAnnotationUsage( OneToOne.class ); - assertThat( oneToOneUsage.getList( "cascade" ) ).isEmpty(); - assertThat( oneToOneUsage.getEnum( "fetch", FetchType.class ) ).isEqualTo( FetchType.EAGER ); - assertThat( oneToOneUsage.getString( "mappedBy" ) ).isEmpty(); - assertThat( oneToOneUsage.getBoolean( "optional" ) ).isTrue(); - assertThat( oneToOneUsage.getBoolean( "orphanRemoval" ) ).isFalse(); - assertThat( oneToOneUsage.getClassDetails( "targetEntity" ) ).isEqualTo( ClassDetails.VOID_CLASS_DETAILS ); + final OneToOne oneToOneUsage = memberDetails.getDirectAnnotationUsage( OneToOne.class ); + assertThat( oneToOneUsage.cascade() ).isEmpty(); + assertThat( oneToOneUsage.fetch() ).isEqualTo( FetchType.EAGER ); + assertThat( oneToOneUsage.mappedBy() ).isEmpty(); + assertThat( oneToOneUsage.optional() ).isTrue(); + assertThat( oneToOneUsage.orphanRemoval() ).isFalse(); + assertThat( oneToOneUsage.targetEntity() ).isEqualTo( void.class ); } /** @@ -64,51 +60,51 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase { @Test public void testSinglePrimaryKeyJoinColumn() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm2.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); - final AnnotationUsage pkJoinColumnsUsage = memberDetails.getAnnotationUsage( PrimaryKeyJoinColumns.class ); - final List> pkJoinColumnUsages = pkJoinColumnsUsage.getList( "value" ); + final PrimaryKeyJoinColumns pkJoinColumnsUsage = memberDetails.getDirectAnnotationUsage( PrimaryKeyJoinColumns.class ); + final PrimaryKeyJoinColumn[] pkJoinColumnUsages = pkJoinColumnsUsage.value(); assertThat( pkJoinColumnUsages ).hasSize( 1 ); - final AnnotationUsage pkJoinColumnUsage = pkJoinColumnUsages.get( 0 ); - assertThat( pkJoinColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( pkJoinColumnUsage.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( pkJoinColumnUsage.getString( "columnDefinition" ) ).isEqualTo( "int" ); + final PrimaryKeyJoinColumn pkJoinColumnUsage = pkJoinColumnUsages[0]; + assertThat( pkJoinColumnUsage.name() ).isEqualTo( "col1" ); + assertThat( pkJoinColumnUsage.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( pkJoinColumnUsage.columnDefinition() ).isEqualTo( "int" ); } @Test public void testMultiplePrimaryKeyJoinColumn() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm3.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); - final AnnotationUsage pkJoinColumnsUsage = memberDetails.getAnnotationUsage( PrimaryKeyJoinColumns.class ); - final List> pkJoinColumnUsages = pkJoinColumnsUsage.getList( "value" ); + final PrimaryKeyJoinColumns pkJoinColumnsUsage = memberDetails.getDirectAnnotationUsage( PrimaryKeyJoinColumns.class ); + final PrimaryKeyJoinColumn[] pkJoinColumnUsages = pkJoinColumnsUsage.value(); assertThat( pkJoinColumnUsages ).hasSize( 2 ); - final AnnotationUsage pkJoinColumnUsage0 = pkJoinColumnUsages.get( 0 ); - assertThat( pkJoinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( pkJoinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( pkJoinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); + final PrimaryKeyJoinColumn pkJoinColumnUsage0 = pkJoinColumnUsages[0]; + assertThat( pkJoinColumnUsage0.name() ).isEmpty(); + assertThat( pkJoinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( pkJoinColumnUsage0.columnDefinition() ).isEmpty(); - final AnnotationUsage pkJoinColumnUsage1 = pkJoinColumnUsages.get( 1 ); - assertThat( pkJoinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( pkJoinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( pkJoinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); + final PrimaryKeyJoinColumn pkJoinColumnUsage1 = pkJoinColumnUsages[1]; + assertThat( pkJoinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( pkJoinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( pkJoinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); } /** @@ -118,185 +114,187 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase { @Test public void testSingleJoinColumn() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm4.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); - final AnnotationUsage joinColumnUsage = memberDetails.getAnnotationUsage( JoinColumn.class ); - assertThat( joinColumnUsage.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage.getString( "table" ) ).isEqualTo( "table1" ); + final JoinColumns joinColumnsUsage = memberDetails.getDirectAnnotationUsage( JoinColumns.class ); + assertThat( joinColumnsUsage.value() ).hasSize( 1 ); + final JoinColumn joinColumnUsage = joinColumnsUsage.value()[0]; + assertThat( joinColumnUsage.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage.table() ).isEqualTo( "table1" ); } @Test public void testMultipleJoinColumns(){ final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm5.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isFalse(); - final AnnotationUsage joinColumnsUsage = memberDetails.getAnnotationUsage( JoinColumns.class ); - final List> joinColumnUsages = joinColumnsUsage.getList( "value" ); + final JoinColumns joinColumnsUsage = memberDetails.getDirectAnnotationUsage( JoinColumns.class ); + final JoinColumn[] joinColumnUsages = joinColumnsUsage.value(); assertThat( joinColumnUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumnUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn joinColumnUsage0 = joinColumnUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.nullable() ).isTrue(); + assertThat( joinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage joinColumnUsage1 = joinColumnUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table1" ); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn joinColumnUsage1 = joinColumnUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table1" ); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.nullable() ).isFalse(); + assertThat( joinColumnUsage1.unique() ).isTrue(); } @Test public void testJoinTableNoChildren() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm6.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); - final AnnotationUsage joinTableUsage = memberDetails.getAnnotationUsage( JoinTable.class ); - assertThat( joinTableUsage.getString( "catalog" ) ).isEmpty(); - assertThat( joinTableUsage.getString( "schema" ) ).isEmpty(); - assertThat( joinTableUsage.getString( "name" ) ).isEmpty(); - assertThat( joinTableUsage.getList( "joinColumns" ) ).isEmpty(); - assertThat( joinTableUsage.getList( "inverseJoinColumns" ) ).isEmpty(); - assertThat( joinTableUsage.getList( "uniqueConstraints" ) ).isEmpty(); + final JoinTable joinTableUsage = memberDetails.getDirectAnnotationUsage( JoinTable.class ); + assertThat( joinTableUsage.catalog() ).isEmpty(); + assertThat( joinTableUsage.schema() ).isEmpty(); + assertThat( joinTableUsage.name() ).isEmpty(); + assertThat( joinTableUsage.joinColumns() ).isEmpty(); + assertThat( joinTableUsage.inverseJoinColumns() ).isEmpty(); + assertThat( joinTableUsage.uniqueConstraints() ).isEmpty(); } @Test public void testJoinTableAllChildren() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm7.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( JoinTable.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinTable.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumns.class ) ).isFalse(); - assertThat( memberDetails.hasAnnotationUsage( JoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( PrimaryKeyJoinColumn.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumns.class ) ).isFalse(); + assertThat( memberDetails.hasDirectAnnotationUsage( JoinColumn.class ) ).isFalse(); - final AnnotationUsage joinTableUsage = memberDetails.getAnnotationUsage( JoinTable.class ); - assertThat( joinTableUsage.getString( "catalog" ) ).isEqualTo( "cat1" ); - assertThat( joinTableUsage.getString( "schema" ) ).isEqualTo( "schema1" ); - assertThat( joinTableUsage.getString( "name" ) ).isEqualTo( "table1" ); + final JoinTable joinTableUsage = memberDetails.getDirectAnnotationUsage( JoinTable.class ); + assertThat( joinTableUsage.catalog() ).isEqualTo( "cat1" ); + assertThat( joinTableUsage.schema() ).isEqualTo( "schema1" ); + assertThat( joinTableUsage.name() ).isEqualTo( "table1" ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // JoinColumns - final List> joinColumnUsages = joinTableUsage.getList( "joinColumns" ); + final JoinColumn[] joinColumnUsages = joinTableUsage.joinColumns(); assertThat( joinColumnUsages ).hasSize( 2 ); - final AnnotationUsage joinColumnUsage0 = joinColumnUsages.get( 0 ); - assertThat( joinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( joinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( joinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( joinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn joinColumnUsage0 = joinColumnUsages[0]; + assertThat( joinColumnUsage0.name() ).isEmpty(); + assertThat( joinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( joinColumnUsage0.table() ).isEmpty(); + assertThat( joinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( joinColumnUsage0.insertable() ).isTrue(); + assertThat( joinColumnUsage0.updatable() ).isTrue(); + assertThat( joinColumnUsage0.nullable() ).isTrue(); + assertThat( joinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage joinColumnUsage1 = joinColumnUsages.get( 1 ); - assertThat( joinColumnUsage1.getString( "name" ) ).isEqualTo( "col1" ); - assertThat( joinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col2" ); - assertThat( joinColumnUsage1.getString( "table" ) ).isEqualTo( "table2" ); - assertThat( joinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( joinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( joinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn joinColumnUsage1 = joinColumnUsages[1]; + assertThat( joinColumnUsage1.name() ).isEqualTo( "col1" ); + assertThat( joinColumnUsage1.referencedColumnName() ).isEqualTo( "col2" ); + assertThat( joinColumnUsage1.table() ).isEqualTo( "table2" ); + assertThat( joinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( joinColumnUsage1.insertable() ).isFalse(); + assertThat( joinColumnUsage1.updatable() ).isFalse(); + assertThat( joinColumnUsage1.nullable() ).isFalse(); + assertThat( joinColumnUsage1.unique() ).isTrue(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // InverseJoinColumns - final List> inverseJoinColumnUsages = joinTableUsage.getList( "inverseJoinColumns" ); + final JoinColumn[] inverseJoinColumnUsages = joinTableUsage.inverseJoinColumns(); assertThat( inverseJoinColumnUsages ).hasSize( 2 ); - final AnnotationUsage inverseJoinColumnUsage0 = inverseJoinColumnUsages.get( 0 ); - assertThat( inverseJoinColumnUsage0.getString( "name" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "referencedColumnName" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "table" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getString( "columnDefinition" ) ).isEmpty(); - assertThat( inverseJoinColumnUsage0.getBoolean( "insertable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "updatable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "nullable" ) ).isTrue(); - assertThat( inverseJoinColumnUsage0.getBoolean( "unique" ) ).isFalse(); + final JoinColumn inverseJoinColumnUsage0 = inverseJoinColumnUsages[0]; + assertThat( inverseJoinColumnUsage0.name() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.referencedColumnName() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.table() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.columnDefinition() ).isEmpty(); + assertThat( inverseJoinColumnUsage0.insertable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.updatable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.nullable() ).isTrue(); + assertThat( inverseJoinColumnUsage0.unique() ).isFalse(); - final AnnotationUsage inverseJoinColumnUsage1 = inverseJoinColumnUsages.get( 1 ); - assertThat( inverseJoinColumnUsage1.getString( "name" ) ).isEqualTo( "col3" ); - assertThat( inverseJoinColumnUsage1.getString( "referencedColumnName" ) ).isEqualTo( "col4" ); - assertThat( inverseJoinColumnUsage1.getString( "table" ) ).isEqualTo( "table3" ); - assertThat( inverseJoinColumnUsage1.getString( "columnDefinition" ) ).isEqualTo( "int" ); - assertThat( inverseJoinColumnUsage1.getBoolean( "insertable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "updatable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "nullable" ) ).isFalse(); - assertThat( inverseJoinColumnUsage1.getBoolean( "unique" ) ).isTrue(); + final JoinColumn inverseJoinColumnUsage1 = inverseJoinColumnUsages[1]; + assertThat( inverseJoinColumnUsage1.name() ).isEqualTo( "col3" ); + assertThat( inverseJoinColumnUsage1.referencedColumnName() ).isEqualTo( "col4" ); + assertThat( inverseJoinColumnUsage1.table() ).isEqualTo( "table3" ); + assertThat( inverseJoinColumnUsage1.columnDefinition() ).isEqualTo( "int" ); + assertThat( inverseJoinColumnUsage1.insertable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.updatable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.nullable() ).isFalse(); + assertThat( inverseJoinColumnUsage1.unique() ).isTrue(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // UniqueConstraints - final List> uniqueConstraintUsages = joinTableUsage.getList( "uniqueConstraints" ); + final UniqueConstraint[] uniqueConstraintUsages = joinTableUsage.uniqueConstraints(); assertThat( uniqueConstraintUsages ).hasSize( 2 ); - final AnnotationUsage uniqueConstraintUsage0 = uniqueConstraintUsages.get( 0 ); - assertThat( uniqueConstraintUsage0.getString( "name" ) ).isEmpty(); - assertThat( uniqueConstraintUsage0.getList( "columnNames" ) ).hasSize( 1 ); - assertThat( uniqueConstraintUsage0.getList( "columnNames" ) ).containsOnly( "col5" ); + final UniqueConstraint uniqueConstraintUsage0 = uniqueConstraintUsages[0]; + assertThat( uniqueConstraintUsage0.name() ).isEmpty(); + assertThat( uniqueConstraintUsage0.columnNames() ).hasSize( 1 ); + assertThat( uniqueConstraintUsage0.columnNames() ).containsOnly( "col5" ); - final AnnotationUsage uniqueConstraintUsage1 = uniqueConstraintUsages.get( 1 ); - assertThat( uniqueConstraintUsage1.getString( "name" ) ).isEqualTo( "uq1" ); - assertThat( uniqueConstraintUsage1.getList( "columnNames" ) ).hasSize( 2 ); - assertThat( uniqueConstraintUsage1.getList( "columnNames" ) ).containsOnly( "col6", "col7" ); + final UniqueConstraint uniqueConstraintUsage1 = uniqueConstraintUsages[1]; + assertThat( uniqueConstraintUsage1.name() ).isEqualTo( "uq1" ); + assertThat( uniqueConstraintUsage1.columnNames() ).hasSize( 2 ); + assertThat( uniqueConstraintUsage1.columnNames() ).containsOnly( "col6", "col7" ); } @Test public void testCascadeAll() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm8.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - final AnnotationUsage oneToOneUsage = memberDetails.getAnnotationUsage( OneToOne.class ); - assertThat( oneToOneUsage.getList( "cascade" ) ).isEmpty(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + final OneToOne oneToOneUsage = memberDetails.getDirectAnnotationUsage( OneToOne.class ); + assertThat( oneToOneUsage.cascade() ).isEmpty(); - final AnnotationUsage cascadeUsage = memberDetails.getAnnotationUsage( Cascade.class ); - assertThat( cascadeUsage.getList( "value" ) ).containsOnly( CascadeType.ALL ); + final Cascade cascadeUsage = memberDetails.getDirectAnnotationUsage( Cascade.class ); + assertThat( cascadeUsage.value() ).containsOnly( CascadeType.ALL ); } @Test public void testCascadeSomeWithDefaultPersist() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm9.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - final AnnotationUsage oneToOneUsage = memberDetails.getAnnotationUsage( OneToOne.class ); - assertThat( oneToOneUsage.getList( "cascade" ) ).isEmpty(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + final OneToOne oneToOneUsage = memberDetails.getDirectAnnotationUsage( OneToOne.class ); + assertThat( oneToOneUsage.cascade() ).isEmpty(); - final AnnotationUsage cascadeUsage = memberDetails.getAnnotationUsage( Cascade.class ); - assertThat( cascadeUsage.getList( "value" ) ).containsOnly( CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH, CascadeType.PERSIST ); + final Cascade cascadeUsage = memberDetails.getDirectAnnotationUsage( Cascade.class ); + assertThat( cascadeUsage.value() ).containsOnly( CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH, CascadeType.PERSIST ); } /** @@ -307,12 +305,12 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase { @Test public void testCascadeAllPlusMore() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm10.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - final AnnotationUsage oneToOneUsage = memberDetails.getAnnotationUsage( OneToOne.class ); - assertThat( oneToOneUsage.getList( "cascade" ) ).isEmpty(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + final OneToOne oneToOneUsage = memberDetails.getDirectAnnotationUsage( OneToOne.class ); + assertThat( oneToOneUsage.cascade() ).isEmpty(); - final AnnotationUsage cascadeUsage = memberDetails.getAnnotationUsage( Cascade.class ); - assertThat( cascadeUsage.getList( "value" ) ).containsOnly( + final Cascade cascadeUsage = memberDetails.getDirectAnnotationUsage( Cascade.class ); + assertThat( cascadeUsage.value() ).containsOnly( CascadeType.ALL, CascadeType.PERSIST, CascadeType.REMOVE, @@ -325,27 +323,27 @@ public class Ejb3XmlOneToOneTest extends Ejb3XmlTestCase { @Test public void testAllAttributes() { final MemberDetails memberDetails = getAttributeMember( Entity1.class, "field1", "one-to-one.orm11.xml" ); - assertThat( memberDetails.hasAnnotationUsage( OneToOne.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( MapsId.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Id.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Access.class ) ).isTrue(); - assertThat( memberDetails.hasAnnotationUsage( Target.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( OneToOne.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( MapsId.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( Id.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( Access.class ) ).isTrue(); + assertThat( memberDetails.hasDirectAnnotationUsage( Target.class ) ).isTrue(); - final AnnotationUsage oneToOneUsage = memberDetails.getAnnotationUsage( OneToOne.class ); - assertThat( oneToOneUsage.getList( "cascade" ) ).isEmpty(); - assertThat( oneToOneUsage.getEnum( "fetch", FetchType.class ) ).isEqualTo( FetchType.LAZY ); - assertThat( oneToOneUsage.getString( "mappedBy" ) ).isEqualTo( "field2" ); - assertThat( oneToOneUsage.getBoolean( "optional" ) ).isFalse(); - assertThat( oneToOneUsage.getBoolean( "orphanRemoval" ) ).isTrue(); + final OneToOne oneToOneUsage = memberDetails.getDirectAnnotationUsage( OneToOne.class ); + assertThat( oneToOneUsage.cascade() ).isEmpty(); + assertThat( oneToOneUsage.fetch() ).isEqualTo( FetchType.LAZY ); + assertThat( oneToOneUsage.mappedBy() ).isEqualTo( "field2" ); + assertThat( oneToOneUsage.optional() ).isFalse(); + assertThat( oneToOneUsage.orphanRemoval() ).isTrue(); - final AnnotationUsage targetUsage = memberDetails.getAnnotationUsage( Target.class ); - assertThat( targetUsage.getString( "value" ) ).isEqualTo( Entity3.class.getName() ); + final Target targetUsage = memberDetails.getDirectAnnotationUsage( Target.class ); + assertThat( targetUsage.value() ).isEqualTo( Entity3.class.getName() ); - final AnnotationUsage accessUsage = memberDetails.getAnnotationUsage( Access.class ); - assertThat( accessUsage.getEnum( "value", AccessType.class ) ).isEqualTo( AccessType.PROPERTY ); + final Access accessUsage = memberDetails.getDirectAnnotationUsage( Access.class ); + assertThat( accessUsage.value() ).isEqualTo( AccessType.PROPERTY ); - final AnnotationUsage mapsIsUsage = memberDetails.getAnnotationUsage( MapsId.class ); - assertThat( mapsIsUsage.getString( "value" ) ).isEqualTo( "field3" ); + final MapsId mapsIsUsage = memberDetails.getDirectAnnotationUsage( MapsId.class ); + assertThat( mapsIsUsage.value() ).isEqualTo( "field3" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlTestCase.java index c7077c2eb0..24cbd3b1de 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/xml/ejb3/Ejb3XmlTestCase.java @@ -10,8 +10,9 @@ import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.internal.RootMappingDefaults; import org.hibernate.boot.model.process.spi.ManagedResources; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; -import org.hibernate.boot.models.categorize.internal.DomainModelCategorizationCollector; -import org.hibernate.boot.models.categorize.internal.GlobalRegistrationsImpl; +import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; +import org.hibernate.boot.models.internal.GlobalRegistrationsImpl; +import org.hibernate.boot.models.internal.OrmAnnotationHelper; import org.hibernate.boot.models.xml.internal.PersistenceUnitMetadataImpl; import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult; import org.hibernate.boot.models.xml.spi.XmlPreProcessor; @@ -57,7 +58,7 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase { protected MemberDetails getAttributeMember(Class entityClass, String fieldName, String xmlResourceName) { final ClassDetails classDetails = getClassDetails( entityClass, xmlResourceName ); final FieldDetails fieldByName = classDetails.findFieldByName( fieldName ); - if ( !fieldByName.getAllAnnotationUsages().isEmpty() ) { + if ( !fieldByName.getDirectAnnotationUsages().isEmpty() ) { return fieldByName; } @@ -72,6 +73,8 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase { throw new IllegalStateException( "Unable to locate persistent attribute : " + fieldName ); } + private SourceModelBuildingContext sourceModelContext; + protected ClassDetails getClassDetails(Class entityClass, String xmlResourceName) { final ManagedResources managedResources = new AdditionalManagedResourcesImpl.Builder().addLoadedClasses( entityClass ) .addXmlMappings( "org/hibernate/orm/test/annotations/xml/ejb3/" + xmlResourceName ) @@ -82,7 +85,13 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase { persistenceUnitMetadata ); - final SourceModelBuildingContext modelBuildingContext = new SourceModelBuildingContextImpl( SIMPLE_CLASS_LOADING, null ); + final SourceModelBuildingContext modelBuildingContext = new SourceModelBuildingContextImpl( + SIMPLE_CLASS_LOADING, + null, + (contributions, inFlightContext) -> { + OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation ); + } + ); final BootstrapContext bootstrapContext = new BootstrapContextImpl(); final GlobalRegistrationsImpl globalRegistrations = new GlobalRegistrationsImpl( modelBuildingContext, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/XmlDefinedNamespaceTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/XmlDefinedNamespaceTests.java new file mode 100644 index 0000000000..de6d7ceb9b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/XmlDefinedNamespaceTests.java @@ -0,0 +1,111 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.test.boot.database.qualfiedTableNaming; + +import java.io.StringWriter; +import java.util.EnumSet; + +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; +import org.hibernate.tool.schema.internal.exec.ScriptTargetOutputToWriter; +import org.hibernate.tool.schema.spi.ScriptTargetOutput; +import org.hibernate.tool.schema.spi.TargetDescriptor; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.DomainModelScope; +import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @implNote Limited to H2 so that we can expect and assert based on a consistent qualifier pattern. See + * {@linkplain DefaultCatalogAndSchemaTest} for more complete testing of XML namespace application + * + * @author Steve Ebersole + */ +@SuppressWarnings("JUnitMalformedDeclaration") +@RequiresDialect( H2Dialect.class ) +public class XmlDefinedNamespaceTests { + @ServiceRegistry() + @DomainModel( xmlMappings = "mappings/models/namespace/no-namespace.xml" ) + @Test + public void testNoNamespace(DomainModelScope domainModelScope, ServiceRegistryScope serviceRegistryScope) { + // tests case where there is no namespace - explicit or implicit + final MetadataImplementor domainModel = domainModelScope.getDomainModel(); + final StandardServiceRegistry serviceRegistry = serviceRegistryScope.getRegistry(); + final String script = generateScript( SchemaExport.Action.CREATE, domainModel, serviceRegistry ); + assertThat( script ).containsIgnoringCase( "create table simple_entity" ); + } + + @ServiceRegistry() + @DomainModel( xmlMappings = "mappings/models/namespace/defaults-namespace.xml" ) + @Test + public void testXmlDefaultsNamespace(DomainModelScope domainModelScope, ServiceRegistryScope serviceRegistryScope) { + // tests case where there is no namespace - explicit or implicit + final MetadataImplementor domainModel = domainModelScope.getDomainModel(); + final StandardServiceRegistry serviceRegistry = serviceRegistryScope.getRegistry(); + final String script = generateScript( SchemaExport.Action.CREATE, domainModel, serviceRegistry ); + assertThat( script ).containsIgnoringCase( "create table defaults_schema.simple_entity" ); + } + + @ServiceRegistry() + @DomainModel( xmlMappings = "mappings/models/namespace/file-namespace.xml" ) + @Test + public void testXmlFileNamespace(DomainModelScope domainModelScope, ServiceRegistryScope serviceRegistryScope) { + // tests case where there is no namespace - explicit or implicit + final MetadataImplementor domainModel = domainModelScope.getDomainModel(); + final StandardServiceRegistry serviceRegistry = serviceRegistryScope.getRegistry(); + final String script = generateScript( SchemaExport.Action.CREATE, domainModel, serviceRegistry ); + assertThat( script ).containsIgnoringCase( "create table file_schema.simple_entity" ); + } + + public static class SimpleEntity { + private Integer id; + private String name; + } + + + private String generateScript( + SchemaExport.Action action, + MetadataImplementor domainModel, + StandardServiceRegistry serviceRegistry) { + SchemaExport schemaExport = new SchemaExport(); + schemaExport.setFormat( true ); + schemaExport.setDelimiter( ";" ); + StringWriter writer = new StringWriter(); + schemaExport.doExecution( + action, + false, + domainModel, + serviceRegistry, + new TargetDescriptor() { + @Override + public EnumSet getTargetTypes() { + return EnumSet.of( TargetType.SCRIPT ); + } + + @Override + public ScriptTargetOutput getScriptTargetOutput() { + return new ScriptTargetOutputToWriter( writer ) { + @Override + public void accept(String command) { + super.accept( command ); + } + }; + } + } + ); + return writer.toString(); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelper.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelper.java index 5360a75f7c..88a760ac85 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelper.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelper.java @@ -7,25 +7,46 @@ package org.hibernate.orm.test.boot.models; import java.io.IOException; +import java.io.InputStream; import java.lang.annotation.Annotation; +import java.net.URL; +import java.util.List; +import java.util.stream.Collectors; -import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.boot.models.JpaAnnotations; -import org.hibernate.boot.models.categorize.internal.OrmAnnotationHelper; +import org.hibernate.boot.internal.RootMappingDefaults; +import org.hibernate.boot.model.process.spi.ManagedResources; +import org.hibernate.boot.models.categorize.internal.ClassLoaderServiceLoading; +import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; +import org.hibernate.boot.models.internal.GlobalRegistrationsImpl; +import org.hibernate.boot.models.internal.ModelsHelper; +import org.hibernate.boot.models.internal.OrmAnnotationHelper; +import org.hibernate.boot.models.xml.internal.PersistenceUnitMetadataImpl; +import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult; +import org.hibernate.boot.models.xml.spi.XmlPreProcessor; +import org.hibernate.boot.models.xml.spi.XmlProcessingResult; +import org.hibernate.boot.models.xml.spi.XmlProcessor; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; +import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.models.internal.AnnotationDescriptorRegistryStandard; import org.hibernate.models.internal.BaseLineJavaTypes; import org.hibernate.models.internal.SourceModelBuildingContextImpl; import org.hibernate.models.internal.jandex.JandexBuilders; import org.hibernate.models.internal.jandex.JandexIndexerHelper; import org.hibernate.models.internal.jdk.JdkBuilders; +import org.hibernate.models.spi.AnnotationDescriptorRegistry; +import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.ClassLoading; import org.hibernate.models.spi.SourceModelBuildingContext; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; +import static org.hibernate.internal.util.collections.CollectionHelper.mutableJoin; import static org.hibernate.models.internal.SimpleClassLoading.SIMPLE_CLASS_LOADING; /** @@ -53,9 +74,7 @@ public class SourceModelTestHelper { final SourceModelBuildingContextImpl buildingContext = new SourceModelBuildingContextImpl( classLoadingAccess, jandexIndex, - (contributions, buildingContext1) -> { - OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation ); - } + (contributions, buildingContext1) -> OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation ) ); final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry(); final AnnotationDescriptorRegistryStandard annotationDescriptorRegistry = (AnnotationDescriptorRegistryStandard) buildingContext.getAnnotationDescriptorRegistry(); @@ -77,7 +96,7 @@ public class SourceModelTestHelper { .classForName( knownClass.name().toString() ); annotationDescriptorRegistry.resolveDescriptor( annotationClass, annotationType -> JdkBuilders.buildAnnotationDescriptor( annotationType, - annotationDescriptorRegistry + buildingContext ) ); } } @@ -96,8 +115,7 @@ public class SourceModelTestHelper { public static Index buildJandexIndex(ClassLoading classLoadingAccess, Class... modelClasses) { final Indexer indexer = new Indexer(); BaseLineJavaTypes.forEachJavaType( (javaType) -> JandexIndexerHelper.apply( javaType, indexer, classLoadingAccess ) ); - JpaAnnotations.forEachAnnotation( (descriptor) -> JandexIndexerHelper.apply( descriptor.getAnnotationType(), indexer, classLoadingAccess ) ); - HibernateAnnotations.forEachAnnotation( (descriptor) -> JandexIndexerHelper.apply( descriptor.getAnnotationType(), indexer, classLoadingAccess ) ); + OrmAnnotationHelper.forEachOrmAnnotation( (descriptor) -> JandexIndexerHelper.apply( descriptor.getAnnotationType(), indexer, classLoadingAccess ) ); for ( Class modelClass : modelClasses ) { try { @@ -110,4 +128,103 @@ public class SourceModelTestHelper { return indexer.complete(); } + + public static SourceModelBuildingContext createBuildingContext( + ManagedResources managedResources, + boolean buildJandexIndex, + MetadataBuildingOptions metadataBuildingOptions, + BootstrapContext bootstrapContext) { + final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class ); + final ClassLoaderServiceLoading classLoading = new ClassLoaderServiceLoading( classLoaderService ); + + final PersistenceUnitMetadataImpl persistenceUnitMetadata = new PersistenceUnitMetadataImpl(); + + final XmlPreProcessingResult xmlPreProcessingResult = XmlPreProcessor.preProcessXmlResources( + managedResources, + persistenceUnitMetadata + ); + + //noinspection unchecked + final List allKnownClassNames = mutableJoin( + managedResources.getAnnotatedClassReferences().stream().map( Class::getName ).collect( Collectors.toList() ), + managedResources.getAnnotatedClassNames(), + xmlPreProcessingResult.getMappedClasses() + ); + managedResources.getAnnotatedPackageNames().forEach( (packageName) -> { + try { + final Class packageInfoClass = classLoading.classForName( packageName + ".package-info" ); + allKnownClassNames.add( packageInfoClass.getName() ); + } + catch (ClassLoadingException classLoadingException) { + // no package-info, so there can be no annotations... just skip it + } + } ); + managedResources.getAnnotatedClassReferences().forEach( (clazz) -> allKnownClassNames.add( clazz.getName() ) ); + + final IndexView jandexIndex = buildJandexIndex + ? buildJandexIndex( classLoading, allKnownClassNames ) + : null; + + final SourceModelBuildingContextImpl sourceModelBuildingContext = new SourceModelBuildingContextImpl( + classLoading, + jandexIndex, + ModelsHelper::preFillRegistries + ); + + final RootMappingDefaults rootMappingDefaults = new RootMappingDefaults( + metadataBuildingOptions.getMappingDefaults(), + persistenceUnitMetadata + ); + + final GlobalRegistrationsImpl globalRegistrations = new GlobalRegistrationsImpl( sourceModelBuildingContext, bootstrapContext ); + final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector( + true, + globalRegistrations, + jandexIndex, + sourceModelBuildingContext + ); + + final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml( + xmlPreProcessingResult, + modelCategorizationCollector, + sourceModelBuildingContext, + bootstrapContext, + rootMappingDefaults + ); + + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); + allKnownClassNames.forEach( (className) -> { + final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( className ); + modelCategorizationCollector.apply( classDetails ); + } ); + xmlPreProcessingResult.getMappedNames().forEach( (className) -> { + final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( className ); + modelCategorizationCollector.apply( classDetails ); + } ); + + xmlProcessingResult.apply( xmlPreProcessingResult.getPersistenceUnitMetadata() ); + + return sourceModelBuildingContext; + } + + private static IndexView buildJandexIndex(ClassLoaderServiceLoading classLoading, List classNames) { + final Indexer indexer = new Indexer(); + BaseLineJavaTypes.forEachJavaType( (javaType) -> JandexIndexerHelper.apply( javaType, indexer, classLoading ) ); + OrmAnnotationHelper.forEachOrmAnnotation( (descriptor) -> JandexIndexerHelper.apply( descriptor.getAnnotationType(), indexer, classLoading ) ); + + classNames.forEach( (className) -> { + final URL classUrl = classLoading.locateResource( className.replace( '.', '/' ) + ".class" ); + if ( classUrl == null ) { + throw new RuntimeException( "Could not locate class file : " + className ); + } + try (final InputStream classFileStream = classUrl.openStream() ) { + indexer.index( classFileStream ); + } + catch (IOException e) { + throw new RuntimeException( e ); + } + } ); + + return indexer.complete(); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelperSmokeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelperSmokeTests.java index 6ee055b0df..8fa37a8117 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelperSmokeTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/SourceModelTestHelperSmokeTests.java @@ -6,12 +6,9 @@ */ package org.hibernate.orm.test.boot.models; -import java.util.List; - import org.hibernate.models.AnnotationAccessException; import org.hibernate.models.internal.jandex.JandexClassDetails; import org.hibernate.models.spi.AnnotationDescriptor; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.SourceModelBuildingContext; @@ -47,44 +44,44 @@ public class SourceModelTestHelperSmokeTests { assertThat( classDetails ).isNotNull(); assertThat( classDetails ).isInstanceOf( JandexClassDetails.class ); - final AnnotationUsage entityAnnotation = classDetails.getAnnotationUsage( Entity.class ); + final Entity entityAnnotation = classDetails.getDirectAnnotationUsage( Entity.class ); assertThat( entityAnnotation ).isNotNull(); - assertThat( entityAnnotation.getAttributeValue( "name" ) ).isEqualTo( "AnEntity" ); + assertThat( entityAnnotation.name() ).isEqualTo( "AnEntity" ); - final AnnotationUsage
tableAnnotation = classDetails.getAnnotationUsage( Table.class ); + final Table tableAnnotation = classDetails.getDirectAnnotationUsage( Table.class ); assertThat( tableAnnotation ).isNotNull(); - assertThat( tableAnnotation.getAttributeValue( "name" ) ).isEqualTo( "the_table" ); + assertThat( tableAnnotation.name() ).isEqualTo( "the_table" ); - final AnnotationUsage inheritanceAnnotation = classDetails.getAnnotationUsage( Inheritance.class ); + final Inheritance inheritanceAnnotation = classDetails.getDirectAnnotationUsage( Inheritance.class ); assertThat( inheritanceAnnotation ).isNull(); final FieldDetails idField = classDetails.findFieldByName( "id" ); assertThat( idField ).isNotNull(); - final AnnotationUsage idAnnotation = idField.getAnnotationUsage( Id.class ); + final Id idAnnotation = idField.getDirectAnnotationUsage( Id.class ); assertThat( idAnnotation ).isNotNull(); final FieldDetails nameField = classDetails.findFieldByName( "name" ); assertThat( nameField ).isNotNull(); - final AnnotationUsage nameColumnAnnotation = nameField.getAnnotationUsage( Column.class ); + final Column nameColumnAnnotation = nameField.getDirectAnnotationUsage( Column.class ); assertThat( nameColumnAnnotation ).isNotNull(); try { - classDetails.getAnnotationUsage( NamedQuery.class ); + classDetails.getAnnotationUsage( NamedQuery.class, buildingContext ); fail( "Expecting failure" ); } catch (AnnotationAccessException expected) { } - final List> repeatedUsages = classDetails.getRepeatedAnnotationUsages( NamedQuery.class ); + final NamedQuery[] repeatedUsages = classDetails.getRepeatedAnnotationUsages( NamedQuery.class, buildingContext ); assertThat( repeatedUsages ).hasSize( 2 ); - final AnnotationUsage queryOne = classDetails.getNamedAnnotationUsage( NamedQuery.class, "one" ); + final NamedQuery queryOne = classDetails.getNamedAnnotationUsage( NamedQuery.class, "one", buildingContext ); assertThat( queryOne ).isNotNull(); - final AnnotationUsage queryTwo = classDetails.getNamedAnnotationUsage( NamedQuery.class, "two", "name" ); + final NamedQuery queryTwo = classDetails.getNamedAnnotationUsage( NamedQuery.class, "two", "name", buildingContext ); assertThat( queryTwo ).isNotNull(); - assertThat( classDetails.getRepeatedAnnotationUsages( NamedQuery.class ) ).hasSize( 2 ); + assertThat( classDetails.getRepeatedAnnotationUsages( NamedQuery.class, buildingContext ) ).hasSize( 2 ); } @Entity(name="AnEntity") diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/annotation/SimpleAnnotationUsageTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/annotation/SimpleAnnotationUsageTests.java new file mode 100644 index 0000000000..3b596a9479 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/annotation/SimpleAnnotationUsageTests.java @@ -0,0 +1,53 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. + */ +package org.hibernate.orm.test.boot.models.annotation; + +import org.hibernate.boot.models.annotations.internal.EntityJpaAnnotation; +import org.hibernate.models.internal.OrmAnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptorRegistry; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.orm.test.boot.models.SourceModelTestHelper; + +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Steve Ebersole + */ +public class SimpleAnnotationUsageTests { + @Test + void testSimpleUsage() { + final SourceModelBuildingContext context = SourceModelTestHelper.createBuildingContext( SimpleEntity.class ); + final AnnotationDescriptorRegistry descriptorRegistry = context.getAnnotationDescriptorRegistry(); + final AnnotationDescriptor entityDescriptor = descriptorRegistry.getDescriptor( Entity.class ); + assertThat( entityDescriptor ).isInstanceOf( OrmAnnotationDescriptor.class ); + + final ClassDetailsRegistry classDetailsRegistry = context.getClassDetailsRegistry(); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( SimpleEntity.class.getName() ); + final Entity entityAnnotation = classDetails.getDirectAnnotationUsage( Entity.class ); + assertThat( entityAnnotation ).isInstanceOf( EntityJpaAnnotation.class ); + assertThat( entityAnnotation.name() ).isEqualTo( SimpleEntity.class.getSimpleName() ); + ( (EntityJpaAnnotation) entityAnnotation ).name( "SomethingNew" ); + assertThat( entityAnnotation.name() ).isEqualTo( "SomethingNew" ); + } + + @Entity(name="SimpleEntity") + @Table(name="SimpleEntity") + public static class SimpleEntity { + @Id + private Integer id; + private String name; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/BindingTestingHelper.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/BindingTestingHelper.java deleted file mode 100644 index c87753b40d..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/BindingTestingHelper.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind; - -import java.util.Set; - -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.internal.BootstrapContextImpl; -import org.hibernate.boot.internal.InFlightMetadataCollectorImpl; -import org.hibernate.boot.internal.MetadataBuilderImpl; -import org.hibernate.boot.internal.MetadataBuildingContextRootImpl; -import org.hibernate.boot.internal.RootMappingDefaults; -import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.model.process.spi.MetadataBuildingProcess; -import org.hibernate.boot.models.bind.internal.BindingContextImpl; -import org.hibernate.boot.models.bind.internal.BindingOptionsImpl; -import org.hibernate.boot.models.bind.internal.BindingStateImpl; -import org.hibernate.boot.models.bind.spi.BindingCoordinator; -import org.hibernate.boot.models.categorize.internal.ClassLoaderServiceLoading; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.models.internal.SourceModelBuildingContextImpl; - -/** - * @author Steve Ebersole - */ -public class BindingTestingHelper { - public static void checkDomainModel( - DomainModelCheck check, - StandardServiceRegistry serviceRegistry, - Class... domainClasses) { - final BootstrapContextImpl bootstrapContext = buildBootstrapContext( - serviceRegistry ); - final ManagedResources managedResources = buildManagedResources( - domainClasses, - bootstrapContext - ); - - final InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl( - bootstrapContext, - bootstrapContext.getMetadataBuildingOptions() - ); - - final CategorizedDomainModel categorizedDomainModel = ManagedResourcesProcessor.processManagedResources( - managedResources, - bootstrapContext - ); - - final RootMappingDefaults mappingDefaults = new RootMappingDefaults( - new MetadataBuilderImpl.MappingDefaultsImpl( serviceRegistry ), - metadataCollector.getPersistenceUnitMetadata() - ); - - final MetadataBuildingContextRootImpl metadataBuildingContext = new MetadataBuildingContextRootImpl( - "models", - bootstrapContext, - bootstrapContext.getMetadataBuildingOptions(), - metadataCollector, - mappingDefaults - ); - final BindingStateImpl bindingState = new BindingStateImpl( metadataBuildingContext ); - final BindingOptionsImpl bindingOptions = new BindingOptionsImpl( metadataBuildingContext ); - final BindingContextImpl bindingContext = new BindingContextImpl( - categorizedDomainModel, - bootstrapContext - ); - - BindingCoordinator.coordinateBinding( - categorizedDomainModel, - bindingState, - bindingOptions, - bindingContext - ); - - check.checkDomainModel( new DomainModelCheckContext() { - @Override - public InFlightMetadataCollectorImpl getMetadataCollector() { - return metadataCollector; - } - - @Override - public BindingStateImpl getBindingState() { - return bindingState; - } - } ); - } - - public interface DomainModelCheckContext { - InFlightMetadataCollectorImpl getMetadataCollector(); - BindingStateImpl getBindingState(); - } - - @FunctionalInterface - public interface DomainModelCheck { - void checkDomainModel(DomainModelCheckContext context); - } - - private static BootstrapContextImpl buildBootstrapContext(StandardServiceRegistry serviceRegistry) { - final MetadataBuilderImpl.MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ); - final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl( serviceRegistry, metadataBuildingOptions ); - metadataBuildingOptions.setBootstrapContext( bootstrapContext ); - return bootstrapContext; - } - - private static ManagedResources buildManagedResources( - Class[] domainClasses, - BootstrapContextImpl bootstrapContext) { - final MetadataSources metadataSources = new MetadataSources( bootstrapContext.getServiceRegistry() ); - for ( int i = 0; i < domainClasses.length; i++ ) { - metadataSources.addAnnotatedClass( domainClasses[i] ); - } - return MetadataBuildingProcess.prepare( metadataSources, bootstrapContext ); - } - - public static Set buildHierarchyMetadata(Class... classes) { - final ManagedResources managedResources = new AdditionalManagedResourcesImpl.Builder() - .addLoadedClasses(classes) - .build(); - - try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) { - final MetadataBuilderImpl.MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ); - final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl( serviceRegistry, metadataBuildingOptions ); - - final CategorizedDomainModel categorizedDomainModel = ManagedResourcesProcessor.processManagedResources( - managedResources, - bootstrapContext - ); - - return categorizedDomainModel.getEntityHierarchies(); - } - } - - public static CategorizedDomainModel buildCategorizedDomainModel(Class... classes) { - final ManagedResources managedResources = new AdditionalManagedResourcesImpl.Builder() - .addLoadedClasses(classes) - .build(); - - try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) { - final MetadataBuilderImpl.MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ); - final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl( serviceRegistry, metadataBuildingOptions ); - - return ManagedResourcesProcessor.processManagedResources( managedResources, bootstrapContext ); - } - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/CustomNamingStrategy.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/CustomNamingStrategy.java deleted file mode 100644 index a92aab6247..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/CustomNamingStrategy.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind; - -import java.util.Locale; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.boot.model.naming.PhysicalNamingStrategy; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; - -/** - * @author Steve Ebersole - */ -public class CustomNamingStrategy implements PhysicalNamingStrategy { - @Override - public Identifier toPhysicalCatalogName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) { - if ( logicalName == null ) { - return null; - } - return Identifier.toIdentifier( logicalName.getText().toUpperCase( Locale.ROOT ), logicalName.isQuoted() ); - } - - @Override - public Identifier toPhysicalSchemaName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) { - if ( logicalName == null ) { - return null; - } - return Identifier.toIdentifier( logicalName.getText().toUpperCase( Locale.ROOT ), logicalName.isQuoted() ); - } - - @Override - public Identifier toPhysicalTableName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) { - return Identifier.toIdentifier( logicalName.getText().toUpperCase( Locale.ROOT ), logicalName.isQuoted() ); - } - - @Override - public Identifier toPhysicalSequenceName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) { - return Identifier.toIdentifier( logicalName.getText().toUpperCase( Locale.ROOT ), logicalName.isQuoted() ); - } - - @Override - public Identifier toPhysicalColumnName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) { - return Identifier.toIdentifier( logicalName.getText().toUpperCase( Locale.ROOT ), logicalName.isQuoted() ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/CustomNamingStrategyProvider.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/CustomNamingStrategyProvider.java deleted file mode 100644 index 331a38f83b..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/CustomNamingStrategyProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind; - -import org.hibernate.boot.model.naming.PhysicalNamingStrategy; - -import org.hibernate.testing.orm.junit.SettingProvider; - - -/** - * @author Steve Ebersole - */ -public class CustomNamingStrategyProvider implements SettingProvider.Provider { - @Override - public PhysicalNamingStrategy getSetting() { - return new CustomNamingStrategy(); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/SimpleBindingCoordinatorTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/SimpleBindingCoordinatorTests.java deleted file mode 100644 index 83a3247c7a..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/SimpleBindingCoordinatorTests.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind; - -import java.util.List; - -import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.boot.models.bind.internal.PhysicalTable; -import org.hibernate.boot.models.bind.internal.SecondaryTable; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.RootClass; -import org.hibernate.type.SqlTypes; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.hibernate.testing.orm.junit.SettingProvider; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.EnumType; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Steve Ebersole - */ -@SuppressWarnings("JUnitMalformedDeclaration") -@ServiceRegistry( settingProviders = @SettingProvider( - settingName = AvailableSettings.PHYSICAL_NAMING_STRATEGY, - provider = CustomNamingStrategyProvider.class -) ) -public class SimpleBindingCoordinatorTests { - @Test - void testCollectorState(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final var bindingState = context.getBindingState(); - final var metadataCollector = context.getMetadataCollector(); - - final var filterDefinition = metadataCollector.getFilterDefinition( "by-name" ); - assertThat( filterDefinition ).isNotNull(); - assertThat( filterDefinition.getDefaultFilterCondition() ).isEqualTo( "name = :name" ); - assertThat( filterDefinition.getParameterNames() ).hasSize( 1 ); - final var nameParamJdbcMapping = filterDefinition.getParameterJdbcMapping( "name" ); - assertThat( nameParamJdbcMapping ).isNotNull(); - assertThat( nameParamJdbcMapping.getJdbcJavaType().getJavaType() ).isEqualTo( String.class ); - - assertThat( bindingState.getTableCount() ).isEqualTo( 2 ); - - final PhysicalTable simpletonsTable = bindingState.getTableByName( "simpletons" ); - assertThat( simpletonsTable.logicalName().render() ).isEqualTo( "simpletons" ); - assertThat( simpletonsTable.logicalName().getCanonicalName() ).isEqualTo( "simpletons" ); - assertThat( simpletonsTable.physicalTableName().render() ).isEqualTo( "SIMPLETONS" ); - assertThat( simpletonsTable.physicalTableName().getCanonicalName() ).isEqualTo( "simpletons" ); - assertThat( simpletonsTable.physicalCatalogName() ).isNull(); - assertThat( simpletonsTable.getPhysicalSchemaName() ).isNull(); - assertThat( simpletonsTable.table().getComment() ).isEqualTo( "Stupid is as stupid does" ); - - final SecondaryTable simpleStuffTable = bindingState.getTableByName( "simple_stuff" ); - assertThat( simpleStuffTable.logicalName().render() ).isEqualTo( "simple_stuff" ); - assertThat( simpleStuffTable.physicalName().render() ).isEqualTo( "SIMPLE_STUFF" ); - assertThat( simpleStuffTable.logicalCatalogName().render() ).isEqualTo( "my_catalog" ); - assertThat( simpleStuffTable.physicalCatalogName().render() ).isEqualTo( "MY_CATALOG" ); - assertThat( simpleStuffTable.logicalSchemaName().render() ).isEqualTo( "my_schema" ); - assertThat( simpleStuffTable.physicalSchemaName().render() ).isEqualTo( "MY_SCHEMA" ); - assertThat( simpleStuffTable.table().getComment() ).isEqualTo( "Don't sweat it" ); - - final var database = metadataCollector.getDatabase(); - final var namespaceItr = database.getNamespaces().iterator(); - final var namespace1 = namespaceItr.next(); - final var namespace2 = namespaceItr.next(); - assertThat( namespaceItr.hasNext() ).isFalse(); - assertThat( namespace1.getTables() ).hasSize( 1 ); - assertThat( namespace2.getTables() ).hasSize( 1 ); - }, - scope.getRegistry(), - SimpleEntity.class - ); - } - - @Test - void testAttributes(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final RootClass entityBinding = (RootClass) context.getMetadataCollector().getEntityBinding( SimpleEntity.class.getName() ); - - final Property id = entityBinding.getProperty( "id" ); - assertThat( id.getValue().getTable().getName() ).isEqualTo( "SIMPLETONS" ); - final BasicValue idValue = (BasicValue) id.getValue(); - assertThat( ( (Column) (idValue).getColumn() ).getCanonicalName() ).isEqualTo( "id" ); - assertThat( idValue.resolve().getDomainJavaType().getJavaType() ).isEqualTo( Integer.class ); - - final Property name = entityBinding.getProperty( "name" ); - assertThat( id.getValue().getTable().getName() ).isEqualTo( "SIMPLETONS" ); - final BasicValue nameValue = (BasicValue) name.getValue(); - assertThat( ( (Column) (nameValue).getColumn() ).getCanonicalName() ).isEqualTo( "name" ); - assertThat( nameValue.resolve().getDomainJavaType().getJavaType() ).isEqualTo( String.class ); - - final Property data = entityBinding.getProperty( "data" ); - assertThat( data.getValue().getTable().getName() ).isEqualTo( "SIMPLE_STUFF" ); - final BasicValue dataValue = (BasicValue) data.getValue(); - assertThat( ( (Column) (dataValue).getColumn() ).getCanonicalName() ).isEqualTo( "datum" ); - assertThat( dataValue.resolve().getDomainJavaType().getJavaType() ).isEqualTo( String.class ); - - final Property stuff = entityBinding.getProperty( "stuff" ); - assertThat( stuff.getValue().getTable().getName() ).isEqualTo( "SIMPLETONS" ); - final BasicValue stuffValue = (BasicValue) stuff.getValue(); - assertThat( stuffValue.getEnumerationStyle() ).isEqualTo( EnumType.STRING ); - assertThat( ( (Column) stuffValue.getColumn() ).getCanonicalName() ).isEqualTo( "stuff" ); - assertThat( stuffValue.resolve().getDomainJavaType().getJavaType() ).isEqualTo( SimpleEntity.Stuff.class ); - assertThat( stuffValue.resolve().getJdbcType().getJdbcTypeCode() ).isEqualTo( SqlTypes.VARCHAR ); - - final Property tenantKey = entityBinding.getProperty( "tenantKey" ); - final BasicValue tenantKeyValue = (BasicValue) tenantKey.getValue(); - assertThat( ( (Column) tenantKeyValue.getColumn() ).getCanonicalName() ).isEqualTo( "tenantkey" ); - assertThat( tenantKeyValue.resolve().getDomainJavaType().getJavaType() ).isEqualTo( String.class ); - - final Property version = entityBinding.getProperty( "version" ); - final BasicValue versionValue = (BasicValue) version.getValue(); - assertThat( ( (Column) versionValue.getColumn() ).getCanonicalName() ).isEqualTo( "version" ); - assertThat( versionValue.resolve().getDomainJavaType().getJavaType() ).isEqualTo( Integer.class ); - }, - scope.getRegistry(), - SimpleEntity.class - ); - } - - @Test - void testCaching(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final RootClass entityBinding = (RootClass) context.getMetadataCollector().getEntityBinding( SimpleEntity.class.getName() ); - assertThat( entityBinding.isCached() ).isFalse(); - assertThat( entityBinding.getCacheRegionName() ).isEqualTo( "my-region" ); - assertThat( entityBinding.getCacheConcurrencyStrategy() ).isEqualTo( CacheConcurrencyStrategy.READ_ONLY.toAccessType().getExternalName() ); - - }, - scope.getRegistry(), - SimpleEntity.class - ); - } - - @Test - void testBatchSize(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final RootClass entityBinding = (RootClass) context.getMetadataCollector().getEntityBinding( SimpleEntity.class.getName() ); - assertThat( entityBinding.getBatchSize() ).isEqualTo( 32 ); - }, - scope.getRegistry(), - SimpleEntity.class - ); - } - - @Test - void testSoftDelete(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final RootClass entityBinding = (RootClass) context.getMetadataCollector().getEntityBinding( SimpleEntity.class.getName() ); - - final Column softDeleteColumn = entityBinding.getSoftDeleteColumn(); - assertThat( softDeleteColumn ).isNotNull(); - assertThat( softDeleteColumn.getName() ).isEqualTo( "ACTIVE" ); - - }, - scope.getRegistry(), - SimpleEntity.class - ); - } - - @Test - void testSecondaryTables(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final RootClass entityBinding = (RootClass) context.getMetadataCollector().getEntityBinding( SimpleEntity.class.getName() ); - final List joins = entityBinding.getJoins(); - assertThat( joins ).hasSize( 1 ); - final Join join = joins.get( 0 ); - assertThat( join.getTable() ).isNotNull(); - assertThat( join.getTable().getPrimaryKey() ).isNotNull(); - assertThat( join.getTable().getPrimaryKey().getColumns() ).hasSize( 1 ); - assertThat( join.getKey() ).isNotNull(); - assertThat( join.getKey().getColumns() ).hasSize( 1 ); - }, - scope.getRegistry(), - SimpleEntity.class - ); - } - - @Test - void testSynchronization(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final RootClass entityBinding = (RootClass) context.getMetadataCollector().getEntityBinding( SimpleEntity.class.getName() ); - - assertThat( entityBinding.getSynchronizedTables() ).hasSize( 1 ); - - assertThat( entityBinding.getFilters() ).hasSize( 1 ); - }, - scope.getRegistry(), - SimpleEntity.class - ); - } - - @Test - void testFilters(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final RootClass entityBinding = (RootClass) context.getMetadataCollector().getEntityBinding( SimpleEntity.class.getName() ); - assertThat( entityBinding.getFilters() ).hasSize( 1 ); - }, - scope.getRegistry(), - SimpleEntity.class - ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/SimpleEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/SimpleEntity.java deleted file mode 100644 index 22042bae24..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/SimpleEntity.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind; - -import org.hibernate.annotations.BatchSize; -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.annotations.Filter; -import org.hibernate.annotations.FilterDef; -import org.hibernate.annotations.ParamDef; -import org.hibernate.annotations.SoftDelete; -import org.hibernate.annotations.SoftDeleteType; -import org.hibernate.annotations.Synchronize; -import org.hibernate.annotations.TenantId; - -import jakarta.persistence.Basic; -import jakarta.persistence.Cacheable; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.Id; -import jakarta.persistence.SecondaryTable; -import jakarta.persistence.Table; -import jakarta.persistence.Version; - -/** - * A simple entity for initial work on the table - * - * @author Steve Ebersole - */ -@Entity -@Table(name = "simpletons", comment = "Stupid is as stupid does") -@SecondaryTable(name = "simple_stuff", schema = "my_schema", catalog = "my_catalog", comment = "Don't sweat it") -@FilterDef(name = "by-name", defaultCondition = "name = :name", parameters = @ParamDef( name = "name", type = String.class ) ) -@Filter(name = "by-name") -@SoftDelete(strategy = SoftDeleteType.ACTIVE) -@Cacheable(false) -@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "my-region") -@BatchSize(size = 32) -@Synchronize("some_other_table") -public class SimpleEntity { - @Id - private Integer id; - @Basic - private String name; - @Basic - @Column(table = "simple_stuff", name = "datum") - private String data; - - @TenantId - private String tenantKey; - - @Version - private int version; - - @Enumerated(EnumType.STRING) - private Stuff stuff; - - enum Stuff {BITS, BOBS} - - protected SimpleEntity() { - // for Hibernate use - } - - public SimpleEntity(Integer id, String name) { - this.id = id; - this.name = name; - } - - public Integer getId() { - return id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/cache/SimpleCachingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/cache/SimpleCachingTests.java deleted file mode 100644 index 1c34567293..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/cache/SimpleCachingTests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.cache; - -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.NaturalIdCache; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.RootClass; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.Cacheable; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.Table; - -import static jakarta.persistence.InheritanceType.JOINED; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -public class SimpleCachingTests { - @SuppressWarnings("JUnitMalformedDeclaration") - @Test - @ServiceRegistry - void simpleTest(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final RootClass entityBinding = (RootClass) metadataCollector.getEntityBinding( CacheableEntity.class.getName() ); - assertThat( entityBinding.isCached() ).isTrue(); - assertThat( entityBinding.getCacheRegionName() ).isEqualTo( "org.hibernate.testing.entity" ); - assertThat( entityBinding.getCacheConcurrencyStrategy() ).isEqualToIgnoringCase( "read-write" ); - assertThat( entityBinding.getNaturalIdCacheRegionName() ).isEqualTo( "org.hibernate.testing.natural-id" ); - - final PersistentClass subEntityBinding = metadataCollector.getEntityBinding( CacheableEntitySub.class.getName() ); - assertThat( subEntityBinding.isCached() ).isFalse(); - }, - scope.getRegistry(), - CacheableEntity.class, - CacheableEntitySub.class - ); - } - - @Entity(name="CacheableEntity") - @Table(name="CacheableEntity") - @Cacheable - @Cache( region = "org.hibernate.testing.entity", usage = READ_WRITE) - @NaturalIdCache( region = "org.hibernate.testing.natural-id" ) - @Inheritance(strategy = JOINED) - public static class CacheableEntity { - @Id - private Integer id; - private String name; - } - - @Entity(name="CacheableEntitySub") - @Table(name="CacheableEntitySub") - @Cacheable(false) - public static class CacheableEntitySub extends CacheableEntity { - private String someText; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/CallbackTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/CallbackTests.java deleted file mode 100644 index 5b6ab2b29b..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/CallbackTests.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.callbacks; - -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; -import org.hibernate.mapping.MappedSuperclass; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.orm.test.boot.models.bind.BindingTestingHelper; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Steve Ebersole - */ -public class CallbackTests { - @Test - @ServiceRegistry - void testMappedSuper(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final var bindingState = context.getBindingState(); - final var metadataCollector = context.getMetadataCollector(); - - final MappedSuperclass mappedSuper = metadataCollector.getMappedSuperclass( HierarchySuper.class ); - assertThat( mappedSuper ).isNotNull(); - - final PersistentClass entityBinding = metadataCollector.getEntityBinding( HierarchyRoot.class.getName() ); - assertThat( entityBinding ).isNotNull(); - assertThat( entityBinding.getSuperPersistentClass() ).isNull(); - assertThat( entityBinding.getSuperType() ).isEqualTo( mappedSuper ); - assertThat( entityBinding.getSuperMappedSuperclass() ).isEqualTo( mappedSuper ); - assertThat( entityBinding.getCallbackDefinitions() ).hasSize( 3 ); - }, - scope.getRegistry(), - HierarchySuper.class, - HierarchyRoot.class - ); - } - - @Test - void testSimpleEventListenerResolution() { - final CategorizedDomainModel categorizedDomainModel = BindingTestingHelper.buildCategorizedDomainModel( - HierarchyRoot.class, - HierarchySuper.class - ); - final Set entityHierarchies = categorizedDomainModel.getEntityHierarchies(); - final EntityHierarchy hierarchy = entityHierarchies.iterator().next(); - - final EntityTypeMetadata rootMapping = hierarchy.getRoot(); - assertThat( rootMapping.getHierarchyJpaEventListeners() ).hasSize( 3 ); - final List listenerClassNames = rootMapping.getHierarchyJpaEventListeners() - .stream() - .map( listener -> listener.getCallbackClass().getClassName() ) - .collect( Collectors.toList() ); - assertThat( listenerClassNames ).containsExactly( - Listener1.class.getName(), - Listener2.class.getName(), - HierarchyRoot.class.getName() - ); - - final IdentifiableTypeMetadata superMapping = rootMapping.getSuperType(); - assertThat( superMapping.getHierarchyJpaEventListeners() ).hasSize( 1 ); - final String callbackClassName = superMapping.getHierarchyJpaEventListeners() - .get( 0 ) - .getCallbackClass() - .getClassName(); - assertThat( callbackClassName ).isEqualTo( Listener1.class.getName() ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/HierarchyRoot.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/HierarchyRoot.java deleted file mode 100644 index ad2638ae31..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/HierarchyRoot.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.callbacks; - -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.CacheConcurrencyStrategy; - -import jakarta.persistence.Entity; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.PostLoad; - -/** - * @author Steve Ebersole - */ -@Entity -@Cache(usage = CacheConcurrencyStrategy.READ_ONLY) -@Inheritance(strategy = InheritanceType.JOINED) -@EntityListeners(Listener2.class) -public class HierarchyRoot extends HierarchySuper { - @PostLoad - public void wasLoaded() {} -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/HierarchySuper.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/HierarchySuper.java deleted file mode 100644 index c0168ce7c0..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/callbacks/HierarchySuper.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.callbacks; - -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.annotations.TenantId; - -import jakarta.persistence.Basic; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.MappedSuperclass; -import jakarta.persistence.Version; - -/** - * @author Steve Ebersole - */ -@MappedSuperclass -@Cache(usage = CacheConcurrencyStrategy.NONE) -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@EntityListeners(Listener1.class) -public class HierarchySuper { - @Id - private Integer id; - @Basic - private String name; - @Version - private Integer version; - @TenantId - private String tenantId; - - protected HierarchySuper() { - // for Hibernate use - } - - public HierarchySuper(Integer id, String name) { - this.id = id; - this.name = name; - } - - public Integer getId() { - return id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/AggregatedIdEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/AggregatedIdEntity.java deleted file mode 100644 index 5eb5ac9c91..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/AggregatedIdEntity.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.id; - -import org.hibernate.annotations.NaturalId; -import org.hibernate.annotations.TenantId; - -import jakarta.persistence.Embeddable; -import jakarta.persistence.Embedded; -import jakarta.persistence.EmbeddedId; -import jakarta.persistence.Entity; -import jakarta.persistence.Table; -import jakarta.persistence.Version; - -/** - * @author Steve Ebersole - */ -@Entity -@Table(name = "agg_id_entities") -public class AggregatedIdEntity { - @EmbeddedId - private Pk id; - @Embedded - @NaturalId - private NatKey naturalId; - - @Version - private Integer version; - @TenantId - private String tenantId; - - @Embeddable - public static class Pk { - private Integer id1; - private Integer id2; - } - - @Embeddable - public static class NatKey { - private Integer key1; - private Integer key2; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/BasicIdEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/BasicIdEntity.java deleted file mode 100644 index 01031b4bfc..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/BasicIdEntity.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.id; - -import org.hibernate.annotations.NaturalId; -import org.hibernate.annotations.TenantId; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Version; - -/** - * @author Steve Ebersole - */ -@Entity -public class BasicIdEntity { - @Id - private Integer id; - @Version - private Integer version; - @TenantId - private String tenantId; - @NaturalId - private String naturalId; - -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/IdBindingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/IdBindingTests.java deleted file mode 100644 index a7fefa0505..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/IdBindingTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.id; - -import org.hibernate.mapping.KeyValue; -import org.hibernate.mapping.PrimaryKey; -import org.hibernate.mapping.RootClass; - -import org.hibernate.testing.orm.junit.FailureExpected; -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -@ServiceRegistry -@SuppressWarnings("JUnitMalformedDeclaration") -public class IdBindingTests { - @Test - void testBasicId(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final RootClass rootBinding = (RootClass) metadataCollector.getEntityBinding( BasicIdEntity.class.getName() ); - - final PrimaryKey primaryKey = rootBinding.getIdentityTable().getPrimaryKey(); - final KeyValue identifier = rootBinding.getIdentifier(); - - assertThat( primaryKey.getColumns() ).hasSize( 1 ); - assertThat( identifier.getColumns() ).hasSize( 1 ); - assertThat( identifier.getColumns().get( 0 ) ).isSameAs( primaryKey.getColumns().get( 0 ) ); - assertThat( identifier.getColumns().get( 0 ).getName() ).isEqualToIgnoringCase( "id" ); - }, - scope.getRegistry(), - BasicIdEntity.class - ); - } - - @Test - @FailureExpected(reason = "Embeddables not yet supported") - void testAggregatedId(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final RootClass rootBinding = (RootClass) metadataCollector.getEntityBinding( AggregatedIdEntity.class.getName() ); - - final PrimaryKey primaryKey = rootBinding.getIdentityTable().getPrimaryKey(); - final KeyValue identifier = rootBinding.getIdentifier(); - - assertThat( primaryKey.getColumns() ).hasSize( 2 ); - assertThat( identifier.getColumns() ).hasSize( 2 ); - assertThat( identifier.getColumns() ).containsAll( primaryKey.getColumns() ); - }, - scope.getRegistry(), - AggregatedIdEntity.class - ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/NonAggregatedIdEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/NonAggregatedIdEntity.java deleted file mode 100644 index b26d02ddc8..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/NonAggregatedIdEntity.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.id; - -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.annotations.NaturalId; -import org.hibernate.annotations.TenantId; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.IdClass; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Table; -import jakarta.persistence.Version; - -/** - * @author Steve Ebersole - */ -@Entity -@Table(name = "non_agg_id_entities") -@IdClass( NonAggregatedIdEntity.Pk.class ) -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) -public class NonAggregatedIdEntity { - @Id private Integer id1; - @Id private Integer id2; - @Version private Integer version; - @TenantId private String tenantId; - @NaturalId private Integer naturalKey1; - @NaturalId private Integer naturalKey2; - - public static class Pk { - private Integer id1; - private Integer id2; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/SimpleIdTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/SimpleIdTests.java deleted file mode 100644 index e60f6b79b4..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/id/SimpleIdTests.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.id; - -import java.util.Set; - -import org.hibernate.annotations.NaturalId; -import org.hibernate.annotations.TenantId; -import org.hibernate.boot.models.categorize.spi.AggregatedKeyMapping; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.BasicKeyMapping; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.NonAggregatedKeyMapping; -import org.hibernate.cache.spi.access.AccessType; - -import org.junit.jupiter.api.Test; - -import jakarta.persistence.EmbeddedId; -import jakarta.persistence.Id; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Version; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.buildHierarchyMetadata; - -/** - * @author Steve Ebersole - */ -public class SimpleIdTests { - @Test - void testSimpleId() { - final Set entityHierarchies = buildHierarchyMetadata( BasicIdEntity.class ); - assertThat( entityHierarchies ).hasSize( 1 ); - final EntityHierarchy entityHierarchy = entityHierarchies.iterator().next(); - - assertThat( entityHierarchy.getIdMapping() ).isNotNull(); - final BasicKeyMapping idMapping = (BasicKeyMapping) entityHierarchy.getIdMapping(); - assertThat( idMapping.getAttribute().getMember().getAnnotationUsage( Id.class ) ).isNotNull(); - assertThat( idMapping.getAttribute().getMember().getAnnotationUsage( EmbeddedId.class ) ).isNull(); - - assertThat( entityHierarchy.getNaturalIdMapping() ).isNotNull(); - final BasicKeyMapping naturalIdMapping = (BasicKeyMapping) entityHierarchy.getNaturalIdMapping(); - assertThat( naturalIdMapping.getAttribute().getMember().getAnnotationUsage( NaturalId.class ) ).isNotNull(); - assertThat( naturalIdMapping.getAttribute().getMember().getAnnotationUsage( Id.class ) ).isNull(); - assertThat( naturalIdMapping.getAttribute().getMember().getAnnotationUsage( EmbeddedId.class ) ).isNull(); - - assertThat( entityHierarchy.getVersionAttribute() ).isNotNull(); - assertThat( entityHierarchy.getVersionAttribute().getMember().getAnnotationUsage( Version.class ) ).isNotNull(); - - assertThat( entityHierarchy.getTenantIdAttribute() ).isNotNull(); - assertThat( entityHierarchy.getTenantIdAttribute().getMember().getAnnotationUsage( TenantId.class ) ).isNotNull(); - } - - @Test - void testAggregatedId() { - final Set entityHierarchies = buildHierarchyMetadata( AggregatedIdEntity.class ); - assertThat( entityHierarchies ).hasSize( 1 ); - final EntityHierarchy entityHierarchy = entityHierarchies.iterator().next(); - - assertThat( entityHierarchy.getIdMapping() ).isNotNull(); - final AggregatedKeyMapping idMapping = (AggregatedKeyMapping) entityHierarchy.getIdMapping(); - assertThat( idMapping.getAttribute().getMember().getAnnotationUsage( Id.class ) ).isNull(); - assertThat( idMapping.getAttribute().getMember().getAnnotationUsage( EmbeddedId.class ) ).isNotNull(); - - assertThat( entityHierarchy.getNaturalIdMapping() ).isNotNull(); - assertThat( entityHierarchy.getNaturalIdMapping() ).isInstanceOf( AggregatedKeyMapping.class ); - final AggregatedKeyMapping naturalIdMapping = (AggregatedKeyMapping) entityHierarchy.getNaturalIdMapping(); - assertThat( naturalIdMapping.getAttribute().getMember().getAnnotationUsage( Id.class ) ).isNull(); - assertThat( naturalIdMapping.getAttribute().getMember().getAnnotationUsage( EmbeddedId.class ) ).isNull(); - assertThat( naturalIdMapping.getAttribute().getMember().getAnnotationUsage( NaturalId.class ) ).isNotNull(); - - assertThat( entityHierarchy.getVersionAttribute() ).isNotNull(); - assertThat( entityHierarchy.getVersionAttribute().getMember().getAnnotationUsage( Version.class ) ).isNotNull(); - - assertThat( entityHierarchy.getTenantIdAttribute() ).isNotNull(); - assertThat( entityHierarchy.getTenantIdAttribute().getMember().getAnnotationUsage( TenantId.class ) ).isNotNull(); - } - - @Test - void testNonAggregatedId() { - final Set entityHierarchies = buildHierarchyMetadata( NonAggregatedIdEntity.class ); - assertThat( entityHierarchies ).hasSize( 1 ); - final EntityHierarchy entityHierarchy = entityHierarchies.iterator().next(); - - assertThat( entityHierarchy.getIdMapping() ).isNotNull(); - final NonAggregatedKeyMapping idMapping = (NonAggregatedKeyMapping) entityHierarchy.getIdMapping(); - assertThat( idMapping.getIdAttributes() ).hasSize( 2 ); - assertThat( idMapping.getIdAttributes().stream().map( AttributeMetadata::getName ) ).containsExactly( "id1", "id2" ); - assertThat( idMapping.getIdClassType().getClassName() ).isEqualTo( NonAggregatedIdEntity.Pk.class.getName() ); - - assertThat( entityHierarchy.getNaturalIdMapping() ).isNotNull(); - final NonAggregatedKeyMapping naturalIdMapping = (NonAggregatedKeyMapping) entityHierarchy.getNaturalIdMapping(); - assertThat( naturalIdMapping.getIdAttributes() ).hasSize( 2 ); - assertThat( naturalIdMapping.getIdAttributes().stream().map( AttributeMetadata::getName ) ).containsExactly( "naturalKey1", "naturalKey2" ); - - assertThat( entityHierarchy.getVersionAttribute() ).isNotNull(); - assertThat( entityHierarchy.getVersionAttribute().getMember().getAnnotationUsage( Version.class ) ).isNotNull(); - - assertThat( entityHierarchy.getTenantIdAttribute() ).isNotNull(); - assertThat( entityHierarchy.getTenantIdAttribute().getMember().getAnnotationUsage( TenantId.class ) ).isNotNull(); - - assertThat( entityHierarchy.getCacheRegion() ).isNotNull(); - assertThat( entityHierarchy.getCacheRegion().getAccessType() ).isEqualTo( AccessType.TRANSACTIONAL ); - - assertThat( entityHierarchy.getInheritanceType() ).isNotNull(); - assertThat( entityHierarchy.getInheritanceType() ).isEqualTo( InheritanceType.TABLE_PER_CLASS ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/JoinedTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/JoinedTests.java deleted file mode 100644 index 366e0ef5b2..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/JoinedTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.inheritance; - -import org.hibernate.mapping.JoinedSubclass; -import org.hibernate.mapping.RootClass; -import org.hibernate.mapping.SingleTableSubclass; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.DiscriminatorColumn; -import jakarta.persistence.DiscriminatorType; -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Table; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -@ServiceRegistry -@SuppressWarnings("JUnitMalformedDeclaration") -public class JoinedTests { - @Test - void simpleTest(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final RootClass rootBinding = (RootClass) metadataCollector.getEntityBinding( Root.class.getName() ); - final JoinedSubclass subBinding = (JoinedSubclass) metadataCollector.getEntityBinding( Sub.class.getName() ); - - assertThat( rootBinding.getTable() ).isNotNull(); - assertThat( rootBinding.getTable() ).isSameAs( rootBinding.getIdentityTable() ); - assertThat( rootBinding.getTable() ).isSameAs( rootBinding.getRootTable() ); - assertThat( rootBinding.getDiscriminator() ).isNotNull(); - assertThat( rootBinding.getDiscriminator().getColumns() ).hasSize( 1 ); - assertThat( rootBinding.getDiscriminatorValue() ).isEqualTo( "R" ); - - assertThat( subBinding.getTable() ).isNotNull(); - assertThat( subBinding.getTable() ).isNotSameAs( rootBinding.getIdentityTable() ); - assertThat( subBinding.getTable() ).isNotSameAs( rootBinding.getRootTable() ); - assertThat( subBinding.getIdentityTable() ).isSameAs( rootBinding.getRootTable() ); - assertThat( subBinding.getRootTable() ).isSameAs( rootBinding.getRootTable() ); - assertThat( subBinding.getDiscriminatorValue() ).isEqualTo( "S" ); - - assertThat( rootBinding.getTable().getPrimaryKey() ).isNotNull(); - assertThat( rootBinding.getTable().getPrimaryKey().getColumns() ).hasSize( 1 ); - - assertThat( subBinding.getTable().getPrimaryKey() ).isNotNull(); - assertThat( subBinding.getTable().getPrimaryKey().getColumns() ).hasSize( 1 ); - }, - scope.getRegistry(), - Root.class, - Sub.class - ); - } - - @Test - void testAttributes(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final RootClass rootBinding = (RootClass) metadataCollector.getEntityBinding( Root.class.getName() ); - final JoinedSubclass subBinding = (JoinedSubclass) metadataCollector.getEntityBinding( Sub.class.getName() ); - - assertThat( rootBinding.getDeclaredProperties() ).hasSize( 2 ); - assertThat( rootBinding.getProperties() ).hasSize( 2 ); - assertThat( rootBinding.getPropertyClosure() ).hasSize( 2 ); - assertThat( rootBinding.getSubclassPropertyClosure() ).hasSize( 3 ); - - assertThat( subBinding.getDeclaredProperties() ).hasSize( 1 ); - assertThat( subBinding.getProperties() ).hasSize( 1 ); - assertThat( subBinding.getPropertyClosure() ).hasSize( 3 ); - assertThat( subBinding.getSubclassPropertyClosure() ).hasSize( 3 ); - }, - scope.getRegistry(), - Root.class, - Sub.class - ); - } - - @Entity(name="Root") - @Table(name="Root") - @Inheritance(strategy = InheritanceType.JOINED) - @DiscriminatorColumn(discriminatorType = DiscriminatorType.CHAR) - @DiscriminatorValue("R") - public static class Root { - @Id - private Integer id; - private String name; - } - - @Entity(name="Sub") - @Table(name="Sub") - @DiscriminatorValue("S") - public static class Sub extends Root { - private String otherStuff; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/SingleTableTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/SingleTableTests.java deleted file mode 100644 index 87e0eb64c9..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/SingleTableTests.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.inheritance; - -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.RootClass; -import org.hibernate.mapping.SingleTableSubclass; -import org.hibernate.mapping.Subclass; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.DiscriminatorColumn; -import jakarta.persistence.DiscriminatorType; -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Table; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -@SuppressWarnings("JUnitMalformedDeclaration") -@ServiceRegistry -public class SingleTableTests { - @Test - void testNoInheritance(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final PersistentClass rootBinding = metadataCollector.getEntityBinding( Single.class.getName() ); - final BasicValue discriminatorMapping = (BasicValue) rootBinding.getDiscriminator(); - assertThat( discriminatorMapping ).isNull(); - }, - scope.getRegistry(), - Single.class - ); - } - - @Test - void testImplicitDiscriminator(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final PersistentClass rootBinding = metadataCollector.getEntityBinding( Root.class.getName() ); - final PersistentClass subBinding = metadataCollector.getEntityBinding( Sub.class.getName() ); - - assertThat( rootBinding.getTable().isAbstract() ).isFalse(); - assertThat( rootBinding.getTable().getName() ).isEqualToIgnoringCase( "data" ); - - final BasicValue discriminatorMapping = (BasicValue) rootBinding.getDiscriminator(); - assertThat( discriminatorMapping ).isNotNull(); - assertThat( discriminatorMapping.getColumn() ).isNotNull(); - assertThat( ( (Column) discriminatorMapping.getColumn() ).getName() ).isEqualToIgnoringCase( "dtype" ); - assertThat( discriminatorMapping.resolve().getDomainJavaType().getJavaType() ).isEqualTo( String.class ); - - assertThat( rootBinding.getDiscriminatorValue() ).isEqualTo( Root.class.getName() ); - - assertThat( subBinding.getTable() ).isSameAs( rootBinding.getTable() ); - assertThat( subBinding.getDiscriminatorValue() ).isEqualTo( Sub.class.getName() ); - }, - scope.getRegistry(), - Root.class, - Sub.class - ); - } - - @Test - void testExplicitDiscriminator(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final PersistentClass rootBinding = metadataCollector.getEntityBinding( ExplicitRoot.class.getName() ); - final PersistentClass subBinding = metadataCollector.getEntityBinding( ExplicitSub.class.getName() ); - - assertThat( rootBinding.getTable().isAbstract() ).isFalse(); - assertThat( rootBinding.getTable().getName() ).isEqualToIgnoringCase( "data2" ); - - final BasicValue discriminatorMapping = (BasicValue) rootBinding.getDiscriminator(); - assertThat( discriminatorMapping ).isNotNull(); - assertThat( discriminatorMapping.getColumn() ).isNotNull(); - assertThat( ( (Column) discriminatorMapping.getColumn() ).getName() ).isEqualToIgnoringCase( "type_discriminator" ); - assertThat( discriminatorMapping.resolve().getDomainJavaType().getJavaType() ).isEqualTo( Character.class ); - - assertThat( rootBinding.getDiscriminatorValue() ).isEqualTo( "R" ); - - assertThat( subBinding.getTable() ).isSameAs( rootBinding.getTable() ); - assertThat( subBinding.getDiscriminatorValue() ).isEqualTo( "S" ); - }, - scope.getRegistry(), - ExplicitRoot.class, - ExplicitSub.class - ); - } - - @Test - void testAttributes(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final RootClass rootBinding = (RootClass) metadataCollector.getEntityBinding( Root.class.getName() ); - final SingleTableSubclass subBinding = (SingleTableSubclass) metadataCollector.getEntityBinding( Sub.class.getName() ); - - assertThat( rootBinding.getDeclaredProperties() ).hasSize( 2 ); - assertThat( rootBinding.getProperties() ).hasSize( 2 ); - assertThat( rootBinding.getPropertyClosure() ).hasSize( 2 ); - assertThat( rootBinding.getSubclassPropertyClosure() ).hasSize( 3 ); - - assertThat( subBinding.getDeclaredProperties() ).hasSize( 1 ); - assertThat( subBinding.getProperties() ).hasSize( 1 ); - assertThat( subBinding.getPropertyClosure() ).hasSize( 3 ); - assertThat( subBinding.getSubclassPropertyClosure() ).hasSize( 3 ); - }, - scope.getRegistry(), - Root.class, - Sub.class - ); - } - - @Entity(name="Single") - @Table(name="Single") - public static class Single { - @Id - private Integer id; - private String name; - } - - @Entity(name="Root") - @Table(name="data") - @Inheritance(strategy = InheritanceType.SINGLE_TABLE) - public static class Root { - @Id - private Integer id; - private String name; - } - - @Entity(name="Sub") - public static class Sub extends Root { - private String details; - } - - @Entity(name="ExplicitRoot") - @Table(name="data2") - @Inheritance(strategy = InheritanceType.SINGLE_TABLE) - @DiscriminatorColumn(name = "type_discriminator", discriminatorType = DiscriminatorType.CHAR, length = 1) - @DiscriminatorValue( "R" ) - public static class ExplicitRoot { - @Id - private Integer id; - private String name; - } - - @Entity(name="Sub") - @DiscriminatorValue( "S" ) - public static class ExplicitSub extends ExplicitRoot { - private String details; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/UnionSubclassTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/UnionSubclassTests.java deleted file mode 100644 index c279b1ebd4..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/inheritance/UnionSubclassTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.inheritance; - -import org.hibernate.mapping.PersistentClass; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Table; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -public class UnionSubclassTests { - @Test - @ServiceRegistry - @SuppressWarnings("JUnitMalformedDeclaration") - void testSimpleModel(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final PersistentClass rootBinding = metadataCollector.getEntityBinding( UnionRoot.class.getName() ); - assertThat( rootBinding ).isSameAs( rootBinding.getRootClass() ); - assertThat( rootBinding.getTable() ).isSameAs( rootBinding.getRootTable() ); - assertThat( rootBinding.getTable() ).isInstanceOf( org.hibernate.mapping.Table.class ); - assertThat( rootBinding.getTable().isAbstract() ).isFalse(); - assertThat( rootBinding.getTable().getName() ).isEqualToIgnoringCase( "unionroot" ); - - final PersistentClass subBinding = metadataCollector.getEntityBinding( UnionSub.class.getName() ); - assertThat( subBinding ).isNotSameAs( subBinding.getRootClass() ); - assertThat( subBinding.getRootClass() ).isSameAs( rootBinding ); - assertThat( subBinding.getTable() ).isNotSameAs( subBinding.getRootTable() ); - assertThat( rootBinding.getTable() ).isSameAs( subBinding.getRootTable() ); - assertThat( subBinding.getTable() ).isInstanceOf( org.hibernate.mapping.DenormalizedTable.class ); - assertThat( subBinding.getTable().isAbstract() ).isFalse(); - assertThat( subBinding.getTable().getName() ).isEqualToIgnoringCase( "UnionSubclassTests$UnionSub" ); - - assertThat( rootBinding.getIdentifier() ).isNotNull(); - assertThat( rootBinding.getTable().getPrimaryKey() ).isNotNull(); - - assertThat( subBinding.getIdentifier() ).isNotNull(); - assertThat( subBinding.getTable().getPrimaryKey() ).isNotNull(); - }, - scope.getRegistry(), - UnionRoot.class, - UnionSub.class - ); - } - - /** - * @author Steve Ebersole - */ - @Entity - @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) - @Table(name = "unionroot") - public static class UnionRoot { - @Id - private Integer id; - private String name; - } - - /** - * @author Steve Ebersole - */ - @Entity - public static class UnionSub extends UnionRoot { - private String unionData; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/locking/OptimisticLockingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/locking/OptimisticLockingTests.java deleted file mode 100644 index 61b4a357f9..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/locking/OptimisticLockingTests.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.locking; - -import org.hibernate.annotations.OptimisticLockType; -import org.hibernate.annotations.OptimisticLocking; -import org.hibernate.engine.OptimisticLockStyle; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.PersistentClass; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.persistence.Version; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -public class OptimisticLockingTests { - @SuppressWarnings("JUnitMalformedDeclaration") - @Test - @ServiceRegistry - void testVersionAttribute(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - var metadataCollector = context.getMetadataCollector(); - final PersistentClass entityBinding = metadataCollector.getEntityBinding( VersionedEntity.class.getName() ); - assertThat( entityBinding.getVersion() ).isNotNull(); - final BasicValue value = (BasicValue) entityBinding.getVersion().getValue(); - final org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) value.getColumn(); - assertThat( column ).isNotNull(); - assertThat( column.getName() ).isEqualTo( "version" ); - }, - scope.getRegistry(), - VersionedEntity.class - ); - } - - @SuppressWarnings("JUnitMalformedDeclaration") - @Test - @ServiceRegistry - void testVersionAttributeWithColumn(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - var metadataCollector = context.getMetadataCollector(); - final PersistentClass entityBinding = metadataCollector.getEntityBinding( VersionedEntityWithColumn.class.getName() ); - assertThat( entityBinding.getVersion() ).isNotNull(); - final BasicValue value = (BasicValue) entityBinding.getVersion().getValue(); - final org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) value.getColumn(); - assertThat( column ).isNotNull(); - assertThat( column.getName() ).isEqualTo( "revision" ); - }, - scope.getRegistry(), - VersionedEntityWithColumn.class - ); - } - - @SuppressWarnings("JUnitMalformedDeclaration") - @Test - @ServiceRegistry - void testDirtyVersioning(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - var metadataCollector = context.getMetadataCollector(); - final PersistentClass entityBinding = metadataCollector.getEntityBinding( DirtyVersionedEntity.class.getName() ); - assertThat( entityBinding.getOptimisticLockStyle() ).isEqualTo( OptimisticLockStyle.DIRTY ); - assertThat( entityBinding.getVersion() ).isNull(); - }, - scope.getRegistry(), - DirtyVersionedEntity.class - ); - } - - @Entity(name="VersionedEntity") - @Table(name="versioned") - public static class VersionedEntity { - @Id - private Integer id; - private String name; - @Version - private int version; - } - - @Entity(name="VersionedEntity") - @Table(name="versioned2") - public static class VersionedEntityWithColumn { - @Id - private Integer id; - private String name; - @Version - @Column(name = "revision") - private int version; - } - - @Entity(name="DirtyVersionedEntity") - @Table(name="versioned3") - @OptimisticLocking(type = OptimisticLockType.DIRTY) - public static class DirtyVersionedEntity { - @Id - private Integer id; - private String name; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/mappedsuper/MappedSuperclassTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/mappedsuper/MappedSuperclassTests.java deleted file mode 100644 index 4518007be0..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/mappedsuper/MappedSuperclassTests.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.mappedsuper; - -import java.util.Set; - -import org.hibernate.annotations.TenantId; -import org.hibernate.orm.test.boot.models.bind.callbacks.HierarchyRoot; -import org.hibernate.orm.test.boot.models.bind.callbacks.HierarchySuper; -import org.hibernate.boot.models.categorize.spi.BasicKeyMapping; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.mapping.MappedSuperclass; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.orm.test.boot.models.bind.BindingTestingHelper; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.EmbeddedId; -import jakarta.persistence.Id; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Version; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Steve Ebersole - */ -public class MappedSuperclassTests { - - @Test - void testAssumptions() { - final Set entityHierarchies = BindingTestingHelper.buildHierarchyMetadata( HierarchyRoot.class, HierarchySuper.class ); - assertThat( entityHierarchies ).hasSize( 1 ); - final EntityHierarchy entityHierarchy = entityHierarchies.iterator().next(); - - assertThat( entityHierarchy.getIdMapping() ).isNotNull(); - final BasicKeyMapping idMapping = (BasicKeyMapping) entityHierarchy.getIdMapping(); - assertThat( idMapping.getAttribute().getMember().getAnnotationUsage( Id.class ) ).isNotNull(); - assertThat( idMapping.getAttribute().getMember().getAnnotationUsage( EmbeddedId.class ) ).isNull(); - - assertThat( entityHierarchy.getVersionAttribute() ).isNotNull(); - assertThat( entityHierarchy.getVersionAttribute().getMember().getAnnotationUsage( Version.class ) ).isNotNull(); - - assertThat( entityHierarchy.getTenantIdAttribute() ).isNotNull(); - assertThat( entityHierarchy.getTenantIdAttribute().getMember().getAnnotationUsage( TenantId.class ) ).isNotNull(); - - assertThat( entityHierarchy.getCacheRegion() ).isNotNull(); - assertThat( entityHierarchy.getCacheRegion().getAccessType() ).isEqualTo( AccessType.READ_ONLY ); - - assertThat( entityHierarchy.getInheritanceType() ).isNotNull(); - assertThat( entityHierarchy.getInheritanceType() ).isEqualTo( InheritanceType.JOINED ); - } - - @SuppressWarnings("JUnitMalformedDeclaration") - @Test - @ServiceRegistry - void testBindings(ServiceRegistryScope scope) { - BindingTestingHelper.checkDomainModel( - (context) -> { - final var metadataCollector = context.getMetadataCollector(); - final MappedSuperclass superBinding = metadataCollector.getMappedSuperclass( HierarchySuper.class ); - final PersistentClass rootBinding = metadataCollector.getEntityBinding( HierarchyRoot.class.getName() ); - - // todo - https://github.com/sebersole/hibernate-models2/issues/81 -// assertThat( superBinding.getMappedClass() ).isEqualTo( HierarchySuper.class ); -// assertThat( superBinding.getImplicitTable() ).isNull(); -// assertThat( superBinding.hasIdentifierProperty() ).isFalse(); - - assertThat( rootBinding.getMappedClass() ).isEqualTo( HierarchyRoot.class ); - assertThat( rootBinding.getSuperMappedSuperclass() ).isSameAs( superBinding ); - assertThat( rootBinding.getImplicitTable() ).isNotNull(); - assertThat( rootBinding.getTable() ).isNotNull(); - assertThat( rootBinding.getRootTable() ).isSameAs( rootBinding.getTable() ); - assertThat( rootBinding.getIdentityTable() ).isSameAs( rootBinding.getTable() ); - assertThat( rootBinding.getIdentityTable().getPrimaryKey() ).isNotNull(); - assertThat( rootBinding.getIdentityTable().getPrimaryKey().getColumns() ).hasSize( 1 ); - assertThat( rootBinding.getIdentifier() ).isNotNull(); - assertThat( rootBinding.getIdentifierProperty() ).isNotNull(); - assertThat( rootBinding.getIdentifierProperty().getColumns() ).hasSize( 1 ); - }, - scope.getRegistry(), - HierarchyRoot.class, - HierarchySuper.class - ); - } - -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/tables/SecondaryTableTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/tables/SecondaryTableTests.java deleted file mode 100644 index 502f21ad09..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/tables/SecondaryTableTests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.tables; - -import java.util.List; - -import org.hibernate.annotations.SecondaryRow; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.SecondaryTable; -import jakarta.persistence.Table; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -public class SecondaryTableTests { - @Test - @ServiceRegistry - void testSimpleSecondaryTest(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - var metadataCollector = context.getMetadataCollector(); - final PersistentClass entityBinding = metadataCollector.getEntityBinding( Employee.class.getName() ); - final List joins = entityBinding.getJoins(); - assertThat( joins ).hasSize( 1 ); - final Join join = joins.get( 0 ); - assertThat( join.getTable().getName() ).isEqualTo( "employee_hr" ); - assertThat( join.isOptional() ).isFalse(); - // owned == false -> inverse == true - assertThat( join.isInverse() ).isTrue(); - assertThat( join.getPersistentClass() ).isSameAs( entityBinding ); - - assertThat( entityBinding.getUnjoinedProperties() ).hasSize( 2 ); - assertThat( join.getProperties() ).hasSize( 1 ); - final Property joinProperty = join.getProperties().get( 0 ); - final BasicValue value = (BasicValue) joinProperty.getValue(); - assertThat( ( (org.hibernate.mapping.Column) value.getColumn() ).getName() ).isEqualTo( "permanent_record" ); - assertThat( value.getTable() ).isSameAs( join.getTable() ); - }, - scope.getRegistry(), - Employee.class - ); - } - - @Entity(name="Employee") - @Table(name="employee") - @SecondaryTable(name="employee_hr") - @SecondaryRow(table="employee_hr", optional = false, owned = false) - public static class Employee { - @Id - private Integer id; - private String name; - @Column(name = "permanent_record", table = "employee_hr") - private String permanentRecord; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/tenancy/SimpleTenancyTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/tenancy/SimpleTenancyTests.java deleted file mode 100644 index fc1e040b8e..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/bind/tenancy/SimpleTenancyTests.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.bind.tenancy; - -import org.hibernate.annotations.TenantId; -import org.hibernate.boot.models.bind.internal.BasicValueHelper; -import org.hibernate.mapping.BasicValue; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; - -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; -import org.junit.jupiter.api.Test; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.Id; -import jakarta.persistence.Table; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.orm.test.boot.models.bind.BindingTestingHelper.checkDomainModel; - -/** - * @author Steve Ebersole - */ -public class SimpleTenancyTests { - @SuppressWarnings("JUnitMalformedDeclaration") - @Test - @ServiceRegistry - void testSimpleTenancy(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - var metadataCollector = context.getMetadataCollector(); - - assertThat( metadataCollector.getFilterDefinition( BasicValueHelper.TENANT_FILTER_NAME ) ).isNotNull(); - - final PersistentClass entityBinding = metadataCollector.getEntityBinding( ProtectedEntity.class.getName() ); - final Property tenantProperty = entityBinding.getProperty( "tenant" ); - final BasicValue value = (BasicValue) tenantProperty.getValue(); - final org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) value.getColumn(); - - assertThat( tenantProperty.isUpdateable() ).isFalse(); - assertThat( tenantProperty.isOptional() ).isFalse(); - - assertThat( value.getEnumerationStyle() ).isEqualTo( EnumType.ORDINAL ); - - assertThat( column.getName() ).isEqualTo( "tenant" ); - }, - scope.getRegistry(), - ProtectedEntity.class - ); - } - - @SuppressWarnings("JUnitMalformedDeclaration") - @Test - @ServiceRegistry - void testTenancyWithColumn(ServiceRegistryScope scope) { - checkDomainModel( - (context) -> { - var metadataCollector = context.getMetadataCollector(); - - assertThat( metadataCollector.getFilterDefinition( BasicValueHelper.TENANT_FILTER_NAME ) ).isNotNull(); - - final PersistentClass entityBinding = metadataCollector.getEntityBinding( ProtectedEntityWithColumn.class.getName() ); - final Property tenantProperty = entityBinding.getProperty( "tenant" ); - final BasicValue value = (BasicValue) tenantProperty.getValue(); - final org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) value.getColumn(); - - assertThat( tenantProperty.isUpdateable() ).isFalse(); - assertThat( tenantProperty.isOptional() ).isFalse(); - - assertThat( value.getEnumerationStyle() ).isEqualTo( EnumType.STRING ); - - assertThat( column.getName() ).isEqualTo( "customer" ); - }, - scope.getRegistry(), - ProtectedEntityWithColumn.class - ); - } - - enum Tenant { ACME, SPACELY } - - @Entity(name="ProtectedEntity") - @Table(name="protected_entity") - public static class ProtectedEntity { - @Id - private Integer id; - private String name; - @TenantId - @Enumerated - private Tenant tenant; - } - - @Entity(name="ProtectedEntity") - @Table(name="protected_entity") - public static class ProtectedEntityWithColumn { - @Id - private Integer id; - private String name; - @TenantId - @Enumerated(EnumType.STRING) - @Column(name="customer") - private Tenant tenant; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/ManagedResourcesSmokeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/ManagedResourcesSmokeTests.java deleted file mode 100644 index 5bec74a303..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/ManagedResourcesSmokeTests.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.process; - -import java.util.Iterator; -import java.util.Set; - -import org.hibernate.annotations.FilterDef; -import org.hibernate.annotations.ParamDef; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.internal.BootstrapContextImpl; -import org.hibernate.boot.internal.MetadataBuilderImpl; -import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.model.process.spi.MetadataBuildingProcess; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.BasicKeyMapping; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.FieldDetails; - -import org.junit.jupiter.api.Test; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.persistence.spi.PersistenceUnitInfo; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * {@linkplain MetadataBuildingProcess#prepare} produces a {@linkplain ManagedResources} which - * represents the complete set of classes and xml mappings. - *

- * The known XML mappings combine explicit mappings, plus any discovered during scanning. - *

- * The known classes combine explicit values, plus any discovered during scanning. It also - * already excludes classes as per JPA's {@linkplain PersistenceUnitInfo#excludeUnlistedClasses()} - * handling. - *

- * The "known classes" + all classes named in "known XML mappings" represents the complete - * set of "managed classes" (JPA's term) which Hibernate will process for annotations - - * {@code @Entity}, {@code @Converter}, ... - *

- * Let's see how using that with hibernate-models that might work... - * - * @author Steve Ebersole - */ -public class ManagedResourcesSmokeTests { - @Test - void testCategorization() { - try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) { - final MetadataSources metadataSources = new MetadataSources( serviceRegistry ).addAnnotatedClass( Person.class ); - final MetadataBuilderImpl.MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ); - final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl( serviceRegistry, metadataBuildingOptions ); - final ManagedResources managedResources = MetadataBuildingProcess.prepare( metadataSources, bootstrapContext ); - - final CategorizedDomainModel categorizedDomainModel = ManagedResourcesProcessor.processManagedResources( - managedResources, - bootstrapContext - ); - - final Set entityHierarchies = categorizedDomainModel.getEntityHierarchies(); - assertThat( entityHierarchies ).hasSize( 1 ); - final EntityHierarchy entityHierarchy = entityHierarchies.iterator().next(); - final EntityTypeMetadata entityDescriptor = entityHierarchy.getRoot(); - final ClassDetails entityClassDetails = entityDescriptor.getClassDetails(); - assertThat( entityClassDetails.getClassName() ).isEqualTo( Person.class.getName() ); - assertThat( entityDescriptor.getAttributes() ).hasSize( 2 ); - - final Iterator attributes = entityDescriptor.getAttributes().iterator(); - final AttributeMetadata firstAttribute = attributes.next(); - final AttributeMetadata secondAttribute = attributes.next(); - - assertThat( firstAttribute.getMember() ).isInstanceOf( FieldDetails.class ); - assertThat( secondAttribute.getMember() ).isInstanceOf( FieldDetails.class ); - - assertThat( entityHierarchy.getIdMapping() ).isInstanceOf( BasicKeyMapping.class ); - final BasicKeyMapping idMapping = (BasicKeyMapping) entityHierarchy.getIdMapping(); - final AttributeMetadata idAttribute = idMapping.getAttribute(); - assertThat( idAttribute.getName() ).isEqualTo( "id" ); - assertThat( idAttribute.getMember() ).isInstanceOf( FieldDetails.class ); - } - } - - @Entity(name="Person") - @Table(name="persons", comment = "We store stuff here") - @FilterDef( name = "name", defaultCondition = "name = :name", parameters = @ParamDef( name = "name", type = String.class ) ) - public static class Person { - @Id - private Integer id; - private String name; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Person.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Person.java deleted file mode 100644 index 44de01336c..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Person.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.process; - -import java.util.UUID; - -import org.hibernate.annotations.ConverterRegistration; -import org.hibernate.annotations.FilterDef; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.JavaTypeRegistration; -import org.hibernate.annotations.ParamDef; -import org.hibernate.id.IncrementGenerator; -import org.hibernate.orm.test.boot.models.MyUuidConverter; -import org.hibernate.type.descriptor.java.StringJavaType; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.NamedNativeQuery; -import jakarta.persistence.NamedQuery; -import jakarta.persistence.NamedStoredProcedureQuery; -import jakarta.persistence.SequenceGenerator; -import jakarta.persistence.Table; -import jakarta.persistence.TableGenerator; - -/** - * @author Steve Ebersole - */ -@Entity(name = "Person") -@Table(name = "persons") -@SequenceGenerator(name = "seq_gen", sequenceName = "id_seq") -@TableGenerator(name = "tbl_gen", table = "id_tbl") -@GenericGenerator(name = "increment_gen", type = IncrementGenerator.class) -@JavaTypeRegistration(javaType = String.class, descriptorClass = StringJavaType.class) -@ConverterRegistration(domainType = UUID.class, converter = MyUuidConverter.class) -@NamedQuery(name = "jpaHql", query = "from Person") -@NamedNativeQuery(name = "jpaNative", query = "select * from persons") -@NamedStoredProcedureQuery(name = "jpaCallable", procedureName = "jpa_callable") -@org.hibernate.annotations.NamedQuery(name = "ormHql", query = "from Person") -@org.hibernate.annotations.NamedNativeQuery(name = "ormNative", query = "select * from persons") -@FilterDef(name = "name_filter", defaultCondition = "name = :name", parameters = {@ParamDef(name = "name", type = String.class)}) -public class Person { - @Id - private Integer id; - private String name; -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Root.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Root.java deleted file mode 100644 index 8e324a75bc..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Root.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.process; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Table; - -/** - * @author Steve Ebersole - */ -@Entity(name = "Root") -@Table(name = "roots") -@Inheritance(strategy = InheritanceType.JOINED) -public class Root { - @Id - private Integer id; - private String name; -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/SimpleProcessorTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/SimpleProcessorTests.java deleted file mode 100644 index 1a6e4d6939..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/SimpleProcessorTests.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.process; - -import java.util.Iterator; -import java.util.Map; - -import org.hibernate.boot.internal.MetadataBuilderImpl; -import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.orm.test.boot.models.BootstrapContextTesting; -import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; -import org.hibernate.orm.test.boot.models.MyStringConverter; -import org.hibernate.orm.test.boot.models.MyUuidConverter; -import org.hibernate.orm.test.boot.models.SourceModelTestHelper; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.FilterDefRegistration; -import org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.type.CharBooleanConverter; -import org.hibernate.type.YesNoConverter; -import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; -import org.hibernate.type.descriptor.java.AbstractClassJavaType; -import org.hibernate.type.descriptor.java.StringJavaType; - -import org.junit.jupiter.api.Test; - -import org.jboss.jandex.Index; - -import jakarta.persistence.InheritanceType; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.models.internal.SimpleClassLoading.SIMPLE_CLASS_LOADING; - -/** - * Tests the general process / flow of using hibernate-models - * - * @author Steve Ebersole - */ -public class SimpleProcessorTests { - @Test - void testSimpleUsage() { - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // ManagedResources is built by scanning and from explicit resources - // during ORM bootstrap - final AdditionalManagedResourcesImpl.Builder managedResourcesBuilder = new AdditionalManagedResourcesImpl.Builder(); - managedResourcesBuilder - .addLoadedClasses( Person.class, Root.class, Sub.class, MyStringConverter.class, MyUuidConverter.class ) - .addPackages( "org.hibernate.models.orm.process" ); - final ManagedResources managedResources = managedResourcesBuilder.build(); - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // The Jandex index would generally (1) be built by WF and passed - // to ORM or (2) be built by ORM - final Index jandexIndex = SourceModelTestHelper.buildJandexIndex( - SIMPLE_CLASS_LOADING, - Person.class, - Root.class, - Sub.class, - MyStringConverter.class, - MyUuidConverter.class, - YesNoConverter.class, - CharBooleanConverter.class, - BasicValueConverter.class, - StringJavaType.class, - AbstractClassJavaType.class - ); - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) { - final MetadataBuilderImpl.MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ); - final BootstrapContextTesting bootstrapContext = new BootstrapContextTesting( jandexIndex, serviceRegistry, metadataBuildingOptions ); - final CategorizedDomainModel categorizedDomainModel = ManagedResourcesProcessor.processManagedResources( managedResources, bootstrapContext ); - - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 2 ); - final Iterator hierarchies = categorizedDomainModel.getEntityHierarchies().iterator(); - final EntityHierarchy one = hierarchies.next(); - final EntityHierarchy two = hierarchies.next(); - - assertThat( one.getRoot() ).isNotNull(); - assertThat( one.getRoot().getClassDetails() ).isNotNull(); - assertThat( one.getRoot().getClassDetails().getClassName() ).isNotNull(); - if ( one.getRoot().getClassDetails().getClassName().endsWith( "Person" ) ) { - validatePersonHierarchy( one ); - validateJoinedHierarchy( two ); - } - else { - validatePersonHierarchy( two ); - validateJoinedHierarchy( one ); - } - - validateFilterDefs( categorizedDomainModel.getGlobalRegistrations().getFilterDefRegistrations() ); - } - } - - private void validatePersonHierarchy(EntityHierarchy hierarchy) { - assertThat( hierarchy.getInheritanceType() ).isEqualTo( InheritanceType.SINGLE_TABLE ); - final EntityTypeMetadata personMetadata = hierarchy.getRoot(); - assertThat( personMetadata.getClassDetails().getClassName() ).isEqualTo( Person.class.getName() ); - assertThat( personMetadata.getJpaEntityName() ).isEqualTo( "Person" ); - assertThat( personMetadata.getEntityName() ).isEqualTo( Person.class.getName() ); - - assertThat( personMetadata.getSuperType() ).isNull(); - assertThat( personMetadata.hasSubTypes() ).isFalse(); - assertThat( personMetadata.getNumberOfSubTypes() ).isEqualTo( 0 ); - } - - private void validateJoinedHierarchy(EntityHierarchy hierarchy) { - assertThat( hierarchy.getInheritanceType() ).isEqualTo( InheritanceType.JOINED ); - final EntityTypeMetadata rootMetadata = hierarchy.getRoot(); - assertThat( rootMetadata.getClassDetails().getClassName() ).isEqualTo( Root.class.getName() ); - assertThat( rootMetadata.getJpaEntityName() ).isEqualTo( "Root" ); - assertThat( rootMetadata.getEntityName() ).isEqualTo( Root.class.getName() ); - - assertThat( rootMetadata.getSuperType() ).isNull(); - assertThat( rootMetadata.hasSubTypes() ).isTrue(); - assertThat( rootMetadata.getNumberOfSubTypes() ).isEqualTo( 1 ); - - final EntityTypeMetadata subMetadata = (EntityTypeMetadata) rootMetadata.getSubTypes().iterator().next(); - assertThat( subMetadata ).isNotNull(); - assertThat( subMetadata.getClassDetails().getClassName() ).isEqualTo( Sub.class.getName() ); - assertThat( subMetadata.getJpaEntityName() ).isEqualTo( "Sub" ); - assertThat( subMetadata.getEntityName() ).isEqualTo( Sub.class.getName() ); - assertThat( subMetadata.getSuperType() ).isEqualTo( rootMetadata ); - assertThat( subMetadata.hasSubTypes() ).isFalse(); - assertThat( subMetadata.getNumberOfSubTypes() ).isEqualTo( 0 ); - } - - private void validateFilterDefs(Map filterDefRegistrations) { - assertThat( filterDefRegistrations ).hasSize( 1 ); - assertThat( filterDefRegistrations ).containsKey( "name_filter" ); - final FilterDefRegistration nameFilter = filterDefRegistrations.get( "name_filter" ); - assertThat( nameFilter.getDefaultCondition() ).isEqualTo( "name = :name" ); - final Map parameters = nameFilter.getParameterTypes(); - assertThat( parameters ).hasSize( 1 ); - assertThat( parameters ).containsKey( "name" ); - assertThat( parameters.get( "name" ).getName() ).isEqualTo( String.class.getName() ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Sub.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Sub.java deleted file mode 100644 index f613df4afa..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/process/Sub.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.orm.test.boot.models.process; - -import jakarta.persistence.Access; -import jakarta.persistence.AccessType; -import jakarta.persistence.Basic; -import jakarta.persistence.Entity; -import jakarta.persistence.Table; - -/** - * @author Steve Ebersole - */ -@Entity(name = "Sub") -@Table(name = "subs") -@Access(AccessType.PROPERTY) -public class Sub extends Root { - private String moreDetails; - - @Basic - public String getMoreDetails() { - return moreDetails; - } - - public void setMoreDetails(String moreDetails) { - this.moreDetails = moreDetails; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java index f276466a6f..1adba41e3a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java @@ -9,21 +9,26 @@ package org.hibernate.orm.test.boot.models.xml; import java.util.List; import java.util.Map; +import org.hibernate.boot.internal.MetadataBuilderImpl; +import org.hibernate.boot.internal.RootMappingDefaults; import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl; -import org.hibernate.orm.test.boot.models.SourceModelTestHelper; -import org.hibernate.boot.models.categorize.internal.DomainModelCategorizationCollector; -import org.hibernate.boot.models.categorize.internal.GlobalRegistrationsImpl; -import org.hibernate.boot.models.categorize.spi.FilterDefRegistration; +import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; +import org.hibernate.boot.models.internal.GlobalRegistrationsImpl; +import org.hibernate.boot.models.spi.FilterDefRegistration; +import org.hibernate.boot.models.xml.internal.XmlDocumentContextImpl; import org.hibernate.boot.models.xml.internal.XmlDocumentImpl; import org.hibernate.boot.models.xml.internal.XmlPreProcessingResultImpl; import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata; import org.hibernate.models.internal.StringTypeDescriptor; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.orm.test.boot.models.SourceModelTestHelper; import org.hibernate.orm.test.boot.models.XmlHelper; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; import org.hibernate.testing.boot.BootstrapContextImpl; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; import org.junit.jupiter.api.Test; import static jakarta.persistence.AccessType.FIELD; @@ -118,7 +123,8 @@ public class XmlProcessingSmokeTests { } @Test - void testSimpleGlobalXmlProcessing() { + @ServiceRegistry + void testSimpleGlobalXmlProcessing(ServiceRegistryScope scope) { final SourceModelBuildingContext buildingContext = SourceModelTestHelper.createBuildingContext( StringTypeDescriptor.class ); final XmlPreProcessingResultImpl collectedXmlResources = new XmlPreProcessingResultImpl(); @@ -131,7 +137,18 @@ public class XmlProcessingSmokeTests { null, buildingContext ); - collectedXmlResources.getDocuments().forEach( collector::apply ); + collectedXmlResources.getDocuments().forEach( jaxbEntityMappings -> { + final XmlDocumentContextImpl xmlDocumentContext = new XmlDocumentContextImpl( + XmlDocumentImpl.consume( jaxbEntityMappings, collectedXmlResources.getPersistenceUnitMetadata() ), + new RootMappingDefaults( + new MetadataBuilderImpl.MappingDefaultsImpl( scope.getRegistry() ), + collectedXmlResources.getPersistenceUnitMetadata() + ), + buildingContext, + new BootstrapContextImpl() + ); + collector.apply( jaxbEntityMappings, xmlDocumentContext ); + } ); final GlobalRegistrationsImpl globalRegistrations = collector.getGlobalRegistrations(); assertThat( globalRegistrations.getJavaTypeRegistrations() ).hasSize( 1 ); @@ -147,8 +164,8 @@ public class XmlProcessingSmokeTests { .isEqualTo( MyUserType.class.getName() ); assertThat( globalRegistrations.getConverterRegistrations() ).hasSize( 1 ); - assertThat( globalRegistrations.getConverterRegistrations().get(0).getConverterType().getClassName() ) - .isEqualTo( org.hibernate.type.YesNoConverter.class.getName() ); + assertThat( globalRegistrations.getConverterRegistrations().get(0).getConverterType() ) + .isEqualTo( org.hibernate.type.YesNoConverter.class ); validateFilterDefs( globalRegistrations.getFilterDefRegistrations() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/AnyTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/AnyTests.java index 3bb719f7ea..2278e3abfe 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/AnyTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/AnyTests.java @@ -6,22 +6,22 @@ */ package org.hibernate.orm.test.boot.models.xml.attr; +import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import org.hibernate.annotations.Any; import org.hibernate.annotations.AnyDiscriminator; import org.hibernate.annotations.AnyDiscriminatorValue; +import org.hibernate.boot.internal.AnyKeyType; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.internal.AnyKeyType; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistryScope; @@ -34,7 +34,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.Table; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Steve Ebersole @@ -55,42 +55,42 @@ public class AnyTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 3 ); - final EntityHierarchy entity3Hierarchy = categorizedDomainModel.getEntityHierarchies() - .stream() - .filter( hierarchy -> hierarchy.getRoot().getEntityName().endsWith( "Entity3" ) ) - .findFirst() - .orElse( null ); - assertThat( entity3Hierarchy ).isNotNull(); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - final FieldDetails associationField = entity3Hierarchy.getRoot().getClassDetails().findFieldByName( "association" ); + // Entity3 is mapped by XML + final ClassDetails entity3ClassDetails = classDetailsRegistry.resolveClassDetails( Entity3.class.getName() ); + + final FieldDetails associationField = entity3ClassDetails.findFieldByName( "association" ); assertThat( associationField ).isNotNull(); - assertThat( associationField.getAnnotationUsage( Any.class ) ).isNotNull(); + assertThat( associationField.getDirectAnnotationUsage( Any.class ) ).isNotNull(); - final AnnotationUsage discrimAnn = associationField.getAnnotationUsage( AnyDiscriminator.class ); + final AnyDiscriminator discrimAnn = associationField.getDirectAnnotationUsage( AnyDiscriminator.class ); assertThat( discrimAnn ).isNotNull(); - assertThat( discrimAnn.getEnum( "value" ) ).isEqualTo( DiscriminatorType.INTEGER ); + assertThat( discrimAnn.value() ).isEqualTo( DiscriminatorType.INTEGER ); - final List> discriminatorMappings = associationField.getRepeatedAnnotationUsages( AnyDiscriminatorValue.class ); + final AnyDiscriminatorValue[] discriminatorMappings = associationField.getRepeatedAnnotationUsages( AnyDiscriminatorValue.class, sourceModelBuildingContext ); assertThat( discriminatorMappings ).hasSize( 2 ); - final List mappedEntityNames = discriminatorMappings.stream() - .map( (valueAnn) -> valueAnn.getClassDetails( "entity" ).getName() ) - .collect( Collectors.toList() ); + final List mappedEntityNames = Arrays.stream( discriminatorMappings ) + .map( (valueAnn) -> valueAnn.entity().getName() ) + .toList(); assertThat( mappedEntityNames ).containsExactly( Entity1.class.getName(), Entity2.class.getName() ); - final AnnotationUsage keyTypeAnn = associationField.getAnnotationUsage( AnyKeyType.class ); + final AnyKeyType keyTypeAnn = associationField.getDirectAnnotationUsage( AnyKeyType.class ); assertThat( keyTypeAnn ).isNotNull(); - assertThat( keyTypeAnn.getString( "value" ) ).isEqualTo( "integer" ); + assertThat( keyTypeAnn.value() ).isEqualTo( "integer" ); - final AnnotationUsage keyColumn = associationField.getAnnotationUsage( JoinColumn.class ); + final JoinColumn keyColumn = associationField.getAnnotationUsage( JoinColumn.class, sourceModelBuildingContext ); assertThat( keyColumn ).isNotNull(); - assertThat( keyColumn.getString( "name" ) ).isEqualTo( "association_fk" ); + assertThat( keyColumn.name() ).isEqualTo( "association_fk" ); } @Entity(name="Entity1") diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/ManyToOneTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/ManyToOneTests.java index 6fd2fd7dab..a3a04c9318 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/ManyToOneTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/attr/ManyToOneTests.java @@ -6,8 +6,6 @@ */ package org.hibernate.orm.test.boot.models.xml.attr; -import java.util.List; - import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; import org.hibernate.annotations.Fetch; @@ -21,13 +19,12 @@ import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.internal.Target; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistryScope; @@ -40,7 +37,7 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Steve Ebersole @@ -59,47 +56,46 @@ public class ManyToOneTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( SimpleEntity.class.getName() ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata root = hierarchy.getRoot(); - - final FieldDetails parentField = root.getClassDetails().findFieldByName( "parent" ); - final AnnotationUsage manyToOneAnn = parentField.getAnnotationUsage( ManyToOne.class ); + final FieldDetails parentField = classDetails.findFieldByName( "parent" ); + final ManyToOne manyToOneAnn = parentField.getDirectAnnotationUsage( ManyToOne.class ); assertThat( manyToOneAnn ).isNotNull(); - final AnnotationUsage joinColumnAnn = parentField.getAnnotationUsage( JoinColumn.class ); + final JoinColumn joinColumnAnn = parentField.getAnnotationUsage( JoinColumn.class, sourceModelBuildingContext ); assertThat( joinColumnAnn ).isNotNull(); - assertThat( joinColumnAnn.getString( "name" ) ).isEqualTo( "parent_fk" ); + assertThat( joinColumnAnn.name() ).isEqualTo( "parent_fk" ); - assertThat( parentField.getAnnotationUsage( JoinColumn.class ) ).isNotNull(); - - final AnnotationUsage notFoundAnn = parentField.getAnnotationUsage( NotFound.class ); + final NotFound notFoundAnn = parentField.getDirectAnnotationUsage( NotFound.class ); assertThat( notFoundAnn ).isNotNull(); - assertThat( notFoundAnn.getEnum( "action" ) ).isEqualTo( NotFoundAction.IGNORE ); + assertThat( notFoundAnn.action() ).isEqualTo( NotFoundAction.IGNORE ); - final AnnotationUsage onDeleteAnn = parentField.getAnnotationUsage( OnDelete.class ); + final OnDelete onDeleteAnn = parentField.getDirectAnnotationUsage( OnDelete.class ); assertThat( onDeleteAnn ).isNotNull(); - assertThat( onDeleteAnn.getEnum( "action" ) ).isEqualTo( OnDeleteAction.CASCADE ); + assertThat( onDeleteAnn.action() ).isEqualTo( OnDeleteAction.CASCADE ); - final AnnotationUsage fetchAnn = parentField.getAnnotationUsage( Fetch.class ); + final Fetch fetchAnn = parentField.getDirectAnnotationUsage( Fetch.class ); assertThat( fetchAnn ).isNotNull(); - assertThat( fetchAnn.getEnum( "value" ) ).isEqualTo( FetchMode.SELECT ); + assertThat( fetchAnn.value() ).isEqualTo( FetchMode.SELECT ); - final AnnotationUsage optLockAnn = parentField.getAnnotationUsage( OptimisticLock.class ); + final OptimisticLock optLockAnn = parentField.getDirectAnnotationUsage( OptimisticLock.class ); assertThat( optLockAnn ).isNotNull(); - assertThat( optLockAnn.getBoolean( "excluded" ) ).isTrue(); + assertThat( optLockAnn.excluded() ).isTrue(); - final AnnotationUsage targetAnn = parentField.getAnnotationUsage( Target.class ); + final Target targetAnn = parentField.getDirectAnnotationUsage( Target.class ); assertThat( targetAnn ).isNotNull(); - assertThat( targetAnn.getString( "value" ) ).isEqualTo( "org.hibernate.orm.test.boot.models.xml.attr.ManyToOneTests$SimpleEntity" ); + assertThat( targetAnn.value() ).isEqualTo( "org.hibernate.orm.test.boot.models.xml.attr.ManyToOneTests$SimpleEntity" ); - final AnnotationUsage cascadeAnn = parentField.getAnnotationUsage( Cascade.class ); - final List cascadeTypes = cascadeAnn.getList( "value" ); + final Cascade cascadeAnn = parentField.getDirectAnnotationUsage( Cascade.class ); + final CascadeType[] cascadeTypes = cascadeAnn.value(); assertThat( cascadeTypes ).isNotEmpty(); assertThat( cascadeTypes ).containsOnly( CascadeType.ALL ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/column/ColumnTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/column/ColumnTests.java index fe3524e80e..df3a07eceb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/column/ColumnTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/column/ColumnTests.java @@ -9,13 +9,11 @@ package org.hibernate.orm.test.boot.models.xml.column; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistryScope; @@ -24,7 +22,7 @@ import org.junit.jupiter.api.Test; import jakarta.persistence.Column; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Steve Ebersole @@ -41,26 +39,25 @@ public class ColumnTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); + final ClassDetails anEntityDetails = sourceModelBuildingContext.getClassDetailsRegistry().getClassDetails( AnEntity.class.getName() ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata root = hierarchy.getRoot(); - assertThat( root.getClassDetails().getClassName() ).isEqualTo( AnEntity.class.getName() ); - assertThat( root.getNumberOfAttributes() ).isEqualTo( 2 ); - final FieldDetails nameField = root.getClassDetails().findFieldByName( "name" ); + final FieldDetails nameField = anEntityDetails.findFieldByName( "name" ); assertThat( nameField ).isNotNull(); - final AnnotationUsage annotationUsage = nameField.getAnnotationUsage( Column.class ); - assertThat( annotationUsage.getString( "name" ) ).isEqualTo( "nombre" ); - assertThat( annotationUsage.getInteger( "length" ) ).isEqualTo( 256 ); - assertThat( annotationUsage.getString( "comment" ) ).isEqualTo( "The name column" ); - assertThat( annotationUsage.getString( "table" ) ).isEqualTo( "tbl" ); - assertThat( annotationUsage.getString( "options" ) ).isEqualTo( "the options" ); - assertThat( annotationUsage.getList( "check" ) ).isNotEmpty(); + final Column annotationUsage = nameField.getDirectAnnotationUsage( Column.class ); + assertThat( annotationUsage.name() ).isEqualTo( "nombre" ); + assertThat( annotationUsage.length() ).isEqualTo( 256 ); + assertThat( annotationUsage.comment() ).isEqualTo( "The name column" ); + assertThat( annotationUsage.table() ).isEqualTo( "tbl" ); + assertThat( annotationUsage.options() ).isEqualTo( "the options" ); + assertThat( annotationUsage.check() ).isNotEmpty(); } @Test @@ -74,22 +71,20 @@ public class ColumnTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); + final ClassDetails anEntityDetails = sourceModelBuildingContext.getClassDetailsRegistry().getClassDetails( AnEntity.class.getName() ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata root = hierarchy.getRoot(); - assertThat( root.getClassDetails().getClassName() ).isEqualTo( AnEntity.class.getName() ); - - assertThat( root.getNumberOfAttributes() ).isEqualTo( 2 ); - final FieldDetails nameField = root.getClassDetails().findFieldByName( "name" ); + final FieldDetails nameField = anEntityDetails.findFieldByName( "name" ); assertThat( nameField ).isNotNull(); - final AnnotationUsage columnAnn = nameField.getAnnotationUsage( Column.class ); + final Column columnAnn = nameField.getDirectAnnotationUsage( Column.class ); assertThat( columnAnn ).isNotNull(); - assertThat( columnAnn.getString( "name" ) ).isEqualTo( "nombre" ); + assertThat( columnAnn.name() ).isEqualTo( "nombre" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlInheritanceTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlInheritanceTests.java index c92cc92c09..0710ba483e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlInheritanceTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlInheritanceTests.java @@ -6,28 +6,30 @@ */ package org.hibernate.orm.test.boot.models.xml.complete; +import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; +import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.orm.test.boot.models.BootstrapContextTesting; import org.hibernate.orm.test.boot.models.SourceModelTestHelper; -import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.junit.jupiter.api.Test; import org.jboss.jandex.Index; import jakarta.persistence.Id; +import jakarta.persistence.Inheritance; import static jakarta.persistence.InheritanceType.JOINED; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; import static org.hibernate.models.internal.SimpleClassLoading.SIMPLE_CLASS_LOADING; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Steve Ebersole @@ -52,16 +54,23 @@ public class CompleteXmlInheritanceTests { serviceRegistry, new MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( managedResources, bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - assertThat( hierarchy.getInheritanceType() ).isEqualTo( JOINED ); + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( + managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), + bootstrapContext + ); - final EntityTypeMetadata rootMetadata = hierarchy.getRoot(); - assertThat( rootMetadata.getClassDetails().getClassName() ).isEqualTo( Root.class.getName() ); - final AttributeMetadata idAttr = rootMetadata.findAttribute( "id" ); - assertThat( idAttr.getMember().getAnnotationUsage( Id.class ) ).isNotNull(); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); + final ClassDetails root = classDetailsRegistry.getClassDetails( Root.class.getName() ); + + final Inheritance inheritance = root.getDirectAnnotationUsage( Inheritance.class ); + assertThat( inheritance.strategy() ).isEqualTo( JOINED ); + + assertThat( root.getClassName() ).isEqualTo( Root.class.getName() ); + final FieldDetails idAttr = root.findFieldByName( "id" ); + assertThat( idAttr.getDirectAnnotationUsage( Id.class ) ).isNotNull(); } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlWithEmbeddableTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlWithEmbeddableTests.java index d6d47ec6ea..b7712d5da5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlWithEmbeddableTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/CompleteXmlWithEmbeddableTests.java @@ -17,6 +17,10 @@ import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.junit.jupiter.api.Test; @@ -29,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.BASIC; import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.EMBEDDED; import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Steve Ebersole @@ -45,27 +50,22 @@ public class CompleteXmlWithEmbeddableTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); + final ClassDetails personClassDetails = classDetailsRegistry.getClassDetails( SimplePerson.class.getName() ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata personMetadata = hierarchy.getRoot(); - assertThat( personMetadata.getClassLevelAccessType() ).isEqualTo( ClassAttributeAccessType.EXPLICIT_FIELD ); + final FieldDetails idAttribute = personClassDetails.findFieldByName( "id" ); + assertThat( idAttribute.getDirectAnnotationUsage( Basic.class ) ).isNotNull(); + assertThat( idAttribute.getDirectAnnotationUsage( Id.class ) ).isNotNull(); - assertThat( personMetadata.getAttributes() ).hasSize( 2 ); - - final AttributeMetadata idAttribute = personMetadata.findAttribute( "id" ); - assertThat( idAttribute.getNature() ).isEqualTo( BASIC ); - assertThat( idAttribute.getMember().getAnnotationUsage( Basic.class ) ).isNotNull(); - assertThat( idAttribute.getMember().getAnnotationUsage( Id.class ) ).isNotNull(); - - final AttributeMetadata nameAttribute = personMetadata.findAttribute( "name" ); - assertThat( nameAttribute.getNature() ).isEqualTo( EMBEDDED ); - assertThat( nameAttribute.getMember().getAnnotationUsage( Embedded.class ) ).isNotNull(); + final FieldDetails nameAttribute = personClassDetails.findFieldByName( "name" ); + assertThat( nameAttribute.getDirectAnnotationUsage( Embedded.class ) ).isNotNull(); } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/DiscriminatorValueTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/DiscriminatorValueTest.java index 9b91b5a87f..49e3634916 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/DiscriminatorValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/DiscriminatorValueTest.java @@ -6,20 +6,17 @@ */ package org.hibernate.orm.test.boot.models.xml.complete; -import java.util.Set; - import org.hibernate.annotations.DiscriminatorFormula; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.orm.test.boot.models.xml.SimpleEntity; import org.junit.jupiter.api.Test; @@ -28,7 +25,7 @@ import jakarta.persistence.DiscriminatorType; import jakarta.persistence.DiscriminatorValue; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; public class DiscriminatorValueTest { @Test @@ -41,90 +38,64 @@ public class DiscriminatorValueTest { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - final Set entityHierarchies = categorizedDomainModel.getEntityHierarchies(); - assertThat( entityHierarchies ).hasSize( 3 ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - for ( EntityHierarchy entityHierarchy : entityHierarchies ) { - final EntityTypeMetadata root = entityHierarchy.getRoot(); + { + final ClassDetails rootClassDetails = classDetailsRegistry.getClassDetails( Root.class.getName() ); + assertThat( rootClassDetails.hasDirectAnnotationUsage( DiscriminatorValue.class ) ).isFalse(); + assertThat( rootClassDetails.hasDirectAnnotationUsage( DiscriminatorFormula.class ) ).isFalse(); - final String entityName = root.getClassDetails().getName(); - if ( entityName.equals( "org.hibernate.orm.test.boot.models.xml.complete.Root" ) ) { + final DiscriminatorColumn discriminatorColumn = rootClassDetails.getDirectAnnotationUsage( + DiscriminatorColumn.class ); + assertThat( discriminatorColumn ).isNotNull(); + assertThat( discriminatorColumn.name() ).isEqualTo( "TYPE_COLUMN" ); + assertThat( discriminatorColumn.discriminatorType() ).isEqualTo( DiscriminatorType.INTEGER ); - final AnnotationUsage rootDiscriminatorValueAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorValue.class ); - assertThat( rootDiscriminatorValueAnnotationUsage ).isNull(); + final ClassDetails subClassDetails = classDetailsRegistry.getClassDetails( Sub.class.getName() ); + assertThat( subClassDetails.hasDirectAnnotationUsage( DiscriminatorColumn.class ) ).isFalse(); + assertThat( subClassDetails.hasDirectAnnotationUsage( DiscriminatorFormula.class ) ).isFalse(); - final AnnotationUsage discriminatorColumnAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorColumn.class ); - - assertThat( discriminatorColumnAnnotationUsage ).isNotNull(); - - final String discriminatorColumName = discriminatorColumnAnnotationUsage.getString( "name" ); - assertThat( discriminatorColumName ).isEqualTo( "TYPE_COLUMN" ); - - final DiscriminatorType discriminatorColumnType = discriminatorColumnAnnotationUsage - .getEnum( "discriminatorType" ); - assertThat( discriminatorColumnType ).isEqualTo( DiscriminatorType.INTEGER ); - - final Iterable subTypes = root.getSubTypes(); - assertThat( subTypes ).hasSize( 1 ); - - final IdentifiableTypeMetadata subType = subTypes.iterator().next(); - final AnnotationUsage subTypeDiscriminatorValueAnnotationUsage = subType.getClassDetails() - .getAnnotationUsage( DiscriminatorValue.class ); - assertThat( subTypeDiscriminatorValueAnnotationUsage ).isNotNull(); - String discriminatorValue = subTypeDiscriminatorValueAnnotationUsage.getString( "value" ); - assertThat( discriminatorValue ).isEqualTo( "R" ); - - final AnnotationUsage discriminatorFortmulaAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorFormula.class ); - assertThat( discriminatorFortmulaAnnotationUsage ).isNull(); - } - else if ( entityName.equals( "org.hibernate.orm.test.boot.models.xml.complete.SimplePerson" ) ) { - final AnnotationUsage rootDiscriminatorValueAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorValue.class ); - assertThat( rootDiscriminatorValueAnnotationUsage ).isNull(); - - final AnnotationUsage discriminatorColumnAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorColumn.class ); - assertThat( discriminatorColumnAnnotationUsage ).isNotNull(); - - final String discriminatorColumName = discriminatorColumnAnnotationUsage.getString( "name" ); - assertThat( discriminatorColumName ).isEqualTo( "DTYPE" ); - - final DiscriminatorType discriminatorColumnType = discriminatorColumnAnnotationUsage - .getEnum( "discriminatorType" ); - assertThat( discriminatorColumnType ).isEqualTo( DiscriminatorType.STRING ); - - final AnnotationUsage discriminatorFortmulaAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorFormula.class ); - assertThat( discriminatorFortmulaAnnotationUsage ).isNull(); - } - else { - assertThat( entityName ).isEqualTo( "org.hibernate.orm.test.boot.models.xml.SimpleEntity" ); - - final AnnotationUsage rootDiscriminatorValueAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorValue.class ); - assertThat( rootDiscriminatorValueAnnotationUsage ).isNull(); - - final AnnotationUsage discriminatorColumnAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorColumn.class ); - assertThat( discriminatorColumnAnnotationUsage ).isNull(); - - final AnnotationUsage discriminatorFortmulaAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( DiscriminatorFormula.class ); - assertThat( discriminatorFortmulaAnnotationUsage ).isNotNull(); - - final String formula = discriminatorFortmulaAnnotationUsage.getString( "value" ); - assertThat( formula ).isEqualTo( "CASE WHEN VALUE1 IS NOT NULL THEN 1 WHEN VALUE2 IS NOT NULL THEN 2 END" ); - } + final DiscriminatorValue discriminatorValue = subClassDetails.getDirectAnnotationUsage( + DiscriminatorValue.class ); + assertThat( discriminatorValue.value() ).isEqualTo( "R" ); } + { + final ClassDetails simplePersonClassDetails = classDetailsRegistry.getClassDetails( SimplePerson.class.getName() ); + assertThat( simplePersonClassDetails.hasDirectAnnotationUsage( DiscriminatorValue.class ) ).isFalse(); + assertThat( simplePersonClassDetails.hasDirectAnnotationUsage( DiscriminatorFormula.class ) ).isFalse(); + final DiscriminatorColumn discriminatorColumn = simplePersonClassDetails.getDirectAnnotationUsage( + DiscriminatorColumn.class ); + assertThat( discriminatorColumn ).isNotNull(); + assertThat( discriminatorColumn.name() ).isEqualTo( "DTYPE" ); + assertThat( discriminatorColumn.discriminatorType() ).isEqualTo( DiscriminatorType.STRING ); + } + + { + final ClassDetails simpleEntityClassDetails = classDetailsRegistry.getClassDetails( SimpleEntity.class.getName() ); + + final DiscriminatorValue discriminatorValue = simpleEntityClassDetails.getDirectAnnotationUsage( + DiscriminatorValue.class ); + assertThat( discriminatorValue ).isNull(); + + final DiscriminatorColumn discriminatorColumn = simpleEntityClassDetails.getDirectAnnotationUsage( + DiscriminatorColumn.class ); + assertThat( discriminatorColumn ).isNull(); + + final DiscriminatorFormula discriminatorFormula = simpleEntityClassDetails.getDirectAnnotationUsage( + DiscriminatorFormula.class ); + assertThat( discriminatorFormula ).isNotNull(); + assertThat( discriminatorFormula.value() ).isEqualTo( + "CASE WHEN VALUE1 IS NOT NULL THEN 1 WHEN VALUE2 IS NOT NULL THEN 2 END" ); + assertThat( discriminatorFormula.discriminatorType() ).isEqualTo( DiscriminatorType.STRING ); + } } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/SimpleCompleteXmlTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/SimpleCompleteXmlTests.java index be52b6c194..43f64122fe 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/SimpleCompleteXmlTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/complete/SimpleCompleteXmlTests.java @@ -6,8 +6,6 @@ */ package org.hibernate.orm.test.boot.models.xml.complete; -import java.util.List; - import org.hibernate.annotations.Filter; import org.hibernate.annotations.ResultCheckStyle; import org.hibernate.annotations.SQLInsert; @@ -16,16 +14,14 @@ import org.hibernate.annotations.SqlFragmentAlias; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; -import org.hibernate.orm.test.boot.models.xml.SimpleEntity; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.orm.test.boot.models.xml.SimpleEntity; import org.junit.jupiter.api.Test; @@ -34,7 +30,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Id; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Steve Ebersole @@ -51,61 +47,56 @@ public class SimpleCompleteXmlTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata root = hierarchy.getRoot(); - assertThat( root.getClassDetails().getClassName() ).isEqualTo( SimpleEntity.class.getName() ); - assertThat( root.getNumberOfAttributes() ).isEqualTo( 2 ); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( SimpleEntity.class.getName() ); - final AttributeMetadata idAttribute = root.findAttribute( "id" ); - assertThat( idAttribute.getNature() ).isEqualTo( AttributeMetadata.AttributeNature.BASIC ); - assertThat( idAttribute.getMember().getAnnotationUsage( Basic.class ) ).isNotNull(); - assertThat( idAttribute.getMember().getAnnotationUsage( Id.class ) ).isNotNull(); - final AnnotationUsage idColumnAnn = idAttribute.getMember().getAnnotationUsage( Column.class ); + final FieldDetails idField = classDetails.findFieldByName( "id" ); + assertThat( idField.getDirectAnnotationUsage( Basic.class ) ).isNotNull(); + assertThat( idField.getDirectAnnotationUsage( Id.class ) ).isNotNull(); + final Column idColumnAnn = idField.getDirectAnnotationUsage( Column.class ); assertThat( idColumnAnn ).isNotNull(); - assertThat( idColumnAnn.getAttributeValue( "name" ) ).isEqualTo( "pk" ); + assertThat( idColumnAnn.name() ).isEqualTo( "pk" ); - final AttributeMetadata nameAttribute = root.findAttribute( "name" ); - assertThat( nameAttribute.getNature() ).isEqualTo( AttributeMetadata.AttributeNature.BASIC ); - assertThat( nameAttribute.getMember().getAnnotationUsage( Basic.class ) ).isNotNull(); - final AnnotationUsage nameColumnAnn = nameAttribute.getMember().getAnnotationUsage( Column.class ); + final FieldDetails nameField = classDetails.findFieldByName( "name" ); + assertThat( nameField.getDirectAnnotationUsage( Basic.class ) ).isNotNull(); + final Column nameColumnAnn = nameField.getDirectAnnotationUsage( Column.class ); assertThat( nameColumnAnn ).isNotNull(); - assertThat( nameColumnAnn.getAttributeValue( "name" ) ).isEqualTo( "description" ); + assertThat( nameColumnAnn.name() ).isEqualTo( "description" ); - final AnnotationUsage sqlRestriction = root.getClassDetails().getAnnotationUsage( SQLRestriction.class ); + final SQLRestriction sqlRestriction = classDetails.getDirectAnnotationUsage( SQLRestriction.class ); assertThat( sqlRestriction ).isNotNull(); - assertThat( sqlRestriction.getAttributeValue( "value" ) ).isEqualTo( "name is not null" ); + assertThat( sqlRestriction.value() ).isEqualTo( "name is not null" ); - validateSqlInsert( root.getClassDetails().getAnnotationUsage( SQLInsert.class )); + validateSqlInsert( classDetails.getDirectAnnotationUsage( SQLInsert.class )); - validateFilterUsage( root.getClassDetails().getAnnotationUsage( Filter.class ) ); + validateFilterUsage( classDetails.getAnnotationUsage( Filter.class, sourceModelBuildingContext ) ); } } - private void validateFilterUsage(AnnotationUsage filter) { + private void validateFilterUsage(Filter filter) { assertThat( filter ).isNotNull(); - assertThat( filter.getAttributeValue( "name" ) ).isEqualTo( "name_filter" ); - assertThat( filter.getAttributeValue( "condition" ) ).isEqualTo( "{t}.name = :name" ); - final List> aliases = filter.getAttributeValue( "aliases" ); + assertThat( filter.name() ).isEqualTo( "name_filter" ); + assertThat( filter.condition() ).isEqualTo( "{t}.name = :name" ); + final SqlFragmentAlias[] aliases = filter.aliases(); assertThat( aliases ).hasSize( 1 ); - assertThat( aliases.get( 0 ).getAttributeValue( "alias" ) ).isEqualTo( "t" ); - assertThat( aliases.get( 0 ).getAttributeValue( "table" ) ).isEqualTo( "SimpleEntity" ); - assertThat( aliases.get( 0 ) - .getAttributeValue( "entity" ) - .getName() ).isEqualTo( SimpleEntity.class.getName() ); + assertThat( aliases[0].alias() ).isEqualTo( "t" ); + assertThat( aliases[0].table() ).isEqualTo( "SimpleEntity" ); + assertThat( aliases[0].entity().getName() ).isEqualTo( SimpleEntity.class.getName() ); } - private void validateSqlInsert(AnnotationUsage sqlInsert) { + private void validateSqlInsert(SQLInsert sqlInsert) { assertThat( sqlInsert ).isNotNull(); - assertThat( sqlInsert.getAttributeValue( "sql" ) ).isEqualTo( "insert into SimpleEntity(name) values(?)" ); - assertThat( sqlInsert.getAttributeValue( "callable" ) ).isTrue(); - assertThat( sqlInsert.getAttributeValue( "check" ) ).isEqualTo( ResultCheckStyle.COUNT ); - assertThat( sqlInsert.getAttributeValue( "table" ) ).isEqualTo( "SimpleEntity" ); + assertThat( sqlInsert.sql() ).isEqualTo( "insertSimpleEntity(?)" ); + assertThat( sqlInsert.callable() ).isTrue(); + assertThat( sqlInsert.check() ).isEqualTo( ResultCheckStyle.COUNT ); + assertThat( sqlInsert.table() ).isEqualTo( "SimpleEntity" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/DynamicModelTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/DynamicModelTests.java index 5ea6907878..c8ecaedbac 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/DynamicModelTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/DynamicModelTests.java @@ -23,15 +23,13 @@ import org.hibernate.boot.internal.LimitedCollectionClassification; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.internal.Target; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.junit.jupiter.api.Test; @@ -46,7 +44,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Steve Ebersole @@ -62,25 +60,27 @@ public class DynamicModelTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata rootEntity = hierarchy.getRoot(); - assertThat( rootEntity.getClassDetails().getClassName() ).isNull(); - assertThat( rootEntity.getClassDetails().getName() ).isEqualTo( "SimpleEntity" ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - final FieldDetails idField = rootEntity.getClassDetails().findFieldByName( "id" ); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( "SimpleEntity" ); + assertThat( classDetails.getClassName() ).isNull(); + assertThat( classDetails.getName() ).isEqualTo( "SimpleEntity" ); + + final FieldDetails idField = classDetails.findFieldByName( "id" ); assertThat( idField.getType().determineRawClass().getClassName() ).isEqualTo( Integer.class.getName() ); - final FieldDetails nameField = rootEntity.getClassDetails().findFieldByName( "name" ); + final FieldDetails nameField = classDetails.findFieldByName( "name" ); assertThat( nameField.getType().determineRawClass().getClassName() ).isEqualTo( String.class.getName() ); - assertThat( nameField.getAnnotationUsage( JavaType.class ) ).isNotNull(); + assertThat( nameField.getDirectAnnotationUsage( JavaType.class ) ).isNotNull(); - final FieldDetails qtyField = rootEntity.getClassDetails().findFieldByName( "quantity" ); + final FieldDetails qtyField = classDetails.findFieldByName( "quantity" ); assertThat( qtyField.getType().determineRawClass().getClassName() ).isEqualTo( int.class.getName() ); } } @@ -95,52 +95,55 @@ public class DynamicModelTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata rootEntity = hierarchy.getRoot(); - assertThat( rootEntity.getClassDetails().getClassName() ).isNull(); - assertThat( rootEntity.getClassDetails().getName() ).isEqualTo( "Contact" ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - final FieldDetails idField = rootEntity.getClassDetails().findFieldByName( "id" ); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( "Contact" ); + assertThat( classDetails.getClassName() ).isNull(); + assertThat( classDetails.getName() ).isEqualTo( "Contact" ); + + final FieldDetails idField = classDetails.findFieldByName( "id" ); assertThat( idField.getType().determineRawClass().getClassName() ).isEqualTo( Integer.class.getName() ); - final FieldDetails nameField = rootEntity.getClassDetails().findFieldByName( "name" ); + final FieldDetails nameField = classDetails.findFieldByName( "name" ); assertThat( nameField.getType().determineRawClass().getClassName() ).isNull(); assertThat( nameField.getType().getName() ).isEqualTo( "Name" ); - assertThat( nameField.getAnnotationUsage( Target.class ) ).isNotNull(); - assertThat( nameField.getAnnotationUsage( Target.class ).getString( "value" ) ).isEqualTo( "Name" ); + assertThat( nameField.getDirectAnnotationUsage( Target.class ) ).isNotNull(); + assertThat( nameField.getDirectAnnotationUsage( Target.class ).value() ).isEqualTo( "Name" ); assertThat( nameField.getType().determineRawClass().getFields() ).hasSize( 2 ); - final FieldDetails labels = rootEntity.getClassDetails().findFieldByName( "labels" ); + final FieldDetails labels = classDetails.findFieldByName( "labels" ); assertThat( labels.getType().determineRawClass().getClassName() ).isEqualTo( Set.class.getName() ); - final AnnotationUsage elementCollection = labels.getAnnotationUsage( ElementCollection.class ); + final ElementCollection elementCollection = labels.getDirectAnnotationUsage( ElementCollection.class ); + assertThat( elementCollection.targetClass() ).isEqualTo( void.class ); + final Target targetUsage = labels.getDirectAnnotationUsage( Target.class ); + assertThat( targetUsage.value() ).isEqualTo( "string" ); - assertThat( elementCollection.getClassDetails( "targetClass" ) ).isEqualTo( ClassDetails.VOID_CLASS_DETAILS ); - final AnnotationUsage targetUsage = labels.getAnnotationUsage( Target.class ); - assertThat( targetUsage.getString( "value" ) ).isEqualTo( "string" ); + final CollectionClassification collectionClassification = labels.getDirectAnnotationUsage( CollectionClassification.class ); + assertThat( collectionClassification.value() ).isEqualTo( LimitedCollectionClassification.SET ); - final AnnotationUsage collectionClassification = labels.getAnnotationUsage( CollectionClassification.class ); - assertThat( collectionClassification.getAttributeValue( "value" ) ).isEqualTo( LimitedCollectionClassification.SET ); + assertThat( labels.getDirectAnnotationUsage( SortNatural.class ) ).isNotNull(); - assertThat( labels.getAnnotationUsage( SortNatural.class ) ).isNotNull(); + final CollectionTable collectionTable = labels.getDirectAnnotationUsage( CollectionTable.class ); + assertThat( collectionTable.name() ).isEqualTo( "labels" ); - final AnnotationUsage collectionTable = labels.getAnnotationUsage( CollectionTable.class ); - assertThat( collectionTable.getAttributeValue( "name" ) ).isEqualTo( "labels" ); - - final List> joinColumns = collectionTable.getList( "joinColumns" ); + final JoinColumn[] joinColumns = collectionTable.joinColumns(); assertThat( joinColumns ).hasSize( 1 ); - assertThat( joinColumns.get( 0 ).getAttributeValue( "name" ) ).isEqualTo( "contact_fk" ); + assertThat( joinColumns[0].name() ).isEqualTo( "contact_fk" ); } } @Test void testIdClass() { + // todo (7.0) : how is this dynamic? + final ManagedResources managedResources = new AdditionalManagedResourcesImpl.Builder() .addXmlMappings( "mappings/models/dynamic/dynamic-id-class.xml" ) .build(); @@ -149,25 +152,26 @@ public class DynamicModelTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata rootEntity = hierarchy.getRoot(); - assertThat( rootEntity.getClassDetails().getName() ).isEqualTo( Employee.class.getName() ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( Employee.class.getName() ); - final AnnotationUsage idClass = rootEntity.getClassDetails().getAnnotationUsage( IdClass.class ); + final IdClass idClass = classDetails.getDirectAnnotationUsage( IdClass.class ); assertThat( idClass ).isNotNull(); - assertThat( idClass.getAttributeValue( "value" ) - .getName() ).isEqualTo( EmployeePK.class.getName() ); + assertThat( idClass.value().getName() ).isEqualTo( EmployeePK.class.getName() ); } } @Test void testOneToMany() { + // todo (7.0) : how is this dynamic? + final ManagedResources managedResources = new AdditionalManagedResourcesImpl.Builder() .addXmlMappings( "mappings/models/dynamic/dynamic-plurals.xml" ) .build(); @@ -176,35 +180,35 @@ public class DynamicModelTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); - final EntityTypeMetadata rootEntity = categorizedDomainModel.getEntityHierarchies().iterator().next().getRoot(); - assertThat( rootEntity.getClassDetails().getName() ).isEqualTo( Employee.class.getName() ); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( Employee.class.getName() ); + assertThat( classDetails.getName() ).isEqualTo( Employee.class.getName() ); - final FieldDetails oneToMany = rootEntity.getClassDetails().findFieldByName( "oneToMany" ); + final FieldDetails oneToMany = classDetails.findFieldByName( "oneToMany" ); assertThat( oneToMany.getType().determineRawClass().getClassName() ).isEqualTo( List.class.getName() ); - final AnnotationUsage oneToManyAnn = oneToMany.getAnnotationUsage( OneToMany.class ); - assertThat( oneToManyAnn.getAttributeValue( "fetch" ) ).isEqualTo( FetchType.EAGER ); - assertThat( oneToMany.getAnnotationUsage( NotFound.class ) - .getAttributeValue( "action" ) ).isEqualTo( NotFoundAction.IGNORE ); - assertThat( oneToMany.getAnnotationUsage( OnDelete.class ) - .getAttributeValue( "action" ) ).isEqualTo( OnDeleteAction.CASCADE ); - final AnnotationUsage joinColumn = oneToMany.getAnnotationUsage( JoinColumn.class ); - assertThat( joinColumn.getAttributeValue( "name" ) ).isEqualTo( "employee_id" ); - assertThat( joinColumn.getAttributeValue( "insertable" ) ).isEqualTo( Boolean.FALSE ); - assertThat( joinColumn.getAttributeValue( "updatable" ) ).isEqualTo( Boolean.FALSE ); - final AnnotationUsage foreignKey = joinColumn.getAttributeValue( "foreignKey" ); - assertThat( foreignKey.getAttributeValue( "name" ) ).isEqualTo( "employee_fk" ); - assertThat( foreignKey.getAttributeValue( "value" ) ).isEqualTo( ConstraintMode.NO_CONSTRAINT ); - final List> checkConstraints = joinColumn.getList( "check" ); + final OneToMany oneToManyAnn = oneToMany.getDirectAnnotationUsage( OneToMany.class ); + assertThat( oneToManyAnn.fetch() ).isEqualTo( FetchType.EAGER ); + assertThat( oneToMany.getDirectAnnotationUsage( NotFound.class ).action() ).isEqualTo( NotFoundAction.IGNORE ); + assertThat( oneToMany.getDirectAnnotationUsage( OnDelete.class ).action() ).isEqualTo( OnDeleteAction.CASCADE ); + final JoinColumn joinColumn = oneToMany.getAnnotationUsage( JoinColumn.class, sourceModelBuildingContext ); + assertThat( joinColumn.name() ).isEqualTo( "employee_id" ); + assertThat( joinColumn.insertable() ).isEqualTo( Boolean.FALSE ); + assertThat( joinColumn.updatable() ).isEqualTo( Boolean.FALSE ); + final ForeignKey foreignKey = joinColumn.foreignKey(); + assertThat( foreignKey.name() ).isEqualTo( "employee_fk" ); + assertThat( foreignKey.value() ).isEqualTo( ConstraintMode.NO_CONSTRAINT ); + final CheckConstraint[] checkConstraints = joinColumn.check(); assertThat( checkConstraints ).hasSize( 1 ); - assertThat( checkConstraints.get( 0 ).getAttributeValue( "name" ) ).isEqualTo( "employee_id_nn" ); - assertThat( checkConstraints.get( 0 ).getAttributeValue( "constraint" ) ).isEqualTo( "employee_id is not null" ); - assertThat( oneToMany.getAnnotationUsage( Cascade.class ).getList( "value" ) ) + assertThat( checkConstraints[0].name() ).isEqualTo( "employee_id_nn" ); + assertThat( checkConstraints[0].constraint() ).isEqualTo( "employee_id is not null" ); + assertThat( oneToMany.getDirectAnnotationUsage( Cascade.class ).value() ) .contains( CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.LOCK ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/NamedEntityGraphTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/NamedEntityGraphTest.java index d642ec0b09..0025761609 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/NamedEntityGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/NamedEntityGraphTest.java @@ -6,20 +6,15 @@ */ package org.hibernate.orm.test.boot.models.xml.dynamic; -import java.util.List; -import java.util.Set; - import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.junit.jupiter.api.Test; @@ -28,7 +23,7 @@ import jakarta.persistence.NamedEntityGraph; import jakarta.persistence.NamedSubgraph; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; public class NamedEntityGraphTest { @Test @@ -41,95 +36,74 @@ public class NamedEntityGraphTest { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - final Set entityHierarchies = categorizedDomainModel.getEntityHierarchies(); - assertThat( entityHierarchies ).hasSize( 2 ); + { + final ClassDetails employeeClassDetails = classDetailsRegistry.getClassDetails( "Employee" ); + final NamedEntityGraph namedEntityGraph = employeeClassDetails.getAnnotationUsage( NamedEntityGraph.class, sourceModelBuildingContext ); + assertThat( namedEntityGraph ).isNotNull(); - entityHierarchies.forEach( - entityHierarchy -> { - final EntityTypeMetadata root = entityHierarchy.getRoot(); - final String entityName = root.getEntityName(); + assertThat( namedEntityGraph.name() ).isEqualTo( "employee" ); + assertThat( namedEntityGraph.includeAllAttributes() ).isTrue(); - final AnnotationUsage namedEntityGraphAnnotationUsage = root.getClassDetails() - .getAnnotationUsage( NamedEntityGraph.class ); + final NamedAttributeNode[] attributeNodes = namedEntityGraph.attributeNodes(); + assertThat( attributeNodes ).hasSize( 2 ); - if ( entityName.equals( "Address" ) ) { - assertThat( namedEntityGraphAnnotationUsage ).isNull(); - } - else { - assertThat( namedEntityGraphAnnotationUsage ).isNotNull(); + final NamedAttributeNode firstAttributeNode = attributeNodes[0]; + checkAttributeNode( firstAttributeNode, "name", "", "" ); - final String graphName = namedEntityGraphAnnotationUsage.getAttributeValue( "name" ); - assertThat( graphName ).isEqualTo( "employee" ); - - final boolean includeAllAttributes = namedEntityGraphAnnotationUsage.getAttributeValue( - "includeAllAttributes" ); - assertThat( includeAllAttributes ).isTrue(); - - List> namedAttributeNodeUsage = namedEntityGraphAnnotationUsage - .getAttributeValue( "attributeNodes" ); - assertThat( namedAttributeNodeUsage ).size().isEqualTo( 2 ); - - // check NamedEntityGraph attributeNodes - - AnnotationUsage firstAttributeNode = namedAttributeNodeUsage.get( 0 ); - checkAttributeNode( firstAttributeNode, "name", "", "" ); - - AnnotationUsage secondAttributeNode = namedAttributeNodeUsage.get( 1 ); - checkAttributeNode( secondAttributeNode, "address", "employee.address", "" ); - - // check NamedEntityGraph subgraphs - final List> subgraphUsages = namedEntityGraphAnnotationUsage - .getAttributeValue( "subgraphs" ); - assertThat( subgraphUsages ).size().isEqualTo( 2 ); - - AnnotationUsage firstSubgraph = subgraphUsages.get( 0 ); - assertThat( firstSubgraph.getString( "name" ) ).isEqualTo( "first.subgraph" ); - assertThat( firstSubgraph.getAttributeValue( "type" ).getName() ) - .isEqualTo( void.class.getName() ); - - // check first NamedSubgraph attributeNodes - - namedAttributeNodeUsage = firstSubgraph.getAttributeValue( "attributeNodes" ); - assertThat( namedAttributeNodeUsage ).size().isEqualTo( 1 ); - - checkAttributeNode( namedAttributeNodeUsage.get( 0 ), "city", "", "" ); - - AnnotationUsage secondSubgraph = subgraphUsages.get( 1 ); - assertThat( secondSubgraph.getString( "name" ) ).isEqualTo( "second.subgraph" ); - assertThat( secondSubgraph.getAttributeValue( "type" ).getName() ) - .isEqualTo( String.class.getName() ); - - namedAttributeNodeUsage = secondSubgraph.getAttributeValue( "attributeNodes" ); - assertThat( namedAttributeNodeUsage ).size().isEqualTo( 3 ); - - // check second NamedSubgraph attributeNodes - checkAttributeNode( namedAttributeNodeUsage.get( 0 ), "city", "sub1", "" ); - checkAttributeNode( namedAttributeNodeUsage.get( 1 ), "name", "sub", "" ); - checkAttributeNode( namedAttributeNodeUsage.get( 2 ), "surname", "", "" ); + final NamedAttributeNode secondAttributeNode = attributeNodes[1]; + checkAttributeNode( secondAttributeNode, "address", "employee.address", "" ); - final List> subClassSubgraphUsages = namedEntityGraphAnnotationUsage - .getAttributeValue( "subclassSubgraphs" ); - assertThat( subClassSubgraphUsages ).size().isEqualTo( 0 ); + final NamedSubgraph[] subgraphs = namedEntityGraph.subgraphs(); + assertThat( subgraphs ).hasSize( 2 ); - } - } - ); + final NamedSubgraph firstSubgraph = subgraphs[0]; + assertThat( firstSubgraph.name() ).isEqualTo( "first.subgraph" ); + assertThat( firstSubgraph.type() ).isEqualTo( void.class ); + + final NamedAttributeNode[] firstSubgraphAttributeNodes = firstSubgraph.attributeNodes(); + assertThat( firstSubgraphAttributeNodes ).hasSize( 1 ); + checkAttributeNode( firstSubgraphAttributeNodes[0], "city", "", "" ); + + final NamedSubgraph secondSubgraph = subgraphs[1]; + assertThat( secondSubgraph.name() ).isEqualTo( "second.subgraph" ); + assertThat( secondSubgraph.type() ).isEqualTo( String.class ); + + final NamedAttributeNode[] secondSubgraphAttributeNodes = secondSubgraph.attributeNodes(); + assertThat( secondSubgraphAttributeNodes ).hasSize( 3 ); + + checkAttributeNode( secondSubgraphAttributeNodes[0], "city", "sub1", "" ); + checkAttributeNode( secondSubgraphAttributeNodes[1], "name", "sub", "" ); + checkAttributeNode( secondSubgraphAttributeNodes[2], "surname", "", "" ); + + + final NamedSubgraph[] subClassSubgraphUsages = namedEntityGraph.subclassSubgraphs(); + assertThat( subClassSubgraphUsages ).isEmpty(); + } + + { + final ClassDetails addressClassDetails = classDetailsRegistry.getClassDetails( "Address" ); + final NamedEntityGraph namedEntityGraph = addressClassDetails.getDirectAnnotationUsage( NamedEntityGraph.class ); + assertThat( namedEntityGraph ).isNull(); + } } } private static void checkAttributeNode( - AnnotationUsage firstAttributeNode, + NamedAttributeNode firstAttributeNode, String expectedValueName, String expectedSubgraph, String expectedKeySubgraph) { - assertThat( firstAttributeNode.getString( "value" ) ).isEqualTo( expectedValueName ); - assertThat( firstAttributeNode.getString( "subgraph" ) ).isEqualTo( expectedSubgraph ); - assertThat( firstAttributeNode.getString( "keySubgraph" ) ).isEqualTo( expectedKeySubgraph ); + assertThat( firstAttributeNode.value() ).isEqualTo( expectedValueName ); + assertThat( firstAttributeNode.subgraph() ).isEqualTo( expectedSubgraph ); + assertThat( firstAttributeNode.keySubgraph() ).isEqualTo( expectedKeySubgraph ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/RowIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/RowIdTest.java index bace0b4b47..19ded85fc0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/RowIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/RowIdTest.java @@ -6,24 +6,21 @@ */ package org.hibernate.orm.test.boot.models.xml.dynamic; -import java.util.Set; - import org.hibernate.annotations.RowId; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; public class RowIdTest { @Test @@ -36,35 +33,31 @@ public class RowIdTest { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - final Set entityHierarchies = categorizedDomainModel.getEntityHierarchies(); - assertThat( entityHierarchies ).hasSize( 3 ); + { + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( "EntityWithoutRowId" ); + final RowId rowId = classDetails.getDirectAnnotationUsage( RowId.class ); + assertThat( rowId ).isNull(); + } - entityHierarchies.forEach( - entityHierarchy -> { - final EntityTypeMetadata root = entityHierarchy.getRoot(); - final AnnotationUsage rowIdAnnotationUsage = root.getClassDetails().getAnnotationUsage( - RowId.class ); - final String entityName = root.getEntityName(); - if ( entityName.equals( "EntityWithoutRowId" ) ) { - assertThat( rowIdAnnotationUsage ).isNull(); - } - else { - assertThat( rowIdAnnotationUsage ).isNotNull(); - final String value = rowIdAnnotationUsage.getString( "value" ); - if ( entityName.equals( "EntityWithRowIdNoValue" ) ) { - assertThat( value ).isEmpty(); - } - else { - assertThat( value ).isEqualTo( "ROW_ID" ); - } - } - } - ); + { + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( "EntityWithRowIdNoValue" ); + final RowId rowId = classDetails.getDirectAnnotationUsage( RowId.class ); + assertThat( rowId.value() ).isEmpty(); + } + + { + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( "EntityWithRowId" ); + final RowId rowId = classDetails.getDirectAnnotationUsage( RowId.class ); + assertThat( rowId.value() ).isEqualTo( "ROW_ID" ); + } } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/TenantIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/TenantIdTest.java index 147e443c93..979c8ec917 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/TenantIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/dynamic/TenantIdTest.java @@ -7,20 +7,17 @@ package org.hibernate.orm.test.boot.models.xml.dynamic; -import java.util.Set; - import org.hibernate.annotations.TenantId; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.FieldDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; import org.junit.jupiter.api.Test; @@ -29,7 +26,7 @@ import jakarta.persistence.Column; import jakarta.persistence.FetchType; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; public class TenantIdTest { @@ -43,42 +40,30 @@ public class TenantIdTest { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); - final Set entityHierarchies = categorizedDomainModel.getEntityHierarchies(); - assertThat( entityHierarchies ).hasSize( 2 ); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( "EntityWithTenantId" ); - entityHierarchies.forEach( - entityHierarchy -> { - final EntityTypeMetadata root = entityHierarchy.getRoot(); - final String entityName = root.getEntityName(); + final FieldDetails tenantIdField = classDetails.findFieldByName( "tenantId" ); - final FieldDetails field = root.getClassDetails().findFieldByName( "tenantId" ); + final TenantId tenantId = tenantIdField.getDirectAnnotationUsage( TenantId.class ); + assertThat( tenantId ).isNotNull(); - if ( entityName.equals( "EntityWithoutTenantId" ) ) { - assertThat( field ).isNull(); - } - else { - final AnnotationUsage tenantIdAnnotationUsage = field.getAnnotationUsage( TenantId.class ); + final Basic basic = tenantIdField.getDirectAnnotationUsage( Basic.class ); + assertThat( basic ).isNotNull(); + assertThat( basic.fetch() ).isEqualTo( FetchType.EAGER ); + assertThat( basic.optional() ).isTrue(); - assertThat( tenantIdAnnotationUsage ).isNotNull(); - - final AnnotationUsage basicAnnotationUsage = field.getAnnotationUsage( Basic.class ); - assertThat( basicAnnotationUsage ).isNotNull(); - assertThat( basicAnnotationUsage.getAttributeValue( "fetch" ) ) - .isEqualTo( FetchType.EAGER ); - assertThat( basicAnnotationUsage.getBoolean( "optional" ) ).isTrue(); - - final AnnotationUsage columnAnnotationUsage = field.getAnnotationUsage( Column.class ); - assertThat( basicAnnotationUsage ).isNotNull(); - assertThat( columnAnnotationUsage.getString( "name" ) ).isEqualTo( "TENANT_ID" ); - assertThat( columnAnnotationUsage.getBoolean( "insertable" ) ).isFalse(); - } - } - ); + final Column column = tenantIdField.getDirectAnnotationUsage( Column.class ); + assertThat( column ).isNotNull(); + assertThat( column.name() ).isEqualTo( "TENANT_ID" ); + assertThat( column.insertable() ).isFalse(); } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/globals/JpaEventListenerTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/globals/JpaEventListenerTests.java index 9636d237f7..e8fb9d1857 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/globals/JpaEventListenerTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/globals/JpaEventListenerTests.java @@ -12,7 +12,7 @@ import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.JpaEventListener; +import org.hibernate.boot.models.spi.JpaEventListener; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/lifecycle/EntityLifecycleTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/lifecycle/EntityLifecycleTests.java index 9fc1aa6738..cf2220df52 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/lifecycle/EntityLifecycleTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/lifecycle/EntityLifecycleTests.java @@ -12,15 +12,14 @@ import java.util.stream.Collectors; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; -import org.hibernate.orm.test.boot.models.xml.SimpleEntity; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.MethodDetails; +import org.hibernate.models.spi.SourceModelBuildingContext; +import org.hibernate.orm.test.boot.models.xml.SimpleEntity; import org.junit.jupiter.api.Test; @@ -34,7 +33,7 @@ import jakarta.persistence.PreRemove; import jakarta.persistence.PreUpdate; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; +import static org.hibernate.orm.test.boot.models.SourceModelTestHelper.createBuildingContext; /** * @author Marco Belladelli @@ -50,22 +49,19 @@ public class EntityLifecycleTests { serviceRegistry, new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( + final SourceModelBuildingContext sourceModelBuildingContext = createBuildingContext( managedResources, + false, + new MetadataBuilderImpl.MetadataBuildingOptionsImpl( bootstrapContext.getServiceRegistry() ), bootstrapContext ); - - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); - final EntityTypeMetadata rootEntity = categorizedDomainModel.getEntityHierarchies() - .iterator() - .next() - .getRoot(); - final ClassDetails classDetails = rootEntity.getClassDetails(); + final ClassDetailsRegistry classDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( SimpleEntity.class.getName() ); assertThat( classDetails.getName() ).isEqualTo( SimpleEntity.class.getName() ); // lifecycle callback methods getMethodDetails( classDetails, "prePersist" ).forEach( method -> { - final AnnotationUsage prePersist = method.getAnnotationUsage( PrePersist.class ); + final PrePersist prePersist = method.getDirectAnnotationUsage( PrePersist.class ); if ( !method.getArgumentTypes().isEmpty() ) { assertThat( prePersist ).isNull(); } @@ -73,18 +69,19 @@ public class EntityLifecycleTests { assertThat( prePersist ).isNotNull(); } } ); - assertThat( getMethodDetails( classDetails, "preRemove" ).get( 0 ).getAnnotationUsage( PreRemove.class ) ).isNotNull(); - assertThat( getMethodDetails( classDetails, "preUpdate" ).get( 0 ).getAnnotationUsage( PreUpdate.class ) ).isNotNull(); + assertThat( getMethodDetails( classDetails, "preRemove" ).get( 0 ).getDirectAnnotationUsage( PreRemove.class ) ).isNotNull(); + assertThat( getMethodDetails( classDetails, "preUpdate" ).get( 0 ).getDirectAnnotationUsage( PreUpdate.class ) ).isNotNull(); // entity listeners - final AnnotationUsage entityListenersAnn = classDetails.getAnnotationUsage( EntityListeners.class ); + final EntityListeners entityListenersAnn = classDetails.getDirectAnnotationUsage( EntityListeners.class ); assertThat( entityListenersAnn ).isNotNull(); - final List entityListeners = entityListenersAnn.getAttributeValue( "value" ); + final Class[] entityListeners = entityListenersAnn.value(); assertThat( entityListeners ).hasSize( 1 ); - final ClassDetails listener = entityListeners.get( 0 ); + final Class listener = entityListeners[0]; assertThat( listener.getName() ).isEqualTo( SimpleEntityListener.class.getName() ); - getMethodDetails( classDetails, "postPersist" ).forEach( method -> { - final AnnotationUsage prePersist = method.getAnnotationUsage( PostPersist.class ); + final ClassDetails listenerClassDetails = classDetailsRegistry.getClassDetails( listener.getName() ); + getMethodDetails( listenerClassDetails, "postPersist" ).forEach( method -> { + final PostPersist prePersist = method.getDirectAnnotationUsage( PostPersist.class ); if ( method.getArgumentTypes().size() != 1 ) { assertThat( prePersist ).isNull(); } @@ -92,9 +89,9 @@ public class EntityLifecycleTests { assertThat( prePersist ).isNotNull(); } } ); - assertThat( getMethodDetails( listener, "postRemove" ).get( 0 ).getAnnotationUsage( PostRemove.class ) ).isNotNull(); - assertThat( getMethodDetails( listener, "postUpdate" ).get( 0 ).getAnnotationUsage( PostUpdate.class ) ).isNotNull(); - assertThat( getMethodDetails( listener, "postLoad" ).get( 0 ).getAnnotationUsage( PostLoad.class ) ).isNotNull(); + assertThat( getMethodDetails( listenerClassDetails, "postRemove" ).get( 0 ).getDirectAnnotationUsage( PostRemove.class ) ).isNotNull(); + assertThat( getMethodDetails( listenerClassDetails, "postUpdate" ).get( 0 ).getDirectAnnotationUsage( PostUpdate.class ) ).isNotNull(); + assertThat( getMethodDetails( listenerClassDetails, "postLoad" ).get( 0 ).getDirectAnnotationUsage( PostLoad.class ) ).isNotNull(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/AttributeOverrideXmlTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/AttributeOverrideXmlTests.java index 390782eb63..e74c2f9533 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/AttributeOverrideXmlTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/AttributeOverrideXmlTests.java @@ -6,8 +6,6 @@ */ package org.hibernate.orm.test.boot.models.xml.override; -import java.util.List; - import org.hibernate.boot.MetadataSources; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.InFlightMetadataCollectorImpl; @@ -17,7 +15,6 @@ import org.hibernate.boot.model.process.spi.ManagedResources; import org.hibernate.boot.model.process.spi.MetadataBuildingProcess; import org.hibernate.boot.model.source.internal.annotations.DomainModelSource; import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.FieldDetails; @@ -74,33 +71,27 @@ public class AttributeOverrideXmlTests { assertThat( embeddable.getFields() ).hasSize( 4 ); final FieldDetails cityField = embeddable.findFieldByName( "city" ); - assertThat( cityField.hasAnnotationUsage( Column.class ) ).isFalse(); + assertThat( cityField.hasDirectAnnotationUsage( Column.class ) ).isFalse(); } private static void checkOverrides(FieldDetails embedded, String prefix) { - final AnnotationUsage overridesUsage = embedded.getAnnotationUsage( AttributeOverrides.class ); + final AttributeOverrides overridesUsage = embedded.getDirectAnnotationUsage( AttributeOverrides.class ); assertThat( overridesUsage ).isNotNull(); - final List> overrideList = overridesUsage.getList( "value" ); + final AttributeOverride[] overrideList = overridesUsage.value(); assertThat( overrideList ).hasSize( 4 ); - for ( AnnotationUsage overrideUsage : overrideList ) { - final String attributeName = overrideUsage.getString( "name" ); + for ( AttributeOverride overrideUsage : overrideList ) { + final String attributeName = overrideUsage.name(); - final AnnotationUsage columnUsage = overrideUsage.getNestedUsage( "column" ); - final String columnName = columnUsage.getString( "name" ); + final Column columnUsage = overrideUsage.column(); + final String columnName = columnUsage.name(); - if ( attributeName.equals( "street" ) ) { - assertThat( columnName ).isEqualTo( prefix + "street" ); - } - else if ( attributeName.equals( "city" ) ) { - assertThat( columnName ).isEqualTo( prefix + "city" ); - } - else if ( attributeName.equals( "state" ) ) { - assertThat( columnName ).isEqualTo( prefix + "state" ); - } - else if ( attributeName.equals( "zip" ) ) { - assertThat( columnName ).isEqualTo( prefix + "zip" ); + switch ( attributeName ) { + case "street" -> assertThat( columnName ).isEqualTo( prefix + "street" ); + case "city" -> assertThat( columnName ).isEqualTo( prefix + "city" ); + case "state" -> assertThat( columnName ).isEqualTo( prefix + "state" ); + case "zip" -> assertThat( columnName ).isEqualTo( prefix + "zip" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/SimpleOverrideXmlTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/SimpleOverrideXmlTests.java index 8c040103bf..6500b3dede 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/SimpleOverrideXmlTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/override/SimpleOverrideXmlTests.java @@ -6,19 +6,21 @@ */ package org.hibernate.orm.test.boot.models.xml.override; +import org.hibernate.boot.MetadataSources; import org.hibernate.boot.internal.BootstrapContextImpl; +import org.hibernate.boot.internal.InFlightMetadataCollectorImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.CategorizedDomainModel; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.EntityTypeMetadata; -import org.hibernate.boot.model.source.internal.annotations.AdditionalManagedResourcesImpl; -import org.hibernate.orm.test.boot.models.xml.SimpleEntity; +import org.hibernate.boot.model.process.spi.MetadataBuildingProcess; +import org.hibernate.boot.model.source.internal.annotations.DomainModelSource; import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.models.spi.AnnotationUsage; +import org.hibernate.models.spi.ClassDetails; +import org.hibernate.models.spi.ClassDetailsRegistry; +import org.hibernate.models.spi.FieldDetails; +import org.hibernate.orm.test.boot.models.xml.SimpleEntity; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; import org.junit.jupiter.api.Test; import jakarta.persistence.Basic; @@ -26,47 +28,42 @@ import jakarta.persistence.Column; import jakarta.persistence.Id; import static org.assertj.core.api.Assertions.assertThat; -import static org.hibernate.boot.models.categorize.spi.ManagedResourcesProcessor.processManagedResources; /** * @author Steve Ebersole */ public class SimpleOverrideXmlTests { @Test - void testSimpleCompleteEntity() { + @ServiceRegistry + void testSimpleCompleteEntity(ServiceRegistryScope scope) { + final StandardServiceRegistry serviceRegistry = scope.getRegistry(); - final AdditionalManagedResourcesImpl.Builder managedResourcesBuilder = new AdditionalManagedResourcesImpl.Builder(); - managedResourcesBuilder.addXmlMappings( "mappings/models/override/simple-override.xml" ); - final ManagedResources managedResources = managedResourcesBuilder.build(); + final MetadataSources metadataSources = new MetadataSources().addResource( "mappings/models/override/simple-override.xml" ); + final MetadataBuilderImpl.MetadataBuildingOptionsImpl options = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ); + final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl( serviceRegistry, options ); + options.setBootstrapContext( bootstrapContext ); - try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) { - final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl( - serviceRegistry, - new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) - ); - final CategorizedDomainModel categorizedDomainModel = processManagedResources( - managedResources, - bootstrapContext - ); + final ManagedResources managedResources = MetadataBuildingProcess.prepare( metadataSources, bootstrapContext ); + final InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl( bootstrapContext, options ); + final DomainModelSource domainModelSource = MetadataBuildingProcess.processManagedResources( + managedResources, + metadataCollector, + bootstrapContext, + new MetadataBuilderImpl.MappingDefaultsImpl( serviceRegistry ) + ); - assertThat( categorizedDomainModel.getEntityHierarchies() ).hasSize( 1 ); + final ClassDetailsRegistry classDetailsRegistry = domainModelSource.getClassDetailsRegistry(); - final EntityHierarchy hierarchy = categorizedDomainModel.getEntityHierarchies().iterator().next(); - final EntityTypeMetadata root = hierarchy.getRoot(); - assertThat( root.getClassDetails().getClassName() ).isEqualTo( SimpleEntity.class.getName() ); - assertThat( root.getNumberOfAttributes() ).isEqualTo( 2 ); + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( SimpleEntity.class.getName() ); - final AttributeMetadata idAttribute = root.findAttribute( "id" ); - assertThat( idAttribute.getNature() ).isEqualTo( AttributeMetadata.AttributeNature.BASIC ); - assertThat( idAttribute.getMember().getAnnotationUsage( Id.class ) ).isNotNull(); + final FieldDetails idField = classDetails.findFieldByName( "id" ); + assertThat( idField.getDirectAnnotationUsage( Id.class ) ).isNotNull(); - final AttributeMetadata nameAttribute = root.findAttribute( "name" ); - assertThat( nameAttribute.getNature() ).isEqualTo( AttributeMetadata.AttributeNature.BASIC ); - assertThat( nameAttribute.getMember().getAnnotationUsage( Basic.class ) ).isNotNull(); - final AnnotationUsage nameColumnAnn = nameAttribute.getMember().getAnnotationUsage( Column.class ); - assertThat( nameColumnAnn ).isNotNull(); - assertThat( nameColumnAnn.getAttributeValue( "name" ) ).isEqualTo( "description" ); - assertThat( nameColumnAnn.getAttributeValue( "columnDefinition" ) ).isEqualTo( "nvarchar(512)" ); - } + final FieldDetails nameField = classDetails.findFieldByName( "name" ); + assertThat( nameField.getDirectAnnotationUsage( Basic.class ) ).isNotNull(); + final Column nameColumnAnn = nameField.getDirectAnnotationUsage( Column.class ); + assertThat( nameColumnAnn ).isNotNull(); + assertThat( nameColumnAnn.name() ).isEqualTo( "description" ); + assertThat( nameColumnAnn.columnDefinition() ).isEqualTo( "nvarchar(512)" ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/intg/AdditionalMappingContributorTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/intg/AdditionalMappingContributorTests.java index b6154bd14e..d2f1543bcb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/intg/AdditionalMappingContributorTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/intg/AdditionalMappingContributorTests.java @@ -13,6 +13,7 @@ import java.util.List; import org.hibernate.boot.ResourceStreamLocator; import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.annotations.internal.EntityJpaAnnotation; import org.hibernate.boot.spi.AdditionalMappingContributions; import org.hibernate.boot.spi.AdditionalMappingContributor; import org.hibernate.boot.spi.InFlightMetadataCollector; @@ -23,7 +24,6 @@ import org.hibernate.models.internal.dynamic.DynamicFieldDetails; import org.hibernate.models.internal.jdk.JdkClassDetails; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; -import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableMemberDetails; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; @@ -330,11 +330,11 @@ public class AdditionalMappingContributorTests { modelBuildingContext ); - final MutableAnnotationUsage entityUsage = jdkClassDetails.applyAnnotationUsage( + final EntityJpaAnnotation entityUsage = (EntityJpaAnnotation) jdkClassDetails.applyAnnotationUsage( JpaAnnotations.ENTITY, modelBuildingContext ); - entityUsage.setAttributeValue( "name", "___Entity5___" ); + entityUsage.name( "___Entity5___" ); final MutableMemberDetails idField = (MutableMemberDetails) jdkClassDetails.findFieldByName( "id" ); idField.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext ); @@ -370,11 +370,11 @@ public class AdditionalMappingContributorTests { assertThat( modelBuildingContext ).isSameAs( buildingContext.getMetadataCollector().getSourceModelBuildingContext() ); final DynamicClassDetails classDetails = new DynamicClassDetails( "Entity6", modelBuildingContext ); - final MutableAnnotationUsage entityUsage = classDetails.applyAnnotationUsage( + final EntityJpaAnnotation entityUsage = (EntityJpaAnnotation) classDetails.applyAnnotationUsage( JpaAnnotations.ENTITY, modelBuildingContext ); - entityUsage.setAttributeValue( "name", "Entity6" ); + entityUsage.name( "Entity6" ); final DynamicFieldDetails idMember = classDetails.applyAttribute( "id", diff --git a/hibernate-core/src/test/resources/mappings/models/attr/any/simple.xml b/hibernate-core/src/test/resources/mappings/models/attr/any/simple.xml index db7f7d9e22..5700e74a91 100644 --- a/hibernate-core/src/test/resources/mappings/models/attr/any/simple.xml +++ b/hibernate-core/src/test/resources/mappings/models/attr/any/simple.xml @@ -6,7 +6,7 @@ --> + version="7.0"> org.hibernate.orm.test.boot.models.xml.attr diff --git a/hibernate-core/src/test/resources/mappings/models/complete/simple-complete.xml b/hibernate-core/src/test/resources/mappings/models/complete/simple-complete.xml index b754202340..f9aa0634e3 100644 --- a/hibernate-core/src/test/resources/mappings/models/complete/simple-complete.xml +++ b/hibernate-core/src/test/resources/mappings/models/complete/simple-complete.xml @@ -7,10 +7,10 @@ --> + version="7.0"> name is not null - insert into SimpleEntity(name) values(?) + insertSimpleEntity(?) {t}.name = :name diff --git a/hibernate-core/src/test/resources/mappings/models/namespace/defaults-namespace.xml b/hibernate-core/src/test/resources/mappings/models/namespace/defaults-namespace.xml new file mode 100644 index 0000000000..d8ed85041e --- /dev/null +++ b/hibernate-core/src/test/resources/mappings/models/namespace/defaults-namespace.xml @@ -0,0 +1,28 @@ + + + + + + + defaults_schema + + + + org.hibernate.orm.test.boot.database.qualfiedTableNaming + FIELD + + +

+ + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/resources/mappings/models/namespace/file-namespace.xml b/hibernate-core/src/test/resources/mappings/models/namespace/file-namespace.xml new file mode 100644 index 0000000000..5b3dc0e513 --- /dev/null +++ b/hibernate-core/src/test/resources/mappings/models/namespace/file-namespace.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + org.hibernate.orm.test.boot.database.qualfiedTableNaming + + file_schema + + FIELD + + +
+ + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/resources/mappings/models/namespace/no-namespace.xml b/hibernate-core/src/test/resources/mappings/models/namespace/no-namespace.xml new file mode 100644 index 0000000000..0343ed1de8 --- /dev/null +++ b/hibernate-core/src/test/resources/mappings/models/namespace/no-namespace.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + org.hibernate.orm.test.boot.database.qualfiedTableNaming + + + + FIELD + + +
+ + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/resources/org/hibernate/orm/test/schemaupdate/checkconstraint/column/mapping.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/schemaupdate/checkconstraint/column/mapping.xml index 95d96e111c..eb4a45e794 100644 --- a/hibernate-core/src/test/resources/org/hibernate/orm/test/schemaupdate/checkconstraint/column/mapping.xml +++ b/hibernate-core/src/test/resources/org/hibernate/orm/test/schemaupdate/checkconstraint/column/mapping.xml @@ -16,9 +16,6 @@ - - - diff --git a/hibernate-envers/hibernate-envers.gradle b/hibernate-envers/hibernate-envers.gradle index e7ecc9e508..787f17504e 100644 --- a/hibernate-envers/hibernate-envers.gradle +++ b/hibernate-envers/hibernate-envers.gradle @@ -13,6 +13,7 @@ apply plugin: 'org.hibernate.matrix-test' dependencies { api project( ':hibernate-core' ) + implementation libs.hibernateModels implementation jakartaLibs.jaxbApi implementation jakartaLibs.jaxb implementation libs.jandex diff --git a/settings.gradle b/settings.gradle index 961c1d635c..ab05c70014 100644 --- a/settings.gradle +++ b/settings.gradle @@ -40,6 +40,8 @@ dependencyResolutionManagement { } } + mavenLocal() + //Allow loading additional dependencies from a local path; //useful to load JDBC drivers which can not be distributed in public. if (System.env['ADDITIONAL_REPO'] != null) { @@ -70,7 +72,7 @@ dependencyResolutionManagement { def byteBuddyVersion = version "byteBuddy", "1.14.18" def classmateVersion = version "classmate", "1.5.1" def geolatteVersion = version "geolatte", "1.9.1" - def hibernateModelsVersion = version "hibernateModels", "0.8.3" + def hibernateModelsVersion = version "hibernateModels", "0.8.4" def jandexVersion = version "jandex", "3.2.0" def hcannVersion = version "hcann", "7.0.1.Final" def jacksonVersion = version "jackson", "2.17.0" @@ -330,6 +332,8 @@ include 'hibernate-integrationtest-java-modules' include 'documentation' include 'release' +include 'annotation-descriptor-generator' + // Not all JDK implementations support JFR if ( "OpenJDK Runtime Environment".equals( System.getProperty( "java.runtime.name" ) ) ) { include 'hibernate-jfr'