-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hibernate Reactive Panache: open session on demand for repositories
- also open reactive session automatically on demand if a JAX-RS endpoint returns Uni and the resource class imports a Panache repository; currently only Panache entities are supported (cherry picked from commit cabb4de)
- Loading branch information
Showing
5 changed files
with
112 additions
and
39 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...yment/src/main/java/io/quarkus/hibernate/reactive/panache/common/deployment/DotNames.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,40 @@ | ||
package io.quarkus.hibernate.reactive.panache.common.deployment; | ||
|
||
import jakarta.persistence.NamedQueries; | ||
import jakarta.persistence.NamedQuery; | ||
|
||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkus.hibernate.reactive.panache.common.WithSession; | ||
import io.quarkus.hibernate.reactive.panache.common.WithSessionOnDemand; | ||
import io.quarkus.hibernate.reactive.panache.common.WithTransaction; | ||
import io.quarkus.hibernate.reactive.panache.common.runtime.ReactiveTransactional; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
final class DotNames { | ||
|
||
static final DotName DOTNAME_NAMED_QUERY = DotName.createSimple(NamedQuery.class.getName()); | ||
static final DotName DOTNAME_NAMED_QUERIES = DotName.createSimple(NamedQueries.class.getName()); | ||
static final DotName REACTIVE_TRANSACTIONAL = DotName.createSimple(ReactiveTransactional.class.getName()); | ||
static final DotName WITH_SESSION_ON_DEMAND = DotName.createSimple(WithSessionOnDemand.class.getName()); | ||
static final DotName WITH_SESSION = DotName.createSimple(WithSession.class.getName()); | ||
static final DotName WITH_TRANSACTION = DotName.createSimple(WithTransaction.class.getName()); | ||
static final DotName UNI = DotName.createSimple(Uni.class.getName()); | ||
|
||
static final DotName PANACHE_ENTITY_BASE = DotName | ||
.createSimple("io.quarkus.hibernate.reactive.panache.PanacheEntityBase"); | ||
static final DotName PANACHE_ENTITY = DotName.createSimple("io.quarkus.hibernate.reactive.panache.PanacheEntity"); | ||
static final DotName PANACHE_KOTLIN_ENTITY_BASE = DotName | ||
.createSimple("io.quarkus.hibernate.reactive.panache.kotlin.PanacheEntityBase"); | ||
static final DotName PANACHE_KOTLIN_ENTITY = DotName | ||
.createSimple("io.quarkus.hibernate.reactive.panache.kotlin.PanacheEntity"); | ||
|
||
static final DotName PANACHE_REPOSITORY_BASE = DotName | ||
.createSimple("io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase"); | ||
static final DotName PANACHE_REPOSITORY = DotName.createSimple("io.quarkus.hibernate.reactive.panache.PanacheRepository"); | ||
static final DotName PANACHE_KOTLIN_REPOSITORY_BASE = DotName | ||
.createSimple("io.quarkus.hibernate.reactive.panache.kotlin.PanacheRepositoryBase"); | ||
static final DotName PANACHE_KOTLIN_REPOSITORY = DotName | ||
.createSimple("io.quarkus.hibernate.reactive.panache.kotlin.PanacheRepository"); | ||
|
||
} |
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
10 changes: 10 additions & 0 deletions
10
...bernate-reactive-panache/src/main/java/io/quarkus/it/panache/reactive/BeerRepository.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,10 @@ | ||
package io.quarkus.it.panache.reactive; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheRepository; | ||
|
||
@ApplicationScoped | ||
public class BeerRepository implements PanacheRepository<Beer> { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...reactive-panache/src/main/java/io/quarkus/it/panache/reactive/TestRepositoryEndpoint.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,22 @@ | ||
package io.quarkus.it.panache.reactive; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
@Path("test-repo") | ||
public class TestRepositoryEndpoint { | ||
|
||
@Inject | ||
BeerRepository beerRepository; | ||
|
||
// @WithSessionOnDemand is added automatically | ||
@GET | ||
@Path("beers") | ||
public Uni<String> testBeers() { | ||
return beerRepository.count().map(v -> "OK"); | ||
} | ||
|
||
} |
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