|
17 | 17 | import com.querydsl.core.types.Expression; |
18 | 18 | import com.querydsl.core.types.Path; |
19 | 19 | import com.querydsl.core.types.PathMetadataFactory; |
| 20 | +import java.lang.reflect.InvocationTargetException; |
20 | 21 | import java.util.Collections; |
21 | 22 | import java.util.Map; |
22 | 23 | import java.util.WeakHashMap; |
23 | 24 | import java.util.concurrent.ConcurrentHashMap; |
24 | | -import net.sf.cglib.proxy.Enhancer; |
25 | | -import net.sf.cglib.proxy.MethodInterceptor; |
| 25 | +import net.bytebuddy.ByteBuddy; |
| 26 | +import net.bytebuddy.implementation.MethodDelegation; |
| 27 | +import net.bytebuddy.matcher.ElementMatchers; |
26 | 28 | import org.jetbrains.annotations.Nullable; |
27 | 29 |
|
28 | 30 | /** |
@@ -98,21 +100,26 @@ public <A> A createAliasForVariable(Class<A> cl, String var) { |
98 | 100 | * @param path underlying expression |
99 | 101 | * @return proxy instance |
100 | 102 | */ |
101 | | - @SuppressWarnings("unchecked") |
102 | 103 | protected <A> A createProxy(Class<A> cl, Expression<?> path) { |
103 | | - Enhancer enhancer = new Enhancer(); |
104 | | - enhancer.setClassLoader(AliasFactory.class.getClassLoader()); |
105 | | - if (cl.isInterface()) { |
106 | | - enhancer.setInterfaces(new Class<?>[] {cl, ManagedObject.class}); |
107 | | - } else { |
108 | | - enhancer.setSuperclass(cl); |
109 | | - enhancer.setInterfaces(new Class<?>[] {ManagedObject.class}); |
| 104 | + try { |
| 105 | + return new ByteBuddy() |
| 106 | + .subclass(cl) |
| 107 | + .implement(ManagedObject.class) |
| 108 | + .method(ElementMatchers.any()) |
| 109 | + .intercept( |
| 110 | + MethodDelegation.to( |
| 111 | + new PropertyAccessInvocationHandler(path, this, pathFactory, typeSystem))) |
| 112 | + .make() |
| 113 | + .load(AliasFactory.class.getClassLoader()) |
| 114 | + .getLoaded() |
| 115 | + .getDeclaredConstructor() |
| 116 | + .newInstance(); |
| 117 | + } catch (InvocationTargetException |
| 118 | + | InstantiationException |
| 119 | + | IllegalAccessException |
| 120 | + | NoSuchMethodException e) { |
| 121 | + throw new RuntimeException(e); |
110 | 122 | } |
111 | | - // creates one handler per proxy |
112 | | - MethodInterceptor handler = |
113 | | - new PropertyAccessInvocationHandler(path, this, pathFactory, typeSystem); |
114 | | - enhancer.setCallback(handler); |
115 | | - return (A) enhancer.create(); |
116 | 123 | } |
117 | 124 |
|
118 | 125 | /** |
|
0 commit comments