Example usage for org.springframework.dao DeadlockLoserDataAccessException getMessage

List of usage examples for org.springframework.dao DeadlockLoserDataAccessException getMessage

Introduction

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

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:org.zenoss.zep.dao.impl.DaoUtilsTest.java

@Test
public void testDeadlockRetryAllFailed() throws Exception {
    final AtomicInteger i = new AtomicInteger();
    try {// w w  w. j av a2  s.com
        DaoUtils.deadlockRetry(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                throw new DeadlockLoserDataAccessException(String.valueOf(i.incrementAndGet()), null);
            }
        });
        fail("Should have thrown an exception after 5 retries");
    } catch (DeadlockLoserDataAccessException e) {
        assertEquals("5", e.getMessage());
    }
}

From source file:ome.services.util.ServiceHandler.java

protected Throwable getAndLogException(Throwable t) {
    if (null == t) {
        log.error("Exception thrown. (null)");
        return new InternalException("Exception thrown with null message");
    } else {//from ww w .  ja v a  2s  .  c  om
        String msg = " Wrapped Exception: (" + t.getClass().getName() + "):\n" + t.getMessage();

        // Base type of the hierarchy that we are converting to.
        // Just rethrow.
        if (RootException.class.isAssignableFrom(t.getClass())) {
            return t;
        }

        //
        // Spring's transient exception hierarchy
        //
        if (DeadlockLoserDataAccessException.class.isAssignableFrom(t.getClass())) {

            DeadlockLoserDataAccessException dldae = (DeadlockLoserDataAccessException) t;
            TryAgain ta = new TryAgain(dldae.getMessage(), 500L); // ticket:5639
            ta.setStackTrace(t.getStackTrace());
            printException("Deadlock exception thrown.", t);
            return ta;

        } else if (OptimisticLockingFailureException.class.isAssignableFrom(t.getClass())) {

            OptimisticLockException ole = new OptimisticLockException(t.getMessage());
            ole.setStackTrace(t.getStackTrace());
            printException("OptimisticLockingFailureException thrown.", t);
            return ole;

        } else if (ConcurrencyFailureException.class.isAssignableFrom(t.getClass())) {

            ConcurrencyFailureException cfe = (ConcurrencyFailureException) t;
            ConcurrencyException ce = new ConcurrencyException(cfe.getMessage(), 500);
            ce.setStackTrace(t.getStackTrace());
            printException("Unknown concurrency failure", t);
            return ce;

        } else if (TransientDataAccessResourceException.class.isAssignableFrom(t.getClass())) {

            ConcurrencyFailureException cfe = (ConcurrencyFailureException) t;
            ConcurrencyException ce = new ConcurrencyException(cfe.getMessage(), 500);
            ce.setStackTrace(t.getStackTrace());
            printException("Unknown transient failure", t);
            return ce;

        } else if (IllegalArgumentException.class.isAssignableFrom(t.getClass())) {
            ApiUsageException aue = new ApiUsageException(t.getMessage());
            aue.setStackTrace(t.getStackTrace());
            printException("IllegalArgumentException thrown.", t);
            return aue;
        }

        else if (InvalidDataAccessResourceUsageException.class.isAssignableFrom(t.getClass())) {
            ApiUsageException aue = new ApiUsageException(t.getMessage());
            aue.setStackTrace(t.getStackTrace());
            printException("InvalidDataAccessResourceUsageException thrown.", t);
            return aue;
        }

        else if (DataIntegrityViolationException.class.isAssignableFrom(t.getClass())) {
            ValidationException ve = new ValidationException(t.getMessage());
            ve.setStackTrace(t.getStackTrace());
            printException("DataIntegrityViolationException thrown.", t);
            return ve;
        }

        else if (CannotCreateTransactionException.class.isAssignableFrom(t.getClass())) {
            DatabaseBusyException dbe = new DatabaseBusyException("cannot create transaction", 5000L);
            dbe.setStackTrace(t.getStackTrace());
            printException("CannotCreateTransactionException thrown.", t);
            return dbe;
        }

        else if (HibernateObjectRetrievalFailureException.class.isAssignableFrom(t.getClass())) {
            ValidationException ve = new ValidationException(t.getMessage());
            ve.setStackTrace(t.getStackTrace());
            printException("HibernateObjectRetrievealFailureException thrown.", t);
            return ve;
        }

        else if (HibernateSystemException.class.isAssignableFrom(t.getClass())) {
            Throwable cause = t.getCause();
            if (cause == null || cause == t) {
                return wrapUnknown(t, msg);
            } else if (PropertyValueException.class.isAssignableFrom(cause.getClass())) {
                ValidationException ve = new ValidationException(cause.getMessage());
                ve.setStackTrace(cause.getStackTrace());
                printException("PropertyValueException thrown.", cause);
                return ve;
            } else {
                return wrapUnknown(t, msg);
            }
        }

        return wrapUnknown(t, msg);

    }

}