HHH-17506 Return exceptions instead of throwing them in SQLExceptionConversionDelegate
This commit is contained in:
parent
6168582103
commit
c931c86896
|
@ -892,11 +892,10 @@ public class DB2LegacyDialect extends Dialect {
|
||||||
@Override
|
@Override
|
||||||
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
|
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
|
||||||
return (sqlException, message, sql) -> {
|
return (sqlException, message, sql) -> {
|
||||||
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
|
|
||||||
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
||||||
|
switch ( errorCode ) {
|
||||||
if ( -952 == errorCode && "57014".equals( sqlState ) ) {
|
case -952:
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
|
@ -716,7 +716,7 @@ public class DerbyLegacyDialect extends Dialect {
|
||||||
switch ( sqlState ) {
|
switch ( sqlState ) {
|
||||||
case "40XL1":
|
case "40XL1":
|
||||||
case "40XL2":
|
case "40XL2":
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1015,13 +1015,13 @@ public class OracleLegacyDialect extends Dialect {
|
||||||
|
|
||||||
case 30006:
|
case 30006:
|
||||||
// ORA-30006: resource busy; acquire with WAIT timeout expired
|
// ORA-30006: resource busy; acquire with WAIT timeout expired
|
||||||
throw new LockTimeoutException(message, sqlException, sql);
|
return new LockTimeoutException(message, sqlException, sql);
|
||||||
case 54:
|
case 54:
|
||||||
// ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
|
// ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
|
||||||
throw new LockTimeoutException(message, sqlException, sql);
|
return new LockTimeoutException(message, sqlException, sql);
|
||||||
case 4021:
|
case 4021:
|
||||||
// ORA-04021 timeout occurred while waiting to lock object
|
// ORA-04021 timeout occurred while waiting to lock object
|
||||||
throw new LockTimeoutException(message, sqlException, sql);
|
return new LockTimeoutException(message, sqlException, sql);
|
||||||
|
|
||||||
// deadlocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// deadlocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -1036,7 +1036,7 @@ public class OracleLegacyDialect extends Dialect {
|
||||||
|
|
||||||
case 1013:
|
case 1013:
|
||||||
// ORA-01013: user requested cancel of current operation
|
// ORA-01013: user requested cancel of current operation
|
||||||
throw new QueryTimeoutException( message, sqlException, sql );
|
return new QueryTimeoutException( message, sqlException, sql );
|
||||||
|
|
||||||
// data integrity violation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// data integrity violation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -731,14 +731,25 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect {
|
||||||
}
|
}
|
||||||
return (sqlException, message, sql) -> {
|
return (sqlException, message, sql) -> {
|
||||||
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
|
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
|
||||||
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
|
||||||
if ( "HY008".equals( sqlState ) ) {
|
if ( "HY008".equals( sqlState ) ) {
|
||||||
throw new QueryTimeoutException( message, sqlException, sql );
|
return new QueryTimeoutException( message, sqlException, sql );
|
||||||
}
|
|
||||||
if ( 1222 == errorCode ) {
|
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
||||||
|
switch ( errorCode ) {
|
||||||
|
case 1222:
|
||||||
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
|
case 2627:
|
||||||
|
case 2601:
|
||||||
|
return new ConstraintViolationException(
|
||||||
|
message,
|
||||||
|
sqlException,
|
||||||
|
sql,
|
||||||
|
getViolatedConstraintNameExtractor().extractConstraintName( sqlException )
|
||||||
|
);
|
||||||
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1105,4 +1116,14 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect {
|
||||||
// public String getEnableConstraintStatement(String tableName, String name) {
|
// public String getEnableConstraintStatement(String tableName, String name) {
|
||||||
// return "alter table " + tableName + " with check check constraint " + name;
|
// return "alter table " + tableName + " with check check constraint " + name;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DmlTargetColumnQualifierSupport getDmlTargetColumnQualifierSupport() {
|
||||||
|
return DmlTargetColumnQualifierSupport.TABLE_ALIAS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsFromClauseInUpdate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -667,7 +667,7 @@ public class SybaseASELegacyDialect extends SybaseLegacyDialect {
|
||||||
switch ( sqlState ) {
|
switch ( sqlState ) {
|
||||||
case "JZ0TO":
|
case "JZ0TO":
|
||||||
case "JZ006":
|
case "JZ006":
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
case "S1000":
|
case "S1000":
|
||||||
switch ( errorCode ) {
|
switch ( errorCode ) {
|
||||||
case 515:
|
case 515:
|
||||||
|
|
|
@ -515,7 +515,7 @@ public abstract class AbstractHANADialect extends Dialect {
|
||||||
// 262 - Invalid query name
|
// 262 - Invalid query name
|
||||||
// 263 - Invalid alias name
|
// 263 - Invalid alias name
|
||||||
if ( errorCode == 257 || ( errorCode >= 259 && errorCode <= 263 ) ) {
|
if ( errorCode == 257 || ( errorCode >= 259 && errorCode <= 263 ) ) {
|
||||||
throw new SQLGrammarException( message, sqlException, sql );
|
return new SQLGrammarException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
|
|
||||||
// 257 - Cannot insert NULL or update to NULL
|
// 257 - Cannot insert NULL or update to NULL
|
||||||
|
|
|
@ -976,11 +976,10 @@ public class DB2Dialect extends Dialect {
|
||||||
@Override
|
@Override
|
||||||
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
|
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
|
||||||
return (sqlException, message, sql) -> {
|
return (sqlException, message, sql) -> {
|
||||||
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
|
|
||||||
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
||||||
|
switch ( errorCode ) {
|
||||||
if ( -952 == errorCode && "57014".equals( sqlState ) ) {
|
case -952:
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
|
@ -700,7 +700,7 @@ public class DerbyDialect extends Dialect {
|
||||||
switch ( sqlState ) {
|
switch ( sqlState ) {
|
||||||
case "40XL1":
|
case "40XL1":
|
||||||
case "40XL2":
|
case "40XL2":
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1055,13 +1055,13 @@ public class OracleDialect extends Dialect {
|
||||||
|
|
||||||
case 30006:
|
case 30006:
|
||||||
// ORA-30006: resource busy; acquire with WAIT timeout expired
|
// ORA-30006: resource busy; acquire with WAIT timeout expired
|
||||||
throw new LockTimeoutException(message, sqlException, sql);
|
return new LockTimeoutException(message, sqlException, sql);
|
||||||
case 54:
|
case 54:
|
||||||
// ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
|
// ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
|
||||||
throw new LockTimeoutException(message, sqlException, sql);
|
return new LockTimeoutException(message, sqlException, sql);
|
||||||
case 4021:
|
case 4021:
|
||||||
// ORA-04021 timeout occurred while waiting to lock object
|
// ORA-04021 timeout occurred while waiting to lock object
|
||||||
throw new LockTimeoutException(message, sqlException, sql);
|
return new LockTimeoutException(message, sqlException, sql);
|
||||||
|
|
||||||
// deadlocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// deadlocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -1076,7 +1076,7 @@ public class OracleDialect extends Dialect {
|
||||||
|
|
||||||
case 1013:
|
case 1013:
|
||||||
// ORA-01013: user requested cancel of current operation
|
// ORA-01013: user requested cancel of current operation
|
||||||
throw new QueryTimeoutException( message, sqlException, sql );
|
return new QueryTimeoutException( message, sqlException, sql );
|
||||||
|
|
||||||
// data integrity violation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// data integrity violation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -704,16 +704,21 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
|
||||||
return (sqlException, message, sql) -> {
|
return (sqlException, message, sql) -> {
|
||||||
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
|
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
|
||||||
if ( "HY008".equals( sqlState ) ) {
|
if ( "HY008".equals( sqlState ) ) {
|
||||||
throw new QueryTimeoutException( message, sqlException, sql );
|
return new QueryTimeoutException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
|
|
||||||
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
||||||
switch ( errorCode ) {
|
switch ( errorCode ) {
|
||||||
case 1222:
|
case 1222:
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
case 2627:
|
case 2627:
|
||||||
case 2601:
|
case 2601:
|
||||||
throw new ConstraintViolationException( message, sqlException, sql );
|
return new ConstraintViolationException(
|
||||||
|
message,
|
||||||
|
sqlException,
|
||||||
|
sql,
|
||||||
|
getViolatedConstraintNameExtractor().extractConstraintName( sqlException )
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -669,7 +669,7 @@ public class SybaseASEDialect extends SybaseDialect {
|
||||||
switch ( sqlState ) {
|
switch ( sqlState ) {
|
||||||
case "JZ0TO":
|
case "JZ0TO":
|
||||||
case "JZ006":
|
case "JZ006":
|
||||||
throw new LockTimeoutException( message, sqlException, sql );
|
return new LockTimeoutException( message, sqlException, sql );
|
||||||
case "S1000":
|
case "S1000":
|
||||||
switch ( errorCode ) {
|
switch ( errorCode ) {
|
||||||
case 515:
|
case 515:
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class SQLExceptionTypeDelegate extends AbstractSQLExceptionConversionDele
|
||||||
}
|
}
|
||||||
else if ( sqlException instanceof DataTruncation ||
|
else if ( sqlException instanceof DataTruncation ||
|
||||||
sqlException instanceof SQLDataException ) {
|
sqlException instanceof SQLDataException ) {
|
||||||
throw new DataException( message, sqlException, sql );
|
return new DataException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
else if ( sqlException instanceof SQLIntegrityConstraintViolationException ) {
|
else if ( sqlException instanceof SQLIntegrityConstraintViolationException ) {
|
||||||
return new ConstraintViolationException(
|
return new ConstraintViolationException(
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class SQLStateConversionDelegate extends AbstractSQLExceptionConversionDe
|
||||||
if ( "70100".equals( sqlState ) ||
|
if ( "70100".equals( sqlState ) ||
|
||||||
// Oracle user requested cancel of current operation
|
// Oracle user requested cancel of current operation
|
||||||
( "72000".equals( sqlState ) && errorCode == 1013 ) ) {
|
( "72000".equals( sqlState ) && errorCode == 1013 ) ) {
|
||||||
throw new QueryTimeoutException( message, sqlException, sql );
|
return new QueryTimeoutException( message, sqlException, sql );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,14 @@ import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
import org.hibernate.JDBCException;
|
||||||
|
import org.hibernate.QueryTimeoutException;
|
||||||
import org.hibernate.cache.spi.QueryKey;
|
import org.hibernate.cache.spi.QueryKey;
|
||||||
import org.hibernate.cache.spi.QueryResultsCache;
|
import org.hibernate.cache.spi.QueryResultsCache;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
|
import org.hibernate.exception.DataException;
|
||||||
|
import org.hibernate.exception.LockTimeoutException;
|
||||||
import org.hibernate.query.spi.QueryOptions;
|
import org.hibernate.query.spi.QueryOptions;
|
||||||
import org.hibernate.sql.ast.spi.SqlSelection;
|
import org.hibernate.sql.ast.spi.SqlSelection;
|
||||||
import org.hibernate.sql.exec.ExecutionException;
|
import org.hibernate.sql.exec.ExecutionException;
|
||||||
|
@ -259,13 +263,18 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExecutionException makeExecutionException(String message, SQLException cause) {
|
private ExecutionException makeExecutionException(String message, SQLException cause) {
|
||||||
return new ExecutionException(
|
final JDBCException jdbcException = executionContext.getSession().getJdbcServices().getSqlExceptionHelper().convert(
|
||||||
message + " [" + cause.getMessage() + "]",
|
|
||||||
executionContext.getSession().getJdbcServices().getSqlExceptionHelper().convert(
|
|
||||||
cause,
|
cause,
|
||||||
message
|
message
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
if ( jdbcException instanceof QueryTimeoutException
|
||||||
|
|| jdbcException instanceof DataException
|
||||||
|
|| jdbcException instanceof LockTimeoutException ) {
|
||||||
|
// So far, the exception helper threw these exceptions more or less directly during conversion,
|
||||||
|
// so to retain the same behavior, we throw that directly now as well instead of wrapping it
|
||||||
|
throw jdbcException;
|
||||||
|
}
|
||||||
|
return new ExecutionException( message + " [" + cause.getMessage() + "]", jdbcException );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readCurrentRowValues() {
|
private void readCurrentRowValues() {
|
||||||
|
|
Loading…
Reference in New Issue