mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-23 03:24:55 +00:00
HHH-15090 Allow passing unloaded types and a TypePool to ByteBuddyProxyHelper#buildUnloadedProxy
This is necessary to solve this bug in Quarkus.
This commit is contained in:
parent
9dcd5e55b1
commit
3d8f5db3e0
@ -189,6 +189,10 @@ public Unloaded<?> make(Function<ByteBuddy, DynamicType.Builder<?>> makeProxyFun
|
||||
return make( makeProxyFunction.apply( byteBuddy ) );
|
||||
}
|
||||
|
||||
public Unloaded<?> make(TypePool typePool, Function<ByteBuddy, DynamicType.Builder<?>> makeProxyFunction) {
|
||||
return make( typePool, makeProxyFunction.apply( byteBuddy ) );
|
||||
}
|
||||
|
||||
private Unloaded<?> make(DynamicType.Builder<?> builder) {
|
||||
return make( null, builder );
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
@ -27,9 +28,13 @@
|
||||
import net.bytebuddy.NamingStrategy;
|
||||
import net.bytebuddy.TypeCache;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.description.type.TypeDefinition;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.description.type.TypeList;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
|
||||
import net.bytebuddy.implementation.SuperMethodCall;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
public class ByteBuddyProxyHelper implements Serializable {
|
||||
|
||||
@ -52,22 +57,34 @@ public Class buildProxy(
|
||||
}
|
||||
Collections.addAll( key, interfaces );
|
||||
|
||||
return byteBuddyState.loadProxy( persistentClass, new TypeCache.SimpleKey( key ), proxyBuilder( persistentClass, interfaces ) );
|
||||
return byteBuddyState.loadProxy( persistentClass, new TypeCache.SimpleKey( key ),
|
||||
proxyBuilder( TypeDescription.ForLoadedType.of( persistentClass ), new TypeList.Generic.ForLoadedTypes( interfaces ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #buildUnloadedProxy(TypePool, TypeDefinition, Collection)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public DynamicType.Unloaded<?> buildUnloadedProxy(final Class<?> persistentClass, final Class<?>[] interfaces) {
|
||||
return byteBuddyState.make( proxyBuilder( TypeDescription.ForLoadedType.of( persistentClass ),
|
||||
new TypeList.Generic.ForLoadedTypes( interfaces ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not remove: used by Quarkus
|
||||
*/
|
||||
public DynamicType.Unloaded<?> buildUnloadedProxy(final Class<?> persistentClass, final Class<?>[] interfaces) {
|
||||
return byteBuddyState.make( proxyBuilder( persistentClass, interfaces ) );
|
||||
public DynamicType.Unloaded<?> buildUnloadedProxy(TypePool typePool, TypeDefinition persistentClass,
|
||||
Collection<? extends TypeDefinition> interfaces) {
|
||||
return byteBuddyState.make( typePool, proxyBuilder( persistentClass, interfaces ) );
|
||||
}
|
||||
|
||||
private Function<ByteBuddy, DynamicType.Builder<?>> proxyBuilder(Class<?> persistentClass, Class<?>[] interfaces) {
|
||||
private Function<ByteBuddy, DynamicType.Builder<?>> proxyBuilder(TypeDefinition persistentClass,
|
||||
Collection<? extends TypeDefinition> interfaces) {
|
||||
ByteBuddyState.ProxyDefinitionHelpers helpers = byteBuddyState.getProxyDefinitionHelpers();
|
||||
return byteBuddy -> byteBuddy
|
||||
.ignore( helpers.getGroovyGetMetaClassFilter() )
|
||||
.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 )
|
||||
.with( new NamingStrategy.SuffixingRandom( PROXY_NAMING_SUFFIX, new NamingStrategy.SuffixingRandom.BaseNameResolver.ForFixedValue( persistentClass.getTypeName() ) ) )
|
||||
.subclass( interfaces.size() == 1 ? persistentClass : TypeDescription.OBJECT, ConstructorStrategy.Default.IMITATE_SUPER_CLASS_OPENING )
|
||||
.implement( interfaces )
|
||||
.method( helpers.getVirtualNotFinalizerFilter() )
|
||||
.intercept( helpers.getDelegateToInterceptorDispatcherMethodDelegation() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user