use of java.sql.SQLNonTransientConnectionException in project derby by apache.
the class TestJDBC40Exception method testConnectionException.
public void testConnectionException() throws SQLException {
Statement stmt = createStatement();
getConnection().close();
try {
stmt.execute("select * from exception1");
fail("Statement didn't fail.");
} catch (SQLNonTransientConnectionException cone) {
assertTrue("Unexpected SQL State: " + cone.getSQLState(), cone.getSQLState().startsWith("08"));
}
if (usingEmbedded()) {
// test exception after database shutdown
// DERBY-3074
stmt = createStatement();
TestConfiguration.getCurrent().shutdownDatabase();
try {
stmt.execute("select * from exception1");
fail("Statement didn't fail.");
} catch (SQLNonTransientConnectionException cone) {
assertTrue("Unexpected SQL State: " + cone.getSQLState(), cone.getSQLState().startsWith("08"));
}
}
// DERBY-3075
if (usingDerbyNetClient()) {
DataSource ds = JDBCDataSource.getDataSource();
JDBCDataSource.setBeanProperty(ds, "portNumber", 0);
try {
ds.getConnection();
} catch (SQLNonTransientConnectionException cone) {
assertTrue("Unexpected SQL State: " + cone.getSQLState(), cone.getSQLState().startsWith("08"));
}
}
}
use of java.sql.SQLNonTransientConnectionException in project derby by apache.
the class SQLExceptionFactory method getSQLException.
/**
* <p>
* method to construct SQLException
* version specific drivers can overload this method to create
* version specific exceptions
* </p>
*
* <p>
* This implementation creates JDBC 4 exceptions.
* </p>
*
* <pre>
* SQLSTATE CLASS (prefix) Exception
* 0A java.sql.SQLFeatureNotSupportedException
* 08 java.sql.SQLNonTransientConnectionException
* 22 java.sql.SQLDataException
* 28 java.sql.SQLInvalidAuthorizationSpecException
* 40 java.sql.SQLTransactionRollbackException
* 42 java.sql.SQLSyntaxErrorException
* </pre>
*/
@Override
public SQLException getSQLException(String message, String messageId, SQLException next, int severity, Throwable t, Object... args) {
String sqlState = StandardException.getSQLStateFromIdentifier(messageId);
//
// Create dummy exception which ferries arguments needed to serialize
// SQLExceptions across the DRDA network layer.
//
StandardException ferry = wrapArgsForTransportAcrossDRDA(messageId, t, args);
final SQLException ex;
if (sqlState.startsWith(SQLState.CONNECTIVITY_PREFIX)) {
// no derby sqlstate belongs to
// TransientConnectionException DERBY-3074
ex = new SQLNonTransientConnectionException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
ex = new SQLDataException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
if (sqlState.equals(SQLState.LANG_NULL_INTO_NON_NULL))
ex = new SQLIntegrityConstraintViolationException(message, sqlState, severity, ferry);
else if (sqlState.equals(SQLState.LANG_CHECK_CONSTRAINT_VIOLATED))
ex = new DerbySQLIntegrityConstraintViolationException(message, sqlState, severity, ferry, args[1], args[0]);
else
ex = new DerbySQLIntegrityConstraintViolationException(message, sqlState, severity, ferry, args[0], args[1]);
} else if (sqlState.startsWith(SQLState.AUTHORIZATION_SPEC_PREFIX)) {
ex = new SQLInvalidAuthorizationSpecException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.TRANSACTION_PREFIX)) {
ex = new SQLTransactionRollbackException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.LSE_COMPILATION_PREFIX)) {
ex = new SQLSyntaxErrorException(message, sqlState, severity, ferry);
} else if (sqlState.startsWith(SQLState.UNSUPPORTED_PREFIX)) {
ex = new SQLFeatureNotSupportedException(message, sqlState, severity, ferry);
} else if (sqlState.equals(SQLState.LANG_STATEMENT_CANCELLED_OR_TIMED_OUT.substring(0, 5)) || sqlState.equals(SQLState.LOGIN_TIMEOUT.substring(0, 5))) {
ex = new SQLTimeoutException(message, sqlState, severity, ferry);
} else {
ex = new SQLException(message, sqlState, severity, ferry);
}
// If the argument ferry has recorded any extra next exceptions,
// graft them into the parent exception.
SQLException ferriedExceptions = ferry.getNextException();
if (ferriedExceptions != null) {
ex.setNextException(ferriedExceptions);
}
if (next != null) {
ex.setNextException(next);
}
return ex;
}
Aggregations