HHH-13849 Convert BytecodeProvider into a Service as well
This commit is contained in:
parent
e19acd5a9c
commit
5c81089d65
|
@ -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 <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.BytecodeProvider;
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
|
||||||
|
public final class BytecodeProviderInitiator implements StandardServiceInitiator<BytecodeProvider> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton access
|
||||||
|
*/
|
||||||
|
public static final StandardServiceInitiator<BytecodeProvider> 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<BytecodeProvider> getServiceInitiated() {
|
||||||
|
return BytecodeProvider.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,10 +9,16 @@ package org.hibernate.bytecode.internal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
|
import org.hibernate.bytecode.spi.BytecodeProvider;
|
||||||
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
||||||
import org.hibernate.cfg.Environment;
|
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
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<ProxyFactoryFactory> {
|
public final class ProxyFactoryFactoryInitiator implements StandardServiceInitiator<ProxyFactoryFactory> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +28,8 @@ public final class ProxyFactoryFactoryInitiator implements StandardServiceInitia
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProxyFactoryFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
public ProxyFactoryFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||||
return Environment.getBytecodeProvider().getProxyFactoryFactory();
|
final BytecodeProvider bytecodeProvider = registry.getService( BytecodeProvider.class );
|
||||||
|
return bytecodeProvider.getProxyFactoryFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.bytecode.spi;
|
||||||
|
|
||||||
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
|
import org.hibernate.bytecode.enhance.spi.EnhancementContext;
|
||||||
import org.hibernate.bytecode.enhance.spi.Enhancer;
|
import org.hibernate.bytecode.enhance.spi.Enhancer;
|
||||||
|
import org.hibernate.service.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract for providers of bytecode services to Hibernate.
|
* Contract for providers of bytecode services to Hibernate.
|
||||||
|
@ -19,7 +20,7 @@ import org.hibernate.bytecode.enhance.spi.Enhancer;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface BytecodeProvider {
|
public interface BytecodeProvider extends Service {
|
||||||
/**
|
/**
|
||||||
* Retrieve the specific factory for this provider capable of
|
* Retrieve the specific factory for this provider capable of
|
||||||
* generating run-time proxies for lazy-loading purposes.
|
* generating run-time proxies for lazy-loading purposes.
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.boot.cfgxml.internal.CfgXmlAccessServiceInitiator;
|
import org.hibernate.boot.cfgxml.internal.CfgXmlAccessServiceInitiator;
|
||||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
|
import org.hibernate.bytecode.internal.BytecodeProviderInitiator;
|
||||||
import org.hibernate.bytecode.internal.ProxyFactoryFactoryInitiator;
|
import org.hibernate.bytecode.internal.ProxyFactoryFactoryInitiator;
|
||||||
import org.hibernate.cache.internal.RegionFactoryInitiator;
|
import org.hibernate.cache.internal.RegionFactoryInitiator;
|
||||||
import org.hibernate.engine.config.internal.ConfigurationServiceInitiator;
|
import org.hibernate.engine.config.internal.ConfigurationServiceInitiator;
|
||||||
|
@ -53,6 +54,7 @@ public final class StandardServiceInitiators {
|
||||||
private static List<StandardServiceInitiator> buildStandardServiceInitiatorList() {
|
private static List<StandardServiceInitiator> buildStandardServiceInitiatorList() {
|
||||||
final ArrayList<StandardServiceInitiator> serviceInitiators = new ArrayList<StandardServiceInitiator>();
|
final ArrayList<StandardServiceInitiator> serviceInitiators = new ArrayList<StandardServiceInitiator>();
|
||||||
|
|
||||||
|
serviceInitiators.add( BytecodeProviderInitiator.INSTANCE );
|
||||||
serviceInitiators.add( ProxyFactoryFactoryInitiator.INSTANCE );
|
serviceInitiators.add( ProxyFactoryFactoryInitiator.INSTANCE );
|
||||||
|
|
||||||
serviceInitiators.add( CfgXmlAccessServiceInitiator.INSTANCE );
|
serviceInitiators.add( CfgXmlAccessServiceInitiator.INSTANCE );
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.tuple.component;
|
package org.hibernate.tuple.component;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.bytecode.spi.BasicProxyFactory;
|
import org.hibernate.bytecode.spi.BasicProxyFactory;
|
||||||
|
import org.hibernate.bytecode.spi.BytecodeProvider;
|
||||||
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
import org.hibernate.bytecode.spi.ProxyFactoryFactory;
|
||||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
@ -68,9 +70,8 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer {
|
||||||
optimizer = null;
|
optimizer = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: here is why we need to make bytecode provider global :(
|
final BytecodeProvider bytecodeProvider = component.getServiceRegistry().getService( BytecodeProvider.class );
|
||||||
// TODO : again, fix this after HHH-1907 is complete
|
optimizer = bytecodeProvider.getReflectionOptimizer(
|
||||||
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
|
|
||||||
componentClass, getterNames, setterNames, propTypes
|
componentClass, getterNames, setterNames, propTypes
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||||
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
|
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.ProxyFactoryFactory;
|
||||||
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
import org.hibernate.bytecode.spi.ReflectionOptimizer;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
@ -76,16 +77,13 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
|
||||||
optimizer = null;
|
optimizer = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// todo : YUCK!!!
|
final BytecodeProvider bytecodeProvider = entityMetamodel.getSessionFactory().getServiceRegistry().getService( BytecodeProvider.class );
|
||||||
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
|
optimizer = bytecodeProvider.getReflectionOptimizer(
|
||||||
mappedClass,
|
mappedClass,
|
||||||
getterNames,
|
getterNames,
|
||||||
setterNames,
|
setterNames,
|
||||||
propTypes
|
propTypes
|
||||||
);
|
);
|
||||||
// optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
|
|
||||||
// mappedClass, getterNames, setterNames, propTypes
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue