Skip to content

Have Uni return types on all Session opening methods #973 #983

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

Merged
merged 6 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
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
16 changes: 9 additions & 7 deletions documentation/src/main/asciidoc/reference/introduction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,14 @@ the session when you're done.

[source, JAVA, indent=0]
----
Session session = sessionFactory.openSession();
session.find(Book.class, id)
.invoke(
book -> ... //do something with the book
)
.eventually(session::close);
Uni<Session> sessionUni = sessionFactory.openSession();
sessionUni.chain(
session -> session.find(Book.class, id)
.invoke(
book -> ... //do something with the book
)
.eventually(session::close)
);
----

=== Using the reactive session
Expand Down Expand Up @@ -1281,4 +1283,4 @@ or `withTransaction()`.

Hibernate Reactive is now integrated in {Quarkus}[Quarkus] and {Panache}[Panache].
Configuration works slightly differently in Quarkus, so be sure to check the Quarkus
documentation for details.
documentation for details.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Hibernate, Relational Persistence for Idiomatic Java
*
* SPDX-License-Identifier: Apache-2.0
* Copyright: Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.reactive.common.spi;

import java.util.function.Function;

import org.hibernate.reactive.mutiny.Mutiny;

/**
* @deprecated It will be removed
*/
@Deprecated
public interface MutinyImplementor {

/**
* Obtain a new {@link Mutiny.Session reactive session}, the main
* interaction point between the user's program and Hibernate
* Reactive.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link Mutiny.Session} needs to access the database.
* <p>
* The client must explicitly close the session by calling
* {@link Mutiny.Session#close()}.
*
* @see Mutiny.SessionFactory#withSession(Function)
* @see Mutiny.SessionFactory#openSession()
*/
Mutiny.Session newSession();

/**
* Obtain a new {@link Mutiny.Session reactive session} for a
* specified tenant.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link Mutiny.Session} needs to access the database.
* <p>
* The client must explicitly close the session by calling
* {@link Mutiny.Session#close()}.
*
* @param tenantId the id of the tenant
*
* @see Mutiny.SessionFactory#withSession(String, Function)
* @see Mutiny.SessionFactory#openSession(String)
*/
Mutiny.Session newSession(String tenantId);

/**
* Obtain a {@link Mutiny.StatelessSession reactive stateless session}.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link Mutiny.StatelessSession} needs to access the
* database.
* <p>
* The client must explicitly close the session by calling
* {@link Mutiny.StatelessSession#close()}.
*
* @see Mutiny.SessionFactory#openStatelessSession()
* @see Mutiny.SessionFactory#withStatelessSession(Function)
*/
Mutiny.StatelessSession newStatelessSession();

/**
* Obtain a {@link Mutiny.StatelessSession reactive stateless session}.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link Mutiny.StatelessSession} needs to access the
* database.
* <p>
* The client must explicitly close the session by calling
* {@link Mutiny.StatelessSession#close()}.
*
* @param tenantId the id of the tenant
*
* @see Mutiny.SessionFactory#openStatelessSession(String)
* @see Mutiny.SessionFactory#withSession(String, Function)
*/
Mutiny.StatelessSession newStatelessSession(String tenantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ interface StatelessSession extends Closeable {
*
* @param association a lazy-loaded association
*
* @return the fetched association, via a {@code CompletionStage}
* @return the fetched association, via a {@code Uni}
*
* @see org.hibernate.Hibernate#initialize(Object)
*/
Expand Down Expand Up @@ -1516,26 +1516,24 @@ interface Transaction {
interface SessionFactory extends AutoCloseable {

/**
* Obtain a new {@link Session reactive session}, the main
* Obtain a new {@link Session reactive session} {@link Uni}, the main
* interaction point between the user's program and Hibernate
* Reactive.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link Session} needs to access the database.
* When the {@link Uni} completes successfully it returns a newly created session.
* <p>
* The client must explicitly close the session by calling
* {@link Session#close()}.
*
* @see #withSession(Function)
*/
Session openSession();
Uni<Session> openSession();

/**
* Obtain a new {@link Session reactive session} for a
* Obtain a new {@link Session reactive session} {@link Uni} for a
* specified tenant.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link Session} needs to access the database.
* When the {@link Uni} completes successfully it returns a newly created session.
* <p>
* The client must explicitly close the session by calling
* {@link Session#close()}.
Expand All @@ -1544,33 +1542,36 @@ interface SessionFactory extends AutoCloseable {
*
* @see #withSession(Function)
*/
Session openSession(String tenantId);
Uni<Session> openSession(String tenantId);

/**
* Obtain a {@link StatelessSession reactive stateless session}.
* Obtain a {@link StatelessSession reactive stateless session}
*{@link Uni}.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link StatelessSession} needs to access the
* database.
* When the {@link Uni} completes successfully it returns a newly created session.
* <p>
* The client must explicitly close the session by calling
* {@link StatelessSession#close()}.
*
* @see #withStatelessSession(Function)
*/
StatelessSession openStatelessSession();
Uni<StatelessSession> openStatelessSession();

/**
* Obtain a {@link StatelessSession reactive stateless session}.
* Obtain a {@link StatelessSession reactive stateless session}
* {@link Uni}.
* <p>
* The underlying database connection is obtained lazily when
* the returned {@link StatelessSession} needs to access the
* database.
* When the {@link Uni} completes successfully it returns a newly created session.
* <p>
* The client must explicitly close the session by calling
* {@link StatelessSession#close()}.
*
* @param tenantId the id of the tenant
*
* @see #withStatelessSession(String, Function)
*/
StatelessSession openStatelessSession(String tenantId);
Uni<StatelessSession> openStatelessSession(String tenantId);


/**
* Perform work using a {@link Session reactive session}.
Expand Down Expand Up @@ -1615,6 +1616,14 @@ interface SessionFactory extends AutoCloseable {
* Perform work using a {@link Session reactive session} within an
* associated {@link Transaction transaction}.
* <p>
* <il>
* <li>If there is already a session associated with the
* current reactive stream, then the work will be executed using that
* session.
* <li>Otherwise, if there is no session associated with the
* current stream, a new stateless session will be created.
* </il>
* <p>
* The session will be {@link Session#flush() flushed} and closed
* automatically, and the transaction committed automatically.
*
Expand All @@ -1630,6 +1639,14 @@ interface SessionFactory extends AutoCloseable {
* Perform work using a {@link StatelessSession reactive session} within an
* associated {@link Transaction transaction}.
* <p>
* <il>
* <li>If there is already a stateless session associated with the
* current reactive stream, then the work will be executed using that
* session.
* <li>Otherwise, if there is no stateless session associated with the
* current stream, a new stateless session will be created.
* </il>
* <p>
* The session will be closed automatically and the transaction committed automatically.
*
* @param work a function which accepts the stateless session and returns
Expand Down Expand Up @@ -1663,10 +1680,10 @@ interface SessionFactory extends AutoCloseable {
* <p>
* <il>
* <li>If there is already a stateless session associated with the
* current reactive stream, then the work will be executed using that
* current reactive stream and given tenant id, then the work will be executed using that
* session.
* <li>Otherwise, if there is no stateless session associated with the
* current stream, a new stateless session will be created.
* current stream and given tenant id, a new stateless session will be created.
* </il>
* <p>
* The session will be closed automatically.
Expand All @@ -1681,6 +1698,14 @@ interface SessionFactory extends AutoCloseable {
* Perform work using a {@link Session reactive session} for a
* specified tenant within an associated {@link Transaction transaction}.
* <p>
* <il>
* <li>If there is already a session associated with the
* current reactive stream and given tenant id, then the work will be executed using that
* session.
* <li>Otherwise, if there is no session associated with the
* current stream and given tenant id, a new stateless session will be created.
* </il>
* <p>
* The session will be {@link Session#flush() flushed} and closed
* automatically, and the transaction committed automatically.
*
Expand All @@ -1697,6 +1722,14 @@ interface SessionFactory extends AutoCloseable {
* Perform work using a {@link StatelessSession reactive session} for a
* specified tenant within an associated {@link Transaction transaction}.
* <p>
* <il>
* <li>If there is already a stateless session associated with the
* current reactive stream and given tenant id, then the work will be executed using that
* session.
* <li>Otherwise, if there is no stateless session associated with the
* current stream and given tenant id, a new stateless session will be created.
* </il>
* <p>
* The session will be closed automatically and the transaction committed automatically.
*
* @param tenantId the id of the tenant
Expand Down
Loading