use of org.hibernate.exception.JDBCConnectionException in project hibernate-orm by hibernate.
the class SQLStateConversionDelegate method convert.
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
final String sqlState = JdbcExceptionHelper.extractSqlState(sqlException);
final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
if (sqlState != null) {
String sqlStateClassCode = JdbcExceptionHelper.determineSqlStateClassCode(sqlState);
if (sqlStateClassCode != null) {
if (SQL_GRAMMAR_CATEGORIES.contains(sqlStateClassCode)) {
return new SQLGrammarException(message, sqlException, sql);
} else if (INTEGRITY_VIOLATION_CATEGORIES.contains(sqlStateClassCode)) {
final String constraintName = getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName(sqlException);
return new ConstraintViolationException(message, sqlException, sql, constraintName);
} else if (CONNECTION_CATEGORIES.contains(sqlStateClassCode)) {
return new JDBCConnectionException(message, sqlException, sql);
} else if (DATA_CATEGORIES.contains(sqlStateClassCode)) {
return new DataException(message, sqlException, sql);
}
}
if ("40001".equals(sqlState)) {
return new LockAcquisitionException(message, sqlException, sql);
}
if ("40XL1".equals(sqlState) || "40XL2".equals(sqlState)) {
// Derby "A lock could not be obtained within the time requested."
return new PessimisticLockException(message, sqlException, sql);
}
// MySQL Query execution was interrupted
if ("70100".equals(sqlState) || // Oracle user requested cancel of current operation
("72000".equals(sqlState) && errorCode == 1013)) {
throw new QueryTimeoutException(message, sqlException, sql);
}
}
return null;
}
use of org.hibernate.exception.JDBCConnectionException in project hibernate-orm by hibernate.
the class ConnectionCreatorTest method testBadUrl.
@Test
@TestForIssue(jiraKey = "HHH-8621")
public void testBadUrl() throws Exception {
DriverConnectionCreator connectionCreator = new DriverConnectionCreator((Driver) Class.forName("org.h2.Driver").newInstance(), new StandardServiceRegistryImpl(true, new BootstrapServiceRegistryImpl(), Collections.<StandardServiceInitiator>emptyList(), Collections.<ProvidedService>emptyList(), Collections.emptyMap()) {
@Override
@SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if (JdbcServices.class.equals(serviceRole)) {
// return a new, not fully initialized JdbcServicesImpl
return (R) new JdbcServicesImpl();
}
return super.getService(serviceRole);
}
}, "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", new Properties(), false, null);
try {
Connection conn = connectionCreator.createConnection();
conn.close();
fail("Expecting the bad Connection URL to cause an exception");
} catch (JDBCConnectionException expected) {
}
}
Aggregations