Skip to content

Commit 1753cb6

Browse files
committed
HHH-19737 - Support Envers with StatelessSession
# Conflicts: # hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSharedSessionBuilder.java # hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java # hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java # Conflicts: # hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java # Conflicts: # hibernate-core/src/main/java/org/hibernate/engine/spi/ActionQueue.java # hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java # hibernate-core/src/main/java/org/hibernate/event/internal/PostUpdateEventListenerStandardImpl.java # hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java # hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java
1 parent 0eeb3d0 commit 1753cb6

File tree

132 files changed

+2113
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2113
-770
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate;
6+
7+
import java.util.function.UnaryOperator;
8+
9+
/**
10+
* Common options builders of {@linkplain Session} and {@linkplain StatelessSession}.
11+
*
12+
* @author Steve Ebersole
13+
*/
14+
public interface CommonSessionBuilderOptions {
15+
/**
16+
* Adds a specific interceptor to the session options.
17+
*
18+
* @param interceptor The interceptor to use.
19+
*
20+
* @return {@code this}, for method chaining
21+
*/
22+
CommonSessionBuilderOptions interceptor(Interceptor interceptor);
23+
24+
/**
25+
* Signifies that no {@link Interceptor} should be used.
26+
* <p>
27+
* By default, if no {@code Interceptor} is explicitly specified, the
28+
* {@code Interceptor} associated with the {@link SessionFactory} is
29+
* inherited by the new session.
30+
* <p>
31+
* Calling {@link #interceptor(Interceptor)} with null has the same effect.
32+
*
33+
* @return {@code this}, for method chaining
34+
*/
35+
CommonSessionBuilderOptions noInterceptor();
36+
37+
/**
38+
* Applies the given statement inspection function to the session.
39+
*
40+
* @param operator An operator which accepts a SQL string, returning
41+
* a processed SQL string to be used by Hibernate instead of the given
42+
* original SQL. The operator may simply return the original SQL.
43+
*
44+
* @return {@code this}, for method chaining
45+
*/
46+
CommonSessionBuilderOptions statementInspector(UnaryOperator<String> operator);
47+
48+
/**
49+
* Define the tenant identifier to be associated with the opened session.
50+
*
51+
* @param tenantIdentifier The tenant identifier.
52+
*
53+
* @return {@code this}, for method chaining
54+
*/
55+
CommonSessionBuilderOptions tenantIdentifier(Object tenantIdentifier);
56+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate;
6+
7+
import java.util.function.UnaryOperator;
8+
9+
/**
10+
* Common options for builders of {@linkplain Session} and {@linkplain StatelessSession}
11+
* which share state from an underlying {@linkplain Session} or {@linkplain StatelessSession}.
12+
*
13+
* @author Steve Ebersole
14+
*/
15+
public interface CommonSharedSessionBuilderOptions extends CommonSessionBuilderOptions {
16+
17+
/**
18+
* Signifies that the connection from the original session should be used to create the new session.
19+
*
20+
* @return {@code this}, for method chaining
21+
*/
22+
CommonSharedSessionBuilderOptions connection();
23+
24+
/**
25+
* Signifies the interceptor from the original session should be used to create the new session.
26+
*
27+
* @return {@code this}, for method chaining
28+
*/
29+
CommonSharedSessionBuilderOptions interceptor();
30+
31+
/**
32+
* Signifies that the SQL {@linkplain org.hibernate.resource.jdbc.spi.StatementInspector statement inspector}
33+
* from the original session should be used.
34+
*/
35+
CommonSharedSessionBuilderOptions statementInspector();
36+
37+
/**
38+
* Signifies that no SQL {@linkplain org.hibernate.resource.jdbc.spi.StatementInspector statement inspector}
39+
* should be used.
40+
*/
41+
CommonSharedSessionBuilderOptions noStatementInspector();
42+
43+
@Override
44+
CommonSharedSessionBuilderOptions interceptor(Interceptor interceptor);
45+
46+
@Override
47+
CommonSharedSessionBuilderOptions noInterceptor();
48+
49+
@Override
50+
CommonSharedSessionBuilderOptions statementInspector(UnaryOperator<String> operator);
51+
52+
@Override
53+
CommonSharedSessionBuilderOptions tenantIdentifier(Object tenantIdentifier);
54+
}

hibernate-core/src/main/java/org/hibernate/SessionBuilder.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,21 @@
1818
*
1919
* @see SessionFactory#withOptions()
2020
*/
21-
public interface SessionBuilder {
21+
public interface SessionBuilder extends CommonSessionBuilderOptions {
2222
/**
2323
* Opens a session with the specified options.
2424
*
2525
* @return The session
2626
*/
2727
Session openSession();
2828

29-
/**
30-
* Adds a specific interceptor to the session options.
31-
*
32-
* @param interceptor The interceptor to use.
33-
*
34-
* @return {@code this}, for method chaining
35-
*/
29+
@Override
3630
SessionBuilder interceptor(Interceptor interceptor);
3731

38-
/**
39-
* Signifies that no {@link Interceptor} should be used.
40-
* <p>
41-
* By default, if no {@code Interceptor} is explicitly specified, the
42-
* {@code Interceptor} associated with the {@link SessionFactory} is
43-
* inherited by the new {@link Session}.
44-
* <p>
45-
* Calling {@link #interceptor(Interceptor)} with null has the same effect.
46-
*
47-
* @return {@code this}, for method chaining
48-
*/
32+
@Override
4933
SessionBuilder noInterceptor();
5034

51-
/**
52-
* Applies the given statement inspection function to the session.
53-
*
54-
* @param operator An operator which accepts a SQL string, returning
55-
* a processed SQL string to be used by Hibernate
56-
* instead of the given original SQL. Alternatively.
57-
* the operator may work by side effect, and simply
58-
* return the original SQL.
59-
*
60-
* @return {@code this}, for method chaining
61-
*
62-
* @since 7.0
63-
*/
35+
@Override
6436
SessionBuilder statementInspector(UnaryOperator<String> operator);
6537

6638
/**

hibernate-core/src/main/java/org/hibernate/SharedSessionBuilder.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,12 @@
1818
*
1919
* @see Session#sessionWithOptions()
2020
*/
21-
public interface SharedSessionBuilder extends SessionBuilder {
21+
public interface SharedSessionBuilder extends SessionBuilder, CommonSharedSessionBuilderOptions {
2222

23-
/**
24-
* Signifies that the connection from the original session should be used to create the new session.
25-
*
26-
* @return {@code this}, for method chaining
27-
*/
23+
@Override
2824
SharedSessionBuilder connection();
2925

30-
/**
31-
* Signifies the interceptor from the original session should be used to create the new session.
32-
*
33-
* @return {@code this}, for method chaining
34-
*/
26+
@Override
3527
SharedSessionBuilder interceptor();
3628

3729
/**
@@ -76,7 +68,7 @@ public interface SharedSessionBuilder extends SessionBuilder {
7668
SharedSessionBuilder statementInspector(StatementInspector statementInspector);
7769

7870
@Override
79-
SessionBuilder statementInspector(UnaryOperator<String> operator);
71+
SharedSessionBuilder statementInspector(UnaryOperator<String> operator);
8072

8173
@Override @Deprecated
8274
SharedSessionBuilder connectionHandlingMode(PhysicalConnectionHandlingMode mode);

hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
* @author Steve Ebersole
2727
*/
2828
public interface SharedSessionContract extends QueryProducer, AutoCloseable, Serializable {
29+
30+
/**
31+
* Obtain a {@link StatelessSession} builder with the ability to copy certain
32+
* information from this session.
33+
*
34+
* @return the session builder
35+
*
36+
* @since 7.2
37+
*/
38+
@Incubating
39+
SharedStatelessSessionBuilder statelessWithOptions();
40+
2941
/**
3042
* Obtain the tenant identifier associated with this session, as a string.
3143
*
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate;
6+
7+
import java.util.function.UnaryOperator;
8+
9+
/**
10+
* Allows for creation of a {@linkplain StatelessSession stateless session} sharing the
11+
* underpinnings of another {@linkplain Session stateful} or {@linkplain StatelessSession stateless}
12+
* session.
13+
*
14+
* @see Session#statelessWithOptions()
15+
* @see StatelessSession#statelessWithOptions()
16+
*
17+
* @since 7.2
18+
*
19+
* @author Steve Ebersole
20+
*/
21+
@Incubating
22+
public interface SharedStatelessSessionBuilder extends CommonSharedSessionBuilderOptions {
23+
/**
24+
* Open the stateless session.
25+
*/
26+
StatelessSession open();
27+
28+
@Override
29+
SharedStatelessSessionBuilder connection();
30+
31+
@Override
32+
SharedStatelessSessionBuilder interceptor();
33+
34+
@Override
35+
SharedStatelessSessionBuilder interceptor(Interceptor interceptor);
36+
37+
@Override
38+
SharedStatelessSessionBuilder noInterceptor();
39+
40+
SharedStatelessSessionBuilder statementInspector(UnaryOperator<String> operator);
41+
42+
@Override
43+
SharedStatelessSessionBuilder statementInspector();
44+
45+
@Override
46+
SharedStatelessSessionBuilder noStatementInspector();
47+
48+
@Override
49+
SharedStatelessSessionBuilder tenantIdentifier(Object tenantIdentifier);
50+
}

hibernate-core/src/main/java/org/hibernate/action/internal/EntityIncrementVersionProcess.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package org.hibernate.action.internal;
66

77
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
8-
import org.hibernate.engine.spi.SessionImplementor;
8+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
99
import org.hibernate.internal.OptimisticLockHelper;
1010

1111
/**
@@ -33,9 +33,9 @@ public EntityIncrementVersionProcess(Object object) {
3333
* @param session The session on which the transaction is preparing to complete.
3434
*/
3535
@Override
36-
public void doBeforeTransactionCompletion(SessionImplementor session) {
36+
public void doBeforeTransactionCompletion(SharedSessionContractImplementor session) {
3737
final var entry = session.getPersistenceContext().getEntry( object );
38-
// Don't increment version for an entity that is not in the PersistenceContext;
38+
// Don't increment the version for an entity that is not in the PersistenceContext;
3939
if ( entry != null ) {
4040
OptimisticLockHelper.forceVersionIncrement( object, entry, session.asEventSource() );
4141
}

hibernate-core/src/main/java/org/hibernate/action/internal/EntityVerifyVersionProcess.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
88
import org.hibernate.dialect.lock.OptimisticEntityLockException;
9-
import org.hibernate.engine.spi.SessionImplementor;
9+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1010
import org.hibernate.pretty.MessageHelper;
1111

1212
/**
@@ -29,9 +29,9 @@ public EntityVerifyVersionProcess(Object object) {
2929
}
3030

3131
@Override
32-
public void doBeforeTransactionCompletion(SessionImplementor session) {
32+
public void doBeforeTransactionCompletion(SharedSessionContractImplementor session) {
3333
final var entry = session.getPersistenceContext().getEntry( object );
34-
// Don't check version for an entity that is not in the PersistenceContext
34+
// Don't check the version for an entity that is not in the PersistenceContext
3535
if ( entry != null ) {
3636
final Object latestVersion = entry.getPersister().getCurrentVersion( entry.getId(), session );
3737
if ( !entry.getVersion().equals( latestVersion ) ) {

hibernate-core/src/main/java/org/hibernate/action/spi/AfterTransactionCompletionProcess.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
*/
55
package org.hibernate.action.spi;
66

7-
import org.hibernate.engine.spi.SharedSessionContractImplementor;
7+
import org.hibernate.engine.spi.TransactionCompletionCallbacks;
88

99
/**
1010
* Contract representing some process that needs to occur during after transaction completion.
1111
*
1212
* @author Steve Ebersole
1313
*/
14-
public interface AfterTransactionCompletionProcess {
15-
/**
16-
* Perform whatever processing is encapsulated here after completion of the transaction.
17-
*
18-
* @param success Did the transaction complete successfully? True means it did.
19-
* @param session The session on which the transaction is completing.
20-
*/
21-
void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session);
14+
public interface AfterTransactionCompletionProcess extends TransactionCompletionCallbacks.AfterCompletionCallback {
2215
}

hibernate-core/src/main/java/org/hibernate/action/spi/BeforeTransactionCompletionProcess.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
package org.hibernate.action.spi;
66

77
import org.hibernate.engine.spi.SessionImplementor;
8+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
9+
import org.hibernate.engine.spi.TransactionCompletionCallbacks;
810

911
/**
1012
* Contract representing some process that needs to occur during before transaction completion.
1113
*
1214
* @author Steve Ebersole
1315
*/
14-
public interface BeforeTransactionCompletionProcess {
16+
public interface BeforeTransactionCompletionProcess extends TransactionCompletionCallbacks.BeforeCompletionCallback {
1517
/**
1618
* Perform whatever processing is encapsulated here before completion of the transaction.
1719
*
1820
* @param session The session on which the transaction is preparing to complete.
21+
* @deprecated Use {@linkplain #doBeforeTransactionCompletion(SharedSessionContractImplementor)} instead.
1922
*/
20-
void doBeforeTransactionCompletion(SessionImplementor session);
23+
@Deprecated(since = "7.2", forRemoval = true)
24+
default void doBeforeTransactionCompletion(SessionImplementor session) {
25+
doBeforeTransactionCompletion( (SharedSessionContractImplementor) session );
26+
}
2127
}

0 commit comments

Comments
 (0)