Example usage for org.springframework.dao OptimisticLockingFailureException OptimisticLockingFailureException

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

Introduction

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

Prototype

public OptimisticLockingFailureException(String msg, @Nullable Throwable cause) 

Source Link

Document

Constructor for OptimisticLockingFailureException.

Usage

From source file:org.seasar.doma.boot.autoconfigure.DomaPersistenceExceptionTranslator.java

@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
    if (!(ex instanceof JdbcException)) {
        // Fallback to other translators if not JdbcException
        return null;
    }//ww w  . j  a  va2  s . c om

    if (ex instanceof OptimisticLockException) {
        return new OptimisticLockingFailureException(ex.getMessage(), ex);
    } else if (ex instanceof UniqueConstraintException) {
        return new DuplicateKeyException(ex.getMessage(), ex);
    } else if (ex instanceof NonUniqueResultException || ex instanceof NonSingleColumnException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    } else if (ex instanceof NoResultException) {
        return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
    } else if (ex instanceof UnknownColumnException || ex instanceof ResultMappingException) {
        return new TypeMismatchDataAccessException(ex.getMessage(), ex);
    }

    if (ex.getCause() instanceof SQLException) {
        SQLException e = (SQLException) ex.getCause();
        String sql = null;
        if (ex instanceof SqlExecutionException) {
            sql = ((SqlExecutionException) ex).getRawSql();
        }
        return translator.translate(ex.getMessage(), sql, e);
    }

    return new UncategorizedDataAccessException(ex.getMessage(), ex) {
    };
}

From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java

private DataAccessException convertConditionalCheckFailedExceptionForDelete(AmazonClientException e,
        long version, K key) {
    if (version == -1 || false == exists(key)) {
        return getNotFoundException("didnt delete since entity didnt exist", e);
    }// ww  w.  j a v  a  2 s  .  co m
    return new OptimisticLockingFailureException("did not delete entity because of version mismatch", e);
}

From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java

protected DataAccessException processUpdateItemException(K key, AmazonClientException e) {
    final String format = "unable to update entity due to %s.";
    if (e instanceof ConditionalCheckFailedException) {
        if (null == findOne(key)) {
            return getNotFoundException(UPDATE_FAILED_ENTITY_NOT_FOUND, e);
        }/*w ww  .ja  va  2 s  .  c  o m*/
        return new OptimisticLockingFailureException(UPDATE_FAILED_NOT_FOUND_OR_BAD_VERSION, e);
    } else if (e instanceof ProvisionedThroughputExceededException) {
        throw new QueryTimeoutException(String.format(Locale.ENGLISH, format, "throttling"), e);
    } else if (e instanceof AmazonServiceException) {
        AmazonServiceException ase = (AmazonServiceException) e;
        if (VALIDATION_EXCEPTION.equals(ase.getErrorCode())) {
            if (EXPRESSION_REFERS_TO_NON_EXTANT_ATTRIBUTE.equals(ase.getErrorMessage())
                    && null == findOne(key)) {
                // if no locking and we get a specific message, then it also means the item does not exist
                return getNotFoundException(UPDATE_FAILED_ENTITY_NOT_FOUND, e);
            }
            return new InvalidDataAccessResourceUsageException(
                    String.format(Locale.ENGLISH, format, "client error"), e);
        } else {
            return new DynamoDbServiceException(String.format(Locale.ENGLISH, format, "DynamoDB service error"),
                    ase);
        }
    } else {
        return new InvalidDataAccessResourceUsageException(
                String.format(Locale.ENGLISH, format, "client error"), e);
    }
}