HHH-10365 added OsgiClassLoaderService support for non-container-managed JPA, tweaked method overloading
This commit is contained in:
parent
585a8aa757
commit
69bdf979cb
|
@ -16,8 +16,8 @@ import javax.persistence.spi.PersistenceProvider;
|
|||
import javax.persistence.spi.PersistenceUnitInfo;
|
||||
import javax.persistence.spi.ProviderUtil;
|
||||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
|
||||
import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor;
|
||||
import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
|
||||
import org.hibernate.jpa.boot.spi.Bootstrap;
|
||||
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
||||
|
@ -68,10 +68,21 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
|
|||
}
|
||||
|
||||
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties) {
|
||||
return getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties, null );
|
||||
return getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties, null, null );
|
||||
}
|
||||
|
||||
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties, ClassLoader providedClassLoader) {
|
||||
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties,
|
||||
ClassLoader providedClassLoader) {
|
||||
return getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties, providedClassLoader, null );
|
||||
}
|
||||
|
||||
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties,
|
||||
ClassLoaderService providedClassLoaderService) {
|
||||
return getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties, null, providedClassLoaderService );
|
||||
}
|
||||
|
||||
private EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties,
|
||||
ClassLoader providedClassLoader, ClassLoaderService providedClassLoaderService) {
|
||||
log.tracef( "Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s", persistenceUnitName );
|
||||
|
||||
final Map integration = wrap( properties );
|
||||
|
@ -111,8 +122,12 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (providedClassLoaderService != null) {
|
||||
return getEntityManagerFactoryBuilder( persistenceUnit, integration, providedClassLoaderService );
|
||||
} else {
|
||||
return getEntityManagerFactoryBuilder( persistenceUnit, integration, providedClassLoader );
|
||||
}
|
||||
}
|
||||
|
||||
log.debug( "Found no matching persistence units" );
|
||||
return null;
|
||||
|
@ -156,8 +171,8 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
|
|||
return true;
|
||||
}
|
||||
|
||||
private EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitInfo info, Map integration) {
|
||||
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( info ), integration, null );
|
||||
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitInfo info, Map integration) {
|
||||
return Bootstrap.getEntityManagerFactoryBuilder( info, integration );
|
||||
}
|
||||
|
||||
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor,
|
||||
|
@ -165,6 +180,11 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
|
|||
return Bootstrap.getEntityManagerFactoryBuilder( persistenceUnitDescriptor, integration, providedClassLoader );
|
||||
}
|
||||
|
||||
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor,
|
||||
Map integration, ClassLoaderService providedClassLoaderService) {
|
||||
return Bootstrap.getEntityManagerFactoryBuilder( persistenceUnitDescriptor, integration, providedClassLoaderService );
|
||||
}
|
||||
|
||||
private final ProviderUtil providerUtil = new ProviderUtil() {
|
||||
@Override
|
||||
public LoadState isLoadedWithoutReference(Object proxy, String property) {
|
||||
|
|
|
@ -159,7 +159,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
|||
}
|
||||
|
||||
public EntityManagerFactoryBuilderImpl(PersistenceUnitDescriptor persistenceUnit, Map integrationSettings) {
|
||||
this( persistenceUnit, integrationSettings, null );
|
||||
this( persistenceUnit, integrationSettings, null, null );
|
||||
}
|
||||
|
||||
public EntityManagerFactoryBuilderImpl(
|
||||
|
@ -170,6 +170,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
|||
}
|
||||
|
||||
public EntityManagerFactoryBuilderImpl(
|
||||
PersistenceUnitDescriptor persistenceUnit,
|
||||
Map integrationSettings,
|
||||
ClassLoaderService providedClassLoaderService ) {
|
||||
this( persistenceUnit, integrationSettings, null, providedClassLoaderService);
|
||||
}
|
||||
|
||||
private EntityManagerFactoryBuilderImpl(
|
||||
PersistenceUnitDescriptor persistenceUnit,
|
||||
Map integrationSettings,
|
||||
ClassLoader providedClassLoader,
|
||||
|
@ -324,9 +331,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
|||
ClassLoader providedClassLoader,
|
||||
ClassLoaderService providedClassLoaderService) {
|
||||
final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
|
||||
if (providedClassLoaderService != null) {
|
||||
bsrBuilder.applyClassLoaderService(providedClassLoaderService);
|
||||
}
|
||||
|
||||
bsrBuilder.applyIntegrator( new JpaIntegrator() );
|
||||
|
||||
final IntegratorProvider integratorProvider = (IntegratorProvider) integrationSettings.get( INTEGRATOR_PROVIDER );
|
||||
|
@ -346,7 +351,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
|||
|
||||
|
||||
// ClassLoaders ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// NOTE: See BootstrapServiceRegistryBuilder#build. providedClassLoaderService and providedClassLoaders are
|
||||
// mutually exclusive concepts, with priority given to the former
|
||||
|
||||
if ( providedClassLoaderService != null ) {
|
||||
bsrBuilder.applyClassLoaderService( providedClassLoaderService );
|
||||
} else {
|
||||
if ( persistenceUnit.getClassLoader() != null ) {
|
||||
bsrBuilder.applyClassLoader( persistenceUnit.getClassLoader() );
|
||||
}
|
||||
|
@ -379,6 +389,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
|||
bsrBuilder.applyClassLoader( (ClassLoader) classLoadersSetting );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bsrBuilder.build();
|
||||
}
|
||||
|
|
|
@ -39,9 +39,8 @@ public final class Bootstrap {
|
|||
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
|
||||
PersistenceUnitDescriptor persistenceUnitDescriptor,
|
||||
Map integration,
|
||||
ClassLoader providedClassLoader,
|
||||
ClassLoaderService providedClassLoaderService) {
|
||||
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoader, providedClassLoaderService );
|
||||
return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoaderService );
|
||||
}
|
||||
|
||||
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
|
||||
|
@ -60,8 +59,7 @@ public final class Bootstrap {
|
|||
public static EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(
|
||||
PersistenceUnitInfo persistenceUnitInfo,
|
||||
Map integration,
|
||||
ClassLoader providedClassLoader,
|
||||
ClassLoaderService providedClassLoaderService) {
|
||||
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, providedClassLoader, providedClassLoaderService );
|
||||
return getEntityManagerFactoryBuilder( new PersistenceUnitInfoDescriptor( persistenceUnitInfo ), integration, providedClassLoaderService );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider {
|
|||
* @param osgiClassLoader The ClassLoader we built from OSGi Bundles
|
||||
* @param osgiJtaPlatform The OSGi-specific JtaPlatform impl we built
|
||||
* @param requestingBundle The OSGi Bundle requesting the PersistenceProvider
|
||||
* @param context The OSGi context
|
||||
*/
|
||||
public OsgiPersistenceProvider(
|
||||
OsgiClassLoader osgiClassLoader,
|
||||
|
@ -75,7 +74,8 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider {
|
|||
|
||||
osgiClassLoader.addBundle( requestingBundle );
|
||||
|
||||
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, settings, osgiClassLoader );
|
||||
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, settings,
|
||||
new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) );
|
||||
return builder == null ? null : builder.build();
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,8 @@ public class OsgiPersistenceProvider extends HibernatePersistenceProvider {
|
|||
|
||||
osgiClassLoader.addClassLoader( info.getClassLoader() );
|
||||
|
||||
return Bootstrap.getEntityManagerFactoryBuilder( info, settings, osgiClassLoader, new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) ).build();
|
||||
return Bootstrap.getEntityManagerFactoryBuilder( info, settings,
|
||||
new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) ).build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue