Skip to content

Commit

Permalink
Avoid Class to String conversions during Proxy pre-processing as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Mar 17, 2021
1 parent 8fc289d commit b66fcc8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
import org.hibernate.loader.BatchFetchStyle;
import org.hibernate.proxy.HibernateProxy;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget.Kind;
import org.jboss.jandex.AnnotationValue;
Expand Down Expand Up @@ -152,6 +151,7 @@ public final class HibernateOrmProcessor {
public static final DotName PROXY = DotName.createSimple("org.hibernate.annotations.Proxy");

private static final String INTEGRATOR_SERVICE_FILE = "META-INF/services/org.hibernate.integrator.spi.Integrator";
public static final String HIBERNATE_PROXY_INTERFACENAME = "org.hibernate.proxy.HibernateProxy";

@BuildStep
CapabilityBuildItem capability() {
Expand Down Expand Up @@ -1234,18 +1234,18 @@ private PreGeneratedProxies generatedProxies(Set<String> managedClassAndPackageN
&& !isModified(managedClassOrPackageName, changedClasses, combinedIndex)) {
result = proxyCache.cache.get(managedClassOrPackageName);
} else {
Set<Class<?>> proxyInterfaces = new HashSet<>();
proxyInterfaces.add(HibernateProxy.class); //always added
Set<String> proxyInterfaceNames = new TreeSet<>();
proxyInterfaceNames.add(HIBERNATE_PROXY_INTERFACENAME); //always added
String proxy = proxyAnnotations.get(managedClassOrPackageName);
if (proxy == null) {
if (!proxyHelper.isProxiable(managedClassOrPackageName)) {
//if there is no @Proxy we need to make sure the actual class is proxiable
continue;
}
} else {
proxyInterfaces.add(proxyHelper.uninitializedClass(proxy));
proxyInterfaceNames.add(proxy);
}
Class<?> mappedClass = proxyHelper.uninitializedClass(managedClassOrPackageName);
final String mappedClass = managedClassOrPackageName;
for (ClassInfo subclass : combinedIndex
.getAllKnownSubclasses(DotName.createSimple(managedClassOrPackageName))) {
String subclassName = subclass.name().toString();
Expand All @@ -1255,13 +1255,11 @@ private PreGeneratedProxies generatedProxies(Set<String> managedClassAndPackageN
}
proxy = proxyAnnotations.get(subclassName);
if (proxy != null) {
proxyInterfaces.add(proxyHelper.uninitializedClass(proxy));
proxyInterfaceNames.add(proxy);
}
}
DynamicType.Unloaded<?> unloaded = proxyHelper.buildUnloadedProxy(mappedClass,
toArray(proxyInterfaces));
result = new CachedProxy(unloaded,
proxyInterfaces.stream().map(Class::getName).collect(Collectors.toSet()));
DynamicType.Unloaded<?> unloaded = proxyHelper.buildUnloadedProxy(mappedClass, proxyInterfaceNames);
result = new CachedProxy(unloaded, proxyInterfaceNames);
proxyCache.cache.put(managedClassOrPackageName, result);
}
for (Entry<TypeDescription, byte[]> i : result.proxyDef.getAllTypes().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.hibernate.orm.deployment;

import java.lang.reflect.Modifier;
import java.util.Set;

import org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl;
import org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper;
Expand All @@ -22,7 +23,13 @@ public ProxyBuildingHelper(ClassLoader contextClassLoader) {
this.contextClassLoader = contextClassLoader;
}

public DynamicType.Unloaded<?> buildUnloadedProxy(Class<?> mappedClass, Class[] interfaces) {
public DynamicType.Unloaded<?> buildUnloadedProxy(String mappedClassName, Set<String> interfaceNames) {
final Class[] interfaces = new Class[interfaceNames.size()];
int i = 0;
for (String name : interfaceNames) {
interfaces[i++] = uninitializedClass(name);
}
final Class<?> mappedClass = uninitializedClass(mappedClassName);
return getByteBuddyProxyHelper().buildUnloadedProxy(mappedClass, interfaces);
}

Expand All @@ -36,7 +43,7 @@ private ByteBuddyProxyHelper getByteBuddyProxyHelper() {
return this.byteBuddyProxyHelper;
}

public Class<?> uninitializedClass(String entity) {
private Class<?> uninitializedClass(String entity) {
try {
return Class.forName(entity, false, contextClassLoader);
} catch (ClassNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.dialect.MariaDB103Dialect;
import org.hibernate.dialect.MySQL8Dialect;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.proxy.HibernateProxy;
import org.jboss.jandex.DotName;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -45,6 +46,7 @@ public void testConstantsInHibernateOrmProcessor() {
assertMatch(HibernateOrmProcessor.JPA_ENTITY, javax.persistence.Entity.class);
assertMatch(HibernateOrmProcessor.MAPPED_SUPERCLASS, javax.persistence.MappedSuperclass.class);
assertMatch(HibernateOrmProcessor.PROXY, org.hibernate.annotations.Proxy.class);
Assertions.assertEquals(HibernateProxy.class.getName(), HibernateOrmProcessor.HIBERNATE_PROXY_INTERFACENAME);
}

@Test
Expand Down

0 comments on commit b66fcc8

Please sign in to comment.