From 056024a8b66257edc4e1696c2c14776ac0379b92 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 10 Feb 2014 01:00:19 -0600 Subject: [PATCH] HHH-8893 - Develop Hibernate mapping XSD extending the JPA mapping (orm) XSD; HHH-8894 - Use an "upgrade" approach to validate and bind (JAXB) mapping XML - hbm-to-orm XSLT --- hibernate-core/hibernate-core.gradle | 16 +-- .../main/java/org/hibernate/FlushMode.java | 8 +- .../hibernate/metamodel/MetadataSources.java | 71 +++------- .../metamodel/internal/MetadataImpl.java | 45 ++++-- ...AnnotationMetadataSourceProcessorImpl.java | 2 +- .../attribute/AssociationAttribute.java | 2 +- .../annotations/util/JPAListenerHelper.java | 2 +- .../xml/mocker/AttributesContainer.java | 35 ----- .../annotations/xml/mocker/EntityElement.java | 17 --- .../annotations/xml/mocker/Listener.java | 8 -- .../xml/mocker/PropertyElement.java | 14 -- .../hbm/transform/HbmXmlTransformer.java | 45 +++--- .../jandex}/AbstractAttributesBuilder.java | 33 ++--- .../jandex}/AbstractEntityObjectMocker.java | 40 +++--- .../internal/jandex}/AbstractMocker.java | 13 +- .../internal/jandex}/AccessHelper.java | 48 ++++--- .../internal/jandex}/AnnotationMocker.java | 36 ++--- .../internal/jandex}/AttributesBuilder.java | 24 ++-- .../internal/jandex}/BasicMocker.java | 12 +- .../jandex}/DefaultConfigurationHelper.java | 32 +++-- .../jandex}/ElementCollectionMocker.java | 11 +- .../jandex}/EmbeddableAttributesBuilder.java | 26 ++-- .../internal/jandex}/EmbeddableMocker.java | 29 ++-- .../internal/jandex}/EmbeddedIdMocker.java | 11 +- .../internal/jandex}/EmbeddedMocker.java | 11 +- .../jandex}/EntityMappingsMocker.java | 109 +++++++++------ .../internal/jandex}/EntityMocker.java | 47 ++++--- .../jandex}/GlobalAnnotationMocker.java | 58 ++++---- .../internal/jandex}/GlobalAnnotations.java | 39 +++--- .../internal/jandex}/IdMocker.java | 13 +- .../internal/jandex}/IndexBuilder.java | 37 +++-- .../internal/jandex}/ListenerMocker.java | 17 +-- .../internal/jandex}/ManyToManyMocker.java | 12 +- .../internal/jandex}/ManyToOneMocker.java | 11 +- .../jandex}/MappedSuperclassMocker.java | 36 ++--- .../internal/jandex}/MockHelper.java | 18 +-- .../internal/jandex}/OneToManyMocker.java | 12 +- .../internal/jandex}/OneToOneMocker.java | 11 +- .../jandex}/PersistenceMetadataMocker.java | 9 +- .../internal/jandex}/PropertyMocker.java | 48 ++++--- .../internal/jandex}/PseudoJpaDotNames.java | 2 +- .../internal/jandex}/TransientMocker.java | 34 +++-- .../source/internal/jandex/Unifier.java | 85 +++++++++++ .../internal/jandex}/VersionMocker.java | 12 +- .../filter/AbstractAnnotationFilter.java | 4 +- .../filter/ExclusiveAnnotationFilter.java | 6 +- .../filter/IndexedAnnotationFilter.java | 4 +- .../jandex}/filter/NameAnnotationFilter.java | 2 +- .../filter/NameTargetAnnotationFilter.java | 77 +++++----- .../internal}/jaxb/AttributesContainer.java | 2 +- .../internal}/jaxb/LifecycleCallback.java | 2 +- .../internal}/jaxb/ManagedType.java | 6 +- .../internal}/jaxb/Parameterized.java | 2 +- .../internal}/jaxb/PersistentAttribute.java | 10 +- .../internal}/jaxb/SchemaAware.java | 2 +- .../internal}/jaxb/ToolingHintContainer.java | 2 +- .../marshalling/AccessTypeMarshalling.java | 41 ++++++ .../DiscriminatorTypeMarshalling.java | 41 ++++++ .../jaxb/marshalling/EnumTypeMarshalling.java | 41 ++++++ .../marshalling/FetchTypeMarshalling.java | 41 ++++++ .../marshalling/FlushModeMarshalling.java | 41 ++++++ .../marshalling/LockModeTypeMarshalling.java | 41 ++++++ .../marshalling/ParameterModeMarshalling.java | 41 ++++++ .../marshalling/TemporalTypeMarshalling.java | 41 ++++++ .../spi/package-info.java} | 17 +-- .../xml/internal/jaxb/AbstractXmlBinder.java | 3 + .../xml/internal/jaxb/HbmEventReader.java | 105 ++++++++++++++ .../xml/internal/jaxb/MappingXmlBinder.java | 55 ++------ .../internal/jaxb/UnifiedMappingBinder.java | 19 +-- .../jaxb/UnifiedMappingEventReader.java | 17 +-- .../xml/internal/stax/LocalSchema.java | 4 +- .../java/org/hibernate/xml/spi/Origin.java | 8 +- .../xsd/mapping/legacy-mapping-4.0.xsd | 2 - .../hibernate/xsd/mapping/mapping-2.1.0.xsd | 37 ++--- .../src/main/xjb/mapping-bindings.xjb | 132 ++++++++++++------ .../xml/mocker/AbstractMockerTest.java | 4 +- .../xml/mocker/BasicMockerTest.java | 11 +- .../DefaultConfigurationHelperTest.java | 4 +- .../xml/mocker/EntityListenerTest.java | 2 +- .../xml/mocker/IndexBuilderTest.java | 2 + .../annotations/xml/mocker/OverrideTest.java | 5 +- .../mocker/PersistenceMetadataMockerTest.java | 2 +- .../xml/ejb3/NonExistentOrmVersionTest.java | 22 +-- .../discriminator/SimpleInheritanceTest.java | 5 - .../unified/jaxb/SimpleBindingTest.java | 9 +- .../org/hibernate/test/ops/SimpleOpsTest.java | 5 - .../FailureExpectedWithNewMetamodel.java | 3 +- .../junit4/BaseCoreFunctionalTestCase.java | 11 +- .../testing/junit4/BaseUnitTestCase.java | 6 - .../testing/junit4/CustomRunner.java | 2 +- 90 files changed, 1301 insertions(+), 839 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AttributesContainer.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityElement.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/Listener.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PropertyElement.java rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/AbstractAttributesBuilder.java (75%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/AbstractEntityObjectMocker.java (81%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/AbstractMocker.java (92%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/AccessHelper.java (80%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/AnnotationMocker.java (95%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/AttributesBuilder.java (70%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/BasicMocker.java (86%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/DefaultConfigurationHelper.java (91%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/ElementCollectionMocker.java (90%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/EmbeddableAttributesBuilder.java (69%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/EmbeddableMocker.java (73%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/EmbeddedIdMocker.java (82%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/EmbeddedMocker.java (84%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/EntityMappingsMocker.java (65%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/EntityMocker.java (86%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/GlobalAnnotationMocker.java (86%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/GlobalAnnotations.java (91%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/IdMocker.java (86%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/IndexBuilder.java (96%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/ListenerMocker.java (91%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/ManyToManyMocker.java (89%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/ManyToOneMocker.java (88%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/MappedSuperclassMocker.java (74%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/MockHelper.java (99%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/OneToManyMocker.java (90%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/OneToOneMocker.java (89%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/PersistenceMetadataMocker.java (92%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/PropertyMocker.java (84%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml => source/internal/jandex}/PseudoJpaDotNames.java (97%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/TransientMocker.java (69%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/Unifier.java rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker => source/internal/jandex}/VersionMocker.java (83%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml => source/internal/jandex}/filter/AbstractAnnotationFilter.java (94%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml => source/internal/jandex}/filter/ExclusiveAnnotationFilter.java (96%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml => source/internal/jandex}/filter/IndexedAnnotationFilter.java (91%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml => source/internal/jandex}/filter/NameAnnotationFilter.java (96%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml => source/internal/jandex}/filter/NameTargetAnnotationFilter.java (62%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{spi/source => source/internal}/jaxb/AttributesContainer.java (96%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{spi/source => source/internal}/jaxb/LifecycleCallback.java (95%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{spi/source => source/internal}/jaxb/ManagedType.java (92%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{spi/source => source/internal}/jaxb/Parameterized.java (95%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{spi/source => source/internal}/jaxb/PersistentAttribute.java (89%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{spi/source => source/internal}/jaxb/SchemaAware.java (96%) rename hibernate-core/src/main/java/org/hibernate/metamodel/{spi/source => source/internal}/jaxb/ToolingHintContainer.java (95%) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/AccessTypeMarshalling.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/DiscriminatorTypeMarshalling.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/EnumTypeMarshalling.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FetchTypeMarshalling.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FlushModeMarshalling.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/LockModeTypeMarshalling.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/ParameterModeMarshalling.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/TemporalTypeMarshalling.java rename hibernate-core/src/main/java/org/hibernate/metamodel/{internal/source/annotations/xml/mocker/SchemaAware.java => source/spi/package-info.java} (72%) create mode 100644 hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/HbmEventReader.java diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 5f060cb72e..3c6163d1f6 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -111,18 +111,17 @@ task jaxb { // input schemas cfgXsd = file( 'src/main/resources/org/hibernate/hibernate-configuration-4.0.xsd') hbmXsd = file( 'src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd' ) - ormXsd = file( 'src/main/resources/org/hibernate/jpa/orm_2_1.xsd' ) unifiedOrmXsd = file( 'src/main/resources/org/hibernate/xsd/mapping/mapping-2.1.0.xsd' ) // input bindings cfgXjb = file( 'src/main/xjb/hbm-configuration-bindings.xjb' ) hbmXjb = file( 'src/main/xjb/hbm-mapping-bindings.xjb' ) - ormXjb = file( 'src/main/xjb/orm-bindings.xjb' ) unifiedOrmXjb = file( 'src/main/xjb/mapping-bindings.xjb' ) } // configure Gradle up-to-date checking - inputs.files( [cfgXsd, hbmXsd, ormXsd, unifiedOrmXsd, cfgXjb, hbmXjb, ormXjb, unifiedOrmXjb] ) +// inputs.files( [cfgXsd, hbmXsd, ormXsd, unifiedOrmXsd, cfgXjb, hbmXjb, ormXjb, unifiedOrmXjb] ) + inputs.files( [cfgXsd, hbmXsd, unifiedOrmXsd, cfgXjb, hbmXjb, unifiedOrmXjb] ) outputs.dir( jaxbTargetDir ) // perform actions @@ -150,17 +149,6 @@ task jaxb { arg line: '-Xinheritance -Xsimplify' } - // orm.xml (jpa) - ant.xjc( - destdir: '${jaxbTargetDir}', - package: 'org.hibernate.jaxb.spi.orm', - binding: 'src/main/xjb/orm-bindings.xjb', - schema: ormXsd.path, - extension: 'true' - ) { - arg line: '-Xinheritance' - } - // unified mapping xsd ant.xjc( destdir: '${jaxbTargetDir}', diff --git a/hibernate-core/src/main/java/org/hibernate/FlushMode.java b/hibernate-core/src/main/java/org/hibernate/FlushMode.java index 8a0dbacb93..159532b749 100644 --- a/hibernate-core/src/main/java/org/hibernate/FlushMode.java +++ b/hibernate-core/src/main/java/org/hibernate/FlushMode.java @@ -23,6 +23,8 @@ */ package org.hibernate; +import java.util.Locale; + /** * Represents a flushing strategy. The flush process synchronizes * database state with session state by detecting state changes @@ -102,6 +104,10 @@ public enum FlushMode { return MANUAL.level == mode.level; } + public String toExternalForm() { + return name().toLowerCase( Locale.ENGLISH ); + } + /** * Interprets an external representation of the flush mode. {@code null} is returned as {@code null}, otherwise * {@link FlushMode#valueOf(String)} is used with the upper-case version of the incoming value. An unknown, @@ -119,7 +125,7 @@ public enum FlushMode { } try { - return FlushMode.valueOf( externalName.toUpperCase() ); + return FlushMode.valueOf( externalName.toUpperCase( Locale.ENGLISH ) ); } catch ( IllegalArgumentException e ) { throw new MappingException( "unknown FlushMode : " + externalName ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java index de7b7819e3..2885d8f187 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java @@ -32,7 +32,6 @@ import java.io.InputStream; import java.io.Serializable; import java.net.URL; import java.util.ArrayList; -import java.util.Collection; import java.util.Enumeration; import java.util.HashSet; import java.util.LinkedHashSet; @@ -47,6 +46,7 @@ import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.SerializationHelper; @@ -56,16 +56,16 @@ import org.hibernate.jaxb.spi.hbm.JaxbHibernateMapping; import org.hibernate.jaxb.spi.hbm.JaxbJoinedSubclassElement; import org.hibernate.jaxb.spi.hbm.JaxbSubclassElement; import org.hibernate.jaxb.spi.hbm.JaxbUnionSubclassElement; -import org.hibernate.jaxb.spi.orm.JaxbConverter; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddable; -import org.hibernate.jaxb.spi.orm.JaxbEntity; -import org.hibernate.jaxb.spi.orm.JaxbEntityMappings; -import org.hibernate.jaxb.spi.orm.JaxbMappedSuperclass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbConverter; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddable; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jaxb.JaxbMappedSuperclass; import org.hibernate.metamodel.internal.MetadataBuilderImpl; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; -import org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityMappingsMocker; +import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker; import org.hibernate.metamodel.spi.source.InvalidMappingException; import org.hibernate.metamodel.spi.source.MappingException; import org.hibernate.metamodel.spi.source.MappingNotFoundException; @@ -78,7 +78,6 @@ import org.hibernate.xml.spi.SourceType; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.jboss.jandex.IndexView; @@ -96,15 +95,7 @@ import org.w3c.dom.Document; * @author Brett Meyer */ public class MetadataSources { - public static final String UNKNOWN_FILE_PATH = ""; - - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, MetadataSources.class.getName()); - - /** - * temporary option - */ - public static final String USE_NEW_METADATA_MAPPINGS = "hibernate.test.new_metadata_mappings"; + private static final CoreMessageLogger LOG = CoreLogging.messageLogger( MetadataSources.class ); private final ServiceRegistry serviceRegistry; private final MappingXmlBinder jaxbProcessor; @@ -448,7 +439,7 @@ public class MetadataSources { * @return this (for method chaining purposes) */ public MetadataSources addInputStream(InputStream xmlInputStream) { - add( xmlInputStream, new Origin( SourceType.INPUT_STREAM, UNKNOWN_FILE_PATH ), false ); + add( xmlInputStream, new Origin( SourceType.INPUT_STREAM, Origin.UNKNOWN_FILE_PATH ), false ); return this; } @@ -481,7 +472,7 @@ public class MetadataSources { * @return this (for method chaining purposes) */ public MetadataSources addDocument(Document document) { - final Origin origin = new Origin( SourceType.DOM, UNKNOWN_FILE_PATH ); + final Origin origin = new Origin( SourceType.DOM, Origin.UNKNOWN_FILE_PATH ); BindResult bindResult = jaxbProcessor.bind( document, origin ); addJaxbRoot( bindResult ); return this; @@ -562,31 +553,20 @@ public class MetadataSources { return this; } - @SuppressWarnings("unchecked") - public IndexView wrapJandexView(IndexView jandexView) { - if ( ! hasOrmXmlJaxbRoots ) { - // no need to wrap - return jandexView; - } - - final List collectedOrmXmlMappings = new ArrayList(); - for ( BindResult bindResult : getBindResultList() ) { - if ( JaxbEntityMappings.class.isInstance( bindResult.getRoot() ) ) { - collectedOrmXmlMappings.add( ( (BindResult) bindResult ).getRoot() ); - } - } - - if ( collectedOrmXmlMappings.isEmpty() ) { - // log a warning or something - } - - return new EntityMappingsMocker( collectedOrmXmlMappings, jandexView, serviceRegistry ).mockNewIndex(); - } - public IndexView buildJandexView() { return buildJandexView( false ); } + /** + * Create a Jandex IndexView from scratch given the sources information contained here. + * + * @param autoIndexMemberTypes Should the types of class members automatically be added to the built index? + * + * @return + */ + public IndexView buildJandexView(boolean autoIndexMemberTypes) { + return JandexIndexBuilder.process( autoIndexMemberTypes, this ); + } public static class JandexIndexBuilder { private static final Logger log = Logger.getLogger( JandexIndexBuilder.class ); @@ -864,15 +844,4 @@ public class MetadataSources { } } } - - /** - * Create a Jandex IndexView from scratch given the sources information contained here. - * - * @param autoIndexMemberTypes Should the types of class members automatically be added to the built index? - * - * @return - */ - public IndexView buildJandexView(boolean autoIndexMemberTypes) { - return wrapJandexView( JandexIndexBuilder.process( autoIndexMemberTypes, this ) ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java index 8ddbd349aa..ba80e343e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java @@ -25,16 +25,11 @@ package org.hibernate.metamodel.internal; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.IndexView; -import org.jboss.logging.Logger; - import org.hibernate.AssertionFailure; import org.hibernate.DuplicateMappingException; import org.hibernate.EntityMode; @@ -62,13 +57,13 @@ import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ValueHolder; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.xml.spi.BindResult; import org.hibernate.metamodel.MetadataSourceProcessingOrder; import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.SessionFactoryBuilder; import org.hibernate.metamodel.internal.source.annotations.AnnotationMetadataSourceProcessorImpl; -import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.hbm.HbmMetadataSourceProcessorImpl; +import org.hibernate.metamodel.source.internal.jandex.Unifier; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; import org.hibernate.metamodel.spi.AdditionalJaxbRootProducer; import org.hibernate.metamodel.spi.MetadataContributor; import org.hibernate.metamodel.spi.MetadataImplementor; @@ -110,6 +105,10 @@ import org.hibernate.type.TypeFactory; import org.hibernate.type.TypeResolver; import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.UserType; +import org.hibernate.xml.spi.BindResult; + +import org.jboss.jandex.IndexView; +import org.jboss.logging.Logger; /** * Container for configuration data collected during binding the metamodel. @@ -177,13 +176,31 @@ public class MetadataImpl implements MetadataImplementor, Serializable { } }; - // todo : cache the built index if no inputs have changed (look at gradle-style hashing for up-to-date checking) - boolean autoIndexMemberTypes = serviceRegistry.getService( ConfigurationService.class ).getSetting( - AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES, StandardConverters.BOOLEAN, false ); - final IndexView jandexView = options.getJandexView() != null - ? metadataSources.wrapJandexView( options.getJandexView() ) - : metadataSources.buildJandexView( autoIndexMemberTypes ); - Collection tables = jandexView.getAnnotations( JPADotNames.TABLE ); + final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class ); + + final IndexView baseJandexIndex; + if ( options.getJandexView() != null ) { + baseJandexIndex = options.getJandexView(); + } + else { + final boolean autoIndexMemberTypes = configurationService.getSetting( + AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES, + StandardConverters.BOOLEAN, + false + ); + baseJandexIndex = metadataSources.buildJandexView( autoIndexMemberTypes ); + } + + final List> jpaXmlBindings = new ArrayList>(); + for ( BindResult bindResult : metadataSources.getBindResultList() ) { + if ( JaxbEntityMappings.class.isInstance( bindResult.getRoot() ) ) { + // todo : this will be checked after hbm transformation is in place. + //noinspection unchecked + jpaXmlBindings.add( bindResult ); + } + } + final IndexView jandexView = Unifier.unify( baseJandexIndex, jpaXmlBindings, serviceRegistry ); + final MetadataSourceProcessor[] metadataSourceProcessors; if ( options.getMetadataSourceProcessingOrder() == MetadataSourceProcessingOrder.HBM_FIRST ) { metadataSourceProcessors = new MetadataSourceProcessor[] { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java index 6aabbf358d..676016a477 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/AnnotationMetadataSourceProcessorImpl.java @@ -37,7 +37,7 @@ import org.hibernate.metamodel.internal.source.annotations.global.TableProcessor import org.hibernate.metamodel.internal.source.annotations.util.EntityHierarchyBuilder; import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; -import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; +import org.hibernate.metamodel.source.internal.jandex.PseudoJpaDotNames; import org.hibernate.metamodel.spi.MetadataSourceProcessor; import org.hibernate.metamodel.spi.source.EntityHierarchy; import org.hibernate.metamodel.spi.source.FilterDefinitionSource; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java index 60a185cb63..71d2a85de8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/AssociationAttribute.java @@ -50,7 +50,7 @@ import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHe import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; -import org.hibernate.metamodel.internal.source.annotations.xml.mocker.MockHelper; +import org.hibernate.metamodel.source.internal.jandex.MockHelper; import org.hibernate.metamodel.spi.source.MappingException; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPAListenerHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPAListenerHelper.java index bcaee034b6..e3cace80f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPAListenerHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JPAListenerHelper.java @@ -51,7 +51,7 @@ import org.hibernate.metamodel.internal.source.annotations.entity.ConfiguredClas import org.hibernate.metamodel.internal.source.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass; import org.hibernate.metamodel.internal.source.annotations.entity.MappedSuperclass; -import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; +import org.hibernate.metamodel.source.internal.jandex.PseudoJpaDotNames; import org.hibernate.metamodel.spi.source.JpaCallbackSource; /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AttributesContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AttributesContainer.java deleted file mode 100644 index d8626f0e06..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AttributesContainer.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; - -import java.util.List; - -import org.hibernate.jaxb.spi.orm.JaxbBasic; -import org.hibernate.jaxb.spi.orm.JaxbElementCollection; -import org.hibernate.jaxb.spi.orm.JaxbEmbedded; -import org.hibernate.jaxb.spi.orm.JaxbManyToMany; -import org.hibernate.jaxb.spi.orm.JaxbManyToOne; -import org.hibernate.jaxb.spi.orm.JaxbOneToMany; -import org.hibernate.jaxb.spi.orm.JaxbOneToOne; -import org.hibernate.jaxb.spi.orm.JaxbTransient; - -/** - * @author Strong Liu - */ -public interface AttributesContainer { - - List getTransient(); - - List getBasic(); - - List getElementCollection(); - - List getEmbedded(); - - List getManyToMany(); - - List getManyToOne(); - - List getOneToMany(); - - List getOneToOne(); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityElement.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityElement.java deleted file mode 100644 index 7501d3b0e5..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityElement.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; - -import org.hibernate.jaxb.spi.orm.JaxbAccessType; - -/** - * @author Strong Liu - */ -public interface EntityElement { - String getClazz(); - - void setClazz(String className); - - Boolean isMetadataComplete(); - - void setMetadataComplete(Boolean isMetadataComplete); - public JaxbAccessType getAccess(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/Listener.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/Listener.java deleted file mode 100644 index c2093d1456..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/Listener.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; - -/** - * @author Strong Liu - */ -public interface Listener { - public String getMethodName(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PropertyElement.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PropertyElement.java deleted file mode 100644 index b3a596b9a7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PropertyElement.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; - -import org.hibernate.jaxb.spi.orm.JaxbAccessType; - -/** - * @author Strong Liu - */ -public interface PropertyElement { - String getName(); - - JaxbAccessType getAccess(); - - void setAccess(JaxbAccessType accessType); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/transform/HbmXmlTransformer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/transform/HbmXmlTransformer.java index 44b2e08a19..dfe64f29d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/transform/HbmXmlTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/transform/HbmXmlTransformer.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.internal.source.hbm.transform; import java.util.Date; +import org.hibernate.FlushMode; import org.hibernate.internal.util.StringHelper; import org.hibernate.jaxb.spi.hbm.JaxbCacheModeAttribute; import org.hibernate.jaxb.spi.hbm.JaxbClassElement; @@ -43,21 +44,19 @@ import org.hibernate.jaxb.spi.hbm.JaxbQueryParamElement; import org.hibernate.jaxb.spi.hbm.JaxbSqlQueryElement; import org.hibernate.jaxb.spi.hbm.JaxbSubclassElement; import org.hibernate.jaxb.spi.hbm.JaxbTypedefElement; -import org.hibernate.metamodel.spi.source.jaxb.JaxbCacheModeType; -import org.hibernate.metamodel.spi.source.jaxb.JaxbEntity; -import org.hibernate.metamodel.spi.source.jaxb.JaxbEntityMappings; -import org.hibernate.metamodel.spi.source.jaxb.JaxbFlushModeType; -import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmFetchProfile; -import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmFilterDef; -import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmIdGeneratorDef; -import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmParam; -import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmToolingHint; -import org.hibernate.metamodel.spi.source.jaxb.JaxbHbmTypeDef; -import org.hibernate.metamodel.spi.source.jaxb.JaxbMappedSuperclass; -import org.hibernate.metamodel.spi.source.jaxb.JaxbNamedNativeQuery; -import org.hibernate.metamodel.spi.source.jaxb.JaxbNamedQuery; -import org.hibernate.metamodel.spi.source.jaxb.JaxbPersistenceUnitMetadata; -import org.hibernate.metamodel.spi.source.jaxb.JaxbQueryParamType; +import org.hibernate.metamodel.source.internal.jaxb.JaxbCacheModeType; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFetchProfile; +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFilterDef; +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmIdGeneratorDef; +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmParam; +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmToolingHint; +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmTypeDef; +import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery; +import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitMetadata; +import org.hibernate.metamodel.source.internal.jaxb.JaxbQueryParamType; import org.jboss.logging.Logger; @@ -255,7 +254,7 @@ public class HbmXmlTransformer { query.setCacheRegion( hbmQuery.getCacheRegion() ); query.setComment( hbmQuery.getComment() ); query.setFetchSize( hbmQuery.getFetchSize() ); - query.setFlushMode( convert( hbmQuery.getFlushMode() ) ); + query.setFlushMode( interpret( hbmQuery.getFlushMode() ) ); query.setFetchSize( hbmQuery.getFetchSize() ); query.setReadOnly( hbmQuery.isReadOnly() ); query.setTimeout( hbmQuery.getTimeout() ); @@ -285,13 +284,13 @@ public class HbmXmlTransformer { return JaxbCacheModeType.fromValue( value ); } - private JaxbFlushModeType convert(JaxbFlushModeAttribute flushMode) { + private FlushMode interpret(JaxbFlushModeAttribute flushMode) { final String value = flushMode == null ? null : flushMode.value(); if ( StringHelper.isEmpty( value ) ) { return null; } - return JaxbFlushModeType.fromValue( value ); + return FlushMode.valueOf( value ); } private void transferNamedSqlQuery(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) { @@ -308,7 +307,7 @@ public class HbmXmlTransformer { query.setCacheRegion( hbmQuery.getCacheRegion() ); query.setComment( hbmQuery.getComment() ); query.setFetchSize( hbmQuery.getFetchSize() ); - query.setFlushMode( convert( hbmQuery.getFlushMode() ) ); + query.setFlushMode( interpret( hbmQuery.getFlushMode() ) ); query.setFetchSize( hbmQuery.getFetchSize() ); query.setReadOnly( hbmQuery.isReadOnly() ); query.setTimeout( hbmQuery.getTimeout() ); @@ -334,11 +333,11 @@ public class HbmXmlTransformer { } private void transferEntities(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) { - // todo : make MappedSuperclass for abstract hbm class mappings? - // thoughts... - // 1) We only need to transfer the "extends" attribute if the model is dynamic (map mode) - // + // 1) We only need to transfer the "extends" attribute if the model is dynamic (map mode), + // otherwise it will be discovered via jandex + // 2) ?? Have abstract hbm class mappings become MappedSuperclass mappings ?? + if ( !hbmXmlMapping.getClazz().isEmpty() ) { for ( JaxbClassElement hbmClass : hbmXmlMapping.getClazz() ) { final JaxbEntity entity = new JaxbEntity(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractAttributesBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractAttributesBuilder.java similarity index 75% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractAttributesBuilder.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractAttributesBuilder.java index fcf3f8bbbc..acc267622c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractAttributesBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractAttributesBuilder.java @@ -21,33 +21,34 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.AttributesContainer; +import org.hibernate.metamodel.source.internal.jaxb.JaxbBasic; +import org.hibernate.metamodel.source.internal.jaxb.JaxbElementCollection; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbedded; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddedId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbManyToMany; +import org.hibernate.metamodel.source.internal.jaxb.JaxbManyToOne; +import org.hibernate.metamodel.source.internal.jaxb.JaxbOneToMany; +import org.hibernate.metamodel.source.internal.jaxb.JaxbOneToOne; +import org.hibernate.metamodel.source.internal.jaxb.JaxbTransient; +import org.hibernate.metamodel.source.internal.jaxb.JaxbVersion; + import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbBasic; -import org.hibernate.jaxb.spi.orm.JaxbElementCollection; -import org.hibernate.jaxb.spi.orm.JaxbEmbedded; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddedId; -import org.hibernate.jaxb.spi.orm.JaxbId; -import org.hibernate.jaxb.spi.orm.JaxbManyToMany; -import org.hibernate.jaxb.spi.orm.JaxbManyToOne; -import org.hibernate.jaxb.spi.orm.JaxbOneToMany; -import org.hibernate.jaxb.spi.orm.JaxbOneToOne; -import org.hibernate.jaxb.spi.orm.JaxbTransient; -import org.hibernate.jaxb.spi.orm.JaxbVersion; - /** - * Abstract parse to handle {@link org.hibernate.jaxb.spi.orm.JaxbAttributes JaxbAttributes} - * and {@link org.hibernate.jaxb.spi.orm.JaxbEmbeddableAttributes JaxbEmbeddableAttributes}. + * Abstract parse to handle {@link org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes JaxbAttributes} + * and {@link org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddableAttributes JaxbEmbeddableAttributes}. * * It would be really helpful if these two classes can implement an interface with those abstract methods in this class. * * @author Strong Liu */ -abstract class AbstractAttributesBuilder { +public abstract class AbstractAttributesBuilder { private ClassInfo classInfo; private EntityMappingsMocker.Default defaults; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractEntityObjectMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractEntityObjectMocker.java similarity index 81% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractEntityObjectMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractEntityObjectMocker.java index cb21b1e3be..6fa0cbbdb7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractEntityObjectMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractEntityObjectMocker.java @@ -21,30 +21,32 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; + +import javax.persistence.AccessType; + +import org.hibernate.AssertionFailure; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners; +import org.hibernate.metamodel.source.internal.jaxb.JaxbIdClass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostLoad; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostPersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostUpdate; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPrePersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreUpdate; +import org.hibernate.metamodel.source.internal.jaxb.ManagedType; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.hibernate.AssertionFailure; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; -import org.hibernate.jaxb.spi.orm.JaxbAttributes; -import org.hibernate.jaxb.spi.orm.JaxbEntityListeners; -import org.hibernate.jaxb.spi.orm.JaxbIdClass; -import org.hibernate.jaxb.spi.orm.JaxbPostLoad; -import org.hibernate.jaxb.spi.orm.JaxbPostPersist; -import org.hibernate.jaxb.spi.orm.JaxbPostRemove; -import org.hibernate.jaxb.spi.orm.JaxbPostUpdate; -import org.hibernate.jaxb.spi.orm.JaxbPrePersist; -import org.hibernate.jaxb.spi.orm.JaxbPreRemove; -import org.hibernate.jaxb.spi.orm.JaxbPreUpdate; - /** * @author Strong Liu */ -abstract class AbstractEntityObjectMocker extends AnnotationMocker { +public abstract class AbstractEntityObjectMocker extends AnnotationMocker { private ListenerMocker listenerparse; protected AbstractAttributesBuilder attributesBuilder; protected ClassInfo classInfo; @@ -58,7 +60,7 @@ abstract class AbstractEntityObjectMocker extends AnnotationMocker { /** * Pre-process Entity Objects to find the default {@link javax.persistence.Access} for later attributes processing. */ - final void preProcess() { + public final void preProcess() { DefaultConfigurationHelper.INSTANCE.applyDefaults( getEntityElement(), getDefaults() ); classInfo = indexBuilder.createClassInfo( getEntityElement().getClazz() ); DotName classDotName = classInfo.name(); @@ -69,12 +71,12 @@ abstract class AbstractEntityObjectMocker extends AnnotationMocker { isPreProcessCalled = true; } - final void process() { + public final void process() { if ( !isPreProcessCalled ) { throw new AssertionFailure( "preProcess should be called before process" ); } if ( getEntityElement().getAccess() == null ) { - JaxbAccessType accessType = AccessHelper.getEntityAccess( getTargetName(), indexBuilder ); + AccessType accessType = AccessHelper.getEntityAccess( getTargetName(), indexBuilder ); if ( accessType == null ) { accessType = getDefaults().getAccess(); } @@ -107,7 +109,7 @@ abstract class AbstractEntityObjectMocker extends AnnotationMocker { indexBuilder.finishEntityObject( getTargetName(), getDefaults() ); } - abstract protected EntityElement getEntityElement(); + abstract protected ManagedType getEntityElement(); abstract protected void processExtra(); abstract protected boolean isExcludeDefaultListeners(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractMocker.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractMocker.java index 7c91c44df0..a9304ab2a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractMocker.java @@ -21,16 +21,17 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import javax.persistence.AccessType; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; -import org.hibernate.jaxb.spi.orm.JaxbIndex; -import org.hibernate.jaxb.spi.orm.JaxbUniqueConstraint; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.internal.jaxb.JaxbIndex; +import org.hibernate.metamodel.source.internal.jaxb.JaxbUniqueConstraint; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; @@ -41,7 +42,7 @@ import org.jboss.jandex.DotName; * * @author Strong Liu */ -abstract class AbstractMocker implements JPADotNames { +public abstract class AbstractMocker implements JPADotNames { final protected IndexBuilder indexBuilder; AbstractMocker(IndexBuilder indexBuilder) { @@ -69,7 +70,7 @@ abstract class AbstractMocker implements JPADotNames { } - protected AnnotationInstance parseAccessType(JaxbAccessType accessType, AnnotationTarget target) { + protected AnnotationInstance parseAccessType(AccessType accessType, AnnotationTarget target) { if ( accessType == null ) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AccessHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AccessHelper.java similarity index 80% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AccessHelper.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AccessHelper.java index 5ed99c12bc..ecd80f2c0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AccessHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AccessHelper.java @@ -21,20 +21,20 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.List; import java.util.Map; +import javax.persistence.AccessType; import org.hibernate.AssertionFailure; import org.hibernate.MappingException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; -import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.ClassInfo; @@ -45,13 +45,13 @@ import org.jboss.logging.Logger; /** * @author Strong Liu */ -class AccessHelper implements JPADotNames { +public class AccessHelper implements JPADotNames { private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, AccessHelper.class.getName() ); - static JaxbAccessType getAccessFromDefault(IndexBuilder indexBuilder) { + static AccessType getAccessFromDefault(IndexBuilder indexBuilder) { AnnotationInstance annotationInstance = JandexHelper.getSingleAnnotation( indexBuilder.getAnnotations(), PseudoJpaDotNames.DEFAULT_ACCESS @@ -60,16 +60,20 @@ class AccessHelper implements JPADotNames { return null; } else { - return JandexHelper.getEnumValue( annotationInstance, "value", JaxbAccessType.class, - indexBuilder.getServiceRegistry().getService( ClassLoaderService.class ) ); + return JandexHelper.getEnumValue( + annotationInstance, + "value", + AccessType.class, + indexBuilder.getServiceRegistry().getService( ClassLoaderService.class ) + ); } } - static JaxbAccessType getAccessFromIdPosition(DotName className, IndexBuilder indexBuilder) { + static AccessType getAccessFromIdPosition(DotName className, IndexBuilder indexBuilder) { Map> indexedAnnotations = indexBuilder.getIndexedAnnotations( className ); Map> ormAnnotations = indexBuilder.getClassInfoAnnotationsMap( className ); - JaxbAccessType accessType = getAccessFromIdPosition( ormAnnotations ); + AccessType accessType = getAccessFromIdPosition( ormAnnotations ); if ( accessType == null ) { accessType = getAccessFromIdPosition( indexedAnnotations ); } @@ -88,7 +92,7 @@ class AccessHelper implements JPADotNames { return accessType; } - private static JaxbAccessType getAccessFromIdPosition(Map> annotations) { + private static AccessType getAccessFromIdPosition(Map> annotations) { if ( annotations == null || annotations.isEmpty() || !( annotations.containsKey( ID ) ) ) { return null; } @@ -99,8 +103,8 @@ class AccessHelper implements JPADotNames { return null; } - private static JaxbAccessType processIdAnnotations(List idAnnotations) { - JaxbAccessType accessType = null; + private static AccessType processIdAnnotations(List idAnnotations) { + AccessType accessType = null; for ( AnnotationInstance annotation : idAnnotations ) { AnnotationTarget tmpTarget = annotation.target(); if ( tmpTarget == null ) { @@ -118,14 +122,14 @@ class AccessHelper implements JPADotNames { return accessType; } - static JaxbAccessType annotationTargetToAccessType(AnnotationTarget target) { - return ( target instanceof MethodInfo ) ? JaxbAccessType.PROPERTY : JaxbAccessType.FIELD; + static AccessType annotationTargetToAccessType(AnnotationTarget target) { + return ( target instanceof MethodInfo ) ? AccessType.PROPERTY : AccessType.FIELD; } - static JaxbAccessType getEntityAccess(DotName className, IndexBuilder indexBuilder) { + static AccessType getEntityAccess(DotName className, IndexBuilder indexBuilder) { Map> indexedAnnotations = indexBuilder.getIndexedAnnotations( className ); Map> ormAnnotations = indexBuilder.getClassInfoAnnotationsMap( className ); - JaxbAccessType accessType = getAccess( ormAnnotations, indexBuilder ); + AccessType accessType = getAccess( ormAnnotations, indexBuilder ); if ( accessType == null ) { accessType = getAccess( indexedAnnotations, indexBuilder ); } @@ -143,7 +147,7 @@ class AccessHelper implements JPADotNames { } - private static JaxbAccessType getAccess(Map> annotations, IndexBuilder indexBuilder) { + private static AccessType getAccess(Map> annotations, IndexBuilder indexBuilder) { if ( annotations == null || annotations.isEmpty() || !isEntityObject( annotations ) ) { return null; } @@ -154,7 +158,7 @@ class AccessHelper implements JPADotNames { return JandexHelper.getEnumValue( annotationInstance, "value", - JaxbAccessType.class, + AccessType.class, indexBuilder.getServiceRegistry().getService( ClassLoaderService.class ) ); } @@ -171,7 +175,7 @@ class AccessHelper implements JPADotNames { /** * Get {@link javax.persistence.AccessType } from {@link javax.persistence.Access @Access} on the attribute of the given class */ - static JaxbAccessType getAccessFromAttributeAnnotation(DotName className, String attributeName, IndexBuilder indexBuilder) { + static AccessType getAccessFromAttributeAnnotation(DotName className, String attributeName, IndexBuilder indexBuilder) { Map> indexedAnnotations = indexBuilder.getIndexedAnnotations( className ); if ( indexedAnnotations != null && indexedAnnotations.containsKey( ACCESS ) ) { List annotationInstances = indexedAnnotations.get( ACCESS ); @@ -182,16 +186,16 @@ class AccessHelper implements JPADotNames { continue; } if ( JandexHelper.getPropertyName( indexedPropertyTarget ).equals( attributeName ) ) { - JaxbAccessType accessType = JandexHelper.getEnumValue( + AccessType accessType = JandexHelper.getEnumValue( annotationInstance, "value", - JaxbAccessType.class, + AccessType.class, indexBuilder.getServiceRegistry().getService( ClassLoaderService.class ) ); /** * here we ignore @Access(FIELD) on property (getter) and @Access(PROPERTY) on field */ - JaxbAccessType targetAccessType = annotationTargetToAccessType( indexedPropertyTarget ); + AccessType targetAccessType = annotationTargetToAccessType( indexedPropertyTarget ); if ( accessType.equals( targetAccessType ) ) { return targetAccessType; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AnnotationMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AnnotationMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java index 410c7e486d..e6088c2f72 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AnnotationMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java @@ -21,37 +21,37 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import javax.persistence.EnumType; +import javax.persistence.TemporalType; + +import org.hibernate.AssertionFailure; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAssociationOverride; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributeOverride; +import org.hibernate.metamodel.source.internal.jaxb.JaxbCollectionTable; +import org.hibernate.metamodel.source.internal.jaxb.JaxbColumn; +import org.hibernate.metamodel.source.internal.jaxb.JaxbJoinColumn; +import org.hibernate.metamodel.source.internal.jaxb.JaxbJoinTable; +import org.hibernate.metamodel.source.internal.jaxb.JaxbLob; +import org.hibernate.metamodel.source.internal.jaxb.JaxbOrderColumn; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPrimaryKeyJoinColumn; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.DotName; -import org.hibernate.AssertionFailure; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbAssociationOverride; -import org.hibernate.jaxb.spi.orm.JaxbAttributeOverride; -import org.hibernate.jaxb.spi.orm.JaxbCollectionTable; -import org.hibernate.jaxb.spi.orm.JaxbColumn; -import org.hibernate.jaxb.spi.orm.JaxbEnumType; -import org.hibernate.jaxb.spi.orm.JaxbJoinColumn; -import org.hibernate.jaxb.spi.orm.JaxbJoinTable; -import org.hibernate.jaxb.spi.orm.JaxbLob; -import org.hibernate.jaxb.spi.orm.JaxbOrderColumn; -import org.hibernate.jaxb.spi.orm.JaxbPrimaryKeyJoinColumn; -import org.hibernate.jaxb.spi.orm.JaxbTemporalType; - /** * @author Strong Liu */ -abstract class AnnotationMocker extends AbstractMocker { +public abstract class AnnotationMocker extends AbstractMocker { private EntityMappingsMocker.Default defaults; AnnotationMocker(IndexBuilder indexBuilder, EntityMappingsMocker.Default defaults) { @@ -209,14 +209,14 @@ abstract class AnnotationMocker extends AbstractMocker { return create( LOB, target ); } - protected AnnotationInstance parseTemporalType(JaxbTemporalType temporalType, AnnotationTarget target) { + protected AnnotationInstance parseTemporalType(TemporalType temporalType, AnnotationTarget target) { if ( temporalType == null ) { return null; } return create( TEMPORAL, target, MockHelper.enumValueArray( "value", TEMPORAL_TYPE, temporalType ) ); } - protected AnnotationInstance parseEnumType(JaxbEnumType enumerated, AnnotationTarget target) { + protected AnnotationInstance parseEnumType(EnumType enumerated, AnnotationTarget target) { if ( enumerated == null ) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AttributesBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AttributesBuilder.java similarity index 70% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AttributesBuilder.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AttributesBuilder.java index dd320c1365..cb796618d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AttributesBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AttributesBuilder.java @@ -21,25 +21,31 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.List; +import javax.persistence.AccessType; + +import org.hibernate.metamodel.source.internal.jaxb.AttributesContainer; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddedId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbVersion; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; -import org.hibernate.jaxb.spi.orm.JaxbAttributes; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddedId; -import org.hibernate.jaxb.spi.orm.JaxbId; -import org.hibernate.jaxb.spi.orm.JaxbVersion; - /** * @author Strong Liu */ -class AttributesBuilder extends AbstractAttributesBuilder { +public class AttributesBuilder extends AbstractAttributesBuilder { private final JaxbAttributes attributes; - AttributesBuilder(IndexBuilder indexBuilder, ClassInfo classInfo, JaxbAccessType accessType, EntityMappingsMocker.Default defaults, JaxbAttributes attributes) { + AttributesBuilder( + IndexBuilder indexBuilder, + ClassInfo classInfo, + AccessType accessType, + EntityMappingsMocker.Default defaults, + JaxbAttributes attributes) { super( indexBuilder, classInfo, defaults ); this.attributes = attributes; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/BasicMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/BasicMocker.java similarity index 86% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/BasicMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/BasicMocker.java index daa283365b..5d867316e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/BasicMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/BasicMocker.java @@ -21,20 +21,21 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.JaxbBasic; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; + import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbBasic; - /** * @author Strong Liu */ -class BasicMocker extends PropertyMocker { +public class BasicMocker extends PropertyMocker { private final JaxbBasic basic; BasicMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbBasic basic) { @@ -43,9 +44,10 @@ class BasicMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return basic; } + @Override protected void processExtra() { List annotationValueList = new ArrayList(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/DefaultConfigurationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/DefaultConfigurationHelper.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/DefaultConfigurationHelper.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/DefaultConfigurationHelper.java index 5f0ec033e4..5c227803ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/DefaultConfigurationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/DefaultConfigurationHelper.java @@ -21,34 +21,36 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; +import org.hibernate.metamodel.source.internal.jandex.filter.IndexedAnnotationFilter; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbTable; +import org.hibernate.metamodel.source.internal.jaxb.ManagedType; +import org.hibernate.metamodel.source.internal.jaxb.SchemaAware; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.DotName; import org.jboss.logging.Logger; -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.jaxb.spi.orm.JaxbEntity; -import org.hibernate.jaxb.spi.orm.JaxbTable; -import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; -import org.hibernate.metamodel.internal.source.annotations.util.JandexHelper; -import org.hibernate.metamodel.internal.source.annotations.xml.filter.IndexedAnnotationFilter; - /** * @author Strong Liu */ -class DefaultConfigurationHelper { +public class DefaultConfigurationHelper { private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, DefaultConfigurationHelper.class.getName() ); - static final DefaultConfigurationHelper INSTANCE = new DefaultConfigurationHelper(); + public static final DefaultConfigurationHelper INSTANCE = new DefaultConfigurationHelper(); static final DotName[] GLOBAL_ANNOTATIONS = new DotName[] { JPADotNames.SEQUENCE_GENERATOR, JPADotNames.TABLE_GENERATOR, @@ -75,7 +77,7 @@ class DefaultConfigurationHelper { private DefaultConfigurationHelper() { } - void applyDefaults(SchemaAware schemaAware, EntityMappingsMocker.Default defaults) { + public void applyDefaults(SchemaAware schemaAware, EntityMappingsMocker.Default defaults) { if ( hasSchemaOrCatalogDefined( defaults ) ) { if ( StringHelper.isEmpty( schemaAware.getSchema() ) ) { schemaAware.setSchema( defaults.getSchema() ); @@ -86,7 +88,7 @@ class DefaultConfigurationHelper { } } - void applyDefaults(Map> annotationsMap, EntityMappingsMocker.Default defaults) { + public void applyDefaults(Map> annotationsMap, EntityMappingsMocker.Default defaults) { if ( annotationsMap.isEmpty() || defaults == null ) { return; } @@ -98,7 +100,7 @@ class DefaultConfigurationHelper { } } - void applyDefaults(EntityElement entityElement, EntityMappingsMocker.Default defaults) { + public void applyDefaults(ManagedType entityElement, EntityMappingsMocker.Default defaults) { if(JaxbEntity.class.isInstance( entityElement )) mockTableIfNonExist( JaxbEntity.class.cast( entityElement ), defaults ); applyDefaultsToEntityObject( entityElement , defaults ); @@ -114,7 +116,7 @@ class DefaultConfigurationHelper { } } - private void applyDefaultsToEntityObject(EntityElement entityObject, EntityMappingsMocker.Default defaults) { + private void applyDefaultsToEntityObject(ManagedType entityObject, EntityMappingsMocker.Default defaults) { if ( defaults == null ) { return; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ElementCollectionMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ElementCollectionMocker.java similarity index 90% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ElementCollectionMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ElementCollectionMocker.java index 5bb203255d..af33a3aca9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ElementCollectionMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ElementCollectionMocker.java @@ -21,20 +21,21 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.JaxbElementCollection; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; + import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbElementCollection; - /** * @author Strong Liu */ -class ElementCollectionMocker extends PropertyMocker { +public class ElementCollectionMocker extends PropertyMocker { private final JaxbElementCollection elementCollection; ElementCollectionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbElementCollection elementCollection) { @@ -43,7 +44,7 @@ class ElementCollectionMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return elementCollection; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddableAttributesBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddableAttributesBuilder.java similarity index 69% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddableAttributesBuilder.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddableAttributesBuilder.java index 772967e406..3908bdc881 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddableAttributesBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddableAttributesBuilder.java @@ -21,26 +21,32 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.Collections; import java.util.List; +import javax.persistence.AccessType; + +import org.hibernate.metamodel.source.internal.jaxb.AttributesContainer; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddableAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddedId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbVersion; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddableAttributes; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddedId; -import org.hibernate.jaxb.spi.orm.JaxbId; -import org.hibernate.jaxb.spi.orm.JaxbVersion; - /** * @author Strong Liu */ -class EmbeddableAttributesBuilder extends AbstractAttributesBuilder { +public class EmbeddableAttributesBuilder extends AbstractAttributesBuilder { private final JaxbEmbeddableAttributes attributes; - EmbeddableAttributesBuilder(IndexBuilder indexBuilder, ClassInfo classInfo, JaxbAccessType accessType, EntityMappingsMocker.Default defaults, JaxbEmbeddableAttributes embeddableAttributes) { + EmbeddableAttributesBuilder( + IndexBuilder indexBuilder, + ClassInfo classInfo, + AccessType accessType, + EntityMappingsMocker.Default defaults, + JaxbEmbeddableAttributes embeddableAttributes) { super( indexBuilder, classInfo, defaults ); this.attributes = embeddableAttributes; } @@ -49,6 +55,7 @@ class EmbeddableAttributesBuilder extends AbstractAttributesBuilder { protected AttributesContainer getAttributesContainer() { return attributes; } + @Override List getId() { return Collections.emptyList(); @@ -58,6 +65,7 @@ class EmbeddableAttributesBuilder extends AbstractAttributesBuilder { List getVersion() { return Collections.emptyList(); } + @Override JaxbEmbeddedId getEmbeddedId() { return null; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddableMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddableMocker.java similarity index 73% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddableMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddableMocker.java index 5e68f0cbc7..be47555122 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddableMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddableMocker.java @@ -21,26 +21,27 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; -import org.hibernate.jaxb.spi.orm.JaxbAttributes; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddable; -import org.hibernate.jaxb.spi.orm.JaxbEntityListeners; -import org.hibernate.jaxb.spi.orm.JaxbIdClass; -import org.hibernate.jaxb.spi.orm.JaxbPostLoad; -import org.hibernate.jaxb.spi.orm.JaxbPostPersist; -import org.hibernate.jaxb.spi.orm.JaxbPostRemove; -import org.hibernate.jaxb.spi.orm.JaxbPostUpdate; -import org.hibernate.jaxb.spi.orm.JaxbPrePersist; -import org.hibernate.jaxb.spi.orm.JaxbPreRemove; -import org.hibernate.jaxb.spi.orm.JaxbPreUpdate; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddable; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners; +import org.hibernate.metamodel.source.internal.jaxb.JaxbIdClass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostLoad; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostPersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostUpdate; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPrePersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreUpdate; +import org.hibernate.metamodel.source.internal.jaxb.ManagedType; /** * Mock to {@link javax.persistence.Embeddable @Embeddable} * * @author Strong Liu */ -class EmbeddableMocker extends AbstractEntityObjectMocker { +public class EmbeddableMocker extends AbstractEntityObjectMocker { private final JaxbEmbeddable embeddable; EmbeddableMocker(IndexBuilder indexBuilder, JaxbEmbeddable embeddable, EntityMappingsMocker.Default defaults) { @@ -59,7 +60,7 @@ class EmbeddableMocker extends AbstractEntityObjectMocker { } @Override - protected EntityElement getEntityElement() { + protected ManagedType getEntityElement() { return embeddable; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddedIdMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddedIdMocker.java similarity index 82% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddedIdMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddedIdMocker.java index f333b8c0be..3fe7728b3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddedIdMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddedIdMocker.java @@ -21,16 +21,17 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; + +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddedId; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddedId; - /** * @author Strong Liu */ -class EmbeddedIdMocker extends PropertyMocker { +public class EmbeddedIdMocker extends PropertyMocker { private final JaxbEmbeddedId embeddedId; EmbeddedIdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbEmbeddedId embeddedId) { @@ -39,7 +40,7 @@ class EmbeddedIdMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return embeddedId; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddedMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddedMocker.java similarity index 84% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddedMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddedMocker.java index 80312e3003..f53df95797 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EmbeddedMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EmbeddedMocker.java @@ -21,16 +21,17 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; + +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbedded; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbEmbedded; - /** * @author Strong Liu */ -class EmbeddedMocker extends PropertyMocker { +public class EmbeddedMocker extends PropertyMocker { private final JaxbEmbedded embedded; EmbeddedMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbEmbedded embedded) { @@ -47,7 +48,7 @@ class EmbeddedMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return embedded; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMappingsMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EntityMappingsMocker.java similarity index 65% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMappingsMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EntityMappingsMocker.java index d312410f79..29b2976538 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMappingsMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EntityMappingsMocker.java @@ -21,37 +21,40 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import javax.persistence.AccessType; + +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEmbeddable; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jaxb.JaxbMappedSuperclass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitDefaults; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitMetadata; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.xml.spi.BindResult; +import org.hibernate.xml.spi.Origin; +import org.hibernate.xml.spi.SourceType; import org.jboss.jandex.Index; import org.jboss.jandex.IndexView; -import org.jboss.logging.Logger; - -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; -import org.hibernate.jaxb.spi.orm.JaxbEmbeddable; -import org.hibernate.jaxb.spi.orm.JaxbEntity; -import org.hibernate.jaxb.spi.orm.JaxbEntityMappings; -import org.hibernate.jaxb.spi.orm.JaxbMappedSuperclass; -import org.hibernate.jaxb.spi.orm.JaxbPersistenceUnitDefaults; -import org.hibernate.jaxb.spi.orm.JaxbPersistenceUnitMetadata; -import org.hibernate.service.ServiceRegistry; /** - * Parse all {@link org.hibernate.jaxb.spi.orm.JaxbEntityMappings} generated from orm.xml. + * Parse all {@link org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings} generated from orm.xml. * * @author Strong Liu */ +@Deprecated public class EntityMappingsMocker { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, - EntityMappingsMocker.class.getName() - ); - private final List entityMappingsList; + private static final CoreMessageLogger LOG = CoreLogging.messageLogger( EntityMappingsMocker.class ); + + private final List> xmlBindings; + /** * Default configuration defined in Persistence Metadata Unit, one or zero per Persistence Unit. */ @@ -59,21 +62,45 @@ public class EntityMappingsMocker { private final IndexBuilder indexBuilder; private final GlobalAnnotations globalAnnotations; - public EntityMappingsMocker(List entityMappingsList, IndexView index, ServiceRegistry serviceRegistry) { - this.entityMappingsList = entityMappingsList; + public EntityMappingsMocker(List> xmlBindings, IndexView index, ServiceRegistry serviceRegistry) { + this.xmlBindings = xmlBindings; this.indexBuilder = new IndexBuilder( index, serviceRegistry ); this.globalAnnotations = new GlobalAnnotations(); } + public EntityMappingsMocker( + List xmlEntityMappingsList, + Index index, + ServiceRegistry serviceRegistry) { + this( + grabJaxbEntityMappings( xmlEntityMappingsList ), + index, + serviceRegistry + ); + } + + private static List> grabJaxbEntityMappings(List xmlEntityMappingsList) { + final List> result = new ArrayList>(); + for ( JaxbEntityMappings binding : xmlEntityMappingsList ) { + result.add( + new BindResult( + binding, + new Origin( SourceType.OTHER, Origin.UNKNOWN_FILE_PATH ) + ) + ); + } + return result; + } + /** - * Create new {@link Index} with mocking JPA annotations from {@link org.hibernate.jaxb.spi.orm.JaxbEntityMappings} + * Create new {@link Index} with mocking JPA annotations from {@link org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings} * and merge them with existing {@link Index} * * @return new {@link Index} */ public Index mockNewIndex() { - processPersistenceUnitMetadata( entityMappingsList ); - processEntityMappings( entityMappingsList ); + processPersistenceUnitMetadata( xmlBindings ); + processEntityMappings( xmlBindings ); processGlobalAnnotations(); return indexBuilder.build( globalDefaults ); } @@ -81,10 +108,10 @@ public class EntityMappingsMocker { /** * processing PersistenceUnitMetadata, there should be only one PersistenceUnitMetadata in all mapping xml files. */ - private void processPersistenceUnitMetadata(List entityMappingsList) { - for ( JaxbEntityMappings entityMappings : entityMappingsList ) { + private void processPersistenceUnitMetadata(List> xmlBindings) { + for ( BindResult xmlBinding : xmlBindings ) { //we have to iterate entityMappingsList first to find persistence-unit-metadata - JaxbPersistenceUnitMetadata pum = entityMappings.getPersistenceUnitMetadata(); + JaxbPersistenceUnitMetadata pum = xmlBinding.getRoot().getPersistenceUnitMetadata(); if ( globalDefaults != null ) { LOG.duplicateMetadata(); return; @@ -110,24 +137,24 @@ public class EntityMappingsMocker { } - private void processEntityMappings(List entityMappingsList) { + private void processEntityMappings(List> xmlBindings) { List mockerList = new ArrayList(); - for ( JaxbEntityMappings entityMappings : entityMappingsList ) { - final Default defaults = getEntityMappingsDefaults( entityMappings ); - globalAnnotations.collectGlobalMappings( entityMappings, defaults ); - for ( JaxbMappedSuperclass mappedSuperclass : entityMappings.getMappedSuperclass() ) { + for ( BindResult xmlBinding : xmlBindings ) { + final Default defaults = getEntityMappingsDefaults( xmlBinding.getRoot() ); + globalAnnotations.collectGlobalMappings( xmlBinding.getRoot(), defaults ); + for ( JaxbMappedSuperclass mappedSuperclass : xmlBinding.getRoot().getMappedSuperclass() ) { AbstractEntityObjectMocker mocker = new MappedSuperclassMocker( indexBuilder, mappedSuperclass, defaults ); mockerList.add( mocker ); mocker.preProcess(); } - for ( JaxbEmbeddable embeddable : entityMappings.getEmbeddable() ) { + for ( JaxbEmbeddable embeddable : xmlBinding.getRoot().getEmbeddable() ) { AbstractEntityObjectMocker mocker = new EmbeddableMocker( indexBuilder, embeddable, defaults ); mockerList.add( mocker ); mocker.preProcess(); } - for ( JaxbEntity entity : entityMappings.getEntity() ) { + for ( JaxbEntity entity : xmlBinding.getRoot().getEntity() ) { globalAnnotations.collectGlobalMappings( entity, defaults ); AbstractEntityObjectMocker mocker = new EntityMocker( indexBuilder, entity, defaults ); @@ -163,18 +190,18 @@ public class EntityMappingsMocker { public static class Default implements Serializable { - private JaxbAccessType access; + private AccessType access; private String packageName; private String schema; private String catalog; private Boolean metadataComplete; private Boolean cascadePersist; - public JaxbAccessType getAccess() { + public AccessType getAccess() { return access; } - void setAccess(JaxbAccessType access) { + public void setAccess(AccessType access) { this.access = access; } @@ -182,7 +209,7 @@ public class EntityMappingsMocker { return catalog; } - void setCatalog(String catalog) { + public void setCatalog(String catalog) { this.catalog = catalog; } @@ -190,7 +217,7 @@ public class EntityMappingsMocker { return packageName; } - void setPackageName(String packageName) { + public void setPackageName(String packageName) { this.packageName = packageName; } @@ -198,7 +225,7 @@ public class EntityMappingsMocker { return schema; } - void setSchema(String schema) { + public void setSchema(String schema) { this.schema = schema; } @@ -206,7 +233,7 @@ public class EntityMappingsMocker { return metadataComplete; } - void setMetadataComplete(Boolean metadataComplete) { + public void setMetadataComplete(Boolean metadataComplete) { this.metadataComplete = metadataComplete; } @@ -214,7 +241,7 @@ public class EntityMappingsMocker { return cascadePersist; } - void setCascadePersist(Boolean cascadePersist) { + public void setCascadePersist(Boolean cascadePersist) { this.cascadePersist = cascadePersist; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EntityMocker.java similarity index 86% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EntityMocker.java index c1346c35c1..3e14a1342f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EntityMocker.java @@ -21,46 +21,47 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.persistence.AccessType; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbDiscriminatorColumn; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners; +import org.hibernate.metamodel.source.internal.jaxb.JaxbIdClass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbInheritance; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostLoad; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostPersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostUpdate; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPrePersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreUpdate; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSecondaryTable; +import org.hibernate.metamodel.source.internal.jaxb.JaxbTable; +import org.hibernate.metamodel.source.internal.jaxb.ManagedType; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbAttributes; -import org.hibernate.jaxb.spi.orm.JaxbDiscriminatorColumn; -import org.hibernate.jaxb.spi.orm.JaxbEntity; -import org.hibernate.jaxb.spi.orm.JaxbEntityListeners; -import org.hibernate.jaxb.spi.orm.JaxbIdClass; -import org.hibernate.jaxb.spi.orm.JaxbInheritance; -import org.hibernate.jaxb.spi.orm.JaxbPostLoad; -import org.hibernate.jaxb.spi.orm.JaxbPostPersist; -import org.hibernate.jaxb.spi.orm.JaxbPostRemove; -import org.hibernate.jaxb.spi.orm.JaxbPostUpdate; -import org.hibernate.jaxb.spi.orm.JaxbPrePersist; -import org.hibernate.jaxb.spi.orm.JaxbPreRemove; -import org.hibernate.jaxb.spi.orm.JaxbPreUpdate; -import org.hibernate.jaxb.spi.orm.JaxbSecondaryTable; -import org.hibernate.jaxb.spi.orm.JaxbTable; - /** * Mock to {@link javax.persistence.Entity @Entity} * * @author Strong Liu */ -class EntityMocker extends AbstractEntityObjectMocker { +public class EntityMocker extends AbstractEntityObjectMocker { private final JaxbEntity entity; - EntityMocker(IndexBuilder indexBuilder, JaxbEntity entity, EntityMappingsMocker.Default defaults) { + public EntityMocker(IndexBuilder indexBuilder, JaxbEntity entity, EntityMappingsMocker.Default defaults) { super( indexBuilder, defaults ); this.entity = entity; } @@ -115,7 +116,7 @@ class EntityMocker extends AbstractEntityObjectMocker { protected AccessType getDefaultAccess() { if ( entity.getAccess() != null ) { - return AccessType.valueOf( entity.getAccess().value() ); + return entity.getAccess(); } return null; @@ -139,7 +140,7 @@ class EntityMocker extends AbstractEntityObjectMocker { } @Override - protected EntityElement getEntityElement() { + protected ManagedType getEntityElement() { return entity; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotationMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/GlobalAnnotationMocker.java similarity index 86% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotationMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/GlobalAnnotationMocker.java index 9d7ece7bb0..41ec193eed 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotationMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/GlobalAnnotationMocker.java @@ -21,31 +21,30 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery; +import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery; +import org.hibernate.metamodel.source.internal.jaxb.JaxbQueryHint; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSequenceGenerator; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMapping; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingColumnResult; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingEntityResult; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingFieldResult; +import org.hibernate.metamodel.source.internal.jaxb.JaxbTableGenerator; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbColumnResult; -import org.hibernate.jaxb.spi.orm.JaxbEntityResult; -import org.hibernate.jaxb.spi.orm.JaxbFieldResult; -import org.hibernate.jaxb.spi.orm.JaxbNamedNativeQuery; -import org.hibernate.jaxb.spi.orm.JaxbNamedQuery; -import org.hibernate.jaxb.spi.orm.JaxbQueryHint; -import org.hibernate.jaxb.spi.orm.JaxbSequenceGenerator; -import org.hibernate.jaxb.spi.orm.JaxbSqlResultSetMapping; -import org.hibernate.jaxb.spi.orm.JaxbTableGenerator; - /** * @author Strong Liu */ -class GlobalAnnotationMocker extends AbstractMocker { +public class GlobalAnnotationMocker extends AbstractMocker { private GlobalAnnotations globalAnnotations; GlobalAnnotationMocker(IndexBuilder indexBuilder, GlobalAnnotations globalAnnotations) { @@ -92,8 +91,8 @@ class GlobalAnnotationMocker extends AbstractMocker { private AnnotationInstance parseSqlResultSetMappings(Collection namedQueries) { AnnotationValue[] values = new AnnotationValue[namedQueries.size()]; int i = 0; - for ( Iterator iterator = namedQueries.iterator(); iterator.hasNext(); ) { - AnnotationInstance annotationInstance = parseSqlResultSetMapping( iterator.next() ); + for ( JaxbSqlResultSetMapping namedQuery : namedQueries ) { + AnnotationInstance annotationInstance = parseSqlResultSetMapping( namedQuery ); values[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance ); @@ -108,21 +107,16 @@ class GlobalAnnotationMocker extends AbstractMocker { //@SqlResultSetMapping private AnnotationInstance parseSqlResultSetMapping(JaxbSqlResultSetMapping mapping) { - List annotationValueList = new ArrayList(); MockHelper.stringValue( "name", mapping.getName(), annotationValueList ); nestedEntityResultList( "entities", mapping.getEntityResult(), annotationValueList ); nestedColumnResultList( "columns", mapping.getColumnResult(), annotationValueList ); - return - create( - SQL_RESULT_SET_MAPPING, null, annotationValueList - - ); + return create( SQL_RESULT_SET_MAPPING, null, annotationValueList ); } //@EntityResult - private AnnotationInstance parseEntityResult(JaxbEntityResult result) { + private AnnotationInstance parseEntityResult(JaxbSqlResultSetMappingEntityResult result) { List annotationValueList = new ArrayList(); MockHelper.stringValue( @@ -139,7 +133,7 @@ class GlobalAnnotationMocker extends AbstractMocker { ); } - private void nestedEntityResultList(String name, List entityResults, List annotationValueList) { + private void nestedEntityResultList(String name, List entityResults, List annotationValueList) { if ( CollectionHelper.isNotEmpty( entityResults ) ) { AnnotationValue[] values = new AnnotationValue[entityResults.size()]; for ( int i = 0; i < entityResults.size(); i++ ) { @@ -155,11 +149,11 @@ class GlobalAnnotationMocker extends AbstractMocker { } //@ColumnResult - private AnnotationInstance parseColumnResult(JaxbColumnResult result) { + private AnnotationInstance parseColumnResult(JaxbSqlResultSetMappingColumnResult result) { return create( COLUMN_RESULT, null, MockHelper.stringValueArray( "name", result.getName() ) ); } - private void nestedColumnResultList(String name, List columnResults, List annotationValueList) { + private void nestedColumnResultList(String name, List columnResults, List annotationValueList) { if ( CollectionHelper.isNotEmpty( columnResults ) ) { AnnotationValue[] values = new AnnotationValue[columnResults.size()]; for ( int i = 0; i < columnResults.size(); i++ ) { @@ -175,7 +169,7 @@ class GlobalAnnotationMocker extends AbstractMocker { } //@FieldResult - private AnnotationInstance parseFieldResult(JaxbFieldResult result) { + private AnnotationInstance parseFieldResult(JaxbSqlResultSetMappingFieldResult result) { List annotationValueList = new ArrayList(); MockHelper.stringValue( "name", result.getName(), annotationValueList ); MockHelper.stringValue( "column", result.getColumn(), annotationValueList ); @@ -183,7 +177,7 @@ class GlobalAnnotationMocker extends AbstractMocker { } - private void nestedFieldResultList(String name, List fieldResultList, List annotationValueList) { + private void nestedFieldResultList(String name, List fieldResultList, List annotationValueList) { if ( CollectionHelper.isNotEmpty( fieldResultList ) ) { AnnotationValue[] values = new AnnotationValue[fieldResultList.size()]; for ( int i = 0; i < fieldResultList.size(); i++ ) { @@ -201,8 +195,8 @@ class GlobalAnnotationMocker extends AbstractMocker { private AnnotationInstance parseNamedNativeQueries(Collection namedQueries) { AnnotationValue[] values = new AnnotationValue[namedQueries.size()]; int i = 0; - for ( Iterator iterator = namedQueries.iterator(); iterator.hasNext(); ) { - AnnotationInstance annotationInstance = parseNamedNativeQuery( iterator.next() ); + for ( JaxbNamedNativeQuery namedQuery : namedQueries ) { + AnnotationInstance annotationInstance = parseNamedNativeQuery( namedQuery ); values[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance ); @@ -237,8 +231,8 @@ class GlobalAnnotationMocker extends AbstractMocker { private AnnotationInstance parseNamedQueries(Collection namedQueries) { AnnotationValue[] values = new AnnotationValue[namedQueries.size()]; int i = 0; - for ( Iterator iterator = namedQueries.iterator(); iterator.hasNext(); ) { - AnnotationInstance annotationInstance = parseNamedQuery( iterator.next() ); + for ( JaxbNamedQuery namedQuery : namedQueries ) { + AnnotationInstance annotationInstance = parseNamedQuery( namedQuery ); values[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotations.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/GlobalAnnotations.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotations.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/GlobalAnnotations.java index 1098efdc37..9a2b84d1ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/GlobalAnnotations.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/GlobalAnnotations.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.Collection; @@ -31,34 +31,33 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationValue; -import org.jboss.jandex.DotName; -import org.jboss.logging.Logger; - +import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbAttributes; -import org.hibernate.jaxb.spi.orm.JaxbEntity; -import org.hibernate.jaxb.spi.orm.JaxbEntityMappings; -import org.hibernate.jaxb.spi.orm.JaxbId; -import org.hibernate.jaxb.spi.orm.JaxbNamedNativeQuery; -import org.hibernate.jaxb.spi.orm.JaxbNamedQuery; -import org.hibernate.jaxb.spi.orm.JaxbSequenceGenerator; -import org.hibernate.jaxb.spi.orm.JaxbSqlResultSetMapping; -import org.hibernate.jaxb.spi.orm.JaxbTableGenerator; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jaxb.JaxbId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery; +import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSequenceGenerator; +import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMapping; +import org.hibernate.metamodel.source.internal.jaxb.JaxbTableGenerator; +import org.hibernate.metamodel.source.internal.jaxb.SchemaAware; import org.hibernate.metamodel.spi.source.MappingException; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationValue; +import org.jboss.jandex.DotName; + /** * @author Strong Liu */ -class GlobalAnnotations implements JPADotNames { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, - GlobalAnnotations.class.getName() - ); +public class GlobalAnnotations implements JPADotNames { + private static final CoreMessageLogger LOG = CoreLogging.messageLogger( GlobalAnnotations.class ); + private final Map sequenceGeneratorMap = new HashMap(); private final Map tableGeneratorMap = new HashMap(); private final Map namedQueryMap = new HashMap(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IdMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/IdMocker.java similarity index 86% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IdMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/IdMocker.java index 79a8021d20..6e1d679091 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IdMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/IdMocker.java @@ -21,23 +21,24 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.JaxbGeneratedValue; +import org.hibernate.metamodel.source.internal.jaxb.JaxbId; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbGeneratedValue; -import org.hibernate.jaxb.spi.orm.JaxbId; - /** * @author Strong Liu */ -class IdMocker extends PropertyMocker { +public class IdMocker extends PropertyMocker { private final JaxbId id; IdMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbId id) { @@ -46,7 +47,7 @@ class IdMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return id; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/IndexBuilder.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/IndexBuilder.java index d67bc038d3..e44450a9a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/IndexBuilder.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.Collection; @@ -30,40 +30,39 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.hibernate.AssertionFailure; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.metamodel.source.internal.jandex.filter.IndexedAnnotationFilter; +import org.hibernate.service.ServiceRegistry; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.jboss.jandex.IndexView; -import org.jboss.logging.Logger; - -import org.hibernate.AssertionFailure; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.internal.source.annotations.xml.filter.IndexedAnnotationFilter; -import org.hibernate.service.ServiceRegistry; /** * @author Strong Liu */ public class IndexBuilder { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, - IndexBuilder.class.getName() - ); + private static final CoreMessageLogger LOG = CoreLogging.messageLogger( IndexBuilder.class ); + + private IndexView index; + private final ServiceRegistry serviceRegistry; + private final Map> annotations; private final Map> subclasses; private final Map> implementors; private final Map classes; - private IndexView index; private final Map>> classInfoAnnotationsMap; private final Map>> indexedClassInfoAnnotationsMap; - private final ServiceRegistry serviceRegistry; - IndexBuilder(IndexView index, ServiceRegistry serviceRegistry) { + public IndexBuilder(IndexView index, ServiceRegistry serviceRegistry) { this.index = index; this.serviceRegistry = serviceRegistry; this.annotations = new HashMap>(); @@ -82,7 +81,7 @@ public class IndexBuilder { * * @return Index. */ - Index build(EntityMappingsMocker.Default globalDefaults) { + public Index build(EntityMappingsMocker.Default globalDefaults) { //merge annotations that not overrided by xml into the new Index for ( ClassInfo ci : index.getKnownClasses() ) { DotName name = ci.name(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ListenerMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ListenerMocker.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ListenerMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ListenerMocker.java index bab3572da8..6a81959a25 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ListenerMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ListenerMocker.java @@ -21,28 +21,29 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.MappingException; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListener; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners; +import org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.hibernate.MappingException; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.jaxb.spi.orm.JaxbEntityListener; -import org.hibernate.jaxb.spi.orm.JaxbEntityListeners; - /** * {@link javax.persistence.EntityListeners @EntityListeners} mocker * * @author Strong Liu */ -class ListenerMocker extends AbstractMocker { +public class ListenerMocker extends AbstractMocker { private final ClassInfo classInfo; ListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo) { @@ -86,7 +87,7 @@ class ListenerMocker extends AbstractMocker { protected ListenerMocker createListenerMocker(IndexBuilder indexBuilder, ClassInfo classInfo) { return new ListenerMocker( indexBuilder, classInfo ); } - AnnotationInstance parse(Listener callback, DotName target) { + AnnotationInstance parse(LifecycleCallback callback, DotName target) { if ( callback == null ) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ManyToManyMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ManyToManyMocker.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ManyToManyMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ManyToManyMocker.java index abcb635f7a..f880e96b56 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ManyToManyMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ManyToManyMocker.java @@ -21,28 +21,30 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.JaxbManyToMany; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; + import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbManyToMany; - /** * @author Strong Liu */ -class ManyToManyMocker extends PropertyMocker { +public class ManyToManyMocker extends PropertyMocker { private final JaxbManyToMany manyToMany; ManyToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbManyToMany manyToMany) { super( indexBuilder, classInfo, defaults ); this.manyToMany = manyToMany; } + @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return manyToMany; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ManyToOneMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ManyToOneMocker.java similarity index 88% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ManyToOneMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ManyToOneMocker.java index 0d6e57bf5b..f6043d8e5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/ManyToOneMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ManyToOneMocker.java @@ -21,20 +21,21 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.JaxbManyToOne; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; + import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbManyToOne; - /** * @author Strong Liu */ -class ManyToOneMocker extends PropertyMocker { +public class ManyToOneMocker extends PropertyMocker { private final JaxbManyToOne manyToOne; ManyToOneMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbManyToOne manyToOne) { @@ -43,7 +44,7 @@ class ManyToOneMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return manyToOne; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MappedSuperclassMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/MappedSuperclassMocker.java similarity index 74% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MappedSuperclassMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/MappedSuperclassMocker.java index fa305410d0..9960906cca 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MappedSuperclassMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/MappedSuperclassMocker.java @@ -21,33 +21,27 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; -import org.jboss.logging.Logger; - -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.jaxb.spi.orm.JaxbAttributes; -import org.hibernate.jaxb.spi.orm.JaxbEntityListeners; -import org.hibernate.jaxb.spi.orm.JaxbIdClass; -import org.hibernate.jaxb.spi.orm.JaxbMappedSuperclass; -import org.hibernate.jaxb.spi.orm.JaxbPostLoad; -import org.hibernate.jaxb.spi.orm.JaxbPostPersist; -import org.hibernate.jaxb.spi.orm.JaxbPostRemove; -import org.hibernate.jaxb.spi.orm.JaxbPostUpdate; -import org.hibernate.jaxb.spi.orm.JaxbPrePersist; -import org.hibernate.jaxb.spi.orm.JaxbPreRemove; -import org.hibernate.jaxb.spi.orm.JaxbPreUpdate; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners; +import org.hibernate.metamodel.source.internal.jaxb.JaxbIdClass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbMappedSuperclass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostLoad; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostPersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPostUpdate; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPrePersist; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreRemove; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPreUpdate; +import org.hibernate.metamodel.source.internal.jaxb.ManagedType; /** * Mock to {@link javax.persistence.MappedSuperclass @MappedSuperClass} * * @author Strong Liu */ -class MappedSuperclassMocker extends AbstractEntityObjectMocker { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, - MappedSuperclassMocker.class.getName() - ); +public class MappedSuperclassMocker extends AbstractEntityObjectMocker { private JaxbMappedSuperclass mappedSuperclass; MappedSuperclassMocker(IndexBuilder indexBuilder, JaxbMappedSuperclass mappedSuperclass, EntityMappingsMocker.Default defaults) { @@ -56,7 +50,7 @@ class MappedSuperclassMocker extends AbstractEntityObjectMocker { } @Override - protected EntityElement getEntityElement() { + protected ManagedType getEntityElement() { return mappedSuperclass; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MockHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/MockHelper.java similarity index 99% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MockHelper.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/MockHelper.java index d2582a3e9d..55ddc498bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/MockHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/MockHelper.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.beans.Introspector; import java.lang.reflect.Field; @@ -31,6 +31,14 @@ import java.util.Collection; import java.util.List; import javax.persistence.CascadeType; +import org.hibernate.HibernateException; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.internal.jaxb.JaxbCascadeType; +import org.hibernate.service.ServiceRegistry; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; @@ -40,14 +48,6 @@ import org.jboss.jandex.FieldInfo; import org.jboss.jandex.MethodInfo; import org.jboss.jandex.Type; -import org.hibernate.HibernateException; -import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbCascadeType; -import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; -import org.hibernate.service.ServiceRegistry; - /** * @author Strong Liu */ diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OneToManyMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/OneToManyMocker.java similarity index 90% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OneToManyMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/OneToManyMocker.java index cd6366b5f5..dc38cdcdd7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OneToManyMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/OneToManyMocker.java @@ -21,20 +21,21 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.JaxbOneToMany; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; + import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbOneToMany; - /** * @author Strong Liu */ -class OneToManyMocker extends PropertyMocker { +public class OneToManyMocker extends PropertyMocker { private final JaxbOneToMany oneToMany; OneToManyMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbOneToMany oneToMany) { @@ -43,9 +44,10 @@ class OneToManyMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return oneToMany; } + @Override protected void processExtra() { List annotationValueList = new ArrayList(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OneToOneMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/OneToOneMocker.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OneToOneMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/OneToOneMocker.java index d197f4a52d..0c6e168a7f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OneToOneMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/OneToOneMocker.java @@ -21,20 +21,21 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import org.hibernate.metamodel.source.internal.jaxb.JaxbOneToOne; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; + import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbOneToOne; - /** * @author Strong Liu */ -class OneToOneMocker extends PropertyMocker { +public class OneToOneMocker extends PropertyMocker { private JaxbOneToOne oneToOne; OneToOneMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbOneToOne oneToOne) { @@ -43,7 +44,7 @@ class OneToOneMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return oneToOne; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PersistenceMetadataMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PersistenceMetadataMocker.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PersistenceMetadataMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PersistenceMetadataMocker.java index 65db372dc8..badb7c9c24 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PersistenceMetadataMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PersistenceMetadataMocker.java @@ -1,21 +1,20 @@ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.HashMap; import java.util.Map; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitDefaults; + import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.hibernate.jaxb.spi.orm.JaxbPersistenceUnitDefaults; -import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; - /** * @author Strong Liu */ -class PersistenceMetadataMocker extends AbstractMocker { +public class PersistenceMetadataMocker extends AbstractMocker { private final JaxbPersistenceUnitDefaults persistenceUnitDefaults; private final GlobalAnnotations globalAnnotations = new GlobalAnnotations(); /** diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PropertyMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PropertyMocker.java similarity index 84% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PropertyMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PropertyMocker.java index 7455fb2de1..82fc118cbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PropertyMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PropertyMocker.java @@ -21,10 +21,21 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; import java.util.ArrayList; import java.util.List; +import javax.persistence.AccessType; +import javax.persistence.EnumType; +import javax.persistence.TemporalType; + +import org.hibernate.HibernateException; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.metamodel.source.internal.jaxb.JaxbMapKey; +import org.hibernate.metamodel.source.internal.jaxb.JaxbMapKeyClass; +import org.hibernate.metamodel.source.internal.jaxb.JaxbMapKeyColumn; +import org.hibernate.metamodel.source.internal.jaxb.JaxbMapKeyJoinColumn; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; @@ -32,20 +43,10 @@ import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; -import org.hibernate.HibernateException; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; -import org.hibernate.jaxb.spi.orm.JaxbEnumType; -import org.hibernate.jaxb.spi.orm.JaxbMapKey; -import org.hibernate.jaxb.spi.orm.JaxbMapKeyClass; -import org.hibernate.jaxb.spi.orm.JaxbMapKeyColumn; -import org.hibernate.jaxb.spi.orm.JaxbMapKeyJoinColumn; -import org.hibernate.jaxb.spi.orm.JaxbTemporalType; - /** * @author Strong Liu */ -abstract class PropertyMocker extends AnnotationMocker { +public abstract class PropertyMocker extends AnnotationMocker { protected ClassInfo classInfo; private AnnotationTarget target; @@ -53,7 +54,8 @@ abstract class PropertyMocker extends AnnotationMocker { super( indexBuilder, defaults ); this.classInfo = classInfo; } - protected abstract PropertyElement getPropertyElement(); + + protected abstract PersistentAttribute getPersistentAttribute(); protected abstract void processExtra(); @Override @@ -63,10 +65,10 @@ abstract class PropertyMocker extends AnnotationMocker { protected void resolveTarget() { //attribute in orm.xml has access sub-element - JaxbAccessType accessType = getPropertyElement().getAccess(); + AccessType accessType = getPersistentAttribute().getAccess(); if ( accessType == null ) { //attribute in the entity class has @Access - accessType = AccessHelper.getAccessFromAttributeAnnotation( getTargetName(), getPropertyElement().getName(), indexBuilder ); + accessType = AccessHelper.getAccessFromAttributeAnnotation( getTargetName(), getPersistentAttribute().getName(), indexBuilder ); if ( accessType == null ) { accessType = AccessHelper.getEntityAccess( getTargetName(), indexBuilder ); } @@ -78,10 +80,10 @@ abstract class PropertyMocker extends AnnotationMocker { accessType = AccessHelper.getAccessFromDefault( indexBuilder ); } if ( accessType == null ) { - accessType = JaxbAccessType.PROPERTY; + accessType = AccessType.PROPERTY; } - getPropertyElement().setAccess( accessType ); + getPersistentAttribute().setAccess( accessType ); } } @@ -89,12 +91,12 @@ abstract class PropertyMocker extends AnnotationMocker { @Override protected AnnotationTarget getTarget() { if ( target == null ) { - target = getTargetFromAttributeAccessType( getPropertyElement().getAccess() ); + target = getTargetFromAttributeAccessType( getPersistentAttribute().getAccess() ); } return target; } - protected AnnotationTarget getTargetFromAttributeAccessType(JaxbAccessType accessType) { + protected AnnotationTarget getTargetFromAttributeAccessType(AccessType accessType) { if ( accessType == null ) { throw new IllegalArgumentException( "access type can't be null." ); } @@ -103,14 +105,14 @@ abstract class PropertyMocker extends AnnotationMocker { return MockHelper.getTarget( indexBuilder.getServiceRegistry(), classInfo, - getPropertyElement().getName(), + getPersistentAttribute().getName(), MockHelper.TargetType.FIELD ); case PROPERTY: return MockHelper.getTarget( indexBuilder.getServiceRegistry(), classInfo, - getPropertyElement().getName(), + getPersistentAttribute().getName(), MockHelper.TargetType.PROPERTY ); default: @@ -154,7 +156,7 @@ abstract class PropertyMocker extends AnnotationMocker { ); } - protected AnnotationInstance parseMapKeyTemporal(JaxbTemporalType temporalType, AnnotationTarget target) { + protected AnnotationInstance parseMapKeyTemporal(TemporalType temporalType, AnnotationTarget target) { if ( temporalType == null ) { return null; } @@ -164,7 +166,7 @@ abstract class PropertyMocker extends AnnotationMocker { ); } - protected AnnotationInstance parseMapKeyEnumerated(JaxbEnumType enumType, AnnotationTarget target) { + protected AnnotationInstance parseMapKeyEnumerated(EnumType enumType, AnnotationTarget target) { if ( enumType == null ) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/PseudoJpaDotNames.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PseudoJpaDotNames.java similarity index 97% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/PseudoJpaDotNames.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PseudoJpaDotNames.java index f2de81d23a..5da6e29758 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/PseudoJpaDotNames.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/PseudoJpaDotNames.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml; +package org.hibernate.metamodel.source.internal.jandex; import org.jboss.jandex.DotName; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/TransientMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/TransientMocker.java similarity index 69% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/TransientMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/TransientMocker.java index 06f8d1badd..5f5e21fcb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/TransientMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/TransientMocker.java @@ -21,36 +21,48 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; + +import javax.persistence.AccessType; + +import org.hibernate.metamodel.source.internal.jaxb.JaxbTransient; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbAccessType; -import org.hibernate.jaxb.spi.orm.JaxbTransient; - /** * @author Strong Liu */ -class TransientMocker extends PropertyMocker { +public class TransientMocker extends PropertyMocker { private final JaxbTransient transientObj; - private final PropertyElement wrapper; + private final PersistentAttribute wrapper; TransientMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, final JaxbTransient transientObj) { super( indexBuilder, classInfo, defaults ); this.transientObj = transientObj; - this.wrapper = new PropertyElement() { + this.wrapper = new PersistentAttribute() { @Override public String getName() { return transientObj.getName(); } @Override - public JaxbAccessType getAccess() { - return JaxbAccessType.FIELD; + public AccessType getAccess() { + return AccessType.FIELD; } @Override - public void setAccess(JaxbAccessType accessType) { + public void setAccess(AccessType accessType) { + } + + @Override + public String getCustomAccess() { + return null; + } + + @Override + public void setCustomAccess(String customAccess) { + } }; } @@ -61,7 +73,7 @@ class TransientMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return wrapper; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/Unifier.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/Unifier.java new file mode 100644 index 0000000000..4977852292 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/Unifier.java @@ -0,0 +1,85 @@ +/* + * 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.jandex; + +import java.util.List; + +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jaxb.JaxbPersistenceUnitMetadata; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.xml.spi.BindResult; + +import org.jboss.jandex.IndexView; + +/** + * Responsible for consolidating mapping information supplied by annotations and mapping information + * supplied by XML into a unified view. + *

+ * Ultimately we are building a Jandex {@link org.jboss.jandex.IndexView} which is a de-typed (and + * classloading safe!) representation of annotations. We add virtual annotation information into the + * Jandex to represent XML supplied information. + * + * @author Steve Ebersole + * @author Strong Liu + */ +public class Unifier { + private static final CoreMessageLogger log = CoreLogging.messageLogger( Unifier.class ); + + // todo : per Jason, it is bad if we create a CompositeIndex where multiple of the aggregated indexes contain the same classes. + + public static IndexView unify( + IndexView initialJandex, + List> xmlBindings, + ServiceRegistry serviceRegistry) { + if ( xmlBindings == null || xmlBindings.isEmpty() ) { + // if there is no XML information, just return the original index + return initialJandex; + } + + JaxbPersistenceUnitMetadata persistenceUnitMetadata = null; + + for ( BindResult xmlBinding : xmlBindings ) { + if ( xmlBinding.getRoot().getPersistenceUnitMetadata() != null ) { + if ( persistenceUnitMetadata == null ) { + log.debugf( "Using located in %s", xmlBinding.getOrigin() ); + persistenceUnitMetadata = xmlBinding.getRoot().getPersistenceUnitMetadata(); + } + else { + // todo : parameterize duplicateMetadata() to accept the origin + log.duplicateMetadata(); + log.debugf( + "Encountered in %s after previously " + + "encountered one; keeping original", + xmlBinding.getOrigin() + ); + } + } + } + + // for now, simply hook into the existing code... + return new EntityMappingsMocker( xmlBindings, initialJandex, serviceRegistry ).mockNewIndex(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/VersionMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/VersionMocker.java similarity index 83% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/VersionMocker.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/VersionMocker.java index b204da80b6..a237aa0cb7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/VersionMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/VersionMocker.java @@ -21,16 +21,17 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +package org.hibernate.metamodel.source.internal.jandex; + +import org.hibernate.metamodel.source.internal.jaxb.JaxbVersion; +import org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute; import org.jboss.jandex.ClassInfo; -import org.hibernate.jaxb.spi.orm.JaxbVersion; - /** * @author Strong Liu */ -class VersionMocker extends PropertyMocker { +public class VersionMocker extends PropertyMocker { private final JaxbVersion version; VersionMocker(IndexBuilder indexBuilder, ClassInfo classInfo, EntityMappingsMocker.Default defaults, JaxbVersion version) { @@ -39,9 +40,10 @@ class VersionMocker extends PropertyMocker { } @Override - protected PropertyElement getPropertyElement() { + protected PersistentAttribute getPersistentAttribute() { return version; } + @Override protected void processExtra() { create( VERSION ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/AbstractAnnotationFilter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/AbstractAnnotationFilter.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/AbstractAnnotationFilter.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/AbstractAnnotationFilter.java index 75f2c19e71..407adad531 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/AbstractAnnotationFilter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/AbstractAnnotationFilter.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.filter; +package org.hibernate.metamodel.source.internal.jandex.filter; import java.util.Arrays; import java.util.HashSet; @@ -32,7 +32,7 @@ import java.util.Set; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.DotName; -import org.hibernate.metamodel.internal.source.annotations.xml.mocker.IndexBuilder; +import org.hibernate.metamodel.source.internal.jandex.IndexBuilder; /** * @author Strong Liu diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/ExclusiveAnnotationFilter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/ExclusiveAnnotationFilter.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/ExclusiveAnnotationFilter.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/ExclusiveAnnotationFilter.java index bc0510b717..2492aeed42 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/ExclusiveAnnotationFilter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/ExclusiveAnnotationFilter.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.filter; +package org.hibernate.metamodel.source.internal.jandex.filter; import java.util.ArrayList; import java.util.Collections; @@ -35,7 +35,7 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.DotName; -import org.hibernate.metamodel.internal.source.annotations.xml.mocker.MockHelper; +import org.hibernate.metamodel.source.internal.jandex.MockHelper; /** * @author Strong Liu @@ -168,7 +168,7 @@ class ExclusiveAnnotationFilter extends AbstractAnnotationFilter { Scope scope = Scope.ATTRIBUTE; @Override - public Iterator iterator() { + public Iterator iterator() { return names.iterator(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/IndexedAnnotationFilter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/IndexedAnnotationFilter.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/IndexedAnnotationFilter.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/IndexedAnnotationFilter.java index 203fc03415..6a6521ffe2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/IndexedAnnotationFilter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/IndexedAnnotationFilter.java @@ -21,13 +21,13 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.filter; +package org.hibernate.metamodel.source.internal.jandex.filter; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.DotName; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; -import org.hibernate.metamodel.internal.source.annotations.xml.mocker.IndexBuilder; +import org.hibernate.metamodel.source.internal.jandex.IndexBuilder; /** * @author Strong Liu diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/NameAnnotationFilter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/NameAnnotationFilter.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/NameAnnotationFilter.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/NameAnnotationFilter.java index fad2c811be..0c15509609 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/NameAnnotationFilter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/NameAnnotationFilter.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.filter; +package org.hibernate.metamodel.source.internal.jandex.filter; import java.util.List; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/NameTargetAnnotationFilter.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/NameTargetAnnotationFilter.java similarity index 62% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/NameTargetAnnotationFilter.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/NameTargetAnnotationFilter.java index 0124f96810..305114bc4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/filter/NameTargetAnnotationFilter.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/filter/NameTargetAnnotationFilter.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.filter; +package org.hibernate.metamodel.source.internal.jandex.filter; import java.util.Iterator; import java.util.List; @@ -30,8 +30,7 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.DotName; -import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; -import org.hibernate.metamodel.internal.source.annotations.xml.mocker.MockHelper; +import org.hibernate.metamodel.source.internal.jandex.MockHelper; /** * @author Strong Liu @@ -51,42 +50,42 @@ class NameTargetAnnotationFilter extends AbstractAnnotationFilter { public static NameTargetAnnotationFilter INSTANCE = new NameTargetAnnotationFilter(); private static final DotName[] TARGET_ANNOTATIONS = new DotName[] { - JPADotNames.LOB, - JPADotNames.ID, - JPADotNames.BASIC, - JPADotNames.GENERATED_VALUE, - JPADotNames.VERSION, - JPADotNames.TRANSIENT, - JPADotNames.ACCESS, - JPADotNames.POST_LOAD, - JPADotNames.POST_PERSIST, - JPADotNames.POST_REMOVE, - JPADotNames.POST_UPDATE, - JPADotNames.PRE_PERSIST, - JPADotNames.PRE_REMOVE, - JPADotNames.PRE_UPDATE, - JPADotNames.EMBEDDED_ID, - JPADotNames.EMBEDDED, - JPADotNames.MANY_TO_ONE, - JPADotNames.MANY_TO_MANY, - JPADotNames.ONE_TO_ONE, - JPADotNames.ONE_TO_MANY, - JPADotNames.ELEMENT_COLLECTION, - JPADotNames.COLLECTION_TABLE, - JPADotNames.COLUMN, - JPADotNames.ENUMERATED, - JPADotNames.JOIN_TABLE, - JPADotNames.TEMPORAL, - JPADotNames.ORDER_BY, - JPADotNames.ORDER_COLUMN, - JPADotNames.JOIN_COLUMN, - JPADotNames.JOIN_COLUMNS, - JPADotNames.MAPS_ID, - JPADotNames.MAP_KEY_TEMPORAL, - JPADotNames.MAP_KEY, - JPADotNames.MAP_KEY_CLASS, - JPADotNames.MAP_KEY_COLUMN, - JPADotNames.MAP_KEY_ENUMERATED + LOB, + ID, + BASIC, + GENERATED_VALUE, + VERSION, + TRANSIENT, + ACCESS, + POST_LOAD, + POST_PERSIST, + POST_REMOVE, + POST_UPDATE, + PRE_PERSIST, + PRE_REMOVE, + PRE_UPDATE, + EMBEDDED_ID, + EMBEDDED, + MANY_TO_ONE, + MANY_TO_MANY, + ONE_TO_ONE, + ONE_TO_MANY, + ELEMENT_COLLECTION, + COLLECTION_TABLE, + COLUMN, + ENUMERATED, + JOIN_TABLE, + TEMPORAL, + ORDER_BY, + ORDER_COLUMN, + JOIN_COLUMN, + JOIN_COLUMNS, + MAPS_ID, + MAP_KEY_TEMPORAL, + MAP_KEY, + MAP_KEY_CLASS, + MAP_KEY_COLUMN, + MAP_KEY_ENUMERATED }; @Override protected DotName[] targetAnnotation() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/AttributesContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/AttributesContainer.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/AttributesContainer.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/AttributesContainer.java index de6cab496b..7216175c45 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/AttributesContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/AttributesContainer.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source.jaxb; +package org.hibernate.metamodel.source.internal.jaxb; import java.util.List; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/LifecycleCallback.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/LifecycleCallback.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/LifecycleCallback.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/LifecycleCallback.java index c0caf7f3f0..1f800f892e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/LifecycleCallback.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/LifecycleCallback.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source.jaxb; +package org.hibernate.metamodel.source.internal.jaxb; /** * Common interface for all the JAXB bindings representing lifecycle callbacks. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ManagedType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/ManagedType.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ManagedType.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/ManagedType.java index 8230cb56b2..2befc6630b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ManagedType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/ManagedType.java @@ -21,7 +21,9 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source.jaxb; +package org.hibernate.metamodel.source.internal.jaxb; + +import javax.persistence.AccessType; /** * Common interface for JAXB bindings representing entities, mapped-superclasses and embeddables (JPA collective @@ -38,5 +40,5 @@ public interface ManagedType { Boolean isMetadataComplete(); void setMetadataComplete(Boolean isMetadataComplete); - public JaxbAccessType getAccess(); + public AccessType getAccess(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/Parameterized.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/Parameterized.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/Parameterized.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/Parameterized.java index 95b23f7054..eea52887c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/Parameterized.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/Parameterized.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source.jaxb; +package org.hibernate.metamodel.source.internal.jaxb; import java.util.List; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/PersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/PersistentAttribute.java similarity index 89% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/PersistentAttribute.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/PersistentAttribute.java index 92aaed56ee..5879373a81 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/PersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/PersistentAttribute.java @@ -21,7 +21,9 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source.jaxb; +package org.hibernate.metamodel.source.internal.jaxb; + +import javax.persistence.AccessType; /** * Common interface for JAXB bindings that represent persistent attributes. @@ -32,11 +34,9 @@ package org.hibernate.metamodel.spi.source.jaxb; public interface PersistentAttribute { String getName(); - JaxbAccessType getAccess(); - - void setAccess(JaxbAccessType accessType); + AccessType getAccess(); + void setAccess(AccessType accessType); String getCustomAccess(); - void setCustomAccess(String customAccess); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/SchemaAware.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/SchemaAware.java similarity index 96% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/SchemaAware.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/SchemaAware.java index 7a469f6402..515d9dedf9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/SchemaAware.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/SchemaAware.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source.jaxb; +package org.hibernate.metamodel.source.internal.jaxb; /** * Common interface for JAXB bindings that understand database schema (tables, sequences, etc). diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ToolingHintContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/ToolingHintContainer.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ToolingHintContainer.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/ToolingHintContainer.java index 26365c1abb..0d647be6c7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ToolingHintContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/ToolingHintContainer.java @@ -21,7 +21,7 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.spi.source.jaxb; +package org.hibernate.metamodel.source.internal.jaxb; import java.util.List; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/AccessTypeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/AccessTypeMarshalling.java new file mode 100644 index 0000000000..f41b3b8707 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/AccessTypeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import javax.persistence.AccessType; + +/** + * Marshalling support for dealing with JPA AccessType enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class AccessTypeMarshalling { + public static AccessType fromXml(String name) { + return AccessType.valueOf( name ); + } + + public static String toXml(AccessType accessType) { + return accessType.name(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/DiscriminatorTypeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/DiscriminatorTypeMarshalling.java new file mode 100644 index 0000000000..96e139b915 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/DiscriminatorTypeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import javax.persistence.DiscriminatorType; + +/** + * Marshalling support for dealing with JPA DiscriminatorType enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class DiscriminatorTypeMarshalling { + public static DiscriminatorType fromXml(String name) { + return DiscriminatorType.valueOf( name ); + } + + public static String toXml(DiscriminatorType discriminatorType) { + return discriminatorType.name(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/EnumTypeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/EnumTypeMarshalling.java new file mode 100644 index 0000000000..7d704b9a3d --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/EnumTypeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import javax.persistence.EnumType; + +/** + * Marshalling support for dealing with JPA EnumType enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class EnumTypeMarshalling { + public static EnumType fromXml(String name) { + return EnumType.valueOf( name ); + } + + public static String toXml(EnumType enumType) { + return enumType.name(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FetchTypeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FetchTypeMarshalling.java new file mode 100644 index 0000000000..d9eada84c8 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FetchTypeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import javax.persistence.FetchType; + +/** + * Marshalling support for dealing with JPA FetchType enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class FetchTypeMarshalling { + public static FetchType fromXml(String name) { + return FetchType.valueOf( name ); + } + + public static String toXml(FetchType fetchType) { + return fetchType.name(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FlushModeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FlushModeMarshalling.java new file mode 100644 index 0000000000..18ae1347d9 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/FlushModeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import org.hibernate.FlushMode; + +/** + * Marshalling support for dealing with Hibernate FlushMode enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class FlushModeMarshalling { + public static FlushMode fromXml(String name) { + return FlushMode.interpretExternalSetting( name ); + } + + public static String toXml(FlushMode flushMode) { + return flushMode.toExternalForm(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/LockModeTypeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/LockModeTypeMarshalling.java new file mode 100644 index 0000000000..9f0ffc4a36 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/LockModeTypeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import javax.persistence.LockModeType; + +/** + * Marshalling support for dealing with JPA LockModeType enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class LockModeTypeMarshalling { + public static LockModeType fromXml(String name) { + return LockModeType.valueOf( name ); + } + + public static String toXml(LockModeType lockModeType) { + return lockModeType.name(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/ParameterModeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/ParameterModeMarshalling.java new file mode 100644 index 0000000000..1c8b1893c6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/ParameterModeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import javax.persistence.ParameterMode; + +/** + * Marshalling support for dealing with JPA ParameterMode enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class ParameterModeMarshalling { + public static ParameterMode fromXml(String name) { + return ParameterMode.valueOf( name ); + } + + public static String toXml(ParameterMode parameterMode) { + return parameterMode.name(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/TemporalTypeMarshalling.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/TemporalTypeMarshalling.java new file mode 100644 index 0000000000..a5e704cc83 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/marshalling/TemporalTypeMarshalling.java @@ -0,0 +1,41 @@ +/* + * 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.jaxb.marshalling; + +import javax.persistence.TemporalType; + +/** + * Marshalling support for dealing with JPA TemporalType enums. Plugged into JAXB for binding + * + * @author Steve Ebersole + */ +public class TemporalTypeMarshalling { + public static TemporalType fromXml(String name) { + return TemporalType.valueOf( name ); + } + + public static String toXml(TemporalType temporalType) { + return temporalType.name(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/SchemaAware.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/package-info.java similarity index 72% rename from hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/SchemaAware.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/package-info.java index 6b3be43835..c01c20c7ad 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/SchemaAware.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/package-info.java @@ -1,10 +1,10 @@ /* * Hibernate, Relational Persistence for Idiomatic Java * - * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * 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.. + * 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 @@ -21,17 +21,8 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.metamodel.internal.source.annotations.xml.mocker; /** - * @author Strong Liu + * todo : Move org.hibernate.metamodel.spi.source here */ -public interface SchemaAware { - String getSchema(); - - void setSchema(String schema); - - String getCatalog(); - - void setCatalog(String catalog); -} +package org.hibernate.metamodel.source.spi; diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder.java index 6c042c2e5e..74adb6e1c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder.java @@ -55,7 +55,10 @@ import org.hibernate.xml.spi.XmlBinder; * * @author Steve Ebersole * @author Strong Liu + * + * @deprecated See {@link AbstractUnifiedBinder} */ +@Deprecated abstract class AbstractXmlBinder implements XmlBinder { protected static final Logger log = Logger.getLogger( AbstractXmlBinder.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/HbmEventReader.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/HbmEventReader.java new file mode 100644 index 0000000000..8cd26571f1 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/HbmEventReader.java @@ -0,0 +1,105 @@ +/* + * 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.xml.internal.jaxb; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLEventFactory; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.events.Namespace; +import javax.xml.stream.events.StartElement; +import javax.xml.stream.events.XMLEvent; +import javax.xml.stream.util.EventReaderDelegate; + +import org.hibernate.xml.internal.stax.LocalSchema; + +/** + * @author Steve Ebersole + */ +public class HbmEventReader extends EventReaderDelegate { + private static final List NAMESPACE_URIS_TO_MAP = Arrays.asList( + // the initial (premature) hbm.xml xsd namespace + "http://www.hibernate.org/xsd/hibernate-mapping" + ); + + private final XMLEventFactory xmlEventFactory; + + public HbmEventReader(XMLEventReader reader) { + this( reader, XMLEventFactory.newInstance() ); + } + + public HbmEventReader(XMLEventReader reader, XMLEventFactory xmlEventFactory) { + super( reader ); + this.xmlEventFactory = xmlEventFactory; + } + + @Override + public XMLEvent peek() throws XMLStreamException { + return wrap( super.peek() ); + } + + @Override + public XMLEvent nextEvent() throws XMLStreamException { + return wrap( super.nextEvent() ); + } + + private XMLEvent wrap(XMLEvent event) { + if ( event != null && event.isStartElement() ) { + return applyNamespace( event.asStartElement() ); + } + return event; + } + + @SuppressWarnings("unchecked") + private StartElement applyNamespace(StartElement startElement) { + final List targetNamespaces = new ArrayList(); + + if ( "".equals( startElement.getName().getNamespaceURI() ) ) { + // add the default namespace mapping + targetNamespaces.add( xmlEventFactory.createNamespace( LocalSchema.HBM.getNamespaceUri() ) ); + } + + // transfer any namespaces directly, unless it is in the "to map" list in which case + // we transfer a mapped copy pointing to the new namespace + final Iterator originalNamespaces = startElement.getNamespaces(); + while ( originalNamespaces.hasNext() ) { + Namespace namespace = originalNamespaces.next(); + if ( NAMESPACE_URIS_TO_MAP.contains( namespace.getNamespaceURI() ) ) { + // this is a namespace "to map" so map it + namespace = xmlEventFactory.createNamespace( namespace.getPrefix(), LocalSchema.HBM.getNamespaceUri() ); + } + targetNamespaces.add( namespace ); + } + + return xmlEventFactory.createStartElement( + new QName( LocalSchema.HBM.getNamespaceUri(), startElement.getName().getLocalPart() ), + startElement.getAttributes(), + targetNamespaces.iterator() + ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/MappingXmlBinder.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/MappingXmlBinder.java index 472cefe599..1799b5526f 100644 --- a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/MappingXmlBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/MappingXmlBinder.java @@ -26,36 +26,34 @@ package org.hibernate.xml.internal.jaxb; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; -import javax.xml.namespace.QName; import javax.xml.stream.XMLEventReader; -import javax.xml.stream.events.Attribute; import javax.xml.stream.events.XMLEvent; import javax.xml.transform.dom.DOMSource; import javax.xml.validation.Schema; -import org.jboss.logging.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; import org.hibernate.internal.util.StringHelper; -import org.hibernate.xml.internal.stax.LocalXmlResourceResolver; +import org.hibernate.jaxb.spi.hbm.JaxbHibernateMapping; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.spi.source.MappingException; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.xml.internal.stax.LocalSchema; import org.hibernate.xml.internal.stax.SupportedOrmXsdVersion; import org.hibernate.xml.spi.BindResult; import org.hibernate.xml.spi.Origin; -import org.hibernate.jaxb.spi.hbm.JaxbHibernateMapping; -import org.hibernate.jaxb.spi.orm.JaxbEntityMappings; -import org.hibernate.metamodel.spi.source.MappingException; -import org.hibernate.service.ServiceRegistry; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * Loads {@code hbm.xml} and {@code orm.xml} files and processes them using StAX and JAXB. * * @author Steve Ebersole * @author Hardy Ferentschik + * + * @deprecated see {@link org.hibernate.xml.internal.jaxb.UnifiedMappingBinder} */ +@Deprecated public class MappingXmlBinder extends AbstractXmlBinder { - private static final Logger log = Logger.getLogger( MappingXmlBinder.class ); - public static final String HIBERNATE_MAPPING_URI = "http://www.hibernate.org/xsd/hibernate-mapping"; - public MappingXmlBinder(ServiceRegistry serviceRegistry) { this( serviceRegistry, true ); } @@ -64,12 +62,6 @@ public class MappingXmlBinder extends AbstractXmlBinder { super(serviceRegistry, validateXml); } - // todo : DO THIS! - // the goal here ultimately is to: - // 1) use one "combined" XSD for both orm.xml and hbm.xml features (HHH-8893) - // 2) always always always validate against the latest version of that XSD (HHH-8894) - // 3) profit! - @Override protected JAXBContext getJaxbContext(XMLEvent event) throws JAXBException { final String elementName = event.asStartElement().getName().getLocalPart(); @@ -88,9 +80,7 @@ public class MappingXmlBinder extends AbstractXmlBinder { final String elementName = event.asStartElement().getName().getLocalPart(); final Schema validationSchema; if ( "entity-mappings".equals( elementName ) ) { - final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME ); - final String explicitVersion = attribute == null ? null : attribute.getValue(); - validationSchema = validateXml ? resolveSupportedOrmXsd( explicitVersion, origin ) : null; + return LocalSchema.MAPPING.getSchema(); } else { validationSchema = validateXml ? SupportedOrmXsdVersion.HBM_4_0.getSchema() : null; @@ -102,30 +92,13 @@ public class MappingXmlBinder extends AbstractXmlBinder { protected XMLEventReader wrapReader(XMLEventReader staxEventReader, XMLEvent event) { final String elementName = event.asStartElement().getName().getLocalPart(); if ( "entity-mappings".equals( elementName ) ) { - final Attribute attribute = event.asStartElement().getAttributeByName( ORM_VERSION_ATTRIBUTE_QNAME ); - final String explicitVersion = attribute == null ? null : attribute.getValue(); - if ( !"2.1".equals( explicitVersion ) ) { - return new LegacyJPAEventReader( - staxEventReader, - LocalXmlResourceResolver.SECOND_JPA_ORM_NS - ); - } + return new UnifiedMappingEventReader( staxEventReader ); } else { - if ( !isNamespaced( event.asStartElement() ) ) { - // if the elements are not namespaced, wrap the reader in a reader which will namespace them as pulled. - log.debug( "HBM mapping document did not define namespaces; wrapping in custom event reader to introduce namespace information" ); - return new NamespaceAddingEventReader( staxEventReader, HIBERNATE_MAPPING_URI ); - } + return new HbmEventReader( staxEventReader ); } - return super.wrapReader( staxEventReader, event ); } - private static final QName ORM_VERSION_ATTRIBUTE_QNAME = new QName( "version" ); - - - - @SuppressWarnings( { "unchecked" }) public BindResult bind(Document document, Origin origin) { diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingBinder.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingBinder.java index d97e6ae11f..17ffbe052f 100644 --- a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingBinder.java @@ -28,7 +28,7 @@ import javax.xml.stream.events.StartElement; import org.hibernate.jaxb.spi.hbm.JaxbHibernateMapping; import org.hibernate.metamodel.internal.source.hbm.transform.HbmXmlTransformer; -import org.hibernate.metamodel.spi.source.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; import org.hibernate.xml.internal.stax.LocalSchema; import org.hibernate.xml.spi.Origin; @@ -40,7 +40,7 @@ import org.jboss.logging.Logger; * @author Steve Ebersole */ public class UnifiedMappingBinder extends AbstractUnifiedBinder { - private static final Logger log = Logger.getLogger( MappingXmlBinder.class ); + private static final Logger log = Logger.getLogger( UnifiedMappingBinder.class ); public UnifiedMappingBinder() { super(); @@ -59,19 +59,12 @@ public class UnifiedMappingBinder extends AbstractUnifiedBinder namespacesItr; if ( "entity-mappings".equals( startElement.getName().getLocalPart() ) ) { - final List targetAttributeList = new ArrayList(); final List targetNamespaces = new ArrayList(); - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // attributes are pretty straight-forward; copy over any attributes - // *except* the version attribute and then add our specific unified - // schema version explicitly - final Iterator originalAttributes = startElement.getAttributes(); - while ( originalAttributes.hasNext() ) { - final Attribute attribute = originalAttributes.next(); - if ( !"version".equals( attribute.getName().getLocalPart() ) ) { - targetAttributeList.add( attribute ); - } - } - targetAttributeList.add( xmlEventFactory.createAttribute( "version", LocalSchema.MAPPING.getCurrentVersion() ) ); - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // namespaces are a little more complicated. We copy over all namespaces, // but if any uris match known JPA namespaces which point that given @@ -119,7 +104,7 @@ public class UnifiedMappingEventReader extends EventReaderDelegate { targetNamespaces.add( namespace ); } - attributesItr = targetAttributeList.iterator(); + attributesItr = startElement.getAttributes(); namespacesItr = targetNamespaces.iterator(); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchema.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchema.java index 761d015632..84f52423d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchema.java +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchema.java @@ -42,13 +42,13 @@ public enum LocalSchema { "org/hibernate/xsd/mapping/mapping-2.1.0.xsd", "2.1.0" ), - LEGACY_HBM( + HBM( "http://www.hibernate.org/xsd/orm/hbm", "org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd", "4.0" ) // , CONFIGURATION( ) -// , LEGACY_CONFIGURATON( ) +// , CFG( ) ; private static final Logger log = Logger.getLogger( LocalSchema.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/xml/spi/Origin.java b/hibernate-core/src/main/java/org/hibernate/xml/spi/Origin.java index a7dbe7d9a6..67693942f8 100644 --- a/hibernate-core/src/main/java/org/hibernate/xml/spi/Origin.java +++ b/hibernate-core/src/main/java/org/hibernate/xml/spi/Origin.java @@ -24,6 +24,7 @@ package org.hibernate.xml.spi; import java.io.Serializable; +import java.util.Locale; /** * Describes the origin of an xml document @@ -31,6 +32,8 @@ import java.io.Serializable; * @author Steve Ebersole */ public class Origin implements Serializable { + public static final String UNKNOWN_FILE_PATH = ""; + private final SourceType type; private final String name; @@ -88,9 +91,6 @@ public class Origin implements Serializable { @Override public String toString() { - return "Origin{" + - "name='" + name + '\'' + - ", type=" + type + - '}'; + return String.format( Locale.ENGLISH, "Origin(name=%s,type=%s)", name, type ); } } diff --git a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd index e23c46d707..7797ee1c60 100644 --- a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/legacy-mapping-4.0.xsd @@ -315,8 +315,6 @@ - - diff --git a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-2.1.0.xsd b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-2.1.0.xsd index 5ceb0346d4..eb94b56464 100644 --- a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-2.1.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/mapping-2.1.0.xsd @@ -118,7 +118,7 @@ - + @@ -132,7 +132,10 @@ - + + + + @@ -222,9 +225,7 @@ - The JPA "attribute access" enumeration, declaring the discrete set of values - describing how the persistence provider accesses the state of an entity or - embedded object. + javax.persistence.AccessType enum values @@ -443,7 +444,7 @@ - Enumeration values for Hibernate's CacheMode + org.hibernate.CacheMode enum values @@ -462,7 +463,7 @@ - public enum CascadeType { ALL, PERSIST, MERGE, REMOVE, REFRESH, DETACH}; + javax.persistence.CascadeType enum values @@ -584,9 +585,7 @@ - - public enum DiscriminatorType { STRING, CHAR, INTEGER }; - + javax.persistence.DiscriminatorType enum values @@ -961,7 +960,7 @@ - Enumerated values specified by javax.persistence.EnumType + javax.persistence.EnumType enum values @@ -988,7 +987,7 @@ - Enumerated values specified by javax.persistence.FetchType + javax.persistence.FetchType enum values @@ -1003,7 +1002,7 @@ - Enumeration values for Hibernate's FlushMode + org.hibernate.FlushMode enum values @@ -1047,7 +1046,9 @@ - Enumerated values specified by javax.persistence.GenerationType + javax.persistence.GenerationType rnum values + + todo : add custom ones like INCREMENT, UUID, etc @@ -1151,6 +1152,8 @@ Corresponds to the JPA InheritanceType enumeration values + Hibernate's UNION_SUBCLASS + + todo : make a singular enum to cover these @@ -1226,7 +1229,7 @@ - Enumerated values specified by javax.persistence.LockModeType + javax.persistence.LockModeType enum values @@ -1641,7 +1644,7 @@ - Corresponds to enumerated values defined by javax.persistence.ParameterMode + javax.persistence.ParameterMode enum values @@ -2146,7 +2149,7 @@ - javax.persistence.TemporalType enum + javax.persistence.TemporalType enum values diff --git a/hibernate-core/src/main/xjb/mapping-bindings.xjb b/hibernate-core/src/main/xjb/mapping-bindings.xjb index 42a993f4fa..b787a32e19 100644 --- a/hibernate-core/src/main/xjb/mapping-bindings.xjb +++ b/hibernate-core/src/main/xjb/mapping-bindings.xjb @@ -8,7 +8,7 @@ - + @@ -17,35 +17,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer - org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + org.hibernate.metamodel.source.internal.jaxb.ToolingHintContainer @@ -56,103 +104,103 @@ - org.hibernate.metamodel.spi.source.jaxb.Parameterized + org.hibernate.metamodel.source.internal.jaxb.Parameterized - org.hibernate.metamodel.spi.source.jaxb.SchemaAware + org.hibernate.metamodel.source.internal.jaxb.SchemaAware - org.hibernate.metamodel.spi.source.jaxb.SchemaAware + org.hibernate.metamodel.source.internal.jaxb.SchemaAware - org.hibernate.metamodel.spi.source.jaxb.SchemaAware + org.hibernate.metamodel.source.internal.jaxb.SchemaAware - org.hibernate.metamodel.spi.source.jaxb.SchemaAware + org.hibernate.metamodel.source.internal.jaxb.SchemaAware - org.hibernate.metamodel.spi.source.jaxb.SchemaAware + org.hibernate.metamodel.source.internal.jaxb.SchemaAware - org.hibernate.metamodel.spi.source.jaxb.SchemaAware + org.hibernate.metamodel.source.internal.jaxb.SchemaAware - org.hibernate.metamodel.spi.source.jaxb.ManagedType + org.hibernate.metamodel.source.internal.jaxb.ManagedType - org.hibernate.metamodel.spi.source.jaxb.ManagedType + org.hibernate.metamodel.source.internal.jaxb.ManagedType - org.hibernate.metamodel.spi.source.jaxb.ManagedType + org.hibernate.metamodel.source.internal.jaxb.ManagedType - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + org.hibernate.metamodel.source.internal.jaxb.PersistentAttribute - org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback - org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback - org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback - org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback - org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback - org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback - org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + org.hibernate.metamodel.source.internal.jaxb.LifecycleCallback - org.hibernate.metamodel.spi.source.jaxb.AttributesContainer + org.hibernate.metamodel.source.internal.jaxb.AttributesContainer - org.hibernate.metamodel.spi.source.jaxb.AttributesContainer + org.hibernate.metamodel.source.internal.jaxb.AttributesContainer diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMockerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMockerTest.java index 0343f71119..c9571b4e15 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMockerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/AbstractMockerTest.java @@ -30,7 +30,9 @@ import java.util.List; import org.hibernate.HibernateException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.jaxb.spi.orm.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; +import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker; +import org.hibernate.metamodel.source.internal.jandex.IndexBuilder; import org.hibernate.service.ServiceRegistry; import org.hibernate.xml.internal.jaxb.MappingXmlBinder; import org.hibernate.xml.spi.BindResult; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/BasicMockerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/BasicMockerTest.java index e58c852025..52a5f3c9f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/BasicMockerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/BasicMockerTest.java @@ -29,11 +29,14 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.junit.Test; -import org.hibernate.jaxb.spi.orm.JaxbAttributes; -import org.hibernate.jaxb.spi.orm.JaxbEntity; -import org.hibernate.jaxb.spi.orm.JaxbGeneratedValue; -import org.hibernate.jaxb.spi.orm.JaxbId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbGeneratedValue; +import org.hibernate.metamodel.source.internal.jaxb.JaxbId; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker; +import org.hibernate.metamodel.source.internal.jandex.EntityMocker; +import org.hibernate.metamodel.source.internal.jandex.IndexBuilder; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java index 7b3d111778..315a4b87da 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/DefaultConfigurationHelperTest.java @@ -18,8 +18,10 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.junit.Test; -import org.hibernate.jaxb.spi.orm.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.internal.jandex.DefaultConfigurationHelper; +import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityListenerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityListenerTest.java index fc50ac24a3..5dd31d0bd4 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityListenerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/EntityListenerTest.java @@ -29,7 +29,7 @@ import org.jboss.jandex.Index; import org.junit.Test; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; -import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; +import org.hibernate.metamodel.source.internal.jandex.PseudoJpaDotNames; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilderTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilderTest.java index 1ccdb21128..6b79b41bf5 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/IndexBuilderTest.java @@ -1,5 +1,7 @@ package org.hibernate.metamodel.internal.source.annotations.xml.mocker; +import org.hibernate.metamodel.source.internal.jandex.IndexBuilder; + import org.junit.Test; /** diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OverrideTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OverrideTest.java index cf776ddc2b..e0d4668d53 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/OverrideTest.java @@ -32,8 +32,11 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.Index; import org.junit.Test; -import org.hibernate.jaxb.spi.orm.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; import org.hibernate.metamodel.internal.source.annotations.util.JPADotNames; +import org.hibernate.metamodel.source.internal.jandex.EntityMappingsMocker; +import org.hibernate.metamodel.source.internal.jandex.EntityMocker; +import org.hibernate.metamodel.source.internal.jandex.IndexBuilder; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java index 6f8437b7a6..23ac195e4a 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/xml/mocker/PersistenceMetadataMockerTest.java @@ -29,7 +29,7 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.Index; import org.junit.Test; -import org.hibernate.metamodel.internal.source.annotations.xml.PseudoJpaDotNames; +import org.hibernate.metamodel.source.internal.jandex.PseudoJpaDotNames; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java index 445e7e46da..802948bff8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java @@ -23,16 +23,13 @@ */ package org.hibernate.test.annotations.xml.ejb3; -import java.io.InputStream; - -import org.hibernate.InvalidMappingException; -import org.hibernate.cfg.Configuration; -import org.hibernate.xml.internal.stax.UnsupportedOrmXsdVersionException; - -import org.junit.Test; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.spi.source.InvalidMappingException; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; import static org.junit.Assert.fail; @@ -41,16 +38,11 @@ public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase { @Test public void testNonExistentOrmVersion() { try { - Configuration config = buildConfiguration(); - String xmlFileName = "org/hibernate/test/annotations/xml/ejb3/orm5.xml"; - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFileName ); - config.addInputStream( is ); - config.buildMappings(); + MetadataSources sources = new MetadataSources( new BootstrapServiceRegistryBuilder().build() ); + sources.addResource( "org/hibernate/test/annotations/xml/ejb3/orm5.xml" ); fail( "Expecting failure due to unsupported xsd version" ); } - catch ( InvalidMappingException expected ) { - } - catch ( UnsupportedOrmXsdVersionException expected ) { + catch (InvalidMappingException expected) { } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/discriminator/SimpleInheritanceTest.java b/hibernate-core/src/test/java/org/hibernate/test/discriminator/SimpleInheritanceTest.java index 472de2eeb1..4689a62c05 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/discriminator/SimpleInheritanceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/discriminator/SimpleInheritanceTest.java @@ -49,11 +49,6 @@ import static org.junit.Assert.assertTrue; * @author Gavin King */ public class SimpleInheritanceTest extends BaseCoreFunctionalTestCase { - public void configure(Configuration cfg) { - super.configure( cfg ); - cfg.setProperty( MetadataSources.USE_NEW_METADATA_MAPPINGS, "true"); - } - @Override public String[] getMappings() { return new String[] { "discriminator/SimpleInheritance.hbm.xml" }; diff --git a/hibernate-core/src/test/java/org/hibernate/test/metamodel/unified/jaxb/SimpleBindingTest.java b/hibernate-core/src/test/java/org/hibernate/test/metamodel/unified/jaxb/SimpleBindingTest.java index a6aba24256..604a132e30 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/metamodel/unified/jaxb/SimpleBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/metamodel/unified/jaxb/SimpleBindingTest.java @@ -25,11 +25,10 @@ package org.hibernate.test.metamodel.unified.jaxb; import java.io.InputStream; -import org.hibernate.metamodel.spi.source.jaxb.JaxbAttributes; -import org.hibernate.metamodel.spi.source.jaxb.JaxbBasic; -import org.hibernate.metamodel.spi.source.jaxb.JaxbEntity; -import org.hibernate.metamodel.spi.source.jaxb.JaxbEntityMappings; -import org.hibernate.metamodel.spi.source.jaxb.JaxbId; +import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributes; +import org.hibernate.metamodel.source.internal.jaxb.JaxbBasic; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity; +import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityMappings; import org.hibernate.xml.internal.jaxb.UnifiedMappingBinder; import org.hibernate.xml.spi.Origin; import org.hibernate.xml.spi.SourceType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/ops/SimpleOpsTest.java b/hibernate-core/src/test/java/org/hibernate/test/ops/SimpleOpsTest.java index 1da109a60c..7f15c2265c 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/ops/SimpleOpsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/ops/SimpleOpsTest.java @@ -39,11 +39,6 @@ import static org.junit.Assert.assertTrue; * @author Gail Badner */ public class SimpleOpsTest extends AbstractOperationTestCase { - public void configure(Configuration cfg) { - super.configure( cfg ); - cfg.setProperty( MetadataSources.USE_NEW_METADATA_MAPPINGS, "true"); - } - public String[] getMappings() { return new String[] { "ops/SimpleEntity.hbm.xml" }; } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpectedWithNewMetamodel.java b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpectedWithNewMetamodel.java index d5fb910341..7e2050d887 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpectedWithNewMetamodel.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpectedWithNewMetamodel.java @@ -30,8 +30,7 @@ import java.lang.annotation.Target; /** * Used to mark test classes or methods as expecting to fail when using the new metamodel introduced in 5.0. This annotation is - * only honored when the system property - * {@value org.hibernate.metamodel.MetadataSources#USE_NEW_METADATA_MAPPINGS} is set to true. + * only honored when the system property 'hibernate.test.new_metadata_mappings' is set to true. */ @Retention( RetentionPolicy.RUNTIME ) @Target( { ElementType.METHOD, ElementType.TYPE } ) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 75a13467de..5c480a1ed5 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -110,16 +110,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { final ConfigurationService dummyConfigurationService = new ConfigurationServiceImpl( dummyConfiguration.getProperties() ); - isMetadataUsed = dummyConfigurationService.getSetting( - MetadataSources.USE_NEW_METADATA_MAPPINGS, - new ConfigurationService.Converter() { - @Override - public Boolean convert(Object value) { - return Boolean.parseBoolean( ( String ) value ); - } - }, - DEFAULT_USE_NEW_METAMODEL - ); + isMetadataUsed = true; } protected Configuration configuration() { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java index b7eb634d58..ebd86d87a6 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java @@ -44,12 +44,6 @@ import org.junit.runner.RunWith; public abstract class BaseUnitTestCase { private static final Logger log = Logger.getLogger( BaseUnitTestCase.class ); - public static final boolean DEFAULT_USE_NEW_METAMODEL = Boolean.valueOf( - System.getProperty( - MetadataSources.USE_NEW_METADATA_MAPPINGS, "true" - ) - ); - @Rule public TestRule globalTimeout= new Timeout(30 * 60 * 1000); // no test should run longer than 30 minutes @After diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java index e9d83be31f..b9f1932fe8 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/CustomRunner.java @@ -298,7 +298,7 @@ public class CustomRunner extends BlockJUnit4ClassRunner { catch ( Exception e ) { } - return BaseCoreFunctionalTestCase.DEFAULT_USE_NEW_METAMODEL; + return true; } protected Ignore convertSkipToIgnore(FrameworkMethod frameworkMethod) {