diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java index 02f73baeb6..c7d3ef5838 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/metamodel/internal/builder/AttributeBuilder.java @@ -45,7 +45,7 @@ import org.hibernate.jpa.metamodel.internal.MappedSuperclassTypeImpl; import org.hibernate.jpa.metamodel.internal.PluralAttributeImpl; import org.hibernate.jpa.metamodel.internal.SingularAttributeImpl; import org.hibernate.jpa.metamodel.internal.UnsupportedFeature; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.AggregatedCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; @@ -55,6 +55,7 @@ import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.type.ComponentType; +import org.hibernate.type.EmbeddedComponentType; import org.hibernate.type.EntityType; import static javax.persistence.metamodel.Attribute.PersistentAttributeType; @@ -238,8 +239,10 @@ public class AttributeBuilder { (ComponentType) attributeTypeDescriptor.getHibernateType() ); context.registerEmbeddedableType( embeddableType ); - AbstractCompositeAttributeBinding compositeAttributeBinding = - (AbstractCompositeAttributeBinding) attributeTypeDescriptor.getAttributeMetadata().getAttributeBinding(); + AggregatedCompositeAttributeBinding compositeAttributeBinding = + (AggregatedCompositeAttributeBinding) attributeTypeDescriptor + .getAttributeMetadata() + .getAttributeBinding(); for ( AttributeBinding subAttributeBinding : compositeAttributeBinding.attributeBindings() ) { final Attribute attribute = buildAttribute( embeddableType, subAttributeBinding ); if ( attribute != null ) { @@ -302,7 +305,7 @@ public class AttributeBuilder { final SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding; final PersistentAttributeType jpaAttributeType; - if ( singularAttributeBinding.getAttribute().getSingularAttributeType().isComposite() ) { + if ( singularAttributeBinding.getAttribute().getSingularAttributeType().isAggregate() ) { jpaAttributeType = PersistentAttributeType.EMBEDDED; } else if ( singularAttributeBinding.getAttribute().getSingularAttributeType().isAssociation() ) { @@ -337,7 +340,7 @@ public class AttributeBuilder { elementPersistentAttributeType = PersistentAttributeType.BASIC; persistentAttributeType = PersistentAttributeType.ELEMENT_COLLECTION; } - else if ( elementNature == PluralAttributeElementBinding.Nature.COMPOSITE ) { + else if ( elementNature == PluralAttributeElementBinding.Nature.AGGREGATION ) { elementPersistentAttributeType = PersistentAttributeType.EMBEDDED; persistentAttributeType = PersistentAttributeType.ELEMENT_COLLECTION; } @@ -362,7 +365,7 @@ public class AttributeBuilder { else if ( indexNature == PluralAttributeIndexBinding.Nature.MANY_TO_MANY ) { keyPersistentAttributeType = Attribute.PersistentAttributeType.MANY_TO_ONE; } - else if ( indexNature == PluralAttributeIndexBinding.Nature.COMPOSITE ) { + else if ( indexNature == PluralAttributeIndexBinding.Nature.AGGREGATION ) { keyPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED; } else { @@ -446,11 +449,18 @@ public class AttributeBuilder { final IdentifiableType identifiableType = (IdentifiableType) owner; final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel( identifiableType ); if ( ! entityMetamodel.getIdentifierProperty().isVirtual() ) { - throw new IllegalArgumentException( "expecting non-aggregated identifier mapping" ); + throw new IllegalArgumentException( "expecting a virtual (non-aggregated composite) identifier mapping" ); } org.hibernate.type.Type type = entityMetamodel.getIdentifierProperty().getType(); - if ( ! ComponentType.class.isInstance( type ) ) { - throw new IllegalArgumentException( "expecting non-aggregated identifier mapping" ); + if ( entityMetamodel.getIdentifierProperty().hasIdentifierMapper() ) { + if ( ! ComponentType.class.isInstance( type ) ) { + throw new IllegalArgumentException( "expecting an idclass identifier mapping" ); + } + } + else { + if ( ! EmbeddedComponentType.class.isInstance( type ) ) { + throw new IllegalArgumentException( "expecting a non-aggregated composite identifier mapping" ); + } } final ComponentType componentType = (ComponentType) type; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index dc4d096161..850a8b37db 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -36,7 +36,6 @@ import org.jboss.logging.Logger; import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; -import org.hibernate.FetchMode; import org.hibernate.MultiTenancyStrategy; import org.hibernate.TruthValue; import org.hibernate.cfg.AvailableSettings; @@ -56,7 +55,7 @@ import org.hibernate.internal.util.ValueHolder; import org.hibernate.metamodel.internal.HibernateTypeHelper.ReflectedCollectionJavaTypes; import org.hibernate.metamodel.spi.MetadataImplementor; import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.AggregatedCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBindingContainer; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; @@ -83,8 +82,8 @@ import org.hibernate.metamodel.spi.binding.RelationalValueBinding; import org.hibernate.metamodel.spi.binding.SecondaryTable; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.binding.TypeDefinition; +import org.hibernate.metamodel.spi.domain.Aggregate; import org.hibernate.metamodel.spi.domain.Attribute; -import org.hibernate.metamodel.spi.domain.Composite; import org.hibernate.metamodel.spi.domain.Entity; import org.hibernate.metamodel.spi.domain.PluralAttribute; import org.hibernate.metamodel.spi.domain.SingularAttribute; @@ -278,8 +277,8 @@ public class Binder { EntityBinding rootEntityBinding, AggregatedCompositeIdentifierSource identifierSource ) { // locate the attribute binding - final CompositeAttributeBinding idAttributeBinding = - (CompositeAttributeBinding) bindIdentifierAttribute( + final AggregatedCompositeAttributeBinding idAttributeBinding = + (AggregatedCompositeAttributeBinding) bindIdentifierAttribute( rootEntityBinding, identifierSource.getIdentifierAttributeSource() ); @@ -574,16 +573,16 @@ public class Binder { } } - private CompositeAttributeBinding bindAggregatedCompositeAttribute( + private AggregatedCompositeAttributeBinding bindAggregatedCompositeAttribute( final MutableAttributeBindingContainer attributeBindingContainer, final ComponentAttributeSource attributeSource, SingularAttribute attribute, boolean isAttributeIdentifier) { - final Composite composite; + final Aggregate composite; ValueHolder> defaultJavaClassReference = null; if ( attribute == null ) { if ( attributeSource.getClassName() != null ) { - composite = new Composite( + composite = new Aggregate( attributeSource.getPath(), attributeSource.getClassName(), attributeSource.getClassReference() != null ? @@ -597,7 +596,7 @@ public class Binder { defaultJavaClassReference = createSingularAttributeJavaType( attributeBindingContainer.getClassReference(), attributeSource.getName() ); - composite = new Composite( + composite = new Aggregate( attributeSource.getPath(), defaultJavaClassReference.getValue().getName(), defaultJavaClassReference, @@ -610,7 +609,7 @@ public class Binder { ); } else { - composite = (Composite) attribute.getSingularAttributeType(); + composite = (Aggregate) attribute.getSingularAttributeType(); } final SingularAttribute referencingAttribute = @@ -618,7 +617,7 @@ public class Binder { null : composite.createSingularAttribute( attributeSource.getParentReferenceAttributeName() ); final SingularAttributeBinding.NaturalIdMutability naturalIdMutability = attributeSource.getNaturalIdMutability(); - final CompositeAttributeBinding attributeBinding = + final AggregatedCompositeAttributeBinding attributeBinding = attributeBindingContainer.makeAggregatedCompositeAttributeBinding( attribute, referencingAttribute, @@ -1232,10 +1231,8 @@ public class Binder { final EntityBinding referencedEntityBinding, final String defaultElementJavaTypeName) { - //referencedEntityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding().addEntityReferencingAttributeBinding( ); - - elementBinding.setRelationalValueBindings( - referencedEntityBinding.getHierarchyDetails().getEntityIdentifier().getAttributeBinding().getRelationalValueBindings() + elementBinding.setElementEntityIdentifier( + referencedEntityBinding.getHierarchyDetails().getEntityIdentifier() ); final HibernateTypeDescriptor hibernateTypeDescriptor = elementBinding.getHibernateTypeDescriptor(); bindHibernateTypeDescriptor( @@ -1502,6 +1499,8 @@ public class Binder { attribute ); case COMPOSITE: + // TODO: should this deal with both aggregated and non-aggegated + // attribute bindings? return bindAggregatedCompositeAttribute( attributeBindingContainer, ComponentAttributeSource.class.cast( attributeSource ), @@ -2307,7 +2306,7 @@ public class Binder { pluralAttributeBinding.getAttribute().getName(), getReferencedPropertyNameIfNotId( pluralAttributeBinding ), pluralAttributeBinding.getPluralAttributeElementBinding() - .getNature() == PluralAttributeElementBinding.Nature.COMPOSITE + .getNature() == PluralAttributeElementBinding.Nature.AGGREGATION ); } @@ -2318,7 +2317,7 @@ public class Binder { final TypeFactory typeFactory = metadata.getTypeResolver().getTypeFactory(); final String role = pluralAttributeBinding.getAttribute().getRole(); final String propertyRef = getReferencedPropertyNameIfNotId( pluralAttributeBinding ); - final boolean embedded = pluralAttributeBinding.getPluralAttributeElementBinding().getNature() == PluralAttributeElementBinding.Nature.COMPOSITE; + final boolean embedded = pluralAttributeBinding.getPluralAttributeElementBinding().getNature() == PluralAttributeElementBinding.Nature.AGGREGATION; switch ( nature ){ case BAG: return typeFactory.bag( role, propertyRef, embedded ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java index 1260419f61..b8405cf4d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/HibernateTypeHelper.java @@ -38,7 +38,7 @@ import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.beans.BeanInfoHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.spi.MetadataImplementor; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor; @@ -278,10 +278,10 @@ public class HibernateTypeHelper { resolvedHibernateType ); } - else if ( AbstractCompositeAttributeBinding.class.isInstance( attributeBinding ) ) { + else if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) { pushHibernateTypeInformationDown( (ComponentAttributeSource) attributeSource, - (AbstractCompositeAttributeBinding) attributeBinding, + (CompositeAttributeBinding) attributeBinding, resolvedHibernateType ); } @@ -305,7 +305,7 @@ public class HibernateTypeHelper { @SuppressWarnings( {"UnusedParameters"}) private void pushHibernateTypeInformationDown( ComponentAttributeSource attributeSource, - AbstractCompositeAttributeBinding attributeBinding, + CompositeAttributeBinding attributeBinding, Type resolvedHibernateType) { final HibernateTypeDescriptor hibernateTypeDescriptor = attributeBinding.getHibernateTypeDescriptor(); final SingularAttribute singularAttribute = SingularAttribute.class.cast( attributeBinding.getAttribute() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java index 281d55c063..93d55c9386 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeIndexSourceImpl.java @@ -50,7 +50,7 @@ public class PluralAttributeIndexSourceImpl implements PluralAttributeIndexSourc case BASIC: return PluralAttributeIndexBinding.Nature.BASIC; case COMPONENT: - return PluralAttributeIndexBinding.Nature.COMPOSITE; + return PluralAttributeIndexBinding.Nature.AGGREGATION; case MANY_TO_ANY: return PluralAttributeIndexBinding.Nature.MANY_TO_ANY; case MANY_TO_MANY: diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java index 6042a32c7c..d8d8cef08b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ToOneAttributeSourceImpl.java @@ -30,7 +30,6 @@ import java.util.Set; import org.jboss.jandex.AnnotationInstance; -import org.hibernate.FetchMode; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.CascadeStyle; @@ -41,9 +40,8 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttri import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.binding.AggregatedCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource; import org.hibernate.metamodel.spi.source.RelationalValueSource; @@ -88,8 +86,8 @@ public class ToOneAttributeSourceImpl extends SingularAttributeSourceImpl implem @Override public List getDefaultNamingStrategies( final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding) { - if ( CompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { - CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast( + if ( AggregatedCompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { + AggregatedCompositeAttributeBinding compositeAttributeBinding = AggregatedCompositeAttributeBinding.class.cast( referencedAttributeBinding ); List result = new ArrayList( ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java index 120ea53fd7..9c231b0156 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/global/SqlResultSetProcessor.java @@ -46,7 +46,7 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding; @@ -209,8 +209,8 @@ public class SqlResultSetProcessor { String reducedName = name.substring( 0, dotIndex ); AttributeBinding attributeBinding = entityBinding.locateAttributeBinding( reducedName ); Iterable attributeBindings = null; - if ( AbstractCompositeAttributeBinding.class.isInstance( attributeBinding ) ) { - AbstractCompositeAttributeBinding compositeAttributeBinding = AbstractCompositeAttributeBinding.class.cast( + if ( CompositeAttributeBinding.class.isInstance( attributeBinding ) ) { + CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast( attributeBinding ); attributeBindings = compositeAttributeBinding.attributeBindings(); @@ -241,8 +241,8 @@ public class SqlResultSetProcessor { SingularNonAssociationAttributeBinding identifierAttributeBinding = referencedEntityBinding.getHierarchyDetails() .getEntityIdentifier() .getAttributeBinding(); - if ( AbstractCompositeAttributeBinding.class.isInstance( identifierAttributeBinding ) ) { - attributeBindings = AbstractCompositeAttributeBinding.class.cast( identifierAttributeBinding ) + if ( CompositeAttributeBinding.class.isInstance( identifierAttributeBinding ) ) { + attributeBindings = CompositeAttributeBinding.class.cast( identifierAttributeBinding ) .attributeBindings(); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java index a041481a04..496f91f657 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java @@ -85,7 +85,7 @@ import org.hibernate.jaxb.spi.hbm.JaxbUnionSubclassElement; import org.hibernate.jaxb.spi.hbm.QuerySourceElement; import org.hibernate.jaxb.spi.hbm.ReturnElement; import org.hibernate.metamodel.spi.MetadataImplementor; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.FetchProfile; @@ -549,8 +549,8 @@ public class HibernateMappingProcessor { String reducedName = name.substring( 0, dotIndex ); AttributeBinding value = getRecursiveAttributeBinding( entityBinding, reducedName ); Iterable parentPropIter; - if ( AbstractCompositeAttributeBinding.class.isInstance( value ) ) { - AbstractCompositeAttributeBinding comp = (AbstractCompositeAttributeBinding) value; + if ( CompositeAttributeBinding.class.isInstance( value ) ) { + CompositeAttributeBinding comp = (CompositeAttributeBinding) value; parentPropIter = comp.attributeBindings(); } else if ( SingularAssociationAttributeBinding.class.isInstance( value ) ) { @@ -558,7 +558,7 @@ public class HibernateMappingProcessor { EntityBinding referencedEntityBinding = toOne.getReferencedEntityBinding(); SingularAttributeBinding referencedAttributeBinding = toOne.getReferencedAttributeBinding(); try { - parentPropIter = AbstractCompositeAttributeBinding.class.cast( referencedAttributeBinding ) + parentPropIter = CompositeAttributeBinding.class.cast( referencedAttributeBinding ) .attributeBindings(); } catch ( ClassCastException e ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java index 352d8bac02..b9874278b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ManyToOneAttributeSourceImpl.java @@ -26,7 +26,6 @@ package org.hibernate.metamodel.internal.source.hbm; import java.util.ArrayList; import java.util.List; -import org.hibernate.FetchMode; import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.CascadeStyle; @@ -34,8 +33,8 @@ import org.hibernate.jaxb.spi.hbm.JaxbColumnElement; import org.hibernate.jaxb.spi.hbm.JaxbManyToOneElement; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.internal.Binder; +import org.hibernate.metamodel.spi.binding.AggregatedCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; @@ -268,8 +267,8 @@ class ManyToOneAttributeSourceImpl extends AbstractHbmSourceNode implements ToOn @Override public List getDefaultNamingStrategies(final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding) { - if ( CompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { - CompositeAttributeBinding compositeAttributeBinding = CompositeAttributeBinding.class.cast( + if ( AggregatedCompositeAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { + AggregatedCompositeAttributeBinding compositeAttributeBinding = AggregatedCompositeAttributeBinding.class.cast( referencedAttributeBinding ); List result = new ArrayList(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractCompositeAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractCompositeAttributeBinding.java index 7247e7a0bf..6342d71ab7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractCompositeAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractCompositeAttributeBinding.java @@ -36,7 +36,7 @@ import org.hibernate.metamodel.spi.source.MetaAttributeContext; */ public abstract class AbstractCompositeAttributeBinding extends AbstractSingularAttributeBinding - implements SingularNonAssociationAttributeBinding, AttributeBindingContainer { + implements CompositeAttributeBinding { private final String path; protected AbstractCompositeAttributeBinding( @@ -92,8 +92,6 @@ public abstract class AbstractCompositeAttributeBinding return (AttributeContainer) getAttribute().getSingularAttributeType(); } - public abstract boolean isAggregated(); - @Override public boolean isAssociation() { return false; @@ -174,6 +172,7 @@ public abstract class AbstractCompositeAttributeBinding return null; } + @Override public int attributeBindingSpan() { return attributeBindingMapInternal().size(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java index 4ff97a7713..03c898738e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeBinding.java @@ -98,7 +98,7 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi case BASIC: { return new BasicPluralAttributeElementBinding( this ); } - case COMPOSITE: { + case AGGREGATION: { return new CompositePluralAttributeElementBinding( this ); } case ONE_TO_MANY: { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java index c53ff24b06..5b8dbdf63f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AbstractPluralAttributeElementBinding.java @@ -34,7 +34,6 @@ import java.util.List; public abstract class AbstractPluralAttributeElementBinding implements PluralAttributeElementBinding { private final AbstractPluralAttributeBinding pluralAttributeBinding; private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor(); - private List relationalValueBindings; AbstractPluralAttributeElementBinding(AbstractPluralAttributeBinding pluralAttributeBinding) { this.pluralAttributeBinding = pluralAttributeBinding; @@ -49,13 +48,4 @@ public abstract class AbstractPluralAttributeElementBinding implements PluralAtt public HibernateTypeDescriptor getHibernateTypeDescriptor() { return hibernateTypeDescriptor; } - - @Override - public List getRelationalValueBindings() { - return relationalValueBindings; - } - - public void setRelationalValueBindings(List relationalValueBindings) { - this.relationalValueBindings = Collections.unmodifiableList( relationalValueBindings ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AggregatedCompositeAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AggregatedCompositeAttributeBinding.java new file mode 100644 index 0000000000..2bd2f8fb84 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AggregatedCompositeAttributeBinding.java @@ -0,0 +1,262 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.spi.binding; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.hibernate.mapping.PropertyGeneration; +import org.hibernate.metamodel.spi.domain.Aggregate; +import org.hibernate.metamodel.spi.domain.PluralAttribute; +import org.hibernate.metamodel.spi.domain.SingularAttribute; +import org.hibernate.metamodel.spi.source.MetaAttributeContext; + +/** + * A composite attribute binding for an attribute that can be mapped + * to a single entity attribute by means of an actual component class + * that aggregates the tuple values. + * + * @todo should this be named something like AggregationAttributebinding instead? + * + * @author Gail Badner + */ +public class AggregatedCompositeAttributeBinding + extends AbstractCompositeAttributeBinding + implements MutableAttributeBindingContainer { + private final Map attributeBindingMap = new LinkedHashMap(); + private final SingularAttribute parentReference; + + public AggregatedCompositeAttributeBinding( + AttributeBindingContainer container, + SingularAttribute attribute, + String propertyAccessorName, + boolean includedInOptimisticLocking, + boolean lazy, + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + SingularAttribute parentReference) { + super( + container, + attribute, + propertyAccessorName, + includedInOptimisticLocking, + lazy, + naturalIdMutability, + metaAttributeContext + ); + if ( ! attribute.getSingularAttributeType().isAggregate() ) { + throw new IllegalArgumentException( "Expected the attribute type to be a component" ); + } + this.parentReference = parentReference; + } + + @Override + public boolean isAggregated() { + return true; + } + + public Aggregate getComposite() { + return (Aggregate) getAttribute().getSingularAttributeType(); + } + + public SingularAttribute getParentReference() { + return parentReference; + } + + @Override + protected Map attributeBindingMapInternal() { + return attributeBindingMap; + } + + @Override + public BasicAttributeBinding makeBasicAttributeBinding( + SingularAttribute attribute, + List relationalValueBindings, + String propertyAccessorName, + boolean includedInOptimisticLocking, + boolean lazy, + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + PropertyGeneration generation) { + final BasicAttributeBinding binding = new BasicAttributeBinding( + this, + attribute, + relationalValueBindings, + propertyAccessorName, + includedInOptimisticLocking, + lazy, + naturalIdMutability, + metaAttributeContext, + generation + ); + registerAttributeBinding( binding ); + return binding; + } + + protected void registerAttributeBinding(AttributeBinding attributeBinding) { + // todo : hook this into the EntityBinding notion of "entity referencing attribute bindings" + attributeBindingMap.put( attributeBinding.getAttribute().getName(), attributeBinding ); + } + + @Override + public AggregatedCompositeAttributeBinding makeAggregatedCompositeAttributeBinding( + SingularAttribute attribute, + SingularAttribute parentReferenceAttribute, + String propertyAccessorName, + boolean includedInOptimisticLocking, + boolean lazy, + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext) { + final AggregatedCompositeAttributeBinding binding = new AggregatedCompositeAttributeBinding( + this, + attribute, + propertyAccessorName, + includedInOptimisticLocking, + lazy, + naturalIdMutability, + metaAttributeContext, + parentReferenceAttribute + ); + registerAttributeBinding( binding ); + return binding; + } + + @Override + public ManyToOneAttributeBinding makeManyToOneAttributeBinding( + SingularAttribute attribute, + String propertyAccessorName, + boolean includedInOptimisticLocking, + boolean lazy, + NaturalIdMutability naturalIdMutability, + MetaAttributeContext metaAttributeContext, + EntityBinding referencedEntityBinding, + SingularAttributeBinding referencedAttributeBinding, + List valueBindings) { + final ManyToOneAttributeBinding binding = new ManyToOneAttributeBinding( + this, + attribute, + propertyAccessorName, + includedInOptimisticLocking, + lazy, + naturalIdMutability, + metaAttributeContext, + referencedEntityBinding, + referencedAttributeBinding, + valueBindings + ); + registerAttributeBinding( binding ); + return binding; + } + + @Override + public BagBinding makeBagAttributeBinding( + PluralAttribute attribute, + PluralAttributeElementBinding.Nature nature, + SingularAttributeBinding referencedAttributeBinding, + String propertyAccessorName, + boolean includedInOptimisticLocking, + MetaAttributeContext metaAttributeContext) { + Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.BAG ); + final BagBinding binding = new BagBinding( + this, + attribute, + nature, + referencedAttributeBinding, + propertyAccessorName, + includedInOptimisticLocking, + metaAttributeContext + ); + registerAttributeBinding( binding ); + return binding; + } + + @Override + public ListBinding makeListAttributeBinding( + PluralAttribute attribute, + PluralAttributeElementBinding.Nature nature, + SingularAttributeBinding referencedAttributeBinding, + String propertyAccessorName, + boolean includedInOptimisticLocking, + MetaAttributeContext metaAttributeContext, + int base) { + Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.LIST ); + final ListBinding binding = new ListBinding( + this, + attribute, + nature, + referencedAttributeBinding, + propertyAccessorName, + includedInOptimisticLocking, + metaAttributeContext, + base ); + registerAttributeBinding( binding ); + return binding; + } + + @Override + public MapBinding makeMapAttributeBinding( + PluralAttribute attribute, + PluralAttributeElementBinding.Nature elementNature, + PluralAttributeIndexBinding.Nature indexNature, + SingularAttributeBinding referencedAttributeBinding, + String propertyAccessorName, + boolean includedInOptimisticLocking, + MetaAttributeContext metaAttributeContext) { + Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.MAP ); + final MapBinding binding = new MapBinding( + this, + attribute, + elementNature, + indexNature, + referencedAttributeBinding, + propertyAccessorName, + includedInOptimisticLocking, + metaAttributeContext ); + registerAttributeBinding( binding ); + return binding; + } + + @Override + public SetBinding makeSetAttributeBinding( + PluralAttribute attribute, + PluralAttributeElementBinding.Nature nature, + SingularAttributeBinding referencedAttributeBinding, + String propertyAccessorName, + boolean includedInOptimisticLocking, + MetaAttributeContext metaAttributeContext) { + Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.SET ); + final SetBinding binding = new SetBinding( + this, + attribute, + nature, + referencedAttributeBinding, + propertyAccessorName, + includedInOptimisticLocking, + metaAttributeContext + ); + registerAttributeBinding( binding ); + return binding; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java index 02cc6e1684..ca3631f126 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/AttributeBindingContainer.java @@ -30,7 +30,7 @@ import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.source.MetaAttributeContext; /** - * Common contract for {@link EntityBinding} and {@link AbstractCompositeAttributeBinding} in so far as they are both + * Common contract for {@link EntityBinding} and {@link CompositeAttributeBinding} in so far as they are both * containers for {@link AttributeBinding} descriptors * * @author Steve Ebersole @@ -57,6 +57,15 @@ public interface AttributeBindingContainer { */ public Iterable attributeBindings(); + /** + * Return the number of attribute bindings returned by + * {@link #attributeBindings()}. + * + * @return the number of attribute bindings returned by + * {@link #attributeBindings()}. + */ + public int attributeBindingSpan(); + /** * Locate a specific attribute binding, by its local name. * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeElementBinding.java index fc13c1b8e7..bd9789eebc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/BasicPluralAttributeElementBinding.java @@ -23,6 +23,7 @@ */ package org.hibernate.metamodel.spi.binding; +import java.util.Collections; import java.util.List; /** @@ -35,6 +36,7 @@ public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeE private boolean hasDerivedValue; private boolean isNullable = true; + private List relationalValueBindings; public BasicPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) { super( binding ); @@ -45,8 +47,13 @@ public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeE return Nature.BASIC; } + @Override + public List getRelationalValueBindings() { + return relationalValueBindings; + } + public void setRelationalValueBindings(List relationalValueBindings) { - super.setRelationalValueBindings( relationalValueBindings ); + this.relationalValueBindings = Collections.unmodifiableList( relationalValueBindings ); for ( RelationalValueBinding relationalValueBinding : getRelationalValueBindings() ) { this.hasDerivedValue = this.hasDerivedValue || relationalValueBinding.isDerived(); this.isNullable = this.isNullable && relationalValueBinding.isNullable(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java index b867223831..aec52643db 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositeAttributeBinding.java @@ -23,234 +23,29 @@ */ package org.hibernate.metamodel.spi.binding; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.spi.domain.Composite; -import org.hibernate.metamodel.spi.domain.PluralAttribute; -import org.hibernate.metamodel.spi.domain.SingularAttribute; -import org.hibernate.metamodel.spi.source.MetaAttributeContext; - /** + * A specialized binding contract for a singular attribute binding that + * contains other attribute bindings. + * * @author Gail Badner */ -public class CompositeAttributeBinding - extends AbstractCompositeAttributeBinding - implements MutableAttributeBindingContainer { - private final Map attributeBindingMap = new LinkedHashMap(); - private final SingularAttribute parentReference; +public interface CompositeAttributeBinding + extends SingularNonAssociationAttributeBinding, AttributeBindingContainer { - public CompositeAttributeBinding( - AttributeBindingContainer container, - SingularAttribute attribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - SingularAttribute parentReference) { - super( - container, - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext - ); - if ( ! attribute.getSingularAttributeType().isComposite() ) { - throw new IllegalArgumentException( "Expected the attribute type to be a component" ); - } - this.parentReference = parentReference; - } - - @Override - public boolean isAggregated() { - return true; - } - - public Composite getComposite() { - return (Composite) getAttribute().getSingularAttributeType(); - } - - public SingularAttribute getParentReference() { - return parentReference; - } - - @Override - protected Map attributeBindingMapInternal() { - return attributeBindingMap; - } - - @Override - public BasicAttributeBinding makeBasicAttributeBinding( - SingularAttribute attribute, - List relationalValueBindings, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - PropertyGeneration generation) { - final BasicAttributeBinding binding = new BasicAttributeBinding( - this, - attribute, - relationalValueBindings, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext, - generation - ); - registerAttributeBinding( binding ); - return binding; - } - - protected void registerAttributeBinding(AttributeBinding attributeBinding) { - // todo : hook this into the EntityBinding notion of "entity referencing attribute bindings" - attributeBindingMap.put( attributeBinding.getAttribute().getName(), attributeBinding ); - } - - @Override - public CompositeAttributeBinding makeAggregatedCompositeAttributeBinding( - SingularAttribute attribute, - SingularAttribute parentReferenceAttribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext) { - final CompositeAttributeBinding binding = new CompositeAttributeBinding( - this, - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext, - parentReferenceAttribute - ); - registerAttributeBinding( binding ); - return binding; - } - - @Override - public ManyToOneAttributeBinding makeManyToOneAttributeBinding( - SingularAttribute attribute, - String propertyAccessorName, - boolean includedInOptimisticLocking, - boolean lazy, - NaturalIdMutability naturalIdMutability, - MetaAttributeContext metaAttributeContext, - EntityBinding referencedEntityBinding, - SingularAttributeBinding referencedAttributeBinding, - List valueBindings) { - final ManyToOneAttributeBinding binding = new ManyToOneAttributeBinding( - this, - attribute, - propertyAccessorName, - includedInOptimisticLocking, - lazy, - naturalIdMutability, - metaAttributeContext, - referencedEntityBinding, - referencedAttributeBinding, - valueBindings - ); - registerAttributeBinding( binding ); - return binding; - } - - @Override - public BagBinding makeBagAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.BAG ); - final BagBinding binding = new BagBinding( - this, - attribute, - nature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext - ); - registerAttributeBinding( binding ); - return binding; - } - - @Override - public ListBinding makeListAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext, - int base) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.LIST ); - final ListBinding binding = new ListBinding( - this, - attribute, - nature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext, - base ); - registerAttributeBinding( binding ); - return binding; - } - - @Override - public MapBinding makeMapAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature elementNature, - PluralAttributeIndexBinding.Nature indexNature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.MAP ); - final MapBinding binding = new MapBinding( - this, - attribute, - elementNature, - indexNature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext ); - registerAttributeBinding( binding ); - return binding; - } - - @Override - public SetBinding makeSetAttributeBinding( - PluralAttribute attribute, - PluralAttributeElementBinding.Nature nature, - SingularAttributeBinding referencedAttributeBinding, - String propertyAccessorName, - boolean includedInOptimisticLocking, - MetaAttributeContext metaAttributeContext) { - Helper.checkPluralAttributeNature( attribute, PluralAttribute.Nature.SET ); - final SetBinding binding = new SetBinding( - this, - attribute, - nature, - referencedAttributeBinding, - propertyAccessorName, - includedInOptimisticLocking, - metaAttributeContext - ); - registerAttributeBinding( binding ); - return binding; - } + /** + * Can the composite attribute be mapped to a single entity + * attribute by means of an actual component class that aggregates + * the tuple values? + * + * If {@code true} is returned, this instance can safely be cast + * to an {@link AggregatedCompositeAttributeBinding}. + * + * If {@code false} is returned, this instance can safely be cast + * to a {@link NonAggregatedCompositeAttributeBinding}. + * + * @return true, if the attribute can be mapped to a single entity + * attribute by means of an actual component class that aggregates + * the tuple values; false, otherwise. + */ + boolean isAggregated(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java index 5f131b122a..9f1abee9a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/CompositePluralAttributeElementBinding.java @@ -23,8 +23,10 @@ */ package org.hibernate.metamodel.spi.binding; +import java.util.List; + /** - * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#COMPOSITE} elements + * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#AGGREGATION} elements * * @author Steve Ebersole * @author Gail Badner @@ -36,6 +38,11 @@ public class CompositePluralAttributeElementBinding extends AbstractPluralAttrib @Override public Nature getNature() { - return Nature.COMPOSITE; + return Nature.AGGREGATION; + } + + @Override + public List getRelationalValueBindings() { + return null; //To change body of implemented methods use File | Settings | File Templates. } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java index 4d0d9ee3ff..7381a026fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/EntityBinding.java @@ -508,7 +508,7 @@ public class EntityBinding implements MutableAttributeBindingContainer { } @Override - public CompositeAttributeBinding makeAggregatedCompositeAttributeBinding( + public AggregatedCompositeAttributeBinding makeAggregatedCompositeAttributeBinding( SingularAttribute attribute, SingularAttribute parentReferenceAttribute, String propertyAccessorName, @@ -516,7 +516,7 @@ public class EntityBinding implements MutableAttributeBindingContainer { boolean lazy, SingularAttributeBinding.NaturalIdMutability naturalIdMutability, MetaAttributeContext metaAttributeContext) { - final CompositeAttributeBinding binding = new CompositeAttributeBinding( + final AggregatedCompositeAttributeBinding binding = new AggregatedCompositeAttributeBinding( this, attribute, propertyAccessorName, @@ -717,6 +717,11 @@ public class EntityBinding implements MutableAttributeBindingContainer { return attributeBindingMap.values(); } + @Override + public int attributeBindingSpan() { + return attributeBindingMap.size(); + } + /** * Gets the number of attribute bindings defined on this class, including the * identifier attribute binding and attribute bindings defined diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToAnyPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToAnyPluralAttributeElementBinding.java index d380756a69..c54638c1a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToAnyPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToAnyPluralAttributeElementBinding.java @@ -23,6 +23,8 @@ */ package org.hibernate.metamodel.spi.binding; +import java.util.List; + /** * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#MANY_TO_ANY} elements * @@ -38,4 +40,9 @@ public class ManyToAnyPluralAttributeElementBinding extends AbstractPluralAttrib public Nature getNature() { return Nature.MANY_TO_ANY; } + + @Override + public List getRelationalValueBindings() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java index b871dc475c..b086880c1e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/ManyToManyPluralAttributeElementBinding.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.spi.binding; import java.util.HashMap; +import java.util.List; import org.hibernate.metamodel.spi.relational.Value; @@ -49,6 +50,11 @@ public class ManyToManyPluralAttributeElementBinding extends AbstractPluralAttri return Nature.MANY_TO_MANY; } + @Override + public List getRelationalValueBindings() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + public String getManyToManyWhere() { return manyToManyWhere; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MutableAttributeBindingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MutableAttributeBindingContainer.java index e706a59ef4..da627b9b09 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MutableAttributeBindingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/MutableAttributeBindingContainer.java @@ -70,7 +70,7 @@ public interface MutableAttributeBindingContainer extends AttributeBindingContai * * @return The attribute binding instance. */ - public CompositeAttributeBinding makeAggregatedCompositeAttributeBinding( + public AggregatedCompositeAttributeBinding makeAggregatedCompositeAttributeBinding( SingularAttribute attribute, SingularAttribute parentReferenceAttribute, String propertyAccessorName, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/NonAggregatedCompositeAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/NonAggregatedCompositeAttributeBinding.java index 2e4af4e371..cb5894de3d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/NonAggregatedCompositeAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/NonAggregatedCompositeAttributeBinding.java @@ -33,6 +33,13 @@ import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.metamodel.spi.source.MetaAttributeContext; /** + * A composite attribute binding that contains an immutable tuple + * of attribute bindings that are mapped directly to the + * attribute binding's container. In other words, the tuple cannot + * be mapped to a single entity attribute. + * + * @todo should this be named something like TupleAttributebinding instead? + * * @author Gail Badner */ public class NonAggregatedCompositeAttributeBinding extends AbstractCompositeAttributeBinding { @@ -55,7 +62,7 @@ public class NonAggregatedCompositeAttributeBinding extends AbstractCompositeAtt metaAttributeContext ); if ( !AttributeContainer.class.isInstance( attribute.getSingularAttributeType() ) || - attribute.getSingularAttributeType().isComposite() ) { + attribute.getSingularAttributeType().isAggregate() ) { throw new IllegalArgumentException( "Expected the attribute type to be an non-component attribute container" ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToManyPluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToManyPluralAttributeElementBinding.java index f775ef97df..4db88b05a9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToManyPluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/OneToManyPluralAttributeElementBinding.java @@ -23,6 +23,8 @@ */ package org.hibernate.metamodel.spi.binding; +import java.util.List; + /** * Describes plural attributes of {@link org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding.Nature#ONE_TO_MANY} elements * @@ -30,6 +32,8 @@ package org.hibernate.metamodel.spi.binding; * @author Gail Badner */ public class OneToManyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding { + private EntityIdentifier elementEntityIdentifier; + OneToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) { super( binding ); } @@ -38,4 +42,14 @@ public class OneToManyPluralAttributeElementBinding extends AbstractPluralAttrib public Nature getNature() { return Nature.ONE_TO_MANY; } + + public void setElementEntityIdentifier(EntityIdentifier elementEntityIdentifier) { + this.elementEntityIdentifier = elementEntityIdentifier; + } + + @Override + public List getRelationalValueBindings() { + // TODO: ugh, can't call this until after the EntityIdentifier is completely bound... + return elementEntityIdentifier.getAttributeBinding().getRelationalValueBindings(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java index c70fc590de..dc69f5eabb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeElementBinding.java @@ -74,7 +74,7 @@ public interface PluralAttributeElementBinding { /** * The collection elements are compositions. */ - COMPOSITE( false ), + AGGREGATION( false ), /** * The collection elements represent entity's in a one-to-many association. */ diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java index 1847c29feb..851308119f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/binding/PluralAttributeIndexBinding.java @@ -51,9 +51,9 @@ public interface PluralAttributeIndexBinding { */ BASIC, /** - * The map key is a composite + * The map key is an aggregated composite */ - COMPOSITE, + AGGREGATION, /** * The map key is an association identified by a column(s) on the collection table. */ diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java index 7572f4d2c9..6aede577bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AbstractAttributeContainer.java @@ -163,7 +163,7 @@ public abstract class AbstractAttributeContainer implements AttributeContainer, } @Override - public SingularAttribute createCompositeAttribute(String name, Composite composite) { + public SingularAttribute createCompositeAttribute(String name, Aggregate composite) { SingularAttributeImpl attribute = new SingularAttributeImpl( this, name, false ); attribute.resolveType( composite ); addAttribute( attribute ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Composite.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Aggregate.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Composite.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Aggregate.java index 7218412b17..c5dfe4c970 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Composite.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Aggregate.java @@ -32,8 +32,8 @@ import org.hibernate.internal.util.ValueHolder; * * @author Steve Ebersole */ -public class Composite extends AbstractAttributeContainer { - public Composite(String name, String className, ValueHolder> classReference, Hierarchical superType) { +public class Aggregate extends AbstractAttributeContainer { + public Aggregate(String name, String className, ValueHolder> classReference, Hierarchical superType) { super( name, className, classReference, superType ); } @@ -43,7 +43,7 @@ public class Composite extends AbstractAttributeContainer { } @Override - public boolean isComposite() { + public boolean isAggregate() { return true; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AttributeContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AttributeContainer.java index b0a09dcab4..c71b62f29b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AttributeContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/AttributeContainer.java @@ -66,7 +66,7 @@ public interface AttributeContainer extends Type { public IndexedPluralAttribute locateMap(String name); public SingularAttribute createSingularAttribute(String name); - public SingularAttribute createCompositeAttribute(String name, Composite composite); + public SingularAttribute createCompositeAttribute(String name, Aggregate composite); public PluralAttribute createBag(String name); public PluralAttribute createSet(String name); public IndexedPluralAttribute createList(String name); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/BasicType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/BasicType.java index d5be838ff8..baf24ebbd6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/BasicType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/BasicType.java @@ -65,7 +65,7 @@ public class BasicType implements Type { } @Override - public boolean isComposite() { + public boolean isAggregate() { return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Entity.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Entity.java index e86f0548a1..3980d5973c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Entity.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Entity.java @@ -50,7 +50,7 @@ public class Entity extends AbstractAttributeContainer { } @Override - public boolean isComposite() { + public boolean isAggregate() { return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/NonEntity.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/NonEntity.java index 037a8fcffd..7915e097a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/NonEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/NonEntity.java @@ -49,7 +49,7 @@ public class NonEntity extends AbstractAttributeContainer { } @Override - public boolean isComposite() { + public boolean isAggregate() { return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Superclass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Superclass.java index d6df9cba28..24b44186ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Superclass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Superclass.java @@ -49,7 +49,7 @@ public class Superclass extends AbstractAttributeContainer { } @Override - public boolean isComposite() { + public boolean isAggregate() { return false; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Type.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Type.java index ac1c7f4a40..e5d53c5aeb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Type.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/Type.java @@ -60,5 +60,11 @@ public interface Type { public boolean isAssociation(); - public boolean isComposite(); + /** + * Is this attribute an aggregated composite (what JPA calls an Embeddable)? + * + * @return true, if this attribute is an aggregated composite; + * false, otherwise. + */ + public boolean isAggregate(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/TypeNature.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/TypeNature.java index 8366525e89..2550d2bfa4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/TypeNature.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/domain/TypeNature.java @@ -32,7 +32,7 @@ package org.hibernate.metamodel.spi.domain; */ public enum TypeNature { BASIC( "basic" ), - COMPOSITE( "composite" ), + AGGREGATION( "aggregation" ), ENTITY( "entity" ), SUPERCLASS( "superclass" ), NON_ENTITY( "non-entity" ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 1e9755fafd..4977266eaf 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -101,7 +101,7 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Selectable; import org.hibernate.metadata.ClassMetadata; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; @@ -2363,8 +2363,8 @@ public abstract class AbstractEntityPersister } SingularAttributeBinding singularProp = (SingularAttributeBinding) prop; String propname = path == null ? prop.getAttribute().getName() : path + "." + prop.getAttribute().getName(); - if ( prop instanceof AbstractCompositeAttributeBinding ) { - AbstractCompositeAttributeBinding component = (AbstractCompositeAttributeBinding) prop; + if ( prop instanceof CompositeAttributeBinding ) { + CompositeAttributeBinding component = (CompositeAttributeBinding) prop; internalInitSubclassPropertyAliasesMap( propname, component.attributeBindings() ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java index 6eb3b81c55..23957fb761 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java @@ -577,7 +577,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister { discriminatorInsertable = false; } else if ( entityBinding.isDiscriminatorMatchValueNotNull() ) { - discriminatorValue = NULL_DISCRIMINATOR; + discriminatorValue = NOT_NULL_DISCRIMINATOR; discriminatorSQLValue = InFragment.NOT_NULL; discriminatorInsertable = false; } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java index 59aa03a58e..a14399b249 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java @@ -31,8 +31,8 @@ import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.property.Getter; import org.hibernate.property.Setter; @@ -76,8 +76,12 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer { hasCustomAccessors = foundCustomAccessor; } + // TODO: Get rid of the need for isIdentifierMapper arg. + // Instead the CompositeAttributeBinding should be wrapped (e.g., by a proxy) + // so it can provide the information needed to create getters and setters + // for an identifier mapper. protected AbstractComponentTuplizer( - AbstractCompositeAttributeBinding compositeAttributeBinding, + CompositeAttributeBinding compositeAttributeBinding, boolean isIdentifierMapper ) { propertySpan = compositeAttributeBinding.attributeBindingSpan(); @@ -86,7 +90,12 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer { boolean foundCustomAccessor=false; int i = 0; + // TODO: when compositeAttributeBinding is wrapped for an identifier mapper + // there will be no need for PropertyFactory.getIdentifierMapperGetter() + // and PropertyFactory.getIdentifierMapperSetter if ( isIdentifierMapper ) { + // HACK ALERT: when isIdentifierMapper is true, the entity identifier + // must be completely bound when this method is called. final EntityMode entityMode = compositeAttributeBinding.getContainer().seekEntityBinding().getHierarchyDetails().getEntityMode(); final EntityIdentifier entityIdentifier = diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java index 3fa1b7fff0..01e0039d84 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentMetamodel.java @@ -32,8 +32,8 @@ import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.tuple.PropertyFactory; import org.hibernate.tuple.StandardProperty; @@ -84,7 +84,7 @@ public class ComponentMetamodel implements Serializable { } public ComponentMetamodel( - AbstractCompositeAttributeBinding component, + CompositeAttributeBinding component, boolean isIdentifierAttributeBinding, boolean isIdentifierMapper) { this.isKey = isIdentifierAttributeBinding; diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java index e876e12bd1..c18cdba380 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizerFactory.java @@ -32,7 +32,7 @@ import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.mapping.Component; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; /** * A registry allowing users to define the default {@link ComponentTuplizer} class to use per {@link EntityMode}. @@ -42,7 +42,7 @@ import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; public class ComponentTuplizerFactory implements Serializable { private static final Class[] COMPONENT_TUP_CTOR_SIG = new Class[] { Component.class }; private static final Class[] COMPONENT_TUP_CTOR_SIG_NEW = new Class[] { - AbstractCompositeAttributeBinding.class, + CompositeAttributeBinding.class, boolean.class }; @@ -102,7 +102,7 @@ public class ComponentTuplizerFactory implements Serializable { @SuppressWarnings({ "unchecked" }) public ComponentTuplizer constructTuplizer( String tuplizerClassName, - AbstractCompositeAttributeBinding metadata, + CompositeAttributeBinding metadata, boolean isIdentifierMapper) { try { Class tuplizerClass = ReflectHelper.classForName( tuplizerClassName ); @@ -146,7 +146,7 @@ public class ComponentTuplizerFactory implements Serializable { */ public ComponentTuplizer constructTuplizer( Class tuplizerClass, - AbstractCompositeAttributeBinding metadata, + CompositeAttributeBinding metadata, boolean isIdentifierMapper) { Constructor constructor = getProperConstructor( tuplizerClass, COMPONENT_TUP_CTOR_SIG_NEW ); assert constructor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]"; @@ -191,7 +191,7 @@ public class ComponentTuplizerFactory implements Serializable { */ public ComponentTuplizer constructDefaultTuplizer( EntityMode entityMode, - AbstractCompositeAttributeBinding metadata, + CompositeAttributeBinding metadata, boolean isIdentifierMapper) { Class tuplizerClass = defaultImplClassByMode.get( entityMode ); if ( tuplizerClass == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java index a2ecb65b75..33a79c5701 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java @@ -36,7 +36,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.AggregatedCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.property.BackrefPropertyAccessor; @@ -99,7 +99,7 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { } public PojoComponentTuplizer( - AbstractCompositeAttributeBinding component, + CompositeAttributeBinding component, boolean isIdentifierMapper) { super( component, isIdentifierMapper ); @@ -122,8 +122,8 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { final String parentPropertyName = component.isAggregated() && - ( (CompositeAttributeBinding) component ).getParentReference() != null ? - ( (CompositeAttributeBinding) component ).getParentReference().getName() : + ( (AggregatedCompositeAttributeBinding) component ).getParentReference() != null ? + ( (AggregatedCompositeAttributeBinding) component ).getParentReference().getName() : null; if ( parentPropertyName == null ) { parentSetter = null; diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index f33d10488b..392fd494a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -52,13 +52,13 @@ import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.binding.EntityIdentifier; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.domain.Aggregate; import org.hibernate.metamodel.spi.domain.Attribute; -import org.hibernate.metamodel.spi.domain.Composite; import org.hibernate.metamodel.spi.domain.SingularAttribute; import org.hibernate.tuple.IdentifierProperty; import org.hibernate.tuple.PropertyFactory; @@ -404,7 +404,7 @@ public class EntityMetamodel implements Serializable { } else if ( rootEntityIdentifier.isNonAggregatedComposite() ) { identifierAttributeBindingSpan = - ( (AbstractCompositeAttributeBinding) rootEntityIdentifier.getAttributeBinding() ).attributeBindingSpan(); + ( (CompositeAttributeBinding) rootEntityIdentifier.getAttributeBinding() ).attributeBindingSpan(); } else { identifierAttributeBindingSpan = 1; @@ -708,9 +708,9 @@ public class EntityMetamodel implements Serializable { private void mapPropertyToIndex(Attribute attribute, int i) { propertyIndexes.put( attribute.getName(), i ); if ( attribute.isSingular() && - ( ( SingularAttribute ) attribute ).getSingularAttributeType().isComposite() ) { - Composite composite = - (Composite) ( (SingularAttribute) attribute ).getSingularAttributeType(); + ( ( SingularAttribute ) attribute ).getSingularAttributeType().isAggregate() ) { + Aggregate composite = + (Aggregate) ( (SingularAttribute) attribute ).getSingularAttributeType(); for ( Attribute subAttribute : composite.attributes() ) { propertyIndexes.put( attribute.getName() + '.' + subAttribute.getName(), diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java index 33194346b9..983e85c31f 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/EmbeddableBindingTest.java @@ -35,8 +35,8 @@ import org.junit.Test; import org.hibernate.annotations.Parent; import org.hibernate.annotations.Target; -import org.hibernate.metamodel.spi.binding.AbstractCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; +import org.hibernate.metamodel.spi.binding.AggregatedCompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.testing.junit4.BaseAnnotationBindingTestCase; @@ -75,8 +75,8 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "phone"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof AbstractCompositeAttributeBinding ); - AbstractCompositeAttributeBinding compositeBinding = (AbstractCompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); + CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( componentName ); @@ -116,8 +116,8 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "embedded"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof AbstractCompositeAttributeBinding ); - AbstractCompositeAttributeBinding compositeBinding = (AbstractCompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); + CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( componentName ); @@ -171,8 +171,8 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String addressComponentName = "address"; assertNotNull( binding.locateAttributeBinding( addressComponentName ) ); - assertTrue( binding.locateAttributeBinding( addressComponentName ) instanceof AbstractCompositeAttributeBinding ); - AbstractCompositeAttributeBinding attributeCompositeBinding = (AbstractCompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( addressComponentName ) instanceof CompositeAttributeBinding ); + CompositeAttributeBinding attributeCompositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( addressComponentName ); @@ -195,8 +195,8 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String zipComponentName = "zipcode"; assertNotNull( attributeCompositeBinding.locateAttributeBinding( zipComponentName ) ); - assertTrue( attributeCompositeBinding.locateAttributeBinding( zipComponentName ) instanceof AbstractCompositeAttributeBinding ); - AbstractCompositeAttributeBinding zipCompositeBinding = (AbstractCompositeAttributeBinding) attributeCompositeBinding.locateAttributeBinding( + assertTrue( attributeCompositeBinding.locateAttributeBinding( zipComponentName ) instanceof CompositeAttributeBinding ); + CompositeAttributeBinding zipCompositeBinding = (CompositeAttributeBinding) attributeCompositeBinding.locateAttributeBinding( zipComponentName ); @@ -265,15 +265,15 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String aComponentName = "a"; assertNotNull( binding.locateAttributeBinding( aComponentName ) ); - assertTrue( binding.locateAttributeBinding( aComponentName ) instanceof AbstractCompositeAttributeBinding ); - AbstractCompositeAttributeBinding aCompositeBinding = (AbstractCompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( aComponentName ) instanceof CompositeAttributeBinding ); + CompositeAttributeBinding aCompositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( aComponentName ); final String bComponentName = "b"; assertNotNull( aCompositeBinding.locateAttributeBinding( bComponentName ) ); - assertTrue( aCompositeBinding.locateAttributeBinding( bComponentName ) instanceof AbstractCompositeAttributeBinding ); - AbstractCompositeAttributeBinding bCompositeBinding = (AbstractCompositeAttributeBinding) aCompositeBinding.locateAttributeBinding( + assertTrue( aCompositeBinding.locateAttributeBinding( bComponentName ) instanceof CompositeAttributeBinding ); + CompositeAttributeBinding bCompositeBinding = (CompositeAttributeBinding) aCompositeBinding.locateAttributeBinding( bComponentName ); @@ -331,8 +331,8 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "embedded"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof AbstractCompositeAttributeBinding ); - CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); + AggregatedCompositeAttributeBinding compositeBinding = (AggregatedCompositeAttributeBinding) binding.locateAttributeBinding( componentName ); @@ -385,8 +385,8 @@ public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase { final String componentName = "car"; assertNotNull( binding.locateAttributeBinding( componentName ) ); - assertTrue( binding.locateAttributeBinding( componentName ) instanceof AbstractCompositeAttributeBinding ); - AbstractCompositeAttributeBinding compositeBinding = (AbstractCompositeAttributeBinding) binding.locateAttributeBinding( + assertTrue( binding.locateAttributeBinding( componentName ) instanceof CompositeAttributeBinding ); + CompositeAttributeBinding compositeBinding = (CompositeAttributeBinding) binding.locateAttributeBinding( componentName ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java index 8cb7ff16cb..7c32d04bca 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java @@ -194,7 +194,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { assertEquals( referencedEntityName, simpleEntityAttributeType.getName() ); Assert.assertEquals( referencedEntityName, simpleEntityAttributeType.getClassName()); Assert.assertTrue( simpleEntityAttributeType.isAssociation() ); - assertFalse( simpleEntityAttributeType.isComposite() ); + assertFalse( simpleEntityAttributeType.isAggregate() ); // relational List relationalValueBindings = manyToOneAttributeBinding.getRelationalValueBindings(); @@ -240,8 +240,8 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase { assertRoot( metadata, entityBinding ); assertIdAndSimpleProperty( entityBinding ); - CompositeAttributeBinding compositeAttributeBinding = - (CompositeAttributeBinding) entityBinding.locateAttributeBinding( "simpleComponent" ); + AggregatedCompositeAttributeBinding compositeAttributeBinding = + (AggregatedCompositeAttributeBinding) entityBinding.locateAttributeBinding( "simpleComponent" ); assertNotNull( compositeAttributeBinding ); assertSame( compositeAttributeBinding.getAttribute().getSingularAttributeType(), compositeAttributeBinding.getAttributeContainer() ); assertEquals( SimpleEntityWithSimpleComponent.class.getName() + ".simpleComponent", compositeAttributeBinding.getPathBase() );