Example usage for org.springframework.dao RecoverableDataAccessException RecoverableDataAccessException

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

Introduction

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

Prototype

public RecoverableDataAccessException(String msg, Throwable cause) 

Source Link

Document

Constructor for RecoverableDataAccessException.

Usage

From source file:com.duergner.michael.blog.examples.lbm.repository.riak.AbstractRiakLBMCrudRepository.java

@Override
@SuppressWarnings("unchecked")
public <S extends T> S save(S entity) {
    BinaryValue oldValue = entity.binaryValue;
    String id = entity.getId();//w  w  w.j ava2s . c  o  m
    StoreValue.Builder builder = new StoreValue.Builder(entity).withOption(StoreValue.Option.RETURN_BODY,
            Boolean.TRUE);
    if (null == id) {
        builder.withNamespace(namespace());
    } else {
        builder.withLocation(location(entity));
    }
    if (null != entity.vClock) {
        builder.withVectorClock(entity.vClock);
    }
    StoreValue storeValue = builder.build();
    try {
        StoreValue.Response storeValueResponse = riakClient.execute(storeValue);
        entity = (S) storeValueResponse.getValue(entity.getClass());
        if (storeValueResponse.hasGeneratedKey()) {
            entity.setId(storeValueResponse.getGeneratedKey().toString(CHARSET));
        } else {
            entity.setId(id);
        }
        getProxy().addOrUpdateIndices(oldValue, entity, entity.getId());
        entity.vClock = storeValueResponse.getVectorClock();
        entity.binaryValue = storeValueResponse.getValue(RiakObject.class).getValue();
        return entity;
    } catch (ExecutionException | InterruptedException e) {
        throw new RecoverableDataAccessException(e.getMessage(), e);
    }
}

From source file:com.duergner.michael.blog.examples.lbm.repository.riak.AbstractRiakLBMCrudRepository.java

@Override
public T findOne(String id) {
    FetchValue fetchValue = new FetchValue.Builder(location(id)).build();
    try {//from w  w  w  .ja  v a 2  s. c o m
        FetchValue.Response fetchValueResponse = riakClient.execute(fetchValue);
        if (!fetchValueResponse.isNotFound()) {
            T result = fetchValueResponse.getValue(clazz);
            result.setId(id);
            result.vClock = fetchValueResponse.getVectorClock();
            result.binaryValue = fetchValueResponse.getValue(RiakObject.class).getValue();
            return result;
        } else {
            return null;
        }
    } catch (ExecutionException | InterruptedException e) {
        throw new RecoverableDataAccessException(e.getMessage(), e);
    }
}

From source file:com.duergner.michael.blog.examples.lbm.repository.riak.AbstractRiakLBMCrudRepository.java

@Override
public boolean exists(String id) {
    FetchValue fetchValue = new FetchValue.Builder(location(id))
            .withOption(FetchValue.Option.HEAD, Boolean.TRUE).build();
    try {// w ww  . j  a v a2 s.  c o m
        FetchValue.Response fetchValueResponse = riakClient.execute(fetchValue);
        return !fetchValueResponse.isNotFound();
    } catch (ExecutionException | InterruptedException e) {
        throw new RecoverableDataAccessException(e.getMessage(), e);
    }
}

From source file:com.duergner.michael.blog.examples.lbm.repository.riak.AbstractRiakLBMCrudRepository.java

@Override
public void delete(T entity) {
    DeleteValue deleteValue = new DeleteValue.Builder(location(entity.getId())).build();
    try {//  ww w.  j ava2s .c  o m
        riakClient.execute(deleteValue);
        getProxy().removeIndices(entity, entity.getId());
    } catch (ExecutionException | InterruptedException e) {
        throw new RecoverableDataAccessException(e.getMessage(), e);
    }
}

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

public DataAccessException translate(String task, String sql, SQLException ex) {
    Assert.notNull(ex, "Cannot translate a null SQLException.");
    if (task == null) {
        task = "";
    }//from  w  ww  . ja  v  a2 s  .c  om
    if (sql == null) {
        sql = "";
    }
    if (ex instanceof SQLTransientException) {
        if (ex instanceof SQLTransactionRollbackException) {
            return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
        }
        if (ex instanceof SQLTransientConnectionException) {
            return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
        }
        if (ex instanceof SQLTimeoutException) {
            return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
        }
    } else if (ex instanceof SQLNonTransientException) {
        if (ex instanceof SQLDataException) {
            return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLFeatureNotSupportedException) {
            return new BadSqlGrammarException(task, sql, ex);
        } else if (ex instanceof SQLIntegrityConstraintViolationException) {
            return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLInvalidAuthorizationSpecException) {
            return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLNonTransientConnectionException) {
            return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
        } else if (ex instanceof SQLSyntaxErrorException) {
            return new BadSqlGrammarException(task, sql, ex);
        }
    } else if (ex instanceof SQLRecoverableException) {
        return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
    }
    // We couldn't identify it more precisely - let's allow other translation strategies to kick in.
    return null;
}