From d57ffbdb32b8450599f30c9c28a4918ff9752802 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 16 Jul 2012 18:28:49 +0800 Subject: [PATCH] HHH-7450 apply simplify plugin --- .../jaxb/mapping/hbm/EntityElement.java | 15 +- .../source/hbm/AbstractEntitySourceImpl.java | 265 ++++++++++++------ ...ositePluralAttributeElementSourceImpl.java | 11 +- .../source/hbm/RootEntitySourceImpl.java | 65 +++-- .../org/hibernate/hibernate-mapping-4.0.xsd | 36 ++- 5 files changed, 282 insertions(+), 110 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/jaxb/mapping/hbm/EntityElement.java b/hibernate-core/src/main/java/org/hibernate/internal/jaxb/mapping/hbm/EntityElement.java index 0335c14ec6..e3d552afad 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/jaxb/mapping/hbm/EntityElement.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/jaxb/mapping/hbm/EntityElement.java @@ -56,5 +56,18 @@ public interface EntityElement extends MetaAttributeContainer { public List getQueryOrSqlQuery(); - public List getPropertyOrManyToOneOrOneToOne(); + public List getProperty(); + public List getManyToOne(); + public List getOneToOne(); + public List getComponent(); + public List getDynamicComponent(); +// public List getProperties(); + public List getAny(); + public List getMap(); + public List getSet(); + public List getList(); + public List getBag(); + public List getIdbag(); + public List getArray(); + public List getPrimitiveArray(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java index 0199344215..346a76449e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractEntitySourceImpl.java @@ -35,6 +35,7 @@ import org.hibernate.internal.jaxb.mapping.hbm.EntityElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbAnyElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbBagElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbComponentElement; +import org.hibernate.internal.jaxb.mapping.hbm.JaxbDynamicComponentElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbIdbagElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbJoinElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbListElement; @@ -105,97 +106,172 @@ public abstract class AbstractEntitySourceImpl } protected List buildAttributeSources(List attributeSources) { - processAttributes( + return buildAttributeSources( entityElement, attributeSources, null, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID ); + } + protected List buildAttributeSources(EntityElement element, + List attributeSources, + String logicTalbeName, + SingularAttributeBinding.NaturalIdMutability naturalIdMutability){ + processPropertyAttributes( attributeSources, element.getProperty(), logicTalbeName, naturalIdMutability ); + processComponentAttributes( attributeSources, - entityElement.getPropertyOrManyToOneOrOneToOne(), - null, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID + element.getComponent(), + logicTalbeName, + naturalIdMutability ); + processDynamicComponentAttributes( + attributeSources, + element.getDynamicComponent(), + logicTalbeName, + naturalIdMutability + ); + processManyToOneAttributes( + attributeSources, + element.getManyToOne(), + logicTalbeName, + naturalIdMutability + ); + processOneToOneAttributes( + attributeSources, + element.getOneToOne(), + logicTalbeName, + naturalIdMutability + ); + processAnyAttributes( + attributeSources, + element.getAny(), + logicTalbeName, + naturalIdMutability + ); + processMapAttributes( attributeSources, element.getMap() ); + processListAttributes( attributeSources, element.getList() ); + processSetAttributes( attributeSources, element.getSet() ); + processIdBagAttributes( attributeSources, element.getIdbag() ); + processBagAttributes( attributeSources, element.getBag() ); return attributeSources; } - protected void processAttributes( - List results, - List attributeElements, - String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { - for ( Object attributeElement : attributeElements ) { - results.add( buildAttributeSource( attributeElement, logicalTableName, naturalIdMutability ) ); + protected void processPropertyAttributes(List results, + List propertyElements, + String logicalTableName, + SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + for ( JaxbPropertyElement element : propertyElements ) { + results.add( + new PropertyAttributeSourceImpl( + sourceMappingDocument(), + element, + logicalTableName, + naturalIdMutability + ) + ); } } - protected AttributeSource buildAttributeSource( - Object attributeElement, - String logicalTableName, - SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { - if ( JaxbPropertyElement.class.isInstance( attributeElement ) ) { - return new PropertyAttributeSourceImpl( - sourceMappingDocument(), - JaxbPropertyElement.class.cast( attributeElement ), - logicalTableName, - naturalIdMutability + protected void processComponentAttributes(List results, + List elements, + String logicalTableName, + SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + for ( JaxbComponentElement element : elements ) { + results.add( + new ComponentAttributeSourceImpl( + sourceMappingDocument(), + element, + this, + logicalTableName, + naturalIdMutability + ) ); } - else if ( JaxbComponentElement.class.isInstance( attributeElement ) ) { - return new ComponentAttributeSourceImpl( - sourceMappingDocument(), - (JaxbComponentElement) attributeElement, - this, - logicalTableName, - naturalIdMutability - ); - } - else if ( JaxbManyToOneElement.class.isInstance( attributeElement ) ) { - return new ManyToOneAttributeSourceImpl( - sourceMappingDocument(), - JaxbManyToOneElement.class.cast( attributeElement ), - logicalTableName, - naturalIdMutability - ); - } - else if ( JaxbOneToOneElement.class.isInstance( attributeElement ) ) { - // todo : implement - } - else if ( JaxbAnyElement.class.isInstance( attributeElement ) ) { - // todo : implement - } - else if ( JaxbBagElement.class.isInstance( attributeElement ) ) { - return new BagAttributeSourceImpl( - sourceMappingDocument(), - JaxbBagElement.class.cast( attributeElement ), - this - ); - } - else if ( JaxbIdbagElement.class.isInstance( attributeElement ) ) { - // todo : implement - } - else if ( JaxbSetElement.class.isInstance( attributeElement ) ) { - return new SetAttributeSourceImpl( - sourceMappingDocument(), - JaxbSetElement.class.cast( attributeElement ), - this - ); - } - else if ( JaxbListElement.class.isInstance( attributeElement ) ) { - return new ListAttributeSource( - sourceMappingDocument(), - JaxbListElement.class.cast( attributeElement ), - this - ); - } - else if ( JaxbMapElement.class.isInstance( attributeElement ) ) { - return new MapAttributeSource( - sourceMappingDocument(), - JaxbMapElement.class.cast( attributeElement ), - this - ); - } - - throw new UnexpectedAttributeSourceTypeException( - "Unexpected attribute element type encountered : " + attributeElement.getClass().getName() - ); } + protected void processDynamicComponentAttributes(List results, + List elements, + String logicalTableName, + SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + // todo : implement + } + + protected void processManyToOneAttributes(List results, + List elements, + String logicalTableName, + SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + for ( JaxbManyToOneElement element : elements ) { + results.add( + new ManyToOneAttributeSourceImpl( + sourceMappingDocument(), + element, + logicalTableName, + naturalIdMutability + ) + ); + } + } + protected void processOneToOneAttributes(List results, + List elements, + String logicalTableName, + SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + // todo : implement + } + + protected void processAnyAttributes(List results, + List elements, + String logicalTableName, + SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { + // todo : implement + } + + protected void processMapAttributes(List results, + List propertyElements){ + for ( JaxbMapElement element : propertyElements ) { + results.add( + new MapAttributeSource( + sourceMappingDocument(), + element, this + ) + ); + } + } + protected void processListAttributes(List results, + List propertyElements){ + for ( JaxbListElement element : propertyElements ) { + results.add( + new ListAttributeSource( + sourceMappingDocument(), + element, this + ) + ); + } + } + protected void processSetAttributes(List results, + List propertyElements){ + for ( JaxbSetElement element : propertyElements ) { + results.add( + new SetAttributeSourceImpl( + sourceMappingDocument(), + element, + this + ) + ); + } + } + protected void processIdBagAttributes(List results, + List propertyElements){ + // todo : implement + } + protected void processBagAttributes(List results, + List propertyElements) { + for ( JaxbBagElement element : propertyElements ) { + results.add( + new BagAttributeSourceImpl( + sourceMappingDocument(), + element, + this + ) + ); + } + } + + private Set buildSecondaryTables() { if ( ! JoinElementSource.class.isInstance( entityElement ) ) { return Collections.emptySet(); @@ -211,11 +287,36 @@ public abstract class AbstractEntitySourceImpl secondaryTableSources.add( secondaryTableSource ); final String logicalTableName = secondaryTableSource.getLogicalTableNameForContainedColumns(); - processAttributes( + final SingularAttributeBinding.NaturalIdMutability naturalIdMutability = SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID; + processAnyAttributes( attributeSources, - joinElement.getPropertyOrManyToOneOrComponent(), + joinElement.getAny(), logicalTableName, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID + naturalIdMutability + ); + processComponentAttributes( + attributeSources, + joinElement.getComponent(), + logicalTableName, + naturalIdMutability + ); + processDynamicComponentAttributes( + attributeSources, + joinElement.getDynamicComponent(), + logicalTableName, + naturalIdMutability + ); + processManyToOneAttributes( + attributeSources, + joinElement.getManyToOne(), + logicalTableName, + naturalIdMutability + ); + processPropertyAttributes( + attributeSources, + joinElement.getProperty(), + logicalTableName, + naturalIdMutability ); } return secondaryTableSources; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeElementSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeElementSourceImpl.java index d64735252a..6f78730d1a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeElementSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/CompositePluralAttributeElementSourceImpl.java @@ -97,9 +97,14 @@ public class CompositePluralAttributeElementSourceImpl @Override public List attributeSources() { List attributeSources = new ArrayList(); - for ( Object attribute : compositeElement.getPropertyOrManyToOneOrAny() ) { - - } +// for ( Object attribute : compositeElement .getPropertyOrManyToOneOrAny() ) { +// +// } + compositeElement.getAny(); + compositeElement.getManyToOne(); + compositeElement.getNestedCompositeElement(); + compositeElement.getProperty(); + //todo implement return attributeSources; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/RootEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/RootEntitySourceImpl.java index c835be41fc..eafa5b7e41 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/RootEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/RootEntitySourceImpl.java @@ -39,6 +39,8 @@ import org.hibernate.internal.jaxb.mapping.hbm.JaxbCompositeElementElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbCompositeIdElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbDiscriminatorElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping; +import org.hibernate.internal.jaxb.mapping.hbm.JaxbKeyManyToOneElement; +import org.hibernate.internal.jaxb.mapping.hbm.JaxbKeyPropertyElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbManyToManyElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbMultiTenancyElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbNaturalIdElement; @@ -139,16 +141,15 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro protected List buildAttributeSources(List attributeSources) { final JaxbNaturalIdElement naturalId = entityElement().getNaturalId(); if ( naturalId != null ) { - processAttributes( - attributeSources, - naturalId.getPropertyOrManyToOneOrComponent(), - null, - naturalId.isMutable() - ? SingularAttributeBinding.NaturalIdMutability.MUTABLE - : SingularAttributeBinding.NaturalIdMutability.IMMUTABLE + return buildAttributeSources( + entityElement(), attributeSources, null, naturalId.isMutable() + ? SingularAttributeBinding.NaturalIdMutability.MUTABLE + : SingularAttributeBinding.NaturalIdMutability.IMMUTABLE ); } - return super.buildAttributeSources( attributeSources ); + else { + return super.buildAttributeSources( attributeSources ); + } } @Override @@ -446,8 +447,15 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro @Override protected List buildAttributeSources() { List attributeSources = new ArrayList(); - for ( Object attributeElement : compositeIdElement().getKeyPropertyOrKeyManyToOne() ) { - attributeSources.add( buildAttributeSource( attributeElement ) ); +// for ( Object attributeElement : compositeIdElement().getKeyPropertyOrKeyManyToOne() ) { +// attributeSources.add( buildAttributeSource( attributeElement ) ); +// } + for ( JaxbKeyPropertyElement element : compositeIdElement().getKeyProperty()){ +// attributeSources.add( buildPropertyAttributeSource( element ) ); + //todo : implement + } + for (JaxbKeyManyToOneElement element : compositeIdElement().getKeyManyToOne()){ + //todo: implement } return attributeSources; } @@ -536,18 +544,33 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro @Override public List getAttributeSourcesMakingUpIdentifier() { - List attributeSources = new ArrayList(); - for ( Object attributeElement : entityElement().getCompositeId().getKeyPropertyOrKeyManyToOne() ) { - final AttributeSource attributeSource = buildAttributeSource( - attributeElement, - null, - SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID - ); - if ( ! attributeSource.isSingular() ) { - throw new HibernateException( "Only singular attributes are supported for composite identifiers" ); - } - attributeSources.add( (SingularAttributeSource) attributeSource ); + final List attributeSources = new ArrayList(); + final JaxbCompositeIdElement compositeId = entityElement().getCompositeId(); + for(final JaxbKeyPropertyElement keyProperty: compositeId.getKeyProperty()){ +// final AttributeSource attributeSource = buildAttributeSource( +// keyProperty, +// null, +// SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID +// ); +// if ( ! attributeSource.isSingular() ) { +// throw new HibernateException( "Only singular attributes are supported for composite identifiers" ); +// } +// attributeSources.add( (SingularAttributeSource) attributeSource ); + //todo : implement } + for(final JaxbKeyManyToOneElement keyProperty : compositeId.getKeyManyToOne()){ +// final AttributeSource attributeSource = buildAttributeSource( +// keyProperty, +// null, +// SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID +// ); +// if ( ! attributeSource.isSingular() ) { +// throw new HibernateException( "Only singular attributes are supported for composite identifiers" ); +// } +// attributeSources.add( (SingularAttributeSource) attributeSource ); + //todo : implement + } + return attributeSources; } diff --git a/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd b/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd index 09f2dcba7a..367301a70c 100644 --- a/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd +++ b/hibernate-core/src/main/resources/org/hibernate/hibernate-mapping-4.0.xsd @@ -148,6 +148,11 @@ arbitrary number of queries, and import declarations of arbitrary classes. + + + + + @@ -553,6 +558,11 @@ arbitrary number of queries, and import declarations of arbitrary classes. + + + + + @@ -704,7 +714,12 @@ arbitrary number of queries, and import declarations of arbitrary classes. - + + + + + + @@ -734,7 +749,12 @@ arbitrary number of queries, and import declarations of arbitrary classes. - + + + + + + @@ -1400,6 +1420,11 @@ arbitrary number of queries, and import declarations of arbitrary classes. + + + + + @@ -1480,7 +1505,12 @@ arbitrary number of queries, and import declarations of arbitrary classes. - + + + + + +