Removed deprecated SessionFactoryOptions.getStatelessInterceptorImplementor()

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2022-03-08 22:15:14 +01:00 committed by Steve Ebersole
parent 2244ab8e61
commit 4b5d3e645b
5 changed files with 13 additions and 52 deletions

View File

@ -883,11 +883,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
return interceptor == null ? EmptyInterceptor.INSTANCE : interceptor;
}
@Override
public Class<? extends Interceptor> getStatelessInterceptorImplementor() {
return statelessInterceptorClass;
}
@Override
public Supplier<? extends Interceptor> getStatelessInterceptorImplementorSupplier() {
return statelessInterceptorSupplier;
@ -1251,6 +1246,16 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
public void applyStatelessInterceptor(Class<? extends Interceptor> statelessInterceptorClass) {
this.statelessInterceptorClass = statelessInterceptorClass;
this.applyStatelessInterceptorSupplier(
() -> {
try {
return statelessInterceptorClass.newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
throw new HibernateException( String.format( "Could not supply stateless Interceptor of class %s", statelessInterceptorClass.getName()), e );
}
}
);
}
public void applyStatelessInterceptorSupplier(Supplier<? extends Interceptor> statelessInterceptorSupplier) {

View File

@ -10,7 +10,6 @@ import java.util.Map;
import java.util.TimeZone;
import java.util.function.Supplier;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.CustomEntityDirtinessStrategy;
import org.hibernate.EntityNameResolver;
import org.hibernate.Interceptor;
@ -348,11 +347,6 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
return delegate.isPreferUserTransaction();
}
@Override
public Class<? extends Interceptor> getStatelessInterceptorImplementor() {
return delegate.getStatelessInterceptorImplementor();
}
@Override
public Supplier<? extends Interceptor> getStatelessInterceptorImplementorSupplier() {
return delegate.getStatelessInterceptorImplementorSupplier();

View File

@ -11,7 +11,6 @@ import java.util.function.Supplier;
import org.hibernate.CustomEntityDirtinessStrategy;
import org.hibernate.EntityNameResolver;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.TimeZoneStorageStrategy;
@ -115,26 +114,8 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
* Get the interceptor to use by default for all sessions opened from this factory.
*
* @return The interceptor to use factory wide. May be {@code null}
* @deprecated use {@link #getStatelessInterceptorImplementorSupplier()} instead.
*/
@Deprecated
Class<? extends Interceptor> getStatelessInterceptorImplementor();
/**
* Get the interceptor to use by default for all sessions opened from this factory.
*
* @return The interceptor to use factory wide. May be {@code null}
*/
default Supplier<? extends Interceptor> getStatelessInterceptorImplementorSupplier() {
return () -> {
try {
return getStatelessInterceptorImplementor().newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
throw new HibernateException( "Could not supply session-scoped SessionFactory Interceptor", e );
}
};
}
Supplier<? extends Interceptor> getStatelessInterceptorImplementorSupplier();
StatementInspector getStatementInspector();

View File

@ -1117,26 +1117,8 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
}
// then check the Session-scoped interceptor prototype
final Class<? extends Interceptor> statelessInterceptorImplementor = options.getStatelessInterceptorImplementor();
final Supplier<? extends Interceptor> statelessInterceptorImplementorSupplier = options.getStatelessInterceptorImplementorSupplier();
if ( statelessInterceptorImplementor != null && statelessInterceptorImplementorSupplier != null ) {
throw new HibernateException(
"A session scoped interceptor class or supplier are allowed, but not both!" );
}
else if ( statelessInterceptorImplementor != null ) {
try {
/*
* We could remove the getStatelessInterceptorImplementor method and use just the getStatelessInterceptorImplementorSupplier
* since it can cover both cases when the user has given a Supplier<? extends Interceptor> or just the
* Class<? extends Interceptor>, in which case, we simply instantiate the Interceptor when calling the Supplier.
*/
return statelessInterceptorImplementor.newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
throw new HibernateException( "Could not supply session-scoped SessionFactory Interceptor", e );
}
}
else if ( statelessInterceptorImplementorSupplier != null ) {
if ( statelessInterceptorImplementorSupplier != null ) {
return statelessInterceptorImplementorSupplier.get();
}

View File

@ -18,7 +18,6 @@ import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.Environment;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.orm.test.jpa.Distributor;
@ -169,7 +168,7 @@ public class InterceptorTest {
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
sessionFactoryBuilder.applyStatelessInterceptor( LocalExceptionInterceptor.class );
sessionFactoryBuilder.applyStatelessInterceptor( () -> new LocalExceptionInterceptor() );
sessionFactory = sessionFactoryBuilder.build();
final SessionFactory sessionFactoryInstance = sessionFactory;