From 3244caa6cd72875c6b898e8b811f62876cb8bb8d Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Thu, 30 May 2013 13:43:23 -0700 Subject: [PATCH] HHH-6515 HHH-6516 : Support for map key annotations --- .../hibernate/metamodel/internal/Binder.java | 111 ++++++++++------ .../internal/EntityHierarchyHelper.java | 26 +++- .../metamodel/internal/SourceIndex.java | 78 +++++++++++- ...bstractPluralAttributeIndexSourceImpl.java | 80 ++++++++++++ ...BasicPluralAttributeElementSourceImpl.java | 1 - .../BasicPluralAttributeIndexSourceImpl.java | 56 +++------ .../IndexedPluralAttributeSourceImpl.java | 87 ++++++++++++- .../MapKeyPluralAttributeIndexSourceImpl.java | 76 +++++++++++ .../PluralAttributeSourceImpl.java | 7 +- ...uentialPluralAttributeIndexSourceImpl.java | 18 +++ .../attribute/AssociationAttribute.java | 10 +- .../annotations/attribute/BasicAttribute.java | 10 +- .../attribute/PluralAssociationAttribute.java | 39 ++++-- .../type/AbstractAttributeTypeResolver.java | 72 ++++++++--- .../type/AttributeTypeResolverImpl.java | 87 ------------- .../type/EnumeratedTypeResolver.java | 88 ++++++++----- .../attribute/type/HibernateTypeResolver.java | 118 ++++++++++++++++++ .../attribute/type/LobTypeResolver.java | 60 +++++---- .../attribute/type/TemporalTypeResolver.java | 78 ++++++++---- .../AbstractPluralAttributeSourceImpl.java | 3 +- .../internal/source/hbm/ArraySourceImpl.java | 10 ++ ...mpositePluralAttributeIndexSourceImpl.java | 12 ++ .../internal/source/hbm/ListSourceImpl.java | 10 ++ .../internal/source/hbm/MapKeySourceImpl.java | 8 +- .../internal/source/hbm/MapSourceImpl.java | 10 ++ ...oManyPluralAttributeElementSourceImpl.java | 2 +- ...uentialPluralAttributeIndexSourceImpl.java | 7 +- .../AttributeSourceResolutionContext.java | 33 +++++ .../BasicPluralAttributeIndexSource.java | 1 - ...tyAttributePluralAttributeIndexSource.java | 35 ++++++ .../source/IndexedPluralAttributeSource.java | 4 +- .../PluralAttributeElementSourceResolver.java | 7 +- .../source/PluralAttributeIndexSource.java | 19 +++ .../PluralAttributeIndexSourceResolver.java | 31 +++++ .../CollectionElementTest.java | 3 - .../mapkey/MapKeyEnumeratedTest.java | 1 - 36 files changed, 979 insertions(+), 319 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AbstractPluralAttributeIndexSourceImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/MapKeyPluralAttributeIndexSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AttributeTypeResolverImpl.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/HibernateTypeResolver.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/AttributeSourceResolutionContext.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/EntityAttributePluralAttributeIndexSource.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSourceResolver.java diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java index be5b266062..12a06bf9bc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/Binder.java @@ -131,6 +131,7 @@ import org.hibernate.metamodel.spi.source.CompositePluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.ConstraintSource; import org.hibernate.metamodel.spi.source.DerivedValueSource; import org.hibernate.metamodel.spi.source.DiscriminatorSource; +import org.hibernate.metamodel.spi.source.EntityAttributePluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.EntityHierarchy; import org.hibernate.metamodel.spi.source.EntitySource; import org.hibernate.metamodel.spi.source.FilterSource; @@ -233,10 +234,11 @@ public class Binder { * @param entityHierarchies The entity hierarchies resolved from mappings */ public void addEntityHierarchies(final Iterable entityHierarchies) { + LocalBindingContextExecutor executor = new LocalBindingContextExecutor() { @Override public void execute(LocalBindingContextExecutionContext bindingContextContext) { - sourceIndex.indexEntitySource( bindingContextContext.getEntitySource() ); + sourceIndex.indexEntitySource( bindingContextContext.getRootEntitySource(), bindingContextContext.getEntitySource() ); createEntityBinding( bindingContextContext.getSuperEntityBinding(), bindingContextContext.getEntitySource() @@ -2031,6 +2033,13 @@ public class Binder { } } + private void bindEntityAttributePluralAttributeIndex( + final IndexedPluralAttributeBinding attributeBinding, + final EntityAttributePluralAttributeIndexSource indexSource, + final String defaultIndexJavaTypeName) { + throw new NotYetImplementedException( "Plural attribute index that is an attribute of the referenced entity is not supported yet." ); + } + private void bindBasicCollectionIndex( final IndexedPluralAttributeBinding attributeBinding, final BasicPluralAttributeIndexSource indexSource, @@ -2053,7 +2062,7 @@ public class Binder { typeHelper.bindHibernateTypeDescriptor( indexBinding.getHibernateTypeDescriptor(), - indexSource.explicitHibernateTypeSource(), + indexSource.getTypeInformation(), defaultIndexJavaTypeName ); typeHelper.bindJdbcDataType( @@ -2069,9 +2078,11 @@ public class Binder { private void bindCompositeCollectionIndex( final CompositePluralAttributeIndexBinding indexBinding, - final CompositePluralAttributeIndexSource indexSource, + final IndexedPluralAttributeSource indexedPluralAttributeSource, final String defaultIndexJavaTypeName) { final PluralAttributeBinding pluralAttributeBinding = indexBinding.getIndexedPluralAttributeBinding(); + final CompositePluralAttributeIndexSource indexSource = + (CompositePluralAttributeIndexSource) indexedPluralAttributeSource.getIndexSource(); ValueHolder> defaultElementJavaClassReference = null; // Create the aggregate type // TODO: aggregateName should be set to elementSource.getPath() (which is currently not implemented) @@ -2105,6 +2116,19 @@ public class Binder { ); bindAttributes( compositeAttributeBindingContainer, indexSource ); + /* + final boolean isAssociation = pluralAttributeBinding.getPluralAttributeElementBinding().getNature().isAssociation(); + switch( pluralAttributeBinding.getPluralAttributeElementBinding().getNature() ) { + case ONE_TO_MANY: + OneToManyPluralAttributeElementSource elementSource = + (OneToManyPluralAttributeElementSource) indexedPluralAttributeSource.getElementSource(); + final EntityBinding referencedEntityBinding = locateEntityBinding( elementSource.getReferencedEntityName() ); + for ( final AttributeSource attributeSource : indexSource.attributeSources() ) { + bindAttribute( compositeAttributeBindingContainer, attributeSource ); + } + } + */ + Type resolvedType = metadata.getTypeResolver().getTypeFactory().component( new ComponentMetamodel( compositeAttributeBindingContainer, false, false ) ); @@ -2331,39 +2355,49 @@ public class Binder { final ReflectedCollectionJavaTypes reflectedCollectionJavaTypes) { final String defaultCollectionIndexJavaTypeName = HibernateTypeHelper.defaultCollectionIndexJavaTypeName( reflectedCollectionJavaTypes ); - switch ( attributeSource.getIndexSource().getNature() ) { - case BASIC: { - bindBasicCollectionIndex( - attributeBinding, - (BasicPluralAttributeIndexSource) attributeSource.getIndexSource(), - defaultCollectionIndexJavaTypeName - ); - break; - } - case AGGREGATE: { - bindCompositeCollectionIndex( - (CompositePluralAttributeIndexBinding) attributeBinding.getPluralAttributeIndexBinding(), - (CompositePluralAttributeIndexSource) attributeSource.getIndexSource(), - defaultCollectionIndexJavaTypeName - ); - break; - } - default: { - throw new NotYetImplementedException( - String.format( - "%s collection indexes are not supported yet.", - attributeSource.getIndexSource().getNature() - ) - ); - } + final PluralAttributeIndexSource indexSource = attributeSource.getIndexSource(); + if ( indexSource.isReferencedEntityAttribute() ) { + bindEntityAttributePluralAttributeIndex( + attributeBinding, + (EntityAttributePluralAttributeIndexSource) indexSource, + defaultCollectionIndexJavaTypeName + ); } - if ( attributeBinding.getPluralAttributeElementBinding() - .getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY ) { - for ( RelationalValueBinding relationalValueBinding : attributeBinding.getPluralAttributeIndexBinding().getRelationalValueBindings() ) { - if ( Column.class.isInstance( relationalValueBinding.getValue() ) ) { - // TODO: fix this when column nullability is refactored - Column column = (Column) relationalValueBinding.getValue(); - column.setNullable( true ); + else { + switch ( attributeSource.getIndexSource().getNature() ) { + case BASIC: { + bindBasicCollectionIndex( + attributeBinding, + (BasicPluralAttributeIndexSource) attributeSource.getIndexSource(), + defaultCollectionIndexJavaTypeName + ); + break; + } + case AGGREGATE: { + bindCompositeCollectionIndex( + (CompositePluralAttributeIndexBinding) attributeBinding.getPluralAttributeIndexBinding(), + attributeSource, + defaultCollectionIndexJavaTypeName + ); + break; + } + default: { + throw new NotYetImplementedException( + String.format( + "%s collection indexes are not supported yet.", + attributeSource.getIndexSource().getNature() + ) + ); + } + } + if ( attributeBinding.getPluralAttributeElementBinding() + .getNature() == PluralAttributeElementBinding.Nature.ONE_TO_MANY ) { + for ( RelationalValueBinding relationalValueBinding : attributeBinding.getPluralAttributeIndexBinding().getRelationalValueBindings() ) { + if ( Column.class.isInstance( relationalValueBinding.getValue() ) ) { + // TODO: fix this when column nullability is refactored + Column column = (Column) relationalValueBinding.getValue(); + column.setNullable( true ); + } } } } @@ -3240,9 +3274,8 @@ public class Binder { private static void bindIndexedCollectionTablePrimaryKey( final IndexedPluralAttributeBinding attributeBinding) { - final PrimaryKey primaryKey = attributeBinding.getPluralAttributeKeyBinding() - .getCollectionTable() - .getPrimaryKey(); + final TableSpecification collectionTable = attributeBinding.getPluralAttributeKeyBinding().getCollectionTable(); + final PrimaryKey primaryKey = collectionTable.getPrimaryKey(); final List keyRelationalValueBindings = attributeBinding.getPluralAttributeKeyBinding().getRelationalValueBindings(); final PluralAttributeIndexBinding indexBinding = attributeBinding.getPluralAttributeIndexBinding(); @@ -3250,7 +3283,7 @@ public class Binder { primaryKey.addColumn( (Column) keyRelationalValueBinding.getValue() ); } for ( RelationalValueBinding relationalValueBinding : indexBinding.getRelationalValueBindings() ) { - if ( !relationalValueBinding.isDerived() ) { + if ( !relationalValueBinding.isDerived() && relationalValueBinding.getTable().equals( collectionTable ) ) { primaryKey.addColumn( (Column) relationalValueBinding.getValue() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityHierarchyHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityHierarchyHelper.java index 4c81aeb667..8b0a9cb4f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityHierarchyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityHierarchyHelper.java @@ -92,6 +92,7 @@ public class EntityHierarchyHelper { applyToSubEntities( executionContext.getEntityBinding(), rootEntitySource, + rootEntitySource, subEntityExecutor ); } } @@ -127,27 +128,28 @@ public class EntityHierarchyHelper { bindingContexts.push( rootEntitySource.getLocalBindingContext() ); } - private void applyToSubEntities( final EntityBinding entityBinding, + final RootEntitySource rootEntitySource, final EntitySource entitySource, final LocalBindingContextExecutor subEntityExecutor) { for ( final SubclassEntitySource subEntitySource : entitySource.subclassEntitySources() ) { - applyToSubEntity( entityBinding, subEntitySource, subEntityExecutor ); + applyToSubEntity( entityBinding, rootEntitySource, subEntitySource, subEntityExecutor ); } } private void applyToSubEntity( final EntityBinding superEntityBinding, + final RootEntitySource rootEntitySource, final EntitySource entitySource, final LocalBindingContextExecutor subEntityExecutor) { final LocalBindingContext bindingContext = entitySource.getLocalBindingContext(); bindingContexts.push( bindingContext ); try { LocalBindingContextExecutionContext executionContext = - new LocalBindingContextExecutionContextImpl( entitySource, superEntityBinding ); + new LocalBindingContextExecutionContextImpl( rootEntitySource, entitySource, superEntityBinding ); subEntityExecutor.execute( executionContext ); - applyToSubEntities( executionContext.getEntityBinding(), entitySource, subEntityExecutor ); + applyToSubEntities( executionContext.getEntityBinding(), rootEntitySource, entitySource, subEntityExecutor ); } finally { bindingContexts.pop(); @@ -155,22 +157,38 @@ public class EntityHierarchyHelper { } public interface LocalBindingContextExecutionContext { + RootEntitySource getRootEntitySource(); EntitySource getEntitySource(); EntityBinding getEntityBinding(); EntityBinding getSuperEntityBinding(); } private class LocalBindingContextExecutionContextImpl implements LocalBindingContextExecutionContext { + private final RootEntitySource rootEntitySource; private final EntitySource entitySource; private final EntityBinding superEntityBinding; private LocalBindingContextExecutionContextImpl( + RootEntitySource rootEntitySource, + EntityBinding superEntityBinding) { + this.rootEntitySource = rootEntitySource; + this.entitySource = rootEntitySource; + this.superEntityBinding = superEntityBinding; + } + + private LocalBindingContextExecutionContextImpl( + RootEntitySource rootEntitySource, EntitySource entitySource, EntityBinding superEntityBinding) { + this.rootEntitySource = rootEntitySource; this.entitySource = entitySource; this.superEntityBinding = superEntityBinding; } + @Override + public RootEntitySource getRootEntitySource() { + return rootEntitySource; + } @Override public EntitySource getEntitySource() { return entitySource; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/SourceIndex.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/SourceIndex.java index 12760e07ea..6c6fc0289c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/SourceIndex.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/SourceIndex.java @@ -39,11 +39,12 @@ import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.source.AggregatedCompositeIdentifierSource; import org.hibernate.metamodel.spi.source.AttributeSource; +import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext; import org.hibernate.metamodel.spi.source.ComponentAttributeSource; import org.hibernate.metamodel.spi.source.EntitySource; import org.hibernate.metamodel.spi.source.IdentifierSource; +import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource; import org.hibernate.metamodel.spi.source.NonAggregatedCompositeIdentifierSource; -import org.hibernate.metamodel.spi.source.PluralAttributeElementSourceResolver; import org.hibernate.metamodel.spi.source.PluralAttributeSource; import org.hibernate.metamodel.spi.source.RootEntitySource; import org.hibernate.metamodel.spi.source.SimpleIdentifierSource; @@ -66,9 +67,13 @@ public class SourceIndex { private final Map mappedByAttributeKeysByOwnerAttributeKeys = new HashMap(); - public void indexEntitySource(final EntitySource entitySource) { + public void indexRootEntitySource(final RootEntitySource entitySource) { + indexEntitySource( entitySource, entitySource ); + } + + public void indexEntitySource(final RootEntitySource rootEntitySource, final EntitySource entitySource) { String entityName = entitySource.getEntityName(); - EntitySourceIndex entitySourceIndex = new EntitySourceIndex( this, entitySource ); + EntitySourceIndex entitySourceIndex = new EntitySourceIndex( this, rootEntitySource, entitySource ); entitySourceIndexByEntityName.put( entityName, entitySourceIndex ); log.debugf( "Mapped entity source \"%s\"", entityName ); indexAttributes( entitySourceIndex ); @@ -106,6 +111,10 @@ public class SourceIndex { return entitySourceIndexByEntityName.get( entityName ).entitySource; } + private EntitySourceIndex entitySourceIndex(String entityName) { + return entitySourceIndexByEntityName.get( entityName ); + } + private void indexAttributes(EntitySourceIndex entitySourceIndex) { final String emptyString = ""; if ( entitySourceIndex.entitySource instanceof RootEntitySource ) { @@ -267,6 +276,7 @@ public class SourceIndex { private static class EntitySourceIndex { private final SourceIndex sourceIndex; + private final RootEntitySource rootEntitySource; private final EntitySource entitySource; private final Map> identifierAttributeSourcesByNature = new HashMap>(); @@ -281,8 +291,16 @@ public class SourceIndex { private final Map inversePluralAttributeSourcesByKey = new LinkedHashMap(); - private EntitySourceIndex(final SourceIndex sourceIndex, final EntitySource entitySource) { + private EntitySourceIndex(final SourceIndex sourceIndex, final RootEntitySource rootEntitySource) { + this( sourceIndex, rootEntitySource, rootEntitySource ); + } + + private EntitySourceIndex( + final SourceIndex sourceIndex, + final RootEntitySource rootEntitySource, + final EntitySource entitySource) { this.sourceIndex = sourceIndex; + this.rootEntitySource = rootEntitySource; this.entitySource = entitySource; } @@ -375,12 +393,20 @@ public class SourceIndex { // so it needs to be resolved. // TODO: this should really just resolve PluralAttributeElementSource.Nature pluralAttributeSource.resolvePluralAttributeElementSource( - new PluralAttributeElementSourceResolver.PluralAttributeElementSourceResolutionContext() { + new AttributeSourceResolutionContext() { + @Override + public IdentifierSource resolveIdentifierSource(String entityName) { + return sourceIndex.entitySourceIndex( entityName ).rootEntitySource.getIdentifierSource(); + } + @Override public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) { AttributeSourceKey ownerAttributeSourceKey = new AttributeSourceKey( referencedEntityName, mappedBy ); AttributeSource ownerAttributeSource = sourceIndex.attributeSource( referencedEntityName, mappedBy ); // TODO: is this needed? if so, make more obvious and rename method. + // If it's not needed, then resolvePluralAttributeElementSource() and + // and resolvePluralAttributeIndexSource() can use the same + // AttributeSourceResolutionContext. sourceIndex.addMappedByAssociationByOwnerAssociation( ownerAttributeSourceKey, pluralAttributeSourceKey @@ -388,9 +414,49 @@ public class SourceIndex { return ownerAttributeSource; } } - ); + ); + } + if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) { + IndexedPluralAttributeSource indexedPluralAttributeSource = + (IndexedPluralAttributeSource) pluralAttributeSource; + indexedPluralAttributeSource.resolvePluralAttributeIndexSource( + new AttributeSourceResolutionContext() { + @Override + public IdentifierSource resolveIdentifierSource(String entityName) { + return sourceIndex.entitySourceIndex( entityName ).rootEntitySource.getIdentifierSource(); + } + + @Override + public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) {; + return sourceIndex.attributeSource( referencedEntityName, mappedBy ); + } + } + ); } } + + for ( Map.Entry entry : nonInversePluralAttributeSourcesByKey.entrySet() ) { + final AttributeSourceKey pluralAttributeSourceKey = entry.getKey(); + final PluralAttributeSource pluralAttributeSource = entry.getValue(); + if ( IndexedPluralAttributeSource.class.isInstance( pluralAttributeSource ) ) { + IndexedPluralAttributeSource indexedPluralAttributeSource = + (IndexedPluralAttributeSource) pluralAttributeSource; + indexedPluralAttributeSource.resolvePluralAttributeIndexSource( + new AttributeSourceResolutionContext() { + @Override + public IdentifierSource resolveIdentifierSource(String entityName) { + return sourceIndex.entitySourceIndex( entityName ).rootEntitySource.getIdentifierSource(); + } + + @Override + public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy) {; + return sourceIndex.attributeSource( referencedEntityName, mappedBy ); + } + } + ); + } + } + final Map unresolvedSingularAttributeSourceMap = singularAttributeSourcesByNature.get( null ); if ( unresolvedSingularAttributeSourceMap != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AbstractPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AbstractPluralAttributeIndexSourceImpl.java new file mode 100644 index 0000000000..e1567bd151 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AbstractPluralAttributeIndexSourceImpl.java @@ -0,0 +1,80 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.internal.source.annotations; + +import java.util.Map; + +import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; +import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; + +/** + * @author Gail Badner + */ +public abstract class AbstractPluralAttributeIndexSourceImpl implements PluralAttributeIndexSource { + private final PluralAssociationAttribute attribute; + + public AbstractPluralAttributeIndexSourceImpl(PluralAssociationAttribute attribute) { + this.attribute = attribute; + } + + @Override + public ExplicitHibernateTypeSource getTypeInformation() { + return new ExplicitHibernateTypeSource() { + @Override + public String getName() { + return attribute.getIndexTypeResolver().getExplicitHibernateTypeName(); + } + + @Override + public Map getParameters() { + return attribute.getIndexTypeResolver().getExplicitHibernateTypeParameters(); + } + }; + } + + @Override + public boolean isReferencedEntityAttribute() { + return false; + } + + @Override + public boolean areValuesIncludedInInsertByDefault() { + return false; + } + + @Override + public boolean areValuesIncludedInUpdateByDefault() { + return false; + } + + @Override + public boolean areValuesNullableByDefault() { + return false; + } + + protected PluralAssociationAttribute pluralAssociationAttribute() { + return attribute; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java index f2407774b9..56a6c244b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeElementSourceImpl.java @@ -3,7 +3,6 @@ package org.hibernate.metamodel.internal.source.annotations; import java.util.ArrayList; import java.util.List; -import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.Column; import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeIndexSourceImpl.java index 6383601957..1ebf53f693 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/BasicPluralAttributeIndexSourceImpl.java @@ -23,10 +23,8 @@ */ package org.hibernate.metamodel.internal.source.annotations; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import org.jboss.jandex.AnnotationInstance; @@ -38,23 +36,34 @@ import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource; -import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.RelationalValueSource; /** * @author Strong Liu */ -public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource { - private final PluralAssociationAttribute attribute; +public class BasicPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements BasicPluralAttributeIndexSource { private final IndexedPluralAttributeSourceImpl indexedPluralAttributeSource; - private final List relationalValueSources = new ArrayList( 1 ); + private final List relationalValueSources; private final Binder.DefaultNamingStrategy defaultNamingStrategy; public BasicPluralAttributeIndexSourceImpl( IndexedPluralAttributeSourceImpl indexedPluralAttributeSource, PluralAssociationAttribute attribute, Binder.DefaultNamingStrategy defaultNamingStrategy) { - this.attribute = attribute; + this( indexedPluralAttributeSource, attribute, defaultNamingStrategy, createRelationalValueSources( attribute ) ); + } + + public BasicPluralAttributeIndexSourceImpl( + IndexedPluralAttributeSourceImpl indexedPluralAttributeSource, + PluralAssociationAttribute attribute, + Binder.DefaultNamingStrategy defaultNamingStrategy, + List relationalValueSources) { + super( attribute ); this.indexedPluralAttributeSource = indexedPluralAttributeSource; + this.relationalValueSources = relationalValueSources; + this.defaultNamingStrategy = defaultNamingStrategy; + } + + private static List createRelationalValueSources(PluralAssociationAttribute attribute) { AnnotationInstance columnAnnotation = JandexHelper.getSingleAnnotation( attribute.annotations(), HibernateDotNames.INDEX_COLUMN @@ -72,10 +81,8 @@ public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttribute ); } Column indexColumn = new Column( columnAnnotation ); - relationalValueSources.add( new ColumnValuesSourceImpl( indexColumn ) ); - this.defaultNamingStrategy = defaultNamingStrategy; + return Collections.singletonList( (RelationalValueSource) new ColumnValuesSourceImpl( indexColumn ) ); } - @Override public PluralAttributeIndexBinding.Nature getNature() { return PluralAttributeIndexBinding.Nature.BASIC; @@ -86,38 +93,9 @@ public class BasicPluralAttributeIndexSourceImpl implements BasicPluralAttribute return Collections.singletonList( defaultNamingStrategy ); } - @Override - public ExplicitHibernateTypeSource explicitHibernateTypeSource() { - return new ExplicitHibernateTypeSource() { - @Override - public String getName() { - return "integer"; - } - - @Override - public Map getParameters() { - return null; - } - }; - } - @Override public List relationalValueSources() { return relationalValueSources; } - @Override - public boolean areValuesIncludedInInsertByDefault() { - return false; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return false; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IndexedPluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IndexedPluralAttributeSourceImpl.java index 8a77957729..4af8b1ed57 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IndexedPluralAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/IndexedPluralAttributeSourceImpl.java @@ -26,27 +26,30 @@ package org.hibernate.metamodel.internal.source.annotations; import java.util.EnumSet; import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.JandexAntTask; -import org.hibernate.cfg.NamingStrategy; import org.hibernate.cfg.NotYetImplementedException; -import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.internal.Binder; import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; import org.hibernate.metamodel.internal.source.annotations.entity.ConfiguredClass; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.source.AttributeSource; +import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext; +import org.hibernate.metamodel.spi.source.ComponentAttributeSource; +import org.hibernate.metamodel.spi.source.IdentifierSource; import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource; import org.hibernate.metamodel.spi.source.MappingException; import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; +import org.hibernate.metamodel.spi.source.SimpleIdentifierSource; +import org.hibernate.metamodel.spi.source.SingularAttributeSource; /** * @author Strong Liu */ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl implements IndexedPluralAttributeSource { - private final PluralAttributeIndexSource indexSource; + private PluralAttributeIndexSource indexSource; private final static EnumSet VALID_NATURES = EnumSet.of( MappedAttribute.Nature.MANY_TO_MANY, MappedAttribute.Nature.ONE_TO_MANY, @@ -74,8 +77,8 @@ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl indexSource = new SequentialPluralAttributeIndexSourceImpl( this, attribute, defaultNamingStrategy ); } else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY ) ) { - // basic - throw new NotYetImplementedException( "@MapKey is not supported yet." ); + // need to wait until the ID or attribute source can be resolved. + indexSource = null; } else if ( attribute.annotations().containsKey( JPADotNames.MAP_KEY_COLUMN ) ) { final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() { @@ -130,6 +133,78 @@ public class IndexedPluralAttributeSourceImpl extends PluralAttributeSourceImpl } } + @Override + public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext attributeSourceResolutionContext) { + if ( indexSource == null ) { + if ( pluralAssociationAttribute().annotations().containsKey( JPADotNames.MAP_KEY ) ) { + indexSource = resolveMapKeyPluralAttributeIndexSource( attributeSourceResolutionContext ); + } + else { + throw new NotYetImplementedException( "caonnot resolve index source." ); + } + } + return indexSource; + } + + private PluralAttributeIndexSource resolveMapKeyPluralAttributeIndexSource(AttributeSourceResolutionContext attributeSourceResolutionContext) { + final AnnotationInstance mapKeyAnnotation = + JandexHelper.getSingleAnnotation( pluralAssociationAttribute().annotations(), JPADotNames.MAP_KEY ); + final String attributeName = JandexHelper.getValue( mapKeyAnnotation, "name", String.class ); + final PluralAttributeIndexSource innerIndexSource; + if ( attributeName == null ) { + IdentifierSource identifierSource = attributeSourceResolutionContext.resolveIdentifierSource( + pluralAssociationAttribute().getReferencedEntityType() + ); + switch ( identifierSource.getNature() ) { + case SIMPLE: + innerIndexSource = new BasicPluralAttributeIndexSourceImpl( + this, + pluralAssociationAttribute(), + null, + ( (SimpleIdentifierSource) identifierSource ).getIdentifierAttributeSource().relationalValueSources() ); + break; + default: + throw new NotYetImplementedException( "Only simple IDs are supported for @MapKey" ); + } + } + else { + AttributeSource attributeSource = attributeSourceResolutionContext.resolveAttributeSource( + pluralAssociationAttribute().getReferencedEntityType(), + attributeName + ); + if ( ! attributeSource.isSingular() ) { + throw new MappingException( + String.format( + "Plural attribute index [%s.%s] is not a singular attribute.", + pluralAssociationAttribute().getReferencedEntityType(), + attributeName + ), + pluralAssociationAttribute().getContext().getOrigin() + ); + } + final SingularAttributeSource mapKeyAttributeSource = (SingularAttributeSource) attributeSource; + switch ( mapKeyAttributeSource.getNature() ) { + case BASIC: + innerIndexSource = new BasicPluralAttributeIndexSourceImpl( + this, + pluralAssociationAttribute(), + null, + mapKeyAttributeSource.relationalValueSources() ); + break; + case COMPOSITE: + innerIndexSource = new CompositePluralAttributeIndexSourceImpl( + pluralAssociationAttribute(), + ( ( ComponentAttributeSource) attributeSource ).attributeSources(), + null + ); + break; + default: + throw new NotYetImplementedException( "Only basic plural attribute index sources are supported for @MapKey" ); + } + } + return new MapKeyPluralAttributeIndexSourceImpl( pluralAssociationAttribute(), innerIndexSource, attributeName ); + } + @Override public PluralAttributeIndexSource getIndexSource() { return indexSource; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/MapKeyPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/MapKeyPluralAttributeIndexSourceImpl.java new file mode 100644 index 0000000000..9809a4b9c4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/MapKeyPluralAttributeIndexSourceImpl.java @@ -0,0 +1,76 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.internal.source.annotations; + +import java.util.List; + +import org.hibernate.metamodel.internal.Binder; +import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.source.AttributeSource; +import org.hibernate.metamodel.spi.source.EntityAttributePluralAttributeIndexSource; +import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; +import org.hibernate.metamodel.spi.source.RelationalValueSource; + +/** + * @author Gail Badner + */ +public class MapKeyPluralAttributeIndexSourceImpl extends AbstractPluralAttributeIndexSourceImpl implements EntityAttributePluralAttributeIndexSource { + private final PluralAttributeIndexSource pluralAttributeIndexSource; + private final String attributeName; + + public MapKeyPluralAttributeIndexSourceImpl( + PluralAssociationAttribute attribute, + PluralAttributeIndexSource pluralAttributeIndexSource, + String attributeName) { + super( attribute ); + this.pluralAttributeIndexSource = pluralAttributeIndexSource; + this.attributeName = attributeName; + } + + @Override + public String getAttributeName() { + return attributeName; + } + + @Override + public PluralAttributeIndexBinding.Nature getNature() { + return pluralAttributeIndexSource.getNature(); + } + + @Override + public List getDefaultNamingStrategies() { + return pluralAttributeIndexSource.getDefaultNamingStrategies(); + } + + @Override + public boolean isReferencedEntityAttribute() { + return true; + } + + @Override + public List relationalValueSources() { + return pluralAttributeIndexSource.relationalValueSources(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java index 451625cf76..8a25b8c278 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java @@ -41,6 +41,7 @@ import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.source.AttributeSource; +import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.FilterSource; import org.hibernate.metamodel.spi.source.MetaAttributeSource; @@ -352,7 +353,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab @Override public PluralAttributeElementSource resolvePluralAttributeElementSource( - PluralAttributeElementSourceResolutionContext context) { + AttributeSourceResolutionContext context) { if ( elementSource == null ) { // elementSource has not been initialized, so we need to resolve it using the // association owner. @@ -366,6 +367,10 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab } return elementSource; } + + protected PluralAssociationAttribute pluralAssociationAttribute() { + return associationAttribute; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SequentialPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SequentialPluralAttributeIndexSourceImpl.java index ba1770b073..94476fcec2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SequentialPluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/SequentialPluralAttributeIndexSourceImpl.java @@ -23,6 +23,9 @@ */ package org.hibernate.metamodel.internal.source.annotations; +import java.util.Collections; +import java.util.Map; + import org.jboss.jandex.AnnotationInstance; import org.hibernate.metamodel.internal.Binder; @@ -30,6 +33,7 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssoc import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource; /** @@ -62,4 +66,18 @@ public class SequentialPluralAttributeIndexSourceImpl public int base() { return base; } + @Override + public ExplicitHibernateTypeSource getTypeInformation() { + return new ExplicitHibernateTypeSource() { + @Override + public String getName() { + return "integer"; + } + + @Override + public Map getParameters() { + return Collections.emptyMap(); + } + }; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java index 0935bc44f1..0a40167bfc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java @@ -37,7 +37,6 @@ import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.jboss.jandex.Index; import org.jboss.jandex.IndexView; import org.jboss.logging.Logger; @@ -50,7 +49,7 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver; -import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolverImpl; +import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver; import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver; import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper; @@ -275,8 +274,11 @@ public class AssociationAttribute extends MappedAttribute { return PropertyGeneration.NEVER; } - private AttributeTypeResolver getDefaultHibernateTypeResolver() { - return new CompositeAttributeTypeResolver( this, new AttributeTypeResolverImpl( this ) ); + protected AttributeTypeResolver getDefaultHibernateTypeResolver() { + return new CompositeAttributeTypeResolver( + this, + HibernateTypeResolver.createAttributeTypeResolver( this ) + ); } private boolean determineNotFoundBehavior() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java index 423b7758f8..60944f2580 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java @@ -43,7 +43,7 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.internal.source.annotations.IdentifierGeneratorSourceContainer; import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver; -import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolverImpl; +import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver; import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver; import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver; import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver; @@ -422,10 +422,10 @@ public class BasicAttribute extends MappedAttribute { private AttributeTypeResolver getDefaultHibernateTypeResolver() { CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this ); - resolver.addHibernateTypeResolver( new AttributeTypeResolverImpl( this ) ); - resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) ); - resolver.addHibernateTypeResolver( new LobTypeResolver( this ) ); - resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) ); + resolver.addHibernateTypeResolver( HibernateTypeResolver.createAttributeTypeResolver( this ) ); + resolver.addHibernateTypeResolver( TemporalTypeResolver.createAttributeTypeResolver( this ) ); + resolver.addHibernateTypeResolver( LobTypeResolver.createAttributeTypeResolve( this ) ); + resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createAttributeTypeResolver( this ) ); return resolver; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/PluralAssociationAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/PluralAssociationAttribute.java index 8de9290f32..8fad6fca67 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/PluralAssociationAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/PluralAssociationAttribute.java @@ -36,7 +36,6 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.hibernate.AssertionFailure; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.LazyCollectionOption; @@ -44,7 +43,7 @@ import org.hibernate.annotations.OnDeleteAction; import org.hibernate.annotations.SortType; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolver; -import org.hibernate.metamodel.internal.source.annotations.attribute.type.AttributeTypeResolverImpl; +import org.hibernate.metamodel.internal.source.annotations.attribute.type.HibernateTypeResolver; import org.hibernate.metamodel.internal.source.annotations.attribute.type.CompositeAttributeTypeResolver; import org.hibernate.metamodel.internal.source.annotations.attribute.type.EnumeratedTypeResolver; import org.hibernate.metamodel.internal.source.annotations.attribute.type.LobTypeResolver; @@ -95,6 +94,8 @@ public class PluralAssociationAttribute extends AssociationAttribute { private final boolean mutable; private final int batchSize; + private AttributeTypeResolver elementTypeResolver; + private AttributeTypeResolver indexTypeResolver; public static PluralAssociationAttribute createPluralAssociationAttribute( ClassInfo entityClassInfo, @@ -541,18 +542,38 @@ public class PluralAssociationAttribute extends AssociationAttribute { return mutable; } - /* @Override public AttributeTypeResolver getHibernateTypeResolver() { + if ( elementTypeResolver == null ) { + elementTypeResolver = getDefaultElementHibernateTypeResolver(); + } + return elementTypeResolver; + } + + private AttributeTypeResolver getDefaultElementHibernateTypeResolver() { CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this ); - resolver.addHibernateTypeResolver( new AttributeTypeResolverImpl( this ) ); - // TODO: make it work for temporal elements - //resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) ); - resolver.addHibernateTypeResolver( new LobTypeResolver( this ) ); - resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) ); + resolver.addHibernateTypeResolver( HibernateTypeResolver.createCollectionElementTypeResolver( this ) ); + resolver.addHibernateTypeResolver( TemporalTypeResolver.createCollectionElementTypeResolver( this ) ); + resolver.addHibernateTypeResolver( LobTypeResolver.createCollectionElementTypeResolve( this ) ); + resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createCollectionElementTypeResolver( this ) ); return resolver; } - */ + + public AttributeTypeResolver getIndexTypeResolver() { + if ( indexType == null ) { + return getDefaultHibernateTypeResolver(); + } + else if ( indexTypeResolver == null ) { + CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( this ); + final String name = getName() + ".index"; + resolver.addHibernateTypeResolver( HibernateTypeResolver.createCollectionIndexTypeResolver( this ) ); + // TODO: Lob allowed as collection index? I don't see an annotation for that. + resolver.addHibernateTypeResolver( EnumeratedTypeResolver.createCollectionIndexTypeResolver( this ) ); + resolver.addHibernateTypeResolver( TemporalTypeResolver.createCollectionIndexTypeResolver( this ) ); + indexTypeResolver = resolver; + } + return indexTypeResolver; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AbstractAttributeTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AbstractAttributeTypeResolver.java index 2991a01f21..a8d2db10a4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AbstractAttributeTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AbstractAttributeTypeResolver.java @@ -26,26 +26,40 @@ package org.hibernate.metamodel.internal.source.annotations.attribute.type; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.DotName; import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; +import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext; +import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.usertype.DynamicParameterizedType; /** * @author Strong Liu * @author Brett Meyer + * @author Gail Badner */ public abstract class AbstractAttributeTypeResolver implements AttributeTypeResolver { - - protected final MappedAttribute mappedAttribute; - public AbstractAttributeTypeResolver( MappedAttribute mappedAttribute ) { - this.mappedAttribute = mappedAttribute; + private final String name; + private final Class javaClass; + private final AnnotationInstance annotation; + private final EntityBindingContext context; + + public AbstractAttributeTypeResolver( + String name, + Class javaClass, + AnnotationInstance annotation, + EntityBindingContext context){ + this.name = name; + this.javaClass = javaClass; + this.annotation = annotation; + this.context = context; } - + @Override final public String getExplicitHibernateTypeName() { String type = getExplicitAnnotatedHibernateTypeName(); @@ -54,42 +68,60 @@ public abstract class AbstractAttributeTypeResolver implements AttributeTypeReso if ( !StringHelper.isEmpty( type ) ) { return type; } else { - return hasEntityTypeDef() ? mappedAttribute.getAttributeType().getName() : null; + return hasTypeDef() ? javaClass().getName() : null; } } @Override final public String getExplicitAnnotatedHibernateTypeName() { - return resolveAnnotatedHibernateTypeName( - getTypeDeterminingAnnotationInstance() ); + return resolveHibernateTypeName(); } @Override final public Map getExplicitHibernateTypeParameters() { Map result = new HashMap( ); //this is only use by enum type and serializable blob type, but we put there anyway + // TODO: why? result.put( DynamicParameterizedType.RETURNED_CLASS, - mappedAttribute.getAttributeType().getName() + javaClass().getName() ); if ( StringHelper.isNotEmpty( getExplicitHibernateTypeName() ) ) { - result.putAll( resolveHibernateTypeParameters( - getTypeDeterminingAnnotationInstance() ) ); + result.putAll( resolveHibernateTypeParameters() ); } return result; } - final protected boolean hasEntityTypeDef() { - return mappedAttribute.getContext() - .getMetadataImplementor().hasTypeDefinition( - mappedAttribute.getAttributeType().getName() ); + final protected boolean hasTypeDef() { + return context.getMetadataImplementor().hasTypeDefinition( + javaClass().getName() + ); } - - protected abstract AnnotationInstance getTypeDeterminingAnnotationInstance(); - protected abstract String resolveAnnotatedHibernateTypeName(AnnotationInstance annotationInstance); + protected abstract String resolveHibernateTypeName(); - protected Map resolveHibernateTypeParameters(AnnotationInstance annotationInstance) { + protected Map resolveHibernateTypeParameters() { return Collections.emptyMap(); } + + protected String name() { + return name; + } + + protected Class javaClass() { + return javaClass; + } + + protected AnnotationInstance annotation() { + return annotation; + } + + protected static AnnotationInstance resolveAnnotationInstance( + Map> annotations, + DotName dotName) { + return JandexHelper.getSingleAnnotation( + annotations, + dotName + ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AttributeTypeResolverImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AttributeTypeResolverImpl.java deleted file mode 100644 index e4545a6298..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/AttributeTypeResolverImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.internal.source.annotations.attribute.type; - -import java.util.HashMap; -import java.util.Map; - -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationValue; - -import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; -import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; -import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; - -/** - * Type Resolver which checks {@link org.hibernate.annotations.Type} to find the type info. - * - * @author Strong Liu - * @author Brett Meyer - */ -public class AttributeTypeResolverImpl extends AbstractAttributeTypeResolver { - - public AttributeTypeResolverImpl(MappedAttribute mappedAttribute) { - super( mappedAttribute ); - } - - @Override - protected String resolveAnnotatedHibernateTypeName(AnnotationInstance typeAnnotation) { - if ( typeAnnotation != null ) { - return JandexHelper.getValue( - typeAnnotation, "type", String.class ); - } - else { - return null; - } - } - - @Override - protected Map resolveHibernateTypeParameters(AnnotationInstance typeAnnotation) { - HashMap typeParameters = new HashMap(); - - if ( typeAnnotation != null ) { - AnnotationValue parameterAnnotationValue = typeAnnotation.value( "parameters" ); - if ( parameterAnnotationValue != null ) { - AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray(); - for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) { - typeParameters.put( - JandexHelper.getValue( parameterAnnotationInstance, "name", String.class ), - JandexHelper.getValue( parameterAnnotationInstance, "value", String.class ) - ); - } - } - } - - return typeParameters; - } - - @Override - protected AnnotationInstance getTypeDeterminingAnnotationInstance() { - return JandexHelper.getSingleAnnotation( - mappedAttribute.annotations(), - HibernateDotNames.TYPE - ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/EnumeratedTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/EnumeratedTypeResolver.java index 8be6dfc10a..60900e2120 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/EnumeratedTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/EnumeratedTypeResolver.java @@ -34,66 +34,88 @@ import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.type.EnumType; -import org.hibernate.usertype.DynamicParameterizedType; /** * @author Strong Liu * @author Brett Meyer + * @author Gail Badner */ public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver { - private final boolean isMapKey; private final boolean isEnum; -// private final String attributeType; + private final javax.persistence.EnumType enumType; - public EnumeratedTypeResolver(MappedAttribute mappedAttribute) { - super( mappedAttribute ); - isEnum = mappedAttribute.getAttributeType().isEnum(); - isMapKey = false;//todo -// attributeType = mappedAttribute.getAttributeType().getName(); - } - - public EnumeratedTypeResolver(PluralAssociationAttribute pluralAssociationAttribute) { - super( pluralAssociationAttribute ); - isEnum = pluralAssociationAttribute.getReferencedAttributeType().isEnum(); - isMapKey = false;//todo -// attributeType = pluralAssociationAttribute.getReferencedAttributeType().getName(); - } - - @Override - protected AnnotationInstance getTypeDeterminingAnnotationInstance() { - return JandexHelper.getSingleAnnotation( - mappedAttribute.annotations(), - JPADotNames.ENUMERATED + public static EnumeratedTypeResolver createAttributeTypeResolver(MappedAttribute attribute) { + return new EnumeratedTypeResolver( + attribute.getName(), + attribute.getAttributeType(), + resolveAnnotationInstance( attribute.annotations(),JPADotNames.ENUMERATED ), + attribute.getContext() ); } + public static EnumeratedTypeResolver createCollectionElementTypeResolver( + PluralAssociationAttribute pluralAssociationAttribute) { + return new EnumeratedTypeResolver( + pluralAssociationAttribute.getName(), + pluralAssociationAttribute.getReferencedAttributeType(), + resolveAnnotationInstance( pluralAssociationAttribute.annotations(),JPADotNames.ENUMERATED ), + pluralAssociationAttribute.getContext() + ); + } + + public static EnumeratedTypeResolver createCollectionIndexTypeResolver( + PluralAssociationAttribute pluralAssociationAttribute) { + return new EnumeratedTypeResolver( + pluralAssociationAttribute.getName(), + pluralAssociationAttribute.getIndexType(), + resolveAnnotationInstance( pluralAssociationAttribute.annotations(), JPADotNames.MAP_KEY_ENUMERATED ), + pluralAssociationAttribute.getContext() + ); + } + + private EnumeratedTypeResolver( + String name, + Class javaClass, + AnnotationInstance annotation, + EntityBindingContext context) { + super( name, javaClass, annotation, context ); + this.isEnum = javaClass().isEnum(); + this.enumType = annotation == null ? + null : + JandexHelper.getEnumValue( annotation, "value", javax.persistence.EnumType.class ); + } + @Override - public String resolveAnnotatedHibernateTypeName(AnnotationInstance enumeratedAnnotation) { - if ( enumeratedAnnotation != null ) { + public String resolveHibernateTypeName() { + if ( annotation() != null ) { if ( isEnum ) { return EnumType.class.getName(); } else { - throw new AnnotationException( "Attribute " + mappedAttribute.getName() + " is not a Enumerated type, but has a @Enumerated annotation." ); + throw new AnnotationException( + String.format( + "Attribute %s is not a Enumerated type, but has %s or %s annotation.", + name(), + JPADotNames.ENUMERATED, + JPADotNames.MAP_KEY_ENUMERATED + ) + ); } } - else if ( !hasEntityTypeDef() && isEnum ) { + else if ( !hasTypeDef() && isEnum ) { return EnumType.class.getName(); } return null; } @Override - protected Map resolveHibernateTypeParameters(AnnotationInstance annotationInstance) { + protected Map resolveHibernateTypeParameters() { HashMap typeParameters = new HashMap(); - if ( annotationInstance != null ) { - javax.persistence.EnumType enumType = JandexHelper.getEnumValue( - annotationInstance, - "value", - javax.persistence.EnumType.class - ); + + if ( enumType != null ) { if ( javax.persistence.EnumType.ORDINAL.equals( enumType ) ) { typeParameters.put( EnumType.TYPE, String.valueOf( Types.INTEGER ) ); typeParameters.put( EnumType.NAMED, String.valueOf( false ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/HibernateTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/HibernateTypeResolver.java new file mode 100644 index 0000000000..043ab43823 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/HibernateTypeResolver.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.internal.source.annotations.attribute.type; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; + +import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; +import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext; +import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; +import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; + +/** + * Type Resolver which checks {@link org.hibernate.annotations.Type} to find the type info. + * + * @author Strong Liu + * @author Brett Meyer + * @author Gail Badner + */ +public class HibernateTypeResolver extends AbstractAttributeTypeResolver { + + public static HibernateTypeResolver createAttributeTypeResolver(MappedAttribute attribute) { + return new HibernateTypeResolver( + attribute.getName(), + attribute.getAttributeType(), + resolveAnnotationInstance( attribute.annotations(), HibernateDotNames.TYPE ), + attribute.getContext() + ); + } + + public static HibernateTypeResolver createCollectionElementTypeResolver( + PluralAssociationAttribute pluralAssociationAttribute) { + return new HibernateTypeResolver( + pluralAssociationAttribute.getName(), + pluralAssociationAttribute.getReferencedAttributeType(), + resolveAnnotationInstance( pluralAssociationAttribute.annotations(), HibernateDotNames.TYPE ), + pluralAssociationAttribute.getContext() + ); + } + + public static HibernateTypeResolver createCollectionIndexTypeResolver( + PluralAssociationAttribute pluralAssociationAttribute) { + final AnnotationInstance annotation = resolveAnnotationInstance( + pluralAssociationAttribute.annotations(), + HibernateDotNames.MAP_KEY_TYPE + ); + final AnnotationInstance typeAnnotation = annotation == null ? + null : + JandexHelper.getValue( annotation, "value", AnnotationInstance.class ); + return new HibernateTypeResolver( + pluralAssociationAttribute.getName(), + pluralAssociationAttribute.getIndexType(), + typeAnnotation, + pluralAssociationAttribute.getContext() + ); + } + + private HibernateTypeResolver( + String name, + Class javaClass, + AnnotationInstance annotation, + EntityBindingContext context) { + super( name, javaClass, annotation, context ); + } + + @Override + protected String resolveHibernateTypeName() { + return annotation() == null ? + null : + JandexHelper.getValue( annotation(), "type", String.class ); + } + + @Override + protected Map resolveHibernateTypeParameters() { + if ( annotation() != null ) { + AnnotationValue parameterAnnotationValue = annotation().value( "parameters" ); + if ( parameterAnnotationValue != null ) { + AnnotationInstance[] parameterAnnotations = parameterAnnotationValue.asNestedArray(); + final HashMap typeParameters = new HashMap( parameterAnnotations.length ); + for ( AnnotationInstance parameterAnnotationInstance : parameterAnnotations ) { + typeParameters.put( + JandexHelper.getValue( parameterAnnotationInstance, "name", String.class ), + JandexHelper.getValue( parameterAnnotationInstance, "value", String.class ) + ); + } + return typeParameters; + } + } + return Collections.emptyMap(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/LobTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/LobTypeResolver.java index 85489970a1..d3da5c62c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/LobTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/LobTypeResolver.java @@ -27,14 +27,13 @@ package org.hibernate.metamodel.internal.source.annotations.attribute.type; import java.io.Serializable; import java.sql.Blob; import java.sql.Clob; -import java.util.Collections; -import java.util.Map; import org.jboss.jandex.AnnotationInstance; import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; +import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; -import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.type.CharacterArrayClobType; import org.hibernate.type.PrimitiveCharacterArrayClobType; import org.hibernate.type.SerializableToBlobType; @@ -44,54 +43,65 @@ import org.hibernate.type.WrappedMaterializedBlobType; /** * @author Strong Liu * @author Brett Meyer + * @author Gail Badner */ public class LobTypeResolver extends AbstractAttributeTypeResolver { + public static LobTypeResolver createAttributeTypeResolve(MappedAttribute attribute) { + return new LobTypeResolver( + attribute.getName(), + attribute.getAttributeType(), + resolveAnnotationInstance( attribute.annotations(), JPADotNames.LOB ), + attribute.getContext() + ); + } - public LobTypeResolver(MappedAttribute mappedAttribute) { - super( mappedAttribute ); + public static LobTypeResolver createCollectionElementTypeResolve(PluralAssociationAttribute pluralAssociationAttribute) { + return new LobTypeResolver( + pluralAssociationAttribute.getName(), + pluralAssociationAttribute.getReferencedAttributeType(), + resolveAnnotationInstance( pluralAssociationAttribute.annotations(), JPADotNames.LOB ), + pluralAssociationAttribute.getContext() + ); + } + + private LobTypeResolver(String name, + Class javaClass, + AnnotationInstance annotation, + EntityBindingContext context) { + super( name, javaClass, annotation, context ); } @Override - protected AnnotationInstance getTypeDeterminingAnnotationInstance() { - return JandexHelper.getSingleAnnotation( mappedAttribute.annotations(), JPADotNames.LOB ); - } - - @Override - public String resolveAnnotatedHibernateTypeName(AnnotationInstance annotationInstance) { - if ( annotationInstance == null ) { + public String resolveHibernateTypeName() { + if ( annotation() == null ) { //only check attributes annotated with @Lob return null; } String type = "blob"; - if ( Clob.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + if ( Clob.class.isAssignableFrom( javaClass() ) ) { type = StandardBasicTypes.CLOB.getName(); } - else if ( Blob.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + else if ( Blob.class.isAssignableFrom( javaClass() ) ) { type = StandardBasicTypes.BLOB.getName(); } - else if ( String.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + else if ( String.class.isAssignableFrom( javaClass() ) ) { type = StandardBasicTypes.MATERIALIZED_CLOB.getName(); } - else if ( Character[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + else if ( Character[].class.isAssignableFrom( javaClass() ) ) { type = CharacterArrayClobType.class.getName(); } - else if ( char[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + else if ( char[].class.isAssignableFrom( javaClass() ) ) { type = PrimitiveCharacterArrayClobType.class.getName(); } - else if ( Byte[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + else if ( Byte[].class.isAssignableFrom( javaClass() ) ) { type = WrappedMaterializedBlobType.class.getName(); } - else if ( byte[].class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + else if ( byte[].class.isAssignableFrom( javaClass() ) ) { type = StandardBasicTypes.MATERIALIZED_BLOB.getName(); } - else if ( Serializable.class.isAssignableFrom( mappedAttribute.getAttributeType() ) ) { + else if ( Serializable.class.isAssignableFrom( javaClass() ) ) { type = SerializableToBlobType.class.getName(); } return type; } - - @Override - protected Map resolveHibernateTypeParameters(AnnotationInstance annotationInstance) { - return Collections.emptyMap(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java index 1c516ad134..c1ae130bd9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java @@ -33,8 +33,11 @@ import org.jboss.jandex.AnnotationInstance; import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; +import org.hibernate.annotations.SourceType; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute; +import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute; +import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; import org.hibernate.type.StandardBasicTypes; @@ -42,26 +45,58 @@ import org.hibernate.type.StandardBasicTypes; /** * @author Strong Liu * @author Brett Meyer + * @author Gail Badner */ public class TemporalTypeResolver extends AbstractAttributeTypeResolver { - private final BasicAttribute basicAttribute; - private final boolean isMapKey; - - public TemporalTypeResolver(BasicAttribute mappedAttribute) { - super( mappedAttribute ); - this.basicAttribute = mappedAttribute; - this.isMapKey = false;//todo + private final SourceType versionSourceType; + + public static TemporalTypeResolver createAttributeTypeResolver(BasicAttribute attribute) { + return new TemporalTypeResolver( + attribute.getName(), + attribute.getAttributeType(), + resolveAnnotationInstance( attribute.annotations(), JPADotNames.TEMPORAL ), + attribute.getContext(), + attribute.isVersioned() ? attribute.getVersionSourceType() : null + ); + } + + public static TemporalTypeResolver createCollectionElementTypeResolver(PluralAssociationAttribute attribute) { + return new TemporalTypeResolver( + attribute.getName(), + attribute.getReferencedAttributeType(), + resolveAnnotationInstance( attribute.annotations(), JPADotNames.TEMPORAL ), + attribute.getContext(), + null + ); + } + + public static TemporalTypeResolver createCollectionIndexTypeResolver(PluralAssociationAttribute attribute) { + return new TemporalTypeResolver( + attribute.getName(), + attribute.getIndexType(), + resolveAnnotationInstance( attribute.annotations(), JPADotNames.MAP_KEY_TEMPORAL ), + attribute.getContext(), + null + ); + } + private TemporalTypeResolver(String name, + Class javaClass, + AnnotationInstance annotation, + EntityBindingContext context, + SourceType versionSourceType) { + super( name, javaClass, annotation, context ); + this.versionSourceType = versionSourceType; } @Override - public String resolveAnnotatedHibernateTypeName(AnnotationInstance temporalAnnotation) { - Class attributeType = mappedAttribute.getAttributeType(); + public String resolveHibernateTypeName() { + Class attributeType = javaClass(); if ( isTemporalType( attributeType ) ) { - if ( basicAttribute.isVersioned() && basicAttribute.getVersionSourceType() != null ) { - return basicAttribute.getVersionSourceType().typeName(); + if (versionSourceType != null ) { + return versionSourceType.typeName(); } - if ( temporalAnnotation == null ) { + if ( annotation() == null ) { // Although JPA 2.1 states that @Temporal is required on // Date/Calendar attributes, allow it to be left off in order // to support legacy mappings. @@ -80,7 +115,11 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver { return StandardBasicTypes.TIMESTAMP.getName(); } } else { - final TemporalType temporalType = JandexHelper.getEnumValue( temporalAnnotation, "value", TemporalType.class ); + final TemporalType temporalType = JandexHelper.getEnumValue( + annotation(), + "value", + TemporalType.class + ); final boolean isDate = Date.class.isAssignableFrom( attributeType ); String type; switch ( temporalType ) { @@ -102,24 +141,15 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver { return type; } } else { - if ( temporalAnnotation != null ) { + if ( annotation() != null ) { throw new AnnotationException( - "@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + mappedAttribute - .getName() + "@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + name() ); } } return null; } - @Override - protected AnnotationInstance getTypeDeterminingAnnotationInstance() { - return JandexHelper.getSingleAnnotation( - mappedAttribute.annotations(), - JPADotNames.TEMPORAL - ); - } - private static boolean isTemporalType(Class type) { return Date.class.isAssignableFrom( type ) || Calendar.class.isAssignableFrom( type ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractPluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractPluralAttributeSourceImpl.java index b3d99aa7ba..cfb30035e5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractPluralAttributeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractPluralAttributeSourceImpl.java @@ -37,6 +37,7 @@ import org.hibernate.jaxb.spi.hbm.PluralAttributeElement; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.CustomSQL; import org.hibernate.metamodel.spi.source.AttributeSourceContainer; +import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.FilterSource; import org.hibernate.metamodel.spi.source.MappingException; @@ -164,7 +165,7 @@ public abstract class AbstractPluralAttributeSourceImpl } @Override - public PluralAttributeElementSource resolvePluralAttributeElementSource(PluralAttributeElementSourceResolutionContext context) { + public PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context) { // elementSource is already resolved; nothing to do. return elementSource; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ArraySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ArraySourceImpl.java index 6dcf54b1e8..f564c51f92 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ArraySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ArraySourceImpl.java @@ -23,9 +23,11 @@ */ package org.hibernate.metamodel.internal.source.hbm; +import org.hibernate.AssertionFailure; import org.hibernate.jaxb.spi.hbm.JaxbArrayElement; import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement; import org.hibernate.metamodel.spi.source.AttributeSourceContainer; +import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext; import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource; import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource; @@ -50,6 +52,14 @@ public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implement } } + @Override + public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) { + if ( indexSource == null ) { + throw new AssertionFailure( "Array index source should have been resolved already." ); + } + return indexSource; + } + @Override public PluralAttributeIndexSource getIndexSource() { return indexSource; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeIndexSourceImpl.java index a3870296b1..1f55ab7ba3 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeIndexSourceImpl.java @@ -34,8 +34,10 @@ import org.hibernate.jaxb.spi.hbm.JaxbKeyPropertyElement; import org.hibernate.metamodel.internal.Binder; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.source.AttributeSource; import org.hibernate.metamodel.spi.source.CompositePluralAttributeIndexSource; +import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.LocalBindingContext; import org.hibernate.metamodel.spi.source.RelationalValueSource; @@ -95,6 +97,16 @@ public class CompositePluralAttributeIndexSourceImpl return null; //To change body of implemented methods use File | Settings | File Templates. } + @Override + public ExplicitHibernateTypeSource getTypeInformation() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public boolean isReferencedEntityAttribute() { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + @Override public String getClassName() { return className; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListSourceImpl.java index 1cbde62003..8ad480dc28 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/ListSourceImpl.java @@ -23,9 +23,11 @@ */ package org.hibernate.metamodel.internal.source.hbm; +import org.hibernate.AssertionFailure; import org.hibernate.jaxb.spi.hbm.JaxbListElement; import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement; import org.hibernate.metamodel.spi.source.AttributeSourceContainer; +import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext; import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource; import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.SequentialPluralAttributeIndexSource; @@ -74,4 +76,12 @@ public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements public Nature getNature() { return Nature.LIST; } + + @Override + public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) { + if ( indexSource == null ) { + throw new AssertionFailure( "Array index source should have been resolved already." ); + } + return indexSource; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapKeySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapKeySourceImpl.java index 657df3e6e4..bd20d32149 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapKeySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapKeySourceImpl.java @@ -31,6 +31,7 @@ import org.hibernate.jaxb.spi.hbm.JaxbIndexElement; import org.hibernate.jaxb.spi.hbm.JaxbMapKeyElement; import org.hibernate.metamodel.internal.Binder; import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.source.BasicPluralAttributeIndexSource; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.RelationalValueSource; @@ -191,10 +192,15 @@ public class MapKeySourceImpl extends AbstractHbmSourceNode implements BasicPlur } @Override - public ExplicitHibernateTypeSource explicitHibernateTypeSource() { + public ExplicitHibernateTypeSource getTypeInformation() { return typeSource; } + @Override + public boolean isReferencedEntityAttribute() { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + @Override public List relationalValueSources() { return valueSources; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapSourceImpl.java index 0424eaec59..71cb97aff6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/MapSourceImpl.java @@ -27,6 +27,7 @@ import org.hibernate.AssertionFailure; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.jaxb.spi.hbm.JaxbMapElement; import org.hibernate.metamodel.spi.source.AttributeSourceContainer; +import org.hibernate.metamodel.spi.source.AttributeSourceResolutionContext; import org.hibernate.metamodel.spi.source.IndexedPluralAttributeSource; import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource; @@ -73,6 +74,15 @@ public class MapSourceImpl extends AbstractPluralAttributeSourceImpl implements } } + @Override + public PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context) { + if ( indexSource == null ) { + throw new NotYetImplementedException( "Plural attribute index source resolution not implemented yet." ); + + } + return indexSource; + } + @Override public PluralAttributeIndexSource getIndexSource() { return indexSource; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToManyPluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToManyPluralAttributeElementSourceImpl.java index a1b227251d..f66f3fe280 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToManyPluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/OneToManyPluralAttributeElementSourceImpl.java @@ -39,7 +39,7 @@ public class OneToManyPluralAttributeElementSourceImpl public OneToManyPluralAttributeElementSourceImpl( MappingDocument mappingDocument, - JaxbOneToManyElement oneToManyElement, + final JaxbOneToManyElement oneToManyElement, String cascadeString) { super( mappingDocument ); this.oneToManyElement = oneToManyElement; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SequentialPluralAttributeIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SequentialPluralAttributeIndexSourceImpl.java index 5b565380e0..3f596f9766 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SequentialPluralAttributeIndexSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/SequentialPluralAttributeIndexSourceImpl.java @@ -164,10 +164,15 @@ public class SequentialPluralAttributeIndexSourceImpl extends AbstractHbmSourceN } @Override - public ExplicitHibernateTypeSource explicitHibernateTypeSource() { + public ExplicitHibernateTypeSource getTypeInformation() { return typeSource; } + @Override + public boolean isReferencedEntityAttribute() { + return false; + } + @Override public List< RelationalValueSource > relationalValueSources() { return valueSources; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/AttributeSourceResolutionContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/AttributeSourceResolutionContext.java new file mode 100644 index 0000000000..61510c308a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/AttributeSourceResolutionContext.java @@ -0,0 +1,33 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.spi.source; + +/** + * + * @author Gail Badner + */ +public interface AttributeSourceResolutionContext { + public IdentifierSource resolveIdentifierSource(String entityName); + public AttributeSource resolveAttributeSource(String entityName, String attributeName); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/BasicPluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/BasicPluralAttributeIndexSource.java index 263cd334e6..c02473a6b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/BasicPluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/BasicPluralAttributeIndexSource.java @@ -27,5 +27,4 @@ package org.hibernate.metamodel.spi.source; * @author Gail Badner */ public interface BasicPluralAttributeIndexSource extends PluralAttributeIndexSource { - ExplicitHibernateTypeSource explicitHibernateTypeSource(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/EntityAttributePluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/EntityAttributePluralAttributeIndexSource.java new file mode 100644 index 0000000000..262a9aaad1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/EntityAttributePluralAttributeIndexSource.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.spi.source; + +/** + * Represents a plural attribute index source that is an attribute + * of the referenced entity (relevant only to one-to-many and many-to-many + * associations). + * + * @author Gail Badner + */ +public interface EntityAttributePluralAttributeIndexSource extends PluralAttributeIndexSource { + public String getAttributeName(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/IndexedPluralAttributeSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/IndexedPluralAttributeSource.java index 2577ac30b1..3a845db8fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/IndexedPluralAttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/IndexedPluralAttributeSource.java @@ -26,7 +26,9 @@ package org.hibernate.metamodel.spi.source; /** * */ -public interface IndexedPluralAttributeSource extends PluralAttributeSource { +public interface IndexedPluralAttributeSource extends PluralAttributeSource, PluralAttributeIndexSourceResolver { + + PluralAttributeIndexSource resolvePluralAttributeIndexSource(AttributeSourceResolutionContext context); PluralAttributeIndexSource getIndexSource(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeElementSourceResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeElementSourceResolver.java index 184ffa59c0..efd1573102 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeElementSourceResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeElementSourceResolver.java @@ -27,10 +27,5 @@ package org.hibernate.metamodel.spi.source; * @author Gail Badner */ public interface PluralAttributeElementSourceResolver { - - PluralAttributeElementSource resolvePluralAttributeElementSource(PluralAttributeElementSourceResolutionContext context); - - public static interface PluralAttributeElementSourceResolutionContext { - public AttributeSource resolveAttributeSource(String referencedEntityName, String mappedBy); - } + PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java index 6154fb2172..cead497dca 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSource.java @@ -34,4 +34,23 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding; public interface PluralAttributeIndexSource extends RelationalValueSourceContainer { PluralAttributeIndexBinding.Nature getNature(); List getDefaultNamingStrategies(); + /** + * Obtain information about the Hibernate index type ({@link org.hibernate.type.Type}) + * for this plural attribute index. + * + * @return The Hibernate type information + */ + public ExplicitHibernateTypeSource getTypeInformation(); + + /** + * Is this plural attribute index source for an attribute of the referenced entity + * (relevant only for one-to-many and many-to-many associations)? + * + * If this method returns {@code true}, then this object can safely + * be cast to EntityAttributePluralAttributeIndexSource. + * + * @return true, if this plural attribute index source for an attribute of the referenced + * entity; false, otherwise. + */ + public boolean isReferencedEntityAttribute(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSourceResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSourceResolver.java new file mode 100644 index 0000000000..b397733a26 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/PluralAttributeIndexSourceResolver.java @@ -0,0 +1,31 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.spi.source; + +/** + * @author Gail Badner + */ +public interface PluralAttributeIndexSourceResolver { + PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context); +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java index a6004adbef..07e68e0071 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java @@ -52,7 +52,6 @@ import org.junit.Test; @SuppressWarnings("unchecked") public class CollectionElementTest extends BaseCoreFunctionalTestCase { @Test - @FailureExpectedWithNewMetamodel( message = "Map with EnumType value not supported yet.") public void testSimpleElement() throws Exception { assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() ) .getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() ); @@ -160,7 +159,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase { } @Test - @FailureExpectedWithNewMetamodel( message = "Collection with EnumType element not supported yet.") public void testLazyCollectionofElements() throws Exception { assertEquals( "BoyFavoriteNumbers", SchemaUtil.getCollection( Boy.class, "favoriteNumbers", metadata() ) .getPluralAttributeKeyBinding().getCollectionTable().getLogicalName().toString() ); @@ -202,7 +200,6 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase { } @Test - @FailureExpectedWithNewMetamodel( message = "Map with EnumType key not supported yet.") public void testFetchEagerAndFilter() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java index 3b1a617fa4..cb2dda1b48 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java @@ -32,7 +32,6 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; /** * @author Steve Ebersole */ -@FailureExpectedWithNewMetamodel public class MapKeyEnumeratedTest extends BaseCoreFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() {