HHH-17872 Make sure that JdbcServicesImpl does not return a null SqlExceptionHelper
This commit is contained in:
parent
234b24c922
commit
d3357fe719
|
@ -13,10 +13,15 @@ import jakarta.transaction.TransactionManager;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.JDBCException;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||||
|
import org.hibernate.exception.internal.SQLStateConversionDelegate;
|
||||||
|
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
|
||||||
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
||||||
import org.hibernate.resource.transaction.spi.IsolationDelegate;
|
import org.hibernate.resource.transaction.spi.IsolationDelegate;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
|
@ -35,7 +40,7 @@ public class JtaIsolationDelegate implements IsolationDelegate {
|
||||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JtaIsolationDelegate.class );
|
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JtaIsolationDelegate.class );
|
||||||
|
|
||||||
private final JdbcConnectionAccess connectionAccess;
|
private final JdbcConnectionAccess connectionAccess;
|
||||||
private final SqlExceptionHelper sqlExceptionHelper;
|
private final BiFunction<SQLException, String, JDBCException> sqlExceptionConverter;
|
||||||
private final TransactionManager transactionManager;
|
private final TransactionManager transactionManager;
|
||||||
|
|
||||||
public JtaIsolationDelegate(TransactionCoordinatorOwner transactionCoordinatorOwner, TransactionManager transactionManager) {
|
public JtaIsolationDelegate(TransactionCoordinatorOwner transactionCoordinatorOwner, TransactionManager transactionManager) {
|
||||||
|
@ -52,19 +57,30 @@ public class JtaIsolationDelegate implements IsolationDelegate {
|
||||||
|
|
||||||
public JtaIsolationDelegate(
|
public JtaIsolationDelegate(
|
||||||
JdbcConnectionAccess connectionAccess,
|
JdbcConnectionAccess connectionAccess,
|
||||||
SqlExceptionHelper sqlExceptionHelper,
|
SqlExceptionHelper sqlExceptionConverter,
|
||||||
TransactionManager transactionManager) {
|
TransactionManager transactionManager) {
|
||||||
this.connectionAccess = connectionAccess;
|
this.connectionAccess = connectionAccess;
|
||||||
this.sqlExceptionHelper = sqlExceptionHelper;
|
|
||||||
this.transactionManager = transactionManager;
|
this.transactionManager = transactionManager;
|
||||||
|
if ( sqlExceptionConverter != null ) {
|
||||||
|
this.sqlExceptionConverter = sqlExceptionConverter::convert;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SQLStateConversionDelegate delegate = new SQLStateConversionDelegate(
|
||||||
|
() -> {
|
||||||
|
throw new AssertionFailure(
|
||||||
|
"Unexpected call to ConversionContext.getViolatedConstraintNameExtractor" );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.sqlExceptionConverter = (sqlException, message) -> delegate.convert( sqlException, message, null );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JdbcConnectionAccess jdbcConnectionAccess() {
|
private JdbcConnectionAccess jdbcConnectionAccess() {
|
||||||
return connectionAccess;
|
return connectionAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SqlExceptionHelper sqlExceptionHelper() {
|
private BiFunction<SQLException, String, JDBCException> sqlExceptionConverter() {
|
||||||
return sqlExceptionHelper;
|
return sqlExceptionConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -183,7 +199,7 @@ public class JtaIsolationDelegate implements IsolationDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (SQLException e) {
|
||||||
throw sqlExceptionHelper().convert( e, "unable to obtain isolated JDBC connection" );
|
throw sqlExceptionConverter().apply( e, "unable to obtain isolated JDBC connection" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue