HHH-8893 - Develop Hibernate mapping XSD extending the JPA mapping (orm) XSD
This commit is contained in:
parent
ebcd0d9cff
commit
758d635ca2
|
@ -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<Serializable> 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<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||
MockHelper.stringValue( "value", (String) columnOrFormula, annotationValueList );
|
||||
return create( HibernateDotNames.FORMULA, target, annotationValueList );
|
||||
}
|
||||
else {
|
||||
return parseColumn( (JaxbColumn) columnOrFormula, target );
|
||||
}
|
||||
}
|
||||
else {
|
||||
final List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
|
||||
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) {
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
// <xs:element name="class" type="class-element"/>
|
||||
// <xs:element name="subclass" type="subclass-element"/>
|
||||
// <xs:element name="joined-subclass" type="joined-subclass-element"/>
|
||||
|
@ -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 <version/> 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 <composite-id class="XYZ">.
|
||||
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 <primitive-array/> 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 <properties/> 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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class UnifiedMappingBinder extends AbstractUnifiedBinder<JaxbEntityMappin
|
|||
|
||||
XMLEventReader hbmReader = new HbmEventReader( staxEventReader );
|
||||
JaxbHibernateMapping hbmBindings = jaxb( hbmReader, LocalSchema.HBM.getSchema(), JaxbHibernateMapping.class, origin );
|
||||
return HbmXmlTransformer.INSTANCE.transform( hbmBindings );
|
||||
return HbmXmlTransformer.INSTANCE.transform( hbmBindings, origin );
|
||||
}
|
||||
else {
|
||||
final XMLEventReader reader = new UnifiedMappingEventReader( staxEventReader );
|
||||
|
|
|
@ -26,6 +26,8 @@ package org.hibernate.xml.spi;
|
|||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hibernate.internal.util.compare.EqualsHelper;
|
||||
|
||||
/**
|
||||
* Describes the origin of an xml document
|
||||
*
|
||||
|
@ -70,16 +72,10 @@ public class Origin implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
Origin origin = (Origin) o;
|
||||
final Origin other = (Origin) o;
|
||||
return type == other.type
|
||||
&& EqualsHelper.equals( name, other.name );
|
||||
|
||||
if ( name != null ? !name.equals( origin.name ) : origin.name != null ) {
|
||||
return false;
|
||||
}
|
||||
if ( type != origin.type ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -375,7 +375,7 @@
|
|||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="tooling-hint" type="orm:hbm-tooling-hint" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:choice minOccurs="0">
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="column" type="orm:column" />
|
||||
<xsd:element name="formula" type="xsd:string" />
|
||||
</xsd:choice>
|
||||
|
@ -403,6 +403,7 @@
|
|||
<xsd:attribute name="optional" type="xsd:boolean"/>
|
||||
<xsd:attribute name="access" type="orm:access-type"/>
|
||||
<xsd:attribute name="custom-access" type="xsd:string" />
|
||||
<xsd:attribute name="natural-id" type="xsd:boolean" />
|
||||
</xsd:complexType>
|
||||
|
||||
|
||||
|
@ -741,6 +742,7 @@
|
|||
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="access" type="orm:access-type"/>
|
||||
<xsd:attribute name="custom-access" type="xsd:string" />
|
||||
<xsd:attribute name="natural-id" type="xsd:boolean" />
|
||||
</xsd:complexType>
|
||||
|
||||
<!-- **************************************************** -->
|
||||
|
@ -781,12 +783,11 @@
|
|||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="description" type="xsd:string" minOccurs="0" />
|
||||
<!-- hbm: "meta information", used by tooling -->
|
||||
<xsd:element name="tooling-hint" type="orm:hbm-tooling-hint" minOccurs="0" maxOccurs="unbounded" />
|
||||
<!-- hbm: is the entity considered abstract -->
|
||||
<xsd:element name="abstract" type="xsd:boolean" minOccurs="0" />
|
||||
<!-- hbm: The size for batch fetching : @BatchSize -->
|
||||
<xsd:element name="batch-size" type="xsd:string" minOccurs="0" />
|
||||
<xsd:element name="batch-size" type="xsd:int" minOccurs="0" />
|
||||
<!-- hbm : Hibernate specific caching configuration : @Cache -->
|
||||
<xsd:element name="cache" type="orm:cache-element" minOccurs="0" />
|
||||
<!-- hbm : should INSERT statements be dynamically generated : @DynamicInsert -->
|
||||
|
@ -836,7 +837,10 @@
|
|||
|
||||
<xsd:element name="inheritance" type="orm:inheritance" minOccurs="0"/>
|
||||
<xsd:element name="discriminator-value" type="orm:discriminator-value" minOccurs="0"/>
|
||||
<xsd:element name="discriminator-column" type="orm:discriminator-column" minOccurs="0"/>
|
||||
<xsd:choice minOccurs="0" maxOccurs="1">
|
||||
<xsd:element name="discriminator-column" type="orm:discriminator-column" />
|
||||
<xsd:element name="discriminator-formula" type="xsd:string" />
|
||||
</xsd:choice>
|
||||
<!-- hbm : used in query language to control how inherited "abstract schema" references are handled : @Polymorphism -->
|
||||
<xsd:element name="polymorphism" default="implicit" minOccurs="0">
|
||||
<xsd:simpleType>
|
||||
|
@ -880,6 +884,7 @@
|
|||
<xsd:element name="named-entity-graph" type="orm:named-entity-graph" minOccurs="0" maxOccurs="unbounded"/>
|
||||
|
||||
<xsd:element name="persister" type="xsd:string" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element name="tuplizer" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="entity-mode" minOccurs="0" maxOccurs="1">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:token">
|
||||
|
@ -888,10 +893,9 @@
|
|||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:element>
|
||||
<xsd:element name="tuplizer" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="extends" type="xsd:string" minOccurs="0" maxOccurs="1" />
|
||||
|
||||
<xsd:element name="loader" type="orm:hbm-loader" minOccurs="0" maxOccurs="1" />
|
||||
|
||||
<xsd:element name="sql-insert" type="orm:hbm-custom-sql" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="sql-update" type="orm:hbm-custom-sql" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="sql-delete" type="orm:hbm-custom-sql" minOccurs="0" maxOccurs="1" />
|
||||
|
@ -1364,6 +1368,7 @@
|
|||
<xsd:attribute name="custom-access" type="xsd:string" />
|
||||
<xsd:attribute name="maps-id" type="xsd:string"/>
|
||||
<xsd:attribute name="id" type="xsd:boolean"/>
|
||||
<xsd:attribute name="natural-id" type="xsd:boolean" />
|
||||
</xsd:complexType>
|
||||
|
||||
|
||||
|
@ -2390,11 +2395,10 @@
|
|||
|
||||
<xsd:complexType name="hbm-tooling-hint" mixed="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
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.
|
||||
</xsd:documentation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Equivalent to the legacy <meta/> tags from hbm.xml dtd; renamed here for
|
||||
self-documentation. This information is intended mainly for tooling.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleContent>
|
||||
<xsd:extension base="xsd:string">
|
||||
|
|
Loading…
Reference in New Issue