HHH-13849 Convert ProxyFactoryFactory into a Service, scope it to SessionFactory
This commit is contained in:
parent
4b037cdf8f
commit
e19acd5a9c
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.bytecode.internal;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
public final class ProxyFactoryFactoryInitiator implements StandardServiceInitiator<ProxyFactoryFactory> {
|
||||
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final StandardServiceInitiator<ProxyFactoryFactory> INSTANCE = new ProxyFactoryFactoryInitiator();
|
||||
|
||||
@Override
|
||||
public ProxyFactoryFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||
return Environment.getBytecodeProvider().getProxyFactoryFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ProxyFactoryFactory> getServiceInitiated() {
|
||||
return ProxyFactoryFactory.class;
|
||||
}
|
||||
}
|
|
@ -6,11 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.bytecode.spi;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.SessionFactoryImpl;
|
||||
import org.hibernate.proxy.ProxyFactory;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.Service;
|
||||
|
||||
/**
|
||||
* An interface for factories of {@link ProxyFactory proxy factory} instances.
|
||||
|
@ -20,7 +18,7 @@ import org.hibernate.service.ServiceRegistry;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface ProxyFactoryFactory {
|
||||
public interface ProxyFactoryFactory extends Service {
|
||||
/**
|
||||
* Build a proxy factory specifically for handling runtime
|
||||
* lazy loading.
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.boot.cfgxml.internal.CfgXmlAccessServiceInitiator;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.bytecode.internal.ProxyFactoryFactoryInitiator;
|
||||
import org.hibernate.cache.internal.RegionFactoryInitiator;
|
||||
import org.hibernate.engine.config.internal.ConfigurationServiceInitiator;
|
||||
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderInitiator;
|
||||
|
@ -52,6 +53,8 @@ public final class StandardServiceInitiators {
|
|||
private static List<StandardServiceInitiator> buildStandardServiceInitiatorList() {
|
||||
final ArrayList<StandardServiceInitiator> serviceInitiators = new ArrayList<StandardServiceInitiator>();
|
||||
|
||||
serviceInitiators.add( ProxyFactoryFactoryInitiator.INSTANCE );
|
||||
|
||||
serviceInitiators.add( CfgXmlAccessServiceInitiator.INSTANCE );
|
||||
serviceInitiators.add( ConfigurationServiceInitiator.INSTANCE );
|
||||
serviceInitiators.add( PropertyAccessStrategyResolverInitiator.INSTANCE );
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.lang.reflect.Method;
|
|||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.spi.BasicProxyFactory;
|
||||
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -124,7 +125,8 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
|||
|
||||
protected Instantiator buildInstantiator(Component component) {
|
||||
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( this.componentClass ) ) {
|
||||
return new ProxiedInstantiator( this.componentClass );
|
||||
ProxyFactoryFactory proxyFactoryFactory = component.getServiceRegistry().getService( ProxyFactoryFactory.class );
|
||||
return new ProxiedInstantiator( this.componentClass, proxyFactoryFactory );
|
||||
}
|
||||
if ( optimizer == null ) {
|
||||
return new PojoInstantiator( this.componentClass, null );
|
||||
|
@ -151,16 +153,14 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
|||
private final Class proxiedClass;
|
||||
private final BasicProxyFactory factory;
|
||||
|
||||
public ProxiedInstantiator(Class componentClass) {
|
||||
public ProxiedInstantiator(Class componentClass, ProxyFactoryFactory proxyFactoryFactory) {
|
||||
proxiedClass = componentClass;
|
||||
if ( proxiedClass.isInterface() ) {
|
||||
factory = Environment.getBytecodeProvider()
|
||||
.getProxyFactoryFactory()
|
||||
factory = proxyFactoryFactory
|
||||
.buildBasicProxyFactory( null, new Class[] { proxiedClass } );
|
||||
}
|
||||
else {
|
||||
factory = Environment.getBytecodeProvider()
|
||||
.getProxyFactoryFactory()
|
||||
factory = proxyFactoryFactory
|
||||
.buildBasicProxyFactory( proxiedClass, null );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
|
||||
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.classic.Lifecycle;
|
||||
|
@ -182,9 +183,8 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
|
|||
PersistentClass persistentClass,
|
||||
Getter idGetter,
|
||||
Setter idSetter) {
|
||||
// TODO : YUCK!!! fix after HHH-1907 is complete
|
||||
return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory( getFactory() );
|
||||
// return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
|
||||
ProxyFactoryFactory proxyFactory = getFactory().getServiceRegistry().getService( ProxyFactoryFactory.class );
|
||||
return proxyFactory.buildProxyFactory( getFactory() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue