Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8d6c9f

Browse files
committed
Polishing.
Avoid caching. Expand exception handling to all reflective exceptions. Fix since tags. See: #2721 Original pull request: #2743.
1 parent 016e8c2 commit f8d6c9f

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

‎src/main/java/org/springframework/data/util/QTypeContributor.java‎

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
*/
1616
package org.springframework.data.util;
1717

18-
import java.util.Map;
19-
import java.util.WeakHashMap;
20-
import java.util.function.Function;
21-
2218
import org.apache.commons.logging.Log;
2319
import org.apache.commons.logging.LogFactory;
2420
import org.springframework.aot.generate.GenerationContext;
@@ -29,23 +25,25 @@
2925

3026
/**
3127
* @author Christoph Strobl
32-
* @since 4.1
28+
* @since 3.0.1
3329
*/
3430
public class QTypeContributor {
3531

3632
private final static Log logger = LogFactory.getLog(QTypeContributor.class);
37-
private static Function<ClassLoader, Class<?>> entityPathType = cacheOf(QTypeContributor::getEntityPathType);
3833

3934
public static void contributeEntityPath(Class<?> type, GenerationContext context, @Nullable ClassLoader classLoader) {
4035

41-
Class<?> entityPathType = QTypeContributor.entityPathType.apply(classLoader);
42-
if (entityPathType == null) {
43-
return;
44-
}
36+
try {
37+
38+
Class<?> entityPathType = getEntityPathType(classLoader);
39+
40+
if (entityPathType == null) {
41+
return;
42+
}
43+
44+
String queryClassName = getQueryClassName(type);
45+
if (ClassUtils.isPresent(queryClassName, classLoader)) {
4546

46-
String queryClassName = getQueryClassName(type);
47-
if (ClassUtils.isPresent(queryClassName, classLoader)) {
48-
try {
4947
if (ClassUtils.isAssignable(entityPathType, ClassUtils.forName(queryClassName, classLoader))) {
5048

5149
logger.debug("Registering Q type %s for %s.");
@@ -55,33 +53,26 @@ public static void contributeEntityPath(Class<?> type, GenerationContext context
5553
} else {
5654
logger.debug("Skipping Q type %s. Not an EntityPath.");
5755
}
58-
} catch (ClassNotFoundException e) {
59-
throw new IllegalStateException("%s could not be loaded".formatted(queryClassName), e);
6056
}
57+
} catch (ClassNotFoundException e) {
58+
throw new IllegalStateException("Cannot contribute Q class for domain type %s".formatted(type.getName()), e);
6159
}
6260
}
6361

6462
@Nullable
65-
private static Class<?> getEntityPathType(ClassLoader classLoader) {
63+
private static Class<?> getEntityPathType(@NullableClassLoader classLoader)throwsClassNotFoundException {
6664

67-
if (!ClassUtils.isPresent("com.querydsl.core.types.EntityPath", classLoader)) {
65+
String entityPathClassName = "com.querydsl.core.types.EntityPath";
66+
if (!ClassUtils.isPresent(entityPathClassName, classLoader)) {
6867
return null;
6968
}
7069

71-
try {
72-
return ClassUtils.forName("com.querydsl.core.types.EntityPath", classLoader);
73-
} catch (ClassNotFoundException e) {
74-
throw new RuntimeException(e);
75-
}
76-
}
77-
78-
private static Function<ClassLoader, Class<?>> cacheOf(Function<ClassLoader, Class<?>> inFunction) {
79-
Map<ClassLoader, Class<?>> cache = new WeakHashMap<>();
80-
return in -> cache.computeIfAbsent(in, inFunction::apply);
70+
return ClassUtils.forName(entityPathClassName, classLoader);
8171
}
8272

8373
/**
84-
* Returns the name of the query class for the given domain class.
74+
* Returns the name of the query class for the given domain class following {@code SimpleEntityPathResolver}
75+
* conventions.
8576
*
8677
* @param domainClass
8778
* @return

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /