add some @Serial annotations as recommended by IntelliJ

improve a @Deprecated annotation

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-08-29 13:04:38 +02:00
parent 11b11c02eb
commit 64622858ab
8 changed files with 28 additions and 10 deletions

View File

@ -116,7 +116,7 @@ public interface SessionBuilder {
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
* @deprecated Use {@link #tenantIdentifier(Object)} instead * @deprecated Use {@link #tenantIdentifier(Object)} instead
*/ */
@Deprecated(forRemoval = true) @Deprecated(since = "6.4", forRemoval = true)
SessionBuilder tenantIdentifier(String tenantIdentifier); SessionBuilder tenantIdentifier(String tenantIdentifier);
/** /**

View File

@ -9,6 +9,7 @@ package org.hibernate.context.internal;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
@ -364,6 +365,7 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
// serialization ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // serialization ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Serial
private void writeObject(ObjectOutputStream oos) throws IOException { private void writeObject(ObjectOutputStream oos) throws IOException {
// if a ThreadLocalSessionContext-bound session happens to get // if a ThreadLocalSessionContext-bound session happens to get
// serialized, to be completely correct, we need to make sure // 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 { private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
// on the inverse, it makes sense that if a ThreadLocalSessionContext- // on the inverse, it makes sense that if a ThreadLocalSessionContext-
// bound session then gets deserialized to go ahead and re-bind it to // bound session then gets deserialized to go ahead and re-bind it to

View File

@ -81,7 +81,7 @@ public abstract class AbstractDelegatingSessionBuilder implements SessionBuilder
return this; return this;
} }
@Override @Override @Deprecated(forRemoval = true)
public SessionBuilder tenantIdentifier(String tenantIdentifier) { public SessionBuilder tenantIdentifier(String tenantIdentifier) {
delegate.tenantIdentifier( tenantIdentifier ); delegate.tenantIdentifier( tenantIdentifier );
return this; return this;

View File

@ -117,7 +117,7 @@ public abstract class AbstractDelegatingSharedSessionBuilder implements SharedSe
return this; return this;
} }
@Override @Override @Deprecated(forRemoval = true)
public SharedSessionBuilder tenantIdentifier(String tenantIdentifier) { public SharedSessionBuilder tenantIdentifier(String tenantIdentifier) {
delegate.tenantIdentifier( tenantIdentifier ); delegate.tenantIdentifier( tenantIdentifier );
return this; return this;

View File

@ -8,6 +8,7 @@ package org.hibernate.engine.spi;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.internal.util.ValueHolder; import org.hibernate.internal.util.ValueHolder;
@ -58,16 +59,17 @@ public final class TypedValue implements Serializable {
} }
final TypedValue that = (TypedValue) other; final TypedValue that = (TypedValue) other;
return type.getReturnedClass() == that.type.getReturnedClass() return type.getReturnedClass() == that.type.getReturnedClass()
&& type.isEqual( that.value, value ); && type.isEqual( that.value, value );
} }
@Serial
private void readObject(ObjectInputStream ois) private void readObject(ObjectInputStream ois)
throws ClassNotFoundException, IOException { throws ClassNotFoundException, IOException {
ois.defaultReadObject(); ois.defaultReadObject();
this.hashcode = hashCode(type, value); this.hashcode = hashCode(type, value);
} }
private static ValueHolder hashCode(Type type, Object value) { private static ValueHolder<Integer> hashCode(Type type, Object value) {
return new ValueHolder<>( () -> value == null ? 0 : type.getHashCode( value ) ); return new ValueHolder<>( () -> value == null ? 0 : type.getHashCode( value ) );
} }
} }

View File

@ -9,6 +9,7 @@ package org.hibernate.internal;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serial;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -1566,6 +1567,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
getLoadQueryInfluencers().disableFilter( filterName ); getLoadQueryInfluencers().disableFilter( filterName );
} }
@Serial
private void writeObject(ObjectOutputStream oos) throws IOException { private void writeObject(ObjectOutputStream oos) throws IOException {
if ( log.isTraceEnabled() ) { if ( log.isTraceEnabled() ) {
log.trace( "Serializing " + getClass().getSimpleName() + " [" ); log.trace( "Serializing " + getClass().getSimpleName() + " [" );
@ -1600,6 +1602,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
jdbcCoordinator.serialize( oos ); jdbcCoordinator.serialize( oos );
} }
@Serial
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException { private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
if ( log.isTraceEnabled() ) { if ( log.isTraceEnabled() ) {
log.trace( "Deserializing " + getClass().getSimpleName() ); log.trace( "Deserializing " + getClass().getSimpleName() );

View File

@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serial;
import java.sql.Connection; import java.sql.Connection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -1284,7 +1285,8 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
} }
// then check the Session-scoped interceptor prototype // then check the Session-scoped interceptor prototype
final Supplier<? extends Interceptor> statelessInterceptorImplementorSupplier = options.getStatelessInterceptorImplementorSupplier(); final Supplier<? extends Interceptor> statelessInterceptorImplementorSupplier =
options.getStatelessInterceptorImplementorSupplier();
if ( statelessInterceptorImplementorSupplier != null ) { if ( statelessInterceptorImplementorSupplier != null ) {
return statelessInterceptorImplementorSupplier.get(); return statelessInterceptorImplementorSupplier.get();
} }
@ -1329,7 +1331,8 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
this.defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize(); this.defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize();
this.subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled(); this.subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled();
final CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver = sessionFactory.getCurrentTenantIdentifierResolver(); final CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver =
sessionFactory.getCurrentTenantIdentifierResolver();
if ( currentTenantIdentifierResolver != null ) { if ( currentTenantIdentifierResolver != null ) {
tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier(); tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier();
} }
@ -1485,7 +1488,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
return this; return this;
} }
@Override @Override @Deprecated(forRemoval = true)
public SessionBuilderImpl tenantIdentifier(String tenantIdentifier) { public SessionBuilderImpl tenantIdentifier(String tenantIdentifier) {
this.tenantIdentifier = tenantIdentifier; this.tenantIdentifier = tenantIdentifier;
return this; return this;
@ -1677,6 +1680,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
* *
* @throws IOException Can be thrown by the stream * @throws IOException Can be thrown by the stream
*/ */
@Serial
private void writeObject(ObjectOutputStream out) throws IOException { private void writeObject(ObjectOutputStream out) throws IOException {
if ( LOG.isDebugEnabled() ) { if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Serializing: %s", getUuid() ); LOG.debugf( "Serializing: %s", getUuid() );
@ -1693,6 +1697,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
* @throws IOException Can be thrown by the stream * @throws IOException Can be thrown by the stream
* @throws ClassNotFoundException Again, can be thrown by the stream * @throws ClassNotFoundException Again, can be thrown by the stream
*/ */
@Serial
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
LOG.trace( "Deserializing" ); LOG.trace( "Deserializing" );
in.defaultReadObject(); 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. * @throws InvalidObjectException Thrown if we could not resolve the factory by uuid/name.
*/ */
@Serial
private Object readResolve() throws InvalidObjectException { private Object readResolve() throws InvalidObjectException {
LOG.trace( "Resolving serialized SessionFactory" ); LOG.trace( "Resolving serialized SessionFactory" );
return locateSessionFactoryOnDeserialization( getUuid(), name ); 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 ); final SessionFactory uuidResult = SessionFactoryRegistry.INSTANCE.getSessionFactory( uuid );
if ( uuidResult != null ) { if ( uuidResult != null ) {
LOG.debugf( "Resolved SessionFactory by UUID [%s]", uuid ); LOG.debugf( "Resolved SessionFactory by UUID [%s]", uuid );

View File

@ -11,6 +11,7 @@ import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Blob; import java.sql.Blob;
import java.sql.Clob; import java.sql.Clob;
@ -1986,7 +1987,7 @@ public class SessionImpl
// SharedSessionBuilder // SharedSessionBuilder
@Override @Deprecated @Override @Deprecated(forRemoval = true)
public SharedSessionBuilderImpl tenantIdentifier(String tenantIdentifier) { public SharedSessionBuilderImpl tenantIdentifier(String tenantIdentifier) {
super.tenantIdentifier( tenantIdentifier ); super.tenantIdentifier( tenantIdentifier );
tenantIdChanged = true; tenantIdChanged = true;
@ -2865,6 +2866,7 @@ public class SessionImpl
* *
* @throws IOException Indicates a general IO stream exception * @throws IOException Indicates a general IO stream exception
*/ */
@Serial
private void writeObject(ObjectOutputStream oos) throws IOException { private void writeObject(ObjectOutputStream oos) throws IOException {
if ( log.isTraceEnabled() ) { if ( log.isTraceEnabled() ) {
log.tracef( "Serializing Session [%s]", getSessionIdentifier() ); log.tracef( "Serializing Session [%s]", getSessionIdentifier() );
@ -2886,6 +2888,7 @@ public class SessionImpl
* @throws IOException Indicates a general IO stream exception * @throws IOException Indicates a general IO stream exception
* @throws ClassNotFoundException Indicates a class resolution issue * @throws ClassNotFoundException Indicates a class resolution issue
*/ */
@Serial
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException { private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
if ( log.isTraceEnabled() ) { if ( log.isTraceEnabled() ) {
log.tracef( "Deserializing Session [%s]", getSessionIdentifier() ); log.tracef( "Deserializing Session [%s]", getSessionIdentifier() );