HHH-8372 multiple CL issues, updated Felix properties

This commit is contained in:
Brett Meyer 2013-07-23 15:43:48 -04:00
parent 076d064e3f
commit 48a61d9155
4 changed files with 104 additions and 106 deletions

View File

@ -54,6 +54,7 @@ import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.internal.util.ClassLoaderHelper;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
/** /**
@ -501,7 +502,7 @@ public class JandexHelper {
return val; return val;
} }
try { try {
val = Index.class.getClassLoader().loadClass( name ).getMethod( element ).getDefaultValue(); val = ClassLoaderHelper.getContextClassLoader().loadClass( name ).getMethod( element ).getDefaultValue();
if ( val != null ) { if ( val != null ) {
// Annotation parameters of type Class are handled using Strings // Annotation parameters of type Class are handled using Strings
if ( val instanceof Class ) { if ( val instanceof Class ) {

View File

@ -940,111 +940,110 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
final StandardServiceRegistry serviceRegistry = buildServiceRegistry(); final StandardServiceRegistry serviceRegistry = buildServiceRegistry();
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
// IMPL NOTE : TCCL handling here is temporary. // IMPL NOTE : TCCL handling here is needed because of commons-annotations, Jandex, etc. relying on TCCL being set.
// It is needed because this code still uses Hibernate Configuration and Hibernate commons-annotations return ( (ClassLoaderServiceImpl) classLoaderService ).withTccl(
// in turn which relies on TCCL being set. new ClassLoaderServiceImpl.Work<EntityManagerFactoryImpl>() {
if ( usingNewMetadata ) { @Override
final JaccService jaccService = serviceRegistry.getService( JaccService.class ); public EntityManagerFactoryImpl perform() {
for ( GrantedPermission grantedPermission : grantedJaccPermissions ) {
jaccService.addPermission( grantedPermission );
}
final Object strategyProviderValue = configurationValues.get( AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER ); if ( usingNewMetadata ) {
final IdentifierGeneratorStrategyProvider strategyProvider = strategyProviderValue == null final JaccService jaccService = serviceRegistry.getService( JaccService.class );
? null for ( GrantedPermission grantedPermission : grantedJaccPermissions ) {
: serviceRegistry.getService( StrategySelector.class ) jaccService.addPermission( grantedPermission );
.resolveStrategy( IdentifierGeneratorStrategyProvider.class, strategyProviderValue ); }
if ( strategyProvider != null ) { final Object strategyProviderValue = configurationValues.get( AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER );
for ( Map.Entry<String,Class<?>> entry : strategyProvider.getStrategies().entrySet() ) { final IdentifierGeneratorStrategyProvider strategyProvider = strategyProviderValue == null
serviceRegistry.getService( MutableIdentifierGeneratorFactory.class ).register( entry.getKey(), entry.getValue() ); ? null
} : serviceRegistry.getService( StrategySelector.class )
} .resolveStrategy( IdentifierGeneratorStrategyProvider.class, strategyProviderValue );
metadataSources.addCacheRegionDefinitions( cacheRegionDefinitions ); if ( strategyProvider != null ) {
for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping jaxbMapping : cfgXmlNamedMappings ) { for ( Map.Entry<String,Class<?>> entry : strategyProvider.getStrategies().entrySet() ) {
if ( jaxbMapping.getResource() != null ) { serviceRegistry.getService( MutableIdentifierGeneratorFactory.class ).register( entry.getKey(), entry.getValue() );
metadataSources.addResource( jaxbMapping.getResource() );
}
else if ( jaxbMapping.getJar() != null ) {
metadataSources.addJar( new File( jaxbMapping.getJar() ) );
}
}
MetadataBuilder builder = metadataSources.getMetadataBuilder( serviceRegistry );
builder.with( jandexIndex );
if ( namingStrategy != null ) {
builder.with( namingStrategy );
}
MetadataImplementor metadata = (MetadataImplementor)builder.build();
SessionFactoryBuilder sfBuilder = metadata.getSessionFactoryBuilder();
sfBuilder.with( jpaEntityNotFoundDelegate );
if ( sessionFactoryInterceptor != null ) {
sfBuilder.with( sessionFactoryInterceptor );
}
if ( suppliedSessionFactoryObserver != null ) {
sfBuilder.add( suppliedSessionFactoryObserver );
}
sfBuilder.add( new ServiceRegistryCloser() );
SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) sfBuilder.build();
}
catch ( MappingException e ) {
throw persistenceException( "Unable to build Hibernate SessionFactory", e );
}
return new EntityManagerFactoryImpl(
persistenceUnit.getName(),
sessionFactory,
settings,
configurationValues,
serviceRegistry.getService( ConfigurationService.class ).getSettings(),
metadata
);
}
else {
return ( (ClassLoaderServiceImpl) classLoaderService ).withTccl(
new ClassLoaderServiceImpl.Work<EntityManagerFactoryImpl>() {
@Override
public EntityManagerFactoryImpl perform() {
hibernateConfiguration = buildHibernateConfiguration( serviceRegistry );
JpaSchemaGenerator.performGeneration( hibernateConfiguration, serviceRegistry );
SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) hibernateConfiguration.buildSessionFactory(
serviceRegistry
);
}
catch ( MappingException e ) {
throw persistenceException( "Unable to build Hibernate SessionFactory", e );
} }
}
if ( suppliedSessionFactoryObserver != null ) { metadataSources.addCacheRegionDefinitions( cacheRegionDefinitions );
sessionFactory.addObserver( suppliedSessionFactoryObserver ); for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping jaxbMapping : cfgXmlNamedMappings ) {
if ( jaxbMapping.getResource() != null ) {
metadataSources.addResource( jaxbMapping.getResource() );
} }
sessionFactory.addObserver( new ServiceRegistryCloser() ); else if ( jaxbMapping.getJar() != null ) {
metadataSources.addJar( new File( jaxbMapping.getJar() ) );
}
}
// NOTE : passing cfg is temporary until
return new EntityManagerFactoryImpl(
persistenceUnit.getName(), MetadataBuilder builder = metadataSources.getMetadataBuilder( serviceRegistry );
sessionFactory, builder.with( jandexIndex );
settings, if ( namingStrategy != null ) {
configurationValues, builder.with( namingStrategy );
hibernateConfiguration }
MetadataImplementor metadata = (MetadataImplementor)builder.build();
SessionFactoryBuilder sfBuilder = metadata.getSessionFactoryBuilder();
sfBuilder.with( jpaEntityNotFoundDelegate );
if ( sessionFactoryInterceptor != null ) {
sfBuilder.with( sessionFactoryInterceptor );
}
if ( suppliedSessionFactoryObserver != null ) {
sfBuilder.add( suppliedSessionFactoryObserver );
}
sfBuilder.add( new ServiceRegistryCloser() );
SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) sfBuilder.build();
}
catch ( MappingException e ) {
throw persistenceException( "Unable to build Hibernate SessionFactory", e );
}
return new EntityManagerFactoryImpl(
persistenceUnit.getName(),
sessionFactory,
settings,
configurationValues,
serviceRegistry.getService( ConfigurationService.class ).getSettings(),
metadata
);
}
else {
hibernateConfiguration = buildHibernateConfiguration( serviceRegistry );
JpaSchemaGenerator.performGeneration( hibernateConfiguration, serviceRegistry );
SessionFactoryImplementor sessionFactory;
try {
sessionFactory = (SessionFactoryImplementor) hibernateConfiguration.buildSessionFactory(
serviceRegistry
); );
} }
catch ( MappingException e ) {
throw persistenceException( "Unable to build Hibernate SessionFactory", e );
}
if ( suppliedSessionFactoryObserver != null ) {
sessionFactory.addObserver( suppliedSessionFactoryObserver );
}
sessionFactory.addObserver( new ServiceRegistryCloser() );
// NOTE : passing cfg is temporary until
return new EntityManagerFactoryImpl(
persistenceUnit.getName(),
sessionFactory,
settings,
configurationValues,
hibernateConfiguration
);
} }
); }
} }
);
} }
private void processProperties() { private void processProperties() {

View File

@ -122,5 +122,3 @@ runBnd.dependsOn copyBnd
test.dependsOn runBnd test.dependsOn runBnd
test.dependsOn testClientBundleJar test.dependsOn testClientBundleJar
test.dependsOn jar test.dependsOn jar
test.enabled = false

File diff suppressed because one or more lines are too long