HHH-6273 - Bind identifier-generator definitions (was committed by Steve)

This commit is contained in:
Strong Liu 2011-06-01 16:31:01 +08:00
parent 32a320d078
commit 7a18764893
3 changed files with 56 additions and 25 deletions

View File

@ -154,21 +154,10 @@ public class HbmBinder implements MappingDefaults {
}
public void processHibernateMapping() {
if ( hibernateMapping.getImport() != null ) {
bindImports( hibernateMapping.getImport() );
}
if ( hibernateMapping.getTypedef() != null ) {
bindTypeDefinitions( hibernateMapping.getTypedef() );
}
if ( hibernateMapping.getFilterDef() != null ) {
bindFilterDefinitions( hibernateMapping.getFilterDef() );
}
if ( hibernateMapping.getFetchProfile() != null ) {
bindFetchProfiles( hibernateMapping.getFetchProfile(), null );
}
if ( hibernateMapping.getIdentifierGenerator() != null ) {
// parseIdentifierGeneratorRegistrations( hibernateMapping.getIdentifierGenerator() );
}
bindTypeDefinitions( );
bindFilterDefinitions( );
bindFetchProfiles( );
bindIdentifierGenerators();
if ( hibernateMapping.getClazzOrSubclassOrJoinedSubclass() != null ) {
for ( Object clazzOrSubclass : hibernateMapping.getClazzOrSubclassOrJoinedSubclass() ) {
if ( XMLClass.class.isInstance( clazzOrSubclass ) ) {
@ -218,10 +207,26 @@ public class HbmBinder implements MappingDefaults {
if ( hibernateMapping.getDatabaseObject() != null ) {
// bindAuxiliaryDatabaseObjects( element, mappings );
}
bindImports( );
}
private void bindImports(List<XMLImport> imports) {
for ( XMLImport importValue : imports ) {
private void bindIdentifierGenerators() {
if ( hibernateMapping.getIdentifierGenerator() == null ) {
return;
}
for ( XMLHibernateMapping.XMLIdentifierGenerator identifierGeneratorElement : hibernateMapping.getIdentifierGenerator() ) {
metadata.registerIdentifierGenerator(
identifierGeneratorElement.getName(),
identifierGeneratorElement.getClazz()
);
}
}
private void bindImports() {
if ( hibernateMapping.getImport() == null ) {
return;
}
for ( XMLImport importValue : hibernateMapping.getImport() ) {
String className = getClassName( importValue.getClazz() );
String rename = importValue.getRename();
rename = ( rename == null ) ? StringHelper.unqualify( className ) : rename;
@ -229,8 +234,11 @@ public class HbmBinder implements MappingDefaults {
}
}
private void bindTypeDefinitions(List<XMLHibernateMapping.XMLTypedef> typedefs) {
for ( XMLHibernateMapping.XMLTypedef typedef : typedefs ) {
private void bindTypeDefinitions() {
if ( hibernateMapping.getTypedef() == null ) {
return;
}
for ( XMLHibernateMapping.XMLTypedef typedef : hibernateMapping.getTypedef() ) {
final Map<String, String> parameters = new HashMap<String, String>();
for ( XMLParamElement paramElement : typedef.getParam() ) {
parameters.put( paramElement.getName(), paramElement.getValue() );
@ -238,6 +246,12 @@ public class HbmBinder implements MappingDefaults {
metadata.addTypeDef( new TypeDef( typedef.getName(), typedef.getClazz(), parameters ) );
}
}
private void bindFetchProfiles(){
if(hibernateMapping.getFetchProfile() == null){
return;
}
bindFetchProfiles( hibernateMapping.getFetchProfile(),null );
}
protected void bindFetchProfiles(List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
for ( XMLFetchProfileElement fetchProfile : fetchProfiles ) {
@ -258,8 +272,11 @@ public class HbmBinder implements MappingDefaults {
}
}
private void bindFilterDefinitions(List<XMLHibernateMapping.XMLFilterDef> filterDefinitions) {
for ( XMLHibernateMapping.XMLFilterDef filterDefinition : filterDefinitions ) {
private void bindFilterDefinitions() {
if(hibernateMapping.getFilterDef() == null){
return;
}
for ( XMLHibernateMapping.XMLFilterDef filterDefinition : hibernateMapping.getFilterDef() ) {
final String name = filterDefinition.getName();
final Map<String,Type> parameters = new HashMap<String, Type>();
String condition = null;

View File

@ -42,6 +42,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.NamedQueryDefinition;
import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.id.factory.DefaultIdentifierGeneratorFactory;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.SourceProcessingOrder;
@ -77,10 +78,10 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
private final BasicServiceRegistry serviceRegistry;
private final Options options;
private ClassLoaderService classLoaderService;
private final Database database = new Database();
private TypeResolver typeResolver = new TypeResolver();
private DefaultIdentifierGeneratorFactory identifierGeneratorFactory = new DefaultIdentifierGeneratorFactory();
/**
* Maps the fully qualified class name of an entity to its entity binding
*/
@ -135,6 +136,10 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
return idGenerators.get( name );
}
@Override
public void registerIdentifierGenerator(String name, String generatorClassName) {
identifierGeneratorFactory.register( name, classLoaderService().classForName( generatorClassName ) );
}
public void addNamedNativeQuery(String name, NamedSQLQueryDefinition def) {
namedNativeQueryDefs.put( name, def );
@ -225,8 +230,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
* @param className the fully qualified name of the class
*/
private void indexClass(Indexer indexer, String className) {
ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
InputStream stream = classLoaderService.locateResourceStream( className );
InputStream stream = classLoaderService().locateResourceStream( className );
try {
indexer.index( stream );
}
@ -235,6 +239,13 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
}
private ClassLoaderService classLoaderService(){
if(classLoaderService==null){
classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
}
return classLoaderService;
}
@Override
public Options getOptions() {
return options;

View File

@ -63,5 +63,8 @@ public interface MetadataImplementor extends Metadata {
public void addFilterDefinition(FilterDefinition filterDefinition);
public Iterable<FilterDefinition> getFilterDefinitions();
public void registerIdentifierGenerator(String name, String clazz);
public IdGenerator getIdGenerator(String name);
}