HHH-7450 simplify xsd
This commit is contained in:
parent
d6ab4a203a
commit
95a06fc49f
|
@ -32,10 +32,11 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.bytecode.buildtime.spi.Logger;
|
||||
import org.hibernate.cfg.HbmBinder;
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryJoinReturn;
|
||||
|
@ -47,12 +48,14 @@ import org.hibernate.engine.spi.NamedSQLQueryDefinition;
|
|||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.jaxb.Origin;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.EntityElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbClassElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbDatabaseObjectElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbFetchProfileElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbFilterDefElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbIdentifierGeneratorElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbImportElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbJoinedSubclassElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbLoadCollectionElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbQueryElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbQueryParamElement;
|
||||
|
@ -61,12 +64,13 @@ import org.hibernate.internal.jaxb.mapping.hbm.JaxbReturnElement;
|
|||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbReturnJoinElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbReturnScalarElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbSqlQueryElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbSubclassElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbSynchronizeElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbTypedefElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbUnionSubclassElement;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.Value;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.spi.binding.FetchProfile;
|
||||
import org.hibernate.metamodel.spi.relational.AuxiliaryDatabaseObject;
|
||||
|
@ -88,9 +92,7 @@ import org.hibernate.type.Type;
|
|||
* @author Strong Liu
|
||||
*/
|
||||
public class HibernateMappingProcessor {
|
||||
private static final CoreMessageLogger LOG = org.jboss
|
||||
.logging
|
||||
.Logger
|
||||
private static final CoreMessageLogger LOG = Logger
|
||||
.getMessageLogger( CoreMessageLogger.class, HibernateMappingProcessor.class.getName() );
|
||||
private final MetadataImplementor metadata;
|
||||
private final MappingDocument mappingDocument;
|
||||
|
@ -244,23 +246,50 @@ public class HibernateMappingProcessor {
|
|||
metadata.addImport( className, rename );
|
||||
}
|
||||
if ( root.isAutoImport() ) {
|
||||
for ( Object obj : root.getClazzOrSubclassOrJoinedSubclass() ) {
|
||||
EntityElement entityElement = ( EntityElement ) obj;
|
||||
String qualifiedName = bindingContext().determineEntityName( entityElement );
|
||||
metadata.addImport( entityElement.getEntityName() == null
|
||||
? entityElement.getName()
|
||||
: entityElement.getEntityName(), qualifiedName );
|
||||
for(final JaxbClassElement element : root.getClazz()){
|
||||
processEntityElement( element );
|
||||
}
|
||||
for(final JaxbJoinedSubclassElement element : root.getJoinedSubclass()){
|
||||
processEntityElement( element );
|
||||
}
|
||||
for(final JaxbUnionSubclassElement element : root.getUnionSubclass()){
|
||||
processEntityElement( element );
|
||||
}
|
||||
for(final JaxbSubclassElement element : root.getSubclass()){
|
||||
processEntityElement( element );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processEntityElement(EntityElement element) {
|
||||
EntityElement entityElement = element;
|
||||
String qualifiedName = bindingContext().determineEntityName( entityElement );
|
||||
metadata.addImport( entityElement.getEntityName() == null
|
||||
? entityElement.getName()
|
||||
: entityElement.getEntityName(), qualifiedName );
|
||||
}
|
||||
|
||||
private void processResultSetMappings() {
|
||||
List<JaxbResultsetElement> resultsetElements = new ArrayList<JaxbResultsetElement>();
|
||||
if ( CollectionHelper.isNotEmpty( mappingRoot().getResultset() ) ) {
|
||||
resultsetElements.addAll( mappingRoot().getResultset() );
|
||||
}
|
||||
for ( Object obj : mappingRoot().getClazzOrSubclassOrJoinedSubclass() ) {
|
||||
EntityElement element = EntityElement.class.cast( obj );
|
||||
for(final JaxbClassElement element : mappingRoot().getClazz()){
|
||||
if ( CollectionHelper.isNotEmpty( element.getResultset() ) ) {
|
||||
resultsetElements.addAll( element.getResultset() );
|
||||
}
|
||||
}
|
||||
for(final JaxbJoinedSubclassElement element : mappingRoot().getJoinedSubclass()){
|
||||
if ( CollectionHelper.isNotEmpty( element.getResultset() ) ) {
|
||||
resultsetElements.addAll( element.getResultset() );
|
||||
}
|
||||
}
|
||||
for(final JaxbUnionSubclassElement element : mappingRoot().getUnionSubclass()){
|
||||
if ( CollectionHelper.isNotEmpty( element.getResultset() ) ) {
|
||||
resultsetElements.addAll( element.getResultset() );
|
||||
}
|
||||
}
|
||||
for(final JaxbSubclassElement element : mappingRoot().getSubclass()){
|
||||
if ( CollectionHelper.isNotEmpty( element.getResultset() ) ) {
|
||||
resultsetElements.addAll( element.getResultset() );
|
||||
}
|
||||
|
@ -276,33 +305,34 @@ public class HibernateMappingProcessor {
|
|||
|
||||
private void bindResultSetMappingDefinitions(JaxbResultsetElement element) {
|
||||
final ResultSetMappingDefinition definition = new ResultSetMappingDefinition( element.getName() );
|
||||
final List returns = element.getReturnScalarOrReturnOrReturnJoin();
|
||||
int cnt=0;
|
||||
for ( final Object obj : returns ) {
|
||||
NativeSQLQueryReturn nativeSQLQueryReturn;
|
||||
for(final JaxbReturnScalarElement r : element.getReturnScalar()){
|
||||
cnt++;
|
||||
final NativeSQLQueryReturn nativeSQLQueryReturn;
|
||||
if ( JaxbReturnScalarElement.class.isInstance( obj ) ) {
|
||||
JaxbReturnScalarElement scalarElement = JaxbReturnScalarElement.class.cast( obj );
|
||||
String column = scalarElement.getColumn();
|
||||
String typeFromXML = scalarElement.getType();
|
||||
Type type = metadata.getTypeResolver().heuristicType( typeFromXML );
|
||||
nativeSQLQueryReturn = new NativeSQLQueryScalarReturn( column, type );
|
||||
}
|
||||
else if ( JaxbReturnJoinElement.class.isInstance( obj ) ) {
|
||||
nativeSQLQueryReturn = bindReturnJoin(JaxbReturnJoinElement.class.cast( obj ), cnt);
|
||||
|
||||
}
|
||||
else if ( JaxbLoadCollectionElement.class.isInstance( obj ) ) {
|
||||
nativeSQLQueryReturn = bindLoadCollection(JaxbLoadCollectionElement.class.cast( obj ), cnt);
|
||||
}
|
||||
else if ( JaxbReturnElement.class.isInstance( obj ) ) {
|
||||
nativeSQLQueryReturn= bindReturn(JaxbReturnElement.class.cast( obj ), cnt);
|
||||
|
||||
}else {
|
||||
throw new MappingException( "unknown type of Result set mapping return: "+obj.getClass().getName() , origin());
|
||||
}
|
||||
String column = r.getColumn();
|
||||
String typeFromXML = r.getType();
|
||||
Type type = metadata.getTypeResolver().heuristicType( typeFromXML );
|
||||
nativeSQLQueryReturn = new NativeSQLQueryScalarReturn( column, type );
|
||||
definition.addQueryReturn( nativeSQLQueryReturn );
|
||||
}
|
||||
for(final JaxbReturnJoinElement r : element.getReturnJoin()){
|
||||
cnt++;
|
||||
nativeSQLQueryReturn = bindReturnJoin(r, cnt);
|
||||
definition.addQueryReturn( nativeSQLQueryReturn );
|
||||
|
||||
}
|
||||
for(final JaxbLoadCollectionElement r : element.getLoadCollection()){
|
||||
cnt++;
|
||||
nativeSQLQueryReturn = bindLoadCollection( r, cnt );
|
||||
definition.addQueryReturn( nativeSQLQueryReturn );
|
||||
|
||||
}
|
||||
for(final JaxbReturnElement r : element.getReturn()){
|
||||
cnt++;
|
||||
nativeSQLQueryReturn = bindReturn( r, cnt );
|
||||
definition.addQueryReturn( nativeSQLQueryReturn );
|
||||
|
||||
}
|
||||
metadata.addResultSetMapping( definition );
|
||||
|
||||
}
|
||||
|
|
|
@ -65,40 +65,48 @@ public class HierarchyBuilder {
|
|||
}
|
||||
|
||||
private void processCurrentMappingDocument() {
|
||||
for ( Object entityElementO : currentMappingDocument.getMappingRoot().getClazzOrSubclassOrJoinedSubclass() ) {
|
||||
final EntityElement entityElement = (EntityElement) entityElementO;
|
||||
if ( JaxbClassElement.class.isInstance( entityElement ) ) {
|
||||
// we can immediately handle <class/> elements in terms of creating the hierarchy entry
|
||||
final JaxbClassElement jaxbClass = (JaxbClassElement) entityElement;
|
||||
final RootEntitySourceImpl rootEntitySource = new RootEntitySourceImpl( currentMappingDocument,
|
||||
jaxbClass
|
||||
);
|
||||
final EntityHierarchyImpl hierarchy = new EntityHierarchyImpl( rootEntitySource );
|
||||
for(final JaxbClassElement jaxbClass : currentMappingDocument.getMappingRoot().getClazz()){
|
||||
// we can immediately handle <class/> elements in terms of creating the hierarchy entry
|
||||
final RootEntitySourceImpl rootEntitySource = new RootEntitySourceImpl( currentMappingDocument,
|
||||
jaxbClass
|
||||
);
|
||||
final EntityHierarchyImpl hierarchy = new EntityHierarchyImpl( rootEntitySource );
|
||||
|
||||
entityHierarchies.add( hierarchy );
|
||||
subEntityContainerMap.put( rootEntitySource.getEntityName(), rootEntitySource );
|
||||
entityHierarchies.add( hierarchy );
|
||||
subEntityContainerMap.put( rootEntitySource.getEntityName(), rootEntitySource );
|
||||
|
||||
processSubElements( entityElement, rootEntitySource );
|
||||
}
|
||||
else {
|
||||
// we have to see if this things super-type has been found yet, and if not add it to the
|
||||
// extends queue
|
||||
final String entityItExtends = currentMappingDocument.getMappingLocalBindingContext()
|
||||
.qualifyClassName( ( (SubEntityElement) entityElement ).getExtends() );
|
||||
final SubclassEntityContainer container = subEntityContainerMap.get( entityItExtends );
|
||||
final SubclassEntitySourceImpl subClassEntitySource = new SubclassEntitySourceImpl( currentMappingDocument, entityElement, ( EntitySource ) container );
|
||||
final String entityName = subClassEntitySource.getEntityName();
|
||||
subEntityContainerMap.put( entityName, subClassEntitySource );
|
||||
processSubElements( entityElement, subClassEntitySource );
|
||||
if ( container != null ) {
|
||||
// we already have this entity's super, attach it and continue
|
||||
container.add( subClassEntitySource );
|
||||
}
|
||||
else {
|
||||
// we do not yet have the super and have to wait, so add it fto the extends queue
|
||||
extendsQueue.add( new ExtendsQueueEntry( subClassEntitySource, entityItExtends ) );
|
||||
}
|
||||
}
|
||||
processSubElements( jaxbClass, rootEntitySource );
|
||||
}
|
||||
for(final JaxbJoinedSubclassElement element : currentMappingDocument.getMappingRoot().getJoinedSubclass()){
|
||||
processSubclassElement( element );
|
||||
|
||||
}
|
||||
for(final JaxbUnionSubclassElement element : currentMappingDocument.getMappingRoot().getUnionSubclass()){
|
||||
processSubclassElement( element );
|
||||
}
|
||||
for(final JaxbSubclassElement element : currentMappingDocument.getMappingRoot().getSubclass()){
|
||||
processSubclassElement( element );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processSubclassElement(SubEntityElement element) {
|
||||
// we have to see if this things super-type has been found yet, and if not add it to the
|
||||
// extends queue
|
||||
final String entityItExtends = currentMappingDocument.getMappingLocalBindingContext()
|
||||
.qualifyClassName( element.getExtends() );
|
||||
final SubclassEntityContainer container = subEntityContainerMap.get( entityItExtends );
|
||||
final SubclassEntitySourceImpl subClassEntitySource = new SubclassEntitySourceImpl( currentMappingDocument, element, (EntitySource) container );
|
||||
final String entityName = subClassEntitySource.getEntityName();
|
||||
subEntityContainerMap.put( entityName, subClassEntitySource );
|
||||
processSubElements( element, subClassEntitySource );
|
||||
if ( container != null ) {
|
||||
// we already have this entity's super, attach it and continue
|
||||
container.add( subClassEntitySource );
|
||||
}
|
||||
else {
|
||||
// we do not yet have the super and have to wait, so add it fto the extends queue
|
||||
extendsQueue.add( new ExtendsQueueEntry( subClassEntitySource, entityItExtends ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
|
|||
-->
|
||||
<xs:element name="import" minOccurs="0" maxOccurs="unbounded" type="import-element"/>
|
||||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:annotation>
|
||||
<xs:appinfo>
|
||||
<simplify:as-element-property/>
|
||||
</xs:appinfo>
|
||||
</xs:annotation>
|
||||
<!--
|
||||
Root entity mapping. Poorly named as entities do not have to be represented by
|
||||
classes at all. Mapped entities may be represented via different methodologies
|
||||
|
@ -991,6 +996,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
|
|||
<xs:complexType name="composite-map-key-element">
|
||||
<xs:sequence>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:annotation>
|
||||
<xs:appinfo>
|
||||
<simplify:as-element-property/>
|
||||
</xs:appinfo>
|
||||
</xs:annotation>
|
||||
<xs:element name="key-property" type="key-property-element"/>
|
||||
<xs:element name="key-many-to-one" type="key-many-to-one-element"/>
|
||||
</xs:choice>
|
||||
|
@ -1010,6 +1020,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
|
|||
<xs:complexType name="composite-index-element">
|
||||
<xs:sequence>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:annotation>
|
||||
<xs:appinfo>
|
||||
<simplify:as-element-property/>
|
||||
</xs:appinfo>
|
||||
</xs:annotation>
|
||||
<xs:element name="key-property" type="key-property-element"/>
|
||||
<xs:element name="key-many-to-one" type="key-many-to-one-element"/>
|
||||
</xs:choice>
|
||||
|
@ -1211,6 +1226,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
|
|||
<xs:complexType name="properties-element">
|
||||
<xs:sequence>
|
||||
<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="many-to-one" type="many-to-one-element"/>
|
||||
<xs:element name="component" type="component-element"/>
|
||||
|
@ -1279,6 +1299,11 @@ arbitrary number of queries, and import declarations of arbitrary classes.
|
|||
<!-- The resultset element declares a named resultset mapping definition for SQL queries -->
|
||||
<xs:complexType name="resultset-element">
|
||||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:annotation>
|
||||
<xs:appinfo>
|
||||
<simplify:as-element-property/>
|
||||
</xs:appinfo>
|
||||
</xs:annotation>
|
||||
<xs:element name="return-scalar" type="return-scalar-element"/>
|
||||
<xs:element name="return" type="return-element"/>
|
||||
<xs:element name="return-join" type="return-join-element"/>
|
||||
|
@ -1397,6 +1422,7 @@ arbitrary number of queries, and import declarations of arbitrary classes.
|
|||
<!-- The sql-query element declares a named SQL query string -->
|
||||
<xs:complexType name="sql-query-element" mixed="true">
|
||||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||
|
||||
<xs:element name="return-scalar" type="return-scalar-element"/>
|
||||
<xs:element name="return" type="return-element"/>
|
||||
<xs:element name="return-join" type="return-join-element"/>
|
||||
|
|
Loading…
Reference in New Issue