Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Scala-generated QueryDSL path classes. #3030

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*
* @author Oliver Gierke
* @author Jens Schauder
* @author Emanuel Trandafir
*/
public class SimpleEntityPathResolver implements EntityPathResolver {

Expand Down Expand Up @@ -71,6 +72,7 @@ public <T> EntityPath<T> createPath(Class<T> domainClass) {
Class<?> pathClass = ClassUtils.forName(pathClassName, domainClass.getClassLoader());

return getStaticFieldOfType(pathClass)//
.or(() -> getFieldForScalaObject(domainClass, pathClassName))//
.map(it -> (EntityPath<T>) ReflectionUtils.getField(it, null))//
.orElseThrow(() -> new IllegalStateException(String.format(NO_FIELD_FOUND_TEMPLATE, pathClass)));

Expand All @@ -80,6 +82,26 @@ public <T> EntityPath<T> createPath(Class<T> domainClass) {
}
}

/**
* Resolves the static field of the given type inside the specified domain class. Useful for handling Scala-generated
* QueryDSL path classes.
*
* @param domainClass The domain class for which the static field needs to be resolved.
* @param javaPathClassName The Java path class name without the "$" suffix.
* @return
*/
private <T> Optional<Field> getFieldForScalaObject(Class<T> domainClass, String javaPathClassName) {
try {

Class<?> scalaPathClass = ClassUtils.forName(javaPathClassName + "$", domainClass.getClassLoader());
return getStaticFieldOfType(scalaPathClass);

} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
String.format(NO_CLASS_FOUND_TEMPLATE, javaPathClassName + "$", domainClass.getName()), e);
}
}

/**
* Returns the first static field of the given type inside the given type.
*
Expand Down