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.
Fix user methods requiring a session in Panache REST Data with Reactive
These changes add the `@WithSessionOnDemand` annotation at class level when using Panache REST Data with Hibernate Reactive. This annotation makes user methods that return an Uni class to work. About tests, I've covered the following scenarios: - user GET method that returns an Uni - user POST method that returns an Uni (and requires a transaction) - injecting the generated resource will also work Fix quarkusio#34432
- Loading branch information
Showing
10 changed files
with
125 additions
and
6 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
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
24 changes: 24 additions & 0 deletions
24
...o/quarkus/hibernate/reactive/rest/data/panache/deployment/entity/CollectionsResource.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 |
---|---|---|
@@ -1,8 +1,32 @@ | ||
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.entity; | ||
|
||
import java.util.Collections; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
|
||
import io.quarkus.hibernate.reactive.panache.common.WithSessionOnDemand; | ||
import io.quarkus.hibernate.reactive.rest.data.panache.PanacheEntityResource; | ||
import io.quarkus.rest.data.panache.ResourceProperties; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@ResourceProperties(hal = true, paged = false, halCollectionName = "item-collections") | ||
@WithSessionOnDemand | ||
public interface CollectionsResource extends PanacheEntityResource<Collection, String> { | ||
@GET | ||
@Path("/name/{name}") | ||
default Uni<Collection> findByName(@PathParam("name") String name) { | ||
return Collection.find("name = :name", Collections.singletonMap("name", name)).singleResult(); | ||
} | ||
|
||
@POST | ||
@Path("/name/{name}") | ||
default Uni<Collection> addByName(@PathParam("name") String name) { | ||
Collection collection = new Collection(); | ||
collection.id = name; | ||
collection.name = name; | ||
return Collection.persist(collection).onItem().transform(res -> collection); | ||
} | ||
} |
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
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
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
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
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
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
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