From 24b377a774ec4c0ebadd42d1c42ac297d61b97f4 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 7 Feb 2014 16:55:16 -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 | 15 +- .../hibernate/metamodel/MetadataSources.java | 2 +- .../hbm/transform/HbmXmlTransformer.java | 192 +++ .../spi/source/jaxb/AttributesContainer.java | 52 + .../spi/source/jaxb/LifecycleCallback.java | 34 + .../spi/source/jaxb/ManagedType.java | 42 + .../spi/source/jaxb/Parameterized.java | 33 + .../spi/source/jaxb/PersistentAttribute.java | 42 + .../spi/source/jaxb/SchemaAware.java | 40 + .../spi/source/jaxb/ToolingHintContainer.java | 35 + .../xml/internal/jaxb/AbstractXmlBinder.java | 17 +- .../xml/internal/jaxb/AbstractXmlBinder2.java | 159 ++ .../xml/internal/jaxb/MappingXmlBinder.java | 2 +- .../internal/jaxb/UnifiedMappingBinder.java | 91 ++ .../jaxb/UnifiedMappingEventReader.java | 142 ++ .../xml/internal/stax/LocalSchemaLocator.java | 4 + .../internal/stax/SupportedOrmXsdVersion.java | 4 + .../org/hibernate/xsd/mapping/orm-2.1.0.xsd | 1328 ++++++++++++++--- .../xslt/mapping/hbm-to-orm-2.1.0.xsd.xsl | 115 ++ .../src/main/xjb/mapping-bindings.xjb | 172 +++ .../xml/mocker/AbstractMockerTest.java | 4 +- 21 files changed, 2324 insertions(+), 201 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/transform/HbmXmlTransformer.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/AttributesContainer.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/LifecycleCallback.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ManagedType.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/Parameterized.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/PersistentAttribute.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/SchemaAware.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ToolingHintContainer.java create mode 100644 hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder2.java create mode 100644 hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingBinder.java create mode 100644 hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingEventReader.java create mode 100644 hibernate-core/src/main/resources/org/hibernate/xslt/mapping/hbm-to-orm-2.1.0.xsd.xsl create mode 100644 hibernate-core/src/main/xjb/mapping-bindings.xjb diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 275b28bc9f..ac7d7d4db0 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -112,15 +112,17 @@ task jaxb { cfgXsd = file( 'src/main/resources/org/hibernate/hibernate-configuration-4.0.xsd') hbmXsd = file( 'src/main/resources/org/hibernate/hibernate-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/orm-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, cfgXjb, hbmXjb, ormXjb] ) + inputs.files( [cfgXsd, hbmXsd, ormXsd, unifiedOrmXsd, cfgXjb, hbmXjb, ormXjb, unifiedOrmXjb] ) outputs.dir( jaxbTargetDir ) // perform actions @@ -160,6 +162,17 @@ task jaxb { arg line: '-Xinheritance' } + // unified mapping xsd + ant.xjc( + destdir: '${jaxbTargetDir}', +// package: 'org.hibernate.metamodel.spi.source.jaxb', + binding: 'src/main/xjb/mapping-bindings.xjb', + schema: unifiedOrmXsd.path, + extension: 'true' + ) { + arg line: '-Xinheritance' + } + } } 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 1bd266fd0b..18f1bf7d90 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java @@ -479,7 +479,7 @@ public class MetadataSources { */ public MetadataSources addDocument(Document document) { final Origin origin = new Origin( SourceType.DOM, UNKNOWN_FILE_PATH ); - BindResult bindResult = jaxbProcessor.unmarshal( document, origin ); + BindResult bindResult = jaxbProcessor.bind( document, origin ); addJaxbRoot( bindResult ); return this; } 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 new file mode 100644 index 0000000000..b4243f8cde --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/transform/HbmXmlTransformer.java @@ -0,0 +1,192 @@ +/* + * 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.internal.source.hbm.transform; + +import java.util.Date; + +import org.hibernate.jaxb.spi.hbm.JaxbFilterDefElement; +import org.hibernate.jaxb.spi.hbm.JaxbFilterParamElement; +import org.hibernate.jaxb.spi.hbm.JaxbHibernateMapping; +import org.hibernate.jaxb.spi.hbm.JaxbIdentifierGeneratorElement; +import org.hibernate.jaxb.spi.hbm.JaxbImportElement; +import org.hibernate.jaxb.spi.hbm.JaxbMetaContainerElement; +import org.hibernate.jaxb.spi.hbm.JaxbMetaElement; +import org.hibernate.jaxb.spi.hbm.JaxbParamElement; +import org.hibernate.jaxb.spi.hbm.JaxbTypedefElement; +import org.hibernate.metamodel.spi.source.jaxb.JaxbEntityMappings; +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.JaxbPersistenceUnitMetadata; + +/** + * Transforms a JAXB binding of a hbm.xml file into a unified orm.xml representation + * + * @author Steve Ebersole + */ +public class HbmXmlTransformer { + /** + * Singleton access + */ + public static final HbmXmlTransformer INSTANCE = new HbmXmlTransformer(); + + public JaxbEntityMappings transform(JaxbHibernateMapping hbmXmlMapping) { + final JaxbEntityMappings ormRoot = new JaxbEntityMappings(); + ormRoot.setDescription( + "Hibernate orm.xml document auto-generated from legacy hbm.xml format via transformation " + + "(generated at " + new Date().toString() + ")" + ); + + final JaxbPersistenceUnitMetadata metadata = new JaxbPersistenceUnitMetadata(); + ormRoot.setPersistenceUnitMetadata( metadata ); + metadata.setDescription( + "Defines information which applies to the persistence unit overall, not just to this mapping file.\n\n" + + "This transformation only specifies xml-mapping-metadata-complete." + ); + + transferToolingHints( hbmXmlMapping, ormRoot ); + + ormRoot.setPackage( hbmXmlMapping.getPackage() ); + ormRoot.setSchema( hbmXmlMapping.getSchema() ); + ormRoot.setCatalog( hbmXmlMapping.getCatalog() ); + ormRoot.setCustomAccess( hbmXmlMapping.getDefaultAccess() ); + ormRoot.setDefaultCascade( hbmXmlMapping.getDefaultCascade() ); + ormRoot.setAutoImport( hbmXmlMapping.isAutoImport() ); + ormRoot.setDefaultLazy( hbmXmlMapping.isDefaultLazy() ); + + transferTypeDefs( hbmXmlMapping, ormRoot ); + transferFilterDefs( hbmXmlMapping, ormRoot ); + transferIdentifierGenerators( hbmXmlMapping, ormRoot ); + transferImports( hbmXmlMapping, ormRoot ); + + +// +// +// +// + +// +// +// +// + + return ormRoot; + } + + private void transferToolingHints(JaxbMetaContainerElement hbmMetaContainer, JaxbEntityMappings entityMappings) { + if ( hbmMetaContainer.getMeta().isEmpty() ) { + return; + } + + for ( JaxbMetaElement hbmMetaElement : hbmMetaContainer.getMeta() ) { + final JaxbHbmToolingHint toolingHint = new JaxbHbmToolingHint(); + entityMappings.getToolingHint().add( toolingHint ); + toolingHint.setName( hbmMetaElement.getName() ); + toolingHint.setInheritable( hbmMetaElement.isInheritable() ); + toolingHint.setValue( hbmMetaElement.getValue() ); + } + } + + private void transferTypeDefs(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) { + if ( hbmXmlMapping.getTypedef().isEmpty() ) { + return; + } + + for ( JaxbTypedefElement hbmXmlTypeDef : hbmXmlMapping.getTypedef() ) { + final JaxbHbmTypeDef typeDef = new JaxbHbmTypeDef(); + ormRoot.getTypeDef().add( typeDef ); + typeDef.setName( hbmXmlTypeDef.getName() ); + typeDef.setClazz( hbmXmlTypeDef.getClazz() ); + + if ( !hbmXmlTypeDef.getParam().isEmpty() ) { + for ( JaxbParamElement hbmParam : hbmXmlTypeDef.getParam() ) { + final JaxbHbmParam param = new JaxbHbmParam(); + typeDef.getParam().add( param ); + param.setName( hbmParam.getName() ); + param.setValue( hbmParam.getValue() ); + } + } + } + } + + private void transferFilterDefs(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) { + if ( hbmXmlMapping.getFilterDef().isEmpty() ) { + return; + } + + for ( JaxbFilterDefElement hbmFilterDef : hbmXmlMapping.getFilterDef() ) { + JaxbHbmFilterDef filterDef = new JaxbHbmFilterDef(); + ormRoot.getFilterDef().add( filterDef ); + filterDef.setName( hbmFilterDef.getName() ); + + boolean foundCondition = false; + for ( Object content : hbmFilterDef.getContent() ) { + if ( String.class.isInstance( content ) ) { + foundCondition = true; + filterDef.setCondition( (String) content ); + } + else { + JaxbFilterParamElement hbmFilterParam = (JaxbFilterParamElement) content; + JaxbHbmFilterDef.JaxbFilterParam param = new JaxbHbmFilterDef.JaxbFilterParam(); + filterDef.getFilterParam().add( param ); + param.setName( hbmFilterParam.getParameterName() ); + param.setType( hbmFilterParam.getParameterValueTypeName() ); + } + } + + if ( !foundCondition ) { + filterDef.setCondition( hbmFilterDef.getCondition() ); + } + } + } + + private void transferIdentifierGenerators(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) { + if ( hbmXmlMapping.getIdentifierGenerator().isEmpty() ) { + return; + } + + for ( JaxbIdentifierGeneratorElement hbmGenerator : hbmXmlMapping.getIdentifierGenerator() ) { + final JaxbHbmIdGeneratorDef generatorDef = new JaxbHbmIdGeneratorDef(); + ormRoot.getIdentifierGeneratorDef().add( generatorDef ); + generatorDef.setName( hbmGenerator.getName() ); + generatorDef.setClazz( hbmGenerator.getClazz() ); + } + } + + private void transferImports(JaxbHibernateMapping hbmXmlMapping, JaxbEntityMappings ormRoot) { + if ( hbmXmlMapping.getImport().isEmpty() ) { + return; + } + + for ( JaxbImportElement hbmImport : hbmXmlMapping.getImport() ) { + final JaxbEntityMappings.JaxbImport ormImport = new JaxbEntityMappings.JaxbImport(); + ormRoot.getImport().add( ormImport ); + ormImport.setClazz( hbmImport.getClazz() ); + ormImport.setRename( hbmImport.getRename() ); + } + } + +} 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/spi/source/jaxb/AttributesContainer.java new file mode 100644 index 0000000000..de6cab496b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/AttributesContainer.java @@ -0,0 +1,52 @@ +/* + * 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.spi.source.jaxb; + +import java.util.List; + +/** + * Common interface for JAXB bindings which are containers of attributes. + * + * @author Strong Liu + * @author Steve Ebersole + */ +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/spi/source/jaxb/LifecycleCallback.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/LifecycleCallback.java new file mode 100644 index 0000000000..c0caf7f3f0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/LifecycleCallback.java @@ -0,0 +1,34 @@ +/* + * 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.spi.source.jaxb; + +/** + * Common interface for all the JAXB bindings representing lifecycle callbacks. + * + * @author Strong Liu + * @author Steve Ebersole + */ +public interface LifecycleCallback { + public String getMethodName(); +} 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/spi/source/jaxb/ManagedType.java new file mode 100644 index 0000000000..8230cb56b2 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ManagedType.java @@ -0,0 +1,42 @@ +/* + * 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.spi.source.jaxb; + +/** + * Common interface for JAXB bindings representing entities, mapped-superclasses and embeddables (JPA collective + * calls these "managed types" in terms of its Metamodel api). + * + * @author Strong Liu + * @author Steve Ebersole + */ +public interface ManagedType { + 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/spi/source/jaxb/Parameterized.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/Parameterized.java new file mode 100644 index 0000000000..95b23f7054 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/Parameterized.java @@ -0,0 +1,33 @@ +/* + * 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.spi.source.jaxb; + +import java.util.List; + +/** + * @author Steve Ebersole + */ +public interface Parameterized { + public List getParam(); +} 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/spi/source/jaxb/PersistentAttribute.java new file mode 100644 index 0000000000..92aaed56ee --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/PersistentAttribute.java @@ -0,0 +1,42 @@ +/* + * 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.spi.source.jaxb; + +/** + * Common interface for JAXB bindings that represent persistent attributes. + * + * @author Strong Liu + * @author Steve Ebersole + */ +public interface PersistentAttribute { + String getName(); + + JaxbAccessType getAccess(); + + void setAccess(JaxbAccessType 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/spi/source/jaxb/SchemaAware.java new file mode 100644 index 0000000000..7a469f6402 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/SchemaAware.java @@ -0,0 +1,40 @@ +/* + * 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.spi.source.jaxb; + +/** + * Common interface for JAXB bindings that understand database schema (tables, sequences, etc). + * + * @author Strong Liu + * @author Steve Ebersole + */ +public interface SchemaAware { + String getSchema(); + + void setSchema(String schema); + + String getCatalog(); + + void setCatalog(String catalog); +} 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/spi/source/jaxb/ToolingHintContainer.java new file mode 100644 index 0000000000..26365c1abb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/source/jaxb/ToolingHintContainer.java @@ -0,0 +1,35 @@ +/* + * 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.spi.source.jaxb; + +import java.util.List; + +/** + * Common interface for JAXB bindings which are containers of tooling hints. + * + * @author Steve Ebersole + */ +public interface ToolingHintContainer { + public List getToolingHint(); +} 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 e1552c0aba..6c042c2e5e 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 @@ -109,30 +109,29 @@ abstract class AbstractXmlBinder implements XmlBinder { @SuppressWarnings( { "unchecked" }) private BindResult unmarshal(XMLEventReader staxEventReader, final Origin origin) { - XMLEvent event; + XMLEvent rootElementStartEvent; try { - event = staxEventReader.peek(); - while ( event != null && !event.isStartElement() ) { + rootElementStartEvent = staxEventReader.peek(); + while ( rootElementStartEvent != null && !rootElementStartEvent.isStartElement() ) { staxEventReader.nextEvent(); - event = staxEventReader.peek(); + rootElementStartEvent = staxEventReader.peek(); } } catch ( Exception e ) { throw new MappingException( "Error accessing stax stream", e, origin ); } - if ( event == null ) { + if ( rootElementStartEvent == null ) { throw new MappingException( "Could not locate root element", origin ); } - final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler(); try { - final Schema schema = getSchema( event, origin ); - staxEventReader = wrapReader( staxEventReader, event ); + final Schema schema = getSchema( rootElementStartEvent, origin ); + staxEventReader = wrapReader( staxEventReader, rootElementStartEvent ); - final JAXBContext jaxbContext = getJaxbContext( event ); + final JAXBContext jaxbContext = getJaxbContext( rootElementStartEvent ); final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema( schema ); unmarshaller.setEventHandler( handler ); diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder2.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder2.java new file mode 100644 index 0000000000..9cfa295c49 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/AbstractXmlBinder2.java @@ -0,0 +1,159 @@ +/* + * 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.io.InputStream; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.events.StartElement; +import javax.xml.stream.events.XMLEvent; +import javax.xml.validation.Schema; + +import org.hibernate.metamodel.spi.source.MappingException; +import org.hibernate.xml.internal.stax.BufferedXMLEventReader; +import org.hibernate.xml.internal.stax.LocalXmlResourceResolver; +import org.hibernate.xml.spi.BindResult; +import org.hibernate.xml.spi.Origin; +import org.hibernate.xml.spi.XmlBinder; + +/** + * @author Steve Ebersole + */ +public abstract class AbstractXmlBinder2 implements XmlBinder { + private final boolean validateXml; + + protected AbstractXmlBinder2() { + this( true ); + } + + protected AbstractXmlBinder2(boolean validateXml) { + this.validateXml = validateXml; + } + + public boolean isValidationEnabled() { + return validateXml; + } + + @Override + public BindResult bind(InputStream stream, Origin origin) { + final XMLEventReader eventReader = createReader( stream, origin ); + try { + final StartElement rootElementStartEvent = seekRootElementStartEvent( eventReader, origin ); + return doBind( eventReader, rootElementStartEvent, origin ); + } + finally { + try { + eventReader.close(); + } + catch ( Exception ignore ) { + } + } + } + + protected XMLEventReader createReader(InputStream stream, Origin origin) { + try { + // create a standard StAX reader + final XMLEventReader staxReader = staxFactory().createXMLEventReader( stream ); + // and wrap it in a buffered reader (keeping 100 element sized buffer) + return new BufferedXMLEventReader( staxReader, 100 ); + } + catch ( XMLStreamException e ) { + throw new MappingException( "Unable to create stax reader", e, origin ); + } + } + + private XMLInputFactory staxFactory; + + private XMLInputFactory staxFactory() { + if ( staxFactory == null ) { + staxFactory = buildStaxFactory(); + } + return staxFactory; + } + + @SuppressWarnings( { "UnnecessaryLocalVariable" }) + private XMLInputFactory buildStaxFactory() { + XMLInputFactory staxFactory = XMLInputFactory.newInstance(); + staxFactory.setXMLResolver( LocalXmlResourceResolver.INSTANCE ); + return staxFactory; + } + + protected StartElement seekRootElementStartEvent(XMLEventReader staxEventReader, Origin origin) { + XMLEvent rootElementStartEvent; + try { + rootElementStartEvent = staxEventReader.peek(); + while ( rootElementStartEvent != null && !rootElementStartEvent.isStartElement() ) { + staxEventReader.nextEvent(); + rootElementStartEvent = staxEventReader.peek(); + } + } + catch ( Exception e ) { + throw new MappingException( "Error accessing stax stream", e, origin ); + } + + if ( rootElementStartEvent == null ) { + throw new MappingException( "Could not locate root element", origin ); + } + + return rootElementStartEvent.asStartElement(); + } + + protected abstract BindResult doBind(XMLEventReader staxEventReader, StartElement rootElementStartEvent, Origin origin); + + protected static boolean hasNamespace(StartElement startElement) { + return ! "".equals( startElement.getName().getNamespaceURI() ); + } + + @SuppressWarnings("unchecked") + protected T jaxb(XMLEventReader reader, Schema xsd, Class modelClass, Origin origin) { + final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler(); + + try { + final JAXBContext jaxbContext = JAXBContext.newInstance( modelClass ); + final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + if ( isValidationEnabled() ) { + unmarshaller.setSchema( xsd ); + } + else { + unmarshaller.setSchema( null ); + } + unmarshaller.setEventHandler( handler ); + + return (T) unmarshaller.unmarshal( reader ); + } + catch ( JAXBException e ) { + throw new MappingException( + "Unable to perform unmarshalling at line number " + handler.getLineNumber() + + " and column " + handler.getColumnNumber() + + ". Message: " + handler.getMessage(), + e, + origin + ); + } + } +} 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 db975a09ba..472cefe599 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 @@ -128,7 +128,7 @@ public class MappingXmlBinder extends AbstractXmlBinder { @SuppressWarnings( { "unchecked" }) - public BindResult unmarshal(Document document, Origin origin) { + public BindResult bind(Document document, Origin origin) { Element rootElement = document.getDocumentElement(); if ( rootElement == null ) { throw new MappingException( "No root element found", 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 new file mode 100644 index 0000000000..78b79d1701 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingBinder.java @@ -0,0 +1,91 @@ +/* + * 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 javax.xml.stream.XMLEventReader; +import javax.xml.stream.events.StartElement; +import javax.xml.validation.Schema; + +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.service.ServiceRegistry; +import org.hibernate.xml.internal.stax.LocalSchemaLocator; +import org.hibernate.xml.spi.BindResult; +import org.hibernate.xml.spi.Origin; + +import org.jboss.logging.Logger; + +/** + * Binder for the unified orm.xml schema + * + * @author Steve Ebersole + */ +public class UnifiedMappingBinder extends AbstractXmlBinder2 { + private static final Logger log = Logger.getLogger( MappingXmlBinder.class ); + private static final Schema XSD = LocalSchemaLocator.resolveLocalSchema( "org/hibernate/xsd/mapping/orm-2.1.0.xsd" ); + private static final Schema HBM_XSD =LocalSchemaLocator.resolveLocalSchema( "org/hibernate/hibernate-mapping-4.0.xsd" ); + + public static final String HBM_URI = "http://www.hibernate.org/xsd/hibernate-mapping"; + + + public UnifiedMappingBinder() { + super(); + } + + public UnifiedMappingBinder(boolean validateXml) { + super( validateXml ); + } + + @Override + protected BindResult doBind( + XMLEventReader staxEventReader, + StartElement rootElementStartEvent, + Origin origin) { + final String rootElementLocalName = rootElementStartEvent.getName().getLocalPart(); + if ( "hibernate-mappings".equals( rootElementLocalName ) ) { + // todo: finalize message test here, and possibly use a message logger + log.debug( + "Found legacy Hibernate hbm.xml mapping; performing on-the-fly transformation. " + + "Consider using build-time transformation tool to speed up run-time parsing" + ); + + XMLEventReader hbmReader = staxEventReader; + if ( !hasNamespace( rootElementStartEvent ) ) { + // if the elements are not namespaced in the source document, which can cause problems with validation + // and/or JAXB binding (since the xsd is namespaced). So we wrap the reader in a version that will + // return events that are namespaced versions of the original + hbmReader = new NamespaceAddingEventReader( staxEventReader, HBM_URI ); + } + + JaxbHibernateMapping hbmBindings = jaxb( hbmReader, HBM_XSD, JaxbHibernateMapping.class, origin ); + return new BindResult( HbmXmlTransformer.INSTANCE.transform( hbmBindings ), origin ); + } + else { + final XMLEventReader reader = new UnifiedMappingEventReader( staxEventReader ); + final JaxbEntityMappings bindings = jaxb( reader, XSD, JaxbEntityMappings.class, origin ); + return new BindResult( bindings, origin ); + } + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingEventReader.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingEventReader.java new file mode 100644 index 0000000000..5d9ac50b7e --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/jaxb/UnifiedMappingEventReader.java @@ -0,0 +1,142 @@ +/* + * 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.Attribute; +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.jboss.logging.Logger; + +/** + * @author Steve Ebersole + */ +public class UnifiedMappingEventReader extends EventReaderDelegate { + private static final Logger log = Logger.getLogger( UnifiedMappingEventReader.class ); + + public static final String NAMESPACE = "http://www.hibernate.org/xsd/orm"; + public static final String VERSION = "2.1.0"; + + private static final List JPA_NAMESPACE_URIS = Arrays.asList( + // JPA 1.0 and 2.0 namespace uri + "http://java.sun.com/xml/ns/persistence/orm", + // JPA 2.1 namespace uri + "http://xmlns.jcp.org/xml/ns/persistence/orm" + ); + + private final XMLEventFactory xmlEventFactory; + + public UnifiedMappingEventReader(XMLEventReader reader) { + this( reader, XMLEventFactory.newInstance() ); + } + + public UnifiedMappingEventReader(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) { + Iterator attributesItr; + Iterator 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", VERSION ) ); + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // namespaces are a little more complicated. First we add our + // unified schema namespace as the default (no-prefix) namespace. + // Then we will check each of the original namespaces and if they + // have a uri matching any of the JPA mapping schema namespaces + // we will swap our uri; if the uri does not match, we will copy + // it as-is + final Iterator originalNamespaces = startElement.getNamespaces(); + while ( originalNamespaces.hasNext() ) { + Namespace namespace = originalNamespaces.next(); + if ( JPA_NAMESPACE_URIS.contains( namespace.getNamespaceURI() ) ) { + namespace = xmlEventFactory.createNamespace( namespace.getPrefix(), NAMESPACE ); + } + targetNamespaces.add( namespace ); + } + + attributesItr = targetAttributeList.iterator(); + namespacesItr = targetNamespaces.iterator(); + } + else { + attributesItr = startElement.getAttributes(); + namespacesItr = startElement.getNamespaces(); + } + + final StartElement adjusted = xmlEventFactory.createStartElement( + new QName( NAMESPACE, startElement.getName().getLocalPart() ), + attributesItr, + namespacesItr + ); + if ( log.isDebugEnabled() ) { + log.debugf( "Created new StartElement with adjusted namespacing : %s ", adjusted ); + } + return adjusted; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchemaLocator.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchemaLocator.java index bd7b014df5..95f3278f7d 100644 --- a/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchemaLocator.java +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/LocalSchemaLocator.java @@ -34,6 +34,10 @@ import javax.xml.validation.SchemaFactory; import org.jboss.logging.Logger; /** + * Helper for resolving XML Schema references locally. + *

+ * Note that *by design* we always use our ClassLoader to perform the lookups here. + * * @author Steve Ebersole */ public class LocalSchemaLocator { diff --git a/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/SupportedOrmXsdVersion.java b/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/SupportedOrmXsdVersion.java index 3c90f8c104..3f3bfe05c9 100644 --- a/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/SupportedOrmXsdVersion.java +++ b/hibernate-core/src/main/java/org/hibernate/xml/internal/stax/SupportedOrmXsdVersion.java @@ -35,6 +35,7 @@ public enum SupportedOrmXsdVersion { ORM_1_0( "org/hibernate/jpa/orm_1_0.xsd" ), ORM_2_0( "org/hibernate/jpa/orm_2_0.xsd" ), ORM_2_1( "org/hibernate/jpa/orm_2_1.xsd" ), + ORM_2_1_0( "org/hibernate/xsd/mapping/orm-2.1.0.xsd" ), HBM_4_0( "org/hibernate/hibernate-mapping-4.0.xsd" ); private final String schemaResourceName; @@ -53,6 +54,9 @@ public enum SupportedOrmXsdVersion { else if ( "2.1".equals( name ) ) { return ORM_2_1; } + else if ( "2.1.0".equals( name ) ) { + return ORM_2_1_0; + } else if ( "4.0".equals( name ) ) { return HBM_4_0; } diff --git a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/orm-2.1.0.xsd b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/orm-2.1.0.xsd index 3b6065b1ca..dc4103dbb3 100644 --- a/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/orm-2.1.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/xsd/mapping/orm-2.1.0.xsd @@ -68,31 +68,34 @@ - - + + - - - + + + - + - - - + + + + + + - + @@ -113,9 +116,6 @@ - - - @@ -233,6 +233,64 @@ + + + + + + Hibernate specific "any" mapping, which is a polymorphic association to any different + tables based on a discriminator + + the given identifier type. The first listed column is a VARCHAR column + holding the name of the class (for that row). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.acme.Employee + ]]> + + + + + + + + + @@ -251,8 +309,12 @@ - + + + A natural-id element allows declaration of the unique business key + + @@ -274,9 +336,50 @@ + + + + + + + + + @javax.persistence.AssociationOverride + + + + + + + + + + + + + + + + + + + + + + @javax.persistence.AttributeOverride + + + + + + + + + + @@ -286,7 +389,7 @@ - + @@ -314,6 +417,7 @@ + @@ -368,6 +472,49 @@ + + + + + + + public enum CascadeType { ALL, PERSIST, MERGE, REMOVE, REFRESH, DETACH}; + + + + + + + + + + + + + + + + + + + @CollectionTable annotation + + + + + + + + + + + + + + + + + @@ -383,6 +530,7 @@ + @@ -407,6 +555,7 @@ + @@ -429,6 +578,128 @@ + + + + + + @DiscriminatorColumn annotation + + + + + + + + + + + + + + + + + + public enum DiscriminatorType { STRING, CHAR, INTEGER }; + + + + + + + + + + + + + + + + + + @Target({TYPE}) @Retention(RUNTIME) + public @interface DiscriminatorValue { + String value(); + } + + + + + + + + + + + + + Corresponds to the @ElementCollection annotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -479,13 +750,14 @@ - + + @@ -501,6 +773,7 @@ + @@ -524,29 +797,29 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -557,20 +830,20 @@ - + - + - + - + - + - - + + @@ -582,7 +855,7 @@ - + @@ -591,9 +864,13 @@ + + + + @@ -619,8 +896,8 @@ - - + + @@ -628,23 +905,24 @@ - + - + - - - + + + - + - + - + + @@ -747,6 +1025,24 @@ + + + + + + @ForeignKey annotation + + + + + + + + + + + + @@ -776,113 +1072,18 @@ - + Hibernate-specific element used declare and short-name custom org.hibernate.id.IdentifierGenerator implementations + - - - - - - - Names a org.hibernate.id.IdentifierGenerator implementation (class attribute) - as well as any configuration information need by the implementation (Hibernate - will pass it the parameters after instantiation). - - - - - - - - - - - - - - - Corresponds to the org.hibernate.annotations.Parameter annotation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Corresponds to the org.hibernate.annotations.Type annotation, naming - a org.hibernate.type.* or org.hibernate.usertype.* implementation to use. - - name - names the type implementation class - - param - If the type is able to accept parameters (implementation stems from - org.hibernate.type.Type, org.hibernate.type.CollectionType, or - org.hibernate.usertype.ParameterizedType) the specified parameters will be - passed to the type instance after instantiation. - - - - - - - - - @@ -892,11 +1093,11 @@ - + - + @@ -904,13 +1105,14 @@ - - + + + @@ -923,6 +1125,102 @@ + + + + + + Corresponds to @Index annotation + + + + + + + + + + + + + + + + + + + Corresponds to the @Inheritance annotation + + + + + + + + + + + + Corresponds to the JPA InheritanceType enumeration values + Hibernate's UNION_SUBCLASS + + + + + + + + + + + + + + + + + JoinColumn annotation + + + + + + + + + + + + + + + + + + + + @JoinTable annotation + + + + + + + + + + + + + + + + + + + + + + @@ -955,6 +1253,195 @@ + + + + + + Hibernate specific "any" mapping (plural form), which is a polymorphic association to any different + tables based on a discriminator. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @ManyToMany annotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Corresponds to the @ManyToOne annotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @javax.persistence.MapKey + + + + + + + + + + + + @javax.persistence.MapKeyClass + + + + + + + + + + + + + @javax.persistence.MapKeyColumn + + + + + + + + + + + + + + + + + + + + + + @javax.persistence.MapKeyJoinColumn + + + + + + + + + + + + + + @@ -972,6 +1459,7 @@ the case then the defaulting rules will be recursively applied. + @@ -987,8 +1475,10 @@ + + @@ -1002,11 +1492,59 @@ mapping for ANY associations. + + + + + + + @NamedEntityGraph annotation + + + + + + + + + + + + + + + + + @NamedAttributeNode annotation + + + + + + + + + + + + @NamedSubgraph annotation + + + + + + + + + + + + @@ -1017,6 +1555,7 @@ todo : a lot of these extensions could be handled by JPA QueryHint scheme + @@ -1040,6 +1579,7 @@ annotations. + @@ -1067,10 +1607,9 @@ - - + @@ -1083,6 +1622,7 @@ Corresponds to the javax.persistence.NamedStoredProcedureQuery annotation + @@ -1090,6 +1630,7 @@ + @@ -1100,9 +1641,11 @@ Corresponds to javax.persistence.StoredProcedureParameter annotation + + @@ -1114,6 +1657,7 @@ Corresponds to enumerated values defined by javax.persistence.ParameterMode + @@ -1123,6 +1667,130 @@ + + + + + + @OneToMany annotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Corresponds to the @OneToOne annotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @javax.persistence.OrderBy annotation + + + + + + + + + + + + + @javax.persistence.OrderColumn annotation + + + + + + + + + + + @@ -1131,9 +1799,11 @@ Corresponds to the javax.persistence.PostLoad annotation + + @@ -1146,9 +1816,11 @@ Corresponds to the javax.persistence.PostPersist annotation + + @@ -1161,9 +1833,11 @@ Corresponds to the javax.persistence.PostRemove annotation + + @@ -1176,9 +1850,11 @@ Corresponds to the javax.persistence.PostUpdate annotation + + @@ -1191,9 +1867,11 @@ Corresponds to the javax.persistence.PrePersist annotation + + @@ -1206,9 +1884,11 @@ Corresponds to the javax.persistence.PreRemove annotation + + @@ -1221,28 +1901,43 @@ Corresponds to the javax.persistence.PreUpdate annotation + + + + + + + + @PrimaryKeyJoinColumn annotation + + + + + + + + + - @Target({}) @Retention(RUNTIME) - public @interface QueryHint { - String name(); - String value(); - } + @javax.persistence.QueryHint + + @@ -1256,30 +1951,50 @@ Used only by tools to generate finder methods for named queries + + + + + + + @javax.persistence.SecondaryTable + + + + + + + + + + + + + + + + + + + - @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) - public @interface SequenceGenerator { - String name(); - String sequenceName() default ""; - String catalog() default ""; - String schema() default ""; - int initialValue() default 1; - int allocationSize() default 50; - } + @javax.persistence.SequenceGenerator + + @@ -1294,49 +2009,59 @@ - Corresponds to the javax.persistence.SqlResultSetMapping annotation + @javax.persistence.SqlResultSetMapping + + + - Corresponds to the javax.persistence.ColumnResult annotation + @javax.persistence.ColumnResult + + - Corresponds to the javax.persistence.ConstructorResult annotation + @javax.persistence.ConstructorResult + + + - Corresponds to the javax.persistence.EntityResult annotation + @javax.persistence.EntityResult + + @@ -1345,9 +2070,10 @@ - Corresponds to javax.persistence.FieldResult annotation + @javax.persistence.FieldResult + @@ -1365,14 +2091,16 @@ - Corresponds to javax.persistence.Table annotation + @javax.persistence.Table + + @@ -1391,15 +2119,17 @@ - Corresponds to the javax.persistence.TableGenerator annotation + @javax.persistence.TableGenerator + + @@ -1417,7 +2147,7 @@ - See javax.persistence.Temporal + @javax.persistence.Temporal @@ -1429,7 +2159,7 @@ - See javax.persistence.TemporalType enum + javax.persistence.TemporalType enum @@ -1445,7 +2175,7 @@ - See javax.persistence.Transient + @javax.persistence.Transient @@ -1454,7 +2184,223 @@ - + + + + @javax.persistence.UniqueConstraint + + + + + + + + + + + + + + + + + @javax.persistence.Version + + + + + + + + + + + + + + + + + + + + + + + + element defines a single path to which the fetch + refers, as well as the style of fetch to apply. The 'root' of the + path is different depending upon the context in which the + containing occurs; within a element, + the entity-name of the containing class mapping is assumed... + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + Specifies a filter definition. After definition, a filter + can be applied to entity or collection by name. + + + + + + + + + Used to identify all bind parameters in the condition elemement + + + + + + + + + + + + + + + + Applies a filter defined by hbm-filter-def usage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Names a org.hibernate.id.IdentifierGenerator implementation (class attribute) + as well as any configuration information need by the implementation (Hibernate + will pass it the parameters after instantiation). + + + + + + + + + + + + + Corresponds to the org.hibernate.annotations.Parameter annotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The loader element allows specification of a named query to be used for fetching + an entity or collection + + + + + + + + + + + + + + + + + + + + + + + Hibernate-specific element used to assign meta-level attributes to a @@ -1473,34 +2419,44 @@ - + - Corresponds to javax.persistence.UniqueConstraint + Corresponds to the org.hibernate.annotations.Type annotation, naming + a org.hibernate.type.* or org.hibernate.usertype.* implementation to use. + + name - names the type implementation class + + param - If the type is able to accept parameters (implementation stems from + org.hibernate.type.Type, org.hibernate.type.CollectionType, or + org.hibernate.usertype.ParameterizedType) the specified parameters will be + passed to the type instance after instantiation. - + - + - + - - Corresponds to javax.persistence.Version - + + - - - + - - + + + + \ No newline at end of file diff --git a/hibernate-core/src/main/resources/org/hibernate/xslt/mapping/hbm-to-orm-2.1.0.xsd.xsl b/hibernate-core/src/main/resources/org/hibernate/xslt/mapping/hbm-to-orm-2.1.0.xsd.xsl new file mode 100644 index 0000000000..570f46d76c --- /dev/null +++ b/hibernate-core/src/main/resources/org/hibernate/xslt/mapping/hbm-to-orm-2.1.0.xsd.xsl @@ -0,0 +1,115 @@ + + + + + + + + Hibernate orm.xml document auto-generated from legacy hbm.xml format via Hibernate-supplied + XSLT transformation (generated at ). + + + + + Defines information which applies to the persistence unit overall, not just to this mapping file. + + The XSLT transformation does not specify any persistence-unit-metadata itself. + + + + + + + + Defines defaults across the persistence unit overall, not just to this mapping file. + + Again, the XSLT transformation does not specify any. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PROPERTY + + + + + FIELD + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hibernate-core/src/main/xjb/mapping-bindings.xjb b/hibernate-core/src/main/xjb/mapping-bindings.xjb new file mode 100644 index 0000000000..35f4a03c3e --- /dev/null +++ b/hibernate-core/src/main/xjb/mapping-bindings.xjb @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + org.hibernate.metamodel.spi.source.jaxb.ToolingHintContainer + + + + + + + + + + + org.hibernate.metamodel.spi.source.jaxb.Parameterized + + + + + org.hibernate.metamodel.spi.source.jaxb.SchemaAware + + + org.hibernate.metamodel.spi.source.jaxb.SchemaAware + + + org.hibernate.metamodel.spi.source.jaxb.SchemaAware + + + org.hibernate.metamodel.spi.source.jaxb.SchemaAware + + + org.hibernate.metamodel.spi.source.jaxb.SchemaAware + + + org.hibernate.metamodel.spi.source.jaxb.SchemaAware + + + + org.hibernate.metamodel.spi.source.jaxb.ManagedType + + + org.hibernate.metamodel.spi.source.jaxb.ManagedType + + + org.hibernate.metamodel.spi.source.jaxb.ManagedType + + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + org.hibernate.metamodel.spi.source.jaxb.PersistentAttribute + + + + org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + + + org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + + + org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + + + org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + + + org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + + + org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + + + org.hibernate.metamodel.spi.source.jaxb.LifecycleCallback + + + + org.hibernate.metamodel.spi.source.jaxb.AttributesContainer + + + org.hibernate.metamodel.spi.source.jaxb.AttributesContainer + + + + + + + + + + + + + + + + + \ No newline at end of file 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 241572e4a5..0343f71119 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 @@ -70,17 +70,15 @@ public abstract class AbstractMockerTest { } protected EntityMappingsMocker getEntityMappingsMocker(String... mappingFiles) { + MappingXmlBinder processor = new MappingXmlBinder( getServiceRegistry() ); ClassLoaderService classLoaderService = getServiceRegistry().getService( ClassLoaderService.class ); List xmlEntityMappingsList = new ArrayList(); for ( String fileName : mappingFiles ) { - MappingXmlBinder processor = new MappingXmlBinder( getServiceRegistry() ); BindResult bindResult = processor.bind( classLoaderService.locateResourceStream( packagePrefix + fileName ), new Origin( SourceType.FILE, packagePrefix + fileName ) ); JaxbEntityMappings entityMappings = (JaxbEntityMappings) bindResult.getRoot(); - - xmlEntityMappingsList.add( entityMappings ); } return new EntityMappingsMocker( xmlEntityMappingsList, getIndex(), getServiceRegistry() );