From a1ba4dbdb7efff64c258609b74fa1d0624eb0345 Mon Sep 17 00:00:00 2001 From: brmeyer Date: Mon, 12 Nov 2012 18:01:36 -0500 Subject: [PATCH] HHH-7702 Add support for collections of (aggregated) composite elements --- ...ositePluralAttributeElementSourceImpl.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/CompositePluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/CompositePluralAttributeElementSourceImpl.java index f0904aac53..72c33726d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/CompositePluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/CompositePluralAttributeElementSourceImpl.java @@ -23,6 +23,7 @@ package org.hibernate.metamodel.internal.source.annotations; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.internal.util.ValueHolder; @@ -31,6 +32,7 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOv import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute; import org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableClass; import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass; +import org.hibernate.metamodel.spi.binding.CascadeType; import org.hibernate.metamodel.spi.source.AttributeSource; import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource; import org.hibernate.metamodel.spi.source.LocalBindingContext; @@ -45,7 +47,6 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura private final AssociationAttribute associationAttribute; private final RootEntityClass rootEntityClass; - private final Iterable cascadeStyles; private List attributeSources = new ArrayList(); @@ -56,7 +57,6 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura Iterable cascadeStyles ) { this.associationAttribute = associationAttribute; this.rootEntityClass = rootEntityClass; - this.cascadeStyles = cascadeStyles; buildAttributeSources(); } @@ -84,6 +84,12 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura @Override public Iterable getCascadeStyles() { + List cascadeStyles = new ArrayList(); + for ( javax.persistence.CascadeType cascadeType : associationAttribute + .getCascadeTypes() ) { + cascadeStyles.add( CascadeType.getCascadeType( cascadeType ) + .toCascadeStyle() ); + } return cascadeStyles; } @@ -105,13 +111,13 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura @Override public String getParentReferenceAttributeName() { - // TODO Auto-generated method stub - return null; + // TODO: Is this correct? + return associationAttribute.getName(); } @Override public String getExplicitTuplizerClassName() { - // TODO Auto-generated method stub + // TODO ? return null; } @@ -122,9 +128,9 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) { AttributeOverride attributeOverride = null; String tmp = getPath() + PATH_SEPARATOR + attribute.getName(); -// if ( attributeOverrides.containsKey( tmp ) ) { -// attributeOverride = attributeOverrides.get( tmp ); -// } + if ( rootEntityClass.getAttributeOverrideMap().containsKey( tmp ) ) { + attributeOverride = rootEntityClass.getAttributeOverrideMap().get( tmp ); + } attribute.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() ); attributeSources.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) ); } @@ -134,8 +140,7 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura new ComponentAttributeSourceImpl( embeddable, getPath(), -// createAggregatedOverrideMap() - new HashMap() + createAggregatedOverrideMap( embeddableClass, rootEntityClass.getAttributeOverrideMap() ) ) ); } @@ -145,4 +150,22 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura } } + private Map createAggregatedOverrideMap( + EmbeddableClass embeddableClass, + Map attributeOverrides) { + // add all overrides passed down to this instance - they override overrides ;-) which are defined further down + // the embeddable chain + Map aggregatedOverrideMap = new HashMap( + attributeOverrides + ); + + for ( Map.Entry entry : embeddableClass.getAttributeOverrideMap().entrySet() ) { + String fullPath = getPath() + PATH_SEPARATOR + entry.getKey(); + if ( !aggregatedOverrideMap.containsKey( fullPath ) ) { + aggregatedOverrideMap.put( fullPath, entry.getValue() ); + } + } + return aggregatedOverrideMap; + } + }