forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#45649 from zakkak/2025-01-16-fix-45525
Make methods of reachable hibernate services reflectively queryable
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ain/java/io/quarkus/hibernate/orm/runtime/graal/RegisterServicesForReflectionFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.hibernate.orm.runtime.graal; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.graalvm.nativeimage.hosted.Feature; | ||
import org.graalvm.nativeimage.hosted.RuntimeReflection; | ||
|
||
/** | ||
* Makes methods of reachable hibernate services accessible through {@link Class#getMethods()}. | ||
* | ||
* See <a href="https://github.com/quarkusio/quarkus/issues/45525">Github issue #45525</a>. | ||
*/ | ||
public class RegisterServicesForReflectionFeature implements Feature { | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Makes methods of reachable hibernate services accessible through getMethods()`"; | ||
} | ||
|
||
// The {@code duringAnalysis} method is invoked multiple times and increases the set of reachable types, thus we | ||
// need to invoke {@link DuringAnalysisAccess#requireAnalysisIteration()} each time we register new methods. | ||
private static final int ANTICIPATED_SERVICES = 100; | ||
private static final Set<Class<?>> registeredClasses = new HashSet<>(ANTICIPATED_SERVICES); | ||
|
||
@Override | ||
public void duringAnalysis(DuringAnalysisAccess access) { | ||
for (Class<?> service : access.reachableSubtypes(org.hibernate.service.Service.class)) { | ||
if (registeredClasses.add(service)) { | ||
RuntimeReflection.registerAllMethods(service); | ||
access.requireAnalysisIteration(); | ||
} | ||
} | ||
} | ||
} |