From 08ed4c1e80163581fa7c4d046ad502ffdd97402d Mon Sep 17 00:00:00 2001 From: Hardy Ferentschik Date: Wed, 22 Jun 2011 23:11:12 +0200 Subject: [PATCH] HHH-6173 Passing association and attribute overrides to EmbeddedClass --- .../annotations/entity/ConfiguredClass.java | 61 +++++++++++++++++++ .../annotations/entity/EmbeddedClass.java | 5 ++ .../state/binding/EntityBindingStateImpl.java | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java index de762a7149..89c4a45c00 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java @@ -81,6 +81,16 @@ public class ConfiguredClass { */ private final ConfiguredClassType configuredClassType; + /** + * The attribute overrides defined on this entity + */ + private final List attributeOverrides; + + /** + * The association overrides defined on this entity; + */ + private final List associationOverrides; + /** * The mapped attributes for entity */ @@ -106,6 +116,9 @@ public class ConfiguredClass { this.configuredClassType = determineType(); this.classAccessType = determineClassAccessType( defaultAccessType ); + this.attributeOverrides = findAttributeOverrides(); + this.associationOverrides = findAssociationOverrides(); + // find transient field and method names findTransientFieldAndMethodNames(); @@ -388,6 +401,8 @@ public class ConfiguredClass { embeddableClassInfo, classAccessType, context.resolveType( type.getName() ), + attributeOverrides, + associationOverrides, context ); @@ -480,4 +495,50 @@ public class ConfiguredClass { } } } + + private List findAttributeOverrides() { + List attributeOverrideList = new ArrayList(); + + AnnotationInstance attributeOverrideAnnotation = JandexHelper.getSingleAnnotation( + classInfo, + JPADotNames.ATTRIBUTE_OVERRIDE + ); + if ( attributeOverrideAnnotation != null ) { + attributeOverrideList.add( attributeOverrideAnnotation ); + } + + AnnotationInstance attributeOverridesAnnotation = JandexHelper.getSingleAnnotation( + classInfo, + JPADotNames.ATTRIBUTE_OVERRIDES + ); + if ( attributeOverrideAnnotation != null ) { + AnnotationInstance[] attributeOverride = attributeOverridesAnnotation.value().asNestedArray(); + Collections.addAll( attributeOverrideList, attributeOverride ); + } + + return attributeOverrideList; + } + + private List findAssociationOverrides() { + List associationOverrideList = new ArrayList(); + + AnnotationInstance associationOverrideAnnotation = JandexHelper.getSingleAnnotation( + classInfo, + JPADotNames.ASSOCIATION_OVERRIDE + ); + if ( associationOverrideAnnotation != null ) { + associationOverrideList.add( associationOverrideAnnotation ); + } + + AnnotationInstance associationOverridesAnnotation = JandexHelper.getSingleAnnotation( + classInfo, + JPADotNames.ASSOCIATION_OVERRIDES + ); + if ( associationOverrideAnnotation != null ) { + AnnotationInstance[] attributeOverride = associationOverridesAnnotation.value().asNestedArray(); + Collections.addAll( associationOverrideList, attributeOverride ); + } + + return associationOverrideList; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedClass.java index dac0236ecf..b4db759fe2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedClass.java @@ -23,18 +23,23 @@ */ package org.hibernate.metamodel.source.annotations.entity; +import java.util.List; import javax.persistence.AccessType; import com.fasterxml.classmate.ResolvedTypeWithMembers; +import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; /** * @author Hardy Ferentschik */ public class EmbeddedClass extends ConfiguredClass { + // todo - need to take care of the attribute path (HF) public EmbeddedClass(ClassInfo classInfo, AccessType defaultAccessType, ResolvedTypeWithMembers resolvedType, + List attributeOverrides, + List associationOverrides, AnnotationBindingContext context) { super( classInfo, defaultAccessType, resolvedType, context ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/state/binding/EntityBindingStateImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/state/binding/EntityBindingStateImpl.java index 63d39c2ba2..1d9d5285f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/state/binding/EntityBindingStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/state/binding/EntityBindingStateImpl.java @@ -280,7 +280,7 @@ public class EntityBindingStateImpl implements EntityBindingState { } @Override - public Class getCustomEntityPersisterClass() { + public Class getCustomEntityPersisterClass() { return persisterClass; }