HHH-7450 apply simplify plugin

This commit is contained in:
Strong Liu 2012-07-16 18:28:49 +08:00
parent 2eb320b9c6
commit d57ffbdb32
5 changed files with 282 additions and 110 deletions

View File

@ -56,5 +56,18 @@ public interface EntityElement extends MetaAttributeContainer {
public List<Object> getQueryOrSqlQuery(); public List<Object> getQueryOrSqlQuery();
public List<Object> getPropertyOrManyToOneOrOneToOne(); public List<JaxbPropertyElement> getProperty();
public List<JaxbManyToOneElement> getManyToOne();
public List<JaxbOneToOneElement> getOneToOne();
public List<JaxbComponentElement> getComponent();
public List<JaxbDynamicComponentElement> getDynamicComponent();
// public List<JaxbPropertiesElement> getProperties();
public List<JaxbAnyElement> getAny();
public List<JaxbMapElement> getMap();
public List<JaxbSetElement> getSet();
public List<JaxbListElement> getList();
public List<JaxbBagElement> getBag();
public List<JaxbIdbagElement> getIdbag();
public List<JaxbArrayElement> getArray();
public List<JaxbPrimitiveArrayElement> getPrimitiveArray();
} }

View File

@ -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.JaxbAnyElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbBagElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbBagElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbComponentElement; 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.JaxbIdbagElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbJoinElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbJoinElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbListElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbListElement;
@ -105,97 +106,172 @@ public abstract class AbstractEntitySourceImpl
} }
protected List<AttributeSource> buildAttributeSources(List<AttributeSource> attributeSources) { protected List<AttributeSource> buildAttributeSources(List<AttributeSource> attributeSources) {
processAttributes( return buildAttributeSources( entityElement, attributeSources, null, SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID );
}
protected List<AttributeSource> buildAttributeSources(EntityElement element,
List<AttributeSource> attributeSources,
String logicTalbeName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability){
processPropertyAttributes( attributeSources, element.getProperty(), logicTalbeName, naturalIdMutability );
processComponentAttributes(
attributeSources, attributeSources,
entityElement.getPropertyOrManyToOneOrOneToOne(), element.getComponent(),
null, logicTalbeName,
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID 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; return attributeSources;
} }
protected void processAttributes( protected void processPropertyAttributes(List<AttributeSource> results,
List<AttributeSource> results, List<JaxbPropertyElement> propertyElements,
List attributeElements, String logicalTableName,
String logicalTableName, SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { for ( JaxbPropertyElement element : propertyElements ) {
for ( Object attributeElement : attributeElements ) { results.add(
results.add( buildAttributeSource( attributeElement, logicalTableName, naturalIdMutability ) ); new PropertyAttributeSourceImpl(
sourceMappingDocument(),
element,
logicalTableName,
naturalIdMutability
)
);
} }
} }
protected AttributeSource buildAttributeSource( protected void processComponentAttributes(List<AttributeSource> results,
Object attributeElement, List<JaxbComponentElement> elements,
String logicalTableName, String logicalTableName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) { SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
if ( JaxbPropertyElement.class.isInstance( attributeElement ) ) { for ( JaxbComponentElement element : elements ) {
return new PropertyAttributeSourceImpl( results.add(
sourceMappingDocument(), new ComponentAttributeSourceImpl(
JaxbPropertyElement.class.cast( attributeElement ), sourceMappingDocument(),
logicalTableName, element,
naturalIdMutability 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<AttributeSource> results,
List<JaxbDynamicComponentElement> elements,
String logicalTableName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
// todo : implement
}
protected void processManyToOneAttributes(List<AttributeSource> results,
List<JaxbManyToOneElement> elements,
String logicalTableName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
for ( JaxbManyToOneElement element : elements ) {
results.add(
new ManyToOneAttributeSourceImpl(
sourceMappingDocument(),
element,
logicalTableName,
naturalIdMutability
)
);
}
}
protected void processOneToOneAttributes(List<AttributeSource> results,
List<JaxbOneToOneElement> elements,
String logicalTableName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
// todo : implement
}
protected void processAnyAttributes(List<AttributeSource> results,
List<JaxbAnyElement> elements,
String logicalTableName,
SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
// todo : implement
}
protected void processMapAttributes(List<AttributeSource> results,
List<JaxbMapElement> propertyElements){
for ( JaxbMapElement element : propertyElements ) {
results.add(
new MapAttributeSource(
sourceMappingDocument(),
element, this
)
);
}
}
protected void processListAttributes(List<AttributeSource> results,
List<JaxbListElement> propertyElements){
for ( JaxbListElement element : propertyElements ) {
results.add(
new ListAttributeSource(
sourceMappingDocument(),
element, this
)
);
}
}
protected void processSetAttributes(List<AttributeSource> results,
List<JaxbSetElement> propertyElements){
for ( JaxbSetElement element : propertyElements ) {
results.add(
new SetAttributeSourceImpl(
sourceMappingDocument(),
element,
this
)
);
}
}
protected void processIdBagAttributes(List<AttributeSource> results,
List<JaxbIdbagElement> propertyElements){
// todo : implement
}
protected void processBagAttributes(List<AttributeSource> results,
List<JaxbBagElement> propertyElements) {
for ( JaxbBagElement element : propertyElements ) {
results.add(
new BagAttributeSourceImpl(
sourceMappingDocument(),
element,
this
)
);
}
}
private Set<SecondaryTableSource> buildSecondaryTables() { private Set<SecondaryTableSource> buildSecondaryTables() {
if ( ! JoinElementSource.class.isInstance( entityElement ) ) { if ( ! JoinElementSource.class.isInstance( entityElement ) ) {
return Collections.emptySet(); return Collections.emptySet();
@ -211,11 +287,36 @@ public abstract class AbstractEntitySourceImpl
secondaryTableSources.add( secondaryTableSource ); secondaryTableSources.add( secondaryTableSource );
final String logicalTableName = secondaryTableSource.getLogicalTableNameForContainedColumns(); final String logicalTableName = secondaryTableSource.getLogicalTableNameForContainedColumns();
processAttributes( final SingularAttributeBinding.NaturalIdMutability naturalIdMutability = SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID;
processAnyAttributes(
attributeSources, attributeSources,
joinElement.getPropertyOrManyToOneOrComponent(), joinElement.getAny(),
logicalTableName, 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; return secondaryTableSources;

View File

@ -97,9 +97,14 @@ public class CompositePluralAttributeElementSourceImpl
@Override @Override
public List<AttributeSource> attributeSources() { public List<AttributeSource> attributeSources() {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>(); List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
for ( Object attribute : compositeElement.getPropertyOrManyToOneOrAny() ) { // for ( Object attribute : compositeElement .getPropertyOrManyToOneOrAny() ) {
//
} // }
compositeElement.getAny();
compositeElement.getManyToOne();
compositeElement.getNestedCompositeElement();
compositeElement.getProperty();
//todo implement
return attributeSources; return attributeSources;
} }

View File

@ -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.JaxbCompositeIdElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbDiscriminatorElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbDiscriminatorElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping; 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.JaxbManyToManyElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbMultiTenancyElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbMultiTenancyElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbNaturalIdElement; import org.hibernate.internal.jaxb.mapping.hbm.JaxbNaturalIdElement;
@ -139,16 +141,15 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
protected List<AttributeSource> buildAttributeSources(List<AttributeSource> attributeSources) { protected List<AttributeSource> buildAttributeSources(List<AttributeSource> attributeSources) {
final JaxbNaturalIdElement naturalId = entityElement().getNaturalId(); final JaxbNaturalIdElement naturalId = entityElement().getNaturalId();
if ( naturalId != null ) { if ( naturalId != null ) {
processAttributes( return buildAttributeSources(
attributeSources, entityElement(), attributeSources, null, naturalId.isMutable()
naturalId.getPropertyOrManyToOneOrComponent(), ? SingularAttributeBinding.NaturalIdMutability.MUTABLE
null, : SingularAttributeBinding.NaturalIdMutability.IMMUTABLE
naturalId.isMutable()
? SingularAttributeBinding.NaturalIdMutability.MUTABLE
: SingularAttributeBinding.NaturalIdMutability.IMMUTABLE
); );
} }
return super.buildAttributeSources( attributeSources ); else {
return super.buildAttributeSources( attributeSources );
}
} }
@Override @Override
@ -446,8 +447,15 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
@Override @Override
protected List<AttributeSource> buildAttributeSources() { protected List<AttributeSource> buildAttributeSources() {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>(); List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
for ( Object attributeElement : compositeIdElement().getKeyPropertyOrKeyManyToOne() ) { // for ( Object attributeElement : compositeIdElement().getKeyPropertyOrKeyManyToOne() ) {
attributeSources.add( buildAttributeSource( attributeElement ) ); // attributeSources.add( buildAttributeSource( attributeElement ) );
// }
for ( JaxbKeyPropertyElement element : compositeIdElement().getKeyProperty()){
// attributeSources.add( buildPropertyAttributeSource( element ) );
//todo : implement
}
for (JaxbKeyManyToOneElement element : compositeIdElement().getKeyManyToOne()){
//todo: implement
} }
return attributeSources; return attributeSources;
} }
@ -536,18 +544,33 @@ public class RootEntitySourceImpl extends AbstractEntitySourceImpl implements Ro
@Override @Override
public List<SingularAttributeSource> getAttributeSourcesMakingUpIdentifier() { public List<SingularAttributeSource> getAttributeSourcesMakingUpIdentifier() {
List<SingularAttributeSource> attributeSources = new ArrayList<SingularAttributeSource>(); final List<SingularAttributeSource> attributeSources = new ArrayList<SingularAttributeSource>();
for ( Object attributeElement : entityElement().getCompositeId().getKeyPropertyOrKeyManyToOne() ) { final JaxbCompositeIdElement compositeId = entityElement().getCompositeId();
final AttributeSource attributeSource = buildAttributeSource( for(final JaxbKeyPropertyElement keyProperty: compositeId.getKeyProperty()){
attributeElement, // final AttributeSource attributeSource = buildAttributeSource(
null, // keyProperty,
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID // null,
); // SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
if ( ! attributeSource.isSingular() ) { // );
throw new HibernateException( "Only singular attributes are supported for composite identifiers" ); // if ( ! attributeSource.isSingular() ) {
} // throw new HibernateException( "Only singular attributes are supported for composite identifiers" );
attributeSources.add( (SingularAttributeSource) attributeSource ); // }
// 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; return attributeSources;
} }

View File

@ -148,6 +148,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="multi-tenancy" type="multi-tenancy-element"/> <xs:element name="multi-tenancy" type="multi-tenancy-element"/>
</xs:choice> </xs:choice>
<xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
<xs:element name="property" type="property-element"/> <xs:element name="property" type="property-element"/>
<xs:element name="many-to-one" type="many-to-one-element"/> <xs:element name="many-to-one" type="many-to-one-element"/>
<xs:element name="one-to-one" type="one-to-one-element"/> <xs:element name="one-to-one" type="one-to-one-element"/>
@ -553,6 +558,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:complexType name="dynamic-component-element"> <xs:complexType name="dynamic-component-element">
<xs:sequence> <xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
<xs:element name="property" type="property-element"/> <xs:element name="property" type="property-element"/>
<xs:element name="many-to-one" type="many-to-one-element"/> <xs:element name="many-to-one" type="many-to-one-element"/>
<xs:element name="one-to-one" type="one-to-one-element"/> <xs:element name="one-to-one" type="one-to-one-element"/>
@ -704,7 +714,12 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="comment" minOccurs="0" type="xs:string"/> <xs:element name="comment" minOccurs="0" type="xs:string"/>
<xs:element name="key" type="key-element"/> <xs:element name="key" type="key-element"/>
<xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="property" type="property-element"/> <xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
<xs:element name="property" type="property-element"/>
<xs:element name="many-to-one" type="many-to-one-element"/> <xs:element name="many-to-one" type="many-to-one-element"/>
<xs:element name="component" type="component-element"/> <xs:element name="component" type="component-element"/>
<xs:element name="dynamic-component" type="dynamic-component-element"/> <xs:element name="dynamic-component" type="dynamic-component-element"/>
@ -734,7 +749,12 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="tuplizer" minOccurs="0" maxOccurs="unbounded" type="tuplizer-element"/> <xs:element name="tuplizer" minOccurs="0" maxOccurs="unbounded" type="tuplizer-element"/>
<xs:element name="key" type="key-element"/> <xs:element name="key" type="key-element"/>
<xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="property" type="property-element"/> <xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
<xs:element name="property" type="property-element"/>
<xs:element name="many-to-one" type="many-to-one-element"/> <xs:element name="many-to-one" type="many-to-one-element"/>
<xs:element name="one-to-one" type="one-to-one-element"/> <xs:element name="one-to-one" type="one-to-one-element"/>
<xs:element name="component" type="component-element"/> <xs:element name="component" type="component-element"/>
@ -1400,6 +1420,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="tuplizer" minOccurs="0" maxOccurs="unbounded" type="tuplizer-element"/> <xs:element name="tuplizer" minOccurs="0" maxOccurs="unbounded" type="tuplizer-element"/>
<xs:element name="synchronize" minOccurs="0" maxOccurs="unbounded" type="synchronize-element"/> <xs:element name="synchronize" minOccurs="0" maxOccurs="unbounded" type="synchronize-element"/>
<xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
<xs:element name="property" type="property-element"/> <xs:element name="property" type="property-element"/>
<xs:element name="many-to-one" type="many-to-one-element"/> <xs:element name="many-to-one" type="many-to-one-element"/>
<xs:element name="one-to-one" type="one-to-one-element"/> <xs:element name="one-to-one" type="one-to-one-element"/>
@ -1480,7 +1505,12 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="comment" minOccurs="0" type="xs:string"/> <xs:element name="comment" minOccurs="0" type="xs:string"/>
<xs:element name="tuplizer" minOccurs="0" maxOccurs="unbounded" type="tuplizer-element"/> <xs:element name="tuplizer" minOccurs="0" maxOccurs="unbounded" type="tuplizer-element"/>
<xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="property" type="property-element"/> <xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
<xs:element name="property" type="property-element"/>
<xs:element name="many-to-one" type="many-to-one-element"/> <xs:element name="many-to-one" type="many-to-one-element"/>
<xs:element name="one-to-one" type="one-to-one-element"/> <xs:element name="one-to-one" type="one-to-one-element"/>
<xs:element name="component" type="component-element"/> <xs:element name="component" type="component-element"/>