HHH-6371 - Develop metamodel binding creation using a push approach
This commit is contained in:
parent
182150769a
commit
5efd0a8471
|
@ -12,6 +12,7 @@ allprojects {
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
mavenRepo name: 'jboss-nexus', urls: "https://repository.jboss.org/nexus/content/groups/public/"
|
mavenRepo name: 'jboss-nexus', urls: "https://repository.jboss.org/nexus/content/groups/public/"
|
||||||
mavenRepo name: "jboss-snapshots", urls: "http://snapshots.jboss.org/maven2/"
|
mavenRepo name: "jboss-snapshots", urls: "http://snapshots.jboss.org/maven2/"
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.hibernate.metamodel.source.Origin;
|
||||||
import org.hibernate.metamodel.source.hbm.HbmBindingContext;
|
import org.hibernate.metamodel.source.hbm.HbmBindingContext;
|
||||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
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.XMLCacheElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement;
|
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;
|
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 Gail Badner
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -102,7 +105,7 @@ public class EntityViewImpl implements EntityView {
|
||||||
|
|
||||||
public EntityViewImpl(
|
public EntityViewImpl(
|
||||||
Hierarchical superType,
|
Hierarchical superType,
|
||||||
XMLHibernateMapping.XMLClass entityClazz,
|
EntityElement entityClazz,
|
||||||
boolean isRoot,
|
boolean isRoot,
|
||||||
InheritanceType inheritanceType,
|
InheritanceType inheritanceType,
|
||||||
HbmBindingContext bindingContext) {
|
HbmBindingContext bindingContext) {
|
||||||
|
@ -110,7 +113,7 @@ public class EntityViewImpl implements EntityView {
|
||||||
this.bindingContext = bindingContext;
|
this.bindingContext = bindingContext;
|
||||||
|
|
||||||
this.superType = superType;
|
this.superType = superType;
|
||||||
this.entityName = bindingContext.extractEntityName( entityClazz );
|
this.entityName = bindingContext.determineEntityName( entityClazz );
|
||||||
|
|
||||||
final String verbatimClassName = entityClazz.getName();
|
final String verbatimClassName = entityClazz.getName();
|
||||||
this.entityMode = verbatimClassName == null ? EntityMode.MAP : EntityMode.POJO;
|
this.entityMode = verbatimClassName == null ? EntityMode.MAP : EntityMode.POJO;
|
||||||
|
@ -135,7 +138,7 @@ public class EntityViewImpl implements EntityView {
|
||||||
this.isRoot = isRoot;
|
this.isRoot = isRoot;
|
||||||
this.entityInheritanceType = inheritanceType;
|
this.entityInheritanceType = inheritanceType;
|
||||||
|
|
||||||
this.caching = createCaching( entityClazz, bindingContext.extractEntityName( entityClazz ) );
|
this.caching = isRoot ? createCaching( entityClazz, this.entityName ) : null;
|
||||||
|
|
||||||
this.metaAttributeContext = HbmHelper.extractMetaAttributeContext(
|
this.metaAttributeContext = HbmHelper.extractMetaAttributeContext(
|
||||||
entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext()
|
entityClazz.getMeta(), true, bindingContext.getMetaAttributeContext()
|
||||||
|
@ -215,11 +218,11 @@ public class EntityViewImpl implements EntityView {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String extractCustomTuplizerClassName(XMLHibernateMapping.XMLClass entityClazz, EntityMode entityMode) {
|
private String extractCustomTuplizerClassName(EntityElement entityMapping, EntityMode entityMode) {
|
||||||
if ( entityClazz.getTuplizer() == null ) {
|
if ( entityMapping.getTuplizer() == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for ( XMLTuplizerElement tuplizerElement : entityClazz.getTuplizer() ) {
|
for ( XMLTuplizerElement tuplizerElement : entityMapping.getTuplizer() ) {
|
||||||
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) {
|
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) {
|
||||||
return tuplizerElement.getClazz();
|
return tuplizerElement.getClazz();
|
||||||
}
|
}
|
||||||
|
@ -227,8 +230,13 @@ public class EntityViewImpl implements EntityView {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Caching createCaching(XMLHibernateMapping.XMLClass entityClazz, String entityName) {
|
private static Caching createCaching(EntityElement entityMapping, String entityName) {
|
||||||
XMLCacheElement cache = entityClazz.getCache();
|
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 ) {
|
if ( cache == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ abstract class AbstractEntityBinder {
|
||||||
final String entityName = entityBinding.getEntity().getName();
|
final String entityName = entityBinding.getEntity().getName();
|
||||||
|
|
||||||
if ( entityClazz.getFetchProfile() != null ) {
|
if ( entityClazz.getFetchProfile() != null ) {
|
||||||
bindingContext.bindFetchProfiles( entityClazz.getFetchProfile(), entityName );
|
bindingContext.processFetchProfiles( entityClazz.getFetchProfile(), entityName );
|
||||||
}
|
}
|
||||||
|
|
||||||
getMetadata().addImport( entityName, entityName );
|
getMetadata().addImport( entityName, entityName );
|
||||||
|
|
|
@ -26,12 +26,13 @@ package org.hibernate.metamodel.source.hbm;
|
||||||
import org.hibernate.metamodel.binder.EntityBinder;
|
import org.hibernate.metamodel.binder.EntityBinder;
|
||||||
import org.hibernate.metamodel.binder.view.hbm.EntityViewImpl;
|
import org.hibernate.metamodel.binder.view.hbm.EntityViewImpl;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
|
import org.hibernate.metamodel.source.hbm.xml.mapping.EntityElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class EntityProcessor {
|
public abstract class EntityProcessor {
|
||||||
private final HbmBindingContext bindingContext;
|
private final HbmBindingContext bindingContext;
|
||||||
private final EntityBinder entityBinder;
|
private final EntityBinder entityBinder;
|
||||||
|
|
||||||
|
@ -40,17 +41,17 @@ public class EntityProcessor {
|
||||||
this.entityBinder = new EntityBinder( bindingContext.getMetadataImplementor() );
|
this.entityBinder = new EntityBinder( bindingContext.getMetadataImplementor() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(XMLHibernateMapping.XMLClass xmlClass) {
|
public void process(EntityElement entityMapping) {
|
||||||
EntityBinding entityBinding = entityBinder.createEntityBinding(
|
EntityBinding entityBinding = entityBinder.createEntityBinding(
|
||||||
new EntityViewImpl(
|
new EntityViewImpl(
|
||||||
null, // superType
|
null, // superType
|
||||||
xmlClass,
|
entityMapping,
|
||||||
true, // isRoot
|
true, // isRoot
|
||||||
null, // inheritanceType
|
null, // inheritanceType
|
||||||
bindingContext
|
bindingContext
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
bindingContext.
|
bindingContext.getMetadataImplementor().addEntity( entityBinding );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ package org.hibernate.metamodel.source.hbm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.internal.util.xml.XmlDocument;
|
|
||||||
import org.hibernate.metamodel.source.Origin;
|
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.XMLFetchProfileElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
import org.hibernate.metamodel.source.spi.BindingContext;
|
import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
|
@ -37,11 +37,12 @@ import org.hibernate.metamodel.source.spi.BindingContext;
|
||||||
public interface HbmBindingContext extends BindingContext {
|
public interface HbmBindingContext extends BindingContext {
|
||||||
public boolean isAutoImport();
|
public boolean isAutoImport();
|
||||||
|
|
||||||
|
public Origin getOrigin();
|
||||||
|
|
||||||
public String extractEntityName(XMLHibernateMapping.XMLClass entityClazz);
|
public String extractEntityName(XMLHibernateMapping.XMLClass entityClazz);
|
||||||
|
public String determineEntityName(EntityElement entityElement);
|
||||||
|
|
||||||
public String getClassName(String unqualifiedName);
|
public String getClassName(String unqualifiedName);
|
||||||
|
|
||||||
public void bindFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName);
|
public void processFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName);
|
||||||
|
|
||||||
public Origin getOrigin();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
|
||||||
import org.hibernate.metamodel.binding.CustomSQL;
|
import org.hibernate.metamodel.binding.CustomSQL;
|
||||||
import org.hibernate.metamodel.binding.MetaAttribute;
|
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.XMLHibernateMapping.XMLClass;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement;
|
||||||
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
import org.hibernate.metamodel.source.hbm.util.MappingHelper;
|
||||||
|
@ -102,6 +103,14 @@ public class HbmHelper {
|
||||||
return entityName == null ? getClassName( entityClassName, unqualifiedPackageName ) : entityName;
|
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) {
|
public static String getClassName(Attribute att, String unqualifiedPackageName) {
|
||||||
if ( att == null ) {
|
if ( att == null ) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -24,13 +24,20 @@
|
||||||
package org.hibernate.metamodel.source.hbm;
|
package org.hibernate.metamodel.source.hbm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
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.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
import org.hibernate.metamodel.source.internal.JaxbRoot;
|
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.MetadataImplementor;
|
||||||
|
import org.hibernate.metamodel.source.spi.SourceProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responsible for performing binding of hbm xml.
|
* Responsible for performing binding of hbm xml.
|
||||||
|
@ -57,28 +64,118 @@ public class HbmSourceProcessor implements SourceProcessor {
|
||||||
@Override
|
@Override
|
||||||
public void processIndependentMetadata(MetadataSources sources) {
|
public void processIndependentMetadata(MetadataSources sources) {
|
||||||
for ( HibernateMappingProcessor processor : processors ) {
|
for ( HibernateMappingProcessor processor : processors ) {
|
||||||
processor.bindIndependentMetadata();
|
processor.processIndependentMetadata();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processTypeDependentMetadata(MetadataSources sources) {
|
public void processTypeDependentMetadata(MetadataSources sources) {
|
||||||
for ( HibernateMappingProcessor processor : processors ) {
|
for ( HibernateMappingProcessor processor : processors ) {
|
||||||
processor.bindTypeDependentMetadata();
|
processor.processTypeDependentMetadata();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processMappingMetadata(MetadataSources sources, List<String> processedEntityNames) {
|
public void processMappingMetadata(MetadataSources sources, List<String> 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<String> availableEntityNames = new HashSet<String>();
|
||||||
|
availableEntityNames.addAll( processedEntityNames );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
final LinkedHashSet<HibernateMappingProcessor> orderedProcessors = new LinkedHashSet<HibernateMappingProcessor>();
|
||||||
|
final Set<ExtendsQueueEntry> extendsQueue = new HashSet<ExtendsQueueEntry>();
|
||||||
|
|
||||||
for ( HibernateMappingProcessor processor : processors ) {
|
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<ExtendsQueueEntry> 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<String> includedEntityNames = new HashSet<String>();
|
||||||
|
|
||||||
|
private HibernateMappingInformation(HibernateMappingProcessor processor) {
|
||||||
|
this.processor = processor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ExtendsQueueEntry {
|
||||||
|
private HibernateMappingInformation hibernateMappingInformation;
|
||||||
|
private final Set<String> waitingOnEntityNames = new HashSet<String>();
|
||||||
|
|
||||||
|
private ExtendsQueueEntry(HibernateMappingInformation hibernateMappingInformation) {
|
||||||
|
this.hibernateMappingInformation = hibernateMappingInformation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processMappingDependentMetadata(MetadataSources sources) {
|
public void processMappingDependentMetadata(MetadataSources sources) {
|
||||||
for ( HibernateMappingProcessor processor : processors ) {
|
for ( HibernateMappingProcessor processor : processors ) {
|
||||||
processor.bindMappingDependentMetadata();
|
processor.processMappingDependentMetadata();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.Set;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.engine.spi.FilterDefinition;
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
import org.hibernate.internal.util.Value;
|
||||||
import org.hibernate.metamodel.binding.FetchProfile;
|
import org.hibernate.metamodel.binding.FetchProfile;
|
||||||
import org.hibernate.metamodel.binding.TypeDef;
|
import org.hibernate.metamodel.binding.TypeDef;
|
||||||
import org.hibernate.metamodel.domain.JavaType;
|
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.relational.BasicAuxiliaryDatabaseObjectImpl;
|
||||||
import org.hibernate.metamodel.source.MappingException;
|
import org.hibernate.metamodel.source.MappingException;
|
||||||
import org.hibernate.metamodel.source.Origin;
|
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.XMLFetchProfileElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLJoinedSubclassElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLJoinedSubclassElement;
|
||||||
|
@ -85,8 +87,8 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
hibernateMapping.getPackage(),
|
hibernateMapping.getPackage(),
|
||||||
hibernateMapping.getSchema(),
|
hibernateMapping.getSchema(),
|
||||||
hibernateMapping.getCatalog(),
|
hibernateMapping.getCatalog(),
|
||||||
null,
|
null, // idColumnName
|
||||||
null,
|
null, // discriminatorColumnName
|
||||||
hibernateMapping.getDefaultCascade(),
|
hibernateMapping.getDefaultCascade(),
|
||||||
hibernateMapping.getDefaultAccess(),
|
hibernateMapping.getDefaultAccess(),
|
||||||
hibernateMapping.isDefaultLazy()
|
hibernateMapping.isDefaultLazy()
|
||||||
|
@ -103,6 +105,10 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
: HbmHelper.extractMetaAttributeContext( hibernateMapping.getMeta(), true, metadata.getMetaAttributeContext() );
|
: HbmHelper.extractMetaAttributeContext( hibernateMapping.getMeta(), true, metadata.getMetaAttributeContext() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XMLHibernateMapping getHibernateMapping() {
|
||||||
|
return hibernateMapping;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAutoImport() {
|
public boolean isAutoImport() {
|
||||||
return autoImport;
|
return autoImport;
|
||||||
|
@ -153,12 +159,12 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
return metadata.makeJavaType( className );
|
return metadata.makeJavaType( className );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindIndependentMetadata() {
|
public void processIndependentMetadata() {
|
||||||
bindDatabaseObjectDefinitions();
|
processDatabaseObjectDefinitions();
|
||||||
bindTypeDefinitions();
|
processTypeDefinitions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindDatabaseObjectDefinitions() {
|
private void processDatabaseObjectDefinitions() {
|
||||||
if ( hibernateMapping.getDatabaseObject() == null ) {
|
if ( hibernateMapping.getDatabaseObject() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +173,7 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
if ( databaseObjectElement.getDefinition() != null ) {
|
if ( databaseObjectElement.getDefinition() != null ) {
|
||||||
final String className = databaseObjectElement.getDefinition().getClazz();
|
final String className = databaseObjectElement.getDefinition().getClazz();
|
||||||
try {
|
try {
|
||||||
auxiliaryDatabaseObject = (AuxiliaryDatabaseObject) classLoaderService().classForName( className ).newInstance();
|
auxiliaryDatabaseObject = (AuxiliaryDatabaseObject) classLoaderService.getValue().classForName( className ).newInstance();
|
||||||
}
|
}
|
||||||
catch (ClassLoadingException e) {
|
catch (ClassLoadingException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -196,7 +202,7 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindTypeDefinitions() {
|
private void processTypeDefinitions() {
|
||||||
if ( hibernateMapping.getTypedef() == null ) {
|
if ( hibernateMapping.getTypedef() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -209,12 +215,12 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindTypeDependentMetadata() {
|
public void processTypeDependentMetadata() {
|
||||||
bindFilterDefinitions();
|
processFilterDefinitions();
|
||||||
bindIdentifierGenerators();
|
processIdentifierGenerators();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindFilterDefinitions() {
|
private void processFilterDefinitions() {
|
||||||
if(hibernateMapping.getFilterDef() == null){
|
if(hibernateMapping.getFilterDef() == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -249,7 +255,7 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindIdentifierGenerators() {
|
private void processIdentifierGenerators() {
|
||||||
if ( hibernateMapping.getIdentifierGenerator() == null ) {
|
if ( hibernateMapping.getIdentifierGenerator() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -262,10 +268,17 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void bindMappingMetadata(List<String> processedEntityNames) {
|
public void processMappingMetadata(List<String> processedEntityNames) {
|
||||||
if ( hibernateMapping.getClazzOrSubclassOrJoinedSubclass() == null ) {
|
if ( hibernateMapping.getClazzOrSubclassOrJoinedSubclass() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ( Object entityElementO : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) {
|
||||||
|
final EntityElement entityElement = (EntityElement) entityElementO;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
for ( Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) {
|
for ( Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) {
|
||||||
if ( XMLHibernateMapping.XMLClass.class.isInstance( clazzOrSubclass ) ) {
|
if ( XMLHibernateMapping.XMLClass.class.isInstance( clazzOrSubclass ) ) {
|
||||||
XMLHibernateMapping.XMLClass clazz =
|
XMLHibernateMapping.XMLClass clazz =
|
||||||
|
@ -293,21 +306,21 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindMappingDependentMetadata() {
|
public void processMappingDependentMetadata() {
|
||||||
bindFetchProfiles();
|
processFetchProfiles();
|
||||||
bindImports();
|
processImports();
|
||||||
bindResultSetMappings();
|
processResultSetMappings();
|
||||||
bindNamedQueries();
|
processNamedQueries();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindFetchProfiles(){
|
private void processFetchProfiles(){
|
||||||
if(hibernateMapping.getFetchProfile() == null){
|
if ( hibernateMapping.getFetchProfile() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bindFetchProfiles( hibernateMapping.getFetchProfile(),null );
|
processFetchProfiles( hibernateMapping.getFetchProfile(), null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
|
public void processFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
|
||||||
for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) {
|
for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) {
|
||||||
String profileName = fetchProfile.getName();
|
String profileName = fetchProfile.getName();
|
||||||
Set<FetchProfile.Fetch> fetches = new HashSet<FetchProfile.Fetch>();
|
Set<FetchProfile.Fetch> fetches = new HashSet<FetchProfile.Fetch>();
|
||||||
|
@ -326,7 +339,7 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindImports() {
|
private void processImports() {
|
||||||
if ( hibernateMapping.getImport() == null ) {
|
if ( hibernateMapping.getImport() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -338,14 +351,14 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindResultSetMappings() {
|
private void processResultSetMappings() {
|
||||||
if ( hibernateMapping.getResultset() == null ) {
|
if ( hibernateMapping.getResultset() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// bindResultSetMappingDefinitions( element, null, mappings );
|
// bindResultSetMappingDefinitions( element, null, mappings );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindNamedQueries() {
|
private void processNamedQueries() {
|
||||||
if ( hibernateMapping.getQueryOrSqlQuery() == null ) {
|
if ( hibernateMapping.getQueryOrSqlQuery() == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -365,14 +378,14 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassLoaderService classLoaderService;
|
private Value<ClassLoaderService> classLoaderService = new Value<ClassLoaderService>(
|
||||||
|
new Value.DeferredInitializer<ClassLoaderService>() {
|
||||||
private ClassLoaderService classLoaderService() {
|
@Override
|
||||||
if ( classLoaderService == null ) {
|
public ClassLoaderService initialize() {
|
||||||
classLoaderService = metadata.getServiceRegistry().getService( ClassLoaderService.class );
|
return metadata.getServiceRegistry().getService( ClassLoaderService.class );
|
||||||
}
|
}
|
||||||
return classLoaderService;
|
}
|
||||||
}
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String extractEntityName(XMLHibernateMapping.XMLClass entityClazz) {
|
public String extractEntityName(XMLHibernateMapping.XMLClass entityClazz) {
|
||||||
|
@ -383,4 +396,9 @@ public class HibernateMappingProcessor implements HbmBindingContext {
|
||||||
public String getClassName(String unqualifiedName) {
|
public String getClassName(String unqualifiedName) {
|
||||||
return HbmHelper.getClassName( unqualifiedName, mappingDefaults.getPackageName() );
|
return HbmHelper.getClassName( unqualifiedName, mappingDefaults.getPackageName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String determineEntityName(EntityElement entityElement) {
|
||||||
|
return HbmHelper.determineEntityName( entityElement, mappingDefaults.getPackageName() );
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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 {
|
||||||
|
|
||||||
|
}
|
|
@ -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<XMLTuplizerElement> getTuplizer();
|
||||||
|
public String getPersister();
|
||||||
|
|
||||||
|
public XMLLoaderElement getLoader();
|
||||||
|
public XMLSqlInsertElement getSqlInsert();
|
||||||
|
public XMLSqlUpdateElement getSqlUpdate();
|
||||||
|
public XMLSqlDeleteElement getSqlDelete();
|
||||||
|
|
||||||
|
public List<XMLSynchronizeElement> getSynchronize();
|
||||||
|
|
||||||
|
public List<XMLFetchProfileElement> getFetchProfile();
|
||||||
|
|
||||||
|
public List<XMLResultsetElement> getResultset();
|
||||||
|
|
||||||
|
public List<Object> getQueryOrSqlQuery();
|
||||||
|
}
|
|
@ -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<XMLMetaElement> getMeta();
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -565,7 +565,7 @@ public class EntityMetamodel implements Serializable {
|
||||||
|
|
||||||
entityMode = hasPojoRepresentation ? EntityMode.POJO : EntityMode.MAP;
|
entityMode = hasPojoRepresentation ? EntityMode.POJO : EntityMode.MAP;
|
||||||
final EntityTuplizerFactory entityTuplizerFactory = sessionFactory.getSettings().getEntityTuplizerFactory();
|
final EntityTuplizerFactory entityTuplizerFactory = sessionFactory.getSettings().getEntityTuplizerFactory();
|
||||||
Class<EntityTuplizer> tuplizerClass = entityBinding.getCustomEntityTuplizerClass();
|
Class<? extends EntityTuplizer> tuplizerClass = entityBinding.getCustomEntityTuplizerClass();
|
||||||
|
|
||||||
if ( tuplizerClass == null ) {
|
if ( tuplizerClass == null ) {
|
||||||
entityTuplizer = entityTuplizerFactory.constructDefaultTuplizer( entityMode, this, entityBinding );
|
entityTuplizer = entityTuplizerFactory.constructDefaultTuplizer( entityMode, this, entityBinding );
|
||||||
|
|
Loading…
Reference in New Issue