Example usage for org.springframework.dao NonTransientDataAccessResourceException NonTransientDataAccessResourceException

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

Introduction

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

Prototype

public NonTransientDataAccessResourceException(String msg, @Nullable Throwable cause) 

Source Link

Document

Constructor for NonTransientDataAccessResourceException.

Usage

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

/**
 * Translates low level database exceptions to application level exceptions
 *
 * @param e the low level amazon client exception
 * @param action crud action name/*from  w w w .  ja va  2s .co m*/
 * @param conditionalSupplier creates condition failed exception (context dependent)
 * @return a translation of the AWS/DynamoDB exception
 */
DataAccessException convertDynamoDBException(AmazonClientException e, String action,
        Supplier<? extends DataAccessException> conditionalSupplier) {

    final String format = "unable to %s entity due to %s.";
    if (e instanceof ConditionalCheckFailedException) {
        return conditionalSupplier.get();
    } else if (e instanceof ProvisionedThroughputExceededException) {
        return new QueryTimeoutException(String.format(Locale.ENGLISH, format, action, "throttling"), e);
    } else if (e instanceof ResourceNotFoundException) {
        return new NonTransientDataAccessResourceException(
                String.format(Locale.ENGLISH, format, action, "table does not exist"), e);
    } else if (e instanceof AmazonServiceException) {
        AmazonServiceException ase = (AmazonServiceException) e;
        if (VALIDATION_EXCEPTION.equals(((AmazonServiceException) e).getErrorCode())) {
            return new InvalidDataAccessResourceUsageException(
                    String.format(Locale.ENGLISH, format, action, "client error"), e);
        } else {
            return new DynamoDbServiceException(
                    String.format(Locale.ENGLISH, format, action, "DynamoDB service error"), ase);
        }
    } else {
        return new InvalidDataAccessResourceUsageException(
                String.format(Locale.ENGLISH, format, action, "client error"), e);
    }
}

From source file:org.springframework.data.hadoop.pig.PigUtils.java

static DataAccessException convert(PigException ex) {
    if (ex instanceof BackendException) {
        return new DataAccessResourceFailureException("Backend Pig exception", ex);
    }//from  w w  w  . ja v a2s.  co m

    if (ex instanceof VisitorException || ex instanceof PlanException || ex instanceof SchemaMergeException) {
        return new InvalidDataAccessResourceUsageException("Plan failed", ex);
    }

    if (ex instanceof FrontendException) {
        if (ex instanceof JobCreationException) {
            return new InvalidDataAccessResourceUsageException("Map Reduce error", ex);
        }

        // work-around to let compilation on CDH3
        if (PARSER_EXCEPTION != null && PARSER_EXCEPTION.isAssignableFrom(ex.getClass())) {
            return new InvalidDataAccessResourceUsageException("Syntax error", ex);
        }
    }

    return new NonTransientDataAccessResourceException("Unknown Pig error", ex);
}

From source file:org.springframework.data.hadoop.pig.PigUtils.java

static DataAccessException convert(IOException ex) {
    Throwable cause = ex.getCause();
    if (cause instanceof PigException) {
        return convert((PigException) ex);
    }//from w  w  w. jav  a 2s  .  c o  m

    return new NonTransientDataAccessResourceException("Unknown Pig error", ex);
}