Skip to content

Commit 696363e

Browse files
committed
HHH-19350 use UnaryOperator instead of Function
1 parent 0a0de45 commit 696363e

File tree

7 files changed

+40
-34
lines changed

7 files changed

+40
-34
lines changed

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

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

77
import java.sql.Connection;
88
import java.util.TimeZone;
9-
import java.util.function.Function;
9+
import java.util.function.UnaryOperator;
1010

1111
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
1212
import org.hibernate.resource.jdbc.spi.StatementInspector;
@@ -51,16 +51,17 @@ public interface SessionBuilder {
5151
/**
5252
* Applies the given statement inspection function to the session.
5353
*
54-
* @param statementInspector A function which accepts a SQL string,
55-
* returning a possibly-processed SQL string
56-
* to be used by Hibernate instead of the
57-
* given SQL.
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.
5859
*
5960
* @return {@code this}, for method chaining
6061
*
6162
* @since 7.0
6263
*/
63-
SessionBuilder statementInspector(Function<String,String> statementInspector);
64+
SessionBuilder statementInspector(UnaryOperator<String> operator);
6465

6566
/**
6667
* Applies the given {@link StatementInspector} to the session.
@@ -70,7 +71,7 @@ public interface SessionBuilder {
7071
* @return {@code this}, for method chaining
7172
*
7273
* @deprecated This operation exposes the SPI type {@link StatementInspector}
73-
* and is therefore a layer-breaker. Use {@link #statementInspector(Function)}
74+
* and is therefore a layer-breaker. Use {@link #statementInspector(UnaryOperator)}
7475
* instead.
7576
*/
7677
@Deprecated(since = "7.0")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java.sql.Connection;
1111
import java.util.TimeZone;
12-
import java.util.function.Function;
12+
import java.util.function.UnaryOperator;
1313

1414
/**
1515
* Specialized {@link SessionBuilder} with access to stuff from another session.
@@ -76,7 +76,7 @@ public interface SharedSessionBuilder extends SessionBuilder {
7676
SharedSessionBuilder statementInspector(StatementInspector statementInspector);
7777

7878
@Override
79-
SessionBuilder statementInspector(Function<String, String> statementInspector);
79+
SessionBuilder statementInspector(UnaryOperator<String> operator);
8080

8181
@Override @Deprecated
8282
SharedSessionBuilder connectionHandlingMode(PhysicalConnectionHandlingMode mode);

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

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

77
import java.sql.Connection;
8-
import java.util.function.Function;
8+
import java.util.function.UnaryOperator;
99

1010
import org.hibernate.resource.jdbc.spi.StatementInspector;
1111

@@ -57,18 +57,19 @@ public interface StatelessSessionBuilder {
5757
/**
5858
* Applies the given statement inspection function to the session.
5959
*
60-
* @param statementInspector A function which accepts a SQL string,
61-
* returning a possibly-processed SQL string
62-
* to be used by Hibernate instead of the
63-
* given SQL.
60+
* @param operator An operator which accepts a SQL string, returning
61+
* a processed SQL string to be used by Hibernate
62+
* instead of the given original SQL. Alternatively.
63+
* the operator may work by side effect, and simply
64+
* return the original SQL.
6465
*
6566
* @return {@code this}, for method chaining
6667
*
6768
* @apiNote This operation exposes the SPI type
6869
* {@link StatementInspector}
6970
* and is therefore a layer-breaker.
7071
*/
71-
StatelessSessionBuilder statementInspector(Function<String,String> statementInspector);
72+
StatelessSessionBuilder statementInspector(UnaryOperator<String> operator);
7273

7374
/**
7475
* Applies the given {@link StatementInspector} to the session.
@@ -78,7 +79,7 @@ public interface StatelessSessionBuilder {
7879
* @return {@code this}, for method chaining
7980
*
8081
* @deprecated This operation exposes the SPI type{@link StatementInspector}
81-
* and is therefore a layer-breaker. Use {@link #statementInspector(Function)}
82+
* and is therefore a layer-breaker. Use {@link #statementInspector(UnaryOperator)}
8283
* instead.
8384
*/
8485
@Deprecated(since = "7.0")

hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSessionBuilder.java

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

77
import java.sql.Connection;
88
import java.util.TimeZone;
9-
import java.util.function.Function;
9+
import java.util.function.UnaryOperator;
1010

1111
import org.hibernate.ConnectionAcquisitionMode;
1212
import org.hibernate.ConnectionReleaseMode;
@@ -65,8 +65,8 @@ public SessionBuilder statementInspector(StatementInspector statementInspector)
6565
}
6666

6767
@Override
68-
public SessionBuilder statementInspector(Function<String, String> statementInspector) {
69-
delegate.statementInspector( statementInspector );
68+
public SessionBuilder statementInspector(UnaryOperator<String> operator) {
69+
delegate.statementInspector( operator );
7070
return this;
7171
}
7272

hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSharedSessionBuilder.java

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

77
import java.sql.Connection;
88
import java.util.TimeZone;
9-
import java.util.function.Function;
9+
import java.util.function.UnaryOperator;
1010

1111
import org.hibernate.ConnectionAcquisitionMode;
1212
import org.hibernate.ConnectionReleaseMode;
@@ -102,8 +102,8 @@ public SharedSessionBuilder statementInspector(StatementInspector statementInspe
102102
}
103103

104104
@Override
105-
public SessionBuilder statementInspector(Function<String, String> statementInspector) {
106-
delegate.statementInspector( statementInspector );
105+
public SessionBuilder statementInspector(UnaryOperator<String> operator) {
106+
delegate.statementInspector( operator );
107107
return this;
108108
}
109109

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.function.Consumer;
2222
import java.util.function.Function;
2323
import java.util.function.Supplier;
24+
import java.util.function.UnaryOperator;
2425
import javax.naming.Reference;
2526
import javax.naming.StringRefAddr;
2627

@@ -1280,8 +1281,8 @@ public SessionBuilderImpl statementInspector(StatementInspector statementInspect
12801281
}
12811282

12821283
@Override
1283-
public SessionBuilder statementInspector(Function<String, String> statementInspector) {
1284-
this.statementInspector = statementInspector::apply;
1284+
public SessionBuilder statementInspector(UnaryOperator<String> operator) {
1285+
this.statementInspector = operator::apply;
12851286
return this;
12861287
}
12871288

@@ -1422,8 +1423,8 @@ public StatelessSessionBuilder statementInspector(StatementInspector statementIn
14221423
}
14231424

14241425
@Override
1425-
public StatelessSessionBuilder statementInspector(Function<String, String> statementInspector) {
1426-
this.statementInspector = statementInspector::apply;
1426+
public StatelessSessionBuilder statementInspector(UnaryOperator<String> operator) {
1427+
this.statementInspector = operator::apply;
14271428
return this;
14281429
}
14291430

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Map;
2323
import java.util.Set;
2424
import java.util.TimeZone;
25-
import java.util.function.Function;
25+
import java.util.function.UnaryOperator;
2626

2727
import jakarta.persistence.PessimisticLockScope;
2828
import jakarta.persistence.Timeout;
@@ -2149,20 +2149,23 @@ public SharedSessionBuilderImpl connection(Connection connection) {
21492149
return this;
21502150
}
21512151

2152+
private PhysicalConnectionHandlingMode getConnectionHandlingMode() {
2153+
return session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode();
2154+
}
2155+
21522156
@Override
21532157
@Deprecated(since = "6.0")
21542158
public SharedSessionBuilderImpl connectionReleaseMode() {
2155-
final PhysicalConnectionHandlingMode handlingMode = PhysicalConnectionHandlingMode.interpret(
2156-
ConnectionAcquisitionMode.AS_NEEDED,
2157-
session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode().getReleaseMode()
2158-
);
2159+
final PhysicalConnectionHandlingMode handlingMode =
2160+
PhysicalConnectionHandlingMode.interpret( ConnectionAcquisitionMode.AS_NEEDED,
2161+
getConnectionHandlingMode().getReleaseMode() );
21592162
connectionHandlingMode( handlingMode );
21602163
return this;
21612164
}
21622165

21632166
@Override
21642167
public SharedSessionBuilderImpl connectionHandlingMode() {
2165-
connectionHandlingMode( session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode() );
2168+
connectionHandlingMode( getConnectionHandlingMode() );
21662169
return this;
21672170
}
21682171

@@ -2233,8 +2236,8 @@ public SharedSessionBuilderImpl statementInspector(StatementInspector statementI
22332236
}
22342237

22352238
@Override
2236-
public SessionBuilder statementInspector(Function<String, String> statementInspector) {
2237-
super.statementInspector(statementInspector);
2239+
public SessionBuilder statementInspector(UnaryOperator<String> operator) {
2240+
super.statementInspector(operator);
22382241
return this;
22392242
}
22402243

0 commit comments

Comments
 (0)