From 64622858ab4cae7bb87ba3a1d4f77adf5647d86b Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 29 Aug 2024 13:04:38 +0200 Subject: [PATCH] add some @Serial annotations as recommended by IntelliJ improve a @Deprecated annotation Signed-off-by: Gavin King --- .../main/java/org/hibernate/SessionBuilder.java | 2 +- .../internal/ThreadLocalSessionContext.java | 3 +++ .../spi/AbstractDelegatingSessionBuilder.java | 2 +- .../AbstractDelegatingSharedSessionBuilder.java | 2 +- .../java/org/hibernate/engine/spi/TypedValue.java | 6 ++++-- .../internal/AbstractSharedSessionContract.java | 3 +++ .../hibernate/internal/SessionFactoryImpl.java | 15 +++++++++++---- .../java/org/hibernate/internal/SessionImpl.java | 5 ++++- 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java b/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java index 6a83d1c7bf..5ba0f9d950 100644 --- a/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/SessionBuilder.java @@ -116,7 +116,7 @@ public interface SessionBuilder { * @return {@code this}, for method chaining * @deprecated Use {@link #tenantIdentifier(Object)} instead */ - @Deprecated(forRemoval = true) + @Deprecated(since = "6.4", forRemoval = true) SessionBuilder tenantIdentifier(String tenantIdentifier); /** diff --git a/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java b/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java index 71de16441d..45df8088d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java +++ b/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java @@ -9,6 +9,7 @@ package org.hibernate.context.internal; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.Serial; import java.io.Serializable; import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationHandler; @@ -364,6 +365,7 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext { // serialization ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + @Serial private void writeObject(ObjectOutputStream oos) throws IOException { // if a ThreadLocalSessionContext-bound session happens to get // serialized, to be completely correct, we need to make sure @@ -374,6 +376,7 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext { } } + @Serial private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { // on the inverse, it makes sense that if a ThreadLocalSessionContext- // bound session then gets deserialized to go ahead and re-bind it to diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSessionBuilder.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSessionBuilder.java index f82bbe4299..42f2765e3a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSessionBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSessionBuilder.java @@ -81,7 +81,7 @@ public abstract class AbstractDelegatingSessionBuilder implements SessionBuilder return this; } - @Override + @Override @Deprecated(forRemoval = true) public SessionBuilder tenantIdentifier(String tenantIdentifier) { delegate.tenantIdentifier( tenantIdentifier ); return this; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSharedSessionBuilder.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSharedSessionBuilder.java index 70d5e5c589..7c1577269b 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSharedSessionBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/AbstractDelegatingSharedSessionBuilder.java @@ -117,7 +117,7 @@ public abstract class AbstractDelegatingSharedSessionBuilder implements SharedSe return this; } - @Override + @Override @Deprecated(forRemoval = true) public SharedSessionBuilder tenantIdentifier(String tenantIdentifier) { delegate.tenantIdentifier( tenantIdentifier ); return this; diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/TypedValue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/TypedValue.java index a172f62714..0a0db20b6c 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/TypedValue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/TypedValue.java @@ -8,6 +8,7 @@ package org.hibernate.engine.spi; import java.io.IOException; import java.io.ObjectInputStream; +import java.io.Serial; import java.io.Serializable; import org.hibernate.internal.util.ValueHolder; @@ -58,16 +59,17 @@ public final class TypedValue implements Serializable { } final TypedValue that = (TypedValue) other; return type.getReturnedClass() == that.type.getReturnedClass() - && type.isEqual( that.value, value ); + && type.isEqual( that.value, value ); } + @Serial private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); this.hashcode = hashCode(type, value); } - private static ValueHolder hashCode(Type type, Object value) { + private static ValueHolder hashCode(Type type, Object value) { return new ValueHolder<>( () -> value == null ? 0 : type.getHashCode( value ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 6788b47789..60083266d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -9,6 +9,7 @@ package org.hibernate.internal; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.Serial; import java.sql.SQLException; import java.util.List; import java.util.Locale; @@ -1566,6 +1567,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont getLoadQueryInfluencers().disableFilter( filterName ); } + @Serial private void writeObject(ObjectOutputStream oos) throws IOException { if ( log.isTraceEnabled() ) { log.trace( "Serializing " + getClass().getSimpleName() + " [" ); @@ -1600,6 +1602,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont jdbcCoordinator.serialize( oos ); } + @Serial private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException { if ( log.isTraceEnabled() ) { log.trace( "Deserializing " + getClass().getSimpleName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index fb70eba506..84eed82cf0 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.Serial; import java.sql.Connection; import java.util.ArrayList; import java.util.Collections; @@ -1284,7 +1285,8 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im } // then check the Session-scoped interceptor prototype - final Supplier statelessInterceptorImplementorSupplier = options.getStatelessInterceptorImplementorSupplier(); + final Supplier statelessInterceptorImplementorSupplier = + options.getStatelessInterceptorImplementorSupplier(); if ( statelessInterceptorImplementorSupplier != null ) { return statelessInterceptorImplementorSupplier.get(); } @@ -1329,7 +1331,8 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im this.defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize(); this.subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled(); - final CurrentTenantIdentifierResolver currentTenantIdentifierResolver = sessionFactory.getCurrentTenantIdentifierResolver(); + final CurrentTenantIdentifierResolver currentTenantIdentifierResolver = + sessionFactory.getCurrentTenantIdentifierResolver(); if ( currentTenantIdentifierResolver != null ) { tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier(); } @@ -1485,7 +1488,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im return this; } - @Override + @Override @Deprecated(forRemoval = true) public SessionBuilderImpl tenantIdentifier(String tenantIdentifier) { this.tenantIdentifier = tenantIdentifier; return this; @@ -1677,6 +1680,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im * * @throws IOException Can be thrown by the stream */ + @Serial private void writeObject(ObjectOutputStream out) throws IOException { if ( LOG.isDebugEnabled() ) { LOG.debugf( "Serializing: %s", getUuid() ); @@ -1693,6 +1697,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im * @throws IOException Can be thrown by the stream * @throws ClassNotFoundException Again, can be thrown by the stream */ + @Serial private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { LOG.trace( "Deserializing" ); in.defaultReadObject(); @@ -1712,12 +1717,14 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im * * @throws InvalidObjectException Thrown if we could not resolve the factory by uuid/name. */ + @Serial private Object readResolve() throws InvalidObjectException { LOG.trace( "Resolving serialized SessionFactory" ); return locateSessionFactoryOnDeserialization( getUuid(), name ); } - private static SessionFactory locateSessionFactoryOnDeserialization(String uuid, String name) throws InvalidObjectException{ + private static SessionFactory locateSessionFactoryOnDeserialization(String uuid, String name) + throws InvalidObjectException{ final SessionFactory uuidResult = SessionFactoryRegistry.INSTANCE.getSessionFactory( uuid ); if ( uuidResult != null ) { LOG.debugf( "Resolved SessionFactory by UUID [%s]", uuid ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 53158fe24e..3487b32e5d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Reader; +import java.io.Serial; import java.io.Serializable; import java.sql.Blob; import java.sql.Clob; @@ -1986,7 +1987,7 @@ public class SessionImpl // SharedSessionBuilder - @Override @Deprecated + @Override @Deprecated(forRemoval = true) public SharedSessionBuilderImpl tenantIdentifier(String tenantIdentifier) { super.tenantIdentifier( tenantIdentifier ); tenantIdChanged = true; @@ -2865,6 +2866,7 @@ public class SessionImpl * * @throws IOException Indicates a general IO stream exception */ + @Serial private void writeObject(ObjectOutputStream oos) throws IOException { if ( log.isTraceEnabled() ) { log.tracef( "Serializing Session [%s]", getSessionIdentifier() ); @@ -2886,6 +2888,7 @@ public class SessionImpl * @throws IOException Indicates a general IO stream exception * @throws ClassNotFoundException Indicates a class resolution issue */ + @Serial private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException { if ( log.isTraceEnabled() ) { log.tracef( "Deserializing Session [%s]", getSessionIdentifier() );