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
* @deprecated Use {@link #tenantIdentifier(Object)} instead
*/
@Deprecated(forRemoval = true)
@Deprecated(since = "6.4", forRemoval = true)
SessionBuilder tenantIdentifier(String tenantIdentifier);
/**

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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<Integer> hashCode(Type type, Object 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.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() );

View File

@ -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<? extends Interceptor> statelessInterceptorImplementorSupplier = options.getStatelessInterceptorImplementorSupplier();
final Supplier<? extends Interceptor> 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<Object> currentTenantIdentifierResolver = sessionFactory.getCurrentTenantIdentifierResolver();
final CurrentTenantIdentifierResolver<Object> 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 );

View File

@ -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() );