From 77f0c9a1edb732586402982325edc44099cec5c6 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Wed, 21 May 2014 17:09:41 -0400 Subject: [PATCH] HHH-8893 removed o.h.metadata.source.internal.hbm, MetadataSourceProcessor, and MetadataSourceProcessingOrder --- .../hibernate/metamodel/MetadataBuilder.java | 11 - .../MetadataSourceProcessingOrder.java | 35 - .../internal/MetadataBuilderImpl.java | 16 +- .../internal/MetadataBuildingProcess.java | 118 ++- ...=> AnnotationMetadataSourceProcessor.java} | 11 +- .../hbm/AbstractConstraintSource.java | 108 --- .../hbm/AbstractEmbeddableJaxbSource.java | 129 --- .../AbstractEmbeddedAttributeSourceImpl.java | 150 ---- .../hbm/AbstractEntitySourceImpl.java | 638 --------------- .../internal/hbm/AbstractHbmSourceNode.java | 75 -- ...actPluralAssociationElementSourceImpl.java | 72 -- .../AbstractPluralAttributeSourceImpl.java | 438 ----------- .../internal/hbm/AbstractReturnBinder.java | 135 ---- .../hbm/AbstractToOneAttributeSourceImpl.java | 270 ------- .../source/internal/hbm/ArraySourceImpl.java | 73 -- .../source/internal/hbm/BagSourceImpl.java | 62 -- .../hbm/ColumnAttributeSourceImpl.java | 148 ---- .../source/internal/hbm/ColumnSourceImpl.java | 143 ---- .../internal/hbm/EmbeddableJaxbSource.java | 95 --- .../internal/hbm/EmbeddableSourceImpl.java | 308 -------- .../hbm/EmbeddedAttributeSourceImpl.java | 211 ----- .../hbm/EntityHierarchySourceImpl.java | 734 ------------------ .../internal/hbm/FetchProfileSourceImpl.java | 94 --- .../hbm/FilterDefinitionSourceImpl.java | 97 --- .../source/internal/hbm/FilterSourceImpl.java | 110 --- .../source/internal/hbm/FormulaImpl.java | 57 -- .../internal/hbm/HbmBindingContext.java | 47 -- .../hbm/HbmMetadataSourceProcessorImpl.java | 117 --- .../metamodel/source/internal/hbm/Helper.java | 479 ------------ .../hbm/HibernateMappingProcessor.java | 322 -------- .../source/internal/hbm/HierarchyBuilder.java | 226 ------ .../source/internal/hbm/IdBagSourceImpl.java | 156 ---- .../hbm/IdentifierKeyAttributeSourceImpl.java | 45 -- .../hbm/IdentifierKeyManyToOneSourceImpl.java | 46 -- .../internal/hbm/InLineViewSourceImpl.java | 70 -- .../hbm/IndexConstraintSourceImpl.java | 56 -- .../hbm/JoinedSubclassEntitySourceImpl.java | 129 --- .../internal/hbm/KeyAttributeSourceImpl.java | 205 ----- .../internal/hbm/KeyManyToOneSourceImpl.java | 250 ------ .../source/internal/hbm/ListSourceImpl.java | 66 -- .../internal/hbm/LoadCollectionBinder.java | 64 -- .../hbm/ManyToOneAttributeSourceImpl.java | 252 ------ .../internal/hbm/MapKeySourceBasicImpl.java | 200 ----- .../source/internal/hbm/MapSourceImpl.java | 90 --- .../source/internal/hbm/MappingDocument.java | 156 ---- .../internal/hbm/NamedQueryBindingHelper.java | 205 ----- .../hbm/OneToOneAttributeSourceImpl.java | 248 ------ ...PluralAttributeElementSourceBasicImpl.java | 147 ---- ...ralAttributeElementSourceEmbeddedImpl.java | 150 ---- ...lAttributeElementSourceManyToManyImpl.java | 268 ------- ...alAttributeElementSourceOneToManyImpl.java | 75 -- .../hbm/PluralAttributeKeySourceImpl.java | 141 ---- ...uralAttributeMapKeySourceEmbeddedImpl.java | 182 ----- ...ralAttributeSequentialIndexSourceImpl.java | 173 ----- .../hbm/PropertyAttributeSourceImpl.java | 223 ------ .../internal/hbm/ResultSetMappingBinder.java | 61 -- .../source/internal/hbm/ReturnBinder.java | 142 ---- .../source/internal/hbm/ReturnJoinBinder.java | 61 -- .../internal/hbm/RootEntitySourceImpl.java | 90 --- .../hbm/SecondaryTableSourceImpl.java | 199 ----- .../source/internal/hbm/SetSourceImpl.java | 75 -- ...SingularIdentifierAttributeSourceImpl.java | 205 ----- .../source/internal/hbm/SizeSourceImpl.java | 75 -- .../hbm/SubclassEntitySourceImpl.java | 70 -- .../source/internal/hbm/TableSourceImpl.java | 79 -- .../hbm/TimestampAttributeSourceImpl.java | 201 ----- .../hbm/TypeDescriptorSourceImpl.java | 66 -- .../hbm/UniqueConstraintSourceImpl.java | 58 -- .../hbm/VersionAttributeSourceImpl.java | 208 ----- .../AbstractQueryElementContentsParser.java | 228 ------ .../BasicQueryElementContentParser.java | 37 - .../parser/SQLQueryElementContentParser.java | 118 --- .../spi/MetadataBuildingOptions.java | 9 +- .../spi/MetadataSourceProcessor.java | 72 -- .../internal/source/AssertSourcesTest.java | 58 +- .../UnidirectionalManyToManyBindingTests.java | 23 +- 76 files changed, 82 insertions(+), 11179 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSourceProcessingOrder.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/{AnnotationMetadataSourceProcessorImpl.java => AnnotationMetadataSourceProcessor.java} (94%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractConstraintSource.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractHbmSourceNode.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAssociationElementSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractReturnBinder.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FetchProfileSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterDefinitionSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FormulaImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmBindingContext.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmMetadataSourceProcessorImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HibernateMappingProcessor.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HierarchyBuilder.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/InLineViewSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IndexConstraintSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/JoinedSubclassEntitySourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/LoadCollectionBinder.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceBasicImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MappingDocument.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceManyToManyImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceOneToManyImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeKeySourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeSequentialIndexSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ResultSetMappingBinder.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnBinder.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnJoinBinder.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SecondaryTableSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SizeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SubclassEntitySourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TableSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TypeDescriptorSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/UniqueConstraintSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/AbstractQueryElementContentsParser.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/BasicQueryElementContentParser.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/SQLQueryElementContentParser.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataSourceProcessor.java diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java index 492f913330..6392f7cfd2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataBuilder.java @@ -37,9 +37,7 @@ import org.hibernate.type.BasicType; import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.UserType; - import org.jboss.jandex.IndexView; - import org.xml.sax.EntityResolver; /** @@ -67,15 +65,6 @@ public interface MetadataBuilder { */ public MetadataBuilder with(EntityResolver entityResolver); - /** - * Specify the order in which to process metadata sources. - * - * @param metadataSourceProcessingOrder The order. - * - * @return {@code this}, for method chaining - */ - public MetadataBuilder with(MetadataSourceProcessingOrder metadataSourceProcessingOrder); - /** * Specify the second-level cache mode to be used. This is the cache mode in terms of whether or * not to cache. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSourceProcessingOrder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSourceProcessingOrder.java deleted file mode 100644 index 5a099c6f05..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSourceProcessingOrder.java +++ /dev/null @@ -1,35 +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; - -/** - * Enumeration of the possible orders for processing metadata sources. The implication is in terms of precedence; - * for duplicate information in different sources, whichever is processed first has precedence. - * - * @author Steve Ebersole - */ -public enum MetadataSourceProcessingOrder { - ANNOTATIONS_FIRST, - HBM_FIRST -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java index 2f6e485947..5afa3fe940 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuilderImpl.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; + import javax.persistence.SharedCacheMode; import org.hibernate.HibernateException; @@ -43,7 +44,6 @@ import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.metamodel.MetadataBuilder; -import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.archive.scan.internal.StandardScanOptions; import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment; @@ -62,10 +62,8 @@ import org.hibernate.type.CustomType; import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.UserType; - import org.jboss.jandex.IndexView; import org.jboss.logging.Logger; - import org.xml.sax.EntityResolver; import static org.hibernate.internal.DeprecationLogger.DEPRECATION_LOGGER; @@ -136,12 +134,6 @@ public MetadataBuilder with(EntityResolver entityResolver) { return this; } - @Override - public MetadataBuilder with(MetadataSourceProcessingOrder metadataSourceProcessingOrder) { - this.options.metadataSourceProcessingOrder = metadataSourceProcessingOrder; - return this; - } - @Override public MetadataBuilder with(SharedCacheMode sharedCacheMode) { this.options.sharedCacheMode = sharedCacheMode; @@ -338,7 +330,6 @@ public static class Options implements org.hibernate.metamodel.spi.MetadataBuild StandardPersistentAttributeMemberResolver.INSTANCE; // todo : go away - private MetadataSourceProcessingOrder metadataSourceProcessingOrder = MetadataSourceProcessingOrder.HBM_FIRST; private EntityResolver entityResolver = EJB3DTDEntityResolver.INSTANCE; public Options(StandardServiceRegistry serviceRegistry) { @@ -491,11 +482,6 @@ public PersistentAttributeMemberResolver getPersistentAttributeMemberResolver() return persistentAttributeMemberResolver; } - @Override - public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder() { - return metadataSourceProcessingOrder; - } - @Override public EntityResolver getEntityResolver() { return entityResolver; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java index ecc528a416..7e545271ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataBuildingProcess.java @@ -60,7 +60,6 @@ import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.NamedStoredProcedureQueryDefinition; import org.hibernate.metamodel.SessionFactoryBuilder; @@ -78,10 +77,9 @@ import org.hibernate.metamodel.reflite.internal.JavaTypeDescriptorRepositoryImpl; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptorRepository; -import org.hibernate.metamodel.source.internal.annotations.AnnotationMetadataSourceProcessorImpl; +import org.hibernate.metamodel.source.internal.annotations.AnnotationMetadataSourceProcessor; import org.hibernate.metamodel.source.internal.annotations.JandexAccess; import org.hibernate.metamodel.source.internal.annotations.JandexAccessImpl; -import org.hibernate.metamodel.source.internal.hbm.HbmMetadataSourceProcessorImpl; import org.hibernate.metamodel.source.internal.jandex.Unifier; import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; import org.hibernate.metamodel.source.spi.FilterDefinitionSource; @@ -91,12 +89,12 @@ import org.hibernate.metamodel.source.spi.MetaAttributeContext; import org.hibernate.metamodel.source.spi.TypeDescriptorSource; import org.hibernate.metamodel.spi.AdditionalJaxbRootProducer; +import org.hibernate.metamodel.spi.AdditionalJaxbRootProducer.AdditionalJaxbRootProducerContext; import org.hibernate.metamodel.spi.BindingContext; import org.hibernate.metamodel.spi.ClassLoaderAccess; import org.hibernate.metamodel.spi.InFlightMetadataCollector; import org.hibernate.metamodel.spi.MetadataBuildingOptions; import org.hibernate.metamodel.spi.MetadataContributor; -import org.hibernate.metamodel.spi.MetadataSourceProcessor; import org.hibernate.metamodel.spi.PluralAttributeElementNature; import org.hibernate.metamodel.spi.TypeContributions; import org.hibernate.metamodel.spi.TypeContributor; @@ -132,13 +130,10 @@ import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.UserType; import org.hibernate.xml.spi.BindResult; - import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; import org.jboss.logging.Logger; -import static org.hibernate.metamodel.spi.AdditionalJaxbRootProducer.AdditionalJaxbRootProducerContext; - /** * Represents the process of building a Metadata object. The main entry point is the * static {@link #build} @@ -224,25 +219,14 @@ public JandexInitializer getJandexInitializer() { // NOTE : this becomes even more simplified after we move purely // to unified model - final MetadataSourceProcessor[] metadataSourceProcessors; - if ( options.getMetadataSourceProcessingOrder() == MetadataSourceProcessingOrder.HBM_FIRST ) { - metadataSourceProcessors = new MetadataSourceProcessor[] { - new HbmMetadataSourceProcessorImpl( rootBindingContext, sources ), - new AnnotationMetadataSourceProcessorImpl( rootBindingContext, jandexView ) - }; - } - else { - metadataSourceProcessors = new MetadataSourceProcessor[] { - new AnnotationMetadataSourceProcessorImpl( rootBindingContext, jandexView ), - new HbmMetadataSourceProcessorImpl( rootBindingContext, sources ) - }; - } + final AnnotationMetadataSourceProcessor processor = new AnnotationMetadataSourceProcessor( + rootBindingContext, jandexView ); - processTypeDefinitions( metadataSourceProcessors, rootBindingContext ); - processFilterDefinitions( metadataSourceProcessors, rootBindingContext ); - processIdentifierGenerators( metadataSourceProcessors, rootBindingContext ); - processMappings( metadataSourceProcessors, rootBindingContext ); - bindMappingDependentMetadata( metadataSourceProcessors, rootBindingContext ); + processTypeDefinitions( processor, rootBindingContext ); + processFilterDefinitions( processor, rootBindingContext ); + processIdentifierGenerators( processor, rootBindingContext ); + processMappings( processor, rootBindingContext ); + bindMappingDependentMetadata( processor, rootBindingContext ); final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class ); @@ -265,10 +249,6 @@ public StandardServiceRegistry getServiceRegistry() { for ( AdditionalJaxbRootProducer producer : classLoaderService.loadJavaServices( AdditionalJaxbRootProducer.class ) ) { bindResults.addAll( producer.produceRoots( metadataCollector, jaxbRootProducerContext ) ); } - final HbmMetadataSourceProcessorImpl processor = new HbmMetadataSourceProcessorImpl( rootBindingContext, bindResults ); - final Binder binder = new Binder( rootBindingContext ); - binder.addEntityHierarchies( processor.extractEntityHierarchies() ); - binder.bindEntityHierarchies(); secondPass( rootBindingContext ); @@ -476,40 +456,36 @@ public void contributeType(CompositeUserType type, String[] keys) { } private static void processTypeDefinitions( - MetadataSourceProcessor[] metadataSourceProcessors, + AnnotationMetadataSourceProcessor processor, RootBindingContextImpl bindingContext) { final ClassLoaderService cls = bindingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class ); - for ( MetadataSourceProcessor processor : metadataSourceProcessors ) { - for ( TypeDescriptorSource typeDescriptorSource : processor.extractTypeDefinitionSources() ) { - bindingContext.getMetadataCollector().addTypeDefinition( - new TypeDefinition( - typeDescriptorSource.getName(), - cls.classForName( typeDescriptorSource.getTypeImplementationClassName() ), - typeDescriptorSource.getRegistrationKeys(), - typeDescriptorSource.getParameters() - ) - ); - } + for ( TypeDescriptorSource typeDescriptorSource : processor.extractTypeDefinitionSources() ) { + bindingContext.getMetadataCollector().addTypeDefinition( + new TypeDefinition( + typeDescriptorSource.getName(), + cls.classForName( typeDescriptorSource.getTypeImplementationClassName() ), + typeDescriptorSource.getRegistrationKeys(), + typeDescriptorSource.getParameters() + ) + ); } } private static void processFilterDefinitions( - MetadataSourceProcessor[] metadataSourceProcessors, + AnnotationMetadataSourceProcessor processor, RootBindingContextImpl bindingContext) { - for ( MetadataSourceProcessor processor : metadataSourceProcessors ) { - for ( FilterDefinitionSource filterDefinitionSource : processor.extractFilterDefinitionSources() ) { - bindingContext.getMetadataCollector().addFilterDefinition( - new FilterDefinition( - filterDefinitionSource.getName(), - filterDefinitionSource.getCondition(), - resolveFilterDefinitionParamType( - filterDefinitionSource.getParameterSources(), - bindingContext - ) - ) - ); - } + for ( FilterDefinitionSource filterDefinitionSource : processor.extractFilterDefinitionSources() ) { + bindingContext.getMetadataCollector().addFilterDefinition( + new FilterDefinition( + filterDefinitionSource.getName(), + filterDefinitionSource.getCondition(), + resolveFilterDefinitionParamType( + filterDefinitionSource.getParameterSources(), + bindingContext + ) + ) + ); } } @@ -533,34 +509,30 @@ private static Map resolveFilterDefinitionParam } private static void processIdentifierGenerators( - MetadataSourceProcessor[] metadataSourceProcessors, + AnnotationMetadataSourceProcessor processor, RootBindingContextImpl bindingContext) { - for ( MetadataSourceProcessor processor : metadataSourceProcessors ) { - for ( IdentifierGeneratorSource identifierGeneratorSource : processor.extractGlobalIdentifierGeneratorSources() ) { - bindingContext.getMetadataCollector().addIdGenerator( - new IdentifierGeneratorDefinition( - identifierGeneratorSource.getGeneratorName(), - identifierGeneratorSource.getGeneratorImplementationName(), - identifierGeneratorSource.getParameters() - ) - ); - } + for ( IdentifierGeneratorSource identifierGeneratorSource : processor.extractGlobalIdentifierGeneratorSources() ) { + bindingContext.getMetadataCollector().addIdGenerator( + new IdentifierGeneratorDefinition( + identifierGeneratorSource.getGeneratorName(), + identifierGeneratorSource.getGeneratorImplementationName(), + identifierGeneratorSource.getParameters() + ) + ); } } private static void processMappings( - MetadataSourceProcessor[] metadataSourceProcessors, + AnnotationMetadataSourceProcessor processor, RootBindingContextImpl bindingContext) { final Binder binder = new Binder( bindingContext ); // Add all hierarchies first, before binding. - for ( MetadataSourceProcessor processor : metadataSourceProcessors ) { - binder.addEntityHierarchies( processor.extractEntityHierarchies() ); - } + binder.addEntityHierarchies( processor.extractEntityHierarchies() ); binder.bindEntityHierarchies(); } private static void bindMappingDependentMetadata( - MetadataSourceProcessor[] metadataSourceProcessors, + AnnotationMetadataSourceProcessor processor, RootBindingContextImpl bindingContext) { // Create required back references, which are required for one-to-many associations with key bindings that are non-inverse, // non-nullable, and unidirectional @@ -643,9 +615,7 @@ private static void bindMappingDependentMetadata( } } - for ( MetadataSourceProcessor metadataSourceProcessor : metadataSourceProcessors ) { - metadataSourceProcessor.processMappingDependentMetadata(); - } + processor.processMappingDependentMetadata(); } private static void secondPass(RootBindingContextImpl bindingContext) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AnnotationMetadataSourceProcessor.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AnnotationMetadataSourceProcessor.java index f8f6e0f06a..a8dcaad8cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/AnnotationMetadataSourceProcessor.java @@ -42,8 +42,6 @@ import org.hibernate.metamodel.source.spi.IdentifierGeneratorSource; import org.hibernate.metamodel.source.spi.TypeDescriptorSource; import org.hibernate.metamodel.spi.BindingContext; -import org.hibernate.metamodel.spi.MetadataSourceProcessor; - import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.IndexView; @@ -55,10 +53,10 @@ * @author Hardy Ferentschik * @author Steve Ebersole */ -public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProcessor { +public class AnnotationMetadataSourceProcessor { private final AnnotationBindingContext bindingContext; - public AnnotationMetadataSourceProcessorImpl(BindingContext bindingContext, IndexView jandexView) { + public AnnotationMetadataSourceProcessor(BindingContext bindingContext, IndexView jandexView) { if ( !jandexView.getAnnotations( PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS ).isEmpty() ) { // todo : this needs to move to AnnotationBindingContext @@ -69,7 +67,6 @@ public AnnotationMetadataSourceProcessorImpl(BindingContext bindingContext, Inde this.bindingContext = new AnnotationBindingContextImpl( bindingContext ); } - @Override public Iterable extractTypeDefinitionSources() { List typeDescriptorSources = new ArrayList(); Collection annotations = JandexHelper.getAnnotations( @@ -84,7 +81,6 @@ public Iterable extractTypeDefinitionSources() { return typeDescriptorSources; } - @Override public Iterable extractFilterDefinitionSources() { List filterDefinitionSources = new ArrayList(); Collection annotations = JandexHelper.getAnnotations( @@ -99,18 +95,15 @@ public Iterable extractFilterDefinitionSources() { return filterDefinitionSources; } - @Override public Iterable extractGlobalIdentifierGeneratorSources() { return IdGeneratorProcessor.extractGlobalIdentifierGeneratorSources( bindingContext ); } - @Override public Collection extractEntityHierarchies() { // need to order our annotated entities into an order we can process return EntityHierarchyBuilder.createEntityHierarchies( bindingContext ); } - @Override public void processMappingDependentMetadata() { TableProcessor.bind( bindingContext ); FetchProfileProcessor.bind( bindingContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractConstraintSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractConstraintSource.java deleted file mode 100644 index a8abce0c32..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractConstraintSource.java +++ /dev/null @@ -1,108 +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.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.metamodel.source.spi.ConstraintSource; - -/** - * @author Hardy Ferentschik - */ -class AbstractConstraintSource implements ConstraintSource { - protected final String name; - protected final String tableName; - protected final List columnNames = new ArrayList(); - protected final List orderings = new ArrayList(); - - protected AbstractConstraintSource(String name, String tableName) { - this.name = name; - this.tableName = tableName; - } - - @Override - public String name() { - return name; - } - - @Override - public String getTableName() { - return tableName; - } - - @Override - public List columnNames() { - return columnNames; - } - - public void addColumnName( String columnName ) { - columnNames.add( columnName ); - // TODO: Can HBM have orderings? For now, just add a null -- Binder expects columnNames and - // orderings to be the same size. Find a better data representation... - orderings.add( null ); - } - - public List orderings() { - return orderings; - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - - AbstractConstraintSource that = (AbstractConstraintSource) o; - - if ( columnNames != null ? !columnNames.equals( that.columnNames ) : that.columnNames != null ) { - return false; - } - if ( orderings != null ? !orderings.equals( that.orderings ) : that.orderings != null ) { - return false; - } - if ( name != null ? !name.equals( that.name ) : that.name != null ) { - return false; - } - if ( tableName != null ? !tableName.equals( that.tableName ) : that.tableName != null ) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + ( tableName != null ? tableName.hashCode() : 0 ); - result = 31 * result + ( columnNames != null ? columnNames.hashCode() : 0 ); - result = 31 * result + ( orderings != null ? orderings.hashCode() : 0 ); - return result; - } -} - - diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java deleted file mode 100644 index 3ec044ff3c..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddableJaxbSource.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Collections; -import java.util.List; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; - -/** - * @author Steve Ebersole - */ -public abstract class AbstractEmbeddableJaxbSource implements EmbeddableJaxbSource { - @Override - public List getKeyPropertyElementList() { - return Collections.emptyList(); - } - - @Override - public List getKeyManyToOneElementList() { - return Collections.emptyList(); - } - - @Override - public List getPropertyElementList() { - return Collections.emptyList(); - } - - @Override - public List getManyToOneElementList() { - return Collections.emptyList(); - } - - @Override - public List getOneToOneElementList() { - return Collections.emptyList(); - } - - @Override - public List getComponentElementList() { - return Collections.emptyList(); - } - - @Override - public List getNestedCompositeElementList() { - return Collections.emptyList(); - } - - @Override - public List getDynamicComponentElementList() { - return Collections.emptyList(); - } - - @Override - public List getPropertiesElementList() { - return Collections.emptyList(); - } - - @Override - public List getAnyElementList() { - return Collections.emptyList(); - } - - @Override - public List getMapElementList() { - return Collections.emptyList(); - } - - @Override - public List getSetElementList() { - return Collections.emptyList(); - } - - @Override - public List getListElementList() { - return Collections.emptyList(); - } - - @Override - public List getBagElementList() { - return Collections.emptyList(); - } - - @Override - public List getArrayElementList() { - return Collections.emptyList(); - } - - @Override - public List getPrimitiveArrayElementList() { - return Collections.emptyList(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java deleted file mode 100644 index 5debfa0644..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEmbeddedAttributeSourceImpl.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Collection; -import java.util.List; - -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.jaxb.hbm.ComponentSourceElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.EmbeddableSource; -import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; -import org.hibernate.metamodel.source.spi.HibernateTypeSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; - -/** - * Common bas class for and mappings. - * - * @author Steve Ebersole - */ -public abstract class AbstractEmbeddedAttributeSourceImpl - extends AbstractHbmSourceNode - implements EmbeddedAttributeSource { - - private final ComponentSourceElement jaxbComponentSourceElement; - private final EmbeddableSourceImpl embeddableSource; - - protected AbstractEmbeddedAttributeSourceImpl( - MappingDocument sourceMappingDocument, - AttributeSourceContainer parentContainer, - AttributeRole attributeRoleBase, - AttributePath attributePathBase, - ComponentSourceElement jaxbComponentSourceElement, - EmbeddableJaxbSource embeddableJaxbSource, - NaturalIdMutability naturalIdMutability, - String logicalTableName) { - super( sourceMappingDocument ); - this.jaxbComponentSourceElement = jaxbComponentSourceElement; - this.embeddableSource = new EmbeddableSourceImpl( - sourceMappingDocument, - attributeRoleBase, - attributePathBase, - embeddableJaxbSource, - logicalTableName, - naturalIdMutability - ); - } - - protected ComponentSourceElement jaxbComponentSourceElement() { - return jaxbComponentSourceElement; - } - - @Override - public EmbeddableSource getEmbeddableSource() { - return embeddableSource; - } - - @Override - public String getName() { - return jaxbComponentSourceElement.getName(); - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.COMPOSITE; - } - - @Override - public HibernateTypeSource getTypeInformation() { - // does not support type information. - return null; - } - - @Override - public String getPropertyAccessorName() { - return jaxbComponentSourceElement.getAccess(); - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return null; - } - - @Override - public Collection getToolingHintSources() { - return jaxbComponentSourceElement.getMeta(); - } - - @Override - public PropertyGeneration getGeneration() { - // todo : is this correct here? - return null; - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } - - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // relational value source info comes from the individual sub-attributes - - @Override - public String getContainingTableName() { - return null; - } - - @Override - public List relationalValueSources() { - // none, they are defined on the simple sub-attributes - return null; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java deleted file mode 100644 index f0a6fd4597..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractEntitySourceImpl.java +++ /dev/null @@ -1,638 +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.source.internal.hbm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.hibernate.EntityMode; -import org.hibernate.TruthValue; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIdbagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbJoinElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JoinElementSource; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.ConstraintSource; -import org.hibernate.metamodel.source.spi.EntityHierarchySource; -import org.hibernate.metamodel.source.spi.EntitySource; -import org.hibernate.metamodel.source.spi.FilterSource; -import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; -import org.hibernate.metamodel.source.spi.JpaCallbackSource; -import org.hibernate.metamodel.source.spi.SecondaryTableSource; -import org.hibernate.metamodel.source.spi.SubclassEntitySource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.binding.CustomSQL; -import org.hibernate.xml.spi.Origin; - -/** - * @author Steve Ebersole - * @author Hardy Ferentschik - * @author Brett Meyer - */ -public abstract class AbstractEntitySourceImpl - extends AbstractHbmSourceNode - implements EntitySource, Helper.InLineViewNameInferrer { - - private final EntityElement entityElement; - private final String className; - private final String entityName; - private final String jpaEntityName; - - private final AttributeRole attributeRoleBase; - private final AttributePath attributePathBase; - - private List subclassEntitySources = new ArrayList(); - - private int inLineViewCount = 0; - - // logically final, but built during 'afterInstantiation' callback - private List attributeSources; - private Set secondaryTableSources; - private final FilterSource[] filterSources; - - private Map constraintMap = new HashMap(); - - protected AbstractEntitySourceImpl(MappingDocument sourceMappingDocument, EntityElement entityElement) { - super( sourceMappingDocument ); - this.entityElement = entityElement; - - this.className = bindingContext().qualifyClassName( entityElement.getName() ); - if ( StringHelper.isNotEmpty( entityElement.getEntityName() ) ) { - this.entityName = entityElement.getEntityName(); - this.jpaEntityName = entityElement.getEntityName(); - } - else { - this.entityName = className; - this.jpaEntityName = StringHelper.unqualify( className ); - } - - this.attributePathBase = new AttributePath(); - this.attributeRoleBase = new AttributeRole( entityName ); - - this.filterSources = buildFilterSources(); - } - - @Override - public String getTypeName() { - return StringHelper.isNotEmpty( className ) ? className : entityName; - } - - @Override - public AttributePath getAttributePathBase() { - return attributePathBase; - } - - @Override - public AttributeRole getAttributeRoleBase() { - return attributeRoleBase; - } - - @Override - public Collection getSubTypes() { - return subclassEntitySources; - } - - private FilterSource[] buildFilterSources() { - //todo for now, i think all EntityElement should support this. - if ( JaxbClassElement.class.isInstance( entityElement() ) ) { - JaxbClassElement jaxbClassElement = JaxbClassElement.class.cast( entityElement() ); - final int size = jaxbClassElement.getFilter().size(); - if ( size == 0 ) { - return null; - } - - FilterSource[] results = new FilterSource[size]; - for ( int i = 0; i < size; i++ ) { - JaxbFilterElement element = jaxbClassElement.getFilter().get( i ); - results[i] = new FilterSourceImpl( sourceMappingDocument(), element ); - } - return results; - } - else { - return null; - } - - } - - @Override - public FilterSource[] getFilterSources() { - return filterSources; - } - - @Override - public String inferInLineViewName() { - return entityName + '#' + (++inLineViewCount); - } - - protected void afterInstantiation() { - this.attributeSources = buildAttributeSources(); - this.secondaryTableSources = buildSecondaryTables(); - } - - protected List buildAttributeSources() { - List attributeSources = new ArrayList(); - buildAttributeSources( attributeSources ); - return attributeSources; - } - - protected List buildAttributeSources(List attributeSources) { - return buildAttributeSources( entityElement, attributeSources, null, NaturalIdMutability.NOT_NATURAL_ID ); - } - - protected List buildAttributeSources( - EntityElement element, - List attributeSources, - String logicTalbeName, - NaturalIdMutability naturalIdMutability){ - processPropertyAttributes( attributeSources, element.getProperty(), logicTalbeName, naturalIdMutability ); - processComponentAttributes( - attributeSources, - element.getComponent(), - logicTalbeName, - naturalIdMutability - ); - processDynamicComponentAttributes( - attributeSources, - element.getDynamicComponent(), - logicTalbeName, - naturalIdMutability - ); - processManyToOneAttributes( - attributeSources, - element.getManyToOne(), - logicTalbeName, - naturalIdMutability - ); - processOneToOneAttributes( - attributeSources, - element.getOneToOne(), - logicTalbeName, - naturalIdMutability - ); - processAnyAttributes( - attributeSources, - element.getAny(), - logicTalbeName, - naturalIdMutability - ); - processMapAttributes( attributeSources, element.getMap() ); - processListAttributes( attributeSources, element.getList() ); - processArrayAttributes( attributeSources, element.getArray() ); - processSetAttributes( attributeSources, element.getSet() ); - processIdBagAttributes( attributeSources, element.getIdbag() ); - processBagAttributes( attributeSources, element.getBag() ); - return attributeSources; - } - - protected void processPropertyAttributes( - List results, - List propertyElements, - String logicalTableName, - NaturalIdMutability naturalIdMutability) { - for ( JaxbPropertyElement element : propertyElements ) { - results.add( - new PropertyAttributeSourceImpl( - sourceMappingDocument(), - this, - element, - logicalTableName, - naturalIdMutability - ) - ); - - // TODO: Not sure this is the right place to do this. Can index constraints be defined by anything other - // than just a property? Split off into its own process method? - for ( JaxbColumnElement column : element.getColumn() ) { - // An index constraint can happen on the column element or the surrounding property element. - if ( !StringHelper.isEmpty( column.getIndex() ) ) { - addColumnToIndexConstraint( column.getIndex(), logicalTableName, column.getName() ); - } - if ( !StringHelper.isEmpty( element.getIndex() ) ) { - addColumnToIndexConstraint( element.getIndex(), logicalTableName, column.getName() ); - } - } - } - } - - private void addColumnToIndexConstraint(String constraintName, String logicalTableName, String columnName) { - if ( !constraintMap.containsKey( constraintName ) ) { - constraintMap.put( constraintName, new IndexConstraintSourceImpl( constraintName, logicalTableName ) ); - } - ( (AbstractConstraintSource) constraintMap.get( constraintName ) ).addColumnName( columnName ); - } - - protected void processComponentAttributes(List results, - List elements, - String logicalTableName, - NaturalIdMutability naturalIdMutability) { - for ( JaxbComponentElement element : elements ) { - results.add( - new EmbeddedAttributeSourceImpl( - sourceMappingDocument(), - this, - element, - naturalIdMutability, - logicalTableName - ) - ); - } - } - - protected void processDynamicComponentAttributes(List results, - List elements, - String logicalTableName, - NaturalIdMutability naturalIdMutability) { - // todo : implement - } - - protected void processManyToOneAttributes(List results, - List elements, - String logicalTableName, - NaturalIdMutability naturalIdMutability) { - for ( JaxbManyToOneElement element : elements ) { - results.add( - new ManyToOneAttributeSourceImpl( - sourceMappingDocument(), - this, - element, - logicalTableName, - naturalIdMutability - ) - ); - } - } - protected void processOneToOneAttributes(List results, - List elements, - String logicalTableName, - NaturalIdMutability naturalIdMutability) { - for ( JaxbOneToOneElement element : elements ) { - results.add( - new OneToOneAttributeSourceImpl( - sourceMappingDocument(), - this, - element, - logicalTableName, - naturalIdMutability - ) - ); - } - } - - protected void processAnyAttributes(List results, - List elements, - String logicalTableName, - NaturalIdMutability naturalIdMutability) { - // todo : implement - } - - protected void processMapAttributes(List results, - List propertyElements){ - for ( JaxbMapElement element : propertyElements ) { - results.add( - new MapSourceImpl( - sourceMappingDocument(), - element, this - ) - ); - } - } - protected void processArrayAttributes(List results, - List propertyElements){ - for ( JaxbArrayElement element : propertyElements ) { - results.add( - new ArraySourceImpl( - sourceMappingDocument(), - element, this - ) - ); - } - } - protected void processListAttributes(List results, - List propertyElements){ - for ( JaxbListElement element : propertyElements ) { - results.add( - new ListSourceImpl( - sourceMappingDocument(), - element, this - ) - ); - } - } - protected void processSetAttributes(List results, - List propertyElements){ - for ( JaxbSetElement element : propertyElements ) { - results.add( - new SetSourceImpl( - sourceMappingDocument(), - element, - this - ) - ); - } - } - - protected void processIdBagAttributes( - List results, - List elements){ - for ( JaxbIdbagElement element : elements ) { - results.add( - new IdBagSourceImpl( - sourceMappingDocument(), - element, - this - ) - ); - } - } - - protected void processBagAttributes( - List results, - List propertyElements) { - for ( JaxbBagElement element : propertyElements ) { - results.add( - new BagSourceImpl( - sourceMappingDocument(), - element, - this - ) - ); - } - } - - - private Set buildSecondaryTables() { - if ( ! JoinElementSource.class.isInstance( entityElement ) ) { - return Collections.emptySet(); - } - - final Set secondaryTableSources = new HashSet(); - for ( JaxbJoinElement joinElement : ( (JoinElementSource) entityElement ).getJoin() ) { - final SecondaryTableSourceImpl secondaryTableSource = new SecondaryTableSourceImpl( - sourceMappingDocument(), - joinElement, - this - ); - secondaryTableSources.add( secondaryTableSource ); - - final String logicalTableName = secondaryTableSource.getLogicalTableNameForContainedColumns(); - final NaturalIdMutability naturalIdMutability = NaturalIdMutability.NOT_NATURAL_ID; - processAnyAttributes( - attributeSources, - joinElement.getAny(), - logicalTableName, - naturalIdMutability - ); - processComponentAttributes( - attributeSources, - joinElement.getComponent(), - logicalTableName, - naturalIdMutability - ); - processDynamicComponentAttributes( - attributeSources, - joinElement.getDynamicComponent(), - logicalTableName, - naturalIdMutability - ); - processManyToOneAttributes( - attributeSources, - joinElement.getManyToOne(), - logicalTableName, - naturalIdMutability - ); - processPropertyAttributes( - attributeSources, - joinElement.getProperty(), - logicalTableName, - naturalIdMutability - ); - } - return secondaryTableSources; - } - - protected EntityElement entityElement() { - return entityElement; - } - - @Override - public Origin getOrigin() { - return origin(); - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return bindingContext(); - } - - @Override - public String getEntityName() { - return entityName; - } - - @Override - public String getClassName() { - return className; - } - - @Override - public String getJpaEntityName() { - return jpaEntityName; - } - - @Override - public boolean isAbstract() { - return entityElement().isAbstract(); - } - - @Override - public boolean isLazy() { - if(entityElement.isLazy()==null){ - return getLocalBindingContext().getMappingDefaults().areAssociationsLazy(); - } - return entityElement().isLazy(); - } - - @Override - public String getProxy() { - return entityElement.getProxy(); - } - - @Override - public int getBatchSize() { - return entityElement.getBatchSize(); - } - - @Override - public boolean isDynamicInsert() { - return entityElement.isDynamicInsert(); - } - - @Override - public boolean isDynamicUpdate() { - return entityElement.isDynamicUpdate(); - } - - @Override - public boolean isSelectBeforeUpdate() { - return entityElement.isSelectBeforeUpdate(); - } - - protected EntityMode determineEntityMode() { - return StringHelper.isNotEmpty( getClassName() ) ? EntityMode.POJO : EntityMode.MAP; - } - - @Override - public String getCustomTuplizerClassName() { - if ( entityElement.getTuplizer() == null ) { - return null; - } - final EntityMode entityMode = determineEntityMode(); - for ( JaxbTuplizerElement tuplizerElement : entityElement.getTuplizer() ) { - if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) { - return tuplizerElement.getClazz(); - } - } - return null; - } - - @Override - public String getCustomPersisterClassName() { - return getLocalBindingContext().qualifyClassName( entityElement.getPersister() ); - } - - @Override - public String getCustomLoaderName() { - return entityElement.getLoader() != null ? entityElement.getLoader().getQueryRef() : null; - } - - @Override - public CustomSQL getCustomSqlInsert() { - return Helper.buildCustomSql( entityElement.getSqlInsert() ); - } - - @Override - public CustomSQL getCustomSqlUpdate() { - return Helper.buildCustomSql( entityElement.getSqlUpdate() ); - } - - @Override - public CustomSQL getCustomSqlDelete() { - return Helper.buildCustomSql( entityElement.getSqlDelete() ); - } - - @Override - public String[] getSynchronizedTableNames() { - if ( CollectionHelper.isEmpty( entityElement.getSynchronize() ) ) { - return StringHelper.EMPTY_STRINGS; - } - else { - final int size = entityElement.getSynchronize().size(); - final String[] synchronizedTableNames = new String[size]; - for ( int i = 0; i < size; i++ ) { - synchronizedTableNames[i] = entityElement.getSynchronize().get( i ).getTable(); - } - return synchronizedTableNames; - } - } - - @Override - public java.util.Collection getToolingHintSources() { - return entityElement.getMeta(); - } - - @Override - public List attributeSources() { - return attributeSources; - } - - private EntityHierarchySourceImpl entityHierarchy; - - public void injectHierarchy(EntityHierarchySourceImpl entityHierarchy) { - this.entityHierarchy = entityHierarchy; - } - - @Override - public EntityHierarchySource getHierarchy() { - return entityHierarchy; - } - - void add(SubclassEntitySource subclassEntitySource) { - add( (SubclassEntitySourceImpl) subclassEntitySource ); - } - - void add(SubclassEntitySourceImpl subclassEntitySource) { - subclassEntitySource.injectHierarchy( entityHierarchy ); - entityHierarchy.processSubclass( subclassEntitySource ); - subclassEntitySources.add( subclassEntitySource ); - } - - @Override - public Iterable getConstraints() { - return constraintMap.values(); - } - - @Override - public Set getSecondaryTables() { - return secondaryTableSources; - } - - @Override - @SuppressWarnings( {"unchecked"}) - public List getJpaCallbackClasses() { - return Collections.EMPTY_LIST; - } - - @Override - public TruthValue quoteIdentifiersLocalToEntity() { - // HBM does not allow for this - return TruthValue.UNKNOWN; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractHbmSourceNode.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractHbmSourceNode.java deleted file mode 100644 index 9c9a22487c..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractHbmSourceNode.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbHibernateMapping; -import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.xml.spi.BindResult; -import org.hibernate.xml.spi.Origin; - -/** - * Base class for any and all source objects coming from {@code hbm.xml} parsing. Defines standard access - * back to the {@link MappingDocument} object and the services it provides (namely access to - * {@link HbmBindingContext}). - * - * @author Steve Ebersole - */ -public abstract class AbstractHbmSourceNode { - private final MappingDocument sourceMappingDocument; - - protected AbstractHbmSourceNode(MappingDocument sourceMappingDocument) { - this.sourceMappingDocument = sourceMappingDocument; - } - - protected MappingDocument sourceMappingDocument() { - return sourceMappingDocument; - } - - protected HbmBindingContext bindingContext() { - return sourceMappingDocument().getMappingLocalBindingContext(); - } - - protected Origin origin() { - return sourceMappingDocument().getOrigin(); - } - - protected BindResult mappingRoot() { - return sourceMappingDocument().getJaxbRoot(); - } - - protected JavaTypeDescriptor typeDescriptor(String className) { - return className == null ? - null : - bindingContext().typeDescriptor( className ); - } - - protected MappingException makeMappingException(String message) { - return bindingContext().makeMappingException( message ); - } - - protected MappingException makeMappingException(String message, Exception cause) { - return bindingContext().makeMappingException( message, cause ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAssociationElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAssociationElementSourceImpl.java deleted file mode 100644 index 96a22fe376..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAssociationElementSourceImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.metamodel.source.spi.AssociationSource; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.MappedByAssociationSource; -import org.hibernate.metamodel.source.spi.PluralAttributeSource; - -/** - + * @author Gail Badner - + */ -public abstract class AbstractPluralAssociationElementSourceImpl - extends AbstractHbmSourceNode implements AssociationSource { - - private final PluralAttributeSource pluralAttributeSource; - private final Set ownedAssociationSources = new HashSet( ); - - public AbstractPluralAssociationElementSourceImpl( - MappingDocument mappingDocument, - PluralAttributeSource pluralAttributeSource) { - super( mappingDocument ); - this.pluralAttributeSource = pluralAttributeSource; - } - - @Override - public AttributeSource getAttributeSource() { - return pluralAttributeSource; - } - - @Override - public Set getOwnedAssociationSources() { - return ownedAssociationSources; - } - - @Override - public void addMappedByAssociationSource(MappedByAssociationSource attributeSource) { - if ( attributeSource == null ) { - throw new IllegalArgumentException( "attributeSource must be non-null." ); - } - ownedAssociationSources.add( attributeSource ); - } - - @Override - public boolean isMappedBy() { - return false; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java deleted file mode 100644 index da2d128037..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractPluralAttributeSourceImpl.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.hibernate.AssertionFailure; -import org.hibernate.cfg.NotYetImplementedException; -import org.hibernate.engine.FetchStyle; -import org.hibernate.engine.FetchTiming; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.PluralAttributeElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; -import org.hibernate.metamodel.source.spi.CollectionIdSource; -import org.hibernate.metamodel.source.spi.FilterSource; -import org.hibernate.metamodel.source.spi.HibernateTypeSource; -import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.source.spi.PluralAttributeElementSource; -import org.hibernate.metamodel.source.spi.PluralAttributeKeySource; -import org.hibernate.metamodel.source.spi.PluralAttributeSource; -import org.hibernate.metamodel.source.spi.TableSpecificationSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.binding.Caching; -import org.hibernate.metamodel.spi.binding.CustomSQL; - -/** - * @author Steve Ebersole - * @author Brett Meyer - */ -public abstract class AbstractPluralAttributeSourceImpl - extends AbstractHbmSourceNode - implements PluralAttributeSource, Helper.InLineViewNameInferrer { - private final PluralAttributeElement pluralAttributeElement; - private final AttributeSourceContainer container; - - private final AttributeRole attributeRole; - private final AttributePath attributePath; - - private final HibernateTypeSource typeInformation; - - private final PluralAttributeKeySource keySource; - private final PluralAttributeElementSource elementSource; - private final Caching caching; - private final FilterSource[] filterSources; - - private JavaTypeDescriptor elementTypeDescriptor; - - protected AbstractPluralAttributeSourceImpl( - MappingDocument sourceMappingDocument, - final PluralAttributeElement pluralAttributeElement, - AttributeSourceContainer container) { - super( sourceMappingDocument ); - this.pluralAttributeElement = pluralAttributeElement; - this.container = container; - - this.attributeRole = container.getAttributeRoleBase().append( pluralAttributeElement.getName() ); - this.attributePath = container.getAttributePathBase().append( pluralAttributeElement.getName() ); - - this.keySource = new PluralAttributeKeySourceImpl( - sourceMappingDocument(), - pluralAttributeElement.getKey(), - container - ); - this.elementSource = interpretElementType(); - - this.caching = Helper.createCaching( pluralAttributeElement.getCache() ); - - this.typeInformation = new HibernateTypeSourceImpl( pluralAttributeElement.getCollectionType() ); - this.filterSources = buildFilterSources(); - } - - private FilterSource[] buildFilterSources() { - final int size = pluralAttributeElement.getFilter().size(); - if ( size == 0 ) { - return null; - } - - FilterSource[] results = new FilterSource[size]; - for ( int i = 0; i < size; i++ ) { - JaxbFilterElement element = pluralAttributeElement.getFilter().get( i ); - results[i] = new FilterSourceImpl( sourceMappingDocument(), element ); - } - return results; - - } - - private PluralAttributeElementSource interpretElementType() { - if ( pluralAttributeElement.getElement() != null ) { - // TODO: Is elementClassReference even needed in this context? - // If so, getType is currently null. -// elementClassReference = makeClassReference(pluralAttributeElement -// .getElement().getType().getName()); - return new PluralAttributeElementSourceBasicImpl( - sourceMappingDocument(), - pluralAttributeElement.getElement() - ); - } - else if ( pluralAttributeElement.getCompositeElement() != null ) { - elementTypeDescriptor = typeDescriptor( - pluralAttributeElement - .getCompositeElement().getClazz() - ); - return new PluralAttributeElementSourceEmbeddedImpl( - sourceMappingDocument(), - this, - pluralAttributeElement.getCompositeElement(), - pluralAttributeElement.getCascade() - ); - } - else if ( pluralAttributeElement.getOneToMany() != null ) { - elementTypeDescriptor = typeDescriptor( - pluralAttributeElement - .getOneToMany().getClazz() - ); - return new PluralAttributeElementSourceOneToManyImpl( - sourceMappingDocument(), - this, - pluralAttributeElement.getOneToMany(), - pluralAttributeElement.getCascade() - ); - } - else if ( pluralAttributeElement.getManyToMany() != null ) { - elementTypeDescriptor = typeDescriptor( - pluralAttributeElement - .getManyToMany().getClazz() - ); - return new PluralAttributeElementSourceManyToManyImpl( - sourceMappingDocument(), - this, - pluralAttributeElement.getManyToMany(), - pluralAttributeElement.getCascade() - ); - } - else if ( pluralAttributeElement.getManyToAny() != null ) { - throw new NotYetImplementedException( "Support for many-to-any not yet implemented" ); -// return Nature.MANY_TO_ANY; - } - else { - throw new MappingException( - "Unexpected collection element type : " + pluralAttributeElement.getName(), - bindingContext().getOrigin() - ); - } - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public PluralAttributeElementSource resolvePluralAttributeElementSource(AttributeSourceResolutionContext context) { - // elementSource is already resolved; nothing to do. - return elementSource; - } - - @Override - public boolean usesJoinTable() { - switch ( elementSource.getNature() ) { - case BASIC: - case AGGREGATE: - case ONE_TO_MANY: - return false; - case MANY_TO_MANY: - return true; - case MANY_TO_ANY: - throw new NotYetImplementedException( - String.format( "%s is not implemented yet.", elementSource.getNature() ) - ); - default: - throw new AssertionFailure( - String.format( - "Unexpected plural attribute element source nature: %s", - elementSource.getNature() - ) - ); - } - } - - public PluralAttributeElement getPluralAttributeElement() { - return pluralAttributeElement; - } - - protected AttributeSourceContainer container() { - return container; - } - - @Override - public FilterSource[] getFilterSources() { - return filterSources; - } - - @Override - public PluralAttributeKeySource getKeySource() { - return keySource; - } - - @Override - public PluralAttributeElementSource getElementSource() { - return elementSource; - } - - @Override - public JavaTypeDescriptor getElementTypeDescriptor() { - return elementTypeDescriptor; - } - - @Override - public boolean isMutable() { - return pluralAttributeElement.isMutable(); - } - - @Override - public int getBatchSize() { - return pluralAttributeElement.getBatchSize(); - } - - @Override - public String getMappedBy() { - return null; - } - - @Override - public String inferInLineViewName() { - return getAttributeRole().getFullPath(); - } - - @Override - public CollectionIdSource getCollectionIdSource() { - return null; - } - - @Override - public TableSpecificationSource getCollectionTableSpecificationSource() { - return pluralAttributeElement.getOneToMany() == null ? - Helper.createTableSource( sourceMappingDocument(), pluralAttributeElement, this ) : - null; - } - - @Override - public String getCollectionTableComment() { - return pluralAttributeElement.getComment(); - } - - @Override - public String getCollectionTableCheck() { - return pluralAttributeElement.getCheck(); - } - - @Override - public Caching getCaching() { - return caching; - } - - @Override - public String getWhere() { - return pluralAttributeElement.getWhere(); - } - - @Override - public String getName() { - return pluralAttributeElement.getName(); - } - - @Override - public boolean isSingular() { - return false; - } - - @Override - public HibernateTypeSource getTypeInformation() { - return typeInformation; - } - - @Override - public String getPropertyAccessorName() { - return pluralAttributeElement.getAccess(); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return pluralAttributeElement.isOptimisticLock(); - } - - @Override - public boolean isInverse() { - return pluralAttributeElement.isInverse(); - } - - @Override - public String getCustomPersisterClassName() { - return pluralAttributeElement.getPersister(); - } - - @Override - public String getCustomLoaderName() { - return pluralAttributeElement.getLoader() == null - ? null - : pluralAttributeElement.getLoader().getQueryRef(); - } - - @Override - public CustomSQL getCustomSqlInsert() { - return Helper.buildCustomSql( pluralAttributeElement.getSqlInsert() ); - } - - @Override - public CustomSQL getCustomSqlUpdate() { - return Helper.buildCustomSql( pluralAttributeElement.getSqlUpdate() ); - } - - @Override - public CustomSQL getCustomSqlDelete() { - return Helper.buildCustomSql( pluralAttributeElement.getSqlDelete() ); - } - - @Override - public CustomSQL getCustomSqlDeleteAll() { - return Helper.buildCustomSql( pluralAttributeElement.getSqlDeleteAll() ); - } - - @Override - public Collection getToolingHintSources() { - return pluralAttributeElement.getMeta(); - } - - @Override - public FetchTiming getFetchTiming() { - final String fetchSelection = pluralAttributeElement.getFetch() != null ? - pluralAttributeElement.getFetch().value() : - null; - final String lazySelection = pluralAttributeElement.getLazy() != null - ? pluralAttributeElement.getLazy().value() - : null; - final String outerJoinSelection = pluralAttributeElement.getOuterJoin() != null - ? pluralAttributeElement.getOuterJoin().value() - : null; - - if ( lazySelection == null ) { - if ( "join".equals( fetchSelection ) && "true".equals( outerJoinSelection ) ) { - return FetchTiming.IMMEDIATE; - } - else if ( "false".equals( outerJoinSelection ) ) { - return FetchTiming.DELAYED; - } - else { - return bindingContext().getMappingDefaults().areAssociationsLazy() - ? FetchTiming.DELAYED - : FetchTiming.IMMEDIATE; - } - } - else if ( "extra".equals( lazySelection ) ) { - return FetchTiming.EXTRA_LAZY; - } - else if ( "true".equals( lazySelection ) ) { - return FetchTiming.DELAYED; - } - else if ( "false".equals( lazySelection ) ) { - return FetchTiming.IMMEDIATE; - } - - throw new MappingException( - String.format( - "Unexpected lazy selection [%s] on '%s'", - lazySelection, - pluralAttributeElement.getName() - ), - origin() - ); - } - - @Override - public FetchStyle getFetchStyle() { - final String fetchSelection = pluralAttributeElement.getFetch() != null ? - pluralAttributeElement.getFetch().value() : - null; - final String outerJoinSelection = pluralAttributeElement.getOuterJoin() != null - ? pluralAttributeElement.getOuterJoin().value() - : null; - final int batchSize = getBatchSize(); - - if ( fetchSelection == null ) { - if ( outerJoinSelection == null ) { - return batchSize > 1 ? FetchStyle.BATCH : FetchStyle.SELECT; - } - else { - if ( "auto".equals( outerJoinSelection ) ) { - return bindingContext().getMappingDefaults().areAssociationsLazy() - ? FetchStyle.SELECT - : FetchStyle.JOIN; - } - else { - return "true".equals( outerJoinSelection ) ? FetchStyle.JOIN : FetchStyle.SELECT; - } - } - } - else { - if ( "subselect".equals( fetchSelection ) ) { - return FetchStyle.SUBSELECT; - } - else { - return "join".equals( fetchSelection ) ? FetchStyle.JOIN : FetchStyle.SELECT; - } - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractReturnBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractReturnBinder.java deleted file mode 100644 index 9c6977ef82..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractReturnBinder.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.hibernate.LockMode; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.ReturnElement; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.LocalBindingContext; - -/** - * @author Strong Liu - */ -abstract class AbstractReturnBinder { - protected final InFlightMetadataCollector metadataCollector; - protected final T element; - protected final LocalBindingContext context; - protected final String alias; - protected final LockMode lockMode; - protected List returnPropertyElements; - - AbstractReturnBinder( - final T element, - final int elementIndex, - final LocalBindingContext context, - final InFlightMetadataCollector metadataCollector) { - this.context = context; - this.metadataCollector = metadataCollector; - this.element = element; - this.alias = getAlias( element, elementIndex ); - this.lockMode = Helper.interpretLockMode( element.getLockMode(), context ); - this.returnPropertyElements = element.getReturnProperty(); - } - - private static String getAlias(ReturnElement element, int elementCount) { - return StringHelper.isEmpty( element.getAlias() ) ? "alias_" + elementCount : element.getAlias(); - } - - abstract NativeSQLQueryReturn process(); - - protected void processReturnProperties(ReturnPropertiesCallback callback) { - for ( JaxbReturnPropertyElement propertyElement : returnPropertyElements ) { - callback.process( propertyElement ); - } - } - - static interface ReturnPropertiesCallback { - void process(JaxbReturnPropertyElement propertyElement); - } - - static class ReturnPropertiesCallbackImpl implements ReturnPropertiesCallback { - private final LocalBindingContext bindingContext; - private final String alias; - private final Map propertyResults; - - ReturnPropertiesCallbackImpl( - final String alias, final Map propertyResults, - final LocalBindingContext bindingContext) { - this.alias = alias; - this.bindingContext = bindingContext; - this.propertyResults = propertyResults; - } - - @Override - public void process(final JaxbReturnPropertyElement propertyElement) { - final String name = propertyElement.getName(); - if ( StringHelper.isEmpty( name ) ) { - throw bindingContext.makeMappingException( "Empty return property name on alias " + alias ); - } - if ( name.contains( "." ) ) { - throw bindingContext.makeMappingException( - "dotted notation in or not yet supported" - ); - } - if ( propertyResults.containsKey( name ) ) { - throw bindingContext.makeMappingException( - "duplicate return-property for property " + name + " on alias " + alias - ); - } - final List returnColumnNames = getResultColumns( propertyElement, bindingContext ); - - if ( returnColumnNames.isEmpty() ) { - throw bindingContext.makeMappingException( - "return-property for alias " + alias + " must specify at least one column or return-column name" - ); - } - - propertyResults.put( name, returnColumnNames.toArray( new String[returnColumnNames.size()] ) ); - } - - private static List getResultColumns( - final JaxbReturnPropertyElement propertyresult, final LocalBindingContext context) { - List allResultColumns = new ArrayList(); - if ( propertyresult.getColumn() != null ) { - String column = context.getMetadataCollector().getObjectNameNormalizer() - .normalizeIdentifierQuoting( propertyresult.getColumn() ); - allResultColumns.add( column ); - } - for ( JaxbReturnPropertyElement.JaxbReturnColumn returnColumn : propertyresult.getReturnColumn() ) { - if ( returnColumn.getName() != null ) { - String column = context.getMetadataCollector().getObjectNameNormalizer() - .normalizeIdentifierQuoting( returnColumn.getName() ); - - allResultColumns.add( column ); - } - } - return allResultColumns; - } - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java deleted file mode 100644 index c71a0c6a08..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/AbstractToOneAttributeSourceImpl.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.hibernate.cfg.NamingStrategy; -import org.hibernate.engine.FetchStyle; -import org.hibernate.engine.FetchTiming; -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.AttributeSourceResolutionContext; -import org.hibernate.metamodel.source.spi.MappedByAssociationSource; -import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.source.spi.ToOneAttributeSource; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; -import org.hibernate.metamodel.spi.relational.TableSpecification; -import org.hibernate.metamodel.spi.relational.Value; - -/** - * @author Gail Badner - */ -public abstract class AbstractToOneAttributeSourceImpl extends AbstractHbmSourceNode implements ToOneAttributeSource{ - private final NaturalIdMutability naturalIdMutability; - private final String propertyRef; - private final Set ownedAssociationSources = new HashSet( ); - - AbstractToOneAttributeSourceImpl( - MappingDocument sourceMappingDocument, - NaturalIdMutability naturalIdMutability, - String propertyRef) { - super( sourceMappingDocument ); - this.naturalIdMutability = naturalIdMutability; - this.propertyRef = propertyRef; - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return naturalIdMutability; - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public PropertyGeneration getGeneration() { - return PropertyGeneration.NEVER; - } - - @Override - public boolean isIgnoreNotFound() { - return false; - } - - @Override - public boolean isLazy() { - return getFetchTiming() != FetchTiming.IMMEDIATE; - } - - protected abstract boolean requiresImmediateFetch(); - protected abstract String getFetchSelectionString(); - protected abstract String getLazySelectionString(); - protected abstract String getOuterJoinSelectionString(); - - @Override - public boolean isUnWrapProxy() { - final String lazySelection = getLazySelectionString(); - return lazySelection != null && lazySelection.equals( "no-proxy" ); - } - - @Override - public FetchTiming getFetchTiming() { - final String lazySelection = getLazySelectionString(); - - if ( lazySelection == null ) { - if ( requiresImmediateFetch() ) { - return FetchTiming.IMMEDIATE; - } - else if ( "join".equals( getFetchSelectionString() ) || "true".equals( getOuterJoinSelectionString() ) ) { - return FetchTiming.IMMEDIATE; - } - else if ( "false".equals( getOuterJoinSelectionString() ) ) { - return FetchTiming.DELAYED; - } - else { - return bindingContext().getMappingDefaults().areAssociationsLazy() - ? FetchTiming.DELAYED - : FetchTiming.IMMEDIATE; - } - } - else if ( "extra".equals( lazySelection ) ) { - // TODO: don't think "extra" is valid here - return FetchTiming.EXTRA_LAZY; - } - else if ( "true".equals( lazySelection ) || "proxy".equals( lazySelection ) || "no-proxy".equals( lazySelection ) ) { - return FetchTiming.DELAYED; - } - else if ( "false".equals( lazySelection ) ) { - return FetchTiming.IMMEDIATE; - } - - throw new MappingException( - String.format( - "Unexpected lazy selection [%s] on '%s'", - lazySelection, - getName() - ), - origin() - ); - } - - @Override - public FetchStyle getFetchStyle() { - // todo : handle batch fetches? - - if ( getFetchSelectionString() == null ) { - if ( requiresImmediateFetch() ) { - return FetchStyle.JOIN; - } - else if ( getOuterJoinSelectionString() == null ) { - return FetchStyle.SELECT; - } - else { - if ( "auto".equals( getOuterJoinSelectionString() ) ) { - return bindingContext().getMappingDefaults().areAssociationsLazy() - ? FetchStyle.SELECT - : FetchStyle.JOIN; - } - else { - return "true".equals( getOuterJoinSelectionString() ) ? FetchStyle.JOIN : FetchStyle.SELECT; - } - } - } - else { - return "join".equals( getFetchSelectionString() ) ? FetchStyle.JOIN : FetchStyle.SELECT; - } - } - - @Override - // TODO: change to return the default name for a single column - public List getDefaultNamingStrategies( - final String entityName, - final String tableName, - final AttributeBinding referencedAttributeBinding) { - if ( EmbeddedAttributeBinding.class.isInstance( referencedAttributeBinding ) ) { - EmbeddedAttributeBinding embeddedAttributeBinding = EmbeddedAttributeBinding.class.cast( - referencedAttributeBinding - ); - List result = new ArrayList(); - for ( final AttributeBinding attributeBinding : embeddedAttributeBinding.getEmbeddableBinding().attributeBindings() ) { - result.addAll( getDefaultNamingStrategies( entityName, tableName, attributeBinding ) ); - } - return result; - } - else { - List result = new ArrayList( 1 ); - result.add( - new Binder.DefaultNamingStrategy() { - @Override - public String defaultName(NamingStrategy namingStrategy) { - return namingStrategy.propertyToColumnName( getName() ); - } - } - ); - return result; - } - - } - - @Override - public Set getOwnedAssociationSources() { - return ownedAssociationSources; - } - - @Override - public void addMappedByAssociationSource(MappedByAssociationSource attributeSource) { - ownedAssociationSources.add( attributeSource ); - } - - @Override - public boolean isMappedBy() { - // only applies to annotations - return false; - } - - @Override - public AttributeSource getAttributeSource() { - return this; - } - - @Override - public void resolveToOneAttributeSourceNature(AttributeSourceResolutionContext context) { - // nothing to do - } - - @Override - public void resolveToOneAttributeSourceNatureAsPartOfIdentifier() { - // nothing to do - } - - @Override - public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { - return propertyRef == null - ? null - : new JoinColumnResolutionDelegateImpl( propertyRef ); - } - - public static class JoinColumnResolutionDelegateImpl implements JoinColumnResolutionDelegate { - private final String propertyRef; - - public JoinColumnResolutionDelegateImpl(String propertyRef) { - this.propertyRef = propertyRef; - } - - @Override - public String getReferencedAttributeName() { - return propertyRef; - } - - @Override - public List getJoinColumns(JoinColumnResolutionContext context) { - return context.resolveRelationalValuesForAttribute( propertyRef ); - } - - @Override - public TableSpecification getReferencedTable(JoinColumnResolutionContext context) { - return context.resolveTableForAttribute( propertyRef ); - } - } - - @Override - public boolean createForeignKeyConstraint() { - // TODO: Can HBM do something like JPA's @ForeignKey(NO_CONSTRAINT)? - return true; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java deleted file mode 100644 index 5eb00196b7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ArraySourceImpl.java +++ /dev/null @@ -1,73 +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.source.internal.hbm; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; -import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; -import org.hibernate.metamodel.spi.PluralAttributeNature; - -/** - * @author Brett Meyer - */ -public class ArraySourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource { - - private final PluralAttributeSequentialIndexSource indexSource; - - public ArraySourceImpl( - MappingDocument sourceMappingDocument, - JaxbArrayElement arrayElement, - AttributeSourceContainer container) { - super( sourceMappingDocument, arrayElement, container ); - JaxbListIndexElement listIndexElement = arrayElement.getListIndex(); - if ( listIndexElement == null ) { - this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), arrayElement.getIndex() ); - } else { - this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listIndexElement ); - } - } - - @Override - public PluralAttributeIndexSource getIndexSource() { - return indexSource; - } - - @Override - public JaxbArrayElement getPluralAttributeElement() { - return ( JaxbArrayElement ) super.getPluralAttributeElement(); - } - - /** - * {@inheritDoc} - * - * @see org.hibernate.metamodel.source.spi.PluralAttributeSource#getNature() - */ - @Override - public PluralAttributeNature getNature() { - return PluralAttributeNature.ARRAY; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java deleted file mode 100644 index 091670e194..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/BagSourceImpl.java +++ /dev/null @@ -1,62 +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.source.internal.hbm; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.Orderable; -import org.hibernate.metamodel.spi.PluralAttributeNature; - -/** - * @author Steve Ebersole - */ -public class BagSourceImpl extends AbstractPluralAttributeSourceImpl implements Orderable { - public BagSourceImpl( - MappingDocument sourceMappingDocument, - JaxbBagElement bagElement, - AttributeSourceContainer container) { - super( sourceMappingDocument, bagElement, container ); - } - - @Override - public PluralAttributeNature getNature() { - return PluralAttributeNature.BAG; - } - - @Override - public JaxbBagElement getPluralAttributeElement() { - return (JaxbBagElement) super.getPluralAttributeElement(); - } - - @Override - public boolean isOrdered() { - return StringHelper.isNotEmpty( getOrder() ); - } - - @Override - public String getOrder() { - return getPluralAttributeElement().getOrderBy(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnAttributeSourceImpl.java deleted file mode 100644 index 0c06de5514..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnAttributeSourceImpl.java +++ /dev/null @@ -1,148 +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.source.internal.hbm; - -import org.hibernate.TruthValue; -import org.hibernate.metamodel.source.spi.ColumnSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.relational.JdbcDataType; - -/** - * Implementation of a {@link ColumnSource} when the column is declared as just the name via the column XML - * attribute. For example, {@code }. - * - * @author Steve Ebersole - */ -class ColumnAttributeSourceImpl - extends AbstractHbmSourceNode - implements ColumnSource { - private final String tableName; - private final String columnName; - private final SizeSource sizeSource; - private TruthValue includedInInsert; - private TruthValue includedInUpdate; - private TruthValue nullable; - - ColumnAttributeSourceImpl( - MappingDocument mappingDocument, - String tableName, - String columnName, - SizeSource sizeSource, - TruthValue includedInInsert, - TruthValue includedInUpdate) { - this( mappingDocument, tableName, columnName, sizeSource, includedInInsert, includedInUpdate, TruthValue.UNKNOWN ); - } - - ColumnAttributeSourceImpl( - MappingDocument mappingDocument, - String tableName, - String columnName, - SizeSource sizeSource, - TruthValue includedInInsert, - TruthValue includedInUpdate, - TruthValue nullable) { - super( mappingDocument ); - this.tableName = tableName; - this.columnName = columnName; - this.sizeSource = sizeSource; - this.includedInInsert = includedInInsert; - this.includedInUpdate = includedInUpdate; - this.nullable = nullable; - } - - @Override - public Nature getNature() { - return Nature.COLUMN; - } - - @Override - public TruthValue isIncludedInInsert() { - return includedInInsert; - } - - @Override - public TruthValue isIncludedInUpdate() { - return includedInUpdate; - } - - @Override - public String getContainingTableName() { - return tableName; - } - - @Override - public String getName() { - return columnName; - } - - @Override - public TruthValue isNullable() { - return nullable; - } - - @Override - public String getDefaultValue() { - return null; - } - - @Override - public String getSqlType() { - return null; - } - - @Override - public JdbcDataType getDatatype() { - return null; - } - - @Override - public SizeSource getSizeSource() { - return sizeSource; - } - - @Override - public String getReadFragment() { - return null; - } - - @Override - public String getWriteFragment() { - return null; - } - - @Override - public boolean isUnique() { - return false; - } - - @Override - public String getCheckCondition() { - return null; - } - - @Override - public String getComment() { - return null; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnSourceImpl.java deleted file mode 100644 index 2fdfc400e8..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ColumnSourceImpl.java +++ /dev/null @@ -1,143 +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.source.internal.hbm; - -import org.hibernate.TruthValue; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.spi.ColumnSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.relational.JdbcDataType; - -/** -* @author Steve Ebersole -*/ -class ColumnSourceImpl - extends AbstractHbmSourceNode - implements ColumnSource { - private final String tableName; - private final JaxbColumnElement columnElement; - private final TruthValue includedInInsert; - private final TruthValue includedInUpdate; - private final TruthValue nullable; - - ColumnSourceImpl( - MappingDocument mappingDocument, - String tableName, - JaxbColumnElement columnElement, - TruthValue isIncludedInInsert, - TruthValue isIncludedInUpdate) { - this( mappingDocument, tableName, columnElement, isIncludedInInsert, isIncludedInUpdate, TruthValue.UNKNOWN ); - } - - ColumnSourceImpl( - MappingDocument mappingDocument, - String tableName, - JaxbColumnElement columnElement, - TruthValue isIncludedInInsert, - TruthValue isIncludedInUpdate, - TruthValue nullable) { - super( mappingDocument ); - this.tableName = tableName; - this.columnElement = columnElement; - this.nullable = nullable; - this.includedInInsert = isIncludedInInsert; - this.includedInUpdate = isIncludedInUpdate; - } - - @Override - public Nature getNature() { - return Nature.COLUMN; - } - - @Override - public String getName() { - return columnElement.getName(); - } - - @Override - public TruthValue isNullable() { - return nullable; - } - - @Override - public String getDefaultValue() { - return columnElement.getDefault(); - } - - @Override - public String getSqlType() { - return columnElement.getSqlType(); - } - - @Override - public JdbcDataType getDatatype() { - return null; - } - - @Override - public SizeSource getSizeSource() { - return new SizeSourceImpl( columnElement.getPrecision(), columnElement.getScale(), columnElement.getLength() ); - } - - @Override - public String getReadFragment() { - return columnElement.getRead(); - } - - @Override - public String getWriteFragment() { - return columnElement.getWrite(); - } - - @Override - public boolean isUnique() { - // TODO: should TruthValue be returned instead of boolean? - return columnElement.isUnique() != null && columnElement.isUnique().booleanValue(); - } - - @Override - public String getCheckCondition() { - return columnElement.getCheck(); - } - - @Override - public String getComment() { - return columnElement.getComment(); - } - - @Override - public TruthValue isIncludedInInsert() { - return includedInInsert; - } - - @Override - public TruthValue isIncludedInUpdate() { - return includedInUpdate; - } - - @Override - public String getContainingTableName() { - return tableName; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java deleted file mode 100644 index a8e8c6a0b4..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableJaxbSource.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.List; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; - -/** - * Describes the JAXB source (HBM) for embeddable (composite) information. The - * HBM XML schema unfortunately did not define these consistently between - * {@code } and {@code }, so this contract unifies - * access to this information. - * - * @author Steve Ebersole - */ -public interface EmbeddableJaxbSource { - public String getClazz(); - - public String findParent(); - public String findTuplizer(); - - // todo : ultimately would be nice to remove the distinction between: - // * getKeyPropertyElementList() / getPropertyElementList() - // * getKeyManyToOneElementList() / getManyToOneElementList() - // the difference is really a matter of the "container", not the attribute - - public List getKeyPropertyElementList(); - - public List getKeyManyToOneElementList(); - - public List getPropertyElementList(); - - public List getManyToOneElementList(); - - public List getOneToOneElementList(); - - public List getComponentElementList(); - - public List getNestedCompositeElementList(); - - public List getDynamicComponentElementList(); - - public List getPropertiesElementList(); - - public List getAnyElementList(); - - public List getMapElementList(); - - public List getSetElementList(); - - public List getListElementList(); - - public List getBagElementList(); - - public List getArrayElementList(); - - public List getPrimitiveArrayElementList(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableSourceImpl.java deleted file mode 100644 index bdc6b11538..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddableSourceImpl.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.cfg.NotYetImplementedException; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToManyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToManyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.EmbeddableSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.NaturalIdMutability; - -/** - * @author Steve Ebersole - */ -public class EmbeddableSourceImpl extends AbstractHbmSourceNode implements EmbeddableSource { - private final EmbeddableJaxbSource embeddableSource; - private final JavaTypeDescriptor typeDescriptor; - - private final AttributeRole attributeRoleBase; - private final AttributePath attributePathBase; - - private final String logicalTableName; - private final NaturalIdMutability naturalIdMutability; - - private final List attributeSources; - - public EmbeddableSourceImpl( - MappingDocument mappingDocument, - AttributeRole attributeRoleBase, - AttributePath attributePathBase, - EmbeddableJaxbSource embeddableJaxbSource, - String logicalTableName, - NaturalIdMutability naturalIdMutability) { - super( mappingDocument ); - this.attributeRoleBase = attributeRoleBase; - this.attributePathBase = attributePathBase; - this.embeddableSource = embeddableJaxbSource; - this.logicalTableName = logicalTableName; - this.naturalIdMutability = naturalIdMutability; - - this.typeDescriptor = typeDescriptor( embeddableJaxbSource.getClazz() ); - - this.attributeSources = buildAttributeSources( embeddableJaxbSource, this ); - } - - @Override - public JavaTypeDescriptor getTypeDescriptor() { - return typeDescriptor; - } - - @Override - public String getParentReferenceAttributeName() { - return embeddableSource.findParent(); - } - - @Override - public String getExplicitTuplizerClassName() { - return embeddableSource.findTuplizer(); - } - - @Override - public AttributePath getAttributePathBase() { - return attributePathBase; - } - - @Override - public AttributeRole getAttributeRoleBase() { - return attributeRoleBase; - } - - @Override - public List attributeSources() { - return attributeSources; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return bindingContext(); - } - - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Attribute building - - protected static List buildAttributeSources( - EmbeddableJaxbSource container, - EmbeddableSourceImpl embeddableSource) { - final List attributeSources = new ArrayList(); - - for ( JaxbPropertyElement element : container.getPropertyElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbManyToOneElement element : container.getManyToOneElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbOneToOneElement element: container.getOneToOneElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbComponentElement element: container.getComponentElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbNestedCompositeElementElement element: container.getNestedCompositeElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbDynamicComponentElement element: container.getDynamicComponentElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource(element) ); - } - - for ( JaxbAnyElement element: container.getAnyElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbMapElement element: container.getMapElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbSetElement element: container.getSetElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - for ( JaxbListElement element: container.getListElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbBagElement element: container.getBagElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbArrayElement element: container.getArrayElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbPrimitiveArrayElement element: container.getPrimitiveArrayElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbKeyPropertyElement element : container.getKeyPropertyElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - for ( JaxbKeyManyToOneElement element : container.getKeyManyToOneElementList() ) { - attributeSources.add( embeddableSource.buildAttributeSource( element ) ); - } - - return attributeSources; - } - - private AttributeSource buildAttributeSource(JaxbKeyPropertyElement element) { - return new IdentifierKeyAttributeSourceImpl( sourceMappingDocument(), this, element ); - } - - private AttributeSource buildAttributeSource(JaxbKeyManyToOneElement element) { - return new IdentifierKeyManyToOneSourceImpl( sourceMappingDocument(), this, element ); - } - - protected SingularAttributeSource buildAttributeSource(JaxbPropertyElement attributeElement) { - return new PropertyAttributeSourceImpl( - sourceMappingDocument(), - this, - attributeElement, - logicalTableName, - naturalIdMutability - ); - } - - protected AttributeSource buildAttributeSource(JaxbComponentElement attributeElement) { - return new EmbeddedAttributeSourceImpl( - sourceMappingDocument(), - this, - attributeElement, - naturalIdMutability, - logicalTableName - ); - } - - private AttributeSource buildAttributeSource(JaxbNestedCompositeElementElement element) { - // todo : implement - throw new NotYetImplementedException(); - } - - protected AttributeSource buildAttributeSource(JaxbDynamicComponentElement attributeElement) { - // todo : implement - throw new NotYetImplementedException(); - } - - protected AttributeSource buildAttributeSource(JaxbManyToOneElement attributeElement) { - return new ManyToOneAttributeSourceImpl( - sourceMappingDocument(), - this, - attributeElement, - logicalTableName, - naturalIdMutability - ); - } - - protected AttributeSource buildAttributeSource(JaxbOneToOneElement attributeElement) { - return new OneToOneAttributeSourceImpl( - sourceMappingDocument(), - this, - attributeElement, - logicalTableName, - naturalIdMutability - ); - } - - protected AttributeSource buildAttributeSource(JaxbAnyElement attributeElement) { - // todo : implement - throw new NotYetImplementedException(); - } - - protected AttributeSource buildAttributeSource(JaxbOneToManyElement attributeElement) { - // todo : implement - throw new NotYetImplementedException(); - } - - protected AttributeSource buildAttributeSource(JaxbManyToManyElement attributeElement) { - // todo : implement - throw new NotYetImplementedException(); - } - - protected AttributeSource buildAttributeSource(JaxbMapElement attributeElement) { - return new MapSourceImpl( - sourceMappingDocument(), - attributeElement, - this - ); - } - protected AttributeSource buildAttributeSource(JaxbSetElement attributeElement) { - return new SetSourceImpl( - sourceMappingDocument(), - attributeElement, - this - ); - } - protected AttributeSource buildAttributeSource(JaxbListElement attributeElement) { - return new ListSourceImpl( - sourceMappingDocument(), - attributeElement, - this - ); - } - protected AttributeSource buildAttributeSource(JaxbBagElement attributeElement) { - return new BagSourceImpl( - sourceMappingDocument(), - attributeElement, - this - ); - } - protected AttributeSource buildAttributeSource(JaxbArrayElement attributeElement) { - return new ArraySourceImpl( - sourceMappingDocument(), - attributeElement, - this - ); - } - protected AttributeSource buildAttributeSource(JaxbPrimitiveArrayElement attributeElement) { - // todo : implement - throw new NotYetImplementedException(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java deleted file mode 100644 index eeb7b2b436..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EmbeddedAttributeSourceImpl.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.List; - -import org.hibernate.EntityMode; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDynamicComponentElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPrimitiveArrayElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertiesElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; - -/** - * The source information for a singular attribute whose type is composite - * (embedded in JPA terms). - * - * @author Steve Ebersole - */ -class EmbeddedAttributeSourceImpl extends AbstractEmbeddedAttributeSourceImpl { - public EmbeddedAttributeSourceImpl( - MappingDocument sourceMappingDocument, - AttributeSourceContainer parentContainer, - JaxbComponentElement jaxbComponentElement, - NaturalIdMutability naturalIdMutability, - String logicalTableName) { - super( - sourceMappingDocument, - parentContainer, - parentContainer.getAttributeRoleBase().append( jaxbComponentElement.getName() ), - parentContainer.getAttributePathBase().append( jaxbComponentElement.getName() ), - jaxbComponentElement, - new EmbeddableJaxbSourceImpl( jaxbComponentElement ), - naturalIdMutability, - logicalTableName - ); - } - - @Override - protected JaxbComponentElement jaxbComponentSourceElement() { - return (JaxbComponentElement) super.jaxbComponentSourceElement(); - } - - @Override - public boolean isLazy() { - return jaxbComponentSourceElement().isLazy(); - } - - @Override - public AttributePath getAttributePath() { - return getEmbeddableSource().getAttributePathBase(); - } - - @Override - public AttributeRole getAttributeRole() { - return getEmbeddableSource().getAttributeRoleBase(); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return jaxbComponentSourceElement().isOptimisticLock(); - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return jaxbComponentSourceElement().isInsert(); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return jaxbComponentSourceElement().isUpdate(); - } - - public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource { - private final JaxbComponentElement jaxbComponentElement; - - public EmbeddableJaxbSourceImpl(JaxbComponentElement jaxbComponentElement) { - this.jaxbComponentElement = jaxbComponentElement; - } - - @Override - public String getClazz() { - return jaxbComponentElement.getClazz(); - } - - @Override - public String findParent() { - return jaxbComponentElement.getParent() == null - ? null - : jaxbComponentElement.getParent().getName(); - } - - @Override - public String findTuplizer() { - if ( jaxbComponentElement.getTuplizer() == null ) { - return null; - } - - final EntityMode entityMode = StringHelper.isEmpty( jaxbComponentElement.getClazz() ) - ? EntityMode.MAP - : EntityMode.POJO; - - for ( JaxbTuplizerElement tuplizerElement : jaxbComponentElement.getTuplizer() ) { - if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) { - return tuplizerElement.getClazz(); - } - } - return null; - } - - @Override - public List getPropertyElementList() { - return jaxbComponentElement.getProperty(); - } - - @Override - public List getManyToOneElementList() { - return jaxbComponentElement.getManyToOne(); - } - - @Override - public List getOneToOneElementList() { - return jaxbComponentElement.getOneToOne(); - } - - @Override - public List getComponentElementList() { - return jaxbComponentElement.getComponent(); - } - - @Override - public List getDynamicComponentElementList() { - return jaxbComponentElement.getDynamicComponent(); - } - - @Override - public List getPropertiesElementList() { - return jaxbComponentElement.getProperties(); - } - - @Override - public List getAnyElementList() { - return jaxbComponentElement.getAny(); - } - - @Override - public List getMapElementList() { - return jaxbComponentElement.getMap(); - } - - @Override - public List getSetElementList() { - return jaxbComponentElement.getSet(); - } - - @Override - public List getListElementList() { - return jaxbComponentElement.getList(); - } - - @Override - public List getBagElementList() { - return jaxbComponentElement.getBag(); - } - - @Override - public List getArrayElementList() { - return jaxbComponentElement.getArray(); - } - - @Override - public List getPrimitiveArrayElementList() { - return jaxbComponentElement.getPrimitiveArray(); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java deleted file mode 100644 index d0f76c62c5..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/EntityHierarchySourceImpl.java +++ /dev/null @@ -1,734 +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.source.internal.hbm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.hibernate.EntityMode; -import org.hibernate.TruthValue; -import org.hibernate.engine.OptimisticLockStyle; -import org.hibernate.id.EntityIdentifierNature; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIdElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDiscriminatorElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMultiTenancyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPolymorphismAttribute; -import org.hibernate.metamodel.source.spi.AggregatedCompositeIdentifierSource; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.DiscriminatorSource; -import org.hibernate.metamodel.source.spi.EmbeddableSource; -import org.hibernate.metamodel.source.spi.EmbeddedAttributeSource; -import org.hibernate.metamodel.source.spi.EntityHierarchySource; -import org.hibernate.metamodel.source.spi.EntitySource; -import org.hibernate.metamodel.source.spi.IdentifierSource; -import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.source.spi.MapsIdSource; -import org.hibernate.metamodel.source.spi.MultiTenancySource; -import org.hibernate.metamodel.source.spi.NonAggregatedCompositeIdentifierSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SimpleIdentifierSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.source.spi.VersionAttributeSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.binding.Caching; -import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; -import org.hibernate.metamodel.spi.binding.InheritanceType; - -import org.jboss.logging.Logger; - -/** - * @author Steve Ebersole - */ -public class EntityHierarchySourceImpl implements EntityHierarchySource { - private static final Logger log = Logger.getLogger( EntityHierarchySourceImpl.class ); - - private final RootEntitySourceImpl rootEntitySource; - private InheritanceType hierarchyInheritanceType = InheritanceType.NO_INHERITANCE; - private final Caching caching; - private final Caching naturalIdCaching; - - public EntityHierarchySourceImpl(RootEntitySourceImpl rootEntitySource) { - this.rootEntitySource = rootEntitySource; - this.rootEntitySource.injectHierarchy( this ); - - this.caching = Helper.createCaching( entityElement().getCache() ); - this.naturalIdCaching = Helper.createNaturalIdCaching( - rootEntitySource.entityElement().getNaturalIdCache() - ); - } - - @Override - public InheritanceType getHierarchyInheritanceType() { - return hierarchyInheritanceType; - } - - @Override - public EntitySource getRoot() { - return rootEntitySource; - } - - public void processSubclass(SubclassEntitySourceImpl subclassEntitySource) { - final InheritanceType inheritanceType = Helper.interpretInheritanceType( subclassEntitySource.entityElement() ); - if ( hierarchyInheritanceType == InheritanceType.NO_INHERITANCE ) { - hierarchyInheritanceType = inheritanceType; - } - else if ( hierarchyInheritanceType != inheritanceType ) { - throw new MappingException( "Mixed inheritance strategies not supported", subclassEntitySource.getOrigin() ); - } - } - - - protected JaxbClassElement entityElement() { - return rootEntitySource.entityElement(); - } - - @Override - public IdentifierSource getIdentifierSource() { - if ( entityElement().getId() == null && entityElement().getCompositeId() == null ) { - throw rootEntitySource.getLocalBindingContext().makeMappingException( - String.format( "Entity [%s] did not define an identifier", rootEntitySource.getEntityName() ) - ); - } - - if ( entityElement().getId() != null ) { - return new SimpleIdentifierSourceImpl(); - } - else { - // if we get here, we should have a composite identifier. Just need - // to determine if it is aggregated, or non-aggregated... - if ( StringHelper.isEmpty( entityElement().getCompositeId().getName() ) ) { - if ( entityElement().getCompositeId().isMapped() && - StringHelper.isEmpty( entityElement().getCompositeId().getClazz() ) ) { - throw makeMappingException( "mapped composite identifier must name component class to use." ); - } - return new NonAggregatedCompositeIdentifierSourceImpl(); - } - else { - if ( entityElement().getCompositeId().isMapped() ) { - throw makeMappingException("cannot combine mapped=\"true\" with specified name"); - } - return new AggregatedCompositeIdentifierSourceImpl(); - } - } - } - - protected MappingException makeMappingException(String message) { - return rootEntitySource.bindingContext().makeMappingException( message ); - } - - protected MappingException makeMappingException(String message, Exception cause) { - return rootEntitySource.bindingContext().makeMappingException( message, cause ); - } - - @Override - public VersionAttributeSource getVersionAttributeSource() { - if ( entityElement().getVersion() != null ) { - return new VersionAttributeSourceImpl( - rootEntitySource.sourceMappingDocument(), - rootEntitySource, - entityElement().getVersion() - ); - } - else if ( entityElement().getTimestamp() != null ) { - return new TimestampAttributeSourceImpl( - rootEntitySource.sourceMappingDocument(), - rootEntitySource, - entityElement().getTimestamp() - ); - } - return null; - } - - @Override - public EntityMode getEntityMode() { - return rootEntitySource.determineEntityMode(); - } - - @Override - public boolean isMutable() { - return entityElement().isMutable(); - } - - @Override - public boolean isExplicitPolymorphism() { - return JaxbPolymorphismAttribute.EXPLICIT == entityElement().getPolymorphism(); - } - - @Override - public String getWhere() { - return entityElement().getWhere(); - } - - @Override - public String getRowId() { - return entityElement().getRowid(); - } - - @Override - public OptimisticLockStyle getOptimisticLockStyle() { - final String optimisticLockModeString = Helper.getValue( entityElement().getOptimisticLock().value(), "version" ); - try { - return OptimisticLockStyle.valueOf( optimisticLockModeString.toUpperCase() ); - } - catch ( Exception e ) { - throw new MappingException( - "Unknown optimistic-lock value : " + optimisticLockModeString, - rootEntitySource.sourceMappingDocument().getOrigin() - ); - } - } - - @Override - public Caching getCaching() { - return caching; - } - - @Override - public Caching getNaturalIdCaching() { - return naturalIdCaching; - } - - @Override - public DiscriminatorSource getDiscriminatorSource() { - final JaxbDiscriminatorElement discriminatorElement = entityElement().getDiscriminator(); - if ( discriminatorElement == null ) { - return null; - } - - return new DiscriminatorSource() { - @Override - public RelationalValueSource getDiscriminatorRelationalValueSource() { - SizeSource sizeSource = Helper.createSizeSourceIfMapped( discriminatorElement.getLength(), null, null ); - if ( StringHelper.isNotEmpty( discriminatorElement.getColumnAttribute() ) || sizeSource != null ) { - return new ColumnAttributeSourceImpl( - rootEntitySource.sourceMappingDocument(), - null, // root table - discriminatorElement.getColumnAttribute(), - sizeSource, - discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE, - discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE, - discriminatorElement.isNotNull() ? TruthValue.FALSE : TruthValue.TRUE - ); - } - else if ( StringHelper.isNotEmpty( discriminatorElement.getFormulaAttribute() ) ) { - return new FormulaImpl( - rootEntitySource.sourceMappingDocument(), - null, - discriminatorElement.getFormulaAttribute() - ); - } - else if ( discriminatorElement.getColumn() != null ) { - return new ColumnSourceImpl( - rootEntitySource.sourceMappingDocument(), - null, // root table - discriminatorElement.getColumn(), - discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE, - discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE - ); - } - else if ( StringHelper.isNotEmpty( discriminatorElement.getFormula() ) ) { - return new FormulaImpl( - rootEntitySource.sourceMappingDocument(), - null, - discriminatorElement.getFormula() - ); - } - else { - log.debug( "No source for discriminator column/formula found" ); - return new ColumnAttributeSourceImpl( - rootEntitySource.sourceMappingDocument(), - null, // root table - "class", // the default discriminator column name per-legacy hbm binding - sizeSource, - discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE, - discriminatorElement.isInsert() ? TruthValue.TRUE : TruthValue.FALSE, - discriminatorElement.isNotNull() ? TruthValue.FALSE : TruthValue.TRUE - ); -// throw makeMappingException( "could not determine source of discriminator mapping" ); - } - } - - @Override - public String getExplicitHibernateTypeName() { - return discriminatorElement.getType(); - } - - @Override - public boolean isForced() { - return discriminatorElement.isForce(); - } - - @Override - public boolean isInserted() { - return discriminatorElement.isInsert(); - } - }; - } - - @Override - public MultiTenancySource getMultiTenancySource() { - final JaxbMultiTenancyElement jaxbMultiTenancy = entityElement().getMultiTenancy(); - if ( jaxbMultiTenancy == null ) { - return null; - } - - return new MultiTenancySource() { - @Override - public RelationalValueSource getRelationalValueSource() { - - if ( StringHelper.isNotEmpty( jaxbMultiTenancy.getColumnAttribute() ) ) { - return new ColumnAttributeSourceImpl( - rootEntitySource.sourceMappingDocument(), - null, // root table - jaxbMultiTenancy.getColumnAttribute(), - null, - TruthValue.TRUE, - TruthValue.FALSE - ); - } - else if ( StringHelper.isNotEmpty( jaxbMultiTenancy.getFormulaAttribute() ) ) { - return new FormulaImpl( - rootEntitySource.sourceMappingDocument(), - null, - jaxbMultiTenancy.getFormulaAttribute() - ); - } - else if ( jaxbMultiTenancy.getColumn() != null ) { - return new ColumnSourceImpl( - rootEntitySource.sourceMappingDocument(), - null, // root table - jaxbMultiTenancy.getColumn(), - TruthValue.TRUE, - TruthValue.FALSE - ); - } - else if ( StringHelper.isNotEmpty( jaxbMultiTenancy.getFormula() ) ) { - return new FormulaImpl( - rootEntitySource.sourceMappingDocument(), - null, - jaxbMultiTenancy.getFormula() - ); - } - else { - return null; - } - } - - @Override - public boolean isShared() { - return jaxbMultiTenancy.isShared(); - } - - @Override - public boolean bindAsParameter() { - return jaxbMultiTenancy.isBindAsParam(); - } - }; - } - - private class SimpleIdentifierSourceImpl implements SimpleIdentifierSource { - @Override - public SingularAttributeSource getIdentifierAttributeSource() { - return new SingularIdentifierAttributeSourceImpl( sourceMappingDocument(), rootEntitySource, entityElement().getId() ); - } - - @Override - public IdentifierGeneratorDefinition getIdentifierGeneratorDescriptor() { - if ( entityElement().getId().getGenerator() != null ) { - final String generatorName = entityElement().getId().getGenerator().getClazz(); - IdentifierGeneratorDefinition identifierGeneratorDefinition = sourceMappingDocument().getMappingLocalBindingContext() - .getMetadataCollector() - .getIdGenerator( generatorName ); - if ( identifierGeneratorDefinition == null ) { - identifierGeneratorDefinition = new IdentifierGeneratorDefinition( - getEntityName() + generatorName, - generatorName, - Helper.extractParameters( entityElement().getId().getGenerator().getParam() ) - ); - } - return identifierGeneratorDefinition; - } - return null; - } - - @Override - public EntityIdentifierNature getNature() { - return EntityIdentifierNature.SIMPLE; - } - - @Override - public String getUnsavedValue() { - return entityElement().getId().getUnsavedValue(); - } - - @Override - public Collection getToolingHintSources() { - return entityElement().getId().getMeta(); - } - } - - private class AggregatedCompositeIdentifierSourceImpl implements AggregatedCompositeIdentifierSource { - private final CompositeIdentifierEmbeddedAttributeSourceImpl componentAttributeSource - = new CompositeIdentifierEmbeddedAttributeSourceImpl(); - - @Override - public EmbeddedAttributeSource getIdentifierAttributeSource() { - return componentAttributeSource; - } - - @Override - public List getMapsIdSources() { - return Collections.emptyList(); - } - - @Override - public IdentifierGeneratorDefinition getIndividualAttributeIdGenerator(String identifierAttributeName) { - // for now, return null. this is that stupid specj bs - return null; - } - - @Override - public IdentifierGeneratorDefinition getIdentifierGeneratorDescriptor() { - if ( entityElement().getCompositeId().getGenerator() != null ) { - final String generatorName = entityElement().getCompositeId().getGenerator().getClazz(); - IdentifierGeneratorDefinition identifierGeneratorDefinition = sourceMappingDocument().getMappingLocalBindingContext() - .getMetadataCollector() - .getIdGenerator( generatorName ); - if ( identifierGeneratorDefinition == null ) { - identifierGeneratorDefinition = new IdentifierGeneratorDefinition( - getEntityName() + generatorName, - generatorName, - Helper.extractParameters( entityElement().getCompositeId().getGenerator().getParam() ) - ); - } - return identifierGeneratorDefinition; - } - return null; - } - - @Override - public EntityIdentifierNature getNature() { - return EntityIdentifierNature.AGGREGATED_COMPOSITE; - } - - @Override - public String getUnsavedValue() { - return entityElement().getCompositeId().getUnsavedValue().value(); - } - - @Override - public Collection getToolingHintSources() { - return entityElement().getId().getMeta(); - } - } - - private class CompositeIdentifierEmbeddedAttributeSourceImpl extends AbstractEmbeddedAttributeSourceImpl { - private final List keyPropertyElementList; - private final List keyManyToOneElementList; - - protected CompositeIdentifierEmbeddedAttributeSourceImpl() { - super( - EntityHierarchySourceImpl.this.sourceMappingDocument(), - rootEntitySource, - rootEntitySource.getAttributeRoleBase().append( "id" ), - rootEntitySource.getAttributePathBase().append( "id" ), - entityElement().getCompositeId(), - new EmbeddableJaxbSourceImpl( entityElement().getCompositeId() ), - NaturalIdMutability.NOT_NATURAL_ID, - null - ); - - this.keyPropertyElementList = new ArrayList(); - this.keyManyToOneElementList = new ArrayList(); - - final JaxbCompositeIdElement compositeIdElement = entityElement().getCompositeId(); - for ( final Object obj : compositeIdElement.getKeyPropertyOrKeyManyToOne() ) { - if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) { - keyPropertyElementList.add( JaxbKeyPropertyElement.class.cast( obj ) ); - } - else if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) { - keyManyToOneElementList.add( JaxbKeyManyToOneElement.class.cast( obj ) ); - } - } - } - - @Override - public boolean isLazy() { - return false; - } - - @Override - public AttributePath getAttributePath() { - return getEmbeddableSource().getAttributePathBase(); - } - - @Override - public AttributeRole getAttributeRole() { - return getEmbeddableSource().getAttributeRoleBase(); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return false; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return false; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return false; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - } - - private class NonAggregatedCompositeIdentifierSourceImpl implements NonAggregatedCompositeIdentifierSource { - private final List attributeSources; - private final EmbeddableSource idClassSource; - - private NonAggregatedCompositeIdentifierSourceImpl() { - this.attributeSources = new ArrayList(); - collectCompositeIdAttributes( attributeSources, rootEntitySource ); - - // NOTE : the HBM support for IdClass is very limited. Essentially - // we assume that all identifier attributes occur in the IdClass - // using the same name and type. - this.idClassSource = interpretIdClass(); - } - - private EmbeddableSource interpretIdClass() { - final JaxbCompositeIdElement compositeId = entityElement().getCompositeId(); - // if is null here we have much bigger problems :) - - final String className = compositeId.getClazz(); - if ( StringHelper.isEmpty( className ) ) { - return null; - } - - return new IdClassSource( rootEntitySource.getLocalBindingContext().typeDescriptor( className ) ); - } - - @Override - public List getAttributeSourcesMakingUpIdentifier() { - return attributeSources; - } - - - @Override - public EmbeddableSource getIdClassSource() { - return idClassSource; - } - - @Override - public IdentifierGeneratorDefinition getIndividualAttributeIdGenerator(String identifierAttributeName) { - // for now, return null. this is that stupid specj bs - return null; - } - - @Override - public IdentifierGeneratorDefinition getIdentifierGeneratorDescriptor() { - if ( entityElement().getCompositeId().getGenerator() != null ) { - final String generatorName = entityElement().getCompositeId().getGenerator().getClazz(); - IdentifierGeneratorDefinition identifierGeneratorDefinition = sourceMappingDocument().getMappingLocalBindingContext() - .getMetadataCollector() - .getIdGenerator( generatorName ); - if ( identifierGeneratorDefinition == null ) { - identifierGeneratorDefinition = new IdentifierGeneratorDefinition( - getEntityName() + generatorName, - generatorName, - Helper.extractParameters( entityElement().getCompositeId().getGenerator().getParam() ) - ); - } - return identifierGeneratorDefinition; - } - return null; - } - - @Override - public EntityIdentifierNature getNature() { - return EntityIdentifierNature.NON_AGGREGATED_COMPOSITE; - } - - @Override - public String getUnsavedValue() { - return entityElement().getCompositeId().getUnsavedValue().value(); - } - - @Override - public Collection getToolingHintSources() { - return entityElement().getCompositeId().getMeta(); - } - } - - @SuppressWarnings("unchecked") - private void collectCompositeIdAttributes( - List attributeSources, - AttributeSourceContainer attributeSourceContainer) { - final JaxbCompositeIdElement compositeId = entityElement().getCompositeId(); - final List list = compositeId.getKeyPropertyOrKeyManyToOne(); - for ( final Object obj : list ) { - if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) { - JaxbKeyPropertyElement key = JaxbKeyPropertyElement.class.cast( obj ); - attributeSources.add( - new IdentifierKeyAttributeSourceImpl( - sourceMappingDocument(), - attributeSourceContainer, - key - ) - ); - } - if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) { - JaxbKeyManyToOneElement key = JaxbKeyManyToOneElement.class.cast( obj ); - attributeSources.add( - new IdentifierKeyManyToOneSourceImpl( - sourceMappingDocument(), - attributeSourceContainer, - key - ) - ); - } - } - } - - private class IdClassSource implements EmbeddableSource { - private final JavaTypeDescriptor idClassDescriptor; - private final List attributeSources; - - private IdClassSource(JavaTypeDescriptor idClassDescriptor) { - this.idClassDescriptor = idClassDescriptor; - this.attributeSources = new ArrayList(); - collectCompositeIdAttributes( attributeSources, this ); - } - @Override - public JavaTypeDescriptor getTypeDescriptor() { - return idClassDescriptor; - } - - @Override - public String getParentReferenceAttributeName() { - return null; - } - - @Override - public String getExplicitTuplizerClassName() { - return null; - } - - @Override - public AttributePath getAttributePathBase() { - return rootEntitySource.getAttributePathBase().append( "" ); - } - - @Override - public AttributeRole getAttributeRoleBase() { - return rootEntitySource.getAttributeRoleBase().append( "" ); - } - - @Override - public List attributeSources() { - return attributeSources; - } - - @Override - public LocalBindingContext getLocalBindingContext() { - return rootEntitySource.getLocalBindingContext(); - } - } - - public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource { - private final JaxbCompositeIdElement compositeIdElement; - - private final List keyPropertyElementList; - private final List keyManyToOneElementList; - - public EmbeddableJaxbSourceImpl(JaxbCompositeIdElement compositeIdElement) { - this.compositeIdElement = compositeIdElement; - - this.keyPropertyElementList = new ArrayList(); - this.keyManyToOneElementList = new ArrayList(); - - for ( final Object obj : compositeIdElement.getKeyPropertyOrKeyManyToOne() ) { - if ( JaxbKeyPropertyElement.class.isInstance( obj ) ) { - keyPropertyElementList.add( JaxbKeyPropertyElement.class.cast( obj ) ); - } - else if ( JaxbKeyManyToOneElement.class.isInstance( obj ) ) { - keyManyToOneElementList.add( JaxbKeyManyToOneElement.class.cast( obj ) ); - } - } - } - - @Override - public String getClazz() { - return compositeIdElement.getClazz(); - } - - @Override - public String findParent() { - return null; - } - - @Override - public String findTuplizer() { - return null; - } - - @Override - public List getKeyPropertyElementList() { - return keyPropertyElementList; - } - - @Override - public List getKeyManyToOneElementList() { - return keyManyToOneElementList; - } - - } - - private String getEntityName() { - return rootEntitySource.getEntityName(); - } - - private MappingDocument sourceMappingDocument() { - return rootEntitySource.sourceMappingDocument(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FetchProfileSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FetchProfileSourceImpl.java deleted file mode 100644 index a242943c1b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FetchProfileSourceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFetchProfileElement; -import org.hibernate.metamodel.source.spi.FetchProfileSource; - -/** - * @author Steve Ebersole - */ -public class FetchProfileSourceImpl - extends AbstractHbmSourceNode - implements FetchProfileSource { - - private final String name; - private final List associationOverrideSources; - - public FetchProfileSourceImpl( - MappingDocument mappingDocument, - JaxbFetchProfileElement fetchProfileElement) { - super( mappingDocument ); - this.name = fetchProfileElement.getName(); - this.associationOverrideSources = buildAssociationOverrideSources( fetchProfileElement ); - } - - @Override - public String getName() { - return name; - } - - @Override - public Iterable getAssociationOverrides() { - return associationOverrideSources; - } - - private static List buildAssociationOverrideSources(JaxbFetchProfileElement fetchProfileElement) { - final List associationOverrideSources = new ArrayList(); - for ( JaxbFetchProfileElement.JaxbFetch fetch : fetchProfileElement.getFetch() ) { - associationOverrideSources.add( new AssociationOverrideSourceImpl( fetch ) ); - } - return associationOverrideSources; - } - - private static class AssociationOverrideSourceImpl implements AssociationOverrideSource { - private final String entityName; - private final String attributeName; - private final String fetchMode; - - private AssociationOverrideSourceImpl(JaxbFetchProfileElement.JaxbFetch fetchElement) { - this.entityName = fetchElement.getEntity(); - this.attributeName = fetchElement.getAssociation(); - this.fetchMode = fetchElement.getStyle().value(); - } - - @Override - public String getEntityName() { - return entityName; - } - - @Override - public String getAttributeName() { - return attributeName; - } - - @Override - public String getFetchModeName() { - return fetchMode; - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterDefinitionSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterDefinitionSourceImpl.java deleted file mode 100644 index 6ebdb68f7e..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterDefinitionSourceImpl.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; -import javax.xml.bind.JAXBElement; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterDefElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterParamElement; -import org.hibernate.metamodel.source.spi.FilterDefinitionSource; -import org.hibernate.metamodel.source.spi.FilterParameterSource; - -/** - * @author Steve Ebersole - */ -public class FilterDefinitionSourceImpl - extends AbstractHbmSourceNode - implements FilterDefinitionSource { - private final String name; - private final String condition; - private List parameterSources; - - public FilterDefinitionSourceImpl( - MappingDocument mappingDocument, - JaxbFilterDefElement filterDefElement) { - super( mappingDocument ); - this.name = filterDefElement.getName(); - - String conditionAttribute = filterDefElement.getCondition(); - String conditionContent = null; - - final List parameterSources = new ArrayList(); - for ( Object content : filterDefElement.getContent() ) { - if ( String.class.isInstance( content ) ){ - final String str = content.toString(); - if ( !StringHelper.isEmptyOrWhiteSpace( str ) ) { - conditionContent = str.trim(); - } - } - else if ( JAXBElement.class.isInstance( content ) ) { - JAXBElement jaxbElement = JAXBElement.class.cast( content ); - if ( jaxbElement.getDeclaredType() == JaxbFilterParamElement.class ) { - parameterSources.add( - (JaxbFilterParamElement) jaxbElement.getValue() - ); - } - } - else { - parameterSources.add( - ( JaxbFilterParamElement)content - ); - } - } - - this.condition = Helper.coalesce( conditionContent, conditionAttribute ); - this.parameterSources = parameterSources; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getCondition() { - return condition; - } - - @Override - public Iterable getParameterSources() { - return parameterSources; - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterSourceImpl.java deleted file mode 100644 index 8f843bc6cf..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FilterSourceImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterAliasMappingType; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement; -import org.hibernate.metamodel.source.spi.FilterSource; - -/** - * @author Steve Ebersole - */ -public class FilterSourceImpl - extends AbstractHbmSourceNode - implements FilterSource { - private final String name; - private final String condition; - private final boolean autoAliasInjection; - private final Map aliasTableMap = new HashMap(); - private final Map aliasEntityMap = new HashMap(); - - public FilterSourceImpl( - MappingDocument mappingDocument, - JaxbFilterElement filterElement) { - super( mappingDocument ); - this.name = filterElement.getName(); - - String explicitAutoAliasInjectionSetting = filterElement.getAutoAliasInjection(); - - String conditionAttribute = filterElement.getCondition(); - String conditionContent = null; - - for ( Serializable content : filterElement.getContent() ) { - if ( String.class.isInstance( content ) ) { - final String str = content.toString(); - if ( !StringHelper.isEmptyOrWhiteSpace( str ) ) { - conditionContent = str.trim(); - } - } - else { - final JaxbFilterAliasMappingType aliasMapping = JaxbFilterAliasMappingType.class.cast( content ); - if ( StringHelper.isNotEmpty( aliasMapping.getTable() ) ) { - aliasTableMap.put( aliasMapping.getAlias(), aliasMapping.getTable() ); - } - else if ( StringHelper.isNotEmpty( aliasMapping.getEntity() ) ) { - aliasEntityMap.put( aliasMapping.getAlias(), aliasMapping.getTable() ); - } - else { - throw mappingDocument.getMappingLocalBindingContext() - .makeMappingException( "filter alias must define either table or entity attribute" ); - } - } - } - - this.condition = Helper.coalesce( conditionContent, conditionAttribute ); - this.autoAliasInjection = StringHelper.isNotEmpty( explicitAutoAliasInjectionSetting ) - ? Boolean.valueOf( explicitAutoAliasInjectionSetting ) - : true; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getCondition() { - return condition; - } - - @Override - public boolean shouldAutoInjectAliases() { - return autoAliasInjection; - } - - @Override - public Map getAliasToTableMap() { - return aliasTableMap; - } - - @Override - public Map getAliasToEntityMap() { - return aliasEntityMap; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FormulaImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FormulaImpl.java deleted file mode 100644 index 403d9542ed..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/FormulaImpl.java +++ /dev/null @@ -1,57 +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.source.internal.hbm; - -import org.hibernate.metamodel.source.spi.DerivedValueSource; - -/** -* @author Steve Ebersole -*/ -class FormulaImpl - extends AbstractHbmSourceNode - implements DerivedValueSource { - private String tableName; - private final String expression; - - FormulaImpl(MappingDocument mappingDocument, String tableName, String expression) { - super( mappingDocument ); - this.tableName = tableName; - this.expression = expression; - } - - @Override - public Nature getNature() { - return Nature.DERIVED; - } - - @Override - public String getExpression() { - return expression; - } - - @Override - public String getContainingTableName() { - return tableName; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmBindingContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmBindingContext.java deleted file mode 100644 index 08ebaad097..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmBindingContext.java +++ /dev/null @@ -1,47 +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.source.internal.hbm; - -import java.util.List; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFetchProfileElement; -import org.hibernate.metamodel.source.spi.MetaAttributeContext; -import org.hibernate.metamodel.spi.LocalBindingContext; - -/** - * Defines features specific to the {@code hbm.xml} variety of a {@link org.hibernate.metamodel.spi.BindingContext} - * - * @author Steve Ebersole - */ -public interface HbmBindingContext extends LocalBindingContext { - public boolean isAutoImport(); - - public MetaAttributeContext getMetaAttributeContext(); - - public String determineEntityName(EntityElement entityElement); - - public void processFetchProfiles(List fetchProfiles, String containingEntityName); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmMetadataSourceProcessorImpl.java deleted file mode 100644 index 38a70e42b0..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HbmMetadataSourceProcessorImpl.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.MetadataSources; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbHibernateMapping; -import org.hibernate.metamodel.source.spi.EntityHierarchySource; -import org.hibernate.metamodel.source.spi.FilterDefinitionSource; -import org.hibernate.metamodel.source.spi.IdentifierGeneratorSource; -import org.hibernate.metamodel.source.spi.TypeDescriptorSource; -import org.hibernate.metamodel.spi.BindingContext; -import org.hibernate.metamodel.spi.MetadataSourceProcessor; -import org.hibernate.xml.spi.BindResult; - -import static java.util.Collections.emptyList; - -/** - * The {@link org.hibernate.metamodel.spi.MetadataSourceProcessor} implementation responsible for processing {@code hbm.xml} sources. - * - * @author Steve Ebersole - */ -public class HbmMetadataSourceProcessorImpl implements MetadataSourceProcessor { - private final List processors = new ArrayList(); - private final List entityHierarchies; - - public HbmMetadataSourceProcessorImpl(BindingContext bindingContext, MetadataSources metadataSources) { - this( bindingContext, metadataSources.getBindResultList() ); - } - - @SuppressWarnings("unchecked") - public HbmMetadataSourceProcessorImpl(BindingContext bindingContext, List bindResults) { - final HierarchyBuilder hierarchyBuilder = new HierarchyBuilder( bindingContext ); - - for ( BindResult bindResult : bindResults ) { - if ( ! JaxbHibernateMapping.class.isInstance( bindResult.getRoot() ) ) { - continue; - } - - final MappingDocument mappingDocument = new MappingDocument( bindResult, bindingContext ); - processors.add( new HibernateMappingProcessor( mappingDocument ) ); - - hierarchyBuilder.processMappingDocument( mappingDocument ); - } - - this.entityHierarchies = hierarchyBuilder.groupEntityHierarchies(); - } - - // todo : still need to deal with auxiliary database objects - - @Override - public Iterable extractTypeDefinitionSources() { - if( CollectionHelper.isEmpty( processors )){ - return emptyList(); - } - final List typeDescriptorSources = new ArrayList(); - for ( HibernateMappingProcessor processor : processors ) { - processor.collectTypeDescriptorSources( typeDescriptorSources ); - } - return typeDescriptorSources; - } - - @Override - public Iterable extractFilterDefinitionSources() { - if( CollectionHelper.isEmpty( processors )){ - return emptyList(); - } - final List filterDefinitionSources = new ArrayList(); - for ( HibernateMappingProcessor processor : processors ) { - processor.collectFilterDefSources( filterDefinitionSources ); - } - return filterDefinitionSources; - } - - @Override - public Iterable extractGlobalIdentifierGeneratorSources() { - return emptyList(); - } - - @Override - @SuppressWarnings( {"unchecked", "RedundantCast"}) - public Collection extractEntityHierarchies() { - return entityHierarchies; - } - - @Override - public void processMappingDependentMetadata() { - for ( HibernateMappingProcessor processor : processors ) { - processor.processMappingDependentMetadata(); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java deleted file mode 100644 index 336bf702b4..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/Helper.java +++ /dev/null @@ -1,479 +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.source.internal.hbm; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.hibernate.LockMode; -import org.hibernate.TruthValue; -import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.engine.spi.CascadeStyles; -import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCacheElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbJoinedSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbLockModeAttribute; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNaturalIdCacheElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbParamElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSqlDmlElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbUnionSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.TableInformationSource; -import org.hibernate.metamodel.source.spi.HibernateTypeSource; -import org.hibernate.metamodel.source.spi.MetaAttributeContext; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.source.spi.TableSpecificationSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.Caching; -import org.hibernate.metamodel.spi.binding.CustomSQL; -import org.hibernate.metamodel.spi.binding.InheritanceType; -import org.hibernate.metamodel.spi.binding.MetaAttribute; - -/** - * @author Steve Ebersole - * @author Gail Badner - */ -public class Helper { - public static LockMode interpretLockMode(JaxbLockModeAttribute lockModeAttribute, LocalBindingContext context){ - if ( lockModeAttribute == null ) { - return LockMode.READ; - } - switch ( lockModeAttribute ) { - case NONE: - return LockMode.NONE; - case UPGRADE: - return LockMode.UPGRADE; - case UPGRADE_NOWAIT: - return LockMode.UPGRADE_NOWAIT; - case READ: - return LockMode.READ; - case WRITE: - return LockMode.WRITE; - case FORCE: - return LockMode.FORCE; - case OPTIMISTIC: - return LockMode.OPTIMISTIC; - case OPTIMISTIC_FORCE_INCREMENT: - return LockMode.OPTIMISTIC_FORCE_INCREMENT; - case PESSIMISTIC_READ: - return LockMode.PESSIMISTIC_READ; - case PESSIMISTIC_WRITE: - return LockMode.PESSIMISTIC_WRITE; - case PESSIMISTIC_FORCE_INCREMENT: - return LockMode.PESSIMISTIC_FORCE_INCREMENT; - default: - throw context.makeMappingException( "unknown lock mode: "+lockModeAttribute ); - } - } - - public static InheritanceType interpretInheritanceType(EntityElement entityElement) { - if ( JaxbSubclassElement.class.isInstance( entityElement ) ) { - return InheritanceType.SINGLE_TABLE; - } - else if ( JaxbJoinedSubclassElement.class.isInstance( entityElement ) ) { - return InheritanceType.JOINED; - } - else if ( JaxbUnionSubclassElement.class.isInstance( entityElement ) ) { - return InheritanceType.TABLE_PER_CLASS; - } - else { - return InheritanceType.NO_INHERITANCE; - } - } - - /** - * 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(JaxbSqlDmlElement 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 ); - } - - public static Caching createCaching(JaxbCacheElement cacheElement) { - if ( cacheElement == null ) { - // I'd really rather this be UNKNOWN, but the annotation version resolves this to TRUE/FALSE - return new Caching( TruthValue.FALSE ); - } - - final AccessType accessType = AccessType.fromExternalName( cacheElement.getUsage().value() ); - final boolean cacheLazyProps = cacheElement.getInclude() == null - || !"non-lazy".equals( cacheElement.getInclude().value() ); - - return new Caching( - cacheElement.getRegion(), - accessType, - cacheLazyProps, - TruthValue.TRUE - ); - } - - public static Caching createNaturalIdCaching(JaxbNaturalIdCacheElement cacheElement) { - if ( cacheElement == null ) { - return new Caching( TruthValue.UNKNOWN ); - } - - return new Caching( - StringHelper.nullIfEmpty( cacheElement.getRegion() ), - null, - false, - TruthValue.TRUE - ); - } - - /** - * 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 getValue( access, isEmbedded ? "embedded" : defaultAccess ); - } - - public static MetaAttributeContext extractMetaAttributeContext( - List metaAttributeSourceList, - boolean onlyInheritable, - MetaAttributeContext parentContext) { - final MetaAttributeContext subContext = new MetaAttributeContext( parentContext ); - - for ( ToolingHintSource meta : metaAttributeSourceList ) { - if ( onlyInheritable & !meta.isInheritable() ) { - continue; - } - - final String name = meta.getName(); - 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( meta.getValue() ); - } - - return subContext; - } - - public static T getValue(T value, T defaultValue){ - return value == null ? defaultValue : value; - } - - public static Set interpretCascadeStyles(String cascades, LocalBindingContext bindingContext) { - final Set cascadeStyles = new HashSet(); - if ( StringHelper.isEmpty( cascades ) ) { - cascades = bindingContext.getMappingDefaults().getCascadeStyle(); - } - for ( String cascade : StringHelper.split( " ,", cascades ) ) { - cascadeStyles.add( CascadeStyles.getCascadeStyle( cascade ) ); - } - return cascadeStyles; - } - - public static Map extractParameters(List xmlParamElements) { - if ( xmlParamElements == null || xmlParamElements.isEmpty() ) { - return Collections.emptyMap(); - } - final HashMap params = new HashMap(); - for ( JaxbParamElement paramElement : xmlParamElements ) { - params.put( paramElement.getName(), paramElement.getValue() ); - } - return params; - } - - public static SizeSource createSizeSourceIfMapped(Integer length, Integer precision, Integer scale) { - if ( length != null || precision != null || scale != null ) { - return new SizeSourceImpl( precision, scale, length ); - } - return null; - } - - /** - * Operates like SQL coalesce expression, except empty strings are treated as null. Return the first non-empty value - * - * @param values The list of values. - * @param Generic type of values to coalesce - * - * @return The first non-empty value, or null if all values were empty - */ - public static T coalesce(T... values) { - if ( values == null ) { - return null; - } - for ( T value : values ) { - if ( value != null ) { - if ( String.class.isInstance( value ) ) { - if ( StringHelper.isNotEmpty( (String) value ) ) { - return value; - } - } - else { - return value; - } - } - } - return null; - } - - public static interface InLineViewNameInferrer { - public String inferInLineViewName(); - } - - public static TableSpecificationSource createTableSource( - MappingDocument mappingDocument, - TableInformationSource jaxbTableSource, - InLineViewNameInferrer inLineViewNameInferrer) { - if ( jaxbTableSource.getSubselectAttribute() == null && jaxbTableSource.getSubselect() == null ) { - return new TableSourceImpl( - mappingDocument, - jaxbTableSource.getSchema(), - jaxbTableSource.getCatalog(), - jaxbTableSource.getTable() - ); - } - else { - return new InLineViewSourceImpl( - mappingDocument, - jaxbTableSource.getSchema(), - jaxbTableSource.getCatalog(), - jaxbTableSource.getSubselectAttribute() != null - ? jaxbTableSource.getSubselectAttribute() - : jaxbTableSource.getSubselect(), - jaxbTableSource.getTable() == null - ? inLineViewNameInferrer.inferInLineViewName() - : jaxbTableSource.getTable() - ); - } - - } - - /** - * For things that define one or more "value sources" there is a lot of variance in terms of how they - * look in the XML. As an example, consider {@code } which might have:
    - *
  • a {@code column} XML attribute
  • - *
  • a {@code formula} XML attribute
  • - *
  • one or more nested {@code } XML elements
  • - *
  • a {@code } XML element
  • - *
- * as opposed to {@code } which can only have:
    - *
  • a {@code column} XML attribute
  • - *
- *

- * This class adapts those variances to a unified contract which is intended to be used in conjunction with - * {@link #buildValueSources}. - */ - public static class ValueSourcesAdapter { - public String getContainingTableName() { - return null; - } - - public boolean isIncludedInInsertByDefault() { - return false; - } - - public boolean isIncludedInUpdateByDefault() { - return false; - } - - public String getColumnAttribute() { - return null; - } - - public String getFormulaAttribute() { - return null; - } - - public SizeSource getSizeSource() { - return null; - } - - public List getColumn(){ - return Collections.emptyList(); - } - - public List getFormula(){ - return Collections.emptyList(); - } - - public boolean isForceNotNull() { - return false; - } - } - - private static void checkColumnOrFormulaElements(MappingDocument mappingDocument, ValueSourcesAdapter valueSourcesAdapter) { - if ( CollectionHelper.isNotEmpty( valueSourcesAdapter.getColumn() ) || CollectionHelper.isNotEmpty( - valueSourcesAdapter.getFormula() - ) ) { - throw mappingDocument.getMappingLocalBindingContext().makeMappingException( - "column/formula/size attribute may not be used together with / subelement" - ); - } - } - - /** - * Given a {@link ValueSourcesAdapter}, build the corresponding list of {@link RelationalValueSource} - * - * @param mappingDocument the mapping document - * @param valueSourcesAdapter the adapter describing the value sources. - * - * @return The corresponding list. - */ - public static List buildValueSources( - MappingDocument mappingDocument, - ValueSourcesAdapter valueSourcesAdapter) { - List result = new ArrayList(); - - if ( StringHelper.isNotEmpty( valueSourcesAdapter.getColumnAttribute() ) ) { - // we have the XML defining a column attribute. - // it is therefore illegal for there to also be any nested formula or column elements - checkColumnOrFormulaElements(mappingDocument, valueSourcesAdapter); - // it is also illegal for there to also be a formula attribute - if ( StringHelper.isNotEmpty( valueSourcesAdapter.getFormulaAttribute() ) ) { - throw mappingDocument.getMappingLocalBindingContext().makeMappingException( - "column and formula attributes may not be used together" - ); - } - - result.add( - new ColumnAttributeSourceImpl( - mappingDocument, - valueSourcesAdapter.getContainingTableName(), - valueSourcesAdapter.getColumnAttribute(), - valueSourcesAdapter.getSizeSource(), - valueSourcesAdapter.isIncludedInInsertByDefault() ? TruthValue.TRUE : TruthValue.FALSE, - valueSourcesAdapter.isIncludedInUpdateByDefault() ? TruthValue.TRUE : TruthValue.FALSE, - valueSourcesAdapter.isForceNotNull() ? TruthValue.FALSE : TruthValue.UNKNOWN - ) - ); - } - else if ( StringHelper.isNotEmpty( valueSourcesAdapter.getFormulaAttribute() ) ) { - // we have the XML defining a formula attribute (and not a column attribute) - // it is therefore illegal for there to also be any nested formula or column elements - checkColumnOrFormulaElements( mappingDocument, valueSourcesAdapter ); - // column/formula attribute combo checked already - - result.add( - new FormulaImpl( - mappingDocument, - valueSourcesAdapter.getContainingTableName(), - valueSourcesAdapter.getFormulaAttribute() - ) - ); - } - else if ( valueSourcesAdapter.getSizeSource() != null ) { - // we have XML defining a length, precision, and/or scale attribute with neither - // a column nor formula attribute; assume this is a column. - // it is therefore illegal for there to also be any nested formula or column elements - checkColumnOrFormulaElements(mappingDocument, valueSourcesAdapter); - result.add( - new ColumnAttributeSourceImpl( - mappingDocument, - valueSourcesAdapter.getContainingTableName(), - valueSourcesAdapter.getColumnAttribute(), - valueSourcesAdapter.getSizeSource(), - valueSourcesAdapter.isIncludedInInsertByDefault() ? TruthValue.TRUE : TruthValue.FALSE, - valueSourcesAdapter.isIncludedInUpdateByDefault() ? TruthValue.TRUE : TruthValue.FALSE, - valueSourcesAdapter.isForceNotNull() ? TruthValue.FALSE : TruthValue.UNKNOWN - ) - ); - - } - // we have the XML defining nested formula or column elements (and not column attribute nor formula attribute) - if ( CollectionHelper.isNotEmpty( valueSourcesAdapter.getColumn() ) ) { - for ( JaxbColumnElement column : valueSourcesAdapter.getColumn() ) { - result.add( - new ColumnSourceImpl( - mappingDocument, - valueSourcesAdapter.getContainingTableName(), - column, - valueSourcesAdapter.isIncludedInInsertByDefault() ? TruthValue.TRUE : TruthValue.FALSE, - valueSourcesAdapter.isIncludedInUpdateByDefault() ? TruthValue.TRUE : TruthValue.FALSE, - valueSourcesAdapter.isForceNotNull() ? TruthValue.FALSE : TruthValue.TRUE - ) - ); - } - } - if ( CollectionHelper.isNotEmpty( valueSourcesAdapter.getFormula() ) ) { - for ( String formula : valueSourcesAdapter.getFormula() ) { - result.add( - new FormulaImpl( - mappingDocument, - valueSourcesAdapter.getContainingTableName(), - formula - ) - ); - } - } - return result; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HibernateMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HibernateMappingProcessor.java deleted file mode 100644 index 862101f84d..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HibernateMappingProcessor.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDatabaseObjectElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbDialectScopeElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFetchProfileElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterDefElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbHibernateMapping; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIdentifierGeneratorElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbImportElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbJoinedSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbQueryElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbResultsetElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSqlQueryElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTypedefElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbUnionSubclassElement; -import org.hibernate.metamodel.source.spi.FilterDefinitionSource; -import org.hibernate.metamodel.source.spi.TypeDescriptorSource; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.binding.FetchProfile; -import org.hibernate.metamodel.spi.relational.AuxiliaryDatabaseObject; -import org.hibernate.metamodel.spi.relational.BasicAuxiliaryDatabaseObjectImpl; - -/** - * Responsible for processing a {@code } element. Allows processing to be coordinated across - * all hbm files in an ordered fashion. The order is essentially the same as defined in - * {@link org.hibernate.metamodel.spi.MetadataSourceProcessor} - * - * @author Steve Ebersole - * @author Strong Liu - */ -public class HibernateMappingProcessor { - private final MappingDocument mappingDocument; - - private final ClassLoaderService classLoaderService; - - public HibernateMappingProcessor(MappingDocument mappingDocument) { - this.mappingDocument = mappingDocument; - this.classLoaderService = bindingContext().getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class ); - processDatabaseObjectDefinitions(); - processIdentifierGenerators(); - } - - private InFlightMetadataCollector metadataCollector() { - return bindingContext().getMetadataCollector(); - } - - private JaxbHibernateMapping mappingRoot() { - return mappingDocument.getMappingRoot(); - } - - private HbmBindingContext bindingContext() { - return mappingDocument.getMappingLocalBindingContext(); - } - - private Class classForName(String name) { - return classLoaderService.classForName( bindingContext().qualifyClassName( name ) ); - } - - private void processDatabaseObjectDefinitions() { - if ( mappingRoot().getDatabaseObject() == null ) { - return; - } - - for ( JaxbDatabaseObjectElement databaseObjectElement : mappingRoot().getDatabaseObject() ) { - final AuxiliaryDatabaseObject auxiliaryDatabaseObject; - if ( databaseObjectElement.getDefinition() != null ) { - final String className = databaseObjectElement.getDefinition().getClazz(); - try { - auxiliaryDatabaseObject = (AuxiliaryDatabaseObject) classForName( className ).newInstance(); - } - catch ( ClassLoadingException e ) { - throw e; - } - catch ( Exception e ) { - throw bindingContext().makeMappingException( "could not instantiate custom database object class [" + className + "]" ); - } - } - else { - Set dialectScopes = new HashSet(); - if ( databaseObjectElement.getDialectScope() != null ) { - for ( JaxbDialectScopeElement dialectScope : databaseObjectElement.getDialectScope() ) { - dialectScopes.add( dialectScope.getName() ); - } - } - auxiliaryDatabaseObject = new BasicAuxiliaryDatabaseObjectImpl( - metadataCollector().getDatabase().getDefaultSchema(), - databaseObjectElement.getCreate(), - databaseObjectElement.getDrop(), - dialectScopes - ); - } - metadataCollector().getDatabase().addAuxiliaryDatabaseObject( auxiliaryDatabaseObject ); - } - } - - public void collectTypeDescriptorSources(List typeDescriptorSources) { - if ( mappingRoot().getTypedef() == null ) { - return; - } - - for ( JaxbTypedefElement typeDefElement : mappingRoot().getTypedef() ) { - typeDescriptorSources.add( new TypeDescriptorSourceImpl( typeDefElement ) ); - } - } - - public void collectFilterDefSources(List filterDefinitionSources) { - if ( mappingRoot().getFilterDef() == null ) { - return; - } - - for ( JaxbFilterDefElement filterDefElement : mappingRoot().getFilterDef() ) { - filterDefinitionSources.add( new FilterDefinitionSourceImpl( mappingDocument, filterDefElement ) ); - } - } - - - private void processIdentifierGenerators() { - if ( mappingRoot().getIdentifierGenerator() == null ) { - return; - } - - for ( JaxbIdentifierGeneratorElement identifierGeneratorElement : mappingRoot().getIdentifierGenerator() ) { - metadataCollector().registerIdentifierGenerator( - identifierGeneratorElement.getName(), - identifierGeneratorElement.getClazz() - ); - } - } - - public void processMappingDependentMetadata() { - processFetchProfiles(); - processImports(); - processResultSetMappings(); - processNamedQueries(); - } - - private void processFetchProfiles() { - processFetchProfiles( mappingRoot().getFetchProfile(), null ); - for ( JaxbClassElement classElement : mappingRoot().getClazz() ) { - processFetchProfile( classElement ); - - // processing fetch profiles defined in the - processFetchProfilesInJoinedSubclass( classElement.getJoinedSubclass() ); - // - processFetchProfilesInUnionSubclass( classElement.getUnionSubclass() ); - // - processFetchProfilesInSubclass( classElement.getSubclass() ); - } - } - - private void processFetchProfilesInSubclass(List subclass) { - for ( JaxbSubclassElement subclassElement : subclass ) { - processFetchProfile( subclassElement ); - processFetchProfilesInSubclass( subclassElement.getSubclass() ); - } - } - - private void processFetchProfile(final EntityElement entityElement){ - processFetchProfiles( - entityElement.getFetchProfile(), - bindingContext().qualifyClassName( entityElement.getName() ) - ); - } - - private void processFetchProfilesInUnionSubclass(List unionSubclass) { - for ( JaxbUnionSubclassElement subclassElement : unionSubclass ) { - processFetchProfile( subclassElement ); - processFetchProfilesInUnionSubclass( subclassElement.getUnionSubclass() ); - } - } - - private void processFetchProfilesInJoinedSubclass(List joinedSubclassElements) { - for ( JaxbJoinedSubclassElement subclassElement : joinedSubclassElements ) { - processFetchProfile( subclassElement ); - processFetchProfilesInJoinedSubclass( subclassElement.getJoinedSubclass() ); - } - } - - public void processFetchProfiles(List fetchProfiles, String containingEntityName) { - for ( JaxbFetchProfileElement fetchProfile : fetchProfiles ) { - String profileName = fetchProfile.getName(); - Set fetches = new HashSet(); - for ( JaxbFetchProfileElement.JaxbFetch fetch : fetchProfile.getFetch() ) { - String entityName = fetch.getEntity() == null ? containingEntityName : fetch.getEntity(); - if ( entityName == null ) { - throw bindingContext().makeMappingException( "could not determine entity for fetch-profile fetch [" + profileName + "]:[" + - fetch.getAssociation() + "]" ); - } - fetches.add( new FetchProfile.Fetch( entityName, fetch.getAssociation(), fetch.getStyle().value() ) ); - } - metadataCollector().addFetchProfile( new FetchProfile( profileName, fetches ) ); - } - } - - private void processImports() { - JaxbHibernateMapping root = mappingRoot(); - for ( JaxbImportElement importValue : root.getImport() ) { - String className = bindingContext().qualifyClassName( importValue.getClazz() ); - String rename = importValue.getRename(); - rename = ( rename == null ) ? StringHelper.unqualify( className ) : rename; - metadataCollector().addImport( rename, className ); - } - if ( root.isAutoImport() ) { - processEntityElementsImport( root.getClazz() ); - processEntityElementsImport( root.getJoinedSubclass() ); - processEntityElementsImport( root.getUnionSubclass() ); - processEntityElementsImport( root.getSubclass() ); - } - } - - private void processEntityElementsImport(List entityElements) { - for ( final EntityElement element : entityElements ) { - processEntityElementImport( element ); - } - } - - private void processEntityElementImport(EntityElement entityElement) { - final String qualifiedName = bindingContext().determineEntityName( entityElement ); - final String importName = entityElement.getEntityName() == null - ? entityElement.getName() - : entityElement.getEntityName(); - metadataCollector().addImport( importName, qualifiedName ); - metadataCollector().addImport( StringHelper.unqualify( importName ), qualifiedName ); - - if ( JaxbClassElement.class.isInstance( entityElement ) ) { - processEntityElementsImport( ( (JaxbClassElement) entityElement ).getSubclass() ); - processEntityElementsImport( ( (JaxbClassElement) entityElement ).getJoinedSubclass() ); - processEntityElementsImport( ( (JaxbClassElement) entityElement ).getUnionSubclass() ); - } - else if ( JaxbSubclassElement.class.isInstance( entityElement ) ) { - processEntityElementsImport( ( (JaxbSubclassElement) entityElement ).getSubclass() ); - } - else if ( JaxbJoinedSubclassElement.class.isInstance( entityElement ) ) { - processEntityElementsImport( ( (JaxbJoinedSubclassElement) entityElement ).getJoinedSubclass() ); - } - else if ( JaxbUnionSubclassElement.class.isInstance( entityElement ) ) { - processEntityElementsImport( ( (JaxbUnionSubclassElement) entityElement ).getUnionSubclass() ); - } - } - - private void processResultSetMappings() { - List resultsetElements = new ArrayList(); - - addAllIfNotEmpty( resultsetElements, mappingRoot().getResultset() ); - findResultSets( resultsetElements, mappingRoot().getClazz() ); - findResultSets( resultsetElements, mappingRoot().getJoinedSubclass() ); - findResultSets( resultsetElements, mappingRoot().getUnionSubclass() ); - findResultSets( resultsetElements, mappingRoot().getSubclass() ); - if ( resultsetElements.isEmpty() ) { - return; - } - for ( final JaxbResultsetElement element : resultsetElements ) { - metadataCollector().addResultSetMapping( - ResultSetMappingBinder.buildResultSetMappingDefinitions( - element, bindingContext(), metadataCollector() - ) - ); - } - - } - - private static void findResultSets(List resultsetElements, List entityElements) { - for ( final EntityElement element : entityElements ) { - addAllIfNotEmpty( resultsetElements, element.getResultset() ); - } - } - - private static void addAllIfNotEmpty(List target, List values) { - if ( CollectionHelper.isNotEmpty( values ) ) { - target.addAll( values ); - } - } - - private void processNamedQueries() { - for ( final JaxbQueryElement element : mappingRoot().getQuery() ) { - NamedQueryBindingHelper.bindNamedQuery( element, metadataCollector() ); - } - for ( final JaxbSqlQueryElement element : mappingRoot().getSqlQuery() ) { - NamedQueryBindingHelper.bindNamedSQLQuery( - element, - bindingContext(), - metadataCollector() - ); - } - } - -} \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HierarchyBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HierarchyBuilder.java deleted file mode 100644 index d4ee4dc216..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/HierarchyBuilder.java +++ /dev/null @@ -1,226 +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.source.internal.hbm; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbHibernateMapping; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbJoinedSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbQueryElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSqlQueryElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbUnionSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.SubEntityElement; -import org.hibernate.metamodel.source.spi.EntityHierarchySource; -import org.hibernate.metamodel.source.spi.EntitySource; -import org.hibernate.metamodel.source.spi.SubclassEntitySource; -import org.hibernate.metamodel.spi.BindingContext; - -/** - * @author Steve Ebersole - */ -public class HierarchyBuilder { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( HierarchyBuilder.class ); - - private final BindingContext bindingContext; - - private final List entityHierarchies = new ArrayList(); - - // process state - private final Map subEntityContainerMap = new HashMap(); - private final List extendsQueue = new ArrayList(); - - // mapping file specific state - private MappingDocument currentMappingDocument; - - public HierarchyBuilder(BindingContext bindingContext) { - this.bindingContext = bindingContext; - } - - public void processMappingDocument(MappingDocument mappingDocument) { - this.currentMappingDocument = mappingDocument; - try { - LOG.tracef( "Processing mapping document: %s ", mappingDocument.getOrigin() ); - processCurrentMappingDocument(); - } - finally { - this.currentMappingDocument = null; - } - } - - private void processCurrentMappingDocument() { - final JaxbHibernateMapping root = currentMappingDocument.getMappingRoot(); - for ( final JaxbClassElement jaxbClass : root.getClazz() ) { - // we can immediately handle elements in terms of creating the hierarchy entry - final RootEntitySourceImpl rootEntitySource = new RootEntitySourceImpl( - currentMappingDocument, - jaxbClass - ); - final EntityHierarchySourceImpl hierarchy = new EntityHierarchySourceImpl( rootEntitySource ); - entityHierarchies.add( hierarchy ); - subEntityContainerMap.put( rootEntitySource.getEntityName(), rootEntitySource ); - processSubElements( jaxbClass, rootEntitySource ); - } - List subEntityElements = new ArrayList( root.getJoinedSubclass() ); - subEntityElements.addAll( root.getUnionSubclass() ); - subEntityElements.addAll( root.getSubclass() ); - - for ( final SubEntityElement element : subEntityElements ) { - processSubclassElement( element ); - } - - } - - private void processSubclassElement(SubEntityElement element) { - // we have to see if this things super-type has been found yet, and if not add it to the - // extends queue - final String entityItExtends = currentMappingDocument.getMappingLocalBindingContext() - .qualifyClassName( element.getExtends() ); - final AbstractEntitySourceImpl container = subEntityContainerMap.get( entityItExtends ); - final SubclassEntitySourceImpl subClassEntitySource = createSubClassEntitySource( element, (EntitySource) container ); - final String entityName = subClassEntitySource.getEntityName(); - subEntityContainerMap.put( entityName, subClassEntitySource ); - processSubElements( element, subClassEntitySource ); - if ( container != null ) { - // we already have this entity's super, attach it and continue - container.add( subClassEntitySource ); - } - else { - // we do not yet have the super and have to wait, so add it fto the extends queue - extendsQueue.add( new ExtendsQueueEntry( subClassEntitySource, entityItExtends ) ); - } - } - - public List groupEntityHierarchies() { - while ( ! extendsQueue.isEmpty() ) { - // set up a pass over the queue - int numberOfMappingsProcessed = 0; - Iterator iterator = extendsQueue.iterator(); - while ( iterator.hasNext() ) { - final ExtendsQueueEntry entry = iterator.next(); - final AbstractEntitySourceImpl container = subEntityContainerMap.get( entry.entityItExtends ); - if ( container != null ) { - // we now have this entity's super, attach it and remove entry from extends queue - container.add( entry.subClassEntitySource ); - iterator.remove(); - numberOfMappingsProcessed++; - } - } - - if ( numberOfMappingsProcessed == 0 ) { - - // todo : we could log the waiting dependencies... - throw currentMappingDocument.getMappingLocalBindingContext().makeMappingException( "Unable to process extends dependencies in hbm files" ); - } - } - - return entityHierarchies; - } - - private void processSubElements(EntityElement entityElement, AbstractEntitySourceImpl container) { - if ( JaxbClassElement.class.isInstance( entityElement ) ) { - final JaxbClassElement jaxbClass = (JaxbClassElement) entityElement; - processElements( jaxbClass.getJoinedSubclass(), container ); - processElements( jaxbClass.getSubclass(), container ); - processElements( jaxbClass.getUnionSubclass(), container ); - } - else if ( JaxbSubclassElement.class.isInstance( entityElement ) ) { - final JaxbSubclassElement jaxbSubclass = (JaxbSubclassElement) entityElement; - processElements( jaxbSubclass.getSubclass(), container ); - } - else if ( JaxbJoinedSubclassElement.class.isInstance( entityElement ) ) { - final JaxbJoinedSubclassElement jaxbJoinedSubclass = (JaxbJoinedSubclassElement) entityElement; - processElements( jaxbJoinedSubclass.getJoinedSubclass(), container ); - } - else if ( JaxbUnionSubclassElement.class.isInstance( entityElement ) ) { - final JaxbUnionSubclassElement jaxbUnionSubclass = (JaxbUnionSubclassElement) entityElement; - processElements( jaxbUnionSubclass.getUnionSubclass(), container ); - } - processNamedQueries( entityElement ); - } - - private void processElements(List subElements, AbstractEntitySourceImpl container) { - for ( final SubEntityElement subElement : subElements ) { - final SubclassEntitySourceImpl subclassEntitySource = createSubClassEntitySource( subElement, ( EntitySource ) container ); - container.add( subclassEntitySource ); - final String subEntityName = subclassEntitySource.getEntityName(); - subEntityContainerMap.put( subEntityName, subclassEntitySource ); - - // Re-run the sub element to handle, as an example, subclasses - // within a subclass. - processSubElements(subElement, subclassEntitySource); - } - } - - private SubclassEntitySourceImpl createSubClassEntitySource(SubEntityElement subEntityElement, EntitySource entitySource) { - if ( JaxbJoinedSubclassElement.class.isInstance( subEntityElement ) ) { - return new JoinedSubclassEntitySourceImpl( - currentMappingDocument, - JaxbJoinedSubclassElement.class.cast( subEntityElement ), - entitySource - ); - } - else { - return new SubclassEntitySourceImpl( currentMappingDocument, subEntityElement, entitySource ); - } - } - - private void processNamedQueries( EntityElement entityElement ) { - // For backward compatibility, store named queries prefixed with - // the class name. - String queryNamePrefix = entityElement.getEntityName(); - queryNamePrefix = StringHelper.isNotEmpty( queryNamePrefix ) ? queryNamePrefix : currentMappingDocument.getMappingLocalBindingContext().qualifyClassName( entityElement.getName() ); - for ( final JaxbQueryElement element : entityElement.getQuery() ) { - element.setName( queryNamePrefix + "." + element.getName() ); - NamedQueryBindingHelper.bindNamedQuery( element, bindingContext.getMetadataCollector() ); - } - for ( final JaxbSqlQueryElement element : entityElement.getSqlQuery() ) { - element.setName( queryNamePrefix + "." + element.getName() ); - NamedQueryBindingHelper.bindNamedSQLQuery( - element, - currentMappingDocument.getMappingLocalBindingContext(), - bindingContext.getMetadataCollector() - ); - } - } - - private static class ExtendsQueueEntry { - private final SubclassEntitySource subClassEntitySource; - private final String entityItExtends; - - private ExtendsQueueEntry(SubclassEntitySource subClassEntitySource, String entityItExtends) { - this.subClassEntitySource = subClassEntitySource; - this.entityItExtends = entityItExtends; - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java deleted file mode 100644 index c3034e1e96..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdBagSourceImpl.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2014, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.List; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbBagElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIdbagElement; -import org.hibernate.metamodel.source.spi.CollectionIdSource; -import org.hibernate.metamodel.source.spi.ColumnSource; -import org.hibernate.metamodel.source.spi.Orderable; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.PluralAttributeNature; - -/** - * @author Steve Ebersole - */ -public class IdBagSourceImpl extends AbstractPluralAttributeSourceImpl implements Orderable { - public final CollectionIdSource collectionIdSource; - - public IdBagSourceImpl( - MappingDocument mappingDocument, - final JaxbIdbagElement element, - AbstractEntitySourceImpl abstractEntitySource) { - super( mappingDocument, element, abstractEntitySource ); - - final List relationalValueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return element.getCollectionId().getColumnAttribute(); - } - - @Override - public SizeSource getSizeSource() { - return Helper.createSizeSourceIfMapped( - element.getCollectionId().getLength(), - null, - null - ); - } - - @Override - public List getColumn() { - return element.getCollectionId().getColumn(); - } - - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isForceNotNull() { - return true; - } - } - ); - - ColumnSource collectionIdColumnSource = null; - if ( relationalValueSources != null && relationalValueSources.isEmpty() ) { - if ( relationalValueSources.size() > 1 ) { - throw makeMappingException( "Expecting just a single column for collection id (idbag)" ); - } - - final RelationalValueSource relationalValueSource = relationalValueSources.get( 0 ); - if ( !ColumnSource.class.isInstance( relationalValueSource ) ) { - throw makeMappingException( "Expecting column for collection id (idbag), but found formula" ); - } - - collectionIdColumnSource = (ColumnSource) relationalValueSource; - } - - final HibernateTypeSourceImpl typeSource = new HibernateTypeSourceImpl( element.getCollectionId().getType() ); - this.collectionIdSource = new CollectionIdSourceImpl( - collectionIdColumnSource, - typeSource, - element.getCollectionId().getGenerator().getClazz() - ); - } - - @Override - public PluralAttributeNature getNature() { - return PluralAttributeNature.ID_BAG; - } - - @Override - public JaxbBagElement getPluralAttributeElement() { - return (JaxbBagElement) super.getPluralAttributeElement(); - } - - @Override - public boolean isOrdered() { - return StringHelper.isNotEmpty( getOrder() ); - } - - @Override - public String getOrder() { - return getPluralAttributeElement().getOrderBy(); - } - - private static class CollectionIdSourceImpl implements CollectionIdSource { - private final ColumnSource columnSource; - private final HibernateTypeSourceImpl typeSource; - private final String generator; - - public CollectionIdSourceImpl( - ColumnSource columnSource, - HibernateTypeSourceImpl typeSource, - String generator) { - this.columnSource = columnSource; - this.typeSource = typeSource; - this.generator = generator; - } - - @Override - public ColumnSource getColumnSource() { - return columnSource; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getGeneratorName() { - return generator; - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java deleted file mode 100644 index d8393a75ff..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyAttributeSourceImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.spi.NaturalIdMutability; - -/** - * @author Gail Badner - */ -public class IdentifierKeyAttributeSourceImpl extends KeyAttributeSourceImpl { - public IdentifierKeyAttributeSourceImpl( - MappingDocument mappingDocument, - AttributeSourceContainer container, - JaxbKeyPropertyElement keyPropertyElement) { - super( mappingDocument, keyPropertyElement, container, NaturalIdMutability.NOT_NATURAL_ID ); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return false; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java deleted file mode 100644 index 30b1fea7b5..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IdentifierKeyManyToOneSourceImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.spi.NaturalIdMutability; - -/** - * @author Gail Badner - */ -public class IdentifierKeyManyToOneSourceImpl extends KeyManyToOneSourceImpl { - - public IdentifierKeyManyToOneSourceImpl( - MappingDocument mappingDocument, - AttributeSourceContainer container, - JaxbKeyManyToOneElement keyManyToOneElement) { - super( mappingDocument, container, keyManyToOneElement, NaturalIdMutability.NOT_NATURAL_ID ); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/InLineViewSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/InLineViewSourceImpl.java deleted file mode 100644 index b83d90db30..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/InLineViewSourceImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import org.hibernate.metamodel.source.spi.InLineViewSource; - -/** - * @author Steve Ebersole - */ -public class InLineViewSourceImpl - extends AbstractHbmSourceNode - implements InLineViewSource { - private final String schemaName; - private final String catalogName; - private final String selectStatement; - private final String logicalName; - - public InLineViewSourceImpl( - MappingDocument mappingDocument, - String schemaName, - String catalogName, - String selectStatement, String logicalName) { - super( mappingDocument ); - this.schemaName = schemaName; - this.catalogName = catalogName; - this.selectStatement = selectStatement; - this.logicalName = logicalName; - } - - @Override - public String getExplicitSchemaName() { - return schemaName; - } - - @Override - public String getExplicitCatalogName() { - return catalogName; - } - - @Override - public String getSelectStatement() { - return selectStatement; - } - - @Override - public String getLogicalName() { - return logicalName; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IndexConstraintSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IndexConstraintSourceImpl.java deleted file mode 100644 index a9103b3b60..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/IndexConstraintSourceImpl.java +++ /dev/null @@ -1,56 +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.source.internal.hbm; - -import org.hibernate.metamodel.source.spi.IndexConstraintSource; - -/** - * @author Brett Meyer - */ -class IndexConstraintSourceImpl extends AbstractConstraintSource implements IndexConstraintSource { - - public IndexConstraintSourceImpl( String name, String tableName ) { - super( name, tableName ); - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append( "IndexConstraintSourceImpl" ); - sb.append( "{name='" ).append( name ).append( '\'' ); - sb.append( ", tableName='" ).append( tableName ).append( '\'' ); - sb.append( ", columnNames=" ).append( columnNames ); - sb.append( ", orderings=" ).append( orderings ); - sb.append( '}' ); - return sb.toString(); - } - - @Override - public boolean isUnique() { - // TODO: Is it possible to have a unique index in HBM? - return false; - } -} - - diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/JoinedSubclassEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/JoinedSubclassEntitySourceImpl.java deleted file mode 100644 index a22d2bd42e..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/JoinedSubclassEntitySourceImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbJoinedSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOnDeleteAttribute; -import org.hibernate.metamodel.source.spi.ColumnSource; -import org.hibernate.metamodel.source.spi.EntitySource; -import org.hibernate.metamodel.source.spi.JoinedSubclassEntitySource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.relational.TableSpecification; -import org.hibernate.metamodel.spi.relational.Value; - -/** - * @author Strong Liu - */ -public class JoinedSubclassEntitySourceImpl extends SubclassEntitySourceImpl implements JoinedSubclassEntitySource { - private final JaxbKeyElement key; - private final List primaryKeyJoinColumnSources; - - public JoinedSubclassEntitySourceImpl(MappingDocument sourceMappingDocument, JaxbJoinedSubclassElement entityElement, EntitySource container) { - super( sourceMappingDocument, entityElement, container ); - this.key = entityElement.getKey(); - List valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return Helper.getValue( key.isUpdate(), true ); - } - - @Override - public String getColumnAttribute() { - return key.getColumnAttribute(); - } - - @Override - public List getColumn() { - return key.getColumn(); - } - - @Override - public boolean isForceNotNull() { - return Helper.getValue( key.isNotNull(), false ); - } - - - } - ); - this.primaryKeyJoinColumnSources = new ArrayList( valueSources.size() ); - for ( final RelationalValueSource valueSource : valueSources ) { - primaryKeyJoinColumnSources.add( ColumnSource.class.cast( valueSource ) ) ; - } - } - - @Override - public boolean isCascadeDeleteEnabled() { - return key.getOnDelete() == JaxbOnDeleteAttribute.CASCADE; - } - - @Override - public String getExplicitForeignKeyName() { - return key.getForeignKey(); - } - - @Override - public boolean createForeignKeyConstraint() { - // TODO: Can HBM do something like JPA's @ForeignKey(NO_CONSTRAINT)? - return true; - } - - @Override - public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { - return key.getPropertyRef() == null - ? null - : new JoinColumnResolutionDelegate() { - @Override - public List getJoinColumns(JoinColumnResolutionContext context) { - return context.resolveRelationalValuesForAttribute( key.getPropertyRef() ); - } - - @Override - public TableSpecification getReferencedTable(JoinColumnResolutionContext context) { - return context.resolveTableForAttribute( key.getPropertyRef() ); - } - - @Override - public String getReferencedAttributeName() { - return key.getPropertyRef(); - } - }; - } - - @Override - public List getPrimaryKeyColumnSources() { - return primaryKeyJoinColumnSources; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java deleted file mode 100644 index c1c874ab3b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyAttributeSourceImpl.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; - -/** - * Implementation for {@code } mappings - * - * @author Gail Badner - */ -class KeyAttributeSourceImpl - extends AbstractHbmSourceNode - implements SingularAttributeSource { - private final JaxbKeyPropertyElement keyPropertyElement; - private final NaturalIdMutability naturalIdMutability; - private final HibernateTypeSourceImpl typeSource; - private final List valueSources; - - private final AttributePath attributePath; - private final AttributeRole attributeRole; - - public KeyAttributeSourceImpl( - MappingDocument mappingDocument, - final JaxbKeyPropertyElement keyPropertyElement, - AttributeSourceContainer container, final NaturalIdMutability naturalIdMutability) { - super( mappingDocument ); - this.keyPropertyElement = keyPropertyElement; - this.naturalIdMutability = naturalIdMutability; - - final String name = keyPropertyElement.getTypeAttribute() != null - ? keyPropertyElement.getTypeAttribute() - : keyPropertyElement.getType() != null - ? keyPropertyElement.getType().getName() - : null; - final Map parameters = ( keyPropertyElement.getType() != null ) - ? Helper.extractParameters( keyPropertyElement.getType().getParam() ) - : null; - this.typeSource = new HibernateTypeSourceImpl( name, parameters ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return keyPropertyElement.getColumnAttribute(); - } - - @Override - public SizeSource getSizeSource() { - return Helper.createSizeSourceIfMapped( - keyPropertyElement.getLength(), - null, - null - ); - } - - - @Override - public List getColumn() { - return keyPropertyElement.getColumn(); - } - - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isForceNotNull() { - return true; - } - } - ); - - this.attributePath = container.getAttributePathBase().append( getName() ); - this.attributeRole = container.getAttributeRoleBase().append( getName() ); - } - - @Override - public String getName() { - return keyPropertyElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return keyPropertyElement.getAccess(); - } - - @Override - public PropertyGeneration getGeneration() { - return PropertyGeneration.NEVER; - } - - @Override - public boolean isLazy() { - return false; - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return naturalIdMutability; - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return false; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.BASIC; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - - @Override - public String getContainingTableName() { - return null; - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public Collection getToolingHintSources() { - return keyPropertyElement.getMeta(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java deleted file mode 100644 index a1b726b141..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/KeyManyToOneSourceImpl.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.engine.spi.CascadeStyles; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; -import org.hibernate.type.ForeignKeyDirection; - -/** - * Implementation for {@code } mappings - * - * @author Gail Badner - */ -class KeyManyToOneSourceImpl - extends AbstractToOneAttributeSourceImpl - implements SingularAttributeSource { - private final JaxbKeyManyToOneElement keyManyToOneElement; - private final HibernateTypeSourceImpl typeSource; - private final List valueSources; - - private final AttributePath attributePath; - private final AttributeRole attributeRole; - - public KeyManyToOneSourceImpl( - MappingDocument mappingDocument, - AttributeSourceContainer container, - final JaxbKeyManyToOneElement keyManyToOneElement, - final NaturalIdMutability naturalIdMutability) { - super( mappingDocument, naturalIdMutability, null ); - this.keyManyToOneElement = keyManyToOneElement; - - final String referencedClassName = keyManyToOneElement.getClazz(); - JavaTypeDescriptor referencedClass = null; - if ( StringHelper.isNotEmpty( referencedClassName ) ) { - referencedClass = bindingContext().getJavaTypeDescriptorRepository().getType( - bindingContext().getJavaTypeDescriptorRepository().buildName( - bindingContext().qualifyClassName( keyManyToOneElement.getClazz() ) - ) - ); - } - this.typeSource = new HibernateTypeSourceImpl( referencedClass ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return keyManyToOneElement.getColumnAttribute(); - } - - @Override - public String getFormulaAttribute() { - return null; - } - - @Override - public List getColumn() { - return keyManyToOneElement.getColumn(); - } - - @Override - public List getFormula() { - return Collections.emptyList(); - } - - @Override - public String getContainingTableName() { - return null; - } - - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return false; - } - } - ); - - this.attributePath = container.getAttributePathBase().append( getName() ); - this.attributeRole = container.getAttributeRoleBase().append( getName() ); - } - - @Override - public String getName() { - return keyManyToOneElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return keyManyToOneElement.getAccess(); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return false; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.MANY_TO_ONE; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - protected boolean requiresImmediateFetch() { - return false; - } - - @Override - protected String getFetchSelectionString() { - return null; - } - - @Override - protected String getLazySelectionString() { - return keyManyToOneElement.getLazy() != null ? - keyManyToOneElement.getLazy().value() : - null; - } - - @Override - protected String getOuterJoinSelectionString() { - return null; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - - @Override - public String getContainingTableName() { - return null; - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public Collection getToolingHintSources() { - return keyManyToOneElement.getMeta(); - } - - @Override - public String getReferencedEntityName() { - return keyManyToOneElement.getEntityName(); - } - - @Override - public boolean isUnique() { - return false; - } - - @Override - public ForeignKeyDirection getForeignKeyDirection() { - return ForeignKeyDirection.TO_PARENT; - } - - @Override - public Set getCascadeStyles() { - return Collections.singleton( CascadeStyles.NONE ); - } - - @Override - public String getExplicitForeignKeyName() { - return keyManyToOneElement.getForeignKey(); - } - - @Override - public boolean isCascadeDeleteEnabled() { - return "cascade".equals( keyManyToOneElement.getOnDelete().value() ); - } - - protected String getClassName() { - return keyManyToOneElement.getClazz(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java deleted file mode 100644 index ba3f447d52..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ListSourceImpl.java +++ /dev/null @@ -1,66 +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.source.internal.hbm; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; -import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; -import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; -import org.hibernate.metamodel.spi.PluralAttributeNature; - -public class ListSourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource { - private final PluralAttributeSequentialIndexSource indexSource; - - public ListSourceImpl( - MappingDocument sourceMappingDocument, - JaxbListElement listElement, - AttributeSourceContainer container) { - super( sourceMappingDocument, listElement, container ); - JaxbListIndexElement listIndexElement = listElement.getListIndex(); - if ( listIndexElement == null ) { - this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listElement.getIndex() ); - } - else { - this.indexSource = new PluralAttributeSequentialIndexSourceImpl( sourceMappingDocument(), listIndexElement ); - } - } - - @Override - public PluralAttributeIndexSource getIndexSource() { - return indexSource; - } - - @Override - public JaxbListElement getPluralAttributeElement() { - return ( JaxbListElement ) super.getPluralAttributeElement(); - } - - @Override - public PluralAttributeNature getNature() { - return PluralAttributeNature.LIST; - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/LoadCollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/LoadCollectionBinder.java deleted file mode 100644 index 569b76e7cd..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/LoadCollectionBinder.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.HashMap; -import java.util.Map; - -import org.hibernate.cfg.HbmBinder; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryCollectionReturn; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbLoadCollectionElement; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.LocalBindingContext; - -/** - * @author Strong Liu - */ -class LoadCollectionBinder extends AbstractReturnBinder { - LoadCollectionBinder( - final JaxbLoadCollectionElement element, - final int elementIndex, - final LocalBindingContext context, - final InFlightMetadataCollector metadataCollector) { - super( element, elementIndex, context, metadataCollector ); - } - - @Override - NativeSQLQueryReturn process() { - final String collectionAttribute = element.getRole(); - int dot = collectionAttribute.lastIndexOf( '.' ); - if ( dot == -1 ) { - throw context.makeMappingException( - "Collection attribute for sql query return [alias=" + alias + "] not formatted correctly {OwnerClassName.propertyName}" - ); - } - final String ownerClassName = HbmBinder.getClassName( - collectionAttribute.substring( 0, dot ), context.getMappingDefaults().getPackageName() - ); - final String ownerPropertyName = collectionAttribute.substring( dot + 1 ); - final Map propertyResults = new HashMap(); - processReturnProperties( new ReturnPropertiesCallbackImpl( alias, propertyResults, context ) ); - return new NativeSQLQueryCollectionReturn( - alias, ownerClassName, ownerPropertyName, propertyResults, lockMode - ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java deleted file mode 100644 index 1d1d85c626..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ManyToOneAttributeSourceImpl.java +++ /dev/null @@ -1,252 +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.source.internal.hbm; - -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; -import org.hibernate.type.ForeignKeyDirection; - -/** - * Implementation for {@code } mappings - * - * @author Steve Ebersole - */ -class ManyToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { - private final JaxbManyToOneElement manyToOneElement; - private final HibernateTypeSourceImpl typeSource; - - private final String containingTableName; - private final List valueSources; - - private final AttributeRole attributeRole; - private final AttributePath attributePath; - - ManyToOneAttributeSourceImpl( - MappingDocument sourceMappingDocument, - AttributeSourceContainer container, - final JaxbManyToOneElement manyToOneElement, - final String logicalTableName, - NaturalIdMutability naturalIdMutability) { - super( sourceMappingDocument, naturalIdMutability, manyToOneElement.getPropertyRef() ); - this.manyToOneElement = manyToOneElement; - - final String referencedClassName = manyToOneElement.getClazz(); - JavaTypeDescriptor referencedClass = null; - if ( StringHelper.isNotEmpty( referencedClassName ) ) { - referencedClass = bindingContext().getJavaTypeDescriptorRepository().getType( - bindingContext().getJavaTypeDescriptorRepository().buildName( - bindingContext().qualifyClassName( manyToOneElement.getClazz() ) - ) - ); - } - this.typeSource = new HibernateTypeSourceImpl( referencedClass ); - - this.containingTableName = logicalTableName; - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return manyToOneElement.getColumnAttribute(); - } - - @Override - public String getFormulaAttribute() { - return manyToOneElement.getFormulaAttribute(); - } - - @Override - public List getColumn() { - return manyToOneElement.getColumn(); - } - - @Override - public List getFormula() { - return manyToOneElement.getFormula(); - } - - @Override - public String getContainingTableName() { - return logicalTableName; - } - - @Override - public boolean isIncludedInInsertByDefault() { - return manyToOneElement.isInsert(); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return manyToOneElement.isUpdate(); - } - } - ); - - this.attributeRole = container.getAttributeRoleBase().append( manyToOneElement.getName() ); - this.attributePath = container.getAttributePathBase().append( manyToOneElement.getName() ); - } - - @Override - public String getName() { - return manyToOneElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return manyToOneElement.getAccess(); - } - - @Override - public boolean isIgnoreNotFound() { - return manyToOneElement.getNotFound() != null && "ignore".equalsIgnoreCase( manyToOneElement.getNotFound().value() ); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return manyToOneElement.isOptimisticLock(); - } - - @Override - public Set getCascadeStyles() { - return Helper.interpretCascadeStyles( manyToOneElement.getCascade(), bindingContext() ); - } - - @Override - protected boolean requiresImmediateFetch() { - return false; - } - - @Override - protected String getFetchSelectionString() { - return manyToOneElement.getFetch() != null ? - manyToOneElement.getFetch().value() : - null; - } - - @Override - protected String getLazySelectionString() { - return manyToOneElement.getLazy() != null ? - manyToOneElement.getLazy().value() : - null; - } - - @Override - protected String getOuterJoinSelectionString() { - return manyToOneElement.getOuterJoin() != null ? - manyToOneElement.getOuterJoin().value() : - null; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.MANY_TO_ONE; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return manyToOneElement.isInsert(); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return manyToOneElement.isUpdate(); - } - - @Override - public boolean areValuesNullableByDefault() { - return ! Helper.getValue( manyToOneElement.isNotNull(), false ); - } - - @Override - public String getContainingTableName() { - return containingTableName; - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public Collection getToolingHintSources() { - return manyToOneElement.getMeta(); - } - - @Override - public String getReferencedEntityName() { - return manyToOneElement.getClazz() != null - ? bindingContext().qualifyClassName( manyToOneElement.getClazz() ) - : manyToOneElement.getEntityName(); - } - - @Override - public boolean isUnique() { - return manyToOneElement.isUnique(); - } - - @Override - public String getExplicitForeignKeyName() { - return manyToOneElement.getForeignKey(); - } - - @Override - public boolean isCascadeDeleteEnabled() { - return false; - } - - @Override - public ForeignKeyDirection getForeignKeyDirection() { - return ForeignKeyDirection.TO_PARENT; - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceBasicImpl.java deleted file mode 100644 index 9c128894e3..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapKeySourceBasicImpl.java +++ /dev/null @@ -1,200 +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.source.internal.hbm; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.hibernate.cfg.NamingStrategy; -import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIndexElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapKeyElement; -import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceBasic; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.PluralAttributeIndexNature; - -/** - * - */ -public class MapKeySourceBasicImpl extends AbstractHbmSourceNode implements PluralAttributeMapKeySourceBasic { - private final PluralAttributeIndexNature nature; - private final List valueSources; - private final HibernateTypeSourceImpl typeSource; - - public MapKeySourceBasicImpl(MappingDocument sourceMappingDocument, final JaxbMapKeyElement mapKey) { - super( sourceMappingDocument ); - - final String typeName = extractTypeName( mapKey ); - final Map typeParams = mapKey.getType() != null - ? Helper.extractParameters( mapKey.getType().getParam() ) - : java.util.Collections.emptyMap(); - this.typeSource = new HibernateTypeSourceImpl( typeName, typeParams ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - - @Override - public String getColumnAttribute() { - return mapKey.getColumnAttribute(); - } - - @Override - public SizeSource getSizeSource() { - return Helper.createSizeSourceIfMapped( - mapKey.getLength(), - null, - null - ); - } - - - @Override - public List getColumn() { - return mapKey.getColumn(); - } - - @Override - public List getFormula() { - return mapKey.getFormula(); - } - - @Override - public String getFormulaAttribute() { - return mapKey.getFormulaAttribute(); - } - - @Override - public boolean isIncludedInInsertByDefault() { - return areValuesIncludedInInsertByDefault(); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return areValuesIncludedInUpdateByDefault(); - } - } - ); - - this.nature = PluralAttributeIndexNature.BASIC; - } - - private String extractTypeName(JaxbMapKeyElement mapKey) { - if ( mapKey.getTypeAttribute() != null ) { - return mapKey.getTypeAttribute(); - } - if ( mapKey.getType() != null ) { - return mapKey.getType().getName(); - } - return null; - } - - public MapKeySourceBasicImpl(MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement) { - super( sourceMappingDocument ); - this.typeSource = new HibernateTypeSourceImpl( indexElement.getType() ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument, - new Helper.ValueSourcesAdapter() { - - @Override - public String getColumnAttribute() { - return indexElement.getColumnAttribute(); - } - - @Override - public SizeSource getSizeSource() { - return Helper.createSizeSourceIfMapped( - indexElement.getLength(), - null, - null - ); - } - - - @Override - public List getColumn() { - return indexElement.getColumn(); - } - - @Override - public boolean isIncludedInInsertByDefault() { - return areValuesIncludedInInsertByDefault(); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return areValuesIncludedInUpdateByDefault(); - } - } - ); - - this.nature = PluralAttributeIndexNature.BASIC; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - - @Override - public PluralAttributeIndexNature getNature() { - return nature; - } - - @Override - public List getDefaultNamingStrategies() { - final Binder.DefaultNamingStrategy defaultNamingStrategy = - new Binder.DefaultNamingStrategy() { - @Override - public String defaultName(NamingStrategy namingStrategy) { - return namingStrategy.columnName( "idx" ); - } - }; - return Collections.singletonList( defaultNamingStrategy ); - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public List relationalValueSources() { - return valueSources; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java deleted file mode 100644 index 2e9a38bc75..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MapSourceImpl.java +++ /dev/null @@ -1,90 +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.source.internal.hbm; - -import org.hibernate.AssertionFailure; -import org.hibernate.cfg.NotYetImplementedException; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbMapElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.IndexedPluralAttributeSource; -import org.hibernate.metamodel.source.spi.PluralAttributeIndexSource; -import org.hibernate.metamodel.spi.PluralAttributeNature; - -public class MapSourceImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource { - private final PluralAttributeIndexSource indexSource; - - public MapSourceImpl( - MappingDocument sourceMappingDocument, - JaxbMapElement mapElement, - AttributeSourceContainer container) { - super( sourceMappingDocument, mapElement, container ); - if ( mapElement.getMapKey() != null ) { - this.indexSource = new MapKeySourceBasicImpl( sourceMappingDocument, mapElement.getMapKey() ); - } - else if ( mapElement.getIndex() != null ) { - this.indexSource = new MapKeySourceBasicImpl( sourceMappingDocument, mapElement.getIndex() ); - } - else if ( mapElement.getCompositeMapKey() != null ) { - this.indexSource = new PluralAttributeMapKeySourceEmbeddedImpl( - sourceMappingDocument, - this, - mapElement.getCompositeMapKey() - ); - } - else if ( mapElement.getCompositeIndex() != null ) { - this.indexSource = new PluralAttributeMapKeySourceEmbeddedImpl( - sourceMappingDocument, - this, - mapElement.getCompositeIndex() - ); - } - else if ( mapElement.getMapKeyManyToMany() != null ) { - throw new NotYetImplementedException( " is not supported yet" ); - } - else if ( mapElement.getIndexManyToMany() != null ) { - throw new NotYetImplementedException( " is not supported yet" ); - } - else if ( mapElement.getIndexManyToAny() != null ) { - throw new NotYetImplementedException( " is not supported yet" ); - } - else { - throw new AssertionFailure( "No map key found" ); - } - } - - @Override - public PluralAttributeIndexSource getIndexSource() { - return indexSource; - } - - @Override - public JaxbMapElement getPluralAttributeElement() { - return ( JaxbMapElement ) super.getPluralAttributeElement(); - } - - @Override - public PluralAttributeNature getNature() { - return PluralAttributeNature.MAP; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MappingDocument.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MappingDocument.java deleted file mode 100644 index 2df4768b63..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/MappingDocument.java +++ /dev/null @@ -1,156 +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.source.internal.hbm; - -import java.util.List; - -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.OverriddenMappingDefaults; -import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFetchProfileElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbHibernateMapping; -import org.hibernate.metamodel.source.spi.MappingDefaults; -import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.source.spi.MetaAttributeContext; -import org.hibernate.metamodel.spi.BaseDelegatingBindingContext; -import org.hibernate.metamodel.spi.BindingContext; -import org.hibernate.xml.spi.BindResult; -import org.hibernate.xml.spi.Origin; - -/** - * Aggregates together information about a mapping document. - * - * @author Steve Ebersole - */ -public class MappingDocument { - private final BindResult hbmBindResult; - private final LocalBindingContextImpl mappingLocalBindingContext; - - public MappingDocument(BindResult hbmBindResult, BindingContext bindingContext) { - this.hbmBindResult = hbmBindResult; - this.mappingLocalBindingContext = new LocalBindingContextImpl( bindingContext ); - - } - - public JaxbHibernateMapping getMappingRoot() { - return hbmBindResult.getRoot(); - } - - public Origin getOrigin() { - return hbmBindResult.getOrigin(); - } - - public BindResult getJaxbRoot() { - return hbmBindResult; - } - - public HbmBindingContext getMappingLocalBindingContext() { - return mappingLocalBindingContext; - } - - private class LocalBindingContextImpl extends BaseDelegatingBindingContext implements HbmBindingContext { - private final MappingDefaults localMappingDefaults; - private final MetaAttributeContext metaAttributeContext; - - private LocalBindingContextImpl(BindingContext rootBindingContext) { - super( rootBindingContext ); - this.localMappingDefaults = new OverriddenMappingDefaults( - rootBindingContext.getMappingDefaults(), - hbmBindResult.getRoot().getPackage(), - hbmBindResult.getRoot().getSchema(), - hbmBindResult.getRoot().getCatalog(), - null, - null, - null, - hbmBindResult.getRoot().getDefaultCascade(), - hbmBindResult.getRoot().getDefaultAccess(), - hbmBindResult.getRoot().isDefaultLazy() - ); - - if ( CollectionHelper.isEmpty( hbmBindResult.getRoot().getMeta() ) ) { - this.metaAttributeContext = new MetaAttributeContext( - rootBindingContext.getGlobalMetaAttributeContext() - ); - } - else { - this.metaAttributeContext = Helper.extractMetaAttributeContext( - hbmBindResult.getRoot().getMeta(), - true, - rootBindingContext.getGlobalMetaAttributeContext() - ); - } - } - - @Override - public String qualifyClassName(String unqualifiedName) { - return Helper.qualifyIfNeeded( unqualifiedName, getMappingDefaults().getPackageName() ); - } - - @Override - public JavaTypeDescriptor typeDescriptor(String name) { - return super.typeDescriptor( qualifyClassName( name ) ); - } - - @Override - public MappingDefaults getMappingDefaults() { - return localMappingDefaults; - } - - @Override - public Origin getOrigin() { - return hbmBindResult.getOrigin(); - } - - @Override - public MappingException makeMappingException(String message) { - return new MappingException( message, getOrigin() ); - } - - @Override - public MappingException makeMappingException(String message, Exception cause) { - return new MappingException( message, cause, getOrigin() ); - } - - @Override - public boolean isAutoImport() { - return hbmBindResult.getRoot().isAutoImport(); - } - - @Override - public MetaAttributeContext getMetaAttributeContext() { - return metaAttributeContext; - } - - @Override - public String determineEntityName(EntityElement entityElement) { - return Helper.determineEntityName( entityElement, getMappingDefaults().getPackageName() ); - } - - @Override - public void processFetchProfiles(List fetchProfiles, String containingEntityName) { - // todo : this really needs to not be part of the context - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java deleted file mode 100644 index 48582cee8b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/NamedQueryBindingHelper.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.engine.spi.NamedQueryDefinitionBuilder; -import org.hibernate.engine.spi.NamedSQLQueryDefinition; -import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.hbm.parser.BasicQueryElementContentParser; -import org.hibernate.metamodel.source.internal.hbm.parser.SQLQueryElementContentParser; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbLoadCollectionElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbQueryElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSqlQueryElement; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.AttributeBinding; -import org.hibernate.metamodel.spi.binding.EmbeddedAttributeBinding; -import org.hibernate.metamodel.spi.binding.EntityBinding; -import org.hibernate.metamodel.spi.binding.SingularAssociationAttributeBinding; -import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; - -/** - * Helper class used to bind named query elements. - * - * @author Brett Meyer - * @author Strong Liu - */ -public class NamedQueryBindingHelper { - - /** - * Helper method used to bind {@code } element. - * - * @param queryElement The {@code } element. - * @param metadataCollector The {@link org.hibernate.metamodel.Metadata} which this named query will be added to. - */ - public static void bindNamedQuery( - final JaxbQueryElement queryElement, - final InFlightMetadataCollector metadataCollector) { - final NamedQueryDefinitionBuilder builder = new NamedQueryDefinitionBuilder(); - final BasicQueryElementContentParser parser = new BasicQueryElementContentParser(); - parser.parse( builder, queryElement ); - metadataCollector.addNamedQuery( builder.createNamedQueryDefinition() ); - } - - public static void bindNamedSQLQuery( - final JaxbSqlQueryElement queryElement, - final LocalBindingContext bindingContext, - final InFlightMetadataCollector metadataCollector) { - final NamedSQLQueryDefinitionBuilder builder = new NamedSQLQueryDefinitionBuilder(); - final SQLQueryElementContentParser parser = new SQLQueryElementContentParser(); - - parser.parse( builder, queryElement ); - - final boolean callable = queryElement.isCallable(); - final String resultSetRef = queryElement.getResultsetRef(); - //TODO: check if the refereneced result set mapping definition exist or not? - builder.setCallable( callable ).setResultSetRef( resultSetRef ); - - NamedSQLQueryDefinition namedQuery; - //query returns are defined in the element. - if ( StringHelper.isNotEmpty( resultSetRef ) ) { - namedQuery = builder.createNamedQueryDefinition(); - } - else { - namedQuery = parser.buildQueryReturns( queryElement.getName(),builder, bindingContext, metadataCollector ); - } - metadataCollector.addNamedNativeQuery( namedQuery ); - } - - - - private static Map bindPropertyResults( - String alias, JaxbLoadCollectionElement element, - EntityBinding entityBinding) { - List returnPropertyElements - = element.getReturnProperty(); - List properties - = new ArrayList(); - List propertyNames = new ArrayList(); - HashMap> propertyResults = new HashMap>(); - for ( JaxbReturnPropertyElement propertyElement : returnPropertyElements ) { - String name = propertyElement.getName(); - if ( entityBinding == null || name.indexOf( '.' ) == -1 ) { - properties.add( propertyElement ); - propertyNames.add( name ); - } - else { - /** - * Reorder properties - * 1. get the parent property - * 2. list all the properties following the expected one in the parent property - * 3. calculate the lowest index and insert the property - */ - if ( entityBinding == null ) { - throw new org.hibernate.MappingException( - "dotted notation in or not yet supported" - ); - } - int dotIndex = name.lastIndexOf( '.' ); - String reducedName = name.substring( 0, dotIndex ); - AttributeBinding value = null;// getRecursiveAttributeBinding(entityBinding, reducedName ); - Iterable parentPropIter; - if ( EmbeddedAttributeBinding.class.isInstance( value ) ) { - EmbeddedAttributeBinding comp - = (EmbeddedAttributeBinding) value; - parentPropIter = comp.getEmbeddableBinding().attributeBindings(); - } - else if ( SingularAssociationAttributeBinding.class.isInstance( value ) ) { - SingularAssociationAttributeBinding toOne - = SingularAssociationAttributeBinding.class.cast( - value - ); - EntityBinding referencedEntityBinding - = toOne.getReferencedEntityBinding(); - SingularAttributeBinding referencedAttributeBinding - = toOne.getReferencedAttributeBinding(); - try { - parentPropIter = EmbeddedAttributeBinding.class.cast( - referencedAttributeBinding - ).getEmbeddableBinding().attributeBindings(); - } - catch ( ClassCastException e ) { - throw new org.hibernate.MappingException( - "dotted notation reference neither a component nor a many/one to one", e - ); - } - } - else { - throw new org.hibernate.MappingException( - "dotted notation reference neither a component nor a many/one to one" - ); - } - boolean hasFollowers = false; - List followers = new ArrayList(); - for ( AttributeBinding binding : parentPropIter ) { - String currentPropertyName - = binding.getAttribute().getName(); - String currentName = reducedName + '.' - + currentPropertyName; - if ( hasFollowers ) { - followers.add( currentName ); - } - if ( name.equals( currentName ) ) { - hasFollowers = true; - } - } - - int index = propertyNames.size(); - int followersSize = followers.size(); - for ( int loop = 0; loop < followersSize; loop++ ) { - String follower = followers.get( loop ); - int currentIndex = getIndexOfFirstMatchingProperty( - propertyNames, follower - ); - index = currentIndex != -1 && currentIndex < index - ? currentIndex : index; - } - propertyNames.add( index, name ); - properties.add( index, propertyElement ); - } - } - - Map results = new HashMap( propertyResults.size() ); - return results; - } - - - - private static int getIndexOfFirstMatchingProperty(List propertyNames, - String follower) { - int propertySize = propertyNames.size(); - for ( int propIndex = 0; propIndex < propertySize; propIndex++ ) { - if ( ( (String) propertyNames.get( propIndex ) ).startsWith( - follower - ) ) { - return propIndex; - } - } - return -1; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java deleted file mode 100644 index 3b0ecfc618..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/OneToOneAttributeSourceImpl.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToOneElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; -import org.hibernate.type.ForeignKeyDirection; - -/** - * Implementation for {@code } mappings - * - * @author Gail Badner - * @author Steve Ebersole - */ -class OneToOneAttributeSourceImpl extends AbstractToOneAttributeSourceImpl { - private final JaxbOneToOneElement oneToOneElement; - private final HibernateTypeSourceImpl typeSource; - - private final String containingTableName; - private final List valueSources; - - private final AttributeRole attributeRole; - private final AttributePath attributePath; - - OneToOneAttributeSourceImpl( - MappingDocument sourceMappingDocument, - AttributeSourceContainer container, - final JaxbOneToOneElement oneToOneElement, - final String logicalTableName, - NaturalIdMutability naturalIdMutability) { - super( sourceMappingDocument, naturalIdMutability, oneToOneElement.getPropertyRef() ); - this.oneToOneElement = oneToOneElement; - - final String referencedClassName = oneToOneElement.getClazz(); - JavaTypeDescriptor referencedClass = null; - if ( StringHelper.isNotEmpty( referencedClassName ) ) { - referencedClass = bindingContext().getJavaTypeDescriptorRepository().getType( - bindingContext().getJavaTypeDescriptorRepository().buildName( - bindingContext().qualifyClassName( oneToOneElement.getClazz() ) - ) - ); - } - this.typeSource = new HibernateTypeSourceImpl( referencedClass ); - - this.containingTableName = logicalTableName; - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - // Not applicable to one-to-one - return null; - } - - @Override - public String getFormulaAttribute() { - return oneToOneElement.getFormulaAttribute(); - } - - @Override - public List getColumn() { - // Not applicable to one-to-one - return null; - } - - @Override - public List getFormula() { - return oneToOneElement.getFormula(); - } - - @Override - public String getContainingTableName() { - return logicalTableName; - } - - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return false; - } - } - ); - - this.attributeRole = container.getAttributeRoleBase().append( oneToOneElement.getName() ); - this.attributePath = container.getAttributePathBase().append( oneToOneElement.getName() ); - } - - @Override - public String getName() { - return oneToOneElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return oneToOneElement.getAccess(); - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return false; - } - - @Override - public Set getCascadeStyles() { - return Helper.interpretCascadeStyles( oneToOneElement.getCascade(), bindingContext() ); - } - - @Override - protected String getFetchSelectionString() { - return oneToOneElement.getFetch()!=null? oneToOneElement.getFetch().value() : null; - } - - @Override - protected String getLazySelectionString() { - return oneToOneElement.getLazy()!=null? oneToOneElement.getLazy().value() : null; - } - - @Override - protected String getOuterJoinSelectionString() { - return oneToOneElement.getOuterJoin()!=null? oneToOneElement.getOuterJoin().value() : null; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.ONE_TO_ONE; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - protected boolean requiresImmediateFetch() { - return !oneToOneElement.isConstrained(); - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - - @Override - public String getContainingTableName() { - return containingTableName; - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public Collection getToolingHintSources() { - return oneToOneElement.getMeta(); - } - - @Override - public String getReferencedEntityName() { - return oneToOneElement.getClazz() != null - ? bindingContext().qualifyClassName( oneToOneElement.getClazz() ) - : oneToOneElement.getEntityName(); - } - - @Override - public boolean isUnique() { - return true; - } - - @Override - public String getExplicitForeignKeyName() { - return oneToOneElement.getForeignKey(); - } - - @Override - public boolean isCascadeDeleteEnabled() { - return false; - } - - @Override - public ForeignKeyDirection getForeignKeyDirection() { - return oneToOneElement.isConstrained() ? ForeignKeyDirection.FROM_PARENT : ForeignKeyDirection.TO_PARENT; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java deleted file mode 100644 index 2b506dc493..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceBasicImpl.java +++ /dev/null @@ -1,147 +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.source.internal.hbm; - -import java.util.List; -import java.util.Map; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbElementElement; -import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceBasic; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.PluralAttributeElementNature; - -/** - * @author Steve Ebersole - */ -public class PluralAttributeElementSourceBasicImpl - extends AbstractHbmSourceNode - implements PluralAttributeElementSourceBasic { - private final HibernateTypeSourceImpl typeSource; - private final List valueSources; - - public PluralAttributeElementSourceBasicImpl( - MappingDocument sourceMappingDocument, - final JaxbElementElement elementElement) { - super( sourceMappingDocument ); - - final String typeName = extractTypeName( elementElement ); - final Map typeParams = elementElement.getType() != null - ? Helper.extractParameters( elementElement.getType().getParam() ) - : java.util.Collections.emptyMap(); - this.typeSource = new HibernateTypeSourceImpl( typeName, typeParams ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public boolean isIncludedInInsertByDefault() { - return PluralAttributeElementSourceBasicImpl.this.areValuesIncludedInInsertByDefault(); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return PluralAttributeElementSourceBasicImpl.this.areValuesIncludedInUpdateByDefault(); - } - - @Override - public String getColumnAttribute() { - return elementElement.getColumnAttribute(); - } - - @Override - public String getFormulaAttribute() { - return elementElement.getFormulaAttribute(); - } - - @Override - public SizeSource getSizeSource() { - return Helper.createSizeSourceIfMapped( - elementElement.getLength(), - elementElement.getPrecision(), - elementElement.getScale() - ); - } - - @Override - public List getColumn() { - return elementElement.getColumn(); - } - - @Override - public List getFormula() { - return elementElement.getFormula(); - } - - @Override - public boolean isForceNotNull() { - return elementElement.isNotNull(); - } - } - ); - } - - private String extractTypeName(JaxbElementElement elementElement) { - if ( elementElement.getTypeAttribute() != null ) { - return elementElement.getTypeAttribute(); - } - else if ( elementElement.getType() != null ) { - return elementElement.getType().getName(); - } - else { - return null; - } - } - - @Override - public PluralAttributeElementNature getNature() { - return PluralAttributeElementNature.BASIC; - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } - - @Override - public HibernateTypeSourceImpl getExplicitHibernateTypeSource() { - return typeSource; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java deleted file mode 100644 index 43d8d64fff..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceEmbeddedImpl.java +++ /dev/null @@ -1,150 +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.source.internal.hbm; - -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.hibernate.EntityMode; -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbAnyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeElementElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNestedCompositeElementElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTuplizerElement; -import org.hibernate.metamodel.source.spi.EmbeddableSource; -import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceEmbedded; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.PluralAttributeElementNature; - -/** - * @author Steve Ebersole - * @author Gail Badner - */ -public class PluralAttributeElementSourceEmbeddedImpl - extends AbstractHbmSourceNode - implements PluralAttributeElementSourceEmbedded { - - private final JaxbCompositeElementElement compositeElement; - private final EmbeddableSourceImpl embeddableSource; - private final Set cascadeStyles; - - public PluralAttributeElementSourceEmbeddedImpl( - MappingDocument mappingDocument, - AbstractPluralAttributeSourceImpl pluralAttributeSource, - JaxbCompositeElementElement compositeElement, - String cascadeString) { - super( mappingDocument ); - this.compositeElement = compositeElement; - - this.embeddableSource = new EmbeddableSourceImpl( - mappingDocument, - pluralAttributeSource.getAttributeRole(), - pluralAttributeSource.getAttributePath(), - new EmbeddableJaxbSourceImpl( compositeElement ), - null, - NaturalIdMutability.NOT_NATURAL_ID - ); - - this.cascadeStyles = Helper.interpretCascadeStyles( cascadeString, bindingContext() ); - } - - @Override - public PluralAttributeElementNature getNature() { - return PluralAttributeElementNature.AGGREGATE; - } - - @Override - public EmbeddableSource getEmbeddableSource() { - return embeddableSource; - } - - @Override - public Collection getToolingHintSources() { - return compositeElement.getMeta(); - } - - public static class EmbeddableJaxbSourceImpl extends AbstractEmbeddableJaxbSource { - private final JaxbCompositeElementElement compositeElement; - - public EmbeddableJaxbSourceImpl(JaxbCompositeElementElement compositeElement) { - this.compositeElement = compositeElement; - } - - @Override - public String getClazz() { - return compositeElement.getClazz(); - } - - @Override - public String findParent() { - return compositeElement.getParent() != null - ? compositeElement.getParent().getName() - : null; - } - - @Override - public String findTuplizer() { - if ( compositeElement.getTuplizer() == null ) { - return null; - } - final EntityMode entityMode = StringHelper.isEmpty( compositeElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO; - for ( JaxbTuplizerElement tuplizerElement : compositeElement.getTuplizer() ) { - if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) { - return tuplizerElement.getClazz(); - } - } - return null; - } - - @Override - public List getPropertyElementList() { - return compositeElement.getProperty(); - } - - @Override - public List getAnyElementList() { - return compositeElement.getAny(); - } - - @Override - public List getNestedCompositeElementList() { - return compositeElement.getNestedCompositeElement(); - } - - @Override - public List getManyToOneElementList() { - return compositeElement.getManyToOne(); - } - } - - @Override - public Set getCascadeStyles() { - return cascadeStyles; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceManyToManyImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceManyToManyImpl.java deleted file mode 100644 index bd069566d6..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceManyToManyImpl.java +++ /dev/null @@ -1,268 +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.source.internal.hbm; - -import java.util.List; -import java.util.Set; - -import org.hibernate.engine.FetchTiming; -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFilterElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbManyToManyElement; -import org.hibernate.metamodel.source.spi.FilterSource; -import org.hibernate.metamodel.source.spi.MappingException; -import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceManyToMany; -import org.hibernate.metamodel.source.spi.PluralAttributeSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.PluralAttributeElementNature; -import org.hibernate.metamodel.spi.relational.TableSpecification; -import org.hibernate.metamodel.spi.relational.Value; - -/** - * @author Steve Ebersole - * @author Gail Badner - */ -public class PluralAttributeElementSourceManyToManyImpl - extends AbstractPluralAssociationElementSourceImpl - implements PluralAttributeElementSourceManyToMany { - private final JaxbManyToManyElement manyToManyElement; - private final Set cascadeStyles; - - private final List valueSources; - private final FilterSource[] filterSources; - public PluralAttributeElementSourceManyToManyImpl( - MappingDocument mappingDocument, - final PluralAttributeSource pluralAttributeSource, - final JaxbManyToManyElement manyToManyElement, - String cascadeString) { - super( mappingDocument, pluralAttributeSource ); - this.manyToManyElement = manyToManyElement; - this.cascadeStyles = Helper.interpretCascadeStyles( cascadeString, bindingContext() ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return true; - } - - @Override - public String getColumnAttribute() { - return manyToManyElement.getColumnAttribute(); - } - - @Override - public String getFormulaAttribute() { - return manyToManyElement.getFormulaAttribute(); - } - - @Override - public List getColumn() { - return manyToManyElement.getColumn(); - } - - @Override - public List getFormula() { - return manyToManyElement.getFormula(); - } - } - ); - this.filterSources = buildFilterSources(); - } - - private FilterSource[] buildFilterSources() { - final int size = manyToManyElement.getFilter().size(); - if ( size == 0 ) { - return null; - } - - FilterSource[] results = new FilterSource[size]; - for ( int i = 0; i < size; i++ ) { - JaxbFilterElement element = manyToManyElement.getFilter().get( i ); - results[i] = new FilterSourceImpl( sourceMappingDocument(), element ); - } - return results; - } - - @Override - public PluralAttributeElementNature getNature() { - return PluralAttributeElementNature.MANY_TO_MANY; - } - - @Override - public String getReferencedEntityName() { - return StringHelper.isNotEmpty( manyToManyElement.getEntityName() ) - ? manyToManyElement.getEntityName() - : bindingContext().qualifyClassName( manyToManyElement.getClazz() ); - } - - @Override - public FilterSource[] getFilterSources() { - return filterSources; - } - - @Override - public String getReferencedEntityAttributeName() { - return manyToManyElement.getPropertyRef(); - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean isIgnoreNotFound() { - return manyToManyElement.getNotFound() != null && "ignore".equalsIgnoreCase( manyToManyElement.getNotFound().value() ); - } - - @Override - public String getExplicitForeignKeyName() { - return manyToManyElement.getForeignKey(); - } - - @Override - public boolean isCascadeDeleteEnabled() { - return false; - } - - @Override - public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { - return manyToManyElement.getPropertyRef() == null - ? null - : new JoinColumnResolutionDelegateImpl(); - } - - @Override - public boolean isUnique() { - return manyToManyElement.isUnique(); - } - - @Override - public String getWhere() { - return manyToManyElement.getWhere(); - } - - @Override - public Set getCascadeStyles() { - return cascadeStyles; - } - - @Override - public FetchTiming getFetchTiming() { - final String fetchSelection = manyToManyElement.getFetch() != null ? - manyToManyElement.getFetch().value() : - null; - final String lazySelection = manyToManyElement.getLazy() != null - ? manyToManyElement.getLazy().value() - : null; - final String outerJoinSelection = manyToManyElement.getOuterJoin() != null - ? manyToManyElement.getOuterJoin().value() - : null; - - if ( lazySelection == null ) { - if ( "join".equals( fetchSelection ) || "true".equals( outerJoinSelection ) ) { - return FetchTiming.IMMEDIATE; - } - else if ( "false".equals( outerJoinSelection ) ) { - return FetchTiming.DELAYED; - } - else { - // default is FetchTiming.IMMEDIATE. - return FetchTiming.IMMEDIATE; - } - } - else if ( "true".equals( lazySelection ) ) { - return FetchTiming.DELAYED; - } - else if ( "false".equals( lazySelection ) ) { - return FetchTiming.IMMEDIATE; - } - // TODO: improve this method to say attribute name. - throw new MappingException( - String.format( - "Unexpected lazy selection [%s] on many-to-many element", - lazySelection - ), - origin() - ); - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - - @Override - public boolean isOrdered() { - return StringHelper.isNotEmpty( getOrder() ); - } - - @Override - public String getOrder() { - return manyToManyElement.getOrderBy(); - } - - public class JoinColumnResolutionDelegateImpl implements JoinColumnResolutionDelegate { - @Override - public String getReferencedAttributeName() { - return manyToManyElement.getPropertyRef(); - } - - @Override - public List getJoinColumns(JoinColumnResolutionContext context) { - return context.resolveRelationalValuesForAttribute( manyToManyElement.getPropertyRef() ); - } - - @Override - public TableSpecification getReferencedTable(JoinColumnResolutionContext context) { - return context.resolveTableForAttribute( manyToManyElement.getPropertyRef() ); - } - } - - @Override - public boolean createForeignKeyConstraint() { - // TODO: Can HBM do something like JPA's @ForeignKey(NO_CONSTRAINT)? - return true; - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceOneToManyImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceOneToManyImpl.java deleted file mode 100644 index b3d98c3d7b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeElementSourceOneToManyImpl.java +++ /dev/null @@ -1,75 +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.source.internal.hbm; - -import java.util.Set; - -import org.hibernate.engine.spi.CascadeStyle; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOneToManyElement; -import org.hibernate.metamodel.source.spi.PluralAttributeElementSourceOneToMany; -import org.hibernate.metamodel.source.spi.PluralAttributeSource; -import org.hibernate.metamodel.spi.PluralAttributeElementNature; - -/** - * @author Steve Ebersole - */ -public class PluralAttributeElementSourceOneToManyImpl - extends AbstractPluralAssociationElementSourceImpl - implements PluralAttributeElementSourceOneToMany { - private final JaxbOneToManyElement oneToManyElement; - private final Set cascadeStyles; - - public PluralAttributeElementSourceOneToManyImpl( - MappingDocument mappingDocument, - final PluralAttributeSource pluralAttributeSource, - final JaxbOneToManyElement oneToManyElement, - String cascadeString) { - super( mappingDocument, pluralAttributeSource ); - this.oneToManyElement = oneToManyElement; - this.cascadeStyles = Helper.interpretCascadeStyles( cascadeString, bindingContext() ); - } - - @Override - public PluralAttributeElementNature getNature() { - return PluralAttributeElementNature.ONE_TO_MANY; - } - - @Override - public String getReferencedEntityName() { - return StringHelper.isNotEmpty( oneToManyElement.getEntityName() ) - ? oneToManyElement.getEntityName() - : bindingContext().qualifyClassName( oneToManyElement.getClazz() ); - } - - @Override - public boolean isIgnoreNotFound() { - return oneToManyElement.getNotFound() != null && "ignore".equalsIgnoreCase( oneToManyElement.getNotFound().value() ); - } - - @Override - public Set getCascadeStyles() { - return cascadeStyles; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeKeySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeKeySourceImpl.java deleted file mode 100644 index 720c78a971..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeKeySourceImpl.java +++ /dev/null @@ -1,141 +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.source.internal.hbm; - -import java.util.List; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.PluralAttributeKeySource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.relational.TableSpecification; -import org.hibernate.metamodel.spi.relational.Value; - -/** - * @author Steve Ebersole - */ -public class PluralAttributeKeySourceImpl - extends AbstractHbmSourceNode - implements PluralAttributeKeySource { - private final JaxbKeyElement keyElement; - - private final List valueSources; - - public PluralAttributeKeySourceImpl( - MappingDocument mappingDocument, - final JaxbKeyElement keyElement, - final AttributeSourceContainer container) { - super( mappingDocument ); - this.keyElement = keyElement; - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return Helper.getValue( keyElement.isUpdate(), true ); - } - - @Override - public String getColumnAttribute() { - return keyElement.getColumnAttribute(); - } - - @Override - public List getColumn() { - return keyElement.getColumn(); - } - - @Override - public boolean isForceNotNull() { - return Helper.getValue( keyElement.isNotNull(), false ); - } - } - ); - } - - @Override - public String getExplicitForeignKeyName() { - return keyElement.getForeignKey(); - } - - @Override - public boolean createForeignKeyConstraint() { - // TODO: Can HBM do something like JPA's @ForeignKey(NO_CONSTRAINT)? - return true; - } - - @Override - public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { - return keyElement.getPropertyRef() == null - ? null - : new JoinColumnResolutionDelegate() { - @Override - public List getJoinColumns(JoinColumnResolutionContext context) { - return context.resolveRelationalValuesForAttribute( keyElement.getPropertyRef() ); - } - - @Override - public String getReferencedAttributeName() { - return keyElement.getPropertyRef(); - } - - @Override - public TableSpecification getReferencedTable(JoinColumnResolutionContext context) { - return context.resolveTableForAttribute( keyElement.getPropertyRef() ); - } - }; - } - - @Override - public boolean isCascadeDeleteEnabled() { - return "cascade".equals( keyElement.getOnDelete().value() ); - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java deleted file mode 100644 index 3ca71a0be9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeMapKeySourceEmbeddedImpl.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.List; - -import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeIndexElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCompositeMapKeyElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyManyToOneElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbKeyPropertyElement; -import org.hibernate.metamodel.source.spi.EmbeddableSource; -import org.hibernate.metamodel.source.spi.HibernateTypeSource; -import org.hibernate.metamodel.source.spi.PluralAttributeMapKeySourceEmbedded; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.PluralAttributeIndexNature; - -/** - * @author Gail Badner - */ -public class PluralAttributeMapKeySourceEmbeddedImpl - extends AbstractHbmSourceNode - implements PluralAttributeMapKeySourceEmbedded { - - private final AbstractPluralAttributeSourceImpl pluralAttributeSource; - private final EmbeddableSourceImpl embeddableSource; - - - public PluralAttributeMapKeySourceEmbeddedImpl( - MappingDocument mappingDocument, - AbstractPluralAttributeSourceImpl pluralAttributeSource, - final JaxbCompositeIndexElement compositeIndexElement) { - this( - mappingDocument, - pluralAttributeSource, - new AbstractEmbeddableJaxbSource() { - - @Override - public String getClazz() { - return compositeIndexElement.getClazz(); - } - - @Override - public String findParent() { - return null; - } - - @Override - public String findTuplizer() { - return null; - } - - @Override - public List getKeyPropertyElementList() { - return compositeIndexElement.getKeyProperty(); - } - - @Override - public List getKeyManyToOneElementList() { - return compositeIndexElement.getKeyManyToOne(); - } - } - ); - } - - public PluralAttributeMapKeySourceEmbeddedImpl( - MappingDocument mappingDocument, - AbstractPluralAttributeSourceImpl pluralAttributeSource, - final JaxbCompositeMapKeyElement compositeMapKeyElement) { - this( - mappingDocument, - pluralAttributeSource, - - new AbstractEmbeddableJaxbSource() { - - @Override - public String getClazz() { - return compositeMapKeyElement.getClazz(); - } - - @Override - public String findParent() { - return null; - } - - @Override - public String findTuplizer() { - return null; - } - - @Override - public List getKeyPropertyElementList() { - return compositeMapKeyElement.getKeyProperty(); - } - - @Override - public List getKeyManyToOneElementList() { - return compositeMapKeyElement.getKeyManyToOne(); - } - } - ); - } - - private PluralAttributeMapKeySourceEmbeddedImpl( - MappingDocument mappingDocument, - AbstractPluralAttributeSourceImpl pluralAttributeSource, - EmbeddableJaxbSource embeddableJaxbSource) { - super( mappingDocument ); - - this.pluralAttributeSource = pluralAttributeSource; - this.embeddableSource = new EmbeddableSourceImpl( - mappingDocument, - pluralAttributeSource.getAttributeRole().append( "key" ), - pluralAttributeSource.getAttributePath().append( "key" ), - embeddableJaxbSource, - null, - NaturalIdMutability.NOT_NATURAL_ID - ); - } - - @Override - public PluralAttributeIndexNature getNature() { - return PluralAttributeIndexNature.AGGREGATE; - } - - @Override - public EmbeddableSource getEmbeddableSource() { - return embeddableSource; - } - - @Override - public List getDefaultNamingStrategies() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public HibernateTypeSource getTypeInformation() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List relationalValueSources() { - return null; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return false; - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeSequentialIndexSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeSequentialIndexSourceImpl.java deleted file mode 100644 index 177710c37a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PluralAttributeSequentialIndexSourceImpl.java +++ /dev/null @@ -1,173 +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.source.internal.hbm; - -import java.util.Collections; -import java.util.List; - -import org.hibernate.cfg.NamingStrategy; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.internal.binder.Binder; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIndexElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbListIndexElement; -import org.hibernate.metamodel.source.spi.PluralAttributeSequentialIndexSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.spi.PluralAttributeIndexNature; - -/** - * - */ -public class PluralAttributeSequentialIndexSourceImpl - extends AbstractHbmSourceNode - implements PluralAttributeSequentialIndexSource { - private final int base; - private final HibernateTypeSourceImpl typeSource; - private final List valueSources; - - public PluralAttributeSequentialIndexSourceImpl( - MappingDocument sourceMappingDocument, - final JaxbListIndexElement indexElement) { - super( sourceMappingDocument ); - base = Integer.parseInt( indexElement.getBase() ); - typeSource = new HibernateTypeSourceImpl( "integer", bindingContext().typeDescriptor( "int" ) ); - valueSources = Helper.buildValueSources( - sourceMappingDocument, - new Helper.ValueSourcesAdapter() { - List columnElements = indexElement.getColumn() == null - ? Collections.emptyList() - : Collections.singletonList( indexElement.getColumn() ); - - @Override - public String getColumnAttribute() { - return indexElement.getColumnAttribute(); - } - - @Override - public List getColumn() { - return columnElements; - } - - @Override - public boolean isIncludedInInsertByDefault() { - return areValuesIncludedInInsertByDefault(); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return areValuesIncludedInUpdateByDefault(); - } - } - ); - } - - public PluralAttributeSequentialIndexSourceImpl( - MappingDocument sourceMappingDocument, - final JaxbIndexElement indexElement) { - super( sourceMappingDocument ); - base = 0; - typeSource = new HibernateTypeSourceImpl( - StringHelper.isEmpty( indexElement.getType() ) ? "integer" : indexElement.getType(), - bindingContext().typeDescriptor( "int" ) - ); - valueSources = Helper.buildValueSources( - sourceMappingDocument, - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return indexElement.getColumnAttribute(); - } - - @Override - public SizeSource getSizeSource() { - return Helper.createSizeSourceIfMapped( - indexElement.getLength(), - null, - null - ); - } - @Override - public List getColumn() { - return indexElement.getColumn(); - } - - @Override - public boolean isIncludedInInsertByDefault() { - return areValuesIncludedInInsertByDefault(); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return areValuesIncludedInUpdateByDefault(); - } - } - ); - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return false; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - @Override - public int base() { - return base; - } - - @Override - public PluralAttributeIndexNature getNature() { - return PluralAttributeIndexNature.SEQUENTIAL; - } - - @Override - public List getDefaultNamingStrategies() { - final Binder.DefaultNamingStrategy defaultNamingStrategy = new Binder.DefaultNamingStrategy() { - @Override - public String defaultName(NamingStrategy namingStrategy) { - return namingStrategy.columnName( "idx" ); - } - }; - return Collections.singletonList( defaultNamingStrategy ); - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public List< RelationalValueSource > relationalValueSources() { - return valueSources; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java deleted file mode 100644 index 737f33b37f..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/PropertyAttributeSourceImpl.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbPropertyElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; - -/** - * Implementation for {@code } mappings - * - * @author Steve Ebersole - */ -class PropertyAttributeSourceImpl extends AbstractHbmSourceNode implements SingularAttributeSource { - private final JaxbPropertyElement propertyElement; - private final HibernateTypeSourceImpl typeSource; - private final List valueSources; - private final NaturalIdMutability naturalIdMutability; - private final String containingTableName; - - private final AttributeRole attributeRole; - private final AttributePath attributePath; - - PropertyAttributeSourceImpl( - MappingDocument sourceMappingDocument, - AttributeSourceContainer container, - final JaxbPropertyElement propertyElement, - final String logicalTableName, - NaturalIdMutability naturalIdMutability) { - super( sourceMappingDocument ); - this.propertyElement = propertyElement; - - final String name = propertyElement.getTypeAttribute() != null - ? propertyElement.getTypeAttribute() - : propertyElement.getType() != null - ? propertyElement.getType().getName() - : null; - final Map parameters = ( propertyElement.getType() != null ) - ? Helper.extractParameters( propertyElement.getType().getParam() ) - : null; - this.typeSource = new HibernateTypeSourceImpl( name, parameters ); - - this.containingTableName = logicalTableName; - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return propertyElement.getColumnAttribute(); - } - - @Override - public SizeSource getSizeSource() { - // TODO: propertyElement.getPrecision() and getScale() return String, - // but should return int - return Helper.createSizeSourceIfMapped( - propertyElement.getLength(), - propertyElement.getPrecision() == null ? null : Integer.valueOf( propertyElement.getPrecision() ), - propertyElement.getScale() == null ? null : Integer.valueOf( propertyElement.getScale() ) - ); - } - - @Override - public String getFormulaAttribute() { - return propertyElement.getFormulaAttribute(); - } - - @Override - public List getColumn() { - return propertyElement.getColumn(); - } - - @Override - public List getFormula() { - return propertyElement.getFormula(); - } - - @Override - public String getContainingTableName() { - return logicalTableName; - } - - @Override - public boolean isIncludedInInsertByDefault() { - return Helper.getValue( propertyElement.isInsert(), true ); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return Helper.getValue( propertyElement.isUpdate(), true ); - } - } - ); - this.naturalIdMutability = naturalIdMutability; - - this.attributeRole = container.getAttributeRoleBase().append( getName() ); - this.attributePath = container.getAttributePathBase().append( getName() ); - } - - @Override - public String getName() { - return propertyElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return propertyElement.getAccess(); - } - - @Override - public PropertyGeneration getGeneration() { - return PropertyGeneration.parse( propertyElement.getGenerated().value() ); - } - - @Override - public boolean isLazy() { - return Helper.getValue( propertyElement.isLazy(), false ); - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return naturalIdMutability; - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return Helper.getValue( propertyElement.isOptimisticLock(), true ); - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.BASIC; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return Helper.getValue( propertyElement.isInsert(), true ); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return Helper.getValue( propertyElement.isUpdate(), true ); - } - - @Override - public boolean areValuesNullableByDefault() { - return ! Helper.getValue( propertyElement.isNotNull(), false ); - } - - @Override - public String getContainingTableName() { - return containingTableName; - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public Collection getToolingHintSources() { - return propertyElement.getMeta(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ResultSetMappingBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ResultSetMappingBinder.java deleted file mode 100644 index 9bfdd384c1..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ResultSetMappingBinder.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm; - -import org.hibernate.engine.ResultSetMappingDefinition; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryScalarReturn; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbLoadCollectionElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbResultsetElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnJoinElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnScalarElement; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.type.Type; - -public class ResultSetMappingBinder { - public static ResultSetMappingDefinition buildResultSetMappingDefinitions( - final JaxbResultsetElement element, - final LocalBindingContext bindingContext, - final InFlightMetadataCollector metadataCollector) { - final ResultSetMappingDefinition definition = new ResultSetMappingDefinition( element.getName() ); - int cnt = 0; - for ( final JaxbReturnScalarElement r : element.getReturnScalar() ) { - String column = r.getColumn(); - String typeFromXML = r.getType(); - Type type = StringHelper.isNotEmpty( typeFromXML ) ? metadataCollector.getTypeResolver() - .heuristicType( typeFromXML ) : null; - definition.addQueryReturn( new NativeSQLQueryScalarReturn( column, type ) ); - } - for ( final JaxbReturnElement r : element.getReturn() ) { - definition.addQueryReturn( new ReturnBinder( r, cnt++, bindingContext, metadataCollector ).process() ); - } - for ( final JaxbReturnJoinElement r : element.getReturnJoin() ) { - definition.addQueryReturn( new ReturnJoinBinder( r, cnt++, bindingContext, metadataCollector ).process() ); - } - for ( final JaxbLoadCollectionElement r : element.getLoadCollection() ) { - definition.addQueryReturn( new LoadCollectionBinder( r, cnt++, bindingContext, metadataCollector ).process() ); - } - - return definition; - } -} \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnBinder.java deleted file mode 100644 index 472ab152c4..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnBinder.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnPropertyElement; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.LocalBindingContext; -import org.hibernate.metamodel.spi.binding.EntityBinding; - -/** - * @author Strong Liu - */ -class ReturnBinder extends AbstractReturnBinder { - ReturnBinder( - final JaxbReturnElement element, - final int elementIndex, - final LocalBindingContext context, - final InFlightMetadataCollector metadataCollector) { - super( element, elementIndex, context, metadataCollector ); - } - - @Override - NativeSQLQueryReturn process() { - final String clazz = element.getClazz(); - String entityName = element.getEntityName(); - if ( StringHelper.isEmpty( clazz ) && StringHelper.isEmpty( entityName ) ) { - throw context.makeMappingException( - " must specify either a class or entity-name" - ); - } - entityName = StringHelper.isNotEmpty( entityName ) ? entityName : context.qualifyClassName( clazz ); - final EntityBinding entityBinding = metadataCollector.getEntityBinding( entityName ); - // TODO throw exception here?? - // if ( entityBinding == null ) { - // throw bindingContext.makeMappingException( "Can't locate entitybinding" ); - // } - - final Map propertyResults = new HashMap(); - bindDiscriminatorColumn( propertyResults ); - processReturnProperties( new ReturnPropertiesCallbackImpl2( alias, propertyResults, context ) ); - - return new NativeSQLQueryRootReturn( - alias, entityName, propertyResults, lockMode - ); - } - - - private void bindDiscriminatorColumn(final Map propertyResults) { - final JaxbReturnElement.JaxbReturnDiscriminator discriminator = element.getReturnDiscriminator(); - if ( discriminator != null && StringHelper.isNotEmpty( discriminator.getColumn() ) ) { - String discriminatorColumn = StringHelper.unquote( discriminator.getColumn() ); - propertyResults.put( "class", new String[] { discriminatorColumn } ); - } - } - - private static class ReturnPropertiesCallbackImpl2 implements ReturnPropertiesCallback { - private final LocalBindingContext bindingContext; - private final String alias; - private final Map propertyResults; - - private ReturnPropertiesCallbackImpl2( - final String alias, final Map propertyResults, - final LocalBindingContext bindingContext) { - this.alias = alias; - this.bindingContext = bindingContext; - this.propertyResults = propertyResults; - } - - @Override - public void process(final JaxbReturnPropertyElement propertyElement) { - final String name = propertyElement.getName(); - if ( "class".equals( name ) ) { - throw bindingContext.makeMappingException( - "class is not a valid property name to use in a , use instead" - ); - } - if ( propertyResults.containsKey( name ) ) { - throw bindingContext.makeMappingException( - "duplicate return-property for property " + name + " on alias " + alias - ); - } - final List returnColumnNames = getResultColumns( propertyElement, bindingContext ); - - if ( returnColumnNames.isEmpty() ) { - throw bindingContext.makeMappingException( - "return-property for alias " + alias + " must specify at least one column or return-column name" - ); - } - - propertyResults.put( name, returnColumnNames.toArray( new String[returnColumnNames.size()] ) ); - } - - private static List getResultColumns( - final JaxbReturnPropertyElement propertyresult, final LocalBindingContext context) { - List allResultColumns = new ArrayList(); - if ( propertyresult.getColumn() != null ) { - String column = context.getMetadataCollector() - .getObjectNameNormalizer() - .normalizeIdentifierQuoting( propertyresult.getColumn() ); - allResultColumns.add( column ); - } - for ( JaxbReturnPropertyElement.JaxbReturnColumn returnColumn : propertyresult.getReturnColumn() ) { - if ( returnColumn.getName() != null ) { - String column = context.getMetadataCollector() - .getObjectNameNormalizer() - .normalizeIdentifierQuoting( returnColumn.getName() ); - - allResultColumns.add( column ); - } - } - return allResultColumns; - } - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnJoinBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnJoinBinder.java deleted file mode 100644 index fc5cc57d18..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/ReturnJoinBinder.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.HashMap; -import java.util.Map; - -import org.hibernate.engine.query.spi.sql.NativeSQLQueryJoinReturn; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnJoinElement; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.LocalBindingContext; - -/** - * @author Strong Liu - */ -class ReturnJoinBinder extends AbstractReturnBinder { - ReturnJoinBinder( - final JaxbReturnJoinElement element, - final int elementIndex, - final LocalBindingContext context, - final InFlightMetadataCollector metadataCollector) { - super( element, elementIndex, context, metadataCollector ); - } - - @Override - NativeSQLQueryReturn process() { - final String roleAttribute = element.getProperty(); - int dot = roleAttribute.lastIndexOf( '.' ); - if ( dot == -1 ) { - throw context.makeMappingException( - "Role attribute for sql query return " + "[alias=" + alias + "] not formatted correctly " + "{owningAlias.propertyName}" - ); - } - final String roleOwnerAlias = roleAttribute.substring( 0, dot ); - final String roleProperty = roleAttribute.substring( dot + 1 ); - final Map propertyResults = new HashMap(); - processReturnProperties( new ReturnPropertiesCallbackImpl( alias, propertyResults, context ) ); - return new NativeSQLQueryJoinReturn( - alias, roleOwnerAlias, roleProperty, propertyResults, lockMode - ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java deleted file mode 100644 index b39f699a73..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/RootEntitySourceImpl.java +++ /dev/null @@ -1,90 +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.source.internal.hbm; - -import java.util.List; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbClassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbNaturalIdElement; -import org.hibernate.metamodel.source.spi.AttributeSource; -import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; -import org.hibernate.metamodel.source.spi.TableSpecificationSource; -import org.hibernate.metamodel.spi.NaturalIdMutability; - -/** - * @author Steve Ebersole - * @author Gail Badner - */ -public class RootEntitySourceImpl extends AbstractEntitySourceImpl { - private final TableSpecificationSource primaryTable; - - protected RootEntitySourceImpl( - MappingDocument sourceMappingDocument, - JaxbClassElement entityElement) { - super( sourceMappingDocument, entityElement ); - this.primaryTable = Helper.createTableSource( sourceMappingDocument(), entityElement, this ); - afterInstantiation(); - } - - @Override - protected List buildAttributeSources(List attributeSources) { - final JaxbNaturalIdElement naturalId = entityElement().getNaturalId(); - if ( naturalId != null ) { - final NaturalIdMutability naturalIdMutability = naturalId.isMutable() - ? NaturalIdMutability.MUTABLE - : NaturalIdMutability.IMMUTABLE; - processPropertyAttributes( attributeSources, naturalId.getProperty(), null, naturalIdMutability ); - processManyToOneAttributes( attributeSources, naturalId.getManyToOne(), null, naturalIdMutability ); - processComponentAttributes( attributeSources, naturalId.getComponent(), null, naturalIdMutability ); - processDynamicComponentAttributes( - attributeSources, - naturalId.getDynamicComponent(), - null, - naturalIdMutability - ); - processAnyAttributes( attributeSources, naturalId.getAny(), null, naturalIdMutability ); - } - return super.buildAttributeSources( attributeSources ); - } - - @Override - protected JaxbClassElement entityElement() { - return (JaxbClassElement) super.entityElement(); - } - - @Override - public TableSpecificationSource getPrimaryTable() { - return primaryTable; - } - - @Override - public String getDiscriminatorMatchValue() { - return entityElement().getDiscriminatorValue(); - } - - @Override - public IdentifiableTypeSource getSuperType() { - return null; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SecondaryTableSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SecondaryTableSourceImpl.java deleted file mode 100644 index 05de26066f..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SecondaryTableSourceImpl.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.engine.FetchStyle; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFetchStyleAttribute; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbJoinElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbOnDeleteAttribute; -import org.hibernate.metamodel.source.spi.ColumnSource; -import org.hibernate.metamodel.source.spi.InLineViewSource; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SecondaryTableSource; -import org.hibernate.metamodel.source.spi.TableSource; -import org.hibernate.metamodel.source.spi.TableSpecificationSource; -import org.hibernate.metamodel.spi.binding.CustomSQL; -import org.hibernate.metamodel.spi.relational.TableSpecification; -import org.hibernate.metamodel.spi.relational.Value; - -/** - * @author Steve Ebersole - */ -class SecondaryTableSourceImpl extends AbstractHbmSourceNode implements SecondaryTableSource { - private final JaxbJoinElement joinElement; - private final TableSpecificationSource joinTable; - private final List columnSources; - private final JoinColumnResolutionDelegate fkJoinColumnResolutionDelegate; - - @SuppressWarnings("unchecked") - public SecondaryTableSourceImpl( - MappingDocument sourceMappingDocument, - final JaxbJoinElement joinElement, - Helper.InLineViewNameInferrer inLineViewNameInferrer) { - super( sourceMappingDocument ); - this.joinElement = joinElement; - this.joinTable = Helper.createTableSource( sourceMappingDocument(), joinElement, inLineViewNameInferrer ); - - // the cast is ok here because the adapter should never be returning formulas since the schema does not allow it - this.columnSources = extractColumnSources(); - - fkJoinColumnResolutionDelegate = joinElement.getKey().getPropertyRef() == null - ? null - : new JoinColumnResolutionDelegateImpl( joinElement ); - } - - private List extractColumnSources() { - final List columnSources = new ArrayList(); - final List valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getContainingTableName() { - return joinElement.getTable(); - } - - @Override - public String getColumnAttribute() { - return joinElement.getKey().getColumnAttribute(); - } - - @Override - public List getColumn() { - return joinElement.getKey().getColumn(); - } - - @Override - public boolean isForceNotNull() { - return true; - } - } - ); - for ( RelationalValueSource valueSource : valueSources ) { - columnSources.add( (ColumnSource) valueSource ); - } - return columnSources; - } - - @Override - public TableSpecificationSource getTableSource() { - return joinTable; - } - - @Override - public List getPrimaryKeyColumnSources() { - return columnSources; - } - - @Override - public String getComment() { - return joinElement.getComment(); - } - - @Override - public FetchStyle getFetchStyle() { - return joinElement.getFetch() == JaxbFetchStyleAttribute.JOIN ? - FetchStyle.JOIN : - FetchStyle.SELECT; - } - - @Override - public boolean isInverse() { - return joinElement.isInverse(); - } - - @Override - public boolean isOptional() { - return joinElement.isOptional(); - } - - @Override - public boolean isCascadeDeleteEnabled() { - return joinElement.getKey().getOnDelete() == JaxbOnDeleteAttribute.CASCADE; - } - - @Override - public String getExplicitForeignKeyName() { - return joinElement.getKey().getForeignKey(); - } - - @Override - public boolean createForeignKeyConstraint() { - // TODO: Can HBM do something like JPA's @ForeignKey(NO_CONSTRAINT)? - return true; - } - - @Override - public JoinColumnResolutionDelegate getForeignKeyTargetColumnResolutionDelegate() { - return fkJoinColumnResolutionDelegate; - } - - @Override - public CustomSQL getCustomSqlInsert() { - return Helper.buildCustomSql( joinElement.getSqlInsert() ); - } - - @Override - public CustomSQL getCustomSqlUpdate() { - return Helper.buildCustomSql( joinElement.getSqlUpdate() ); - } - - @Override - public CustomSQL getCustomSqlDelete() { - return Helper.buildCustomSql( joinElement.getSqlDelete() ); - } - - - public String getLogicalTableNameForContainedColumns() { - return TableSource.class.isInstance( joinTable ) - ? ( (TableSource) joinTable ).getExplicitTableName() - : ( (InLineViewSource) joinTable ).getLogicalName(); - } - - private static class JoinColumnResolutionDelegateImpl implements JoinColumnResolutionDelegate { - private final JaxbJoinElement joinElement; - - public JoinColumnResolutionDelegateImpl(JaxbJoinElement joinElement) { - this.joinElement = joinElement; - } - - @Override - public List getJoinColumns(JoinColumnResolutionContext context) { - return context.resolveRelationalValuesForAttribute( getReferencedAttributeName() ); - } - - @Override - public String getReferencedAttributeName() { - return joinElement.getKey().getPropertyRef(); - } - - @Override - public TableSpecification getReferencedTable(JoinColumnResolutionContext context) { - return context.resolveTableForAttribute( joinElement.getKey().getPropertyRef() ); - } - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java deleted file mode 100644 index ac33fcfd20..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SetSourceImpl.java +++ /dev/null @@ -1,75 +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.source.internal.hbm; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSetElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.Orderable; -import org.hibernate.metamodel.source.spi.Sortable; -import org.hibernate.metamodel.spi.PluralAttributeNature; - -/** - * @author Steve Ebersole - */ -public class SetSourceImpl extends AbstractPluralAttributeSourceImpl implements Orderable, Sortable { - public SetSourceImpl( - MappingDocument sourceMappingDocument, - JaxbSetElement setElement, - AttributeSourceContainer container) { - super( sourceMappingDocument, setElement, container ); - } - - @Override - public JaxbSetElement getPluralAttributeElement() { - return (JaxbSetElement) super.getPluralAttributeElement(); - } - - @Override - public PluralAttributeNature getNature() { - return PluralAttributeNature.SET; - } - - @Override - public boolean isSorted() { - String comparatorName = getComparatorName(); - return StringHelper.isNotEmpty( comparatorName ) - && !comparatorName.equals("unsorted"); - } - - @Override - public String getComparatorName() { - return getPluralAttributeElement().getSort(); - } - - @Override - public boolean isOrdered() { - return StringHelper.isNotEmpty( getOrder() ); - } - - @Override - public String getOrder() { - return getPluralAttributeElement().getOrderBy(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java deleted file mode 100644 index e56b8de7b9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SingularIdentifierAttributeSourceImpl.java +++ /dev/null @@ -1,205 +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.source.internal.hbm; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbIdElement; -import org.hibernate.metamodel.source.spi.AttributeSourceContainer; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.SingularAttributeSource; -import org.hibernate.metamodel.source.spi.SizeSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; - -/** - * Implementation for {@code } mappings - * - * @author Steve Ebersole - */ -class SingularIdentifierAttributeSourceImpl - extends AbstractHbmSourceNode - implements SingularAttributeSource { - - private final JaxbIdElement idElement; - private final HibernateTypeSourceImpl typeSource; - private final List valueSources; - - private final AttributeRole attributeRole; - private final AttributePath attributePath; - - public SingularIdentifierAttributeSourceImpl( - MappingDocument mappingDocument, - AttributeSourceContainer container, - final JaxbIdElement idElement) { - super( mappingDocument ); - this.idElement = idElement; - - final String name = idElement.getTypeAttribute() != null - ? idElement.getTypeAttribute() - : idElement.getType() != null - ? idElement.getType().getName() - : null; - final Map parameters = ( idElement.getType() != null ) - ? Helper.extractParameters( idElement.getType().getParam() ) - : null; - this.typeSource = new HibernateTypeSourceImpl( name, parameters ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return idElement.getColumnAttribute(); - } - - @Override - public SizeSource getSizeSource() { - return Helper.createSizeSourceIfMapped( - idElement.getLength(), - null, - null - ); - } - - @Override - public List getColumn() { - return idElement.getColumn(); - } - - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isForceNotNull() { - return true; - } - } - ); - - this.attributeRole = container.getAttributeRoleBase().append( getName() ); - this.attributePath = container.getAttributePathBase().append( getName() ); - } - - @Override - public String getName() { - return idElement.getName() == null - ? "id" - : idElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return idElement.getAccess(); - } - - @Override - public PropertyGeneration getGeneration() { - return PropertyGeneration.INSERT; - } - - @Override - public boolean isLazy() { - return false; - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return NaturalIdMutability.NOT_NATURAL_ID; - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return false; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.BASIC; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return false; - } - - @Override - public boolean areValuesNullableByDefault() { - return false; - } - - @Override - public String getContainingTableName() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public Collection getToolingHintSources() { - return idElement.getMeta(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SizeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SizeSourceImpl.java deleted file mode 100644 index 93073af751..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SizeSourceImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2013, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import org.hibernate.metamodel.source.spi.SizeSource; - -/** - * @author Gail Badner - */ -public class SizeSourceImpl implements SizeSource { - - private final Integer length; - private final Integer precision; - private final Integer scale; - - public SizeSourceImpl(Integer precision, Integer scale, Integer length) { - this.precision = precision; - this.scale = scale; - this.length = length; - } - - public boolean isLengthDefined() { - return length != null; - } - - public int getLength() { - if ( length == null ) { - throw new UnsupportedOperationException( "length is undefined." ); - } - return length; - } - - public boolean isPrecisionDefined() { - return precision != null; - } - - public int getPrecision() { - if ( precision == null ) { - throw new UnsupportedOperationException( "precision is undefined." ); - } - return precision; - } - - public boolean isScaleDefined() { - return scale != null; - } - - public int getScale() { - if ( scale == null ) { - throw new UnsupportedOperationException( "scale is undefined." ); - } - return scale; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SubclassEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SubclassEntitySourceImpl.java deleted file mode 100644 index a3903c3442..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/SubclassEntitySourceImpl.java +++ /dev/null @@ -1,70 +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.source.internal.hbm; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.EntityElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSubclassElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.TableInformationSource; -import org.hibernate.metamodel.source.spi.EntitySource; -import org.hibernate.metamodel.source.spi.IdentifiableTypeSource; -import org.hibernate.metamodel.source.spi.SubclassEntitySource; -import org.hibernate.metamodel.source.spi.TableSpecificationSource; - -/** - * @author Steve Ebersole - */ -public class SubclassEntitySourceImpl extends AbstractEntitySourceImpl implements SubclassEntitySource { - private final EntitySource container; - private final TableSpecificationSource primaryTable; - protected SubclassEntitySourceImpl( - MappingDocument sourceMappingDocument, - EntityElement entityElement, - EntitySource container) { - super( sourceMappingDocument, entityElement ); - this.container = container; - this.primaryTable = TableInformationSource.class.isInstance( entityElement ) - ? Helper.createTableSource( sourceMappingDocument(), (TableInformationSource) entityElement, this ) - : null; - - - afterInstantiation(); - } - - @Override - public TableSpecificationSource getPrimaryTable() { - return primaryTable; - } - - @Override - public String getDiscriminatorMatchValue() { - return JaxbSubclassElement.class.isInstance( entityElement() ) - ? ( (JaxbSubclassElement) entityElement() ).getDiscriminatorValue() - : null; - } - - @Override - public IdentifiableTypeSource getSuperType() { - return container; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TableSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TableSourceImpl.java deleted file mode 100644 index f698415836..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TableSourceImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import org.hibernate.metamodel.source.spi.TableSource; - -/** - * @author Steve Ebersole - */ -public class TableSourceImpl - extends AbstractHbmSourceNode - implements TableSource { - private final String schema; - private final String catalog; - private final String tableName; - private final String rowId; - - TableSourceImpl( - MappingDocument mappingDocument, - String schema, - String catalog, - String tableName) { - this( mappingDocument, schema, catalog, tableName, null ); - } - - TableSourceImpl( - MappingDocument mappingDocument, - String schema, - String catalog, - String tableName, - String rowId) { - super( mappingDocument ); - this.schema = schema; - this.catalog = catalog; - this.tableName = tableName; - this.rowId = rowId; - } - - @Override - public String getExplicitSchemaName() { - return schema; - } - - @Override - public String getExplicitCatalogName() { - return catalog; - } - - @Override - public String getExplicitTableName() { - return tableName; - } - - @Override - public String getRowId() { - return rowId; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java deleted file mode 100644 index 1a8204ef68..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TimestampAttributeSourceImpl.java +++ /dev/null @@ -1,201 +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.source.internal.hbm; - -import java.util.Collection; -import java.util.List; - -import org.hibernate.internal.util.ValueHolder; -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTimestampElement; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.source.spi.VersionAttributeSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; - -/** - * Implementation for {@code } mappings - * - * @author Steve Ebersole - */ -class TimestampAttributeSourceImpl - extends AbstractHbmSourceNode - implements VersionAttributeSource { - private final JaxbTimestampElement timestampElement; - private final HibernateTypeSourceImpl typeSource; - - private final List valueSources; - - private final AttributePath attributePath; - private final AttributeRole attributeRole; - - TimestampAttributeSourceImpl( - MappingDocument mappingDocument, - RootEntitySourceImpl rootEntitySource, - final JaxbTimestampElement timestampElement) { - super( mappingDocument ); - this.timestampElement = timestampElement; - - this.typeSource = new HibernateTypeSourceImpl( - "db".equals( timestampElement.getSource().value() ) - ? "dbtimestamp" - : "timestamp" - ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return timestampElement.getColumnAttribute(); - } - @Override - public boolean isIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return true; - } - } - ); - - this.attributePath = rootEntitySource.getAttributePathBase().append( getName() ); - this.attributeRole = rootEntitySource.getAttributeRoleBase().append( getName() ); - } - - @Override - public String getName() { - return timestampElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return timestampElement.getAccess(); - } - - private ValueHolder propertyGenerationValue = new ValueHolder( - new ValueHolder.DeferredInitializer() { - @Override - public PropertyGeneration initialize() { - final PropertyGeneration propertyGeneration = timestampElement.getGenerated() == null - ? PropertyGeneration.NEVER - : PropertyGeneration.parse( timestampElement.getGenerated().value() ); - if ( propertyGeneration == PropertyGeneration.INSERT ) { - throw makeMappingException( "'generated' attribute cannot be 'insert' for versioning property" ); - } - return propertyGeneration; - } - } - ); - - @Override - public PropertyGeneration getGeneration() { - return propertyGenerationValue.getValue(); - } - - @Override - public boolean isLazy() { - return false; - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return NaturalIdMutability.NOT_NATURAL_ID; - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return false; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.BASIC; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return true; - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } - - @Override - public String getContainingTableName() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public Collection getToolingHintSources() { - return timestampElement.getMeta(); - } - - @Override - public String getUnsavedValue() { - return timestampElement.getUnsavedValue().value(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TypeDescriptorSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TypeDescriptorSourceImpl.java deleted file mode 100644 index 68a5fc0055..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/TypeDescriptorSourceImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * Copyright (c) 2012, Red Hat Inc. or third-party contributors as - * indicated by the @author tags or express copyright attribution - * statements applied by the authors. All third-party contributions are - * distributed under license by Red Hat Inc. - * - * This copyrighted material is made available to anyone wishing to use, modify, - * copy, or redistribute it subject to the terms and conditions of the GNU - * Lesser General Public License, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this distribution; if not, write to: - * Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301 USA - */ -package org.hibernate.metamodel.source.internal.hbm; - -import java.util.Map; - -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbTypedefElement; -import org.hibernate.metamodel.source.spi.TypeDescriptorSource; - -/** - * @author Steve Ebersole - */ -public class TypeDescriptorSourceImpl implements TypeDescriptorSource { - private static final String[] NO_REGISTRATION_KEYS = new String[0]; - - private final String name; - private final String implementationClassName; - private final Map params; - - public TypeDescriptorSourceImpl(JaxbTypedefElement typeDefElement) { - this.name = typeDefElement.getName(); - this.implementationClassName = typeDefElement.getClazz(); - this.params = Helper.extractParameters( typeDefElement.getParam() ); - } - - @Override - public String getName() { - return name; - } - - @Override - public String getTypeImplementationClassName() { - return implementationClassName; - } - - @Override - public String[] getRegistrationKeys() { - return NO_REGISTRATION_KEYS; - } - - @Override - public Map getParameters() { - return params; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/UniqueConstraintSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/UniqueConstraintSourceImpl.java deleted file mode 100644 index c9e1da8f45..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/UniqueConstraintSourceImpl.java +++ /dev/null @@ -1,58 +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.source.internal.hbm; - -import java.util.List; - -import org.hibernate.metamodel.source.spi.UniqueConstraintSource; - -/** - * @author Hardy Ferentschik - */ -class UniqueConstraintSourceImpl extends AbstractConstraintSource implements UniqueConstraintSource { - - public UniqueConstraintSourceImpl(String name, String tableName, List columnNames, List orderings) { -// super( name, tableName, columnNames, orderings ); - super( name, tableName ); - } - - public UniqueConstraintSourceImpl(String name, String tableName, List columnNames) { -// super( name, tableName, columnNames, Collections.EMPTY_LIST ); - super( name, tableName ); - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append( "UniqueConstraintSourceImpl" ); - sb.append( "{name='" ).append( name ).append( '\'' ); - sb.append( ", tableName='" ).append( tableName ).append( '\'' ); - sb.append( ", columnNames=" ).append( columnNames ); - sb.append( ", orderings=" ).append( orderings ); - sb.append( '}' ); - return sb.toString(); - } -} - - diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java deleted file mode 100644 index 480eb4347c..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/VersionAttributeSourceImpl.java +++ /dev/null @@ -1,208 +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.source.internal.hbm; - -import java.util.Collection; -import java.util.List; - -import org.hibernate.internal.util.ValueHolder; -import org.hibernate.mapping.PropertyGeneration; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbColumnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbVersionElement; -import org.hibernate.metamodel.source.spi.RelationalValueSource; -import org.hibernate.metamodel.source.spi.ToolingHintSource; -import org.hibernate.metamodel.source.spi.VersionAttributeSource; -import org.hibernate.metamodel.spi.AttributePath; -import org.hibernate.metamodel.spi.AttributeRole; -import org.hibernate.metamodel.spi.NaturalIdMutability; -import org.hibernate.metamodel.spi.SingularAttributeNature; - - -/** - * Implementation for {@code } mappings - * - * @author Steve Ebersole - */ -class VersionAttributeSourceImpl - extends AbstractHbmSourceNode - implements VersionAttributeSource { - private final JaxbVersionElement versionElement; - private final HibernateTypeSourceImpl typeSource; - - private final List valueSources; - - private final AttributePath attributePath; - private final AttributeRole attributeRole; - - VersionAttributeSourceImpl( - MappingDocument mappingDocument, - RootEntitySourceImpl rootEntitySource, - final JaxbVersionElement versionElement) { - super( mappingDocument ); - this.versionElement = versionElement; - - this.typeSource = new HibernateTypeSourceImpl( - versionElement.getType() == null - ? "integer" - : versionElement.getType() - ); - - this.valueSources = Helper.buildValueSources( - sourceMappingDocument(), - new Helper.ValueSourcesAdapter() { - @Override - public String getColumnAttribute() { - return versionElement.getColumnAttribute(); - } - @Override - public List getColumn() { - return versionElement.getColumn(); - } - - @Override - public boolean isIncludedInInsertByDefault() { - return Helper.getValue( versionElement.isInsert(), true ); - } - - @Override - public boolean isIncludedInUpdateByDefault() { - return true; - } - } - ); - - this.attributePath = rootEntitySource.getAttributePathBase().append( getName() ); - this.attributeRole = rootEntitySource.getAttributeRoleBase().append( getName() ); - } - - - @Override - public String getUnsavedValue() { - return versionElement.getUnsavedValue().value(); - } - - @Override - public String getName() { - return versionElement.getName(); - } - - @Override - public AttributePath getAttributePath() { - return attributePath; - } - - @Override - public AttributeRole getAttributeRole() { - return attributeRole; - } - - @Override - public HibernateTypeSourceImpl getTypeInformation() { - return typeSource; - } - - @Override - public String getPropertyAccessorName() { - return versionElement.getAccess(); - } - - private ValueHolder propertyGenerationValue = new ValueHolder( - new ValueHolder.DeferredInitializer() { - @Override - public PropertyGeneration initialize() { - final PropertyGeneration propertyGeneration = versionElement.getGenerated() == null - ? PropertyGeneration.NEVER - : PropertyGeneration.parse( versionElement.getGenerated().value() ); - if ( propertyGeneration == PropertyGeneration.INSERT ) { - throw makeMappingException( "'generated' attribute cannot be 'insert' for versioning property" ); - } - return propertyGeneration; - } - } - ); - @Override - public PropertyGeneration getGeneration() { - return propertyGenerationValue.getValue(); - } - - @Override - public boolean isLazy() { - return false; - } - - @Override - public NaturalIdMutability getNaturalIdMutability() { - return NaturalIdMutability.NOT_NATURAL_ID; - } - - @Override - public boolean isIncludedInOptimisticLocking() { - return false; - } - - @Override - public SingularAttributeNature getSingularAttributeNature() { - return SingularAttributeNature.BASIC; - } - - @Override - public boolean isVirtualAttribute() { - return false; - } - - @Override - public boolean areValuesIncludedInInsertByDefault() { - return Helper.getValue( versionElement.isInsert(), true ); - } - - @Override - public boolean areValuesIncludedInUpdateByDefault() { - return true; - } - - @Override - public boolean areValuesNullableByDefault() { - return true; - } - - @Override - public String getContainingTableName() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List relationalValueSources() { - return valueSources; - } - - @Override - public boolean isSingular() { - return true; - } - - @Override - public Collection getToolingHintSources() { - return versionElement.getMeta(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/AbstractQueryElementContentsParser.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/AbstractQueryElementContentsParser.java deleted file mode 100644 index c34e92681f..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/AbstractQueryElementContentsParser.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm.parser; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.CacheMode; -import org.hibernate.FlushMode; -import org.hibernate.MappingException; -import org.hibernate.engine.spi.NamedQueryDefinitionBuilder; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbCacheModeAttribute; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbFlushModeAttribute; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbQueryElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbQueryParamElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSqlQueryElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.QuerySourceElement; - -/** - * @author Brett Meyer - */ -abstract class AbstractQueryElementContentsParser { - - // TODO: Hate the use of QuerySourceElement -- remove/refactor. - - public void parse( NamedQueryDefinitionBuilder builder, - final JaxbQueryElement queryElement ) { - - QuerySourceElement element = new QuerySourceElement() { - @Override - public List getContent() { - return queryElement.getContent(); - } - - @Override - public JaxbCacheModeAttribute getCacheMode() { - return queryElement.getCacheMode(); - } - - @Override - public String getCacheRegion() { - return queryElement.getCacheRegion(); - } - - @Override - public boolean isCacheable() { - return queryElement.isCacheable(); - } - - @Override - public String getComment() { - return queryElement.getComment(); - } - - @Override - public Integer getFetchSize() { - return queryElement.getFetchSize(); - } - - @Override - public JaxbFlushModeAttribute getFlushMode() { - return queryElement.getFlushMode(); - } - - @Override - public String getName() { - return queryElement.getName(); - } - - @Override - public boolean isReadOnly() { - return queryElement.isReadOnly(); - } - - @Override - public Integer getTimeout() { - return queryElement.getTimeout(); - } - }; - - parse( builder, element ); - } - - public void parse( NamedQueryDefinitionBuilder builder, - final JaxbSqlQueryElement queryElement ) { - - QuerySourceElement element = new QuerySourceElement() { - @Override - public List getContent() { - return queryElement.getContent(); - } - - @Override - public JaxbCacheModeAttribute getCacheMode() { - return queryElement.getCacheMode(); - } - - @Override - public String getCacheRegion() { - return queryElement.getCacheRegion(); - } - - @Override - public boolean isCacheable() { - return queryElement.isCacheable(); - } - - @Override - public String getComment() { - return queryElement.getComment(); - } - - @Override - public Integer getFetchSize() { - return queryElement.getFetchSize(); - } - - @Override - public JaxbFlushModeAttribute getFlushMode() { - return queryElement.getFlushMode(); - } - - @Override - public String getName() { - return queryElement.getName(); - } - - @Override - public boolean isReadOnly() { - return queryElement.isReadOnly(); - } - - @Override - public Integer getTimeout() { - return queryElement.getTimeout(); - } - }; - - parse( builder, element ); - } - - private void parse( NamedQueryDefinitionBuilder builder, - QuerySourceElement queryElement ) { - final String queryName = queryElement.getName(); - final boolean cacheable = queryElement.isCacheable(); - final String region = queryElement.getCacheRegion(); - final Integer timeout = queryElement.getTimeout(); - final Integer fetchSize = queryElement.getFetchSize(); - final boolean readonly = queryElement.isReadOnly(); - final String comment = queryElement.getComment(); - final CacheMode cacheMode = queryElement.getCacheMode() == null - ? null : CacheMode.valueOf( queryElement - .getCacheMode().value().toUpperCase() ); - final FlushMode flushMode = queryElement.getFlushMode() == null - ? null : FlushMode.valueOf( queryElement - .getFlushMode().value().toUpperCase() ); - - builder.setName( queryName ).setCacheable( cacheable ) - .setCacheRegion( region ).setTimeout( timeout ) - .setFetchSize( fetchSize ).setFlushMode( flushMode ) - .setCacheMode( cacheMode ).setReadOnly( readonly ) - .setComment( comment ); - - final List list = queryElement.getContent(); - parse( queryName, list, builder ); - } - - private void parse(String queryName, List contents, - NamedQueryDefinitionBuilder builder) { - final Map queryParam = new HashMap(); - String query = ""; - boolean isQueryDefined = false; - for ( Serializable obj : contents ) { - if ( obj == null ) { - continue; - } - else if ( JaxbQueryParamElement.class.isInstance( obj ) ) { - JaxbQueryParamElement element - = JaxbQueryParamElement.class.cast( obj ); - queryParam.put( element.getName(), element.getType() ); - } - else if ( String.class.isInstance( obj ) ) { - if ( !isQueryDefined ) { - if ( StringHelper.isNotEmpty( obj.toString().trim() ) ) { - query = obj.toString().trim(); - isQueryDefined = true; - } - - } - else { - throw new MappingException( - "Duplicate query string is defined in Named query[+" - + queryName + "]" ); - } - } - parseExtra( queryName, obj, builder ); - } - builder.setParameterTypes( queryParam ); - if ( StringHelper.isEmpty( query ) ) { - throw new MappingException( - "Named query[" + queryName+ "] has no query string defined"); - } - builder.setQuery( query ); - } - - protected abstract void parseExtra(String queryName, Serializable obj, NamedQueryDefinitionBuilder builder); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/BasicQueryElementContentParser.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/BasicQueryElementContentParser.java deleted file mode 100644 index 5d9714fd4d..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/BasicQueryElementContentParser.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm.parser; - -import java.io.Serializable; - -import org.hibernate.engine.spi.NamedQueryDefinitionBuilder; - -/** - * @author Brett Meyer - */ -public class BasicQueryElementContentParser extends AbstractQueryElementContentsParser { - - @Override - protected void parseExtra(String queryName, Serializable obj, - NamedQueryDefinitionBuilder builder) { - // do nothing - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/SQLQueryElementContentParser.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/SQLQueryElementContentParser.java deleted file mode 100644 index cc8b531b4b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/hbm/parser/SQLQueryElementContentParser.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * JBoss, Home of Professional Open Source - * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * 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, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * 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, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ -package org.hibernate.metamodel.source.internal.hbm.parser; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import javax.xml.bind.JAXBElement; - -import org.hibernate.engine.ResultSetMappingDefinition; -import org.hibernate.engine.spi.NamedQueryDefinitionBuilder; -import org.hibernate.engine.spi.NamedSQLQueryDefinition; -import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder; -import org.hibernate.metamodel.source.internal.hbm.ResultSetMappingBinder; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbLoadCollectionElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbResultsetElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnJoinElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbReturnScalarElement; -import org.hibernate.metamodel.source.internal.jaxb.hbm.JaxbSynchronizeElement; -import org.hibernate.metamodel.spi.InFlightMetadataCollector; -import org.hibernate.metamodel.spi.LocalBindingContext; - -/** - * @author Brett Meyer - * @author String Liu - */ -public class SQLQueryElementContentParser extends AbstractQueryElementContentsParser { - private final List synchronizedTables = new ArrayList(); - private final List loadCollectionElements = new ArrayList(); - private final List returnScalarElements = new ArrayList(); - private final List returnElements = new ArrayList(); - private final List returnJoinElements = new ArrayList(); - - @Override - protected void parseExtra( String queryName, Serializable obj, - NamedQueryDefinitionBuilder builder ) { - if ( !JAXBElement.class.isInstance( obj ) ) { - return; - } - JAXBElement jaxbElement = JAXBElement.class.cast( obj ); - Class targetType = jaxbElement.getDeclaredType(); - Object value = jaxbElement.getValue(); - if ( JaxbSynchronizeElement.class == targetType ) { - JaxbSynchronizeElement element = JaxbSynchronizeElement.class.cast( value ); - synchronizedTables.add( element.getTable() ); - } - else if ( JaxbLoadCollectionElement.class == targetType ) { - loadCollectionElements.add( JaxbLoadCollectionElement.class.cast( value ) ); - } - else if ( JaxbReturnScalarElement.class == targetType ) { - returnScalarElements.add( JaxbReturnScalarElement.class.cast( value ) ); - } - else if ( JaxbReturnElement.class == targetType ) { - returnElements.add( JaxbReturnElement.class.cast( value ) ); - } - else if ( JaxbReturnJoinElement.class == targetType ) { - returnJoinElements.add( JaxbReturnJoinElement.class.cast( value ) ); - } - } - - public NamedSQLQueryDefinition buildQueryReturns( - final String queryName, - final NamedSQLQueryDefinitionBuilder builder, - final LocalBindingContext bindingContext, - final InFlightMetadataCollector metadataCollector) { - - final JaxbResultsetElement mockedResultSet = new JaxbResultsetElement() { - @Override - public String getName() { - return queryName; - } - @Override - public List getLoadCollection() { - return loadCollectionElements; - } - - @Override - public List getReturn() { - return returnElements; - } - - @Override - public List getReturnJoin() { - return returnJoinElements; - } - - @Override - public List getReturnScalar() { - return returnScalarElements; - } - }; - - final ResultSetMappingDefinition definition = ResultSetMappingBinder.buildResultSetMappingDefinitions( mockedResultSet,bindingContext, metadataCollector ); - - return builder.setQueryReturns( definition.getQueryReturns() ) - .setQuerySpaces( synchronizedTables ) - .createNamedQueryDefinition(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataBuildingOptions.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataBuildingOptions.java index 21448abe47..c0ee4b920c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataBuildingOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataBuildingOptions.java @@ -24,6 +24,7 @@ package org.hibernate.metamodel.spi; import java.util.List; + import javax.persistence.SharedCacheMode; import org.hibernate.MultiTenancyStrategy; @@ -31,16 +32,12 @@ import org.hibernate.boot.spi.CacheRegionDefinition; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cfg.NamingStrategy; -import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.archive.scan.spi.ScanEnvironment; import org.hibernate.metamodel.archive.scan.spi.ScanOptions; -import org.hibernate.metamodel.archive.scan.spi.Scanner; import org.hibernate.metamodel.archive.spi.ArchiveDescriptorFactory; import org.hibernate.metamodel.spi.relational.Database; import org.hibernate.type.BasicType; - import org.jboss.jandex.IndexView; - import org.xml.sax.EntityResolver; /** @@ -200,9 +197,7 @@ public interface MetadataBuildingOptions { */ PersistentAttributeMemberResolver getPersistentAttributeMemberResolver(); - // todo : these 2 will go away... - - MetadataSourceProcessingOrder getMetadataSourceProcessingOrder(); + // todo : this will go away... EntityResolver getEntityResolver(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataSourceProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataSourceProcessor.java deleted file mode 100644 index 64349c3619..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetadataSourceProcessor.java +++ /dev/null @@ -1,72 +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.spi; - -import java.util.Collection; - -import org.hibernate.metamodel.source.spi.EntityHierarchySource; -import org.hibernate.metamodel.source.spi.FilterDefinitionSource; -import org.hibernate.metamodel.source.spi.IdentifierGeneratorSource; -import org.hibernate.metamodel.source.spi.TypeDescriptorSource; - -/** - * Handles the processing of metadata sources in a dependency-ordered manner. - * - * @author Steve Ebersole - */ -public interface MetadataSourceProcessor { - /** - * Retrieve the sources pertaining to type descriptors. - * - * @return The type descriptor sources. - */ - Iterable extractTypeDefinitionSources(); - - /** - * Retrieve the sources pertaining to filter defs. - * - * @return The filter def sources. - */ - Iterable extractFilterDefinitionSources(); - - /** - * Retrieve the sources of "global" identifier generator specifications. - * - * @return The identifier generator sources. - */ - Iterable extractGlobalIdentifierGeneratorSources(); - - /** - * Retrieve the entity hierarchies. - * - * @return The entity hierarchies - */ - Collection extractEntityHierarchies(); - - /** - * Process the parts of the metadata that depend on mapping (entities, et al) information having been - * processed and available. - */ - void processMappingDependentMetadata(); -} diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java index 25cda5289c..8869521338 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java @@ -23,6 +23,12 @@ */ package org.hibernate.metamodel.internal.source; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Iterator; import org.hibernate.EntityMode; @@ -34,8 +40,7 @@ import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.MetadataSources; -import org.hibernate.metamodel.source.internal.annotations.AnnotationMetadataSourceProcessorImpl; -import org.hibernate.metamodel.source.internal.hbm.HbmMetadataSourceProcessorImpl; +import org.hibernate.metamodel.source.internal.annotations.AnnotationMetadataSourceProcessor; import org.hibernate.metamodel.source.spi.EntityHierarchySource; import org.hibernate.metamodel.source.spi.EntitySource; import org.hibernate.metamodel.source.spi.IdentifierGeneratorSource; @@ -45,21 +50,12 @@ import org.hibernate.metamodel.source.spi.TableSource; import org.hibernate.metamodel.source.spi.TableSpecificationSource; import org.hibernate.metamodel.spi.BindingContext; -import org.hibernate.metamodel.spi.MetadataSourceProcessor; import org.hibernate.metamodel.spi.SingularAttributeNature; import org.hibernate.metamodel.spi.binding.IdentifierGeneratorDefinition; import org.hibernate.metamodel.spi.binding.InheritanceType; - import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; - import org.jboss.jandex.IndexView; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import org.junit.Test; /** * @author Steve Ebersole @@ -67,18 +63,19 @@ public class AssertSourcesTest extends BaseUnitTestCase { final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build() ; - @Test - public void testUserEntitySourcesHbm() { - BindingContext rootContext = RootBindingContextBuilder.buildBindingContext( serviceRegistry ); - - MetadataSources hbm = new MetadataSources( serviceRegistry ); - hbm.addResource( getClass().getPackage().getName().replace( '.', '/' ) + "/User.hbm.xml" ); - MetadataSourceProcessor hbmProcessor = new HbmMetadataSourceProcessorImpl( - rootContext, - hbm - ); - testUserEntitySources( hbmProcessor, rootContext ); - } + // TODO +// @Test +// public void testUserEntitySourcesHbm() { +// BindingContext rootContext = RootBindingContextBuilder.buildBindingContext( serviceRegistry ); +// +// MetadataSources hbm = new MetadataSources( serviceRegistry ); +// hbm.addResource( getClass().getPackage().getName().replace( '.', '/' ) + "/User.hbm.xml" ); +// MetadataSourceProcessor hbmProcessor = new HbmMetadataSourceProcessorImpl( +// rootContext, +// hbm +// ); +// testUserEntitySources( hbmProcessor, rootContext ); +// } @Test public void testUserEntitySourcesAnnotations() { @@ -89,14 +86,14 @@ public void testUserEntitySourcesAnnotations() { final IndexView indexView = ann.buildJandexView(); BindingContext rootContext = RootBindingContextBuilder.buildBindingContext( serviceRegistry, indexView ); - MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( + AnnotationMetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessor( rootContext, indexView ); testUserEntitySources( annProcessor, rootContext ); } - private void testUserEntitySources(MetadataSourceProcessor processor, BindingContext rootContext) { + private void testUserEntitySources(AnnotationMetadataSourceProcessor processor, BindingContext rootContext) { for ( IdentifierGeneratorSource identifierGeneratorSource : processor.extractGlobalIdentifierGeneratorSources() ) { rootContext.getMetadataCollector().addIdGenerator( new IdentifierGeneratorDefinition( @@ -201,14 +198,14 @@ public void testOrderEntitySources() { ann.addAnnotatedClass( Order.class ); ann.addAnnotatedClass( Order.OrderPk.class ); IndexView indexView = ann.buildJandexView(); - MetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessorImpl( + AnnotationMetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessor( RootBindingContextBuilder.buildBindingContext( serviceRegistry, indexView ), indexView ); testOrderEntitySources( annProcessor ); } - private void testOrderEntitySources(MetadataSourceProcessor processor) { + private void testOrderEntitySources(AnnotationMetadataSourceProcessor processor) { Iterator hierarchies = processor.extractEntityHierarchies().iterator(); assertTrue( hierarchies.hasNext() ); EntityHierarchySource hierarchy = hierarchies.next(); @@ -229,16 +226,15 @@ public void testOrderNonAggregatedEntitySources() { ann.addAnnotatedClass( Order.class ); ann.addAnnotatedClass( Order.class ); ann.addAnnotatedClass( Order.OrderPk.class ); - MetadataSourceProcessor annProcessor; final IndexView indexView = ann.buildJandexView(); - annProcessor = new AnnotationMetadataSourceProcessorImpl( + AnnotationMetadataSourceProcessor annProcessor = new AnnotationMetadataSourceProcessor( RootBindingContextBuilder.buildBindingContext( serviceRegistry, indexView ), indexView ); testOrderNonAggregatedEntitySources( annProcessor ); } - private void testOrderNonAggregatedEntitySources(MetadataSourceProcessor processor) { + private void testOrderNonAggregatedEntitySources(AnnotationMetadataSourceProcessor processor) { Iterator hierarchies = processor.extractEntityHierarchies().iterator(); assertTrue( hierarchies.hasNext() ); EntityHierarchySource hierarchy = hierarchies.next(); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java index 42ede4038e..46e41b4d02 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java @@ -23,22 +23,20 @@ */ package org.hibernate.metamodel.spi.binding; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; -import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.internal.MetadataImpl; import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * @author Gail Badner @@ -56,22 +54,13 @@ public void tearDown() { serviceRegistry.destroy(); } -// @Test -// public void testAnnotations() { -// doTest( MetadataSourceProcessingOrder.ANNOTATIONS_FIRST ); -// } - @Test @TestForIssue( jiraKey = "HHH-7436" ) public void testHbm() { - doTest( MetadataSourceProcessingOrder.HBM_FIRST ); - } - - private void doTest(MetadataSourceProcessingOrder processingOrder) { MetadataSources sources = new MetadataSources( serviceRegistry ); sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml" ); sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" ); - MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).build(); + MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().build(); final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToMany.class.getName() ); final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );