Skip to content

Commit 6462285

Browse files
committed
add some @serial annotations as recommended by IntelliJ
improve a @deprecated annotation Signed-off-by: Gavin King <[email protected]>
1 parent 11b11c0 commit 6462285

File tree

8 files changed

+28
-10
lines changed

8 files changed

+28
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public interface SessionBuilder {
116116
* @return {@code this}, for method chaining
117117
* @deprecated Use {@link #tenantIdentifier(Object)} instead
118118
*/
119-
@Deprecated(forRemoval = true)
119+
@Deprecated(since = "6.4", forRemoval = true)
120120
SessionBuilder tenantIdentifier(String tenantIdentifier);
121121

122122
/**

hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.IOException;
1010
import java.io.ObjectInputStream;
1111
import java.io.ObjectOutputStream;
12+
import java.io.Serial;
1213
import java.io.Serializable;
1314
import java.lang.invoke.MethodHandles;
1415
import java.lang.reflect.InvocationHandler;
@@ -364,6 +365,7 @@ public void setWrapped(Session wrapped) {
364365

365366
// serialization ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366367

368+
@Serial
367369
private void writeObject(ObjectOutputStream oos) throws IOException {
368370
// if a ThreadLocalSessionContext-bound session happens to get
369371
// serialized, to be completely correct, we need to make sure
@@ -374,6 +376,7 @@ private void writeObject(ObjectOutputStream oos) throws IOException {
374376
}
375377
}
376378

379+
@Serial
377380
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
378381
// on the inverse, it makes sense that if a ThreadLocalSessionContext-
379382
// bound session then gets deserialized to go ahead and re-bind it to

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public SessionBuilder autoClose(boolean autoClose) {
8181
return this;
8282
}
8383

84-
@Override
84+
@Override @Deprecated(forRemoval = true)
8585
public SessionBuilder tenantIdentifier(String tenantIdentifier) {
8686
delegate.tenantIdentifier( tenantIdentifier );
8787
return this;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public SharedSessionBuilder autoClose(boolean autoClose) {
117117
return this;
118118
}
119119

120-
@Override
120+
@Override @Deprecated(forRemoval = true)
121121
public SharedSessionBuilder tenantIdentifier(String tenantIdentifier) {
122122
delegate.tenantIdentifier( tenantIdentifier );
123123
return this;

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

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

99
import java.io.IOException;
1010
import java.io.ObjectInputStream;
11+
import java.io.Serial;
1112
import java.io.Serializable;
1213

1314
import org.hibernate.internal.util.ValueHolder;
@@ -58,16 +59,17 @@ public boolean equals(@Nullable Object other) {
5859
}
5960
final TypedValue that = (TypedValue) other;
6061
return type.getReturnedClass() == that.type.getReturnedClass()
61-
&& type.isEqual( that.value, value );
62+
&& type.isEqual( that.value, value );
6263
}
6364

65+
@Serial
6466
private void readObject(ObjectInputStream ois)
6567
throws ClassNotFoundException, IOException {
6668
ois.defaultReadObject();
6769
this.hashcode = hashCode(type, value);
6870
}
6971

70-
private static ValueHolder hashCode(Type type, Object value) {
72+
private static ValueHolder<Integer> hashCode(Type type, Object value) {
7173
return new ValueHolder<>( () -> value == null ? 0 : type.getHashCode( value ) );
7274
}
7375
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.IOException;
1010
import java.io.ObjectInputStream;
1111
import java.io.ObjectOutputStream;
12+
import java.io.Serial;
1213
import java.sql.SQLException;
1314
import java.util.List;
1415
import java.util.Locale;
@@ -1566,6 +1567,7 @@ public void disableFilter(String filterName) {
15661567
getLoadQueryInfluencers().disableFilter( filterName );
15671568
}
15681569

1570+
@Serial
15691571
private void writeObject(ObjectOutputStream oos) throws IOException {
15701572
if ( log.isTraceEnabled() ) {
15711573
log.trace( "Serializing " + getClass().getSimpleName() + " [" );
@@ -1600,6 +1602,7 @@ private void writeObject(ObjectOutputStream oos) throws IOException {
16001602
jdbcCoordinator.serialize( oos );
16011603
}
16021604

1605+
@Serial
16031606
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
16041607
if ( log.isTraceEnabled() ) {
16051608
log.trace( "Deserializing " + getClass().getSimpleName() );

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.InvalidObjectException;
1111
import java.io.ObjectInputStream;
1212
import java.io.ObjectOutputStream;
13+
import java.io.Serial;
1314
import java.sql.Connection;
1415
import java.util.ArrayList;
1516
import java.util.Collections;
@@ -1284,7 +1285,8 @@ public static Interceptor configuredInterceptor(Interceptor interceptor, boolean
12841285
}
12851286

12861287
// then check the Session-scoped interceptor prototype
1287-
final Supplier<? extends Interceptor> statelessInterceptorImplementorSupplier = options.getStatelessInterceptorImplementorSupplier();
1288+
final Supplier<? extends Interceptor> statelessInterceptorImplementorSupplier =
1289+
options.getStatelessInterceptorImplementorSupplier();
12881290
if ( statelessInterceptorImplementorSupplier != null ) {
12891291
return statelessInterceptorImplementorSupplier.get();
12901292
}
@@ -1329,7 +1331,8 @@ public SessionBuilderImpl(SessionFactoryImpl sessionFactory) {
13291331
this.defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize();
13301332
this.subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled();
13311333

1332-
final CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver = sessionFactory.getCurrentTenantIdentifierResolver();
1334+
final CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver =
1335+
sessionFactory.getCurrentTenantIdentifierResolver();
13331336
if ( currentTenantIdentifierResolver != null ) {
13341337
tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier();
13351338
}
@@ -1485,7 +1488,7 @@ public SessionBuilderImpl flushMode(FlushMode flushMode) {
14851488
return this;
14861489
}
14871490

1488-
@Override
1491+
@Override @Deprecated(forRemoval = true)
14891492
public SessionBuilderImpl tenantIdentifier(String tenantIdentifier) {
14901493
this.tenantIdentifier = tenantIdentifier;
14911494
return this;
@@ -1677,6 +1680,7 @@ public JavaType<Object> getTenantIdentifierJavaType() {
16771680
*
16781681
* @throws IOException Can be thrown by the stream
16791682
*/
1683+
@Serial
16801684
private void writeObject(ObjectOutputStream out) throws IOException {
16811685
if ( LOG.isDebugEnabled() ) {
16821686
LOG.debugf( "Serializing: %s", getUuid() );
@@ -1693,6 +1697,7 @@ private void writeObject(ObjectOutputStream out) throws IOException {
16931697
* @throws IOException Can be thrown by the stream
16941698
* @throws ClassNotFoundException Again, can be thrown by the stream
16951699
*/
1700+
@Serial
16961701
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
16971702
LOG.trace( "Deserializing" );
16981703
in.defaultReadObject();
@@ -1712,12 +1717,14 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
17121717
*
17131718
* @throws InvalidObjectException Thrown if we could not resolve the factory by uuid/name.
17141719
*/
1720+
@Serial
17151721
private Object readResolve() throws InvalidObjectException {
17161722
LOG.trace( "Resolving serialized SessionFactory" );
17171723
return locateSessionFactoryOnDeserialization( getUuid(), name );
17181724
}
17191725

1720-
private static SessionFactory locateSessionFactoryOnDeserialization(String uuid, String name) throws InvalidObjectException{
1726+
private static SessionFactory locateSessionFactoryOnDeserialization(String uuid, String name)
1727+
throws InvalidObjectException{
17211728
final SessionFactory uuidResult = SessionFactoryRegistry.INSTANCE.getSessionFactory( uuid );
17221729
if ( uuidResult != null ) {
17231730
LOG.debugf( "Resolved SessionFactory by UUID [%s]", uuid );

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.ObjectInputStream;
1212
import java.io.ObjectOutputStream;
1313
import java.io.Reader;
14+
import java.io.Serial;
1415
import java.io.Serializable;
1516
import java.sql.Blob;
1617
import java.sql.Clob;
@@ -1986,7 +1987,7 @@ public SessionImpl openSession() {
19861987
// SharedSessionBuilder
19871988

19881989

1989-
@Override @Deprecated
1990+
@Override @Deprecated(forRemoval = true)
19901991
public SharedSessionBuilderImpl tenantIdentifier(String tenantIdentifier) {
19911992
super.tenantIdentifier( tenantIdentifier );
19921993
tenantIdChanged = true;
@@ -2865,6 +2866,7 @@ public Metamodel getMetamodel() {
28652866
*
28662867
* @throws IOException Indicates a general IO stream exception
28672868
*/
2869+
@Serial
28682870
private void writeObject(ObjectOutputStream oos) throws IOException {
28692871
if ( log.isTraceEnabled() ) {
28702872
log.tracef( "Serializing Session [%s]", getSessionIdentifier() );
@@ -2886,6 +2888,7 @@ private void writeObject(ObjectOutputStream oos) throws IOException {
28862888
* @throws IOException Indicates a general IO stream exception
28872889
* @throws ClassNotFoundException Indicates a class resolution issue
28882890
*/
2891+
@Serial
28892892
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
28902893
if ( log.isTraceEnabled() ) {
28912894
log.tracef( "Deserializing Session [%s]", getSessionIdentifier() );

0 commit comments

Comments
 (0)