Removed deprecated Interceptor.onPrepareStatement(String sql)

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2022-03-07 22:47:33 +01:00 committed by Steve Ebersole
parent 13527366c9
commit b1ec3ab78b
7 changed files with 45 additions and 42 deletions

View File

@ -511,17 +511,4 @@ public interface Interceptor {
* @param tx The Hibernate transaction facade object
*/
default void afterTransactionCompletion(Transaction tx) {}
/**
* Called when sql string is being prepared.
* @param sql sql to be prepared
* @return original or modified sql
*
* @deprecated Supply a {@link org.hibernate.resource.jdbc.spi.StatementInspector} instead, if you wish
* to inspect and alter SQL statements.
*/
@Deprecated
default String onPrepareStatement(String sql) {
return sql;
}
}

View File

@ -90,6 +90,7 @@ import org.hibernate.query.sqm.tree.select.SqmQueryGroup;
import org.hibernate.query.sqm.tree.select.SqmQuerySpec;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
import org.hibernate.resource.jdbc.internal.EmptyStatementInspector;
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
@ -269,11 +270,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
}
private StatementInspector interpret(StatementInspector statementInspector) {
return statementInspector == null
// If there is no StatementInspector specified, map to the call
// to the (deprecated) Interceptor#onPrepareStatement method
? interceptor::onPrepareStatement
: statementInspector;
return statementInspector == null ? EmptyStatementInspector.INSTANCE : statementInspector;
}
@Override

View File

@ -0,0 +1,26 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.resource.jdbc.internal;
import org.hibernate.resource.jdbc.spi.StatementInspector;
/**
* @author Jan Schatteman
*/
public class EmptyStatementInspector implements StatementInspector {
/**
* The singleton reference.
*/
public static final StatementInspector INSTANCE = new EmptyStatementInspector();
@Override
public String inspect(String sql) {
return sql;
}
protected EmptyStatementInspector() {}
}

View File

@ -26,6 +26,8 @@ import org.hibernate.TransactionException;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.resource.jdbc.internal.EmptyStatementInspector;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.type.Type;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
@ -316,9 +318,9 @@ public class InterceptorTest extends BaseCoreFunctionalTestCase {
expectedSQLs.add( "select" );
expectedSQLs.add( "delete" );
final Interceptor interceptor = new EmptyInterceptor() {
final StatementInspector statementInspector = new EmptyStatementInspector() {
@Override
public String onPrepareStatement(String sql) {
public String inspect(String sql) {
assertNotNull( sql );
String expectedSql = expectedSQLs.poll().toLowerCase( Locale.ROOT );
assertTrue(
@ -329,14 +331,14 @@ public class InterceptorTest extends BaseCoreFunctionalTestCase {
}
};
Session s = openSession( interceptor );
Session s = sessionFactory().withOptions().statementInspector( statementInspector ).openSession();
Transaction t = s.beginTransaction();
User u = new User( "Lukasz", "Antoniak" );
s.persist( u );
t.commit();
s.close();
s = openSession( interceptor );
s = sessionFactory().withOptions().statementInspector( statementInspector ).openSession();
t = s.beginTransaction();
s.get( User.class, "Lukasz" );
s.createQuery( "from User u" ).list();
@ -344,13 +346,13 @@ public class InterceptorTest extends BaseCoreFunctionalTestCase {
s.close();
u.setPassword( "Kinga" );
s = openSession( interceptor );
s = sessionFactory().withOptions().statementInspector( statementInspector ).openSession();
t = s.beginTransaction();
s.merge( u );
t.commit();
s.close();
s = openSession( interceptor );
s = sessionFactory().withOptions().statementInspector( statementInspector ).openSession();
t = s.beginTransaction();
s.delete( u );
t.commit();
@ -360,14 +362,14 @@ public class InterceptorTest extends BaseCoreFunctionalTestCase {
}
public void testPrepareStatementFaultIntercept() {
final Interceptor interceptor = new EmptyInterceptor() {
final StatementInspector statementInspector = new EmptyStatementInspector() {
@Override
public String onPrepareStatement(String sql) {
public String inspect(String sql) {
return null;
}
};
Session s = openSession( interceptor );
Session s = sessionFactory().withOptions().statementInspector( statementInspector ).openSession();
try {
Transaction t = s.beginTransaction();

View File

@ -91,10 +91,6 @@ public class DocumentInterceptor implements Interceptor {
public void afterTransactionCompletion(Transaction tx) {}
public void beforeTransactionCompletion(Transaction tx) {}
public String onPrepareStatement(String sql) {
return sql;
}
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {}
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {}
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {}

View File

@ -9,12 +9,12 @@ package org.hibernate.orm.test.manytomany.batchload;
import java.util.List;
import java.util.Locale;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Hibernate;
import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.resource.jdbc.internal.EmptyStatementInspector;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.stat.CollectionStatistics;
import org.hibernate.testing.orm.junit.DomainModel;
@ -98,9 +98,9 @@ public class BatchedManyToManyTest {
CollectionStatistics groupUserStats = sessionFactory.getStatistics()
.getCollectionStatistics( Group.class.getName() + ".users" );
Interceptor testingInterceptor = new EmptyInterceptor() {
final StatementInspector statementInspector = new EmptyStatementInspector() {
@Override
public String onPrepareStatement(String sql) {
public String inspect(String sql) {
// ugh, this is the best way I could come up with to assert this.
// unfortunately, this is highly dependent on the dialect and its
// outer join fragment. But at least this wil fail on the majority
@ -109,13 +109,13 @@ public class BatchedManyToManyTest {
sql.toLowerCase( Locale.ROOT ).contains( "left join" ),
"batch load of many-to-many should use inner join"
);
return super.onPrepareStatement( sql );
return super.inspect( sql );
}
};
try (final Session session = scope.getSessionFactory()
.withOptions()
.interceptor( testingInterceptor )
.statementInspector( statementInspector )
.openSession()) {
session.getTransaction().begin();
try {
@ -143,5 +143,4 @@ public class BatchedManyToManyTest {
}
}
}
}

View File

@ -107,10 +107,6 @@ public class DocumentInterceptor implements Interceptor {
public void beforeTransactionCompletion(Transaction tx) {
}
public String onPrepareStatement(String sql) {
return sql;
}
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
}