Example usage for org.springframework.dao CannotSerializeTransactionException CannotSerializeTransactionException

List of usage examples for org.springframework.dao CannotSerializeTransactionException CannotSerializeTransactionException

Introduction

In this page you can find the example usage for org.springframework.dao CannotSerializeTransactionException CannotSerializeTransactionException.

Prototype

public CannotSerializeTransactionException(String msg, Throwable cause) 

Source Link

Document

Constructor for CannotSerializeTransactionException.

Usage

From source file:net.chrisrichardson.foodToGo.util.spring.MyOracleSQLExceptionTranslator.java

protected DataAccessException customTranslate(String task, String sql, SQLException sqlex) {
    switch (sqlex.getErrorCode()) {
    case 8177://from   ww  w .j ava  2s . co  m
        return new CannotSerializeTransactionException("Can't serialize", sqlex);
    case 60:
        return new CannotAcquireLockException("Deadlock", sqlex);
    default:
        return null;
    }
}

From source file:org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.java

public DataAccessException translate(String task, String sql, SQLException sqlEx) {
    if (task == null) {
        task = "";
    }//ww  w .j a v a2 s . com
    if (sql == null) {
        sql = "";
    }

    // First, try custom translation from overridden method.
    DataAccessException dex = customTranslate(task, sql, sqlEx);
    if (dex != null) {
        return dex;
    }

    // Check SQLErrorCodes with corresponding error code, if available.
    if (this.sqlErrorCodes != null) {
        String errorCode = null;
        if (this.sqlErrorCodes.isUseSqlStateForTranslation()) {
            errorCode = sqlEx.getSQLState();
        } else {
            errorCode = Integer.toString(sqlEx.getErrorCode());
        }

        if (errorCode != null) {

            // Look for defined custom translations first.
            CustomSQLErrorCodesTranslation[] customTranslations = this.sqlErrorCodes.getCustomTranslations();
            if (customTranslations != null) {
                for (int i = 0; i < customTranslations.length; i++) {
                    CustomSQLErrorCodesTranslation customTranslation = customTranslations[i];
                    if (Arrays.binarySearch(customTranslation.getErrorCodes(), errorCode) >= 0) {
                        if (customTranslation.getExceptionClass() != null) {
                            DataAccessException customException = createCustomException(task, sql, sqlEx,
                                    customTranslation.getExceptionClass());
                            if (customException != null) {
                                logTranslation(task, sql, sqlEx, true);
                                return customException;
                            }
                        }
                    }
                }
            }

            // Next, look for grouped error codes.
            if (Arrays.binarySearch(this.sqlErrorCodes.getBadSqlGrammarCodes(), errorCode) >= 0) {
                logTranslation(task, sql, sqlEx, false);
                return new BadSqlGrammarException(task, sql, sqlEx);
            } else if (Arrays.binarySearch(this.sqlErrorCodes.getInvalidResultSetAccessCodes(),
                    errorCode) >= 0) {
                logTranslation(task, sql, sqlEx, false);
                return new InvalidResultSetAccessException(task, sql, sqlEx);
            } else if (Arrays.binarySearch(this.sqlErrorCodes.getDataAccessResourceFailureCodes(),
                    errorCode) >= 0) {
                logTranslation(task, sql, sqlEx, false);
                return new DataAccessResourceFailureException(buildMessage(task, sql, sqlEx), sqlEx);
            } else if (Arrays.binarySearch(this.sqlErrorCodes.getDataIntegrityViolationCodes(),
                    errorCode) >= 0) {
                logTranslation(task, sql, sqlEx, false);
                return new DataIntegrityViolationException(buildMessage(task, sql, sqlEx), sqlEx);
            } else if (Arrays.binarySearch(this.sqlErrorCodes.getCannotAcquireLockCodes(), errorCode) >= 0) {
                logTranslation(task, sql, sqlEx, false);
                return new CannotAcquireLockException(buildMessage(task, sql, sqlEx), sqlEx);
            } else if (Arrays.binarySearch(this.sqlErrorCodes.getDeadlockLoserCodes(), errorCode) >= 0) {
                logTranslation(task, sql, sqlEx, false);
                return new DeadlockLoserDataAccessException(buildMessage(task, sql, sqlEx), sqlEx);
            } else if (Arrays.binarySearch(this.sqlErrorCodes.getCannotSerializeTransactionCodes(),
                    errorCode) >= 0) {
                logTranslation(task, sql, sqlEx, false);
                return new CannotSerializeTransactionException(buildMessage(task, sql, sqlEx), sqlEx);
            }
        }
    }

    // We couldn't identify it more precisely - let's hand it over to the SQLState fallback translator.
    if (logger.isDebugEnabled()) {
        logger.debug("Unable to translate SQLException with errorCode '" + sqlEx.getErrorCode()
                + "', will now try the fallback translator");
    }
    return this.fallbackTranslator.translate(task, sql, sqlEx);
}