diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeProviderInitiator.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeProviderInitiator.java new file mode 100644 index 0000000000..d694a325af --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeProviderInitiator.java @@ -0,0 +1,35 @@ +/* + * 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 . + */ +package org.hibernate.bytecode.internal; + +import java.util.Map; + +import org.hibernate.boot.registry.StandardServiceInitiator; +import org.hibernate.bytecode.spi.BytecodeProvider; +import org.hibernate.cfg.Environment; +import org.hibernate.service.spi.ServiceRegistryImplementor; + +public final class BytecodeProviderInitiator implements StandardServiceInitiator { + + /** + * Singleton access + */ + public static final StandardServiceInitiator INSTANCE = new BytecodeProviderInitiator(); + + @Override + public BytecodeProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) { + // TODO in 6 this will no longer use Environment, which is configured via global environment variables, + // but move to a component which can be reconfigured differently in each registry. + return Environment.getBytecodeProvider(); + } + + @Override + public Class getServiceInitiated() { + return BytecodeProvider.class; + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/ProxyFactoryFactoryInitiator.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/ProxyFactoryFactoryInitiator.java index 6ba08b6453..f8e1d896a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/ProxyFactoryFactoryInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/ProxyFactoryFactoryInitiator.java @@ -9,10 +9,16 @@ package org.hibernate.bytecode.internal; import java.util.Map; import org.hibernate.boot.registry.StandardServiceInitiator; +import org.hibernate.bytecode.spi.BytecodeProvider; import org.hibernate.bytecode.spi.ProxyFactoryFactory; -import org.hibernate.cfg.Environment; import org.hibernate.service.spi.ServiceRegistryImplementor; +/** + * Most commonly the {@link ProxyFactoryFactory} will depend directly on the chosen {@link BytecodeProvider}, + * however by registering them as two separate services we can allow to override either one + * or both of them. + * @author Sanne Grinovero + */ public final class ProxyFactoryFactoryInitiator implements StandardServiceInitiator { /** @@ -22,7 +28,8 @@ public final class ProxyFactoryFactoryInitiator implements StandardServiceInitia @Override public ProxyFactoryFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) { - return Environment.getBytecodeProvider().getProxyFactoryFactory(); + final BytecodeProvider bytecodeProvider = registry.getService( BytecodeProvider.class ); + return bytecodeProvider.getProxyFactoryFactory(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java index f0c617247b..d56ec0f2dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java @@ -8,6 +8,7 @@ package org.hibernate.bytecode.spi; import org.hibernate.bytecode.enhance.spi.EnhancementContext; import org.hibernate.bytecode.enhance.spi.Enhancer; +import org.hibernate.service.Service; /** * Contract for providers of bytecode services to Hibernate. @@ -19,7 +20,7 @@ import org.hibernate.bytecode.enhance.spi.Enhancer; * * @author Steve Ebersole */ -public interface BytecodeProvider { +public interface BytecodeProvider extends Service { /** * Retrieve the specific factory for this provider capable of * generating run-time proxies for lazy-loading purposes. diff --git a/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java b/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java index 58ace1cf78..e41aba7769 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java +++ b/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java @@ -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.BytecodeProviderInitiator; import org.hibernate.bytecode.internal.ProxyFactoryFactoryInitiator; import org.hibernate.cache.internal.RegionFactoryInitiator; import org.hibernate.engine.config.internal.ConfigurationServiceInitiator; @@ -53,6 +54,7 @@ public final class StandardServiceInitiators { private static List buildStandardServiceInitiatorList() { final ArrayList serviceInitiators = new ArrayList(); + serviceInitiators.add( BytecodeProviderInitiator.INSTANCE ); serviceInitiators.add( ProxyFactoryFactoryInitiator.INSTANCE ); serviceInitiators.add( CfgXmlAccessServiceInitiator.INSTANCE ); diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java index fbb28c6032..d8b771aa4c 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java @@ -5,12 +5,14 @@ * See the lgpl.txt file in the root directory or . */ package org.hibernate.tuple.component; + import java.io.Serializable; import java.lang.reflect.Method; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.bytecode.spi.BasicProxyFactory; +import org.hibernate.bytecode.spi.BytecodeProvider; import org.hibernate.bytecode.spi.ProxyFactoryFactory; import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.cfg.Environment; @@ -68,9 +70,8 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { optimizer = null; } else { - // TODO: here is why we need to make bytecode provider global :( - // TODO : again, fix this after HHH-1907 is complete - optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( + final BytecodeProvider bytecodeProvider = component.getServiceRegistry().getService( BytecodeProvider.class ); + optimizer = bytecodeProvider.getReflectionOptimizer( componentClass, getterNames, setterNames, propTypes ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java index 24b284d521..3d956718d3 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java @@ -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.BytecodeProvider; import org.hibernate.bytecode.spi.ProxyFactoryFactory; import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.cfg.Environment; @@ -76,16 +77,13 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer { optimizer = null; } else { - // todo : YUCK!!! - optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( + final BytecodeProvider bytecodeProvider = entityMetamodel.getSessionFactory().getServiceRegistry().getService( BytecodeProvider.class ); + optimizer = bytecodeProvider.getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes ); -// optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer( -// mappedClass, getterNames, setterNames, propTypes -// ); } }