Skip to content

Commit

Permalink
Propagate all user methods in REST Data with Panache
Browse files Browse the repository at this point in the history
Relates to #35129 (comment) and #35129
  • Loading branch information
Sgitario committed Aug 2, 2023
1 parent c07c61e commit 49cbd18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import io.quarkus.rest.data.panache.deployment.methods.ListMethodImplementor;
import io.quarkus.rest.data.panache.deployment.methods.MethodImplementor;
import io.quarkus.rest.data.panache.deployment.methods.UpdateMethodImplementor;
import io.quarkus.rest.data.panache.deployment.methods.UserMethodsWithTransactionalImplementor;
import io.quarkus.rest.data.panache.deployment.methods.UserMethodsImplementor;
import io.quarkus.rest.data.panache.deployment.methods.hal.ListHalMethodImplementor;
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;
import io.quarkus.runtime.util.HashUtil;
Expand All @@ -49,7 +49,7 @@ class JaxRsResourceImplementor {
new AddMethodImplementor(capabilities),
new UpdateMethodImplementor(capabilities),
new DeleteMethodImplementor(capabilities),
new UserMethodsWithTransactionalImplementor(capabilities),
new UserMethodsImplementor(),
// The list hal endpoint needs to be added for both resteasy classic and resteasy reactive
// because the pagination links are programmatically added.
new ListHalMethodImplementor(capabilities));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.quarkus.rest.data.panache.deployment.methods;

import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.DotName;

import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.gizmo.ClassCreator;
import io.quarkus.gizmo.FieldDescriptor;
import io.quarkus.gizmo.MethodCreator;
Expand All @@ -14,26 +11,17 @@
import io.quarkus.rest.data.panache.deployment.properties.ResourceProperties;

/**
* Propagate the user methods annotated with `@Transactional`.
* This implementor is only used if Hibernate ORM is present.
* Propagate all the user methods. This is necessary when users use annotations with an interceptor binding
* like `@Transactional`.
*/
public final class UserMethodsWithTransactionalImplementor implements MethodImplementor {

public static final DotName TRANSACTIONAL = DotName.createSimple("jakarta.transaction.Transactional");

private final Capabilities capabilities;

public UserMethodsWithTransactionalImplementor(Capabilities capabilities) {
this.capabilities = capabilities;
}
public final class UserMethodsImplementor implements MethodImplementor {

@Override
public void implement(ClassCreator classCreator, ResourceMetadata resourceMetadata,
ResourceProperties resourceProperties, FieldDescriptor resourceField) {
if (capabilities.isPresent(Capability.HIBERNATE_ORM) && resourceMetadata.getResourceInterface() != null) {
if (resourceMetadata.getResourceInterface() != null) {
for (var methodInfo : resourceMetadata.getResourceInterface().methods()) {
// we only need to propagate the user methods annotated with `@Transactional`
if (methodInfo.hasAnnotation(TRANSACTIONAL)) {
if (methodInfo.isDefault()) {
MethodCreator methodCreator = classCreator.getMethodCreator(MethodDescriptor.of(methodInfo));
methodCreator.setSignature(methodInfo.genericSignatureIfRequired());
for (var annotation : methodInfo.annotations()) {
Expand Down

0 comments on commit 49cbd18

Please sign in to comment.