Search in sources :

Example 6 with DerbySQLIntegrityConstraintViolationException

use of org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException 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;
}
Also used : SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) StandardException(org.apache.derby.shared.common.error.StandardException) SQLTransactionRollbackException(java.sql.SQLTransactionRollbackException) SQLDataException(java.sql.SQLDataException) SQLException(java.sql.SQLException) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) DerbySQLIntegrityConstraintViolationException(org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) SQLTimeoutException(java.sql.SQLTimeoutException) SQLInvalidAuthorizationSpecException(java.sql.SQLInvalidAuthorizationSpecException) DerbySQLIntegrityConstraintViolationException(org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException)

Aggregations

DerbySQLIntegrityConstraintViolationException (org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException)6 Statement (java.sql.Statement)5 PreparedStatement (java.sql.PreparedStatement)3 GenericPreparedStatement (org.apache.derby.impl.sql.GenericPreparedStatement)3 SQLDataException (java.sql.SQLDataException)1 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 SQLInvalidAuthorizationSpecException (java.sql.SQLInvalidAuthorizationSpecException)1 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)1 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 SQLTransactionRollbackException (java.sql.SQLTransactionRollbackException)1 Savepoint (java.sql.Savepoint)1 StandardException (org.apache.derby.shared.common.error.StandardException)1