From a7179fbc496707ba5055ea7188a4f01c192b1665 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 6 Jul 2011 23:28:48 -0500 Subject: [PATCH] HHH-6371 - Develop metamodel binding creation using a push approach --- .../org/hibernate/annotations/Entity.java | 7 +- .../cfg/NotYetImplementedException.java | 3 + .../AnnotationsMetadataProcessor.java | 38 +- .../AnnotationsSourceProcessor.java | 4 +- .../ConfiguredClassHierarchyBuilder.java | 17 +- .../UnknownInheritanceTypeException.java | 35 + .../annotations/entity/EntityBinder.java | 891 ++++++++++-------- .../hbm/AbstractEntityDescriptorImpl.java | 316 ------- .../binder/source/hbm/BindingCreator.java | 68 +- ...riminatedSubClassEntityDescriptorImpl.java | 79 -- .../binder/source/hbm/HbmHelper.java | 171 ---- .../metamodel/binder/source/hbm/Helper.java | 176 ++++ .../source/hbm/HibernateMappingProcessor.java | 29 +- .../JoinedSubClassEntityDescriptorImpl.java | 80 -- .../binder/source/hbm/MappingHelper.java | 87 -- .../source/hbm/RootEntityDescriptorImpl.java | 134 --- .../source/hbm/TableDescriptorImpl.java | 86 -- .../UnionSubClassEntityDescriptorImpl.java | 80 -- .../AbstractHbmAttributeBindingState.java | 12 +- .../binding/HbmDiscriminatorBindingState.java | 6 +- .../HbmManyToOneAttributeBindingState.java | 13 +- .../HbmPluralAttributeBindingState.java | 51 +- .../HbmSimpleAttributeBindingState.java | 39 +- .../relational/HbmColumnRelationalState.java | 26 +- .../HbmDerivedValueRelationalState.java | 2 +- .../HbmManyToOneRelationalStateContainer.java | 2 +- ...bmSimpleValueRelationalStateContainer.java | 2 +- .../hbm/xml/mapping/CustomSqlElement.java | 35 + .../attribute/SimpleAttribute.java | 6 +- .../src/main/xjb/hbm-mapping-bindings.xjb | 12 + .../xml/mocker/AbstractMockerTest.java | 6 +- .../source/annotations/xml/mocker/Author.java | 2 +- .../xml/mocker/BasicMockerTest.java | 7 +- .../source/annotations/xml/mocker/Book.java | 2 +- .../DefaultConfigurationHelperTest.java | 5 +- .../xml/mocker/EntityListenerTest.java | 2 +- .../xml/mocker/IndexBuilderTest.java | 4 +- .../source/annotations/xml/mocker/Item.java | 2 +- .../annotations/xml/mocker/ItemListener.java | 2 +- .../annotations/xml/mocker/OverrideTest.java | 5 +- .../mocker/PersistenceMetadataMockerTest.java | 2 +- .../source/annotations/xml/mocker/Topic.java | 2 +- .../annotations/xml/mocker/XmlHelper.java | 2 +- .../binding/SimpleValueBindingTests.java | 21 +- ...=> TestAnnotationsBindingContextImpl.java} | 88 +- .../annotations/entity/ProxyBindingTests.java | 6 +- .../annotations/entity/TableNameTest.java | 10 +- .../util/BaseAnnotationIndexTestCase.java | 6 +- .../xml/mocker/AttributeOverride.xml | 2 +- .../annotations/xml/mocker/default-schema.xml | 0 .../xml/mocker/default-schema2.xml | 2 +- .../xml/mocker/entity-metadata-complete.xml | 2 +- .../annotations/xml/mocker/listener.xml | 6 +- .../mocker/override-to-mappedsuperclass.xml | 2 +- .../xml/mocker/persistence-metadata.xml | 2 +- 55 files changed, 983 insertions(+), 1714 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/UnknownInheritanceTypeException.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/AbstractEntityDescriptorImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/DiscriminatedSubClassEntityDescriptorImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HbmHelper.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/Helper.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/JoinedSubClassEntityDescriptorImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/MappingHelper.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/RootEntityDescriptorImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/TableDescriptorImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/UnionSubClassEntityDescriptorImpl.java rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/binding/AbstractHbmAttributeBindingState.java (92%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/binding/HbmDiscriminatorBindingState.java (94%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java (91%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/binding/HbmPluralAttributeBindingState.java (83%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/binding/HbmSimpleAttributeBindingState.java (87%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/relational/HbmColumnRelationalState.java (89%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/relational/HbmDerivedValueRelationalState.java (95%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/relational/HbmManyToOneRelationalStateContainer.java (96%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{ => binder}/source/hbm/state/relational/HbmSimpleValueRelationalStateContainer.java (99%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/xml/mapping/CustomSqlElement.java rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/AbstractMockerTest.java (95%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/Author.java (96%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/BasicMockerTest.java (90%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/Book.java (97%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java (95%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/EntityListenerTest.java (97%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/IndexBuilderTest.java (56%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/Item.java (94%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/ItemListener.java (94%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/OverrideTest.java (96%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java (96%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/Topic.java (95%) rename hibernate-core/src/test/java/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/XmlHelper.java (97%) rename hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/{entity/AnnotationsBindingContextImpl.java => TestAnnotationsBindingContextImpl.java} (78%) rename hibernate-core/src/test/resources/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/AttributeOverride.xml (90%) rename hibernate-core/src/test/resources/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/default-schema.xml (100%) rename hibernate-core/src/test/resources/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/default-schema2.xml (76%) rename hibernate-core/src/test/resources/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/entity-metadata-complete.xml (78%) rename hibernate-core/src/test/resources/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/listener.xml (71%) rename hibernate-core/src/test/resources/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/override-to-mappedsuperclass.xml (85%) rename hibernate-core/src/test/resources/org/hibernate/metamodel/{ => binder}/source/annotations/xml/mocker/persistence-metadata.xml (83%) diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/Entity.java b/hibernate-core/src/main/java/org/hibernate/annotations/Entity.java index 8e055b07e9..922d0fab7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/Entity.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/Entity.java @@ -51,8 +51,11 @@ public @interface Entity { boolean selectBeforeUpdate() default false; /** polymorphism strategy for this entity */ PolymorphismType polymorphism() default PolymorphismType.IMPLICIT; - /** persister of this entity, default is hibernate internal one */ - String persister() default ""; /** optimistic locking strategy */ OptimisticLockType optimisticLock() default OptimisticLockType.VERSION; + /** + * persister of this entity, default is hibernate internal one + * @deprecated use {@link Persister} instead + */ + String persister() default ""; } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/NotYetImplementedException.java b/hibernate-core/src/main/java/org/hibernate/cfg/NotYetImplementedException.java index c2e9827682..7ba74a52d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/NotYetImplementedException.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/NotYetImplementedException.java @@ -30,6 +30,9 @@ import org.hibernate.MappingException; * @author Emmanuel Bernard */ public class NotYetImplementedException extends MappingException { + public NotYetImplementedException() { + this( "Not yet implemented!" ); + } public NotYetImplementedException(String msg, Throwable root) { super( msg, root ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsMetadataProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsMetadataProcessor.java index d8aba84e07..e3569df968 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsMetadataProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsMetadataProcessor.java @@ -31,14 +31,11 @@ import org.jboss.jandex.Index; import org.hibernate.cfg.NamingStrategy; import org.hibernate.internal.util.Value; -import org.hibernate.metamodel.binder.MappingException; -import org.hibernate.metamodel.binder.source.EntityDescriptor; import org.hibernate.metamodel.binder.source.MappingDefaults; import org.hibernate.metamodel.binder.source.MetadataImplementor; import org.hibernate.metamodel.binder.source.annotations.entity.ConfiguredClass; import org.hibernate.metamodel.binder.source.annotations.entity.EntityBinder; import org.hibernate.metamodel.binder.source.internal.OverriddenMappingDefaults; -import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.domain.JavaType; import org.hibernate.service.ServiceRegistry; @@ -52,7 +49,7 @@ public class AnnotationsMetadataProcessor implements AnnotationsBindingContext { private final MappingDefaults mappingDefaults; - private final org.hibernate.metamodel.binder.EntityBinder entityBinder; + private final EntityBinder entityBinder; public AnnotationsMetadataProcessor( AnnotationsBindingContext parentBindingContext, @@ -84,41 +81,12 @@ public class AnnotationsMetadataProcessor implements AnnotationsBindingContext { null // association laziness ); - this.entityBinder = new org.hibernate.metamodel.binder.EntityBinder( this ); + this.entityBinder = new EntityBinder( configuredClass, this ); } public void processMappingMetadata(List processedEntityNames) { - final EntityDescriptor entityDescriptor; - switch ( configuredClass.getInheritanceType() ) { - case NO_INHERITANCE: { - entityDescriptor = new RootEntityDescriptorImpl( configuredClass, this ); - break; - } -// else if ( XMLSubclassElement.class.isInstance( entityElement ) ) { -// entityDescriptor = new DiscriminatedSubClassEntityDescriptorImpl( entityElement, this ); -// } -// else if ( XMLJoinedSubclassElement.class.isInstance( entityElement ) ) { -// entityDescriptor = new JoinedSubClassEntityDescriptorImpl( entityElement, this ); -// } -// else if ( XMLUnionSubclassElement.class.isInstance( entityElement ) ) { -// entityDescriptor = new UnionSubClassEntityDescriptorImpl( entityElement, this ); -// } - default: { - throw new MappingException( - "unknown type of class or subclass: " + configuredClass.getName(), - null - ); - } - } - - if ( processedEntityNames.contains( configuredClass.getName() ) ) { - return; - } - - final EntityBinding entityBinding = entityBinder.createEntityBinding( entityDescriptor ); - getMetadataImplementor().addEntity( entityBinding ); - processedEntityNames.add( configuredClass.getName() ); + entityBinder.bind( processedEntityNames ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsSourceProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsSourceProcessor.java index a13bbae1d4..849870a737 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsSourceProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/AnnotationsSourceProcessor.java @@ -176,8 +176,8 @@ public class AnnotationsSourceProcessor implements SourceProcessor, AnnotationsB // for classes annotated w/ @Entity we create a EntityBinding if ( ConfiguredClassType.ENTITY.equals( entityClass.getConfiguredClassType() ) ) { LOG.debugf( "Binding entity from annotated class: %s", entityClass.getName() ); - EntityBinder entityBinder = new EntityBinder( metadata, entityClass, parent ); - EntityBinding binding = entityBinder.bind(); + EntityBinder entityBinder = new EntityBinder( entityClass, parent, this ); + EntityBinding binding = entityBinder.bind( processedEntityNames ); parent = binding.getEntity(); } // for classes annotated w/ @MappedSuperclass we just create the domain instance diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/ConfiguredClassHierarchyBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/ConfiguredClassHierarchyBuilder.java index 1e36915d21..feed15f26e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/ConfiguredClassHierarchyBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/ConfiguredClassHierarchyBuilder.java @@ -23,6 +23,7 @@ */ package org.hibernate.metamodel.binder.source.annotations; +import javax.persistence.AccessType; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -30,8 +31,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.AccessType; - import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; @@ -41,7 +40,6 @@ import org.hibernate.AssertionFailure; import org.hibernate.metamodel.binder.source.annotations.entity.ConfiguredClassHierarchy; import org.hibernate.metamodel.source.annotations.entity.EmbeddableClass; import org.hibernate.metamodel.source.annotations.entity.EntityClass; -import org.hibernate.service.classloading.spi.ClassLoaderService; /** * Given a (jandex) annotation index build processes all classes with JPA relevant annotations and pre-orders @@ -55,15 +53,14 @@ public class ConfiguredClassHierarchyBuilder { * Pre-processes the annotated entities from the index and put them into a structure which can * bound to the Hibernate metamodel. * - * @param context the annotation binding context with access to the service registry and the annotation index + * @param bindingContext The binding context, giving access to needed services and information * * @return a set of {@code ConfiguredClassHierarchy}s. One for each "leaf" entity. */ - public static Set> createEntityHierarchies(AnnotationsBindingContext context) { - ClassLoaderService classLoaderService = context.getServiceRegistry().getService( ClassLoaderService.class ); + public static Set> createEntityHierarchies(AnnotationsBindingContext bindingContext) { Map> processedClassInfos = new HashMap>(); - for ( ClassInfo info : context.getIndex().getKnownClasses() ) { + for ( ClassInfo info : bindingContext.getIndex().getKnownClasses() ) { if ( !isEntityClass( info ) ) { continue; } @@ -74,9 +71,9 @@ public class ConfiguredClassHierarchyBuilder { List configuredClassList = new ArrayList(); ClassInfo tmpClassInfo = info; - Class clazz = classLoaderService.classForName( tmpClassInfo.toString() ); + Class clazz = bindingContext.locateClassByName( tmpClassInfo.toString() ); while ( clazz != null && !clazz.equals( Object.class ) ) { - tmpClassInfo = context.getIndex().getClassByName( DotName.createSimple( clazz.getName() ) ); + tmpClassInfo = bindingContext.getIndex().getClassByName( DotName.createSimple( clazz.getName() ) ); clazz = clazz.getSuperclass(); if ( tmpClassInfo == null ) { continue; @@ -101,7 +98,7 @@ public class ConfiguredClassHierarchyBuilder { List> processedList = new ArrayList>(); for ( List classInfoList : processedClassInfos.values() ) { if ( !processedList.contains( classInfoList ) ) { - hierarchies.add( ConfiguredClassHierarchy.createEntityClassHierarchy( classInfoList, context ) ); + hierarchies.add( ConfiguredClassHierarchy.createEntityClassHierarchy( classInfoList, bindingContext ) ); processedList.add( classInfoList ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/UnknownInheritanceTypeException.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/UnknownInheritanceTypeException.java new file mode 100644 index 0000000000..e6f7de4066 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/UnknownInheritanceTypeException.java @@ -0,0 +1,35 @@ +/* + * 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.binder.source.annotations; + +import org.hibernate.HibernateException; + +/** + * @author Steve Ebersole + */ +public class UnknownInheritanceTypeException extends HibernateException { + public UnknownInheritanceTypeException(String message) { + super( message ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/entity/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/entity/EntityBinder.java index 3c2a691487..1e59bec1d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/entity/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/annotations/entity/EntityBinder.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.binder.source.annotations.entity; import javax.persistence.GenerationType; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -35,27 +36,29 @@ import org.jboss.jandex.DotName; import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; +import org.hibernate.EntityMode; import org.hibernate.MappingException; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.OptimisticLockType; import org.hibernate.annotations.PolymorphismType; -import org.hibernate.annotations.ResultCheckStyle; -import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.access.AccessType; +import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.id.IdentifierGenerator; import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.binder.source.MetadataImplementor; -import org.hibernate.metamodel.binder.source.annotations.JandexHelper; -import org.hibernate.metamodel.binder.source.annotations.entity.state.binding.AbstractEntityDescriptorImpl; +import org.hibernate.internal.util.Value; +import org.hibernate.metamodel.binder.source.annotations.AnnotationsBindingContext; import org.hibernate.metamodel.binder.source.annotations.HibernateDotNames; import org.hibernate.metamodel.binder.source.annotations.JPADotNames; +import org.hibernate.metamodel.binder.source.annotations.JandexHelper; +import org.hibernate.metamodel.binder.source.annotations.UnknownInheritanceTypeException; import org.hibernate.metamodel.binder.source.annotations.global.IdGeneratorBinder; import org.hibernate.metamodel.binding.Caching; import org.hibernate.metamodel.binding.CustomSQL; import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityDiscriminator; import org.hibernate.metamodel.binding.IdGenerator; +import org.hibernate.metamodel.binding.InheritanceType; import org.hibernate.metamodel.binding.ManyToOneAttributeBinding; import org.hibernate.metamodel.binding.SimpleAttributeBinding; import org.hibernate.metamodel.binding.state.DiscriminatorBindingState; @@ -63,15 +66,16 @@ import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState; import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState; import org.hibernate.metamodel.domain.Attribute; import org.hibernate.metamodel.domain.AttributeContainer; +import org.hibernate.metamodel.domain.Entity; import org.hibernate.metamodel.domain.Hierarchical; import org.hibernate.metamodel.domain.SingularAttribute; import org.hibernate.metamodel.relational.Identifier; import org.hibernate.metamodel.relational.Schema; -import org.hibernate.metamodel.relational.Table; import org.hibernate.metamodel.relational.TableSpecification; import org.hibernate.metamodel.relational.UniqueKey; import org.hibernate.metamodel.source.annotations.attribute.AssociationAttribute; import org.hibernate.metamodel.source.annotations.attribute.AttributeOverride; +import org.hibernate.metamodel.source.annotations.attribute.DiscriminatorColumnValues; import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute; import org.hibernate.metamodel.source.annotations.attribute.SimpleAttribute; import org.hibernate.metamodel.source.annotations.attribute.state.binding.AttributeBindingStateImpl; @@ -83,6 +87,7 @@ import org.hibernate.metamodel.source.annotations.attribute.state.relational.Tup import org.hibernate.metamodel.source.annotations.entity.EmbeddableClass; import org.hibernate.metamodel.source.annotations.entity.EntityClass; import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.tuple.entity.EntityTuplizer; /** * Creates the domain and relational metamodel for a configured class and binds them together. @@ -91,52 +96,469 @@ import org.hibernate.persister.entity.EntityPersister; */ public class EntityBinder { private final EntityClass entityClass; - private final MetadataImplementor meta; private final Hierarchical superType; + private final AnnotationsBindingContext bindingContext; - public EntityBinder(MetadataImplementor metadata, EntityClass entityClass, Hierarchical superType) { + private final Schema.Name schemaName; + + public EntityBinder(EntityClass entityClass, Hierarchical superType, AnnotationsBindingContext bindingContext) { this.entityClass = entityClass; - this.meta = metadata; this.superType = superType; + this.bindingContext = bindingContext; + this.schemaName = determineSchemaName(); } - public EntityBinding bind() { - EntityBinding entityBinding = new EntityBinding(); - AbstractEntityDescriptorImpl entityBindingState = new AbstractEntityDescriptorImpl( getSuperType(), entityClass ); + private Schema.Name determineSchemaName() { + String schema = bindingContext.getMappingDefaults().getSchemaName(); + String catalog = bindingContext.getMappingDefaults().getCatalogName(); - bindJpaEntityAnnotation( entityBindingState ); - bindHibernateEntityAnnotation( entityBindingState ); // optional hibernate specific @org.hibernate.annotations.Entity - bindTable( entityBinding ); + final AnnotationInstance tableAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), JPADotNames.TABLE + ); + if ( tableAnnotation != null ) { + final AnnotationValue schemaValue = tableAnnotation.value( "schema" ); + if ( schemaValue != null ) { + schema = schemaValue.asString(); + } - // bind entity level annotations - bindWhereFilter( entityBindingState ); - bindJpaCaching( entityBindingState ); - bindHibernateCaching( entityBindingState ); - bindProxy( entityBindingState ); - bindSynchronize( entityBindingState ); - bindCustomSQL( entityBindingState ); - bindRowId( entityBindingState ); - bindBatchSize( entityBindingState ); - entityBinding.initialize( meta, entityBindingState ); + final AnnotationValue catalogValue = tableAnnotation.value( "catalog" ); + if ( catalogValue != null ) { + catalog = catalogValue.asString(); + } + } - bindInheritance( entityBinding ); + return new Schema.Name( schema, catalog ); + } + + public EntityBinding bind(List processedEntityNames) { + if ( processedEntityNames.contains( entityClass.getName() ) ) { + return bindingContext.getMetadataImplementor().getEntityBinding( entityClass.getName() ); + } + + final EntityBinding entityBinding = doEntityBindingCreation(); + + bindingContext.getMetadataImplementor().addEntity( entityBinding ); + processedEntityNames.add( entityBinding.getEntity().getName() ); + + return entityBinding; + } + + private EntityBinding doEntityBindingCreation() { + final EntityBinding entityBinding = buildBasicEntityBinding(); // bind all attributes - simple as well as associations bindAttributes( entityBinding ); bindEmbeddedAttributes( entityBinding ); - // take care of the id, attributes and relations - if ( entityClass.isEntityRoot() ) { - bindId( entityBinding ); - } - bindTableUniqueConstraints( entityBinding ); - // last, but not least we initialize and register the new EntityBinding - meta.addEntity( entityBinding ); + bindingContext.getMetadataImplementor().addEntity( entityBinding ); return entityBinding; } + private EntityBinding buildBasicEntityBinding() { + switch ( entityClass.getInheritanceType() ) { + case NO_INHERITANCE: { + return doRootEntityBindingCreation(); + } + case SINGLE_TABLE: { + return doDiscriminatedSubclassBindingCreation(); + } + case JOINED: { + return doJoinedSubclassBindingCreation(); + } + case TABLE_PER_CLASS: { + return doUnionSubclassBindingCreation(); + } + default: { + throw new UnknownInheritanceTypeException( "Unknown InheritanceType : " + entityClass.getInheritanceType() ); + } + } + } + + private EntityBinding doRootEntityBindingCreation() { + EntityBinding entityBinding = new EntityBinding(); + entityBinding.setInheritanceType( InheritanceType.NO_INHERITANCE ); + entityBinding.setRoot( true ); + + doBasicEntityBinding( entityBinding ); + + // technically the rest of these binds should only apply to root entities, but they are really available on all + // because we do not currently subtype EntityBinding + + final AnnotationInstance hibernateEntityAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.ENTITY + ); + + // see HHH-6400 + PolymorphismType polymorphism = PolymorphismType.IMPLICIT; + if ( hibernateEntityAnnotation != null && hibernateEntityAnnotation.value( "polymorphism" ) != null ) { + polymorphism = PolymorphismType.valueOf( hibernateEntityAnnotation.value( "polymorphism" ).asEnum() ); + } + entityBinding.setExplicitPolymorphism( polymorphism == PolymorphismType.EXPLICIT ); + + // see HHH-6401 + OptimisticLockType optimisticLockType = OptimisticLockType.VERSION; + if ( hibernateEntityAnnotation != null && hibernateEntityAnnotation.value( "optimisticLock" ) != null ) { + optimisticLockType = OptimisticLockType.valueOf( hibernateEntityAnnotation.value( "optimisticLock" ).asEnum() ); + } + entityBinding.setOptimisticLockStyle( OptimisticLockStyle.valueOf( optimisticLockType.name() ) ); + + final AnnotationInstance hibernateImmutableAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.IMMUTABLE + ); + final boolean mutable = hibernateImmutableAnnotation == null + && hibernateEntityAnnotation != null + && hibernateEntityAnnotation.value( "mutable" ) != null + && hibernateEntityAnnotation.value( "mutable" ).asBoolean(); + entityBinding.setMutable( mutable ); + + final AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.WHERE + ); + entityBinding.setWhereFilter( + whereAnnotation != null && whereAnnotation.value( "clause" ) != null + ? whereAnnotation.value( "clause" ).asString() + : null + ); + + final AnnotationInstance rowIdAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.ROW_ID + ); + entityBinding.setRowId( + rowIdAnnotation != null && rowIdAnnotation.value() != null + ? rowIdAnnotation.value().asString() + : null + ); + + entityBinding.setCaching( interpretCaching( entityClass, bindingContext ) ); + + bindPrimaryTable( entityBinding ); + bindId( entityBinding ); + + if ( entityBinding.getInheritanceType() == InheritanceType.SINGLE_TABLE ) { + bindDiscriminatorColumn( entityBinding ); + } + + // todo : version + + return entityBinding; + } + + private Caching interpretCaching(ConfiguredClass configuredClass, AnnotationsBindingContext bindingContext) { + final AnnotationInstance hibernateCacheAnnotation = JandexHelper.getSingleAnnotation( + configuredClass.getClassInfo(), HibernateDotNames.CACHE + ); + if ( hibernateCacheAnnotation != null ) { + final AccessType accessType = hibernateCacheAnnotation.value( "usage" ) == null + ? bindingContext.getMappingDefaults().getCacheAccessType() + : CacheConcurrencyStrategy.parse( hibernateCacheAnnotation.value( "usage" ).asEnum() ).toAccessType(); + return new Caching( + hibernateCacheAnnotation.value( "region" ) == null + ? configuredClass.getName() + : hibernateCacheAnnotation.value( "region" ).asString(), + accessType, + hibernateCacheAnnotation.value( "include" ) != null + && "all".equals( hibernateCacheAnnotation.value( "include" ).asString() ) + ); + } + + final AnnotationInstance jpaCacheableAnnotation = JandexHelper.getSingleAnnotation( + configuredClass.getClassInfo(), JPADotNames.CACHEABLE + ); + + boolean cacheable = true; // true is the default + if ( jpaCacheableAnnotation != null && jpaCacheableAnnotation.value() != null ) { + cacheable = jpaCacheableAnnotation.value().asBoolean(); + } + + final boolean doCaching; + switch ( bindingContext.getMetadataImplementor().getOptions().getSharedCacheMode() ) { + case ALL: { + doCaching = true; + break; + } + case ENABLE_SELECTIVE: { + doCaching = cacheable; + break; + } + case DISABLE_SELECTIVE: { + doCaching = jpaCacheableAnnotation == null || cacheable; + break; + } + default: { + // treat both NONE and UNSPECIFIED the same + doCaching = false; + break; + } + } + + if ( ! doCaching ) { + return null; + } + + return new Caching( + configuredClass.getName(), + bindingContext.getMappingDefaults().getCacheAccessType(), + true + ); + } + + private EntityBinding doDiscriminatedSubclassBindingCreation() { + EntityBinding entityBinding = new EntityBinding(); + entityBinding.setInheritanceType( InheritanceType.SINGLE_TABLE ); + + doBasicEntityBinding( entityBinding ); + + // todo : bind discriminator-based subclassing specifics... + + return entityBinding; + } + + private EntityBinding doJoinedSubclassBindingCreation() { + EntityBinding entityBinding = new EntityBinding(); + entityBinding.setInheritanceType( InheritanceType.JOINED ); + + doBasicEntityBinding( entityBinding ); + + // todo : bind join-based subclassing specifics... + + return entityBinding; + } + + private EntityBinding doUnionSubclassBindingCreation() { + EntityBinding entityBinding = new EntityBinding(); + entityBinding.setInheritanceType( InheritanceType.TABLE_PER_CLASS ); + + doBasicEntityBinding( entityBinding ); + + // todo : bind union-based subclassing specifics... + + return entityBinding; + } + + private void doBasicEntityBinding(EntityBinding entityBinding) { + entityBinding.setEntityMode( EntityMode.POJO ); + + final Entity entity = new Entity( + entityClass.getName(), + entityClass.getName(), + bindingContext.makeClassReference( entityClass.getName() ), + superType + ); + entityBinding.setEntity( entity ); + + final AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), JPADotNames.ENTITY + ); + + final AnnotationValue explicitJpaEntityName = jpaEntityAnnotation.value( "name" ); + if ( explicitJpaEntityName == null ) { + entityBinding.setJpaEntityName( entityClass.getName() ); + } + else { + entityBinding.setJpaEntityName( explicitJpaEntityName.asString() ); + } + + final AnnotationInstance hibernateEntityAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.ENTITY + ); + + // see HHH-6397 + entityBinding.setDynamicInsert( + hibernateEntityAnnotation != null + && hibernateEntityAnnotation.value( "dynamicInsert" ) != null + && hibernateEntityAnnotation.value( "dynamicInsert" ).asBoolean() + ); + + // see HHH-6398 + entityBinding.setDynamicUpdate( + hibernateEntityAnnotation != null + && hibernateEntityAnnotation.value( "dynamicUpdate" ) != null + && hibernateEntityAnnotation.value( "dynamicUpdate" ).asBoolean() + ); + + // see HHH-6399 + entityBinding.setSelectBeforeUpdate( + hibernateEntityAnnotation != null + && hibernateEntityAnnotation.value( "selectBeforeUpdate" ) != null + && hibernateEntityAnnotation.value( "selectBeforeUpdate" ).asBoolean() + ); + + // Custom sql loader + final AnnotationInstance sqlLoaderAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.LOADER + ); + if ( sqlLoaderAnnotation != null ) { + entityBinding.setCustomLoaderName( sqlLoaderAnnotation.value( "namedQuery" ).asString() ); + } + + // Custom sql insert + final AnnotationInstance sqlInsertAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.SQL_INSERT + ); + entityBinding.setCustomInsert( createCustomSQL( sqlInsertAnnotation ) ); + + // Custom sql update + final AnnotationInstance sqlUpdateAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.SQL_UPDATE + ); + entityBinding.setCustomInsert( createCustomSQL( sqlUpdateAnnotation ) ); + + // Custom sql delete + final AnnotationInstance sqlDeleteAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.SQL_DELETE + ); + entityBinding.setCustomInsert( createCustomSQL( sqlDeleteAnnotation ) ); + + // Batch size + final AnnotationInstance batchSizeAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.BATCH_SIZE + ); + entityBinding.setBatchSize( batchSizeAnnotation == null ? -1 : batchSizeAnnotation.value( "size" ).asInt()); + + // Proxy generation + final boolean lazy; + final Value> proxyInterfaceType; + final AnnotationInstance hibernateProxyAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.PROXY + ); + if ( hibernateProxyAnnotation != null ) { + lazy = hibernateProxyAnnotation.value( "lazy" ) == null + || hibernateProxyAnnotation.value( "lazy" ).asBoolean(); + final AnnotationValue proxyClassValue = hibernateProxyAnnotation.value( "proxyClass" ); + if ( proxyClassValue == null ) { + proxyInterfaceType = entity.getClassReferenceUnresolved(); + } + else { + proxyInterfaceType = bindingContext.makeClassReference( proxyClassValue.asString() ); + } + } + else { + lazy = true; + proxyInterfaceType = entity.getClassReferenceUnresolved(); + } + entityBinding.setLazy( lazy ); + entityBinding.setProxyInterfaceType( proxyInterfaceType ); + + // Custom persister + final Class entityPersisterClass; + final AnnotationInstance persisterAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.PERSISTER + ); + if ( persisterAnnotation == null || persisterAnnotation.value( "impl" ) == null ) { + if ( hibernateEntityAnnotation != null && hibernateEntityAnnotation.value( "persister" ) != null ) { + entityPersisterClass = bindingContext.locateClassByName( hibernateEntityAnnotation.value( "persister" ).asString() ); + } + else { + entityPersisterClass = null; + } + } + else { + if ( hibernateEntityAnnotation != null && hibernateEntityAnnotation.value( "persister" ) != null ) { + // todo : error? + } + entityPersisterClass = bindingContext.locateClassByName( persisterAnnotation.value( "impl" ).asString() ); + } + entityBinding.setCustomEntityPersisterClass( entityPersisterClass ); + + // Custom tuplizer + final AnnotationInstance pojoTuplizerAnnotation = locatePojoTuplizerAnnotation(); + if ( pojoTuplizerAnnotation != null ) { + final Class tuplizerClass = + bindingContext.locateClassByName( pojoTuplizerAnnotation.value( "impl" ).asString() ); + entityBinding.setCustomEntityTuplizerClass( tuplizerClass ); + } + + // table synchronizations + final AnnotationInstance synchronizeAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.SYNCHRONIZE + ); + if ( synchronizeAnnotation != null ) { + final String[] tableNames = synchronizeAnnotation.value().asStringArray(); + entityBinding.addSynchronizedTableNames( Arrays.asList( tableNames ) ); + } + } + + private CustomSQL createCustomSQL(AnnotationInstance customSqlAnnotation) { + if ( customSqlAnnotation == null ) { + return null; + } + + final String sql = customSqlAnnotation.value( "sql" ).asString(); + final boolean isCallable = customSqlAnnotation.value( "callable" ) != null + && customSqlAnnotation.value( "callable" ).asBoolean(); + + final ExecuteUpdateResultCheckStyle checkStyle = customSqlAnnotation.value( "check" ) == null + ? isCallable + ? ExecuteUpdateResultCheckStyle.NONE + : ExecuteUpdateResultCheckStyle.COUNT + : ExecuteUpdateResultCheckStyle.valueOf( customSqlAnnotation.value( "check" ).asEnum() ); + + return new CustomSQL( sql, isCallable, checkStyle ); + } + + private AnnotationInstance locatePojoTuplizerAnnotation() { + final AnnotationInstance tuplizersAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.SYNCHRONIZE + ); + if ( tuplizersAnnotation == null ) { + return null; + } + + for ( AnnotationInstance tuplizerAnnotation : JandexHelper.getValue( tuplizersAnnotation, "value", AnnotationInstance[].class ) ) { + if ( EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() ) == EntityMode.POJO ) { + return tuplizerAnnotation; + } + } + + return null; + } + + private void bindDiscriminatorColumn(EntityBinding entityBinding) { + final Map> typeAnnotations = JandexHelper.getTypeAnnotations( + entityClass.getClassInfo() + ); + SimpleAttribute discriminatorAttribute = SimpleAttribute.createDiscriminatorAttribute( typeAnnotations ); + bindSingleMappedAttribute( entityBinding, entityBinding.getEntity(), discriminatorAttribute ); + + if ( !( discriminatorAttribute.getColumnValues() instanceof DiscriminatorColumnValues) ) { + throw new AssertionFailure( "Expected discriminator column values" ); + } + } + + private void bindPrimaryTable(EntityBinding entityBinding) { + final Schema schema = bindingContext.getMetadataImplementor().getDatabase().getSchema( schemaName ); + + AnnotationInstance tableAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), + JPADotNames.TABLE + ); + + String tableName = null; + if ( tableAnnotation != null ) { + String explicitTableName = JandexHelper.getValue( tableAnnotation, "name", String.class ); + if ( StringHelper.isNotEmpty( explicitTableName ) ) { + tableName = bindingContext.getNamingStrategy().tableName( explicitTableName ); + } + } + + // no explicit table name given, let's use the entity name as table name (taking inheritance into consideration + if ( StringHelper.isEmpty( tableName ) ) { + tableName = bindingContext.getNamingStrategy().classToTableName( entityClass.getClassNameForTable() ); + } + + org.hibernate.metamodel.relational.Table table = schema.locateOrCreateTable( Identifier.toIdentifier( tableName ) ); + entityBinding.setBaseTable( table ); + + AnnotationInstance checkAnnotation = JandexHelper.getSingleAnnotation( + entityClass.getClassInfo(), HibernateDotNames.CHECK + ); + if ( checkAnnotation != null ) { + table.addCheckConstraint( checkAnnotation.value( "constraints" ).asString() ); + } + } + private void bindTableUniqueConstraints(EntityBinding entityBinding) { AnnotationInstance tableAnnotation = JandexHelper.getSingleAnnotation( entityClass.getClassInfo(), @@ -149,12 +571,6 @@ public class EntityBinder { bindUniqueConstraints( tableAnnotation, table ); } - /** - * Bind {@link javax.persistence.UniqueConstraint} to table as a {@link UniqueKey} - * - * @param tableAnnotation JPA annotations which has a {@code uniqueConstraints} attribute. - * @param table Table which the UniqueKey bind to. - */ private void bindUniqueConstraints(AnnotationInstance tableAnnotation, TableSpecification table) { AnnotationValue value = tableAnnotation.value( "uniqueConstraints" ); if ( value == null ) { @@ -174,283 +590,6 @@ public class EntityBinder { } } - private void bindInheritance(EntityBinding entityBinding) { - entityBinding.setInheritanceType( entityClass.getInheritanceType() ); - switch ( entityClass.getInheritanceType() ) { - case SINGLE_TABLE: { - bindDiscriminatorColumn( entityBinding ); - break; - } - case JOINED: { - // todo - break; - } - case TABLE_PER_CLASS: { - // todo - break; - } - default: { - // do nothing - } - } - } - - private void bindDiscriminatorColumn(EntityBinding entityBinding) { - final Map> typeAnnotations = JandexHelper.getTypeAnnotations( - entityClass.getClassInfo() - ); - SimpleAttribute discriminatorAttribute = SimpleAttribute.createDiscriminatorAttribute( typeAnnotations ); - bindSingleMappedAttribute( entityBinding, entityBinding.getEntity(), discriminatorAttribute ); - } - - private void bindWhereFilter(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.WHERE - ); - if ( whereAnnotation != null ) { - // no null check needed, it is a required attribute - entityBindingState.setWhereFilter( JandexHelper.getValue( whereAnnotation, "clause", String.class ) ); - } - } - - private void bindHibernateCaching(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance cacheAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.CACHE - ); - if ( cacheAnnotation == null ) { - return; - } - - String region; - if ( cacheAnnotation.value( "region" ) != null ) { - region = cacheAnnotation.value( "region" ).asString(); - } - else { - region = entityBindingState.getEntityName(); - } - - boolean cacheLazyProperties = true; - if ( cacheAnnotation.value( "include" ) != null ) { - String tmp = cacheAnnotation.value( "include" ).asString(); - if ( "all".equalsIgnoreCase( tmp ) ) { - cacheLazyProperties = true; - } - else if ( "non-lazy".equalsIgnoreCase( tmp ) ) { - cacheLazyProperties = false; - } - else { - throw new AnnotationException( "Unknown lazy property annotations: " + tmp ); - } - } - - CacheConcurrencyStrategy strategy = CacheConcurrencyStrategy.valueOf( - cacheAnnotation.value( "usage" ).asEnum() - ); - Caching caching = new Caching( region, strategy.toAccessType(), cacheLazyProperties ); - entityBindingState.setCaching( caching ); - } - - // This does not take care of any inheritance of @Cacheable within a class hierarchy as specified in JPA2. - // This is currently not supported (HF) - private void bindJpaCaching(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance cacheAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), JPADotNames.CACHEABLE - ); - - boolean cacheable = true; // true is the default - if ( cacheAnnotation != null && cacheAnnotation.value() != null ) { - cacheable = cacheAnnotation.value().asBoolean(); - } - - Caching caching = null; - switch ( meta.getOptions().getSharedCacheMode() ) { - case ALL: { - caching = createCachingForCacheableAnnotation( entityBindingState ); - break; - } - case ENABLE_SELECTIVE: { - if ( cacheable ) { - caching = createCachingForCacheableAnnotation( entityBindingState ); - } - break; - } - case DISABLE_SELECTIVE: { - if ( cacheAnnotation == null || cacheable ) { - caching = createCachingForCacheableAnnotation( entityBindingState ); - } - break; - } - default: { - // treat both NONE and UNSPECIFIED the same - break; - } - } - if ( caching != null ) { - entityBindingState.setCaching( caching ); - } - } - - private void bindProxy(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance proxyAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.PROXY - ); - boolean lazy = true; - String proxyInterfaceClass = null; - - if ( proxyAnnotation != null ) { - AnnotationValue lazyValue = proxyAnnotation.value( "lazy" ); - if ( lazyValue != null ) { - lazy = lazyValue.asBoolean(); - } - - AnnotationValue proxyClassValue = proxyAnnotation.value( "proxyClass" ); - if ( proxyClassValue != null ) { - proxyInterfaceClass = proxyClassValue.asString(); - } - } - - entityBindingState.setLazy( lazy ); - entityBindingState.setProxyInterfaceName( proxyInterfaceClass ); - } - - private void bindSynchronize(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance synchronizeAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.SYNCHRONIZE - ); - - if ( synchronizeAnnotation != null ) { - String[] tableNames = synchronizeAnnotation.value().asStringArray(); - for ( String tableName : tableNames ) { - entityBindingState.addSynchronizedTableName( tableName ); - } - } - } - - private void bindCustomSQL(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance sqlInsertAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.SQL_INSERT - ); - entityBindingState.setCustomInsert( createCustomSQL( sqlInsertAnnotation ) ); - - AnnotationInstance sqlUpdateAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.SQL_UPDATE - ); - entityBindingState.setCustomUpdate( createCustomSQL( sqlUpdateAnnotation ) ); - - AnnotationInstance sqlDeleteAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.SQL_DELETE - ); - entityBindingState.setCustomDelete( createCustomSQL( sqlDeleteAnnotation ) ); - - AnnotationInstance sqlDeleteAllAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.SQL_DELETE_ALL - ); - if ( sqlDeleteAllAnnotation != null ) { - entityBindingState.setCustomDelete( createCustomSQL( sqlDeleteAllAnnotation ) ); - } - } - - private CustomSQL createCustomSQL(AnnotationInstance customSQLAnnotation) { - if ( customSQLAnnotation == null ) { - return null; - } - - String sql = customSQLAnnotation.value( "sql" ).asString(); - boolean isCallable = false; - AnnotationValue callableValue = customSQLAnnotation.value( "callable" ); - if ( callableValue != null ) { - isCallable = callableValue.asBoolean(); - } - - ResultCheckStyle checkStyle = ResultCheckStyle.NONE; - AnnotationValue checkStyleValue = customSQLAnnotation.value( "check" ); - if ( checkStyleValue != null ) { - checkStyle = Enum.valueOf( ResultCheckStyle.class, checkStyleValue.asEnum() ); - } - - return new CustomSQL( - sql, - isCallable, - Enum.valueOf( ExecuteUpdateResultCheckStyle.class, checkStyle.toString() ) - ); - } - - private void bindRowId(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance rowIdAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.ROW_ID - ); - - if ( rowIdAnnotation != null ) { - entityBindingState.setRowId( rowIdAnnotation.value().asString() ); - } - } - - private void bindBatchSize(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance batchSizeAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.BATCH_SIZE - ); - - if ( batchSizeAnnotation != null ) { - entityBindingState.setBatchSize( batchSizeAnnotation.value( "size" ).asInt() ); - } - } - - private Caching createCachingForCacheableAnnotation(AbstractEntityDescriptorImpl entityBindingState) { - String region = entityBindingState.getEntityName(); - RegionFactory regionFactory = meta.getServiceRegistry().getService( RegionFactory.class ); - AccessType defaultAccessType = regionFactory.getDefaultAccessType(); - return new Caching( region, defaultAccessType, true ); - } - - private Table createTable() { - String schemaName = null; - String catalogName = null; - String tableName = null; - - // is there an explicit @Table annotation? - AnnotationInstance tableAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), JPADotNames.TABLE - ); - if ( tableAnnotation != null ) { - schemaName = JandexHelper.getValue( tableAnnotation, "schema", String.class ); - catalogName = JandexHelper.getValue( tableAnnotation, "catalog", String.class ); - String explicitTableName = JandexHelper.getValue( tableAnnotation, "name", String.class ); - if ( StringHelper.isNotEmpty( explicitTableName ) ) { - tableName = meta.getNamingStrategy().tableName( explicitTableName ); - } - } - - // no explicit table name given, let's use the entity name as table name (taking inheritance into consideration - if ( StringHelper.isEmpty( tableName ) ) { - tableName = meta.getNamingStrategy().classToTableName( entityClass.getClassNameForTable() ); - } - - // check whether the names should be globally quoted - if ( meta.isGloballyQuotedIdentifiers() ) { - schemaName = StringHelper.quote( schemaName ); - catalogName = StringHelper.quote( catalogName ); - tableName = StringHelper.quote( tableName ); - } - - // last, but not least create the metamodel relational objects - final Identifier tableNameIdentifier = Identifier.toIdentifier( tableName ); - final Schema schema = meta.getDatabase().getSchema( new Schema.Name( schemaName, catalogName ) ); - return schema.locateOrCreateTable( tableNameIdentifier ); - } - - - private void bindTable(EntityBinding entityBinding) { - Table table = createTable(); - entityBinding.setBaseTable( table ); - - AnnotationInstance checkAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.CHECK - ); - if ( checkAnnotation != null ) { - table.addCheckConstraint( checkAnnotation.value( "constraints" ).asString() ); - } - } - private void bindId(EntityBinding entityBinding) { switch ( entityClass.getIdType() ) { case SIMPLE: { @@ -470,21 +609,6 @@ public class EntityBinder { } } - - private void bindJpaEntityAnnotation(AbstractEntityDescriptorImpl entityBindingState) { - AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), JPADotNames.ENTITY - ); - String name; - if ( jpaEntityAnnotation.value( "name" ) == null ) { - name = entityClass.getClass().getSimpleName(); - } - else { - name = jpaEntityAnnotation.value( "name" ).asString(); - } - entityBindingState.setJpaEntityName( name ); - } - private void bindEmbeddedIdAnnotation(EntityBinding entityBinding) { AnnotationInstance idAnnotation = JandexHelper.getSingleAnnotation( entityClass.getClassInfo(), JPADotNames.EMBEDDED_ID @@ -502,11 +626,13 @@ public class EntityBinder { SimpleAttributeBinding attributeBinding = entityBinding.makeSimpleIdAttributeBinding( attribute ); attributeBinding.initialize( new AttributeBindingStateImpl( (SimpleAttribute) idAttribute ) ); + attributeBinding.initialize( new ColumnRelationalStateImpl( (SimpleAttribute) idAttribute, bindingContext.getMetadataImplementor() ) ); + bindSingleIdGeneratedValue( entityBinding, idName ); TupleRelationalStateImpl state = new TupleRelationalStateImpl(); EmbeddableClass embeddableClass = entityClass.getEmbeddedClasses().get( idName ); for ( SimpleAttribute attr : embeddableClass.getSimpleAttributes() ) { - state.addValueState( new ColumnRelationalStateImpl( attr, meta ) ); + state.addValueState( new ColumnRelationalStateImpl( attr, bindingContext.getMetadataImplementor() ) ); } attributeBinding.initialize( state ); Map parms = new HashMap( 1 ); @@ -547,7 +673,7 @@ public class EntityBinder { SimpleAttributeBinding attributeBinding = entityBinding.makeSimpleIdAttributeBinding( attribute ); attributeBinding.initialize( new AttributeBindingStateImpl( (SimpleAttribute) idAttribute ) ); - attributeBinding.initialize( new ColumnRelationalStateImpl( (SimpleAttribute) idAttribute, meta ) ); + attributeBinding.initialize( new ColumnRelationalStateImpl( (SimpleAttribute) idAttribute, bindingContext.getMetadataImplementor() ) ); bindSingleIdGeneratedValue( entityBinding, idAttribute.getName() ); } @@ -572,7 +698,7 @@ public class EntityBinder { String generator = JandexHelper.getValue( generatedValueAnn, "generator", String.class ); IdGenerator idGenerator = null; if ( StringHelper.isNotEmpty( generator ) ) { - idGenerator = meta.getIdGenerator( generator ); + idGenerator = bindingContext.getMetadataImplementor().getIdGenerator( generator ); if ( idGenerator == null ) { throw new MappingException( String.format( @@ -592,7 +718,7 @@ public class EntityBinder { ); String strategy = IdGeneratorBinder.generatorType( generationType, - meta.getOptions().useNewIdentifierGenerators() + bindingContext.getMetadataImplementor().getOptions().useNewIdentifierGenerators() ); if ( idGenerator != null && !strategy.equals( idGenerator.getStrategy() ) ) { //todo how to ? @@ -645,16 +771,11 @@ public class EntityBinder { ConfiguredClassType.NON_ENTITY.equals( parent.getConfiguredClassType() ) ); } - /** - * Creates attribute bindings for the attributes of {@code configuredClass} - * - * @param entityBinding The entity binding for the class we are currently binding - * @param attributeContainer The domain attribute container to which to add the attribute (could be the entity itself, or a mapped super class - * or a component) - * @param configuredClass the configured containing the attributes to be bound - * @param attributeOverrideMap a map with the accumulated attribute overrides - */ - private void bindAttributes(EntityBinding entityBinding, AttributeContainer attributeContainer, ConfiguredClass configuredClass, Map attributeOverrideMap) { + private void bindAttributes( + EntityBinding entityBinding, + AttributeContainer attributeContainer, + ConfiguredClass configuredClass, + Map attributeOverrideMap) { for ( SimpleAttribute simpleAttribute : configuredClass.getSimpleAttributes() ) { String attributeName = simpleAttribute.getName(); @@ -693,7 +814,10 @@ public class EntityBinder { } } - private void bindEmbeddedAttributes(EntityBinding entityBinding, AttributeContainer attributeContainer, ConfiguredClass configuredClass) { + private void bindEmbeddedAttributes( + EntityBinding entityBinding, + AttributeContainer attributeContainer, + ConfiguredClass configuredClass) { for ( Map.Entry entry : configuredClass.getEmbeddedClasses().entrySet() ) { String attributeName = entry.getKey(); EmbeddableClass embeddedClass = entry.getValue(); @@ -715,7 +839,10 @@ public class EntityBinder { } } - private void bindAssociationAttribute(EntityBinding entityBinding, AttributeContainer container, AssociationAttribute associationAttribute) { + private void bindAssociationAttribute( + EntityBinding entityBinding, + AttributeContainer container, + AssociationAttribute associationAttribute) { switch ( associationAttribute.getAssociationType() ) { case MANY_TO_ONE: { container.getOrCreateSingularAttribute( associationAttribute.getName() ); @@ -729,7 +856,7 @@ public class EntityBinder { ManyToOneRelationalStateImpl relationalState = new ManyToOneRelationalStateImpl(); if ( entityClass.hasOwnTable() ) { ColumnRelationalStateImpl columnRelationsState = new ColumnRelationalStateImpl( - associationAttribute, meta + associationAttribute, bindingContext.getMetadataImplementor() ); relationalState.addValueState( columnRelationsState ); } @@ -742,7 +869,10 @@ public class EntityBinder { } } - private void bindSingleMappedAttribute(EntityBinding entityBinding, AttributeContainer container, SimpleAttribute simpleAttribute) { + private void bindSingleMappedAttribute( + EntityBinding entityBinding, + AttributeContainer container, + SimpleAttribute simpleAttribute) { if ( simpleAttribute.isId() ) { return; } @@ -769,7 +899,7 @@ public class EntityBinder { if ( entityClass.hasOwnTable() ) { ColumnRelationalStateImpl columnRelationsState = new ColumnRelationalStateImpl( - simpleAttribute, meta + simpleAttribute, bindingContext.getMetadataImplementor() ); TupleRelationalStateImpl relationalState = new TupleRelationalStateImpl(); relationalState.addValueState( columnRelationsState ); @@ -778,66 +908,5 @@ public class EntityBinder { } } - private void bindHibernateEntityAnnotation(AbstractEntityDescriptorImpl entityBindingState) { - // initialize w/ the defaults - boolean mutable = true; - boolean dynamicInsert = false; - boolean dynamicUpdate = false; - boolean selectBeforeUpdate = false; - PolymorphismType polymorphism = PolymorphismType.IMPLICIT; - OptimisticLockType optimisticLock = OptimisticLockType.VERSION; - - AnnotationInstance hibernateEntityAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.ENTITY - ); - - if ( hibernateEntityAnnotation != null ) { - if ( hibernateEntityAnnotation.value( "mutable" ) != null ) { - mutable = hibernateEntityAnnotation.value( "mutable" ).asBoolean(); - } - - if ( hibernateEntityAnnotation.value( "dynamicInsert" ) != null ) { - dynamicInsert = hibernateEntityAnnotation.value( "dynamicInsert" ).asBoolean(); - } - - if ( hibernateEntityAnnotation.value( "dynamicUpdate" ) != null ) { - dynamicUpdate = hibernateEntityAnnotation.value( "dynamicUpdate" ).asBoolean(); - } - - if ( hibernateEntityAnnotation.value( "selectBeforeUpdate" ) != null ) { - selectBeforeUpdate = hibernateEntityAnnotation.value( "selectBeforeUpdate" ).asBoolean(); - } - - if ( hibernateEntityAnnotation.value( "polymorphism" ) != null ) { - polymorphism = PolymorphismType.valueOf( hibernateEntityAnnotation.value( "polymorphism" ).asEnum() ); - } - - if ( hibernateEntityAnnotation.value( "optimisticLock" ) != null ) { - optimisticLock = OptimisticLockType.valueOf( - hibernateEntityAnnotation.value( "optimisticLock" ).asEnum() - ); - } - - if ( hibernateEntityAnnotation.value( "persister" ) != null ) { - final String persisterClassName = ( hibernateEntityAnnotation.value( "persister" ).toString() ); - entityBindingState.setPersisterClass( meta.locateClassByName( persisterClassName ) ); - } - } - - // also check for the immutable annotation - AnnotationInstance immutableAnnotation = JandexHelper.getSingleAnnotation( - entityClass.getClassInfo(), HibernateDotNames.IMMUTABLE - ); - if ( immutableAnnotation != null ) { - mutable = false; - } - - entityBindingState.setMutable( mutable ); - entityBindingState.setDynamicInsert( dynamicInsert ); - entityBindingState.setDynamicUpdate( dynamicUpdate ); - entityBindingState.setSelectBeforeUpdate( selectBeforeUpdate ); - entityBindingState.setExplicitPolymorphism( PolymorphismType.EXPLICIT.equals( polymorphism ) ); - entityBindingState.setOptimisticLock( optimisticLock ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/AbstractEntityDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/AbstractEntityDescriptorImpl.java deleted file mode 100644 index 1772352778..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/AbstractEntityDescriptorImpl.java +++ /dev/null @@ -1,316 +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.binder.source.hbm; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.EntityMode; -import org.hibernate.metamodel.binder.Origin; -import org.hibernate.metamodel.binder.source.EntityDescriptor; -import org.hibernate.metamodel.binder.source.MetaAttributeContext; -import org.hibernate.metamodel.binder.source.UnifiedDescriptorObject; -import org.hibernate.metamodel.binder.source.hbm.xml.mapping.EntityElement; -import org.hibernate.metamodel.binding.CustomSQL; -import org.hibernate.metamodel.binding.InheritanceType; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLTuplizerElement; -import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.tuple.entity.EntityTuplizer; - -/** - * Convenience base class for handling commonality between the different type of {@link EntityDescriptor} - * implementations. - * - * @author Gail Badner - * @author Steve Ebersole - */ -public abstract class AbstractEntityDescriptorImpl implements EntityDescriptor { - private final HbmBindingContext bindingContext; - - private final String entityName; - private final EntityMode entityMode; - - private final String className; - private final String proxyInterfaceName; - - private final Class entityPersisterClass; - private final Class tuplizerClass; - - private final MetaAttributeContext metaAttributeContext; - - private final String superEntityName; - private final InheritanceType entityInheritanceType; - - private final boolean lazy; - - private final boolean dynamicUpdate; - private final boolean dynamicInsert; - - private final int batchSize; - private final boolean selectBeforeUpdate; - - private final Boolean isAbstract; - - private final String customLoaderName; - private final CustomSQL customInsert; - private final CustomSQL customUpdate; - private final CustomSQL customDelete; - - private final Set synchronizedTableNames; - - - public AbstractEntityDescriptorImpl( - EntityElement entityClazz, - String superEntityName, - InheritanceType inheritanceType, - HbmBindingContext bindingContext) { - - this.bindingContext = bindingContext; - - this.superEntityName = superEntityName; - this.entityName = bindingContext.determineEntityName( entityClazz ); - - final String verbatimClassName = entityClazz.getName(); - this.entityMode = verbatimClassName == null ? EntityMode.MAP : EntityMode.POJO; - - if ( this.entityMode == EntityMode.POJO ) { - this.className = bindingContext.qualifyClassName( verbatimClassName ); - this.proxyInterfaceName = entityClazz.getProxy(); - } - else { - this.className = null; - this.proxyInterfaceName = null; - } - - final String customTuplizerClassName = extractCustomTuplizerClassName( entityClazz, entityMode ); - this.tuplizerClass = customTuplizerClassName != null - ? bindingContext.locateClassByName( customTuplizerClassName ) - : null; - this.entityPersisterClass = entityClazz.getPersister() == null - ? null - : bindingContext.locateClassByName( entityClazz.getPersister() ); - - this.entityInheritanceType = inheritanceType; - - - this.metaAttributeContext = HbmHelper.extractMetaAttributeContext( - entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext() - ); - - // go ahead and set the lazy here, since pojo.proxy can override it. - this.lazy = MappingHelper.getBooleanValue( - entityClazz.isLazy(), bindingContext.getMappingDefaults().areAssociationsLazy() - ); - - this.dynamicUpdate = entityClazz.isDynamicUpdate(); - this.dynamicInsert = entityClazz.isDynamicInsert(); - this.batchSize = MappingHelper.getIntValue( entityClazz.getBatchSize(), 0 ); - this.selectBeforeUpdate = entityClazz.isSelectBeforeUpdate(); - - this.customLoaderName = entityClazz.getLoader().getQueryRef(); - - XMLSqlInsertElement sqlInsert = entityClazz.getSqlInsert(); - if ( sqlInsert != null ) { - this.customInsert = HbmHelper.getCustomSql( - sqlInsert.getValue(), - sqlInsert.isCallable(), - sqlInsert.getCheck().value() - ); - } - else { - this.customInsert = null; - } - - XMLSqlDeleteElement sqlDelete = entityClazz.getSqlDelete(); - if ( sqlDelete != null ) { - this.customDelete = HbmHelper.getCustomSql( - sqlDelete.getValue(), - sqlDelete.isCallable(), - sqlDelete.getCheck().value() - ); - } - else { - this.customDelete = null; - } - - XMLSqlUpdateElement sqlUpdate = entityClazz.getSqlUpdate(); - if ( sqlUpdate != null ) { - this.customUpdate = HbmHelper.getCustomSql( - sqlUpdate.getValue(), - sqlUpdate.isCallable(), - sqlUpdate.getCheck().value() - ); - } - else { - this.customUpdate = null; - } - - if ( entityClazz.getSynchronize() != null ) { - this.synchronizedTableNames = new HashSet( entityClazz.getSynchronize().size() ); - for ( XMLSynchronizeElement synchronize : entityClazz.getSynchronize() ) { - this.synchronizedTableNames.add( synchronize.getTable() ); - } - } - else { - this.synchronizedTableNames = null; - } - - this.isAbstract = entityClazz.isAbstract(); - } - - protected boolean isRoot() { - return entityInheritanceType == InheritanceType.NO_INHERITANCE; - } - - private String extractCustomTuplizerClassName(EntityElement entityMapping, EntityMode entityMode) { - if ( entityMapping.getTuplizer() == null ) { - return null; - } - for ( XMLTuplizerElement tuplizerElement : entityMapping.getTuplizer() ) { - if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) { - return tuplizerElement.getClazz(); - } - } - return null; - } - - @Override - public String getEntityName() { - return entityName; - } - - @Override - public String getJpaEntityName() { - return null; // no such notion in hbm.xml files - } - - @Override - public EntityMode getEntityMode() { - return entityMode; - } - - @Override - public String getClassName() { - return className; - } - - @Override - public String getProxyInterfaceName() { - return proxyInterfaceName; - } - - @Override - public Class getCustomEntityPersisterClass() { - return entityPersisterClass; - } - - @Override - public Class getCustomEntityTuplizerClass() { - return tuplizerClass; - } - - @Override - public String getSuperEntityName() { - return superEntityName; - } - - @Override - public InheritanceType getEntityInheritanceType() { - return entityInheritanceType; - } - - @Override - public MetaAttributeContext getMetaAttributeContext() { - return metaAttributeContext; - } - - @Override - public boolean isLazy() { - return lazy; - } - - @Override - public boolean isDynamicUpdate() { - return dynamicUpdate; - } - - @Override - public boolean isDynamicInsert() { - return dynamicInsert; - } - - @Override - public int getBatchSize() { - return batchSize; - } - - @Override - public boolean isSelectBeforeUpdate() { - return selectBeforeUpdate; - } - - @Override - public Boolean isAbstract() { - return isAbstract; - } - - @Override - public CustomSQL getCustomInsert() { - return customInsert; - } - - @Override - public CustomSQL getCustomUpdate() { - return customUpdate; - } - - @Override - public CustomSQL getCustomDelete() { - return customDelete; - } - - @Override - public Set getSynchronizedTableNames() { - return synchronizedTableNames; - } - - @Override - public String getCustomLoaderName() { - return customLoaderName; - } - - @Override - public UnifiedDescriptorObject getContainingDescriptor() { - return null; - } - - @Override - public Origin getOrigin() { - return bindingContext.getOrigin(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/BindingCreator.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/BindingCreator.java index e52cb3fccb..2148e1172c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/BindingCreator.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/BindingCreator.java @@ -23,6 +23,7 @@ */ package org.hibernate.metamodel.binder.source.hbm; +import java.util.List; import java.util.Map; import org.hibernate.EntityMode; @@ -54,12 +55,27 @@ import org.hibernate.tuple.entity.EntityTuplizer; */ public class BindingCreator { private final HbmBindingContext bindingContext; + private final List processedEntityNames; - public BindingCreator(HbmBindingContext bindingContext) { + public BindingCreator(HbmBindingContext bindingContext, List processedEntityNames) { this.bindingContext = bindingContext; + this.processedEntityNames = processedEntityNames; } public EntityBinding createEntityBinding(EntityElement entityElement, String containingSuperEntityName) { + final String entityName = bindingContext.determineEntityName( entityElement ); + if ( processedEntityNames.contains( entityName ) ) { + return bindingContext.getMetadataImplementor().getEntityBinding( entityName ); + } + + final EntityBinding entityBinding = doEntityBindingCreation( entityElement, containingSuperEntityName ); + + bindingContext.getMetadataImplementor().addEntity( entityBinding ); + processedEntityNames.add( entityBinding.getEntity().getName() ); + return entityBinding; + } + + private EntityBinding doEntityBindingCreation(EntityElement entityElement, String containingSuperEntityName) { if ( XMLHibernateMapping.XMLClass.class.isInstance( entityElement ) ) { return makeEntityBinding( (XMLHibernateMapping.XMLClass) entityElement ); } @@ -97,7 +113,11 @@ public class BindingCreator { protected EntityBinding makeEntityBinding(XMLHibernateMapping.XMLClass xmlClass) { final EntityBinding entityBinding = new EntityBinding(); + // todo : this is actually not correct + // the problem is that we need to know whether we have mapped subclasses which happens later + // one option would be to simply reset the InheritanceType at that time. entityBinding.setInheritanceType( InheritanceType.NO_INHERITANCE ); + entityBinding.setRoot( true ); final String entityName = bindingContext.determineEntityName( xmlClass ); final String verbatimClassName = xmlClass.getName(); @@ -140,7 +160,7 @@ public class BindingCreator { } private OptimisticLockStyle interpretOptimisticLockStyle(XMLHibernateMapping.XMLClass entityClazz) { - final String optimisticLockModeString = MappingHelper.getStringValue( + final String optimisticLockModeString = Helper.getStringValue( entityClazz.getOptimisticLock(), "version" ); @@ -245,14 +265,16 @@ public class BindingCreator { entityBinding.setJpaEntityName( null ); final String proxy = entityElement.getProxy(); - final Boolean isLazy = entityElement.isLazy(); + final boolean isLazy = entityElement.isLazy() == null + ? true + : entityElement.isLazy(); if ( entityBinding.getEntityMode() == EntityMode.POJO ) { if ( proxy != null ) { - entityBinding.setProxyInterfaceType( bindingContext.makeClassReference( - bindingContext.qualifyClassName( - proxy + entityBinding.setProxyInterfaceType( + bindingContext.makeClassReference( + bindingContext.qualifyClassName( proxy ) ) - ) ); + ); entityBinding.setLazy( true ); } else if ( isLazy ) { @@ -275,50 +297,34 @@ public class BindingCreator { } entityBinding.setMetaAttributeContext( - HbmHelper.extractMetaAttributeContext( + Helper.extractMetaAttributeContext( entityElement.getMeta(), true, bindingContext.getMetaAttributeContext() ) ); entityBinding.setDynamicUpdate( entityElement.isDynamicUpdate() ); entityBinding.setDynamicInsert( entityElement.isDynamicInsert() ); - entityBinding.setBatchSize( MappingHelper.getIntValue( entityElement.getBatchSize(), 0 ) ); + entityBinding.setBatchSize( Helper.getIntValue( entityElement.getBatchSize(), 0 ) ); entityBinding.setSelectBeforeUpdate( entityElement.isSelectBeforeUpdate() ); entityBinding.setAbstract( entityElement.isAbstract() ); - entityBinding.setCustomLoaderName( entityElement.getLoader().getQueryRef() ); + if ( entityElement.getLoader() != null ) { + entityBinding.setCustomLoaderName( entityElement.getLoader().getQueryRef() ); + } final XMLSqlInsertElement sqlInsert = entityElement.getSqlInsert(); if ( sqlInsert != null ) { - entityBinding.setCustomInsert( - HbmHelper.getCustomSql( - sqlInsert.getValue(), - sqlInsert.isCallable(), - sqlInsert.getCheck().value() - ) - ); + entityBinding.setCustomInsert( Helper.buildCustomSql( sqlInsert ) ); } final XMLSqlDeleteElement sqlDelete = entityElement.getSqlDelete(); if ( sqlDelete != null ) { - entityBinding.setCustomDelete( - HbmHelper.getCustomSql( - sqlDelete.getValue(), - sqlDelete.isCallable(), - sqlDelete.getCheck().value() - ) - ); + entityBinding.setCustomDelete( Helper.buildCustomSql( sqlDelete ) ); } final XMLSqlUpdateElement sqlUpdate = entityElement.getSqlUpdate(); if ( sqlUpdate != null ) { - entityBinding.setCustomUpdate( - HbmHelper.getCustomSql( - sqlUpdate.getValue(), - sqlUpdate.isCallable(), - sqlUpdate.getCheck().value() - ) - ); + entityBinding.setCustomUpdate( Helper.buildCustomSql( sqlUpdate ) ); } if ( entityElement.getSynchronize() != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/DiscriminatedSubClassEntityDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/DiscriminatedSubClassEntityDescriptorImpl.java deleted file mode 100644 index 4efbfe0d3d..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/DiscriminatedSubClassEntityDescriptorImpl.java +++ /dev/null @@ -1,79 +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.binder.source.hbm; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.binder.MappingException; -import org.hibernate.metamodel.binder.source.DiscriminatorSubClassEntityDescriptor; -import org.hibernate.metamodel.binder.source.hbm.xml.mapping.EntityElement; -import org.hibernate.metamodel.binding.InheritanceType; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSubclassElement; - -/** - * Unified descriptor for discriminator-based inheritance strategies. - * - * @author Steve Ebersole - */ -public class DiscriminatedSubClassEntityDescriptorImpl - extends AbstractEntityDescriptorImpl - implements DiscriminatorSubClassEntityDescriptor { - /** - * This form used when an explicit {@code extends} attribute names this mapping's super entity. - * - * @param entityClazz The JAXB entity mapping - * @param bindingContext The context for the binding process. - */ - public DiscriminatedSubClassEntityDescriptorImpl( - EntityElement entityClazz, - HbmBindingContext bindingContext) { - this( entityClazz, extractExtendsName( entityClazz, bindingContext ), bindingContext ); - } - - private static String extractExtendsName(EntityElement entityClazz, HbmBindingContext bindingContext) { - final String extendsName = ( (XMLSubclassElement) entityClazz ).getExtends(); - if ( StringHelper.isEmpty( extendsName ) ) { - throw new MappingException( - "Subclass entity mapping [" + bindingContext.determineEntityName( entityClazz ) - + "] was not contained in super entity mapping", - bindingContext.getOrigin() - ); - } - return extendsName; - } - - /** - * This form would be used when the subclass definition if nested within its super type mapping. - * - * @param entityClazz The JAXB entity mapping - * @param superEntityName The name of the containing (and thus super) entity - * @param bindingContext The context for the binding process. - */ - public DiscriminatedSubClassEntityDescriptorImpl( - EntityElement entityClazz, - String superEntityName, - HbmBindingContext bindingContext) { - super( entityClazz, superEntityName, InheritanceType.SINGLE_TABLE, bindingContext ); - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HbmHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HbmHelper.java deleted file mode 100644 index 0498b789a7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HbmHelper.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2010, 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.binder.source.hbm; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.dom4j.Attribute; -import org.dom4j.Element; - -import org.hibernate.MappingException; -import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; -import org.hibernate.metamodel.binder.source.MetaAttributeContext; -import org.hibernate.metamodel.binder.source.hbm.xml.mapping.EntityElement; -import org.hibernate.metamodel.binding.CustomSQL; -import org.hibernate.metamodel.binding.MetaAttribute; -import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLHibernateMapping; -import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLMetaElement; - -/** - * @author Steve Ebersole - */ -public class HbmHelper { - - // todo : merge this and MappingHelper together - - public static boolean isCallable(Element e) { - return isCallable( e, true ); - } - - public static boolean isCallable(Element element, boolean supportsCallable) { - Attribute attrib = element.attribute( "callable" ); - if ( attrib != null && "true".equals( attrib.getValue() ) ) { - if ( !supportsCallable ) { - throw new MappingException( "callable attribute not supported yet!" ); - } - return true; - } - return false; - } - - public static ExecuteUpdateResultCheckStyle getResultCheckStyle(String check, boolean callable) { - if ( check == null ) { - // use COUNT as the default. This mimics the old behavior, although - // NONE might be a better option moving forward in the case of callable - return ExecuteUpdateResultCheckStyle.COUNT; - } - return ExecuteUpdateResultCheckStyle.fromExternalName( check ); - } - - public static final Map extractMetas(List meta, Map baseline) { - return extractMetas( meta, false, baseline ); - } - - public static final Map extractMetas(List metaList, boolean onlyInheritable, Map baseline) { - Map extractedMetas = new HashMap(); - extractedMetas.putAll( baseline ); - for ( XMLMetaElement meta : metaList ) { - boolean inheritable = meta.isInherit(); - if ( onlyInheritable & !inheritable ) { - continue; - } - - final String name = meta.getAttribute(); - final MetaAttribute inheritedMetaAttribute = baseline.get( name ); - MetaAttribute metaAttribute = extractedMetas.get( name ); - if ( metaAttribute == null || metaAttribute == inheritedMetaAttribute ) { - metaAttribute = new MetaAttribute( name ); - extractedMetas.put( name, metaAttribute ); - } - metaAttribute.addValue( meta.getValue() ); - } - return extractedMetas; - } - - public static String extractEntityName(XMLHibernateMapping.XMLClass entityClazz, String unqualifiedPackageName) { - return extractEntityName( entityClazz.getEntityName(), entityClazz.getName(), unqualifiedPackageName ); - } - - public static String extractEntityName(String entityName, String entityClassName, String unqualifiedPackageName) { - return entityName == null ? getClassName( entityClassName, unqualifiedPackageName ) : entityName; - } - - public static String determineEntityName(EntityElement entityElement, String packageName) { - return extractEntityName( entityElement.getEntityName(), entityElement.getName(), packageName ); - } - - public static String determineClassName(EntityElement entityElement, String packageName) { - return getClassName( entityElement.getName(), packageName ); - } - - public static String getClassName(Attribute att, String unqualifiedPackageName) { - if ( att == null ) { - return null; - } - return getClassName( att.getValue(), unqualifiedPackageName ); - } - - public static String getClassName(String unqualifiedName, String unqualifiedPackageName) { - if ( unqualifiedName == null ) { - return null; - } - if ( unqualifiedName.indexOf( '.' ) < 0 && unqualifiedPackageName != null ) { - return unqualifiedPackageName + '.' + unqualifiedName; - } - return unqualifiedName; - } - - public static CustomSQL getCustomSql(String sql, boolean isCallable, String check) { - return new CustomSQL( sql.trim(), isCallable, getResultCheckStyle( check, isCallable ) ); - } - - public static String getPropertyAccessorName(String access, boolean isEmbedded, String defaultAccess) { - return MappingHelper.getStringValue( - access, - isEmbedded ? "embedded" : defaultAccess - ); - } - - public static MetaAttributeContext extractMetaAttributeContext( - List metaElementList, - MetaAttributeContext parentContext) { - return extractMetaAttributeContext( metaElementList, false, parentContext ); - } - - public static MetaAttributeContext extractMetaAttributeContext( - List metaElementList, - boolean onlyInheritable, - MetaAttributeContext parentContext) { - final MetaAttributeContext subContext = new MetaAttributeContext( parentContext ); - - for ( XMLMetaElement metaElement : metaElementList ) { - if ( onlyInheritable & !metaElement.isInherit() ) { - continue; - } - - final String name = metaElement.getAttribute(); - final MetaAttribute inheritedMetaAttribute = parentContext.getMetaAttribute( name ); - MetaAttribute metaAttribute = subContext.getLocalMetaAttribute( name ); - if ( metaAttribute == null || metaAttribute == inheritedMetaAttribute ) { - metaAttribute = new MetaAttribute( name ); - subContext.add( metaAttribute ); - } - metaAttribute.addValue( metaElement.getValue() ); - } - - return subContext; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/Helper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/Helper.java new file mode 100644 index 0000000000..795ff4a813 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/Helper.java @@ -0,0 +1,176 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, 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.binder.source.hbm; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; + +import org.hibernate.MappingException; +import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; +import org.hibernate.metamodel.binder.source.MetaAttributeContext; +import org.hibernate.metamodel.binder.source.hbm.xml.mapping.CustomSqlElement; +import org.hibernate.metamodel.binder.source.hbm.xml.mapping.EntityElement; +import org.hibernate.metamodel.binding.CustomSQL; +import org.hibernate.metamodel.binding.MetaAttribute; +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.classloading.spi.ClassLoaderService; +import org.hibernate.service.classloading.spi.ClassLoadingException; + +/** + * @author Steve Ebersole + * @author Gail Badner + */ +public class Helper { + + /** + * Given a user-specified description of how to perform custom SQL, build the {@link CustomSQL} representation. + * + * @param customSqlElement User-specified description of how to perform custom SQL + * + * @return The {@link CustomSQL} representation + */ + public static CustomSQL buildCustomSql(CustomSqlElement customSqlElement) { + if ( customSqlElement == null ) { + return null; + } + final ExecuteUpdateResultCheckStyle checkStyle = customSqlElement.getCheck() == null + ? customSqlElement.isCallable() + ? ExecuteUpdateResultCheckStyle.NONE + : ExecuteUpdateResultCheckStyle.COUNT + : ExecuteUpdateResultCheckStyle.fromExternalName( customSqlElement.getCheck().value() ); + return new CustomSQL( customSqlElement.getValue(), customSqlElement.isCallable(), checkStyle ); + } + + /** + * Given the user-specified entity mapping, determine the appropriate entity name + * + * @param entityElement The user-specified entity mapping + * @param unqualifiedClassPackage The package to use for unqualified class names + * + * @return The appropriate entity name + */ + public static String determineEntityName(EntityElement entityElement, String unqualifiedClassPackage) { + return entityElement.getEntityName() != null + ? entityElement.getEntityName() + : qualifyIfNeeded( entityElement.getName(), unqualifiedClassPackage ); + } + + /** + * Qualify a (supposed class) name with the unqualified-class package name if it is not already qualified + * + * @param name The name + * @param unqualifiedClassPackage The unqualified-class package name + * + * @return {@code null} if the incoming name was {@code null}; or the qualified name. + */ + public static String qualifyIfNeeded(String name, String unqualifiedClassPackage) { + if ( name == null ) { + return null; + } + if ( name.indexOf( '.' ) < 0 && unqualifiedClassPackage != null ) { + return unqualifiedClassPackage + '.' + name; + } + return name; + } + + public static String getPropertyAccessorName(String access, boolean isEmbedded, String defaultAccess) { + return getStringValue( access, isEmbedded ? "embedded" : defaultAccess ); + } + + public static MetaAttributeContext extractMetaAttributeContext( + List metaElementList, + MetaAttributeContext parentContext) { + return extractMetaAttributeContext( metaElementList, false, parentContext ); + } + + public static MetaAttributeContext extractMetaAttributeContext( + List metaElementList, + boolean onlyInheritable, + MetaAttributeContext parentContext) { + final MetaAttributeContext subContext = new MetaAttributeContext( parentContext ); + + for ( XMLMetaElement metaElement : metaElementList ) { + if ( onlyInheritable & !metaElement.isInherit() ) { + continue; + } + + final String name = metaElement.getAttribute(); + final MetaAttribute inheritedMetaAttribute = parentContext.getMetaAttribute( name ); + MetaAttribute metaAttribute = subContext.getLocalMetaAttribute( name ); + if ( metaAttribute == null || metaAttribute == inheritedMetaAttribute ) { + metaAttribute = new MetaAttribute( name ); + subContext.add( metaAttribute ); + } + metaAttribute.addValue( metaElement.getValue() ); + } + + return subContext; + } + + public static String getStringValue(String value, String defaultValue) { + return value == null ? defaultValue : value; + } + + public static int getIntValue(String value, int defaultValue) { + return value == null ? defaultValue : Integer.parseInt( value ); + } + + public static boolean getBooleanValue(String value, boolean defaultValue) { + return value == null ? defaultValue : Boolean.valueOf( value ); + } + + public static boolean getBooleanValue(Boolean value, boolean defaultValue) { + return value == null ? defaultValue : value; + } + + public static Set getStringValueTokens(String str, String delimiters) { + if ( str == null ) { + return Collections.emptySet(); + } + else { + StringTokenizer tokenizer = new StringTokenizer( str, delimiters ); + Set tokens = new HashSet(); + while ( tokenizer.hasMoreTokens() ) { + tokens.add( tokenizer.nextToken() ); + } + return tokens; + } + } + + // todo : remove this once the state objects are cleaned up + + public static Class classForName(String className, ServiceRegistry serviceRegistry) { + ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); + try { + return classLoaderService.classForName( className ); + } + catch ( ClassLoadingException e ) { + throw new MappingException( "Could not find class: " + className ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HibernateMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HibernateMappingProcessor.java index 0d8c5af3bd..616d054b3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HibernateMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/HibernateMappingProcessor.java @@ -76,9 +76,6 @@ public class HibernateMappingProcessor implements HbmBindingContext { private final MappingDefaults mappingDefaults; private final MetaAttributeContext metaAttributeContext; - - private final BindingCreator bindingCreator; - private final boolean autoImport; public HibernateMappingProcessor(HbmSourceProcessorImpl hbmHandler, JaxbRoot jaxbRoot) { @@ -99,16 +96,18 @@ public class HibernateMappingProcessor implements HbmBindingContext { ); this.autoImport = hibernateMapping.isAutoImport(); - - this.bindingCreator = new BindingCreator( this ); - this.metaAttributeContext = extractMetaAttributes(); } private MetaAttributeContext extractMetaAttributes() { return hibernateMapping.getMeta() == null ? new MetaAttributeContext( hbmHandler.getMetadataImplementor().getGlobalMetaAttributeContext() ) - : HbmHelper.extractMetaAttributeContext( hibernateMapping.getMeta(), true, hbmHandler.getMetadataImplementor().getGlobalMetaAttributeContext() ); + : Helper.extractMetaAttributeContext( + hibernateMapping.getMeta(), + true, + hbmHandler.getMetadataImplementor() + .getGlobalMetaAttributeContext() + ); } XMLHibernateMapping getHibernateMapping() { @@ -289,17 +288,11 @@ public class HibernateMappingProcessor implements HbmBindingContext { return; } + final BindingCreator bindingCreator = new BindingCreator( this, processedEntityNames ); + for ( Object entityElementO : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) { final EntityElement entityElement = (EntityElement) entityElementO; - - final String entityName = this.determineEntityName( entityElement ); - if ( processedEntityNames.contains( entityName ) ) { - continue; - } - - final EntityBinding entityBinding = bindingCreator.createEntityBinding( entityElement, null ); - getMetadataImplementor().addEntity( entityBinding ); - processedEntityNames.add( entityBinding.getEntity().getName() ); + bindingCreator.createEntityBinding( entityElement, null ); } } @@ -386,11 +379,11 @@ public class HibernateMappingProcessor implements HbmBindingContext { @Override public String qualifyClassName(String unqualifiedName) { - return HbmHelper.getClassName( unqualifiedName, mappingDefaults.getPackageName() ); + return Helper.qualifyIfNeeded( unqualifiedName, mappingDefaults.getPackageName() ); } @Override public String determineEntityName(EntityElement entityElement) { - return HbmHelper.determineEntityName( entityElement, mappingDefaults.getPackageName() ); + return Helper.determineEntityName( entityElement, mappingDefaults.getPackageName() ); } } \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/JoinedSubClassEntityDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/JoinedSubClassEntityDescriptorImpl.java deleted file mode 100644 index 81a7854abd..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/JoinedSubClassEntityDescriptorImpl.java +++ /dev/null @@ -1,80 +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.binder.source.hbm; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.binder.MappingException; -import org.hibernate.metamodel.binder.source.JoinedSubClassEntityDescriptor; -import org.hibernate.metamodel.binder.source.hbm.xml.mapping.EntityElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLJoinedSubclassElement; - -import static org.hibernate.metamodel.binding.InheritanceType.JOINED; - -/** - * Unified descriptor for (SQL) join-based inheritance strategies. - * - * @author Steve Ebersole - */ -public class JoinedSubClassEntityDescriptorImpl - extends AbstractEntityDescriptorImpl - implements JoinedSubClassEntityDescriptor { - - /** - * This form used when an explicit {@code extends} attribute names this mapping's super entity. - * - * @param entityClazz The JAXB entity mapping - * @param bindingContext The context for the binding process. - */ - public JoinedSubClassEntityDescriptorImpl( - EntityElement entityClazz, - HbmBindingContext bindingContext) { - this( entityClazz, extractExtendsName( entityClazz, bindingContext ), bindingContext ); - } - - private static String extractExtendsName(EntityElement entityClazz, HbmBindingContext bindingContext) { - final String extendsName = ( (XMLJoinedSubclassElement) entityClazz ).getExtends(); - if ( StringHelper.isEmpty( extendsName ) ) { - throw new MappingException( - "Subclass entity mapping [" + bindingContext.determineEntityName( entityClazz ) - + "] was not contained in super entity mapping", - bindingContext.getOrigin() - ); - } - return extendsName; - } - - /** - * This form would be used when the subclass definition if nested within its super type mapping. - * - * @param entityClazz The JAXB entity mapping - * @param superEntityName The name of the containing (and thus super) entity - * @param bindingContext The context for the binding process. - */ - public JoinedSubClassEntityDescriptorImpl( - EntityElement entityClazz, - String superEntityName, - HbmBindingContext bindingContext) { - super( entityClazz, superEntityName, JOINED, bindingContext ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/MappingHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/MappingHelper.java deleted file mode 100644 index 79d3aa2828..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/MappingHelper.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.binder.source.hbm; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.StringTokenizer; - -import org.hibernate.MappingException; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.service.classloading.spi.ClassLoaderService; -import org.hibernate.service.classloading.spi.ClassLoadingException; - -/** - * Helper class. - * - * @author Gail Badner - */ -public class MappingHelper { - - // todo : merge this and HbmHelper together - - private MappingHelper() { - } - - public static String getStringValue(String value, String defaultValue) { - return value == null ? defaultValue : value; - } - - public static int getIntValue(String value, int defaultValue) { - return value == null ? defaultValue : Integer.parseInt( value ); - } - - public static boolean getBooleanValue(String value, boolean defaultValue) { - return value == null ? defaultValue : Boolean.valueOf( value ); - } - - public static boolean getBooleanValue(Boolean value, boolean defaultValue) { - return value == null ? defaultValue : value; - } - - public static Set getStringValueTokens(String str, String delimiters) { - if ( str == null ) { - return Collections.emptySet(); - } - else { - StringTokenizer tokenizer = new StringTokenizer( str, delimiters ); - Set tokens = new HashSet(); - while ( tokenizer.hasMoreTokens() ) { - tokens.add( tokenizer.nextToken() ); - } - return tokens; - } - } - - public static Class classForName(String className, ServiceRegistry serviceRegistry) { - ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); - try { - return classLoaderService.classForName( className ); - } - catch ( ClassLoadingException e ) { - throw new MappingException( "Could not find class: " + className ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/RootEntityDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/RootEntityDescriptorImpl.java deleted file mode 100644 index 153f7a9526..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/RootEntityDescriptorImpl.java +++ /dev/null @@ -1,134 +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.binder.source.hbm; - -import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.engine.OptimisticLockStyle; -import org.hibernate.metamodel.binder.MappingException; -import org.hibernate.metamodel.binder.source.RootEntityDescriptor; -import org.hibernate.metamodel.binder.source.TableDescriptor; -import org.hibernate.metamodel.binder.source.hbm.xml.mapping.EntityElement; -import org.hibernate.metamodel.binding.Caching; -import org.hibernate.metamodel.binding.InheritanceType; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLCacheElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; - -/** - * Unified descriptor for root entity (no inheritance strategy). - * - * @author Steve Ebersole - */ -public class RootEntityDescriptorImpl extends AbstractEntityDescriptorImpl implements RootEntityDescriptor { - private final boolean mutable; - private final boolean explicitPolymorphism; - private final String whereFilter; - private final String rowId; - private final Caching caching; - private final OptimisticLockStyle optimisticLockStyle; - - private final TableDescriptor baseTableDescriptor; - - public RootEntityDescriptorImpl(EntityElement entityClazz, HbmBindingContext bindingContext) { - super( entityClazz, null, InheritanceType.NO_INHERITANCE, bindingContext ); - - // the mapping has to be - final XMLHibernateMapping.XMLClass xmlClass = (XMLHibernateMapping.XMLClass) entityClazz; - - this.mutable = xmlClass.isMutable(); - this.explicitPolymorphism = "explicit".equals( xmlClass.getPolymorphism() ); - this.whereFilter = xmlClass.getWhere(); - this.rowId = xmlClass.getRowid(); - this.caching = interpretCaching( xmlClass, getEntityName() ); - this.optimisticLockStyle = interpretOptimisticLockStyle( xmlClass, bindingContext ); - - this.baseTableDescriptor = new TableDescriptorImpl( - xmlClass.getSchema(), - xmlClass.getCatalog(), - xmlClass.getTable(), - this, - bindingContext - ); - } - - private static Caching interpretCaching(XMLHibernateMapping.XMLClass xmlClass, String entityName) { - final XMLCacheElement cache = xmlClass.getCache(); - if ( cache == null ) { - return null; - } - final String region = cache.getRegion() != null ? cache.getRegion() : entityName; - final AccessType accessType = Enum.valueOf( AccessType.class, cache.getUsage() ); - final boolean cacheLazyProps = !"non-lazy".equals( cache.getInclude() ); - return new Caching( region, accessType, cacheLazyProps ); - } - - private static OptimisticLockStyle interpretOptimisticLockStyle( - XMLHibernateMapping.XMLClass entityClazz, - HbmBindingContext bindingContext) { - final String optimisticLockModeString = MappingHelper.getStringValue( entityClazz.getOptimisticLock(), "version" ); - try { - return OptimisticLockStyle.valueOf( optimisticLockModeString.toUpperCase() ); - } - catch (Exception e) { - throw new MappingException( - "Unknown optimistic-lock value : " + optimisticLockModeString, - bindingContext.getOrigin() - ); - } - } - - @Override - public boolean isMutable() { - return mutable; - } - - @Override - public boolean isExplicitPolymorphism() { - return explicitPolymorphism; - } - - @Override - public String getWhereFilter() { - return whereFilter; - } - - @Override - public String getRowId() { - return rowId; - } - - @Override - public Caching getCaching() { - return caching; - } - - @Override - public OptimisticLockStyle getOptimisticLockStyle() { - return optimisticLockStyle; - } - - @Override - public TableDescriptor getBaseTable() { - return baseTableDescriptor; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/TableDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/TableDescriptorImpl.java deleted file mode 100644 index 8765839653..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/TableDescriptorImpl.java +++ /dev/null @@ -1,86 +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.binder.source.hbm; - -import org.hibernate.metamodel.binder.Origin; -import org.hibernate.metamodel.binder.source.EntityDescriptor; -import org.hibernate.metamodel.binder.source.MetaAttributeContext; -import org.hibernate.metamodel.binder.source.TableDescriptor; -import org.hibernate.metamodel.binder.source.UnifiedDescriptorObject; - -/** - * @author Steve Ebersole - */ -public class TableDescriptorImpl implements TableDescriptor { - private final String explicitSchemaName; - private final String explicitCatalogName; - private final String tableName; - - private final EntityDescriptor entityDescriptor; - private final HbmBindingContext bindingContext; - - public TableDescriptorImpl( - String explicitSchemaName, - String explicitCatalogName, - String tableName, - EntityDescriptor entityDescriptor, - HbmBindingContext bindingContext) { - this.explicitSchemaName = explicitSchemaName; - this.explicitCatalogName = explicitCatalogName; - this.tableName = tableName; - - this.entityDescriptor = entityDescriptor; - this.bindingContext = bindingContext; - } - - @Override - public String getExplicitSchemaName() { - return explicitSchemaName; - } - - @Override - public String getExplicitCatalogName() { - return explicitCatalogName; - } - - @Override - public String getTableName() { - return tableName; - } - - @Override - public Origin getOrigin() { - return bindingContext.getOrigin(); - } - - @Override - public UnifiedDescriptorObject getContainingDescriptor() { - return entityDescriptor; - } - - @Override - public MetaAttributeContext getMetaAttributeContext() { - return bindingContext.getMetaAttributeContext(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/UnionSubClassEntityDescriptorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/UnionSubClassEntityDescriptorImpl.java deleted file mode 100644 index 01792b9080..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/UnionSubClassEntityDescriptorImpl.java +++ /dev/null @@ -1,80 +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.binder.source.hbm; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.binder.MappingException; -import org.hibernate.metamodel.binder.source.JoinedSubClassEntityDescriptor; -import org.hibernate.metamodel.binder.source.hbm.xml.mapping.EntityElement; -import org.hibernate.metamodel.source.hbm.xml.mapping.XMLUnionSubclassElement; - -import static org.hibernate.metamodel.binding.InheritanceType.JOINED; - -/** - * Unified descriptor for (SQL) union-based inheritance strategies. - * - * @author Steve Ebersole - */ -public class UnionSubClassEntityDescriptorImpl - extends AbstractEntityDescriptorImpl - implements JoinedSubClassEntityDescriptor { - - /** - * This form used when an explicit {@code extends} attribute names this mapping's super entity. - * - * @param entityClazz The JAXB entity mapping - * @param bindingContext The context for the binding process. - */ - public UnionSubClassEntityDescriptorImpl( - EntityElement entityClazz, - HbmBindingContext bindingContext) { - this( entityClazz, extractExtendsName( entityClazz, bindingContext ), bindingContext ); - } - - private static String extractExtendsName(EntityElement entityClazz, HbmBindingContext bindingContext) { - final String extendsName = ( (XMLUnionSubclassElement) entityClazz ).getExtends(); - if ( StringHelper.isEmpty( extendsName ) ) { - throw new MappingException( - "Subclass entity mapping [" + bindingContext.determineEntityName( entityClazz ) - + "] was not contained in super entity mapping", - bindingContext.getOrigin() - ); - } - return extendsName; - } - - /** - * This form would be used when the subclass definition if nested within its super type mapping. - * - * @param entityClazz The JAXB entity mapping - * @param superEntityName The name of the containing (and thus super) entity - * @param bindingContext The context for the binding process. - */ - public UnionSubClassEntityDescriptorImpl( - EntityElement entityClazz, - String superEntityName, - HbmBindingContext bindingContext) { - super( entityClazz, superEntityName, JOINED, bindingContext ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/AbstractHbmAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/AbstractHbmAttributeBindingState.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/AbstractHbmAttributeBindingState.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/AbstractHbmAttributeBindingState.java index e0ca19546a..5c49d38376 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/AbstractHbmAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/AbstractHbmAttributeBindingState.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.binding; +package org.hibernate.metamodel.binder.source.hbm.state.binding; import java.util.HashSet; import java.util.Map; @@ -33,7 +33,7 @@ import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.binder.source.BindingContext; import org.hibernate.metamodel.binder.source.MappingDefaults; import org.hibernate.metamodel.binder.source.MetaAttributeContext; -import org.hibernate.metamodel.binder.source.hbm.MappingHelper; +import org.hibernate.metamodel.binder.source.hbm.Helper; import org.hibernate.metamodel.binding.CascadeType; import org.hibernate.metamodel.binding.state.AttributeBindingState; @@ -78,8 +78,12 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi } protected Set determineCascadeTypes(String cascade) { - String commaSeparatedCascades = MappingHelper.getStringValue( cascade, getBindingContext().getMappingDefaults().getCascadeStyle() ); - Set cascades = MappingHelper.getStringValueTokens( commaSeparatedCascades, "," ); + String commaSeparatedCascades = Helper.getStringValue( + cascade, + getBindingContext().getMappingDefaults() + .getCascadeStyle() + ); + Set cascades = Helper.getStringValueTokens( commaSeparatedCascades, "," ); Set cascadeTypes = new HashSet( cascades.size() ); for ( String s : cascades ) { CascadeType cascadeType = CascadeType.getCascadeType( s ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmDiscriminatorBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmDiscriminatorBindingState.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmDiscriminatorBindingState.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmDiscriminatorBindingState.java index d9864bb38f..5ef1a4a63f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmDiscriminatorBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmDiscriminatorBindingState.java @@ -21,12 +21,12 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.binding; +package org.hibernate.metamodel.binder.source.hbm.state.binding; import java.util.Set; import org.hibernate.metamodel.binder.source.BindingContext; -import org.hibernate.metamodel.binder.source.hbm.MappingHelper; +import org.hibernate.metamodel.binder.source.hbm.Helper; import org.hibernate.metamodel.binding.CascadeType; import org.hibernate.metamodel.binding.state.DiscriminatorBindingState; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; @@ -58,7 +58,7 @@ public class HbmDiscriminatorBindingState true ); XMLDiscriminator discriminator = xmlEntityClazz.getDiscriminator(); - this.discriminatorValue = MappingHelper.getStringValue( + this.discriminatorValue = Helper.getStringValue( xmlEntityClazz.getDiscriminatorValue(), entityName ); this.isForced = xmlEntityClazz.getDiscriminator().isForce(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java index 42ba80107c..1d7e038efa 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmManyToOneAttributeBindingState.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.binding; +package org.hibernate.metamodel.binder.source.hbm.state.binding; import java.util.Set; @@ -29,8 +29,7 @@ import org.hibernate.FetchMode; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.metamodel.binder.source.BindingContext; import org.hibernate.metamodel.binder.source.MetaAttributeContext; -import org.hibernate.metamodel.binder.source.hbm.HbmHelper; -import org.hibernate.metamodel.binder.source.hbm.MappingHelper; +import org.hibernate.metamodel.binder.source.hbm.Helper; import org.hibernate.metamodel.binding.CascadeType; import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement; @@ -63,8 +62,8 @@ public class HbmManyToOneAttributeBindingState manyToOne.getName(), bindingContext, manyToOne.getNode(), - HbmHelper.extractMetaAttributeContext( manyToOne.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( + Helper.extractMetaAttributeContext( manyToOne.getMeta(), parentMetaAttributeContext ), + Helper.getPropertyAccessorName( manyToOne.getAccess(), manyToOne.isEmbedXml(), bindingContext.getMappingDefaults().getPropertyAccessorName() @@ -100,12 +99,12 @@ public class HbmManyToOneAttributeBindingState referencedEntityName = manyToOne.getEntityName(); } else if ( manyToOne.getClazz() != null ) { - referencedEntityName = HbmHelper.getClassName( + referencedEntityName = Helper.qualifyIfNeeded( manyToOne.getClazz(), bindingContext.getMappingDefaults().getPackageName() ); } else { - Class ownerClazz = MappingHelper.classForName( ownerClassName, bindingContext.getServiceRegistry() ); + Class ownerClazz = Helper.classForName( ownerClassName, bindingContext.getServiceRegistry() ); referencedEntityName = ReflectHelper.reflectedPropertyClass( ownerClazz, manyToOne.getName() ).getName(); } return referencedEntityName; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmPluralAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmPluralAttributeBindingState.java similarity index 83% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmPluralAttributeBindingState.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmPluralAttributeBindingState.java index e3cf675f4f..7d74f1c686 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmPluralAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmPluralAttributeBindingState.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.binding; +package org.hibernate.metamodel.binder.source.hbm.state.binding; import java.util.Comparator; import java.util.HashMap; @@ -31,8 +31,7 @@ import java.util.Set; import org.hibernate.FetchMode; import org.hibernate.metamodel.binder.source.BindingContext; import org.hibernate.metamodel.binder.source.MetaAttributeContext; -import org.hibernate.metamodel.binder.source.hbm.HbmHelper; -import org.hibernate.metamodel.binder.source.hbm.MappingHelper; +import org.hibernate.metamodel.binder.source.hbm.Helper; import org.hibernate.metamodel.binding.CascadeType; import org.hibernate.metamodel.binding.CustomSQL; import org.hibernate.metamodel.binding.state.PluralAttributeBindingState; @@ -63,14 +62,16 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS collection.getName(), bindingContext, collection.getNode(), - HbmHelper.extractMetaAttributeContext( collection.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( - collection.getAccess(), collection.isEmbedXml(), bindingContext.getMappingDefaults().getPropertyAccessorName() + Helper.extractMetaAttributeContext( collection.getMeta(), parentMetaAttributeContext ), + Helper.getPropertyAccessorName( + collection.getAccess(), + collection.isEmbedXml(), + bindingContext.getMappingDefaults().getPropertyAccessorName() ), collection.isOptimisticLock() ); this.collection = collection; - this.collectionPersisterClass = MappingHelper.classForName( + this.collectionPersisterClass = Helper.classForName( collection.getPersister(), getBindingContext().getServiceRegistry() ); this.cascadeTypes = determineCascadeTypes( collection.getCascade() ); @@ -116,7 +117,7 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS public boolean isLazy() { return isExtraLazy() || - MappingHelper.getBooleanValue( + Helper.getBooleanValue( collection.getLazy().value(), getBindingContext().getMappingDefaults().areAssociationsLazy() ); } @@ -202,7 +203,7 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS } public int getBatchSize() { - return MappingHelper.getIntValue( collection.getBatchSize(), 0 ); + return Helper.getIntValue( collection.getBatchSize(), 0 ); } @Override @@ -238,46 +239,22 @@ public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingS public CustomSQL getCustomSQLInsert() { XMLSqlInsertElement sqlInsert = collection.getSqlInsert(); - return sqlInsert == null ? - null : - HbmHelper.getCustomSql( - collection.getSqlInsert().getValue(), - collection.getSqlInsert().isCallable(), - collection.getSqlInsert().getCheck().value() - ); + return Helper.buildCustomSql( sqlInsert ); } public CustomSQL getCustomSQLUpdate() { XMLSqlUpdateElement sqlUpdate = collection.getSqlUpdate(); - return sqlUpdate == null ? - null : - HbmHelper.getCustomSql( - collection.getSqlUpdate().getValue(), - collection.getSqlUpdate().isCallable(), - collection.getSqlUpdate().getCheck().value() - ); + return Helper.buildCustomSql( sqlUpdate ); } public CustomSQL getCustomSQLDelete() { XMLSqlDeleteElement sqlDelete = collection.getSqlDelete(); - return sqlDelete == null ? - null : - HbmHelper.getCustomSql( - collection.getSqlDelete().getValue(), - collection.getSqlDelete().isCallable(), - collection.getSqlDelete().getCheck().value() - ); + return Helper.buildCustomSql( sqlDelete ); } public CustomSQL getCustomSQLDeleteAll() { XMLSqlDeleteAllElement sqlDeleteAll = collection.getSqlDeleteAll(); - return sqlDeleteAll == null ? - null : - HbmHelper.getCustomSql( - collection.getSqlDeleteAll().getValue(), - collection.getSqlDeleteAll().isCallable(), - collection.getSqlDeleteAll().getCheck().value() - ); + return Helper.buildCustomSql( sqlDeleteAll ); } public String getLoaderName() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmSimpleAttributeBindingState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmSimpleAttributeBindingState.java similarity index 87% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmSimpleAttributeBindingState.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmSimpleAttributeBindingState.java index be47be1b36..db60f625cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/binding/HbmSimpleAttributeBindingState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/binding/HbmSimpleAttributeBindingState.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.binding; +package org.hibernate.metamodel.binder.source.hbm.state.binding; import java.util.HashMap; import java.util.Map; @@ -32,8 +32,7 @@ import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.binder.source.BindingContext; import org.hibernate.metamodel.binder.source.MappingDefaults; import org.hibernate.metamodel.binder.source.MetaAttributeContext; -import org.hibernate.metamodel.binder.source.hbm.HbmHelper; -import org.hibernate.metamodel.binder.source.hbm.MappingHelper; +import org.hibernate.metamodel.binder.source.hbm.Helper; import org.hibernate.metamodel.binding.CascadeType; import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId; @@ -65,8 +64,12 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS id.getName() != null ? id.getName() : bindingContext.getMappingDefaults().getIdColumnName(), bindingContext, id.getNode(), - HbmHelper.extractMetaAttributeContext( id.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( id.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ), + Helper.extractMetaAttributeContext( id.getMeta(), parentMetaAttributeContext ), + Helper.getPropertyAccessorName( + id.getAccess(), + false, + bindingContext.getMappingDefaults().getPropertyAccessorName() + ), true ); @@ -108,8 +111,12 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS version.getName(), bindingContext, version.getNode(), - HbmHelper.extractMetaAttributeContext( version.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( version.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ), + Helper.extractMetaAttributeContext( version.getMeta(), parentMetaAttributeContext ), + Helper.getPropertyAccessorName( + version.getAccess(), + false, + bindingContext.getMappingDefaults().getPropertyAccessorName() + ), true ); this.typeName = version.getType() == null ? "integer" : version.getType(); @@ -123,7 +130,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS if ( propertyGeneration == PropertyGeneration.INSERT ) { throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" ); } - this.isInsertable = MappingHelper.getBooleanValue( version.isInsert(), true ); + this.isInsertable = Helper.getBooleanValue( version.isInsert(), true ); this.isUpdatable = true; } @@ -138,8 +145,12 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS timestamp.getName(), bindingContext, timestamp.getNode(), - HbmHelper.extractMetaAttributeContext( timestamp.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() ), + Helper.extractMetaAttributeContext( timestamp.getMeta(), parentMetaAttributeContext ), + Helper.getPropertyAccessorName( + timestamp.getAccess(), + false, + bindingContext.getMappingDefaults().getPropertyAccessorName() + ), true ); @@ -168,8 +179,8 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS property.getName(), bindingContext, property.getNode(), - HbmHelper.extractMetaAttributeContext( property.getMeta(), parentMetaAttributeContext ), - HbmHelper.getPropertyAccessorName( + Helper.extractMetaAttributeContext( property.getMeta(), parentMetaAttributeContext ), + Helper.getPropertyAccessorName( property.getAccess(), false, bindingContext.getMappingDefaults().getPropertyAccessorName() @@ -192,7 +203,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS isInsertable = false; } else { - isInsertable = MappingHelper.getBooleanValue( property.isInsert(), true ); + isInsertable = Helper.getBooleanValue( property.isInsert(), true ); } if ( propertyGeneration == PropertyGeneration.ALWAYS ) { if ( property.isUpdate() != null && property.isUpdate() ) { @@ -207,7 +218,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS isUpdatable = false; } else { - isUpdatable = MappingHelper.getBooleanValue( property.isUpdate(), true ); + isUpdatable = Helper.getBooleanValue( property.isUpdate(), true ); } if ( property.getTypeAttribute() != null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmColumnRelationalState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmColumnRelationalState.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmColumnRelationalState.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmColumnRelationalState.java index 48b55a3d6e..e470631ce5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmColumnRelationalState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmColumnRelationalState.java @@ -21,13 +21,13 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.relational; +package org.hibernate.metamodel.binder.source.hbm.state.relational; import java.util.Set; import org.hibernate.MappingException; import org.hibernate.cfg.NamingStrategy; -import org.hibernate.metamodel.binder.source.hbm.MappingHelper; +import org.hibernate.metamodel.binder.source.hbm.Helper; import org.hibernate.metamodel.relational.Size; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLColumnElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator; @@ -64,8 +64,8 @@ public class HbmColumnRelationalState implements ColumnRelationalState { this.container = container; this.explicitColumnName = columnElement.getName(); this.size = createSize( columnElement.getLength(), columnElement.getScale(), columnElement.getPrecision() ); - this.isNullable = !MappingHelper.getBooleanValue( columnElement.isNotNull(), true ); - this.isUnique = MappingHelper.getBooleanValue( columnElement.isUnique(), true ); + this.isNullable = !Helper.getBooleanValue( columnElement.isNotNull(), true ); + this.isUnique = Helper.getBooleanValue( columnElement.isUnique(), true ); this.checkCondition = columnElement.getCheck(); this.defaultColumnValue = columnElement.getDefault(); this.sqlType = columnElement.getSqlType(); @@ -75,9 +75,9 @@ public class HbmColumnRelationalState implements ColumnRelationalState { } this.customRead = columnElement.getRead(); this.comment = columnElement.getComment() == null ? null : columnElement.getComment().trim(); - this.uniqueKeys = MappingHelper.getStringValueTokens( columnElement.getUniqueKey(), ", " ); + this.uniqueKeys = Helper.getStringValueTokens( columnElement.getUniqueKey(), ", " ); this.uniqueKeys.addAll( container.getPropertyUniqueKeys() ); - this.indexes = MappingHelper.getStringValueTokens( columnElement.getIndex(), ", " ); + this.indexes = Helper.getStringValueTokens( columnElement.getIndex(), ", " ); this.indexes.addAll( container.getPropertyIndexes() ); } @@ -86,17 +86,17 @@ public class HbmColumnRelationalState implements ColumnRelationalState { this.container = container; this.explicitColumnName = property.getName(); this.size = createSize( property.getLength(), property.getScale(), property.getPrecision() ); - this.isUnique = MappingHelper.getBooleanValue( property.isUnique(), true ); - this.isNullable = !MappingHelper.getBooleanValue( property.isNotNull(), true ); + this.isUnique = Helper.getBooleanValue( property.isUnique(), true ); + this.isNullable = !Helper.getBooleanValue( property.isNotNull(), true ); this.checkCondition = null; this.defaultColumnValue = null; this.sqlType = null; this.customWrite = null; this.customRead = null; this.comment = null; - this.uniqueKeys = MappingHelper.getStringValueTokens( property.getUniqueKey(), ", " ); + this.uniqueKeys = Helper.getStringValueTokens( property.getUniqueKey(), ", " ); this.uniqueKeys.addAll( container.getPropertyUniqueKeys() ); - this.indexes = MappingHelper.getStringValueTokens( property.getIndex(), ", " ); + this.indexes = Helper.getStringValueTokens( property.getIndex(), ", " ); this.indexes.addAll( container.getPropertyIndexes() ); } @@ -105,7 +105,7 @@ public class HbmColumnRelationalState implements ColumnRelationalState { this.container = container; this.explicitColumnName = manyToOne.getName(); this.size = new Size(); - this.isNullable = !MappingHelper.getBooleanValue( manyToOne.isNotNull(), false ); + this.isNullable = !Helper.getBooleanValue( manyToOne.isNotNull(), false ); this.isUnique = manyToOne.isUnique(); this.checkCondition = null; this.defaultColumnValue = null; @@ -113,9 +113,9 @@ public class HbmColumnRelationalState implements ColumnRelationalState { this.customWrite = null; this.customRead = null; this.comment = null; - this.uniqueKeys = MappingHelper.getStringValueTokens( manyToOne.getUniqueKey(), ", " ); + this.uniqueKeys = Helper.getStringValueTokens( manyToOne.getUniqueKey(), ", " ); this.uniqueKeys.addAll( container.getPropertyUniqueKeys() ); - this.indexes = MappingHelper.getStringValueTokens( manyToOne.getIndex(), ", " ); + this.indexes = Helper.getStringValueTokens( manyToOne.getIndex(), ", " ); this.indexes.addAll( container.getPropertyIndexes() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmDerivedValueRelationalState.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmDerivedValueRelationalState.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmDerivedValueRelationalState.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmDerivedValueRelationalState.java index f160d074ee..120d77b7de 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmDerivedValueRelationalState.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmDerivedValueRelationalState.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.relational; +package org.hibernate.metamodel.binder.source.hbm.state.relational; import org.hibernate.metamodel.relational.state.DerivedValueRelationalState; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmManyToOneRelationalStateContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmManyToOneRelationalStateContainer.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmManyToOneRelationalStateContainer.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmManyToOneRelationalStateContainer.java index fd20ba5f3a..878b519273 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmManyToOneRelationalStateContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmManyToOneRelationalStateContainer.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.relational; +package org.hibernate.metamodel.binder.source.hbm.state.relational; import org.hibernate.metamodel.binder.source.BindingContext; import org.hibernate.metamodel.relational.state.ManyToOneRelationalState; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmSimpleValueRelationalStateContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmSimpleValueRelationalStateContainer.java similarity index 99% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmSimpleValueRelationalStateContainer.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmSimpleValueRelationalStateContainer.java index f2f00445a3..71e142b492 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/state/relational/HbmSimpleValueRelationalStateContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/state/relational/HbmSimpleValueRelationalStateContainer.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.hbm.state.relational; +package org.hibernate.metamodel.binder.source.hbm.state.relational; import java.util.ArrayList; import java.util.Collections; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/xml/mapping/CustomSqlElement.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/xml/mapping/CustomSqlElement.java new file mode 100644 index 0000000000..63330b6fbf --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/source/hbm/xml/mapping/CustomSqlElement.java @@ -0,0 +1,35 @@ +/* + * 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.binder.source.hbm.xml.mapping; + +import org.hibernate.metamodel.source.hbm.xml.mapping.XMLCheckAttribute; + +/** + * @author Steve Ebersole + */ +public interface CustomSqlElement { + public String getValue(); + public boolean isCallable(); + public XMLCheckAttribute getCheck(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/SimpleAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/SimpleAttribute.java index 56036c8213..8a426978d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/SimpleAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/SimpleAttribute.java @@ -35,9 +35,9 @@ import org.jboss.jandex.DotName; import org.hibernate.AnnotationException; import org.hibernate.annotations.GenerationTime; import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.annotations.HibernateDotNames; -import org.hibernate.metamodel.source.annotations.JPADotNames; -import org.hibernate.metamodel.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.binder.source.annotations.HibernateDotNames; +import org.hibernate.metamodel.binder.source.annotations.JPADotNames; +import org.hibernate.metamodel.binder.source.annotations.JandexHelper; /** * Represent a mapped attribute (explicitly or implicitly mapped). Also used for synthetic attributes like a diff --git a/hibernate-core/src/main/xjb/hbm-mapping-bindings.xjb b/hibernate-core/src/main/xjb/hbm-mapping-bindings.xjb index b09fadcc8b..e10ce58606 100644 --- a/hibernate-core/src/main/xjb/hbm-mapping-bindings.xjb +++ b/hibernate-core/src/main/xjb/hbm-mapping-bindings.xjb @@ -30,6 +30,18 @@ org.hibernate.metamodel.binder.source.hbm.xml.mapping.SubclassEntityElement + + org.hibernate.metamodel.binder.source.hbm.xml.mapping.CustomSqlElement + + + org.hibernate.metamodel.binder.source.hbm.xml.mapping.CustomSqlElement + + + org.hibernate.metamodel.binder.source.hbm.xml.mapping.CustomSqlElement + + + org.hibernate.metamodel.binder.source.hbm.xml.mapping.CustomSqlElement + diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/AbstractMockerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/AbstractMockerTest.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/AbstractMockerTest.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/AbstractMockerTest.java index 3c025230c2..528f9f9a45 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/AbstractMockerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/AbstractMockerTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import java.io.IOException; import java.io.InputStream; @@ -38,8 +38,6 @@ import org.jboss.jandex.Indexer; import org.hibernate.AnnotationException; import org.hibernate.HibernateException; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.EntityMappingsMocker; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.IndexBuilder; import org.hibernate.metamodel.source.annotation.xml.XMLEntityMappings; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.classloading.spi.ClassLoaderService; @@ -57,7 +55,7 @@ public abstract class AbstractMockerTest { private IndexBuilder indexBuilder; private Index index; private ServiceRegistry serviceRegistry; - protected String packagePrefix = "org/hibernate/metamodel/source/annotations/xml/mocker/"; + protected String packagePrefix = getClass().getPackage().getName().replace( '.', '/' ) + '/'; protected IndexBuilder getIndexBuilder() { if ( indexBuilder == null ) { diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Author.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Author.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Author.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Author.java index 0a2868d18d..1237a50416 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Author.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Author.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import java.util.ArrayList; import java.util.List; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/BasicMockerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/BasicMockerTest.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/BasicMockerTest.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/BasicMockerTest.java index d3bc1aba6d..84b89b0de2 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/BasicMockerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/BasicMockerTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; @@ -29,9 +29,6 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.junit.Test; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.EntityMappingsMocker; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.EntityMocker; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.IndexBuilder; import org.hibernate.metamodel.source.annotation.xml.XMLAttributes; import org.hibernate.metamodel.source.annotation.xml.XMLEntity; import org.hibernate.metamodel.source.annotation.xml.XMLGeneratedValue; @@ -67,7 +64,7 @@ public class BasicMockerTest extends AbstractMockerTest { entity.setClazz( "Item" ); IndexBuilder indexBuilder = getIndexBuilder(); EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default(); - defaults.setPackageName( "org.hibernate.metamodel.source.annotations.xml.mocker" ); + defaults.setPackageName( getClass().getPackage().getName() ); defaults.setSchema( "HIBERNATE_SCHEMA" ); defaults.setCatalog( "HIBERNATE_CATALOG" ); EntityMocker entityMocker = new EntityMocker( indexBuilder, entity, defaults ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Book.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Book.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Book.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Book.java index ccfebfa64e..ecb6024f80 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Book.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Book.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import java.util.ArrayList; import java.util.Date; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java index 4fb08c2f2e..f936857cf5 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java @@ -1,4 +1,4 @@ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import java.util.HashMap; import java.util.HashSet; @@ -18,9 +18,6 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.junit.Test; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.DefaultConfigurationHelper; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.EntityMappingsMocker; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.SchemaAware; import org.hibernate.metamodel.source.annotation.xml.XMLEntity; import org.hibernate.metamodel.binder.source.annotations.JPADotNames; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/EntityListenerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/EntityListenerTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/EntityListenerTest.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/EntityListenerTest.java index fddea69d2b..6f1ee777b0 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/EntityListenerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/EntityListenerTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/IndexBuilderTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/IndexBuilderTest.java similarity index 56% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/IndexBuilderTest.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/IndexBuilderTest.java index d80e5d187c..e539d3222d 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/IndexBuilderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/IndexBuilderTest.java @@ -1,6 +1,4 @@ -package org.hibernate.metamodel.source.annotations.xml.mocker; - -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.IndexBuilder; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Item.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Item.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Item.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Item.java index fa5be30fc4..cd4a40a19c 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Item.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Item.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; /** * @author Strong Liu diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/ItemListener.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/ItemListener.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/ItemListener.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/ItemListener.java index dc1852b0b6..93ea7eead8 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/ItemListener.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/ItemListener.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; /** * @author Strong Liu diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/OverrideTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/OverrideTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/OverrideTest.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/OverrideTest.java index 1c9a65a483..f718ff6229 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/OverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/OverrideTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import java.util.List; @@ -32,9 +32,6 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.junit.Test; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.EntityMappingsMocker; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.EntityMocker; -import org.hibernate.metamodel.binder.source.annotations.xml.mocker.IndexBuilder; import org.hibernate.metamodel.source.annotation.xml.XMLEntity; import org.hibernate.metamodel.binder.source.annotations.JPADotNames; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java index 7896990132..b93cfbdd2a 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import javax.persistence.AccessType; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Topic.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Topic.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Topic.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Topic.java index cf74904525..94daf79c1b 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/Topic.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/Topic.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import javax.persistence.Embeddable; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/XmlHelper.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/XmlHelper.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/XmlHelper.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/XmlHelper.java index 8e4091c024..753a9e6436 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/mocker/XmlHelper.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binder/source/annotations/xml/mocker/XmlHelper.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.xml.mocker; +package org.hibernate.metamodel.binder.source.annotations.xml.mocker; import java.io.InputStream; import java.net.URL; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java index 378b0f8cc6..4f648a287a 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/binding/SimpleValueBindingTests.java @@ -27,6 +27,7 @@ import java.sql.Types; import org.junit.Test; +import org.hibernate.internal.util.Value; import org.hibernate.metamodel.domain.Entity; import org.hibernate.metamodel.domain.JavaType; import org.hibernate.metamodel.domain.SingularAttribute; @@ -35,6 +36,8 @@ import org.hibernate.metamodel.relational.Datatype; import org.hibernate.metamodel.relational.Schema; import org.hibernate.metamodel.relational.Size; import org.hibernate.metamodel.relational.Table; +import org.hibernate.service.classloading.spi.ClassLoadingException; + import org.hibernate.testing.junit4.BaseUnitTestCase; import static org.junit.Assert.assertSame; @@ -52,7 +55,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase { @Test public void testBasicMiddleOutBuilding() { Table table = new Table( new Schema( null, null ), "the_table" ); - Entity entity = new Entity( "TheEntity", null, new JavaType( "NoSuchClass", null ) ); + Entity entity = new Entity( "TheEntity", "NoSuchClass", makeJavaType( "NoSuchClass" ), null ); EntityBinding entityBinding = new EntityBinding(); entityBinding.setRoot( true ); entityBinding.setEntity( entity ); @@ -72,4 +75,20 @@ public class SimpleValueBindingTests extends BaseUnitTestCase { table.getPrimaryKey().setName( "my_table_pk" ); //attributeBinding.setValue( idColumn ); } + + Value> makeJavaType(final String name) { + return new Value>( + new Value.DeferredInitializer>() { + @Override + public Class initialize() { + try { + return Class.forName( name ); + } + catch ( Exception e ) { + throw new ClassLoadingException( "Could not load class : " + name, e ); + } + } + } + ); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/AnnotationsBindingContextImpl.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/TestAnnotationsBindingContextImpl.java similarity index 78% rename from hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/AnnotationsBindingContextImpl.java rename to hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/TestAnnotationsBindingContextImpl.java index 976fc53c41..99fa5039b5 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/AnnotationsBindingContextImpl.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/TestAnnotationsBindingContextImpl.java @@ -21,11 +21,12 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.source.annotations.entity; +package org.hibernate.metamodel.source.annotations; import java.util.HashMap; import java.util.Map; +import com.fasterxml.classmate.MemberResolver; import com.fasterxml.classmate.ResolvedType; import com.fasterxml.classmate.ResolvedTypeWithMembers; import com.fasterxml.classmate.TypeResolver; @@ -35,25 +36,28 @@ import org.jboss.jandex.Index; import org.hibernate.cfg.EJB3NamingStrategy; import org.hibernate.cfg.NamingStrategy; +import org.hibernate.cfg.NotYetImplementedException; +import org.hibernate.internal.util.Value; import org.hibernate.metamodel.binder.source.MappingDefaults; import org.hibernate.metamodel.binder.source.MetadataImplementor; import org.hibernate.metamodel.binder.source.annotations.AnnotationsBindingContext; import org.hibernate.metamodel.domain.JavaType; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.classloading.spi.ClassLoaderService; -import org.hibernate.service.internal.BasicServiceRegistryImpl; /** -* @author Steve Ebersole -*/ -public class AnnotationsBindingContextImpl implements AnnotationsBindingContext { - private final Index index; - private final BasicServiceRegistryImpl serviceRegistry; + * @author Steve Ebersole + */ +public class TestAnnotationsBindingContextImpl implements AnnotationsBindingContext { + private Index index; + private ServiceRegistry serviceRegistry; + + private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE; private final TypeResolver typeResolver = new TypeResolver(); private final Map, ResolvedType> resolvedTypeCache = new HashMap, ResolvedType>(); - public AnnotationsBindingContextImpl(Index index, BasicServiceRegistryImpl serviceRegistry) { + public TestAnnotationsBindingContextImpl(Index index, ServiceRegistry serviceRegistry) { this.index = index; this.serviceRegistry = serviceRegistry; } @@ -63,6 +67,40 @@ public class AnnotationsBindingContextImpl implements AnnotationsBindingContext return index; } + @Override + public ServiceRegistry getServiceRegistry() { + return serviceRegistry; + } + + @Override + public NamingStrategy getNamingStrategy() { + return namingStrategy; + } + + @Override + public MappingDefaults getMappingDefaults() { + throw new NotYetImplementedException(); + } + + @Override + public MetadataImplementor getMetadataImplementor() { + throw new NotYetImplementedException(); + } + + @Override + public Class locateClassByName(String name) { + return serviceRegistry.getService( ClassLoaderService.class ).classForName( name ); + } + + @Override + public JavaType makeJavaType(String className) { + throw new NotYetImplementedException(); + } + + @Override + public Value> makeClassReference(String className) { + throw new NotYetImplementedException(); + } @Override public ClassInfo getClassInfo(String name) { DotName dotName = DotName.createSimple( name ); @@ -91,37 +129,9 @@ public class AnnotationsBindingContextImpl implements AnnotationsBindingContext @Override public ResolvedTypeWithMembers resolveMemberTypes(ResolvedType type) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public ServiceRegistry getServiceRegistry() { - return serviceRegistry; - } - - @Override - public NamingStrategy getNamingStrategy() { - return EJB3NamingStrategy.INSTANCE; - } - - @Override - public MappingDefaults getMappingDefaults() { - return null; - } - - @Override - public MetadataImplementor getMetadataImplementor() { - return null; - } - - @Override - public Class locateClassByName(String name) { - return serviceRegistry.getService( ClassLoaderService.class ).classForName( name ); - } - - @Override - public JavaType makeJavaType(String className) { - return null; + // todo : is there a reason we create this resolver every time? + MemberResolver memberResolver = new MemberResolver( typeResolver ); + return memberResolver.resolve( type, null, null ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/ProxyBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/ProxyBindingTests.java index db087e477d..c6cd800459 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/ProxyBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/ProxyBindingTests.java @@ -46,7 +46,7 @@ public class ProxyBindingTests extends BaseAnnotationBindingTestCase { buildMetadataSources( ProxiedEntity.class ); EntityBinding binding = getEntityBinding( ProxiedEntity.class ); assertTrue( "Wrong laziness", binding.isLazy() ); - assertEquals( "Wrong proxy interface", ProxiedEntity.class, binding.getProxyInterfaceType().getClassReference() ); + assertEquals( "Wrong proxy interface", ProxiedEntity.class, binding.getProxyInterfaceType().getValue() ); } @Test @@ -54,7 +54,7 @@ public class ProxyBindingTests extends BaseAnnotationBindingTestCase { buildMetadataSources(NoProxyEntity.class); EntityBinding binding = getEntityBinding( NoProxyEntity.class ); assertTrue( "Wrong laziness", binding.isLazy() ); - assertEquals( "Wrong proxy interface", NoProxyEntity.class, binding.getProxyInterfaceType().getClassReference() ); + assertEquals( "Wrong proxy interface", NoProxyEntity.class, binding.getProxyInterfaceType().getValue() ); } @Test @@ -73,7 +73,7 @@ public class ProxyBindingTests extends BaseAnnotationBindingTestCase { assertEquals( "Wrong proxy interface", "org.hibernate.metamodel.source.annotations.entity.ProxyBindingTests$ProxyInterfaceEntity", - binding.getProxyInterfaceType().getName() + binding.getProxyInterfaceType().getValue().getName() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/TableNameTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/TableNameTest.java index ceee844c5c..875518f42a 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/TableNameTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/TableNameTest.java @@ -44,6 +44,7 @@ import org.hibernate.metamodel.binder.source.annotations.ConfiguredClassHierarch import org.hibernate.metamodel.binder.source.annotations.JandexHelper; import org.hibernate.metamodel.binder.source.annotations.entity.ConfiguredClassHierarchy; import org.hibernate.metamodel.binding.InheritanceType; +import org.hibernate.metamodel.source.annotations.TestAnnotationsBindingContextImpl; import org.hibernate.service.ServiceRegistryBuilder; import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.service.internal.BasicServiceRegistryImpl; @@ -86,9 +87,8 @@ public class TableNameTest extends BaseUnitTestCase { } Index index = JandexHelper.indexForClass( service, A.class, B.class ); - AnnotationsBindingContext context = new AnnotationsBindingContextImpl( index, serviceRegistry ); Set> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies( - context + new TestAnnotationsBindingContextImpl( index, serviceRegistry ) ); assertEquals( "There should be only one hierarchy", 1, hierarchies.size() ); @@ -134,9 +134,8 @@ public class TableNameTest extends BaseUnitTestCase { } Index index = JandexHelper.indexForClass( service, A.class, B.class ); - AnnotationsBindingContext context = new AnnotationsBindingContextImpl( index, serviceRegistry ); Set> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies( - context + new TestAnnotationsBindingContextImpl( index, serviceRegistry ) ); assertEquals( "There should be only one hierarchy", 1, hierarchies.size() ); @@ -183,9 +182,8 @@ public class TableNameTest extends BaseUnitTestCase { } Index index = JandexHelper.indexForClass( service, B.class, A.class ); - AnnotationsBindingContextImpl context = new AnnotationsBindingContextImpl( index, serviceRegistry ); Set> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies( - context + new TestAnnotationsBindingContextImpl( index, serviceRegistry ) ); assertEquals( "There should be only one hierarchy", 1, hierarchies.size() ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/BaseAnnotationIndexTestCase.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/BaseAnnotationIndexTestCase.java index 9109701cb3..4b11db1ff4 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/BaseAnnotationIndexTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/util/BaseAnnotationIndexTestCase.java @@ -34,7 +34,7 @@ import org.junit.Before; import org.hibernate.metamodel.binder.source.annotations.ConfiguredClassHierarchyBuilder; import org.hibernate.metamodel.binder.source.annotations.JandexHelper; import org.hibernate.metamodel.binder.source.annotations.entity.ConfiguredClassHierarchy; -import org.hibernate.metamodel.source.annotations.entity.AnnotationsBindingContextImpl; +import org.hibernate.metamodel.source.annotations.TestAnnotationsBindingContextImpl; import org.hibernate.metamodel.source.annotations.entity.EmbeddableClass; import org.hibernate.metamodel.source.annotations.entity.EntityClass; import org.hibernate.service.ServiceRegistryBuilder; @@ -60,7 +60,7 @@ public abstract class BaseAnnotationIndexTestCase extends BaseUnitTestCase { public Set> createEntityHierarchies(Class... clazz) { Index index = JandexHelper.indexForClass( serviceRegistry.getService( ClassLoaderService.class ), clazz ); - AnnotationsBindingContextImpl context = new AnnotationsBindingContextImpl( index, serviceRegistry ); + TestAnnotationsBindingContextImpl context = new TestAnnotationsBindingContextImpl( index, serviceRegistry ); return ConfiguredClassHierarchyBuilder.createEntityHierarchies( context ); } @@ -69,7 +69,7 @@ public abstract class BaseAnnotationIndexTestCase extends BaseUnitTestCase { serviceRegistry.getService( ClassLoaderService.class ), configuredClasses ); - AnnotationsBindingContextImpl context = new AnnotationsBindingContextImpl( index, serviceRegistry ); + TestAnnotationsBindingContextImpl context = new TestAnnotationsBindingContextImpl( index, serviceRegistry ); return ConfiguredClassHierarchyBuilder.createEmbeddableHierarchy( configuredClasses[0], accessType, context ); } } diff --git a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/AttributeOverride.xml b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/AttributeOverride.xml similarity index 90% rename from hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/AttributeOverride.xml rename to hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/AttributeOverride.xml index b12d583056..d6b5cc78e8 100644 --- a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/AttributeOverride.xml +++ b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/AttributeOverride.xml @@ -8,7 +8,7 @@ - org.hibernate.metamodel.source.annotations.xml.mocker + org.hibernate.metamodel.binder.source.annotations.xml.mocker diff --git a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/default-schema.xml b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/default-schema.xml similarity index 100% rename from hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/default-schema.xml rename to hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/default-schema.xml diff --git a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/default-schema2.xml b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/default-schema2.xml similarity index 76% rename from hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/default-schema2.xml rename to hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/default-schema2.xml index 3d3c49d449..e82d7f3c9f 100644 --- a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/default-schema2.xml +++ b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/default-schema2.xml @@ -3,7 +3,7 @@ - org.hibernate.metamodel.source.annotations.xml.mocker + org.hibernate.metamodel.binder.source.annotations.xml.mocker XML_SCHEMA XML_CATALOG diff --git a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/entity-metadata-complete.xml b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/entity-metadata-complete.xml similarity index 78% rename from hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/entity-metadata-complete.xml rename to hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/entity-metadata-complete.xml index f31ede7088..1e2a3bb8f1 100644 --- a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/entity-metadata-complete.xml +++ b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/entity-metadata-complete.xml @@ -3,7 +3,7 @@ - org.hibernate.metamodel.source.annotations.xml.mocker + org.hibernate.metamodel.binder.source.annotations.xml.mocker diff --git a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/listener.xml b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/listener.xml similarity index 71% rename from hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/listener.xml rename to hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/listener.xml index 44fe5bbbc4..97c4a81d11 100644 --- a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/listener.xml +++ b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/listener.xml @@ -8,17 +8,17 @@ FIELD - + - org.hibernate.metamodel.source.annotations.xml.mocker + org.hibernate.metamodel.binder.source.annotations.xml.mocker - + diff --git a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/override-to-mappedsuperclass.xml b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/override-to-mappedsuperclass.xml similarity index 85% rename from hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/override-to-mappedsuperclass.xml rename to hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/override-to-mappedsuperclass.xml index 2c98e5dbe6..1e709963ff 100644 --- a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/override-to-mappedsuperclass.xml +++ b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/override-to-mappedsuperclass.xml @@ -3,7 +3,7 @@ - org.hibernate.metamodel.source.annotations.xml.mocker + org.hibernate.metamodel.binder.source.annotations.xml.mocker diff --git a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/persistence-metadata.xml b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/persistence-metadata.xml similarity index 83% rename from hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/persistence-metadata.xml rename to hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/persistence-metadata.xml index 6148c06247..6611bce577 100644 --- a/hibernate-core/src/test/resources/org/hibernate/metamodel/source/annotations/xml/mocker/persistence-metadata.xml +++ b/hibernate-core/src/test/resources/org/hibernate/metamodel/binder/source/annotations/xml/mocker/persistence-metadata.xml @@ -8,7 +8,7 @@ FIELD - +