From 758d635ca23c03a6b75069560190646b480c8b7d Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 18 Feb 2014 12:03:51 -0600 Subject: [PATCH] HHH-8893 - Develop Hibernate mapping XSD extending the JPA mapping (orm) XSD --- .../internal/jandex/AnnotationMocker.java | 38 ++ .../source/internal/jandex/BasicMocker.java | 2 +- .../internal/jaxb/hbm/HbmXmlTransformer.java | 499 +++++++++++++++++- .../internal/jaxb/UnifiedMappingBinder.java | 2 +- .../java/org/hibernate/xml/spi/Origin.java | 14 +- .../hibernate/xsd/mapping/mapping-2.1.0.xsd | 26 +- 6 files changed, 543 insertions(+), 38 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java index e6088c2f72..bd96803846 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java @@ -23,6 +23,7 @@ */ package org.hibernate.metamodel.source.internal.jandex; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -32,7 +33,9 @@ import javax.persistence.EnumType; import javax.persistence.TemporalType; import org.hibernate.AssertionFailure; +import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.metamodel.internal.source.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.jaxb.JaxbAssociationOverride; import org.hibernate.metamodel.source.internal.jaxb.JaxbAttributeOverride; import org.hibernate.metamodel.source.internal.jaxb.JaxbCollectionTable; @@ -126,6 +129,41 @@ public abstract class AnnotationMocker extends AbstractMocker { return MockHelper.EMPTY_ANNOTATION_VALUE_ARRAY; } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + protected AnnotationInstance parseColumnOrFormulas(List columnOrFormulas, AnnotationTarget target) { + if ( columnOrFormulas.isEmpty() ) { + return null; + } + + // todo : add @ColumnOrFormulas and @ColumnOrFormula annotations + + if ( columnOrFormulas.size() == 1 ) { + final Object columnOrFormula = columnOrFormulas.get( 0 ); + if ( String.class.isInstance( columnOrFormula ) ) { + List annotationValueList = new ArrayList(); + MockHelper.stringValue( "value", (String) columnOrFormula, annotationValueList ); + return create( HibernateDotNames.FORMULA, target, annotationValueList ); + } + else { + return parseColumn( (JaxbColumn) columnOrFormula, target ); + } + } + else { + final List annotationValueList = new ArrayList(); + for ( Object columnOrFormula : columnOrFormulas ) { + // currently formulas are not supported in mix + if ( String.class.isInstance( columnOrFormula ) ) { + throw new NotYetImplementedException( "Requires @ColumnOrFormulas" ); + } + + AnnotationInstance annotationInstance = parseColumn( (JaxbColumn) columnOrFormula, null ); + annotationValueList.add( MockHelper.nestedAnnotationValue( "", annotationInstance ) ); + } + + return create( HibernateDotNames.COLUMNS, target, MockHelper.toArray( annotationValueList ) ); + } + } + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //@Column protected AnnotationInstance parseColumn(JaxbColumn column, AnnotationTarget target) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/BasicMocker.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/BasicMocker.java index 5d867316e4..1cc9559e5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/BasicMocker.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/BasicMocker.java @@ -54,7 +54,7 @@ public class BasicMocker extends PropertyMocker { MockHelper.booleanValue( "optional", basic.isOptional(), annotationValueList ); MockHelper.enumValue( "fetch", FETCH_TYPE, basic.getFetch(), annotationValueList ); create( BASIC, annotationValueList ); - parseColumn( basic.getColumn(), getTarget() ); + parseColumnOrFormulas( basic.getColumnOrFormula(), getTarget() ); parseEnumType( basic.getEnumerated(), getTarget() ); parseLob( basic.getLob(), getTarget() ); parseTemporalType( basic.getTemporal(), getTarget() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/hbm/HbmXmlTransformer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/hbm/HbmXmlTransformer.java index 6b35f0aea7..b9f68240d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/hbm/HbmXmlTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jaxb/hbm/HbmXmlTransformer.java @@ -25,21 +25,13 @@ package org.hibernate.metamodel.source.internal.jaxb.hbm; import java.util.Date; +import javax.persistence.FetchType; + import org.hibernate.FlushMode; import org.hibernate.internal.util.StringHelper; -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.hibernate.metamodel.source.internal.jaxb.*; +import org.hibernate.metamodel.source.internal.jaxb.JaxbCacheElement; +import org.hibernate.xml.spi.Origin; import org.jboss.logging.Logger; @@ -56,8 +48,13 @@ public class HbmXmlTransformer { */ public static final HbmXmlTransformer INSTANCE = new HbmXmlTransformer(); - public JaxbEntityMappings transform(JaxbHibernateMapping hbmXmlMapping) { - final JaxbEntityMappings ormRoot = new JaxbEntityMappings(); + private Origin origin; + private JaxbEntityMappings ormRoot; + + public JaxbEntityMappings transform(JaxbHibernateMapping hbmXmlMapping, Origin origin) { + this.origin = origin; + + ormRoot = new JaxbEntityMappings(); ormRoot.setDescription( "Hibernate orm.xml document auto-generated from legacy hbm.xml format via transformation " + "(generated at " + new Date().toString() + ")" @@ -337,6 +334,25 @@ public class HbmXmlTransformer { transferDiscriminatorSubclass( hbmSubclass, entity ); } } + + if ( !hbmXmlMapping.getJoinedSubclass().isEmpty() ) { + for ( JaxbJoinedSubclassElement hbmSubclass : hbmXmlMapping.getJoinedSubclass() ) { + final JaxbEntity entity = new JaxbEntity(); + ormRoot.getEntity().add( entity ); + + transferJoinedSubclass( hbmSubclass, entity ); + } + } + + if ( !hbmXmlMapping.getUnionSubclass().isEmpty() ) { + for ( JaxbUnionSubclassElement hbmSubclass : hbmXmlMapping.getUnionSubclass() ) { + final JaxbEntity entity = new JaxbEntity(); + ormRoot.getEntity().add( entity ); + + transferUnionSubclass( hbmSubclass, entity ); + } + } + // // // @@ -345,11 +361,462 @@ public class HbmXmlTransformer { } private void transferEntity(JaxbClassElement hbmClass, JaxbEntity entity) { - // todo : implement + entity.setMetadataComplete( true ); + entity.setName( hbmClass.getEntityName() ); + entity.setClazz( hbmClass.getName() ); + entity.setAbstract( hbmClass.isAbstract() ); + entity.setMutable( hbmClass.isMutable() ); + entity.setLazy( hbmClass.isLazy() ); + entity.setProxy( hbmClass.getProxy() ); + + entity.setBatchSize( hbmClass.getBatchSize() ); + + entity.setTable( new JaxbTable() ); + entity.getTable().setCatalog( hbmClass.getCatalog() ); + entity.getTable().setSchema( hbmClass.getSchema() ); + entity.getTable().setName( hbmClass.getTable() ); + entity.getTable().setComment( hbmClass.getComment() ); + entity.getTable().setCheck( hbmClass.getCheck() ); + entity.setSubselect( hbmClass.getSubselect() ); + if ( !hbmClass.getSynchronize().isEmpty() ) { + for ( JaxbSynchronizeElement hbmSync : hbmClass.getSynchronize() ) { + final JaxbSynchronizeType sync = new JaxbSynchronizeType(); + sync.setTable( hbmSync.getTable() ); + entity.getSynchronize().add( sync ); + } + } + + entity.setDynamicInsert( hbmClass.isDynamicInsert() ); + entity.setDynamicUpdate( hbmClass.isDynamicUpdate() ); + entity.setSelectBeforeUpdate( hbmClass.isSelectBeforeUpdate() ); + + if ( hbmClass.getLoader() != null ) { + entity.setLoader( new JaxbHbmLoader() ); + entity.getLoader().setQueryRef( hbmClass.getLoader().getQueryRef() ); + } + if ( hbmClass.getSqlInsert() != null ) { + entity.setSqlInsert( new JaxbHbmCustomSql() ); + entity.getSqlInsert().setValue( hbmClass.getSqlInsert().getValue() ); + entity.getSqlInsert().setCheck( convert( hbmClass.getSqlInsert().getCheck() ) ); + entity.getSqlInsert().setValue( hbmClass.getSqlInsert().getValue() ); + } + if ( hbmClass.getSqlUpdate() != null ) { + entity.setSqlUpdate( new JaxbHbmCustomSql() ); + entity.getSqlUpdate().setValue( hbmClass.getSqlUpdate().getValue() ); + entity.getSqlUpdate().setCheck( convert( hbmClass.getSqlUpdate().getCheck() ) ); + entity.getSqlUpdate().setValue( hbmClass.getSqlUpdate().getValue() ); + } + if ( hbmClass.getSqlDelete() != null ) { + entity.setSqlDelete( new JaxbHbmCustomSql() ); + entity.getSqlDelete().setValue( hbmClass.getSqlDelete().getValue() ); + entity.getSqlDelete().setCheck( convert( hbmClass.getSqlDelete().getCheck() ) ); + entity.getSqlDelete().setValue( hbmClass.getSqlDelete().getValue() ); + } + entity.setRowid( hbmClass.getRowid() ); + entity.setWhere( hbmClass.getWhere() ); + + entity.setPersister( hbmClass.getPersister() ); + if ( !hbmClass.getTuplizer().isEmpty() ) { + if ( hbmClass.getTuplizer().size() > 1 ) { + log.warn( "More than one entity-mode per entity not supported" ); + + } + final JaxbTuplizerElement tuplizerElement = hbmClass.getTuplizer().get( 0 ); + entity.setEntityMode( tuplizerElement.getEntityMode().value() ); + entity.setTuplizer( tuplizerElement.getClazz() ); + } + + entity.setOptimisticLock( hbmClass.getOptimisticLock().value() ); + if ( hbmClass.getOptimisticLock() == JaxbOptimisticLockAttribute.VERSION ) { + // todo : transfer version/timestamp + //final JaxbVersionElement hbmVersion = hbmClass.getVersion(); + //final JaxbTimestampElement hbmTimestamp = hbmClass.getTimestamp(); + + // oddly the jpa xsd allows multiple elements :? + } + + + transferDiscriminator( entity, hbmClass ); + entity.setDiscriminatorValue( hbmClass.getDiscriminatorValue() ); + entity.setPolymorphism( hbmClass.getPolymorphism().value() ); + + if ( hbmClass.getMultiTenancy() != null ) { + entity.setMultiTenancy( new JaxbHbmMultiTenancy() ); + transferColumn( + entity.getMultiTenancy().getColumn(), + hbmClass.getMultiTenancy().getColumn(), + null, + true, + true + ); + entity.getMultiTenancy().setFormula( hbmClass.getMultiTenancy().getFormula() ); + entity.getMultiTenancy().setBindAsParam( hbmClass.getMultiTenancy().isBindAsParam() ); + entity.getMultiTenancy().setShared( hbmClass.getMultiTenancy().isShared() ); + } + + if ( hbmClass.getCache() != null ) { + entity.setCache( new JaxbCacheElement() ); + entity.getCache().setRegion( hbmClass.getCache().getRegion() ); + entity.getCache().setUsage( hbmClass.getCache().getUsage().value() ); + entity.getCache().setInclude( hbmClass.getCache().getInclude().value() ); + } + + // todo : transfer named queries + // todo : transfer filters + // todo : transfer fetch-profiles + + transferAttributes( entity, hbmClass ); + } + + private JaxbHbmCustomSqlCheckEnum convert(JaxbCheckAttribute check) { + if ( check == null ) { + return null; + } + return JaxbHbmCustomSqlCheckEnum.valueOf( check.value() ); + } + + private void transferColumn( + JaxbColumn column, + JaxbColumnElement hbmColumn, + String tableName, + boolean insertable, + boolean updateable) { + column.setTable( tableName ); + column.setName( hbmColumn.getName() ); + column.setComment( hbmColumn.getComment() ); + column.setCheck( hbmColumn.getCheck() ); + column.setDefault( hbmColumn.getDefault() ); + column.setNullable( !hbmColumn.isNotNull() ); + column.setColumnDefinition( hbmColumn.getSqlType() ); + column.setInsertable( insertable ); + column.setUpdatable( updateable ); + column.setLength( hbmColumn.getLength() ); + column.setPrecision( hbmColumn.getPrecision() ); + column.setScale( hbmColumn.getScale() ); + column.setRead( hbmColumn.getRead() ); + column.setWrite( hbmColumn.getWrite() ); + column.setUnique( hbmColumn.isUnique() ); + } + + private void transferDiscriminator(JaxbEntity entity, JaxbClassElement hbmClass) { + if ( hbmClass.getDiscriminator() == null ) { + return; + } + + if ( StringHelper.isNotEmpty( hbmClass.getDiscriminator().getColumnAttribute() ) ) { + entity.getDiscriminatorColumn().setName( hbmClass.getDiscriminator().getColumnAttribute() ); + } + else if ( StringHelper.isEmpty( hbmClass.getDiscriminator().getFormulaAttribute() ) ) { + entity.setDiscriminatorFormula( hbmClass.getDiscriminator().getFormulaAttribute() ); + } + else if ( StringHelper.isEmpty( hbmClass.getDiscriminator().getFormula().trim() ) ) { + entity.setDiscriminatorFormula( hbmClass.getDiscriminator().getFormulaAttribute().trim() ); + } + else { + entity.getDiscriminatorColumn().setName( hbmClass.getDiscriminator().getColumn().getName() ); + entity.getDiscriminatorColumn().setColumnDefinition( hbmClass.getDiscriminator().getColumn().getSqlType() ); + entity.getDiscriminatorColumn().setLength( hbmClass.getDiscriminator().getColumn().getLength() ); + entity.getDiscriminatorColumn().setForceInSelect( hbmClass.getDiscriminator().isForce() ); + } + } + + private void transferAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + entity.setAttributes( new JaxbAttributes() ); + + transferIdentifier( entity, hbmClass ); + transferBasicAttributes( entity, hbmClass ); + transferEmbeddedAttributes( entity, hbmClass ); + transferOneToOneAttributes( entity, hbmClass ); + transferManyToOneAttributes( entity, hbmClass ); + transferManyToManyAttributes( entity, hbmClass ); + transferAnyAttributes( entity, hbmClass ); + transferManyToAnyAttributes( entity, hbmClass ); + transferPrimitiveArrayAttributes( entity, hbmClass ); + transferPropertiesGrouping( entity, hbmClass ); + } + + private void transferIdentifier(JaxbEntity entity, JaxbClassElement hbmClass) { + final JaxbIdElement hbmId = hbmClass.getId(); + if ( hbmId != null ) { + // simple id + final JaxbId id = new JaxbId(); + id.setName( hbmId.getName() ); + id.setCustomAccess( hbmId.getAccess() ); + if ( StringHelper.isNotEmpty( hbmId.getTypeAttribute() ) ) { + id.getType().setName( hbmId.getTypeAttribute() ); + } + else { + if ( hbmId.getType() != null ) { + id.setType( new JaxbHbmType() ); + id.getType().setName( hbmId.getType().getName() ); + if ( !hbmId.getType().getParam().isEmpty() ) { + for ( JaxbParamElement hbmParam : hbmId.getType().getParam() ) { + final JaxbHbmParam param = new JaxbHbmParam(); + param.setName( hbmParam.getName() ); + param.setValue( hbmParam.getValue() ); + id.getType().getParam().add( param ); + } + } + } + } + id.setUnsavedValue( hbmId.getUnsavedValue() ); + if ( StringHelper.isNotEmpty( hbmId.getColumnAttribute() ) ) { + id.getColumn().setName( hbmId.getColumnAttribute() ); + } + else { + if ( hbmId.column != null ) { + assert hbmId.column.size() == 1; + transferColumn( id.getColumn(), hbmId.getColumn().get( 0 ), null, true, false ); + } + } + entity.getAttributes().getId().add( id ); + return; + } + + final JaxbCompositeIdElement hbmCompositeId = hbmClass.getCompositeId(); + assert hbmCompositeId != null; + + // we have one of 2 forms of composite id... + final boolean isAggregate; + if ( StringHelper.isNotEmpty( hbmCompositeId.getClazz() ) ) { + // we have . + if ( hbmCompositeId.isMapped() ) { + // user explicitly said the class is an "IdClass" + isAggregate = false; + } + else { + isAggregate = true; + } + } + else { + // there was no class specified, can only be non-aggregated + isAggregate = false; + } + + if ( isAggregate ) { + entity.getAttributes().getEmbeddedId().setName( hbmCompositeId.getName() ); + entity.getAttributes().getEmbeddedId().setCustomAccess( hbmCompositeId.getAccess() ); + + final JaxbEmbeddable embeddable = new JaxbEmbeddable(); + embeddable.setClazz( hbmCompositeId.getClazz() ); + for ( Object hbmCompositeAttribute : hbmCompositeId.getKeyPropertyOrKeyManyToOne() ) { + if ( JaxbKeyPropertyElement.class.isInstance( hbmCompositeAttribute ) ) { + final JaxbKeyPropertyElement keyProp = (JaxbKeyPropertyElement) hbmCompositeAttribute; + final JaxbBasic basic = new JaxbBasic(); + basic.setName( keyProp.getName() ); + basic.setCustomAccess( keyProp.getAccess() ); + if ( StringHelper.isNotEmpty( keyProp.getColumnAttribute() ) ) { + final JaxbColumn column = new JaxbColumn(); + column.setName( keyProp.getColumnAttribute() ); + basic.getColumnOrFormula().add( column ); + } + else { + for ( JaxbColumnElement hbmColumn : keyProp.getColumn() ) { + final JaxbColumn column = new JaxbColumn(); + transferColumn( column, hbmColumn, null, true, false ); + basic.getColumnOrFormula().add( column ); + } + } + embeddable.getAttributes().getBasic().add( basic ); + } + else { + final JaxbKeyManyToOneElement keyManyToOne = (JaxbKeyManyToOneElement) hbmCompositeAttribute; + final JaxbManyToOne manyToOne = new JaxbManyToOne(); + manyToOne.setName( keyManyToOne.getName() ); + manyToOne.setCustomAccess( keyManyToOne.getAccess() ); + if ( StringHelper.isNotEmpty( keyManyToOne.getEntityName() ) ) { + manyToOne.setTargetEntity( keyManyToOne.getEntityName() ); + } + else { + manyToOne.setTargetEntity( keyManyToOne.getClazz() ); + } + // todo : cascade + if ( "true".equals( keyManyToOne.getLazy().value() ) ) { + manyToOne.setFetch( FetchType.LAZY ); + } + manyToOne.getForeignKey().setName( keyManyToOne.getForeignKey() ); + if ( StringHelper.isNotEmpty( keyManyToOne.getColumnAttribute() ) ) { + final JaxbJoinColumn joinColumn = new JaxbJoinColumn(); + joinColumn.setName( keyManyToOne.getColumnAttribute() ); + manyToOne.getJoinColumn().add( joinColumn ); + } + else { + for ( JaxbColumnElement hbmColumn : keyManyToOne.getColumn() ) { + final JaxbJoinColumn joinColumn = new JaxbJoinColumn(); + joinColumn.setName( hbmColumn.getName() ); + joinColumn.setNullable( !hbmColumn.isNotNull() ); + joinColumn.setUnique( hbmColumn.isUnique() ); + manyToOne.getJoinColumn().add( joinColumn ); + } + } + embeddable.getAttributes().getManyToOne().add( manyToOne ); + } + } + ormRoot.getEmbeddable().add( embeddable ); + } + else { + entity.getIdClass().setClazz( hbmCompositeId.getClazz() ); + for ( Object hbmCompositeAttribute : hbmCompositeId.getKeyPropertyOrKeyManyToOne() ) { + if ( JaxbKeyPropertyElement.class.isInstance( hbmCompositeAttribute ) ) { + final JaxbKeyPropertyElement keyProp = (JaxbKeyPropertyElement) hbmCompositeAttribute; + final JaxbId id = new JaxbId(); + id.setName( keyProp.getName() ); + id.setCustomAccess( keyProp.getAccess() ); + if ( StringHelper.isNotEmpty( keyProp.getColumnAttribute() ) ) { + id.getColumn().setName( keyProp.getColumnAttribute() ); + } + else { + if ( keyProp.column != null ) { + assert keyProp.column.size() == 1; + transferColumn( id.getColumn(), keyProp.getColumn().get( 0 ), null, true, false ); + } + } + entity.getAttributes().getId().add( id ); + } + else { + final JaxbKeyManyToOneElement keyManyToOne = (JaxbKeyManyToOneElement) hbmCompositeAttribute; + final JaxbManyToOne manyToOne = new JaxbManyToOne(); + manyToOne.setName( keyManyToOne.getName() ); + manyToOne.setId( true ); + manyToOne.setCustomAccess( keyManyToOne.getAccess() ); + if ( StringHelper.isNotEmpty( keyManyToOne.getEntityName() ) ) { + manyToOne.setTargetEntity( keyManyToOne.getEntityName() ); + } + else { + manyToOne.setTargetEntity( keyManyToOne.getClazz() ); + } + // todo : cascade + if ( "true".equals( keyManyToOne.getLazy().value() ) ) { + manyToOne.setFetch( FetchType.LAZY ); + } + manyToOne.getForeignKey().setName( keyManyToOne.getForeignKey() ); + if ( StringHelper.isNotEmpty( keyManyToOne.getColumnAttribute() ) ) { + final JaxbJoinColumn joinColumn = new JaxbJoinColumn(); + joinColumn.setName( keyManyToOne.getColumnAttribute() ); + manyToOne.getJoinColumn().add( joinColumn ); + } + else { + for ( JaxbColumnElement hbmColumn : keyManyToOne.getColumn() ) { + final JaxbJoinColumn joinColumn = new JaxbJoinColumn(); + joinColumn.setName( hbmColumn.getName() ); + joinColumn.setNullable( !hbmColumn.isNotNull() ); + joinColumn.setUnique( hbmColumn.isUnique() ); + manyToOne.getJoinColumn().add( joinColumn ); + } + } + entity.getAttributes().getManyToOne().add( manyToOne ); + } + } + } + } + + private void transferBasicAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + for ( JaxbPropertyElement hbmProp : hbmClass.getProperty() ) { + final JaxbBasic basic = new JaxbBasic(); + basic.setName( hbmProp.getName() ); + basic.setOptional( hbmProp.isNotNull() != null && !hbmProp.isNotNull() ); + basic.setFetch( FetchType.EAGER ); + basic.setCustomAccess( hbmProp.getAccess() ); + basic.setOptimisticLock( hbmProp.isOptimisticLock() ); + + if ( StringHelper.isNotEmpty( hbmProp.getTypeAttribute() ) ) { + basic.getType().setName( hbmProp.getTypeAttribute() ); + } + else { + if ( hbmProp.getType() != null ) { + basic.setType( new JaxbHbmType() ); + basic.getType().setName( hbmProp.getType().getName() ); + for ( JaxbParamElement hbmParam : hbmProp.getType().getParam() ) { + final JaxbHbmParam param = new JaxbHbmParam(); + param.setName( hbmParam.getName() ); + param.setValue( hbmParam.getValue() ); + basic.getType().getParam().add( param ); + } + } + } + + if ( StringHelper.isNotEmpty( hbmProp.getFormulaAttribute() ) ) { + basic.getColumnOrFormula().add( hbmProp.getFormulaAttribute() ); + } + else if ( StringHelper.isNotEmpty( hbmProp.getColumnAttribute() ) ) { + final JaxbColumn column = new JaxbColumn(); + column.setName( hbmProp.getColumnAttribute() ); + basic.getColumnOrFormula().add( column ); + } + else if ( !hbmProp.getFormula().isEmpty() ) { + for ( String formula : hbmProp.getFormula() ) { + basic.getColumnOrFormula().add( formula ); + } + } + else { + for ( JaxbColumnElement hbmColumn : hbmProp.getColumn() ) { + final JaxbColumn column = new JaxbColumn(); + transferColumn( column, hbmColumn, null, hbmProp.isInsert(), hbmProp.isUpdate() ); + basic.getColumnOrFormula().add( column ); + } + } + entity.getAttributes().getBasic().add( basic ); + } + } + + private void transferEmbeddedAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + + } + + private void transferOneToOneAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + + } + + private void transferManyToOneAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + + } + + private void transferManyToManyAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + + } + + private void transferAnyAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + + } + + private void transferManyToAnyAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + + } + + private void transferPrimitiveArrayAttributes(JaxbEntity entity, JaxbClassElement hbmClass) { + if ( !hbmClass.getPrimitiveArray().isEmpty() ) { + log.warnf( + "Entity mapping [%s : %s] from hbm.xml [%s] used construct " + + "which is not supported in transformation; skipping", + hbmClass.getName(), + hbmClass.getEntityName(), + origin + ); + } + } + + private void transferPropertiesGrouping(JaxbEntity entity, JaxbClassElement hbmClass) { + if ( !hbmClass.getProperties().isEmpty() ) { + log.warnf( + "Entity mapping [%s : %s] from hbm.xml [%s] used construct " + + "which is not supported in transformation; skipping", + hbmClass.getName(), + hbmClass.getEntityName(), + origin + ); + } } private void transferDiscriminatorSubclass(JaxbSubclassElement hbmSubclass, JaxbEntity entity) { // todo : implement } + private void transferJoinedSubclass(JaxbJoinedSubclassElement hbmSubclass, JaxbEntity entity) { + // todo : implement + } + + private void transferUnionSubclass(JaxbUnionSubclassElement hbmSubclass, JaxbEntity entity) { + // todo : implement + } + } 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 19241a586b..22cdd3390c 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 @@ -65,7 +65,7 @@ public class UnifiedMappingBinder extends AbstractUnifiedBinder - + @@ -403,6 +403,7 @@ + @@ -741,6 +742,7 @@ + @@ -781,12 +783,11 @@ - - + @@ -836,7 +837,10 @@ - + + + + @@ -880,6 +884,7 @@ + @@ -888,10 +893,9 @@ - + - @@ -1364,6 +1368,7 @@ + @@ -2390,11 +2395,10 @@ - - Hibernate-specific element used to assign meta-level attributes to a - class or property. Is currently used by tooling (code generators) as - a placeholder for values that is not directly related to O/R mappings. - + tags from hbm.xml dtd; renamed here for + self-documentation. This information is intended mainly for tooling. + ]]>