From 5efd0a84710d2f114f774621ec4a34d5d78fb002 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 30 Jun 2011 21:34:19 -0500 Subject: [PATCH] HHH-6371 - Develop metamodel binding creation using a push approach --- build.gradle | 1 + .../binder/view/hbm/EntityViewImpl.java | 24 ++-- .../source/hbm/AbstractEntityBinder.java | 2 +- .../metamodel/source/hbm/EntityProcessor.java | 9 +- .../source/hbm/HbmBindingContext.java | 9 +- .../metamodel/source/hbm/HbmHelper.java | 9 ++ .../source/hbm/HbmSourceProcessor.java | 107 +++++++++++++++++- .../source/hbm/HibernateMappingProcessor.java | 86 ++++++++------ .../source/hbm/xml/mapping/Discriminated.java | 31 +++++ .../source/hbm/xml/mapping/EntityElement.java | 58 ++++++++++ .../xml/mapping/MetaAttributeContainer.java | 33 ++++++ .../xml/mapping/SubclassEntityElement.java | 31 +++++ .../tuple/entity/EntityMetamodel.java | 2 +- 13 files changed, 345 insertions(+), 57 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/Discriminated.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/EntityElement.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/MetaAttributeContainer.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/SubclassEntityElement.java diff --git a/build.gradle b/build.gradle index 2fe3749a72..53ea1d7826 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ allprojects { buildscript { repositories { + mavenCentral() mavenLocal() mavenRepo name: 'jboss-nexus', urls: "https://repository.jboss.org/nexus/content/groups/public/" mavenRepo name: "jboss-snapshots", urls: "http://snapshots.jboss.org/maven2/" diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/view/hbm/EntityViewImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/view/hbm/EntityViewImpl.java index 2415d2b50a..0a8ebb9b93 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binder/view/hbm/EntityViewImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binder/view/hbm/EntityViewImpl.java @@ -41,6 +41,7 @@ import org.hibernate.metamodel.source.Origin; import org.hibernate.metamodel.source.hbm.HbmBindingContext; import org.hibernate.metamodel.source.hbm.HbmHelper; import org.hibernate.metamodel.source.hbm.util.MappingHelper; +import org.hibernate.metamodel.source.hbm.xml.mapping.EntityElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLCacheElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement; @@ -53,6 +54,8 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.tuple.entity.EntityTuplizer; /** + * TODO : thinking it might be better to have one of these for distinct mapping type (root, subclass, joined, etc) + * * @author Gail Badner * @author Steve Ebersole */ @@ -102,7 +105,7 @@ public class EntityViewImpl implements EntityView { public EntityViewImpl( Hierarchical superType, - XMLHibernateMapping.XMLClass entityClazz, + EntityElement entityClazz, boolean isRoot, InheritanceType inheritanceType, HbmBindingContext bindingContext) { @@ -110,7 +113,7 @@ public class EntityViewImpl implements EntityView { this.bindingContext = bindingContext; this.superType = superType; - this.entityName = bindingContext.extractEntityName( entityClazz ); + this.entityName = bindingContext.determineEntityName( entityClazz ); final String verbatimClassName = entityClazz.getName(); this.entityMode = verbatimClassName == null ? EntityMode.MAP : EntityMode.POJO; @@ -135,7 +138,7 @@ public class EntityViewImpl implements EntityView { this.isRoot = isRoot; this.entityInheritanceType = inheritanceType; - this.caching = createCaching( entityClazz, bindingContext.extractEntityName( entityClazz ) ); + this.caching = isRoot ? createCaching( entityClazz, this.entityName ) : null; this.metaAttributeContext = HbmHelper.extractMetaAttributeContext( entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext() @@ -215,11 +218,11 @@ public class EntityViewImpl implements EntityView { ); } - private String extractCustomTuplizerClassName(XMLHibernateMapping.XMLClass entityClazz, EntityMode entityMode) { - if ( entityClazz.getTuplizer() == null ) { + private String extractCustomTuplizerClassName(EntityElement entityMapping, EntityMode entityMode) { + if ( entityMapping.getTuplizer() == null ) { return null; } - for ( XMLTuplizerElement tuplizerElement : entityClazz.getTuplizer() ) { + for ( XMLTuplizerElement tuplizerElement : entityMapping.getTuplizer() ) { if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) { return tuplizerElement.getClazz(); } @@ -227,8 +230,13 @@ public class EntityViewImpl implements EntityView { return null; } - private static Caching createCaching(XMLHibernateMapping.XMLClass entityClazz, String entityName) { - XMLCacheElement cache = entityClazz.getCache(); + private static Caching createCaching(EntityElement entityMapping, String entityName) { + if ( ! XMLHibernateMapping.XMLClass.class.isInstance( entityMapping ) ) { + // only the root entity can define caching + return null; + } + final XMLHibernateMapping.XMLClass rootEntityMapping = (XMLHibernateMapping.XMLClass) entityMapping; + XMLCacheElement cache = rootEntityMapping.getCache(); if ( cache == null ) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java index ca7f58397a..4810aab849 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntityBinder.java @@ -137,7 +137,7 @@ abstract class AbstractEntityBinder { final String entityName = entityBinding.getEntity().getName(); if ( entityClazz.getFetchProfile() != null ) { - bindingContext.bindFetchProfiles( entityClazz.getFetchProfile(), entityName ); + bindingContext.processFetchProfiles( entityClazz.getFetchProfile(), entityName ); } getMetadata().addImport( entityName, entityName ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/EntityProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/EntityProcessor.java index c4aeb977ca..8ea29c9e7b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/EntityProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/EntityProcessor.java @@ -26,12 +26,13 @@ package org.hibernate.metamodel.source.hbm; import org.hibernate.metamodel.binder.EntityBinder; import org.hibernate.metamodel.binder.view.hbm.EntityViewImpl; import org.hibernate.metamodel.binding.EntityBinding; +import org.hibernate.metamodel.source.hbm.xml.mapping.EntityElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; /** * @author Steve Ebersole */ -public class EntityProcessor { +public abstract class EntityProcessor { private final HbmBindingContext bindingContext; private final EntityBinder entityBinder; @@ -40,17 +41,17 @@ public class EntityProcessor { this.entityBinder = new EntityBinder( bindingContext.getMetadataImplementor() ); } - public void process(XMLHibernateMapping.XMLClass xmlClass) { + public void process(EntityElement entityMapping) { EntityBinding entityBinding = entityBinder.createEntityBinding( new EntityViewImpl( null, // superType - xmlClass, + entityMapping, true, // isRoot null, // inheritanceType bindingContext ) ); - bindingContext. + bindingContext.getMetadataImplementor().addEntity( entityBinding ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmBindingContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmBindingContext.java index ef6118e3c5..9c3ff888b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmBindingContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmBindingContext.java @@ -25,8 +25,8 @@ package org.hibernate.metamodel.source.hbm; import java.util.List; -import org.hibernate.internal.util.xml.XmlDocument; import org.hibernate.metamodel.source.Origin; +import org.hibernate.metamodel.source.hbm.xml.mapping.EntityElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLFetchProfileElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; import org.hibernate.metamodel.source.spi.BindingContext; @@ -37,11 +37,12 @@ import org.hibernate.metamodel.source.spi.BindingContext; public interface HbmBindingContext extends BindingContext { public boolean isAutoImport(); + public Origin getOrigin(); + public String extractEntityName(XMLHibernateMapping.XMLClass entityClazz); + public String determineEntityName(EntityElement entityElement); public String getClassName(String unqualifiedName); - public void bindFetchProfiles(List fetchProfiles, String containingEntityName); - - public Origin getOrigin(); + public void processFetchProfiles(List fetchProfiles, String containingEntityName); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java index cd3529c850..119d86125f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmHelper.java @@ -34,6 +34,7 @@ import org.hibernate.MappingException; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.metamodel.binding.CustomSQL; import org.hibernate.metamodel.binding.MetaAttribute; +import org.hibernate.metamodel.source.hbm.xml.mapping.EntityElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement; import org.hibernate.metamodel.source.hbm.util.MappingHelper; @@ -102,6 +103,14 @@ public class HbmHelper { return entityName == null ? getClassName( entityClassName, unqualifiedPackageName ) : entityName; } + public static String determineEntityName(EntityElement entityElement, String packageName) { + return extractEntityName( entityElement.getEntityName(), entityElement.getName(), packageName ); + } + + public static String determineClassName(EntityElement entityElement, String packageName) { + return getClassName( entityElement.getName(), packageName ); + } + public static String getClassName(Attribute att, String unqualifiedPackageName) { if ( att == null ) { return null; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmSourceProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmSourceProcessor.java index fe3f926ef3..8ae68b1c35 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmSourceProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HbmSourceProcessor.java @@ -24,13 +24,20 @@ package org.hibernate.metamodel.source.hbm; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; +import org.hibernate.MappingException; import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.source.hbm.xml.mapping.EntityElement; +import org.hibernate.metamodel.source.hbm.xml.mapping.SubclassEntityElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; import org.hibernate.metamodel.source.internal.JaxbRoot; -import org.hibernate.metamodel.source.spi.SourceProcessor; import org.hibernate.metamodel.source.spi.MetadataImplementor; +import org.hibernate.metamodel.source.spi.SourceProcessor; /** * Responsible for performing binding of hbm xml. @@ -57,28 +64,118 @@ public class HbmSourceProcessor implements SourceProcessor { @Override public void processIndependentMetadata(MetadataSources sources) { for ( HibernateMappingProcessor processor : processors ) { - processor.bindIndependentMetadata(); + processor.processIndependentMetadata(); } } @Override public void processTypeDependentMetadata(MetadataSources sources) { for ( HibernateMappingProcessor processor : processors ) { - processor.bindTypeDependentMetadata(); + processor.processTypeDependentMetadata(); } } @Override public void processMappingMetadata(MetadataSources sources, List processedEntityNames) { + // Lets get the entities into a better order for processing based on inheritance hierarchy to avoid the need + // for an "extends queue". Really, for correctly, we localize the "extends queue" to just this method stack. + // + // The variable entityMappingByEntityNameMap holds the "resolved" mappings, keyed by entity name. It uses a + // linked map because the order is important here as we will use it to track which entities depend on which + // other entities. + // + // The extendsQueue variable is a temporary queue where we place mappings which have an extends but for which + // we could not find the referenced entity being extended. + + + + + final Set availableEntityNames = new HashSet(); + availableEntityNames.addAll( processedEntityNames ); + + + + + + + + + final LinkedHashSet orderedProcessors = new LinkedHashSet(); + final Set extendsQueue = new HashSet(); + for ( HibernateMappingProcessor processor : processors ) { - processor.bindMappingMetadata( processedEntityNames ); + final HibernateMappingInformation hibernateMappingInformation = new HibernateMappingInformation( processor ); + ExtendsQueueEntry extendsQueueEntry = null; + for ( Object entityElementO : processor.getHibernateMapping().getClazzOrSubclassOrJoinedSubclass() ) { + final EntityElement entityElement = (EntityElement) entityElementO; + final String entityName = processor.determineEntityName( entityElement ); + hibernateMappingInformation.includedEntityNames.add( entityName ); + if ( SubclassEntityElement.class.isInstance( entityElement ) ) { + final String entityItExtends = ( (SubclassEntityElement) entityElement ).getExtends(); + if ( ! availableEntityNames.contains( entityItExtends ) ) { + if ( extendsQueueEntry == null ) { + extendsQueueEntry = new ExtendsQueueEntry( hibernateMappingInformation ); + extendsQueue.add( extendsQueueEntry ); + } + extendsQueueEntry.waitingOnEntityNames.add( entityItExtends ); + } + } + } + if ( extendsQueueEntry == null ) { + // we found no extends names that we have to wait on + orderedProcessors.add( processor ); + availableEntityNames.addAll( hibernateMappingInformation.includedEntityNames ); + } + } + + while ( ! extendsQueue.isEmpty() ) { + // set up a pass over the queue + int numberOfMappingsProcessed = 0; + Iterator iterator = extendsQueue.iterator(); + while ( iterator.hasNext() ) { + final ExtendsQueueEntry entry = iterator.next(); + if ( availableEntityNames.containsAll( entry.waitingOnEntityNames ) ) { + // all the entity names this entry was waiting on have been made available + iterator.remove(); + orderedProcessors.add( entry.hibernateMappingInformation.processor ); + availableEntityNames.addAll( entry.hibernateMappingInformation.includedEntityNames ); + numberOfMappingsProcessed++; + } + } + + if ( numberOfMappingsProcessed == 0 ) { + // todo : we could log the waiting dependencies... + throw new MappingException( "Unable to process extends dependencies in hbm files" ); + } + } + + for ( HibernateMappingProcessor processor : orderedProcessors ) { + processor.processMappingMetadata( processedEntityNames ); + } + } + + private static class HibernateMappingInformation { + private final HibernateMappingProcessor processor; + private final Set includedEntityNames = new HashSet(); + + private HibernateMappingInformation(HibernateMappingProcessor processor) { + this.processor = processor; + } + } + + private static class ExtendsQueueEntry { + private HibernateMappingInformation hibernateMappingInformation; + private final Set waitingOnEntityNames = new HashSet(); + + private ExtendsQueueEntry(HibernateMappingInformation hibernateMappingInformation) { + this.hibernateMappingInformation = hibernateMappingInformation; } } @Override public void processMappingDependentMetadata(MetadataSources sources) { for ( HibernateMappingProcessor processor : processors ) { - processor.bindMappingDependentMetadata(); + processor.processMappingDependentMetadata(); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HibernateMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HibernateMappingProcessor.java index 09e44681a7..1b243fa281 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HibernateMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/HibernateMappingProcessor.java @@ -32,6 +32,7 @@ import java.util.Set; import org.hibernate.cfg.NamingStrategy; import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.Value; import org.hibernate.metamodel.binding.FetchProfile; import org.hibernate.metamodel.binding.TypeDef; import org.hibernate.metamodel.domain.JavaType; @@ -39,6 +40,7 @@ import org.hibernate.metamodel.relational.AuxiliaryDatabaseObject; import org.hibernate.metamodel.relational.BasicAuxiliaryDatabaseObjectImpl; import org.hibernate.metamodel.source.MappingException; import org.hibernate.metamodel.source.Origin; +import org.hibernate.metamodel.source.hbm.xml.mapping.EntityElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLFetchProfileElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLJoinedSubclassElement; @@ -85,8 +87,8 @@ public class HibernateMappingProcessor implements HbmBindingContext { hibernateMapping.getPackage(), hibernateMapping.getSchema(), hibernateMapping.getCatalog(), - null, - null, + null, // idColumnName + null, // discriminatorColumnName hibernateMapping.getDefaultCascade(), hibernateMapping.getDefaultAccess(), hibernateMapping.isDefaultLazy() @@ -103,6 +105,10 @@ public class HibernateMappingProcessor implements HbmBindingContext { : HbmHelper.extractMetaAttributeContext( hibernateMapping.getMeta(), true, metadata.getMetaAttributeContext() ); } + XMLHibernateMapping getHibernateMapping() { + return hibernateMapping; + } + @Override public boolean isAutoImport() { return autoImport; @@ -153,12 +159,12 @@ public class HibernateMappingProcessor implements HbmBindingContext { return metadata.makeJavaType( className ); } - public void bindIndependentMetadata() { - bindDatabaseObjectDefinitions(); - bindTypeDefinitions(); + public void processIndependentMetadata() { + processDatabaseObjectDefinitions(); + processTypeDefinitions(); } - private void bindDatabaseObjectDefinitions() { + private void processDatabaseObjectDefinitions() { if ( hibernateMapping.getDatabaseObject() == null ) { return; } @@ -167,7 +173,7 @@ public class HibernateMappingProcessor implements HbmBindingContext { if ( databaseObjectElement.getDefinition() != null ) { final String className = databaseObjectElement.getDefinition().getClazz(); try { - auxiliaryDatabaseObject = (AuxiliaryDatabaseObject) classLoaderService().classForName( className ).newInstance(); + auxiliaryDatabaseObject = (AuxiliaryDatabaseObject) classLoaderService.getValue().classForName( className ).newInstance(); } catch (ClassLoadingException e) { throw e; @@ -196,7 +202,7 @@ public class HibernateMappingProcessor implements HbmBindingContext { } } - private void bindTypeDefinitions() { + private void processTypeDefinitions() { if ( hibernateMapping.getTypedef() == null ) { return; } @@ -209,12 +215,12 @@ public class HibernateMappingProcessor implements HbmBindingContext { } } - public void bindTypeDependentMetadata() { - bindFilterDefinitions(); - bindIdentifierGenerators(); + public void processTypeDependentMetadata() { + processFilterDefinitions(); + processIdentifierGenerators(); } - private void bindFilterDefinitions() { + private void processFilterDefinitions() { if(hibernateMapping.getFilterDef() == null){ return; } @@ -249,7 +255,7 @@ public class HibernateMappingProcessor implements HbmBindingContext { } } - private void bindIdentifierGenerators() { + private void processIdentifierGenerators() { if ( hibernateMapping.getIdentifierGenerator() == null ) { return; } @@ -262,10 +268,17 @@ public class HibernateMappingProcessor implements HbmBindingContext { } - public void bindMappingMetadata(List processedEntityNames) { + public void processMappingMetadata(List processedEntityNames) { if ( hibernateMapping.getClazzOrSubclassOrJoinedSubclass() == null ) { return; } + + for ( Object entityElementO : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) { + final EntityElement entityElement = (EntityElement) entityElementO; + + + } + for ( Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) { if ( XMLHibernateMapping.XMLClass.class.isInstance( clazzOrSubclass ) ) { XMLHibernateMapping.XMLClass clazz = @@ -293,21 +306,21 @@ public class HibernateMappingProcessor implements HbmBindingContext { } } - public void bindMappingDependentMetadata() { - bindFetchProfiles(); - bindImports(); - bindResultSetMappings(); - bindNamedQueries(); + public void processMappingDependentMetadata() { + processFetchProfiles(); + processImports(); + processResultSetMappings(); + processNamedQueries(); } - private void bindFetchProfiles(){ - if(hibernateMapping.getFetchProfile() == null){ + private void processFetchProfiles(){ + if ( hibernateMapping.getFetchProfile() == null ) { return; } - bindFetchProfiles( hibernateMapping.getFetchProfile(),null ); + processFetchProfiles( hibernateMapping.getFetchProfile(), null ); } - public void bindFetchProfiles(List fetchProfiles, String containingEntityName) { + public void processFetchProfiles(List fetchProfiles, String containingEntityName) { for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) { String profileName = fetchProfile.getName(); Set fetches = new HashSet(); @@ -326,7 +339,7 @@ public class HibernateMappingProcessor implements HbmBindingContext { } } - private void bindImports() { + private void processImports() { if ( hibernateMapping.getImport() == null ) { return; } @@ -338,14 +351,14 @@ public class HibernateMappingProcessor implements HbmBindingContext { } } - private void bindResultSetMappings() { + private void processResultSetMappings() { if ( hibernateMapping.getResultset() == null ) { return; } // bindResultSetMappingDefinitions( element, null, mappings ); } - private void bindNamedQueries() { + private void processNamedQueries() { if ( hibernateMapping.getQueryOrSqlQuery() == null ) { return; } @@ -365,14 +378,14 @@ public class HibernateMappingProcessor implements HbmBindingContext { } } - private ClassLoaderService classLoaderService; - - private ClassLoaderService classLoaderService() { - if ( classLoaderService == null ) { - classLoaderService = metadata.getServiceRegistry().getService( ClassLoaderService.class ); - } - return classLoaderService; - } + private Value classLoaderService = new Value( + new Value.DeferredInitializer() { + @Override + public ClassLoaderService initialize() { + return metadata.getServiceRegistry().getService( ClassLoaderService.class ); + } + } + ); @Override public String extractEntityName(XMLHibernateMapping.XMLClass entityClazz) { @@ -383,4 +396,9 @@ public class HibernateMappingProcessor implements HbmBindingContext { public String getClassName(String unqualifiedName) { return HbmHelper.getClassName( unqualifiedName, mappingDefaults.getPackageName() ); } + + @Override + public String determineEntityName(EntityElement entityElement) { + return HbmHelper.determineEntityName( entityElement, mappingDefaults.getPackageName() ); + } } \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/Discriminated.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/Discriminated.java new file mode 100644 index 0000000000..7f4a653007 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/Discriminated.java @@ -0,0 +1,31 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.source.hbm.xml.mapping; + +/** + * @author Steve Ebersole + */ +public interface Discriminated { + +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/EntityElement.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/EntityElement.java new file mode 100644 index 0000000000..d3bac5b6e4 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/EntityElement.java @@ -0,0 +1,58 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.source.hbm.xml.mapping; + +import java.util.List; + +/** + * @author Steve Ebersole + */ +public interface EntityElement extends MetaAttributeContainer { + public String getName(); + public String getEntityName(); + + public Boolean isAbstract(); + public Boolean isLazy(); + public String getProxy(); + public String getBatchSize(); + public boolean isDynamicInsert(); + public boolean isDynamicUpdate(); + public boolean isSelectBeforeUpdate(); + + public List getTuplizer(); + public String getPersister(); + + public XMLLoaderElement getLoader(); + public XMLSqlInsertElement getSqlInsert(); + public XMLSqlUpdateElement getSqlUpdate(); + public XMLSqlDeleteElement getSqlDelete(); + + public List getSynchronize(); + + public List getFetchProfile(); + + public List getResultset(); + + public List getQueryOrSqlQuery(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/MetaAttributeContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/MetaAttributeContainer.java new file mode 100644 index 0000000000..c1e195f013 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/MetaAttributeContainer.java @@ -0,0 +1,33 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.source.hbm.xml.mapping; + +import java.util.List; + +/** + * @author Steve Ebersole + */ +public interface MetaAttributeContainer { + public List getMeta(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/SubclassEntityElement.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/SubclassEntityElement.java new file mode 100644 index 0000000000..ea92ec3b97 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/xml/mapping/SubclassEntityElement.java @@ -0,0 +1,31 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.source.hbm.xml.mapping; + +/** + * @author Steve Ebersole + */ +public interface SubclassEntityElement extends EntityElement { + public String getExtends(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java index b441e78480..1ada28542c 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java @@ -565,7 +565,7 @@ public class EntityMetamodel implements Serializable { entityMode = hasPojoRepresentation ? EntityMode.POJO : EntityMode.MAP; final EntityTuplizerFactory entityTuplizerFactory = sessionFactory.getSettings().getEntityTuplizerFactory(); - Class tuplizerClass = entityBinding.getCustomEntityTuplizerClass(); + Class tuplizerClass = entityBinding.getCustomEntityTuplizerClass(); if ( tuplizerClass == null ) { entityTuplizer = entityTuplizerFactory.constructDefaultTuplizer( entityMode, this, entityBinding );