Example usage for org.springframework.dao CannotAcquireLockException CannotAcquireLockException

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

Introduction

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

Prototype

public CannotAcquireLockException(String msg, Throwable cause) 

Source Link

Document

Constructor for CannotAcquireLockException.

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://ww w .  j a va  2  s . c o m
        return new CannotSerializeTransactionException("Can't serialize", sqlex);
    case 60:
        return new CannotAcquireLockException("Deadlock", sqlex);
    default:
        return null;
    }
}

From source file:at.ac.univie.isc.asio.d2rq.pool.PooledD2rqFactory.java

@Override
public QueryExecution execution(final Query query, final Principal owner) {
    try {// w  w w  .  j  av  a  2  s  . co m
        final PooledModel model = pool.claim(timeout);
        if (model == null) {
            throw new QueryTimeoutException("timed out while claiming a d2rq model");
        }
        final QueryExecution execution = model.execution(query);
        execution.setTimeout(executionTimeout, MILLISECONDS);
        return execution;
    } catch (InterruptedException e) {
        throw new CannotAcquireLockException("interrupted while claiming a d2rq model", e);
    }
}

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

public DataAccessException translate(String task, String sql, SQLException sqlEx) {
    if (task == null) {
        task = "";
    }/*from w ww  .  j  a v  a  2  s .  c  om*/
    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);
}

From source file:org.springframework.orm.hibernate3.SessionFactoryUtils.java

/**
 * Convert the given HibernateException to an appropriate exception
 * from the {@code org.springframework.dao} hierarchy.
 * @param ex HibernateException that occurred
 * @return the corresponding DataAccessException instance
 * @see HibernateAccessor#convertHibernateAccessException
 * @see HibernateTransactionManager#convertHibernateAccessException
 *//*from  ww  w .  jav a 2 s .  co m*/
public static DataAccessException convertHibernateAccessException(HibernateException ex) {
    if (ex instanceof JDBCConnectionException) {
        return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof SQLGrammarException) {
        SQLGrammarException jdbcEx = (SQLGrammarException) ex;
        return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]",
                ex);
    }
    if (ex instanceof QueryTimeoutException) {
        QueryTimeoutException jdbcEx = (QueryTimeoutException) ex;
        return new org.springframework.dao.QueryTimeoutException(
                ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof LockAcquisitionException) {
        LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
        return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof PessimisticLockException) {
        PessimisticLockException jdbcEx = (PessimisticLockException) ex;
        return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof ConstraintViolationException) {
        ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL()
                + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
    }
    if (ex instanceof DataException) {
        DataException jdbcEx = (DataException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof JDBCException) {
        return new HibernateJdbcException((JDBCException) ex);
    }
    // end of JDBCException (subclass) handling

    if (ex instanceof QueryException) {
        return new HibernateQueryException((QueryException) ex);
    }
    if (ex instanceof NonUniqueResultException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueObjectException) {
        return new DuplicateKeyException(ex.getMessage(), ex);
    }
    if (ex instanceof PropertyValueException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof PersistentObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof TransientObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof ObjectDeletedException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof UnresolvableObjectException) {
        return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex);
    }
    if (ex instanceof WrongClassException) {
        return new HibernateObjectRetrievalFailureException((WrongClassException) ex);
    }
    if (ex instanceof StaleObjectStateException) {
        return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex);
    }
    if (ex instanceof StaleStateException) {
        return new HibernateOptimisticLockingFailureException((StaleStateException) ex);
    }
    if (ex instanceof OptimisticLockException) {
        return new HibernateOptimisticLockingFailureException((OptimisticLockException) ex);
    }

    // fallback
    return new HibernateSystemException(ex);
}

From source file:org.springframework.orm.hibernate4.fix.SessionFactoryUtils.java

/**
 * Convert the given HibernateException to an appropriate exception
 * from the {@code org.springframework.dao} hierarchy.
 * @param ex HibernateException that occured
 * @return the corresponding DataAccessException instance
 * @see HibernateExceptionTranslator#convertHibernateAccessException
 * @see HibernateTransactionManager#convertHibernateAccessException
 *///from w w  w  .  j  av  a  2 s. co  m
public static DataAccessException convertHibernateAccessException(HibernateException ex) {
    if (ex instanceof JDBCConnectionException) {
        return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof SQLGrammarException) {
        SQLGrammarException jdbcEx = (SQLGrammarException) ex;
        return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]",
                ex);
    }
    if (ex instanceof LockAcquisitionException) {
        LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
        return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof ConstraintViolationException) {
        ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL()
                + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
    }
    if (ex instanceof DataException) {
        DataException jdbcEx = (DataException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof JDBCException) {
        return new HibernateJdbcException((JDBCException) ex);
    }
    // end of JDBCException (subclass) handling

    if (ex instanceof QueryException) {
        return new HibernateQueryException((QueryException) ex);
    }
    if (ex instanceof NonUniqueResultException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueObjectException) {
        return new DuplicateKeyException(ex.getMessage(), ex);
    }
    if (ex instanceof PropertyValueException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof PersistentObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof TransientObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof ObjectDeletedException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof UnresolvableObjectException) {
        return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex);
    }
    if (ex instanceof WrongClassException) {
        return new HibernateObjectRetrievalFailureException((WrongClassException) ex);
    }
    if (ex instanceof StaleObjectStateException) {
        return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex);
    }
    if (ex instanceof StaleStateException) {
        return new HibernateOptimisticLockingFailureException((StaleStateException) ex);
    }

    // fallback
    return new HibernateSystemException(ex);
}

From source file:org.springframework.orm.hibernate4.SessionFactoryUtils.java

/**
 * Convert the given HibernateException to an appropriate exception
 * from the {@code org.springframework.dao} hierarchy.
 * @param ex HibernateException that occurred
 * @return the corresponding DataAccessException instance
 * @see HibernateExceptionTranslator#convertHibernateAccessException
 * @see HibernateTransactionManager#convertHibernateAccessException
 *///from ww  w . j a v a  2s.c  o  m
public static DataAccessException convertHibernateAccessException(HibernateException ex) {
    if (ex instanceof JDBCConnectionException) {
        return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof SQLGrammarException) {
        SQLGrammarException jdbcEx = (SQLGrammarException) ex;
        return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]",
                ex);
    }
    if (ex instanceof QueryTimeoutException) {
        QueryTimeoutException jdbcEx = (QueryTimeoutException) ex;
        return new org.springframework.dao.QueryTimeoutException(
                ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof LockAcquisitionException) {
        LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
        return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof PessimisticLockException) {
        PessimisticLockException jdbcEx = (PessimisticLockException) ex;
        return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof ConstraintViolationException) {
        ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL()
                + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
    }
    if (ex instanceof DataException) {
        DataException jdbcEx = (DataException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof JDBCException) {
        return new HibernateJdbcException((JDBCException) ex);
    }
    // end of JDBCException (subclass) handling

    if (ex instanceof QueryException) {
        return new HibernateQueryException((QueryException) ex);
    }
    if (ex instanceof NonUniqueResultException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueObjectException) {
        return new DuplicateKeyException(ex.getMessage(), ex);
    }
    if (ex instanceof PropertyValueException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof PersistentObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof TransientObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof ObjectDeletedException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof UnresolvableObjectException) {
        return new HibernateObjectRetrievalFailureException((UnresolvableObjectException) ex);
    }
    if (ex instanceof WrongClassException) {
        return new HibernateObjectRetrievalFailureException((WrongClassException) ex);
    }
    if (ex instanceof StaleObjectStateException) {
        return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex);
    }
    if (ex instanceof StaleStateException) {
        return new HibernateOptimisticLockingFailureException((StaleStateException) ex);
    }
    if (ex instanceof OptimisticEntityLockException) {
        return new HibernateOptimisticLockingFailureException((OptimisticEntityLockException) ex);
    }
    if (ex instanceof PessimisticEntityLockException) {
        if (ex.getCause() instanceof LockAcquisitionException) {
            return new CannotAcquireLockException(ex.getMessage(), ex.getCause());
        }
        return new PessimisticLockingFailureException(ex.getMessage(), ex);
    }

    // fallback
    return new HibernateSystemException(ex);
}

From source file:org.springframework.orm.jpa.EntityManagerFactoryUtils.java

/**
 * Convert the given runtime exception to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * Return null if no translation is appropriate: any other exception may
 * have resulted from user code, and should not be translated.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JpaTransactionManager etc
 * support sophisticated translation of exceptions via a JpaDialect.
 * @param ex runtime exception that occurred
 * @return the corresponding DataAccessException instance,
 * or {@code null} if the exception should not be translated
 *///from  w w  w  .  j  a  va 2  s. c om
@Nullable
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
    // Following the JPA specification, a persistence provider can also
    // throw these two exceptions, besides PersistenceException.
    if (ex instanceof IllegalStateException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof IllegalArgumentException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // Check for well-known PersistenceException subclasses.
    if (ex instanceof EntityNotFoundException) {
        return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
    }
    if (ex instanceof NoResultException) {
        return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueResultException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof QueryTimeoutException) {
        return new org.springframework.dao.QueryTimeoutException(ex.getMessage(), ex);
    }
    if (ex instanceof LockTimeoutException) {
        return new CannotAcquireLockException(ex.getMessage(), ex);
    }
    if (ex instanceof PessimisticLockException) {
        return new PessimisticLockingFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof OptimisticLockException) {
        return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);
    }
    if (ex instanceof EntityExistsException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof TransactionRequiredException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // If we have another kind of PersistenceException, throw it.
    if (ex instanceof PersistenceException) {
        return new JpaSystemException(ex);
    }

    // If we get here, we have an exception that resulted from user code,
    // rather than the persistence provider, so we return null to indicate
    // that translation should not occur.
    return null;
}

From source file:org.springframework.orm.jpa.vendor.HibernateJpaDialect.java

/**
 * Convert the given HibernateException to an appropriate exception
 * from the {@code org.springframework.dao} hierarchy.
 * @param ex HibernateException that occurred
 * @return the corresponding DataAccessException instance
 *//*from   w  ww  . jav a 2 s  .c om*/
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
    if (ex instanceof JDBCConnectionException) {
        return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof SQLGrammarException) {
        SQLGrammarException jdbcEx = (SQLGrammarException) ex;
        return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]",
                ex);
    }
    if (ex instanceof QueryTimeoutException) {
        QueryTimeoutException jdbcEx = (QueryTimeoutException) ex;
        return new org.springframework.dao.QueryTimeoutException(
                ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof LockAcquisitionException) {
        LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
        return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof PessimisticLockException) {
        PessimisticLockException jdbcEx = (PessimisticLockException) ex;
        return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    if (ex instanceof ConstraintViolationException) {
        ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL()
                + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
    }
    if (ex instanceof DataException) {
        DataException jdbcEx = (DataException) ex;
        return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
    }
    // end of JDBCException subclass handling

    if (ex instanceof QueryException) {
        return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof NonUniqueResultException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueObjectException) {
        return new DuplicateKeyException(ex.getMessage(), ex);
    }
    if (ex instanceof PropertyValueException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof PersistentObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof TransientObjectException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof ObjectDeletedException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof UnresolvableObjectException) {
        UnresolvableObjectException hibEx = (UnresolvableObjectException) ex;
        return new ObjectRetrievalFailureException(hibEx.getEntityName(), hibEx.getIdentifier(),
                ex.getMessage(), ex);
    }
    if (ex instanceof WrongClassException) {
        WrongClassException hibEx = (WrongClassException) ex;
        return new ObjectRetrievalFailureException(hibEx.getEntityName(), hibEx.getIdentifier(),
                ex.getMessage(), ex);
    }
    if (ex instanceof StaleObjectStateException) {
        StaleObjectStateException hibEx = (StaleObjectStateException) ex;
        return new ObjectOptimisticLockingFailureException(hibEx.getEntityName(), hibEx.getIdentifier(), ex);
    }
    if (ex instanceof StaleStateException) {
        return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof OptimisticEntityLockException) {
        return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof PessimisticEntityLockException) {
        if (ex.getCause() instanceof LockAcquisitionException) {
            return new CannotAcquireLockException(ex.getMessage(), ex.getCause());
        }
        return new PessimisticLockingFailureException(ex.getMessage(), ex);
    }

    // fallback
    return new JpaSystemException(ex);
}