diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheDataDescriptionImpl.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheDataDescriptionImpl.java index ecfe6932f5..17c801f09c 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheDataDescriptionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheDataDescriptionImpl.java @@ -28,13 +28,11 @@ import java.util.Comparator; import org.hibernate.cache.spi.CacheDataDescription; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.type.VersionType; /** - * {@inheritDoc} - * * @author Steve Ebersole */ public class CacheDataDescriptionImpl implements CacheDataDescription { @@ -84,7 +82,7 @@ public class CacheDataDescriptionImpl implements CacheDataDescription { ); } - public static CacheDataDescriptionImpl decode(AbstractPluralAttributeBinding model) { + public static CacheDataDescriptionImpl decode(PluralAttributeBinding model) { return new CacheDataDescriptionImpl( model.isMutable(), model.getContainer().seekEntityBinding().isVersioned(), diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index f03391d78f..7df0a0c134 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -112,6 +112,7 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.CollectionMetadata; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.source.MetadataImplementor; import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; @@ -661,7 +662,7 @@ public final class SessionFactoryImpl Map> tmpEntityToCollectionRoleMap = new HashMap>(); collectionPersisters = new HashMap(); - for ( AbstractPluralAttributeBinding model : metadata.getCollectionBindings() ) { + for ( PluralAttributeBinding model : metadata.getCollectionBindings() ) { if ( model.getAttribute() == null ) { throw new IllegalStateException( "No attribute defined for a AbstractPluralAttributeBinding: " + model ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java index db19b8ac2e..0313e266ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/Metadata.java @@ -37,7 +37,7 @@ import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.FetchProfile; import org.hibernate.metamodel.binding.IdGenerator; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.binding.TypeDef; /** @@ -75,7 +75,7 @@ public interface Metadata { */ public EntityBinding getRootEntityBinding(String entityName); - public Iterable getCollectionBindings(); + public Iterable getCollectionBindings(); public TypeDef getTypeDefinition(String name); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractPluralAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractPluralAttributeBinding.java index ee5466a53f..dfe6194d35 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractPluralAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractPluralAttributeBinding.java @@ -41,8 +41,8 @@ import org.hibernate.metamodel.relational.Table; * @author Steve Ebersole */ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBinding implements PluralAttributeBinding { - private CollectionKey collectionKey; - private CollectionElement collectionElement; + private final CollectionKey collectionKey; + private final CollectionElement collectionElement; private Table collectionTable; @@ -81,6 +81,7 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi PluralAttribute attribute, CollectionElementNature collectionElementNature) { super( container, attribute ); + this.collectionKey = new CollectionKey( this ); this.collectionElement = interpretNature( collectionElementNature ); } @@ -160,10 +161,6 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi return collectionKey; } - public void setCollectionKey(CollectionKey collectionKey) { - this.collectionKey = collectionKey; - } - public CollectionElement getCollectionElement() { return collectionElement; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBindingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBindingContainer.java index fd1b8599b6..c208c3911c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBindingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBindingContainer.java @@ -102,6 +102,16 @@ public interface AttributeBindingContainer { */ public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature); + /** + * Factory method for bag attribute bindings. + * + * @param attribute The attribute for which to make a binding. + * @param nature The nature of the collection elements. + * + * @return The attribute binding instance. + */ + public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature); + /** * Seeks out the entity binding that is the root of this component path. * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentAttributeBinding.java index 2014d37baf..b64b79eabe 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/ComponentAttributeBinding.java @@ -30,6 +30,7 @@ import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.domain.AttributeContainer; import org.hibernate.metamodel.domain.Component; import org.hibernate.metamodel.domain.PluralAttribute; +import org.hibernate.metamodel.domain.PluralAttributeNature; import org.hibernate.metamodel.domain.SingularAttribute; import org.hibernate.metamodel.source.MetaAttributeContext; @@ -128,11 +129,20 @@ public class ComponentAttributeBinding extends AbstractSingularAttributeBinding @Override public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG ); final BagBinding binding = new BagBinding( this, attribute, nature ); registerAttributeBinding( attribute.getName(), binding ); return binding; } + @Override + public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET ); + final SetBinding binding = new SetBinding( this, attribute, nature ); + registerAttributeBinding( attribute.getName(), binding ); + return binding; + } + @Override public Class getClassReference() { return getComponent().getClassReference(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java index 8144933668..6d8e083443 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/EntityBinding.java @@ -35,6 +35,7 @@ import org.hibernate.internal.util.Value; import org.hibernate.metamodel.domain.AttributeContainer; import org.hibernate.metamodel.domain.Entity; import org.hibernate.metamodel.domain.PluralAttribute; +import org.hibernate.metamodel.domain.PluralAttributeNature; import org.hibernate.metamodel.domain.SingularAttribute; import org.hibernate.metamodel.relational.TableSpecification; import org.hibernate.metamodel.source.MetaAttributeContext; @@ -424,11 +425,20 @@ public class EntityBinding implements AttributeBindingContainer { @Override public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG ); final BagBinding binding = new BagBinding( this, attribute, nature ); registerAttributeBinding( attribute.getName(), binding ); return binding; } + @Override + public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { + Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET ); + final SetBinding binding = new SetBinding( this, attribute, nature ); + registerAttributeBinding( attribute.getName(), binding ); + return binding; + } + @Override public AttributeBinding locateAttributeBinding(String name) { return attributeBindingMap.get( name ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/Helper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/Helper.java new file mode 100644 index 0000000000..1bd2427d81 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/Helper.java @@ -0,0 +1,47 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.binding; + +import org.hibernate.AssertionFailure; +import org.hibernate.metamodel.domain.PluralAttribute; +import org.hibernate.metamodel.domain.PluralAttributeNature; + +/** + * Helper utilities specific to the binding package. + * + * @author Steve Ebersole + */ +public class Helper { + public static void checkPluralAttributeNature(PluralAttribute attribute, PluralAttributeNature expected) { + if ( attribute.getNature() != expected ) { + throw new AssertionFailure( + String.format( + "Mismatched collection natures; expecting %s, but found %s", + expected.getName(), + attribute.getNature().getName() + ) + ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java index 129d2574cf..348ddf3bf4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.binding; import org.hibernate.metamodel.relational.Table; +import org.hibernate.persister.collection.CollectionPersister; /** * @author Steve Ebersole @@ -37,4 +38,11 @@ public interface PluralAttributeBinding extends AttributeBinding, AssociationAtt public Table getCollectionTable(); + public boolean isMutable(); + + public String getCacheRegionName(); + + public String getCacheConcurrencyStrategy(); + + public Class getCollectionPersisterClass(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/SetBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/SetBinding.java new file mode 100644 index 0000000000..98a0b05d02 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/SetBinding.java @@ -0,0 +1,50 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.binding; + +import java.util.Comparator; + +import org.hibernate.metamodel.domain.PluralAttribute; + +/** + * @author Steve Ebersole + */ +public class SetBinding extends AbstractPluralAttributeBinding { + private Comparator comparator; + + protected SetBinding( + AttributeBindingContainer container, + PluralAttribute attribute, + CollectionElementNature collectionElementNature) { + super( container, attribute, collectionElementNature ); + } + + public Comparator getComparator() { + return comparator; + } + + public void setComparator(Comparator comparator) { + this.comparator = comparator; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/PluralAttributeNature.java b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/PluralAttributeNature.java index 7d81937073..492299ad68 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/domain/PluralAttributeNature.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/domain/PluralAttributeNature.java @@ -35,6 +35,7 @@ import java.util.Set; */ public enum PluralAttributeNature { BAG( "bag", Collection.class ), + IDBAG( "idbag", Collection.class ), SET( "set", Set.class ), LIST( "list", List.class ), MAP( "map", Map.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/MetadataImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/MetadataImplementor.java index 130f41222b..2e7f489e2c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/MetadataImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/MetadataImplementor.java @@ -29,10 +29,10 @@ import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.NamedQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.metamodel.Metadata; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.FetchProfile; import org.hibernate.metamodel.binding.IdGenerator; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.binding.TypeDef; import org.hibernate.metamodel.relational.Database; import org.hibernate.service.BasicServiceRegistry; @@ -52,7 +52,7 @@ public interface MetadataImplementor extends Metadata, BindingContext, Mapping { public void addEntity(EntityBinding entityBinding); - public void addCollection(AbstractPluralAttributeBinding collectionBinding); + public void addCollection(PluralAttributeBinding collectionBinding); public void addFetchProfile(FetchProfile profile); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java index dfde432367..f921778f98 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/JandexHelper.java @@ -44,6 +44,7 @@ import org.jboss.jandex.MethodInfo; import org.jboss.jandex.Type; import org.hibernate.AssertionFailure; +import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.service.classloading.spi.ClassLoaderService; @@ -363,4 +364,25 @@ public class JandexHelper { return type.cast( returnValue ); } + + public static AnnotationInstance locatePojoTuplizerAnnotation(ClassInfo classInfo) { + final AnnotationInstance tuplizersAnnotation = getSingleAnnotation( + classInfo, HibernateDotNames.TUPLIZERS + ); + if ( tuplizersAnnotation == null ) { + return null; + } + + AnnotationInstance[] annotations = getValue( + tuplizersAnnotation, + "value", + AnnotationInstance[].class + ); + for ( AnnotationInstance tuplizerAnnotation : annotations ) { + if ( EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() ) == EntityMode.POJO ) { + return tuplizerAnnotation; + } + } + return null; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ComponentAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ComponentAttributeSourceImpl.java index 699804367c..c0b31bbf18 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ComponentAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ComponentAttributeSourceImpl.java @@ -27,9 +27,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jboss.jandex.AnnotationInstance; + import org.hibernate.internal.util.Value; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.annotations.JandexHelper; import org.hibernate.metamodel.source.annotations.attribute.AssociationAttribute; import org.hibernate.metamodel.source.annotations.attribute.BasicAttribute; import org.hibernate.metamodel.source.annotations.attribute.SingularAttributeSourceImpl; @@ -93,6 +96,16 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource { return embeddableClass.getEmbeddedAttributeName(); } + @Override + public String getExplicitTuplizerClassName() { + String customTuplizer = null; + final AnnotationInstance pojoTuplizerAnnotation = JandexHelper.locatePojoTuplizerAnnotation( embeddableClass.getClassInfo() ); + if ( pojoTuplizerAnnotation != null ) { + customTuplizer = pojoTuplizerAnnotation.value( "impl" ).asString(); + } + return customTuplizer; + } + @Override public String getPropertyAccessorName() { return embeddableClass.getClassAccessType().toString().toLowerCase(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java index 927a482005..d183e810cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java @@ -23,14 +23,14 @@ */ package org.hibernate.metamodel.source.annotations.entity; +import javax.persistence.AccessType; +import javax.persistence.DiscriminatorType; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.persistence.AccessType; -import javax.persistence.DiscriminatorType; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -38,7 +38,6 @@ import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.hibernate.AnnotationException; -import org.hibernate.EntityMode; import org.hibernate.MappingException; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.OptimisticLockType; @@ -54,10 +53,8 @@ import org.hibernate.metamodel.source.annotations.HibernateDotNames; import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JandexHelper; import org.hibernate.metamodel.source.annotations.attribute.ColumnValues; -import org.hibernate.metamodel.source.annotations.attribute.DerivedValueSourceImpl; import org.hibernate.metamodel.source.annotations.attribute.FormulaValue; import org.hibernate.metamodel.source.binder.ConstraintSource; -import org.hibernate.metamodel.source.binder.DerivedValueSource; import org.hibernate.metamodel.source.binder.TableSource; /** @@ -722,34 +719,13 @@ public class EntityClass extends ConfiguredClass { private String determineCustomTuplizer() { // Custom tuplizer String customTuplizer = null; - final AnnotationInstance pojoTuplizerAnnotation = locatePojoTuplizerAnnotation(); + final AnnotationInstance pojoTuplizerAnnotation = JandexHelper.locatePojoTuplizerAnnotation( getClassInfo() ); if ( pojoTuplizerAnnotation != null ) { customTuplizer = pojoTuplizerAnnotation.value( "impl" ).asString(); } return customTuplizer; } - private AnnotationInstance locatePojoTuplizerAnnotation() { - final AnnotationInstance tuplizersAnnotation = JandexHelper.getSingleAnnotation( - getClassInfo(), HibernateDotNames.TUPLIZERS - ); - if ( tuplizersAnnotation == null ) { - return null; - } - - AnnotationInstance[] annotations = JandexHelper.getValue( - tuplizersAnnotation, - "value", - AnnotationInstance[].class - ); - for ( AnnotationInstance tuplizerAnnotation : annotations ) { - if ( EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() ) == EntityMode.POJO ) { - return tuplizerAnnotation; - } - } - return null; - } - private void processProxyGeneration() { // Proxy generation final AnnotationInstance hibernateProxyAnnotation = JandexHelper.getSingleAnnotation( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/BasicPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/BasicPluralAttributeElementSource.java new file mode 100644 index 0000000000..bf1d055bd8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/BasicPluralAttributeElementSource.java @@ -0,0 +1,34 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +import java.util.List; + +/** + * @author Steve Ebersole + */ +public interface BasicPluralAttributeElementSource extends PluralAttributeElementSource { + public List getValueSources(); + public ExplicitHibernateTypeSource getExplicitHibernateTypeSource(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Binder.java index be8b09b081..5f7515a511 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Binder.java @@ -450,15 +450,77 @@ public class Binder { : attributeBindingContainer.getAttributeContainer().createBag( attributeSource.getName() ); pluralAttributeBinding = attributeBindingContainer.makeBagAttributeBinding( attribute, - convert( attributeSource.getPluralAttributeElementNature() ) + convert( attributeSource.getElementSource().getNature() ) + ); + } + else if ( attributeSource.getPluralAttributeNature() == PluralAttributeNature.SET ) { + final PluralAttribute attribute = existingAttribute != null + ? existingAttribute + : attributeBindingContainer.getAttributeContainer().createSet( attributeSource.getName() ); + pluralAttributeBinding = attributeBindingContainer.makeSetAttributeBinding( + attribute, + convert( attributeSource.getElementSource().getNature() ) ); } else { // todo : implement other collection types - throw new NotYetImplementedException( "Collections other than bag not yet implmented :(" ); + throw new NotYetImplementedException( "Collections other than bag not yet implemented :(" ); } doBasicAttributeBinding( attributeSource, pluralAttributeBinding ); + + bindCollectionTable( attributeSource, pluralAttributeBinding ); + bindCollectionKey( attributeSource, pluralAttributeBinding ); + bindSortingAndOrdering( attributeSource, pluralAttributeBinding ); + + metadata.addCollection( pluralAttributeBinding ); + } + + private void bindCollectionTable( + PluralAttributeSource attributeSource, + AbstractPluralAttributeBinding pluralAttributeBinding) { + if ( attributeSource.getElementSource().getNature() == PluralAttributeElementNature.ONE_TO_MANY ) { + return; + } + + if ( StringHelper.isNotEmpty( attributeSource.getExplicitCollectionTableName() ) ) { + final Identifier tableIdentifier = Identifier.toIdentifier( attributeSource.getExplicitCollectionTableName() ); + Table collectionTable = metadata.getDatabase().getDefaultSchema().locateTable( tableIdentifier ); + if ( collectionTable == null ) { + collectionTable = metadata.getDatabase().getDefaultSchema().createTable( tableIdentifier ); + } + pluralAttributeBinding.setCollectionTable( collectionTable ); + } + else { + // todo : we need to infer the name, but that requires possibly knowing the other side + } + } + + private void bindCollectionKey( + PluralAttributeSource attributeSource, + AbstractPluralAttributeBinding pluralAttributeBinding) { + // todo : implement + } + + private void bindSortingAndOrdering( + PluralAttributeSource attributeSource, + AbstractPluralAttributeBinding pluralAttributeBinding) { + if ( Sortable.class.isInstance( attributeSource ) ) { + final Sortable sortable = Sortable.class.cast( attributeSource ); + if ( sortable.isSorted() ) { + // todo : handle setting comparator + + // and then return because sorting and ordering are mutually exclusive + return; + } + } + + if ( Orderable.class.isInstance( attributeSource ) ) { + final Orderable orderable = Orderable.class.cast( attributeSource ); + if ( orderable.isOrdered() ) { + // todo : handle setting ordering + } + } } private void doBasicAttributeBinding(AttributeSource attributeSource, AttributeBinding attributeBinding) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentAttributeSource.java index debe349634..f23c26f8aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentAttributeSource.java @@ -34,4 +34,6 @@ public interface ComponentAttributeSource extends SingularAttributeSource, Attri public Value> getClassReference(); public String getParentReferenceAttributeName(); + + public String getExplicitTuplizerClassName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/CompositePluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/CompositePluralAttributeElementSource.java new file mode 100644 index 0000000000..8b190e32af --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/CompositePluralAttributeElementSource.java @@ -0,0 +1,39 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +import org.hibernate.internal.util.Value; + +/** + * @author Steve Ebersole + */ +public interface CompositePluralAttributeElementSource extends PluralAttributeElementSource, AttributeSourceContainer { + public String getClassName(); + + public Value> getClassReference(); + + public String getParentReferenceAttributeName(); + + public String getExplicitTuplizerClassName(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ManyToAnyPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ManyToAnyPluralAttributeElementSource.java new file mode 100644 index 0000000000..89d49a8a05 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ManyToAnyPluralAttributeElementSource.java @@ -0,0 +1,30 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +/** + * @author Steve Ebersole + */ +public interface ManyToAnyPluralAttributeElementSource extends PluralAttributeElementSource { +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ManyToManyPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ManyToManyPluralAttributeElementSource.java new file mode 100644 index 0000000000..e1c9cfb8ae --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ManyToManyPluralAttributeElementSource.java @@ -0,0 +1,48 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +import java.util.List; + +import org.hibernate.FetchMode; + +/** + * @author Steve Ebersole + */ +public interface ManyToManyPluralAttributeElementSource extends PluralAttributeElementSource { + public String getReferencedEntityName(); + public String getReferencedEntityAttributeName(); + + public List getValueSources(); // these describe the "outgoing" link + + public boolean isNotFoundAnException(); + public String getExplicitForeignKeyName(); + public boolean isUnique(); + + public String getOrderBy(); + public String getWhere(); + + public FetchMode getFetchMode(); + public boolean fetchImmediately(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/OneToManyPluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/OneToManyPluralAttributeElementSource.java new file mode 100644 index 0000000000..aecc755706 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/OneToManyPluralAttributeElementSource.java @@ -0,0 +1,32 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +/** + * @author Steve Ebersole + */ +public interface OneToManyPluralAttributeElementSource extends PluralAttributeElementSource { + public String getReferencedEntityName(); + public boolean isNotFoundAnException(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Orderable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Orderable.java new file mode 100644 index 0000000000..115f67aef9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Orderable.java @@ -0,0 +1,32 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +/** + * @author Steve Ebersole + */ +public interface Orderable { + public boolean isOrdered(); + public String getOrder(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeElementSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeElementSource.java new file mode 100644 index 0000000000..aeb60a31ea --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeElementSource.java @@ -0,0 +1,32 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +/** + * @author Steve Ebersole + */ +public interface PluralAttributeElementSource { + public PluralAttributeElementNature getNature(); + +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeKeySource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeKeySource.java new file mode 100644 index 0000000000..815a7828fa --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeKeySource.java @@ -0,0 +1,38 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +import java.util.List; + +import org.hibernate.metamodel.relational.ForeignKey; + +/** + * @author Steve Ebersole + */ +public interface PluralAttributeKeySource { + public List getValueSources(); + public String getExplicitForeignKeyName(); + public ForeignKey.ReferentialAction getOnDeleteAction(); + public String getReferencedEntityAttributeName(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeSource.java index 9c6ac98059..2c5673497b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/PluralAttributeSource.java @@ -26,8 +26,14 @@ package org.hibernate.metamodel.source.binder; /** * @author Steve Ebersole */ -public interface PluralAttributeSource extends AttributeSource { +public interface PluralAttributeSource extends AssociationAttributeSource { public PluralAttributeNature getPluralAttributeNature(); - public PluralAttributeElementNature getPluralAttributeElementNature(); + public PluralAttributeKeySource getKeySource(); + + public PluralAttributeElementSource getElementSource(); + + public String getExplicitCollectionTableName(); + + public boolean isInverse(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Sortable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Sortable.java new file mode 100644 index 0000000000..cba0da7996 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/Sortable.java @@ -0,0 +1,33 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.binder; + +/** + * @author Steve Ebersole + */ +public interface Sortable { + public boolean isSorted(); + public String getComparatorName(); + +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntitySourceImpl.java index 578ccfe97e..bef0dea833 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntitySourceImpl.java @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.binding.CustomSQL; @@ -41,12 +42,17 @@ import org.hibernate.metamodel.source.binder.SubclassEntitySource; import org.hibernate.metamodel.source.binder.TableSource; import org.hibernate.metamodel.source.hbm.jaxb.mapping.EntityElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLAnyElement; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLBagElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLComponentElement; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLIdbagElement; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLListElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToManyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToOneElement; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLMapElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToOneElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLPropertyElement; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLSetElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLSynchronizeElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLTuplizerElement; @@ -232,12 +238,34 @@ public abstract class AbstractEntitySourceImpl implements EntitySource { else if ( XMLAnyElement.class.isInstance( attributeElement ) ) { // todo : implement } - else if ( XMLOneToManyElement.class.isInstance( attributeElement ) ) { + else if ( XMLBagElement.class.isInstance( attributeElement ) ) { + attributeSources.add( + new BagAttributeSourceImpl( + XMLBagElement.class.cast( attributeElement ), + this + ) + ); + } + else if ( XMLIdbagElement.class.isInstance( attributeElement ) ) { // todo : implement } - else if ( XMLManyToManyElement.class.isInstance( attributeElement ) ) { + else if ( XMLSetElement.class.isInstance( attributeElement ) ) { + attributeSources.add( + new SetAttributeSourceImpl( + XMLSetElement.class.cast( attributeElement ), + this + ) + ); + } + else if ( XMLListElement.class.isInstance( attributeElement ) ) { // todo : implement } + else if ( XMLMapElement.class.isInstance( attributeElement ) ) { + // todo : implement + } + else { + throw new AssertionFailure( "Unexpected attribute element type encountered : " + attributeElement.getClass() ); + } } return attributeSources; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractPluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractPluralAttributeSourceImpl.java new file mode 100644 index 0000000000..25fbedbf4f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractPluralAttributeSourceImpl.java @@ -0,0 +1,52 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.binder.AttributeSourceContainer; +import org.hibernate.metamodel.source.binder.PluralAttributeSource; + +/** + * @author Steve Ebersole + */ +public abstract class AbstractPluralAttributeSourceImpl implements PluralAttributeSource { + private final AttributeSourceContainer container; + + protected AbstractPluralAttributeSourceImpl(AttributeSourceContainer container) { + this.container = container; + } + + protected AttributeSourceContainer container() { + return container; + } + + protected LocalBindingContext bindingContext() { + return container().getLocalBindingContext(); + } + + @Override + public boolean isSingular() { + return false; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/BagAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/BagAttributeSourceImpl.java new file mode 100644 index 0000000000..9c319cb465 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/BagAttributeSourceImpl.java @@ -0,0 +1,149 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import org.hibernate.FetchMode; +import org.hibernate.cfg.NotYetImplementedException; +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.MappingException; +import org.hibernate.metamodel.source.binder.AttributeSourceContainer; +import org.hibernate.metamodel.source.binder.MetaAttributeSource; +import org.hibernate.metamodel.source.binder.PluralAttributeElementSource; +import org.hibernate.metamodel.source.binder.PluralAttributeKeySource; +import org.hibernate.metamodel.source.binder.PluralAttributeNature; +import org.hibernate.metamodel.source.binder.PluralAttributeSource; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLBagElement; + +/** + * @author Steve Ebersole + */ +public class BagAttributeSourceImpl implements PluralAttributeSource { + private final XMLBagElement bagElement; + private final AttributeSourceContainer container; + + // todo : a lot of this could be consolidated with common JAXB interface for collection mappings and moved to a base class + + private final PluralAttributeKeySource keySource; + private final PluralAttributeElementSource elementSource; + + public BagAttributeSourceImpl(XMLBagElement bagElement, AttributeSourceContainer container) { + this.bagElement = bagElement; + this.container = container; + + this.keySource = new PluralAttributeKeySourceImpl( bagElement.getKey(), container ); + this.elementSource = interpretElementType( bagElement ); + } + + private PluralAttributeElementSource interpretElementType(XMLBagElement bagElement) { + if ( bagElement.getElement() != null ) { + return new BasicPluralAttributeElementSourceImpl( bagElement.getElement(), container.getLocalBindingContext() ); + } + else if ( bagElement.getCompositeElement() != null ) { + return new CompositePluralAttributeElementSourceImpl( bagElement.getCompositeElement(), container.getLocalBindingContext() ); + } + else if ( bagElement.getOneToMany() != null ) { + return new OneToManyPluralAttributeElementSourceImpl( bagElement.getOneToMany(), container.getLocalBindingContext() ); + } + else if ( bagElement.getManyToMany() != null ) { + return new ManyToManyPluralAttributeElementSourceImpl( bagElement.getManyToMany(), container.getLocalBindingContext() ); + } + else if ( bagElement.getManyToAny() != null ) { + throw new NotYetImplementedException( "Support for many-to-any not yet implemented" ); +// return PluralAttributeElementNature.MANY_TO_ANY; + } + else { + throw new MappingException( + "Unexpected collection element type : " + bagElement.getName(), + bindingContext().getOrigin() + ); + } + } + + @Override + public PluralAttributeNature getPluralAttributeNature() { + return PluralAttributeNature.BAG; + } + + @Override + public PluralAttributeKeySource getKeySource() { + return keySource; + } + + @Override + public PluralAttributeElementSource getElementSource() { + return elementSource; + } + + @Override + public String getExplicitCollectionTableName() { + return bagElement.getTable(); + } + + private LocalBindingContext bindingContext() { + return container.getLocalBindingContext(); + } + + @Override + public String getName() { + return bagElement.getName(); + } + + @Override + public boolean isSingular() { + return false; + } + + @Override + public String getPropertyAccessorName() { + return bagElement.getAccess(); + } + + @Override + public boolean isIncludedInOptimisticLocking() { + return bagElement.isOptimisticLock(); + } + + @Override + public boolean isInverse() { + return bagElement.isInverse(); + } + + @Override + public Iterable metaAttributes() { + return Helper.buildMetaAttributeSources( bagElement.getMeta() ); + } + + @Override + public Iterable getCascadeStyles() { + return Helper.interpretCascadeStyles( bagElement.getCascade(), bindingContext() ); + } + + @Override + public FetchMode getFetchMode() { + return bagElement.getFetch() == null + ? FetchMode.DEFAULT + : FetchMode.valueOf( bagElement.getFetch().value() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/BasicPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/BasicPluralAttributeElementSourceImpl.java new file mode 100644 index 0000000000..1372f7d789 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/BasicPluralAttributeElementSourceImpl.java @@ -0,0 +1,118 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import java.util.List; +import java.util.Map; + +import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.binder.BasicPluralAttributeElementSource; +import org.hibernate.metamodel.source.binder.ExplicitHibernateTypeSource; +import org.hibernate.metamodel.source.binder.PluralAttributeElementNature; +import org.hibernate.metamodel.source.binder.RelationalValueSource; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLElementElement; + +/** + * @author Steve Ebersole + */ +public class BasicPluralAttributeElementSourceImpl implements BasicPluralAttributeElementSource { + private final List valueSources; + private final ExplicitHibernateTypeSource typeSource; + + public BasicPluralAttributeElementSourceImpl( + final XMLElementElement elementElement, + LocalBindingContext bindingContext) { + this.valueSources = Helper.buildValueSources( + new Helper.ValueSourcesAdapter() { + @Override + public String getContainingTableName() { + return null; + } + + @Override + public boolean isIncludedInInsertByDefault() { + return true; + } + + @Override + public boolean isIncludedInUpdateByDefault() { + return true; + } + + @Override + public String getColumnAttribute() { + return elementElement.getColumn(); + } + + @Override + public String getFormulaAttribute() { + return elementElement.getFormula(); + } + + @Override + public List getColumnOrFormulaElements() { + return elementElement.getColumnOrFormula(); + } + }, + bindingContext + ); + + this.typeSource = new ExplicitHibernateTypeSource() { + @Override + public String getName() { + if ( elementElement.getTypeAttribute() != null ) { + return elementElement.getTypeAttribute(); + } + else if ( elementElement.getType() != null ) { + return elementElement.getType().getName(); + } + else { + return null; + } + } + + @Override + public Map getParameters() { + return elementElement.getType() != null + ? Helper.extractParameters( elementElement.getType().getParam() ) + : java.util.Collections.emptyMap(); + } + }; + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.BASIC; + } + + @Override + public List getValueSources() { + return valueSources; + } + + @Override + public ExplicitHibernateTypeSource getExplicitHibernateTypeSource() { + return typeSource; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/ComponentAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/ComponentAttributeSourceImpl.java index 70f6726e3b..b0bd294ee7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/ComponentAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/ComponentAttributeSourceImpl.java @@ -26,6 +26,8 @@ package org.hibernate.metamodel.source.hbm; import java.util.ArrayList; import java.util.List; +import org.hibernate.EntityMode; +import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.Value; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.source.LocalBindingContext; @@ -43,6 +45,7 @@ import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToOneElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToOneElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLPropertyElement; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLTuplizerElement; /** * @author Steve Ebersole @@ -61,7 +64,9 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource { this.componentElement = componentElement; this.parentContainer = parentContainer; - this.componentClassReference = bindingContext.makeClassReference( componentElement.getClazz() ); + this.componentClassReference = bindingContext.makeClassReference( + bindingContext.qualifyClassName( componentElement.getClazz() ) + ); this.path = parentContainer.getPath() + '.' + componentElement.getName(); } @@ -90,6 +95,20 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource { return componentElement.getParent() == null ? null : componentElement.getParent().getName(); } + @Override + public String getExplicitTuplizerClassName() { + if ( componentElement.getTuplizer() == null ) { + return null; + } + final EntityMode entityMode = StringHelper.isEmpty( componentElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO; + for ( XMLTuplizerElement tuplizerElement : componentElement.getTuplizer() ) { + if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) { + return tuplizerElement.getClazz(); + } + } + return null; + } + @Override public Iterable attributeSources() { List attributeSources = new ArrayList(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/CompositePluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/CompositePluralAttributeElementSourceImpl.java new file mode 100644 index 0000000000..da2c6f1b3e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/CompositePluralAttributeElementSourceImpl.java @@ -0,0 +1,108 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.EntityMode; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.Value; +import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.binder.AttributeSource; +import org.hibernate.metamodel.source.binder.CompositePluralAttributeElementSource; +import org.hibernate.metamodel.source.binder.PluralAttributeElementNature; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLCompositeElementElement; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLTuplizerElement; + +/** + * @author Steve Ebersole + */ +public class CompositePluralAttributeElementSourceImpl implements CompositePluralAttributeElementSource { + private final XMLCompositeElementElement compositeElement; + private final LocalBindingContext bindingContext; + + public CompositePluralAttributeElementSourceImpl( + XMLCompositeElementElement compositeElement, + LocalBindingContext bindingContext) { + this.compositeElement = compositeElement; + this.bindingContext = bindingContext; + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.COMPONENT; + } + + @Override + public String getClassName() { + return bindingContext.qualifyClassName( compositeElement.getClazz() ); + } + + @Override + public Value> getClassReference() { + return bindingContext.makeClassReference( getClassName() ); + } + + @Override + public String getParentReferenceAttributeName() { + return compositeElement.getParent() != null + ? compositeElement.getParent().getName() + : null; + } + + @Override + public String getExplicitTuplizerClassName() { + if ( compositeElement.getTuplizer() == null ) { + return null; + } + final EntityMode entityMode = StringHelper.isEmpty( compositeElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO; + for ( XMLTuplizerElement tuplizerElement : compositeElement.getTuplizer() ) { + if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) { + return tuplizerElement.getClazz(); + } + } + return null; + } + + @Override + public String getPath() { + // todo : implementing this requires passing in the collection source and being able to resolve the collection's role + return null; + } + + @Override + public Iterable attributeSources() { + List attributeSources = new ArrayList(); + for ( Object attribute : compositeElement.getPropertyOrManyToOneOrAny() ) { + + } + return attributeSources; + } + + @Override + public LocalBindingContext getLocalBindingContext() { + return bindingContext; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java new file mode 100644 index 0000000000..430ee8a005 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java @@ -0,0 +1,159 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import java.util.List; + +import org.hibernate.FetchMode; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.binder.ManyToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.binder.PluralAttributeElementNature; +import org.hibernate.metamodel.source.binder.RelationalValueSource; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToManyElement; + +/** + * @author Steve Ebersole + */ +public class ManyToManyPluralAttributeElementSourceImpl implements ManyToManyPluralAttributeElementSource { + private final XMLManyToManyElement manyToManyElement; + private final LocalBindingContext bindingContext; + + private final List valueSources; + + public ManyToManyPluralAttributeElementSourceImpl( + final XMLManyToManyElement manyToManyElement, + final LocalBindingContext bindingContext) { + this.manyToManyElement = manyToManyElement; + this.bindingContext = bindingContext; + + this.valueSources = Helper.buildValueSources( + new Helper.ValueSourcesAdapter() { + @Override + public String getContainingTableName() { + return null; + } + + @Override + public boolean isIncludedInInsertByDefault() { + return true; + } + + @Override + public boolean isIncludedInUpdateByDefault() { + return true; + } + + @Override + public String getColumnAttribute() { + return manyToManyElement.getColumn(); + } + + @Override + public String getFormulaAttribute() { + return manyToManyElement.getFormula(); + } + + @Override + public List getColumnOrFormulaElements() { + return manyToManyElement.getColumnOrFormula(); + } + }, + bindingContext + ); + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.MANY_TO_MANY; + } + + @Override + public String getReferencedEntityName() { + return StringHelper.isNotEmpty( manyToManyElement.getEntityName() ) + ? manyToManyElement.getEntityName() + : bindingContext.qualifyClassName( manyToManyElement.getClazz() ); + } + + @Override + public String getReferencedEntityAttributeName() { + return manyToManyElement.getPropertyRef(); + } + + @Override + public List getValueSources() { + return valueSources; + } + + @Override + public boolean isNotFoundAnException() { + return manyToManyElement.getNotFound() == null + || ! "ignore".equals( manyToManyElement.getNotFound().value() ); + } + + @Override + public String getExplicitForeignKeyName() { + return manyToManyElement.getForeignKey(); + } + + @Override + public boolean isUnique() { + return manyToManyElement.isUnique(); + } + + @Override + public String getOrderBy() { + return manyToManyElement.getOrderBy(); + } + + @Override + public String getWhere() { + return manyToManyElement.getWhere(); + } + + @Override + public FetchMode getFetchMode() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public boolean fetchImmediately() { + if ( manyToManyElement.getLazy() != null ) { + if ( "false".equals( manyToManyElement.getLazy().value() ) ) { + return true; + } + } + + if ( manyToManyElement.getOuterJoin() == null ) { + return ! bindingContext.getMappingDefaults().areAssociationsLazy(); + } + else { + final String value = manyToManyElement.getOuterJoin().value(); + if ( "auto".equals( value ) ) { + return ! bindingContext.getMappingDefaults().areAssociationsLazy(); + } + return "true".equals( value ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/OneToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/OneToManyPluralAttributeElementSourceImpl.java new file mode 100644 index 0000000000..7920072af4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/OneToManyPluralAttributeElementSourceImpl.java @@ -0,0 +1,63 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.binder.OneToManyPluralAttributeElementSource; +import org.hibernate.metamodel.source.binder.PluralAttributeElementNature; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement; + +/** + * @author Steve Ebersole + */ +public class OneToManyPluralAttributeElementSourceImpl implements OneToManyPluralAttributeElementSource { + private final XMLOneToManyElement oneToManyElement; + private final LocalBindingContext bindingContext; + + public OneToManyPluralAttributeElementSourceImpl( + XMLOneToManyElement oneToManyElement, + LocalBindingContext bindingContext) { + this.oneToManyElement = oneToManyElement; + this.bindingContext = bindingContext; + } + + @Override + public PluralAttributeElementNature getNature() { + return PluralAttributeElementNature.ONE_TO_MANY; + } + + @Override + public String getReferencedEntityName() { + return StringHelper.isNotEmpty( oneToManyElement.getEntityName() ) + ? oneToManyElement.getEntityName() + : bindingContext.qualifyClassName( oneToManyElement.getClazz() ); + } + + @Override + public boolean isNotFoundAnException() { + return oneToManyElement.getNotFound() == null + || ! "ignore".equals( oneToManyElement.getNotFound().value() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/PluralAttributeKeySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/PluralAttributeKeySourceImpl.java new file mode 100644 index 0000000000..4de22b245d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/PluralAttributeKeySourceImpl.java @@ -0,0 +1,104 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import java.util.List; + +import org.hibernate.metamodel.relational.ForeignKey; +import org.hibernate.metamodel.source.binder.AttributeSourceContainer; +import org.hibernate.metamodel.source.binder.PluralAttributeKeySource; +import org.hibernate.metamodel.source.binder.RelationalValueSource; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLKeyElement; + +/** + * @author Steve Ebersole + */ +public class PluralAttributeKeySourceImpl implements PluralAttributeKeySource { + private final XMLKeyElement keyElement; + + private final List valueSources; + + public PluralAttributeKeySourceImpl( + final XMLKeyElement keyElement, + final AttributeSourceContainer container) { + this.keyElement = keyElement; + + this.valueSources = Helper.buildValueSources( + new Helper.ValueSourcesAdapter() { + @Override + public String getContainingTableName() { + return null; + } + + @Override + public boolean isIncludedInInsertByDefault() { + return true; + } + + @Override + public boolean isIncludedInUpdateByDefault() { + return Helper.getBooleanValue( keyElement.isUpdate(), true ); + } + + @Override + public String getColumnAttribute() { + return keyElement.getColumnAttribute(); + } + + @Override + public String getFormulaAttribute() { + return null; + } + + @Override + public List getColumnOrFormulaElements() { + return keyElement.getColumn(); + } + }, + container.getLocalBindingContext() + ); + } + + @Override + public List getValueSources() { + return valueSources; + } + + @Override + public String getExplicitForeignKeyName() { + return keyElement.getForeignKey(); + } + + @Override + public ForeignKey.ReferentialAction getOnDeleteAction() { + return "cascade".equals( keyElement.getOnDelete() ) + ? ForeignKey.ReferentialAction.CASCADE + : ForeignKey.ReferentialAction.NO_ACTION; + } + + @Override + public String getReferencedEntityAttributeName() { + return keyElement.getPropertyRef(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/SetAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/SetAttributeSourceImpl.java new file mode 100644 index 0000000000..078b4fc57f --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/SetAttributeSourceImpl.java @@ -0,0 +1,172 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.source.hbm; + +import org.hibernate.FetchMode; +import org.hibernate.cfg.NotYetImplementedException; +import org.hibernate.engine.spi.CascadeStyle; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.LocalBindingContext; +import org.hibernate.metamodel.source.MappingException; +import org.hibernate.metamodel.source.binder.AttributeSourceContainer; +import org.hibernate.metamodel.source.binder.MetaAttributeSource; +import org.hibernate.metamodel.source.binder.Orderable; +import org.hibernate.metamodel.source.binder.PluralAttributeElementSource; +import org.hibernate.metamodel.source.binder.PluralAttributeKeySource; +import org.hibernate.metamodel.source.binder.PluralAttributeNature; +import org.hibernate.metamodel.source.binder.PluralAttributeSource; +import org.hibernate.metamodel.source.binder.Sortable; +import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLSetElement; + +/** + * @author Steve Ebersole + */ +public class SetAttributeSourceImpl implements PluralAttributeSource, Sortable, Orderable { + private XMLSetElement setElement; + private AttributeSourceContainer container; + + // todo : a lot of this could be consolidated with common JAXB interface for collection mappings and moved to a base class + + private final PluralAttributeKeySource keySource; + private final PluralAttributeElementSource elementSource; + + public SetAttributeSourceImpl(XMLSetElement setElement, AttributeSourceContainer container) { + this.setElement = setElement; + this.container = container; + + this.keySource = new PluralAttributeKeySourceImpl( setElement.getKey(), container ); + this.elementSource = interpretElementType( setElement ); + } + + private PluralAttributeElementSource interpretElementType(XMLSetElement setElement) { + if ( setElement.getElement() != null ) { + return new BasicPluralAttributeElementSourceImpl( setElement.getElement(), container.getLocalBindingContext() ); + } + else if ( setElement.getCompositeElement() != null ) { + return new CompositePluralAttributeElementSourceImpl( setElement.getCompositeElement(), container.getLocalBindingContext() ); + } + else if ( setElement.getOneToMany() != null ) { + return new OneToManyPluralAttributeElementSourceImpl( setElement.getOneToMany(), container.getLocalBindingContext() ); + } + else if ( setElement.getManyToMany() != null ) { + return new ManyToManyPluralAttributeElementSourceImpl( setElement.getManyToMany(), container.getLocalBindingContext() ); + } + else if ( setElement.getManyToAny() != null ) { + throw new NotYetImplementedException( "Support for many-to-any not yet implemented" ); +// return PluralAttributeElementNature.MANY_TO_ANY; + } + else { + throw new MappingException( + "Unexpected collection element type : " + setElement.getName(), + bindingContext().getOrigin() + ); + } + } + + private LocalBindingContext bindingContext() { + return container.getLocalBindingContext(); + } + + @Override + public PluralAttributeNature getPluralAttributeNature() { + return PluralAttributeNature.BAG; + } + + @Override + public PluralAttributeKeySource getKeySource() { + return keySource; + } + + @Override + public PluralAttributeElementSource getElementSource() { + return elementSource; + } + + @Override + public String getExplicitCollectionTableName() { + return setElement.getTable(); + } + + @Override + public boolean isInverse() { + return setElement.isInverse(); + } + + @Override + public String getName() { + return setElement.getName(); + } + + @Override + public boolean isSingular() { + return false; + } + + @Override + public String getPropertyAccessorName() { + return setElement.getAccess(); + } + + @Override + public boolean isIncludedInOptimisticLocking() { + return setElement.isOptimisticLock(); + } + + @Override + public Iterable metaAttributes() { + return Helper.buildMetaAttributeSources( setElement.getMeta() ); + } + + @Override + public Iterable getCascadeStyles() { + return Helper.interpretCascadeStyles( setElement.getCascade(), bindingContext() ); + } + + @Override + public FetchMode getFetchMode() { + return setElement.getFetch() == null + ? FetchMode.DEFAULT + : FetchMode.valueOf( setElement.getFetch().value() ); + } + + @Override + public boolean isSorted() { + return StringHelper.isNotEmpty( setElement.getSort() ); + } + + @Override + public String getComparatorName() { + return setElement.getSort(); + } + + @Override + public boolean isOrdered() { + return StringHelper.isNotEmpty( setElement.getOrderBy() ); + } + + @Override + public String getOrder() { + return setElement.getOrderBy(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java index 70b2eeda6a..1820aa72e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java @@ -52,6 +52,7 @@ import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.SessionFactoryBuilder; import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.source.MappingDefaults; import org.hibernate.metamodel.source.MetaAttributeContext; import org.hibernate.metamodel.source.MetadataImplementor; @@ -106,7 +107,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { */ private Map entityBindingMap = new HashMap(); - private Map collectionBindingMap = new HashMap(); + private Map collectionBindingMap = new HashMap(); private Map fetchProfiles = new HashMap(); private Map imports = new HashMap(); private Map typeDefs = new HashMap(); @@ -414,16 +415,16 @@ public class MetadataImpl implements MetadataImplementor, Serializable { entityBindingMap.put( entityName, entityBinding ); } - public AbstractPluralAttributeBinding getCollection(String collectionRole) { + public PluralAttributeBinding getCollection(String collectionRole) { return collectionBindingMap.get( collectionRole ); } @Override - public Iterable getCollectionBindings() { + public Iterable getCollectionBindings() { return collectionBindingMap.values(); } - public void addCollection(AbstractPluralAttributeBinding pluralAttributeBinding) { + public void addCollection(PluralAttributeBinding pluralAttributeBinding) { final String owningEntityName = pluralAttributeBinding.getContainer().getPathBase(); final String attributeName = pluralAttributeBinding.getAttribute().getName(); final String collectionRole = owningEntityName + '.' + attributeName; diff --git a/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java index 6ae929ff03..38ca40f772 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/internal/PersisterFactoryImpl.java @@ -23,6 +23,9 @@ */ package org.hibernate.persister.internal; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + import org.hibernate.HibernateException; import org.hibernate.MappingException; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; @@ -32,9 +35,10 @@ import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; -import org.hibernate.metamodel.source.MetadataImplementor; -import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; +import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; +import org.hibernate.metamodel.source.MetadataImplementor; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.spi.PersisterClassResolver; @@ -42,9 +46,6 @@ import org.hibernate.persister.spi.PersisterFactory; import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - /** * The standard Hibernate {@link PersisterFactory} implementation * @@ -197,10 +198,11 @@ public final class PersisterFactoryImpl implements PersisterFactory, ServiceRegi @Override @SuppressWarnings( {"unchecked"}) - public CollectionPersister createCollectionPersister(MetadataImplementor metadata, - AbstractPluralAttributeBinding collectionMetadata, - CollectionRegionAccessStrategy cacheAccessStrategy, - SessionFactoryImplementor factory) throws HibernateException { + public CollectionPersister createCollectionPersister( + MetadataImplementor metadata, + PluralAttributeBinding collectionMetadata, + CollectionRegionAccessStrategy cacheAccessStrategy, + SessionFactoryImplementor factory) throws HibernateException { Class persisterClass = collectionMetadata.getCollectionPersisterClass(); if ( persisterClass == null ) { persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getCollectionPersisterClass( collectionMetadata ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java b/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java index 3feda73f9a..349bc558a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/internal/StandardPersisterClassResolver.java @@ -28,9 +28,9 @@ import org.hibernate.mapping.JoinedSubclass; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; import org.hibernate.mapping.UnionSubclass; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.CollectionElementNature; import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.persister.collection.BasicCollectionPersister; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.OneToManyPersister; @@ -106,7 +106,7 @@ public class StandardPersisterClassResolver implements PersisterClassResolver { } @Override - public Class getCollectionPersisterClass(AbstractPluralAttributeBinding metadata) { + public Class getCollectionPersisterClass(PluralAttributeBinding metadata) { return metadata.getCollectionElement().getCollectionElementNature() == CollectionElementNature.ONE_TO_MANY ? oneToManyPersister() : basicCollectionPersister(); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterClassResolver.java b/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterClassResolver.java index d3660fb255..f82123e71e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterClassResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterClassResolver.java @@ -25,8 +25,8 @@ package org.hibernate.persister.spi; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.service.Service; @@ -80,5 +80,5 @@ public interface PersisterClassResolver extends Service { * * @return The collection persister class to use */ - Class getCollectionPersisterClass(AbstractPluralAttributeBinding metadata); + Class getCollectionPersisterClass(PluralAttributeBinding metadata); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterFactory.java b/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterFactory.java index 15dfd4cb3e..4716385032 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/spi/PersisterFactory.java @@ -31,9 +31,9 @@ import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; -import org.hibernate.metamodel.source.MetadataImplementor; import org.hibernate.metamodel.binding.EntityBinding; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; +import org.hibernate.metamodel.source.MetadataImplementor; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.service.Service; @@ -122,7 +122,7 @@ public interface PersisterFactory extends Service { */ public CollectionPersister createCollectionPersister( MetadataImplementor metadata, - AbstractPluralAttributeBinding model, + PluralAttributeBinding model, CollectionRegionAccessStrategy cacheAccessStrategy, SessionFactoryImplementor factory) throws HibernateException; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicCollectionBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicCollectionBindingTests.java new file mode 100644 index 0000000000..c5cf91f295 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicCollectionBindingTests.java @@ -0,0 +1,91 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.binding; + +import org.hibernate.metamodel.MetadataSourceProcessingOrder; +import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.source.internal.MetadataImpl; +import org.hibernate.service.ServiceRegistryBuilder; +import org.hibernate.service.internal.BasicServiceRegistryImpl; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; + +/** + * @author Steve Ebersole + */ +public class BasicCollectionBindingTests extends BaseUnitTestCase { + private BasicServiceRegistryImpl serviceRegistry; + + @Before + public void setUp() { + serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry(); + } + + @After + public void tearDown() { + serviceRegistry.destroy(); + } + +// @Test +// public void testAnnotations() { +// doTest( MetadataSourceProcessingOrder.ANNOTATIONS_FIRST ); +// } + + @Test + public void testHbm() { + doTest( MetadataSourceProcessingOrder.HBM_FIRST ); + } + + private void doTest(MetadataSourceProcessingOrder processingOrder) { + MetadataSources sources = new MetadataSources( serviceRegistry ); +// sources.addAnnotatedClass( EntityWithBasicCollections.class ); + sources.addResource( "org/hibernate/metamodel/binding/EntityWithBasicCollections.hbm.xml" ); + MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata(); + + final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithBasicCollections.class.getName() ); + assertNotNull( entityBinding ); + + PluralAttributeBinding bagBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theBag" ); + assertNotNull( bagBinding ); + assertSame( bagBinding, entityBinding.locateAttributeBinding( "theBag" ) ); + assertNotNull( bagBinding.getCollectionTable() ); + assertEquals( CollectionElementNature.BASIC, bagBinding.getCollectionElement().getCollectionElementNature() ); + assertEquals( String.class.getName(), bagBinding.getCollectionElement().getHibernateTypeDescriptor().getJavaTypeName() ); + + PluralAttributeBinding setBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theSet" ); + assertNotNull( setBinding ); + assertSame( setBinding, entityBinding.locateAttributeBinding( "theSet" ) ); + assertNotNull( setBinding.getCollectionTable() ); + assertEquals( CollectionElementNature.BASIC, setBinding.getCollectionElement().getCollectionElementNature() ); + assertEquals( String.class.getName(), setBinding.getCollectionElement().getHibernateTypeDescriptor().getJavaTypeName() ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithBasicCollections.hbm.xml b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithBasicCollections.hbm.xml new file mode 100644 index 0000000000..3eb4ca7633 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithBasicCollections.hbm.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithCollection.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithBasicCollections.java similarity index 65% rename from hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithCollection.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithBasicCollections.java index 9ada02b520..6a23ccea39 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithCollection.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithBasicCollections.java @@ -23,24 +23,33 @@ */ package org.hibernate.metamodel.binding; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.Id; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.Set; /** * @author Gail Badner + * @author Steve Ebersole */ -public class EntityWithCollection { +@Entity +public class EntityWithBasicCollections { private Long id; private String name; - Set otherNames = new HashSet(); + private Collection theBag = new ArrayList(); + private Set theSet = new HashSet(); - public EntityWithCollection() { + public EntityWithBasicCollections() { } - public EntityWithCollection(String name) { + public EntityWithBasicCollections(String name) { this.name = name; } + @Id public Long getId() { return id; } @@ -57,11 +66,21 @@ public class EntityWithCollection { this.name = name; } - public Set getOtherNames() { - return otherNames; + @ElementCollection + public Collection getTheBag() { + return theBag; } - public void setOtherNames(Set otherNames) { - this.otherNames = otherNames; + public void setTheBag(Collection theBag) { + this.theBag = theBag; + } + + @ElementCollection + public Set getTheSet() { + return theSet; + } + + public void setTheSet(Set theSet) { + this.theSet = theSet; } } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithCollection.hbm.xml b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithCollection.hbm.xml deleted file mode 100644 index 1fec13b714..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/EntityWithCollection.hbm.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/GoofyPersisterClassProvider.java b/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/GoofyPersisterClassProvider.java index c11f66ffff..29f2b031ad 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/GoofyPersisterClassProvider.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cfg/persister/GoofyPersisterClassProvider.java @@ -45,8 +45,8 @@ import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.CollectionMetadata; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; @@ -76,7 +76,7 @@ public class GoofyPersisterClassProvider implements PersisterClassResolver { } @Override - public Class getCollectionPersisterClass(AbstractPluralAttributeBinding metadata) { + public Class getCollectionPersisterClass(PluralAttributeBinding metadata) { return NoopCollectionPersister.class; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/PersisterClassProviderTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/PersisterClassProviderTest.java index 24c43bbdee..8ea49b15c9 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/PersisterClassProviderTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/PersisterClassProviderTest.java @@ -20,13 +20,12 @@ */ package org.hibernate.ejb.test.ejb3configuration; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceException; import java.io.Serializable; import java.util.Comparator; import java.util.Map; -import javax.persistence.EntityManagerFactory; -import javax.persistence.PersistenceException; - import org.hibernate.EntityMode; import org.hibernate.HibernateException; import org.hibernate.LockMode; @@ -45,11 +44,11 @@ import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.metadata.ClassMetadata; import org.hibernate.metamodel.binding.EntityBinding; -import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; -import org.hibernate.persister.internal.PersisterClassResolverInitiator; -import org.hibernate.persister.spi.PersisterClassResolver; +import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.persister.internal.PersisterClassResolverInitiator; +import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.type.Type; @@ -92,7 +91,7 @@ public class PersisterClassProviderTest extends junit.framework.TestCase { } @Override - public Class getCollectionPersisterClass(AbstractPluralAttributeBinding metadata) { + public Class getCollectionPersisterClass(PluralAttributeBinding metadata) { return null; } }