HHH-12618 Make sure the proxy classes are created in the right package
This commit is contained in:
parent
c9f5bc920a
commit
562661e0a2
|
@ -26,9 +26,7 @@ import net.bytebuddy.matcher.ElementMatchers;
|
|||
public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
||||
|
||||
private static final Class[] NO_INTERFACES = new Class[0];
|
||||
private static final NamingStrategy PROXY_NAMING = Environment.useLegacyProxyClassnames() ?
|
||||
new NamingStrategy.SuffixingRandom( "HibernateBasicProxy$" ) :
|
||||
new NamingStrategy.SuffixingRandom( "HibernateBasicProxy" );
|
||||
private static final String PROXY_NAMING_SUFFIX = Environment.useLegacyProxyClassnames() ? "HibernateBasicProxy$" : "HibernateBasicProxy";
|
||||
|
||||
private final Class proxyClass;
|
||||
|
||||
|
@ -48,7 +46,7 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
|||
}
|
||||
|
||||
this.proxyClass = bytebuddy.getCurrentyByteBuddy()
|
||||
.with( PROXY_NAMING )
|
||||
.with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( superClassOrMainInterface.getName() ) ) )
|
||||
.subclass( superClass == null ? Object.class : superClass )
|
||||
.implement( interfaces == null ? NO_INTERFACES : interfaces )
|
||||
.defineField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME, ProxyConfiguration.Interceptor.class, Visibility.PRIVATE )
|
||||
|
|
|
@ -38,8 +38,8 @@ import net.bytebuddy.matcher.ElementMatchers;
|
|||
public class BytecodeProviderImpl implements BytecodeProvider {
|
||||
|
||||
private static final ByteBuddyState bytebuddy = new ByteBuddyState();
|
||||
private static final NamingStrategy.SuffixingRandom instantiatorName = new NamingStrategy.SuffixingRandom( "HibernateInstantiator" );
|
||||
private static final NamingStrategy.SuffixingRandom optimizerName = new NamingStrategy.SuffixingRandom( "HibernateAccessOptimizer" );
|
||||
private static final String INSTANTIATOR_PROXY_NAMING_SUFFIX = "HibernateInstantiator";
|
||||
private static final String OPTIMIZER_PROXY_NAMING_SUFFIX = "HibernateAccessOptimizer";
|
||||
private static final ElementMatcher.Junction newInstanceMethodName = ElementMatchers.named( "newInstance" );
|
||||
private static final ElementMatcher.Junction getPropertyValuesMethodName = ElementMatchers.named( "getPropertyValues" );
|
||||
private static final ElementMatcher.Junction setPropertyValuesMethodName = ElementMatchers.named( "setPropertyValues" );
|
||||
|
@ -62,7 +62,8 @@ public class BytecodeProviderImpl implements BytecodeProvider {
|
|||
final Constructor<?> constructor = findConstructor( clazz );
|
||||
|
||||
final Class fastClass = bytebuddy.getCurrentyByteBuddy()
|
||||
.with( instantiatorName )
|
||||
.with( new NamingStrategy.SuffixingRandom( INSTANTIATOR_PROXY_NAMING_SUFFIX,
|
||||
new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( clazz.getName() ) ) )
|
||||
.subclass( ReflectionOptimizer.InstantiationOptimizer.class )
|
||||
.method( newInstanceMethodName )
|
||||
.intercept( MethodCall.construct( constructor ) )
|
||||
|
@ -71,7 +72,8 @@ public class BytecodeProviderImpl implements BytecodeProvider {
|
|||
.getLoaded();
|
||||
|
||||
final Class bulkAccessor = bytebuddy.getCurrentyByteBuddy()
|
||||
.with( optimizerName )
|
||||
.with( new NamingStrategy.SuffixingRandom( OPTIMIZER_PROXY_NAMING_SUFFIX,
|
||||
new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( clazz.getName() ) ) )
|
||||
.subclass( ReflectionOptimizer.AccessOptimizer.class )
|
||||
.method( getPropertyValuesMethodName )
|
||||
.intercept( new Implementation.Simple( new GetPropertyValues( clazz, getters ) ) )
|
||||
|
|
|
@ -47,9 +47,7 @@ import static org.hibernate.internal.CoreLogging.messageLogger;
|
|||
public class ByteBuddyProxyFactory implements ProxyFactory, Serializable {
|
||||
|
||||
private static final CoreMessageLogger LOG = messageLogger( ByteBuddyProxyFactory.class );
|
||||
private static final NamingStrategy PROXY_NAMING = Environment.useLegacyProxyClassnames() ?
|
||||
new NamingStrategy.SuffixingRandom( "HibernateProxy$" ) :
|
||||
new NamingStrategy.SuffixingRandom( "HibernateProxy" );
|
||||
private static final String PROXY_NAMING_SUFFIX = Environment.useLegacyProxyClassnames() ? "HibernateProxy$" : "HibernateProxy";
|
||||
|
||||
private Class persistentClass;
|
||||
private String entityName;
|
||||
|
@ -102,7 +100,7 @@ public class ByteBuddyProxyFactory implements ProxyFactory, Serializable {
|
|||
return cacheForProxies.findOrInsert( persistentClass.getClassLoader(), new TypeCache.SimpleKey(key), () ->
|
||||
ByteBuddyState.getStaticByteBuddyInstance()
|
||||
.ignore( isSynthetic().and( named( "getMetaClass" ).and( returns( td -> "groovy.lang.MetaClass".equals( td.getName() ) ) ) ) )
|
||||
.with( PROXY_NAMING )
|
||||
.with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( persistentClass.getName() ) ) )
|
||||
.subclass( interfaces.length == 1 ? persistentClass : Object.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING )
|
||||
.implement( (Type[]) interfaces )
|
||||
.method( isVirtual().and( not( isFinalizer() ) ) )
|
||||
|
|
Loading…
Reference in New Issue