Skip to content

Commit ac1f872

Browse files
committed
[hibernate#950] Add new methods to the API and deprecate old ones
1 parent 6300a27 commit ac1f872

File tree

4 files changed

+157
-10
lines changed

4 files changed

+157
-10
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/Mutiny.java

+74-1
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,63 @@ interface Transaction {
15151515
*/
15161516
interface SessionFactory extends AutoCloseable {
15171517

1518+
/**
1519+
* Obtain a new {@link Session reactive session} {@link Uni}, the main
1520+
* interaction point between the user's program and Hibernate
1521+
* Reactive.
1522+
* <p>
1523+
* When the {@link Uni} completes successfully it returns a newly created session.
1524+
* <p>
1525+
* The client must explicitly close the session by calling
1526+
* {@link Session#close()}.
1527+
*
1528+
* @see #withSession(Function)
1529+
*/
1530+
Uni<Session> newSession();
1531+
1532+
/**
1533+
* Obtain a new {@link Session reactive session} {@link CompletionStage} for a
1534+
* specified tenant.
1535+
* <p>
1536+
* When the {@link Uni} completes successfully it returns a newly created session.
1537+
* <p>
1538+
* The client must explicitly close the session by calling
1539+
* {@link Session#close()}.
1540+
*
1541+
* @param tenantId the id of the tenant
1542+
*
1543+
* @see #withSession(Function)
1544+
*/
1545+
Uni<Session> newSession(String tenantId);
1546+
1547+
/**
1548+
* Obtain a {@link StatelessSession reactive stateless session}
1549+
*{@link Uni}.
1550+
* <p>
1551+
* When the {@link Uni} completes successfully it returns a newly created session.
1552+
* <p>
1553+
* The client must explicitly close the session by calling
1554+
* {@link StatelessSession#close()}.
1555+
*
1556+
* @see #withStatelessSession(Function)
1557+
*/
1558+
Uni<StatelessSession> newStatelessSession();
1559+
1560+
/**
1561+
* Obtain a {@link StatelessSession reactive stateless session}
1562+
* {@link Uni}.
1563+
* <p>
1564+
* When the {@link Uni} completes successfully it returns a newly created session.
1565+
* <p>
1566+
* The client must explicitly close the session by calling
1567+
* {@link StatelessSession#close()}.
1568+
*
1569+
* @param tenantId the id of the tenant
1570+
*
1571+
* @see #withStatelessSession(String, Function)
1572+
*/
1573+
Uni<StatelessSession> newStatelessSession(String tenantId);
1574+
15181575
/**
15191576
* Obtain a new {@link Session reactive session}, the main
15201577
* interaction point between the user's program and Hibernate
@@ -1527,7 +1584,10 @@ interface SessionFactory extends AutoCloseable {
15271584
* {@link Session#close()}.
15281585
*
15291586
* @see #withSession(Function)
1587+
* @see #newSession()
1588+
* @deprecated It will be removed before the final
15301589
*/
1590+
@Deprecated
15311591
Session openSession();
15321592

15331593
/**
@@ -1542,8 +1602,12 @@ interface SessionFactory extends AutoCloseable {
15421602
*
15431603
* @param tenantId the id of the tenant
15441604
*
1545-
* @see #withSession(Function)
1605+
* @see #withSession(String, Function)
1606+
* @see #newSession(String)
1607+
* @deprecated It will be removed before the final
1608+
*
15461609
*/
1610+
@Deprecated
15471611
Session openSession(String tenantId);
15481612

15491613
/**
@@ -1555,7 +1619,12 @@ interface SessionFactory extends AutoCloseable {
15551619
* <p>
15561620
* The client must explicitly close the session by calling
15571621
* {@link StatelessSession#close()}.
1622+
*
1623+
* @deprecated It will be removed before the final
1624+
* @see #newStatelessSession()
1625+
* @see #withStatelessSession(Function)
15581626
*/
1627+
@Deprecated
15591628
StatelessSession openStatelessSession();
15601629

15611630
/**
@@ -1569,7 +1638,11 @@ interface SessionFactory extends AutoCloseable {
15691638
* {@link StatelessSession#close()}.
15701639
*
15711640
* @param tenantId the id of the tenant
1641+
* @see #newStatelessSession(String)
1642+
* @see #withSession(String, Function)
1643+
* @deprecated Will be removed before the final
15721644
*/
1645+
@Deprecated
15731646
StatelessSession openStatelessSession(String tenantId);
15741647

15751648
/**

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinySessionFactoryImpl.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import javax.persistence.metamodel.Metamodel;
1515

1616
import org.hibernate.Cache;
17-
import org.hibernate.HibernateException;
1817
import org.hibernate.internal.SessionCreationOptions;
1918
import org.hibernate.internal.SessionFactoryImpl;
2019
import org.hibernate.reactive.common.spi.Implementor;
@@ -99,14 +98,16 @@ public Mutiny.Session openSession(String tenantId) {
9998
);
10099
}
101100

102-
Uni<Mutiny.Session> newSession() throws HibernateException {
101+
@Override
102+
public Uni<Mutiny.Session> newSession() {
103103
SessionCreationOptions options = options();
104104
return uni( () -> connection( options.getTenantIdentifier() ) )
105105
.chain( reactiveConnection -> create( reactiveConnection, () -> new ReactiveSessionImpl( delegate, options, reactiveConnection ) ) )
106106
.map( s -> new MutinySessionImpl(s, this) );
107107
}
108108

109-
Uni<Mutiny.Session> newSession(String tenantId) throws HibernateException {
109+
@Override
110+
public Uni<Mutiny.Session> newSession(String tenantId) {
110111
return uni( () -> connection( tenantId ) )
111112
.chain( reactiveConnection -> create( reactiveConnection, () -> new ReactiveSessionImpl( delegate, options( tenantId ), reactiveConnection ) ) )
112113
.map( s -> new MutinySessionImpl(s, this) );
@@ -129,21 +130,24 @@ public Mutiny.StatelessSession openStatelessSession() {
129130
);
130131
}
131132

133+
@Override
132134
public Mutiny.StatelessSession openStatelessSession(String tenantId) {
133135
return new MutinyStatelessSessionImpl(
134136
new ReactiveStatelessSessionImpl( delegate, options( tenantId ), proxyConnection( tenantId ) ),
135137
this
136138
);
137139
}
138140

139-
Uni<Mutiny.StatelessSession> newStatelessSession() throws HibernateException {
141+
@Override
142+
public Uni<Mutiny.StatelessSession> newStatelessSession() {
140143
SessionCreationOptions options = options();
141144
return uni( () -> connection( options.getTenantIdentifier() ) )
142145
.chain( reactiveConnection -> create( reactiveConnection, () -> new ReactiveStatelessSessionImpl( delegate, options, reactiveConnection ) ) )
143146
.map( s -> new MutinyStatelessSessionImpl(s, this) );
144147
}
145148

146-
Uni<Mutiny.StatelessSession> newStatelessSession(String tenantId) {
149+
@Override
150+
public Uni<Mutiny.StatelessSession> newStatelessSession(String tenantId) {
147151
return uni( () -> connection( tenantId ) )
148152
.chain( reactiveConnection -> create( reactiveConnection, () -> new ReactiveStatelessSessionImpl( delegate, options( tenantId ), reactiveConnection ) ) )
149153
.map( s -> new MutinyStatelessSessionImpl( s, this ) );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/Stage.java

+66
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,59 @@ interface Transaction {
15161516
*/
15171517
interface SessionFactory extends AutoCloseable {
15181518

1519+
/**
1520+
* Obtain a new {@link Session reactive session} {@link CompletionStage}, the main
1521+
* interaction point between the user's program and Hibernate
1522+
* Reactive.
1523+
* <p>
1524+
* When the {@link CompletionStage} completes successfully it returns a newly created session.
1525+
* <p>
1526+
* The client must explicitly close the session by calling
1527+
* {@link Mutiny.Session#close()}.
1528+
*
1529+
* @see #withSession(Function)
1530+
*/
1531+
CompletionStage<Session> newSession();
1532+
1533+
/**
1534+
* Obtain a new {@link Session reactive session} {@link CompletionStage} for a
1535+
* specified tenant.
1536+
* <p>
1537+
* When the {@link CompletionStage} completes successfully it returns a newly created session.
1538+
* <p>
1539+
* The client must explicitly close the session by calling
1540+
* {@link Session#close()}.
1541+
*
1542+
* @param tenantId the id of the tenant
1543+
*
1544+
* @see #withSession(Function)
1545+
*/
1546+
CompletionStage<Session> newSession(String tenantId);
1547+
1548+
/**
1549+
* Obtain a {@link StatelessSession reactive stateless session}
1550+
*{@link CompletionStage}.
1551+
* <p>
1552+
* When the {@link CompletionStage} completes successfully it returns a newly created session.
1553+
* <p>
1554+
* The client must explicitly close the session by calling
1555+
* {@link StatelessSession#close()}.
1556+
*/
1557+
CompletionStage<StatelessSession> newStatelessSession();
1558+
1559+
/**
1560+
* Obtain a {@link StatelessSession reactive stateless session}
1561+
* {@link CompletionStage}.
1562+
* <p>
1563+
* When the {@link CompletionStage} completes successfully it returns a newly created session.
1564+
* <p>
1565+
* The client must explicitly close the session by calling
1566+
* {@link StatelessSession#close()}.
1567+
*
1568+
* @param tenantId the id of the tenant
1569+
*/
1570+
CompletionStage<StatelessSession> newStatelessSession(String tenantId);
1571+
15191572
/**
15201573
* Obtain a new {@link Session reactive session}, the main
15211574
* interaction point between the user's program and Hibernate
@@ -1528,7 +1581,10 @@ interface SessionFactory extends AutoCloseable {
15281581
* {@link Session#close()}.
15291582
*
15301583
* @see #withSession(Function)
1584+
* @see #newSession()
1585+
* @deprecated
15311586
*/
1587+
@Deprecated
15321588
Session openSession();
15331589

15341590
/**
@@ -1544,7 +1600,10 @@ interface SessionFactory extends AutoCloseable {
15441600
* @param tenantId the id of the tenant
15451601
*
15461602
* @see #withSession(Function)
1603+
* @see #newSession(String)
1604+
* @deprecated
15471605
*/
1606+
@Deprecated
15481607
Session openSession(String tenantId);
15491608

15501609
/**
@@ -1556,7 +1615,12 @@ interface SessionFactory extends AutoCloseable {
15561615
* <p>
15571616
* The client must explicitly close the session by calling
15581617
* {@link StatelessSession#close()}.
1618+
*
1619+
* @see #newStatelessSession()
1620+
* @see #withStatelessSession(Function)
1621+
* @deprecated
15591622
*/
1623+
@Deprecated
15601624
StatelessSession openStatelessSession();
15611625

15621626
/**
@@ -1570,6 +1634,8 @@ interface SessionFactory extends AutoCloseable {
15701634
* {@link StatelessSession#close()}.
15711635
*
15721636
* @param tenantId the id of the tenant
1637+
* @see #newStatelessSession(String
1638+
* @see #withStatelessSession(String, Function)
15731639
*/
15741640
StatelessSession openStatelessSession(String tenantId);
15751641

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/impl/StageSessionFactoryImpl.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,31 @@ public Stage.StatelessSession openStatelessSession(String tenantId) {
105105
);
106106
}
107107

108-
CompletionStage<Stage.Session> newSession() {
108+
@Override
109+
public CompletionStage<Stage.Session> newSession() {
109110
SessionCreationOptions options = options();
110111
return stage( v -> connection( options.getTenantIdentifier() )
111112
.thenCompose( connection -> create( connection, () -> new ReactiveSessionImpl( delegate, options, connection ) ) )
112113
.thenApply( s -> new StageSessionImpl(s, this) ) );
113114
}
114115

115-
CompletionStage<Stage.Session> newSession(String tenantId) {
116+
@Override
117+
public CompletionStage<Stage.Session> newSession(String tenantId) {
116118
return stage( v -> connection( tenantId )
117119
.thenCompose( connection -> create( connection, () -> new ReactiveSessionImpl( delegate, options( tenantId ), connection ) ) )
118120
.thenApply( s -> new StageSessionImpl(s, this) ) );
119121
}
120122

121-
CompletionStage<Stage.StatelessSession> newStatelessSession() {
123+
@Override
124+
public CompletionStage<Stage.StatelessSession> newStatelessSession() {
122125
SessionCreationOptions options = options();
123126
return stage( v -> connection( options.getTenantIdentifier() )
124127
.thenCompose( connection -> create( connection, () -> new ReactiveStatelessSessionImpl( delegate, options, connection ) ) )
125128
.thenApply( s -> new StageStatelessSessionImpl(s, this) ) );
126129
}
127130

128-
CompletionStage<Stage.StatelessSession> newStatelessSession(String tenantId) {
131+
@Override
132+
public CompletionStage<Stage.StatelessSession> newStatelessSession(String tenantId) {
129133
return stage( v -> connection( tenantId )
130134
.thenCompose( connection -> create( connection, () -> new ReactiveStatelessSessionImpl( delegate, options( tenantId ), connection ) ) )
131135
.thenApply( s -> new StageStatelessSessionImpl( s, this ) ) );

0 commit comments

Comments
 (0)