public static RuntimeException doTranslate(final Exception ex) { if (ex instanceof JpoException) { throw (JpoException) ex; } if (ex instanceof BadSqlGrammarException) { return new JpoSqlBadGrammarException(ex); } else if (ex instanceof DataIntegrityViolationException) { return new JpoSqlDataIntegrityViolationException(ex); } else if (ex instanceof DataAccessResourceFailureException) { return new JpoSqlDataAccessResourceFailureException(ex); } else if (ex instanceof TransientDataAccessResourceException) { return new JpoSqlTransientDataAccessResourceException(ex); } else if (ex instanceof ConcurrencyFailureException) { return new JpoSqlConcurrencyFailureException(ex); } else if (ex instanceof TransactionTimedOutException) { return new JpoTransactionTimedOutException(ex); } return new JpoSqlException(ex); }
@Test public void testTransactionTimeout() { TransactionException transactionException = new TransactionTimedOutException("Transaction timeout test."); when(transactionOperations.execute(any())).thenThrow(transactionException); try { job.call(); fail("TransactionException should be thrown"); } catch (TransactionException expected) { assertSame(expected, transactionException); } verify(transactionOperations).execute(any()); verify(progress).failed(transactionException); verifyNoMoreInteractions(callable, progress, transactionOperations); }
/** * Return the time to live for this object in milliseconds. * @return number of millseconds until expiration * @throws TransactionTimedOutException if the deadline has already been reached */ public long getTimeToLiveInMillis() throws TransactionTimedOutException{ if (this.deadline == null) { throw new IllegalStateException("No timeout specified for this resource holder"); } long timeToLive = this.deadline.getTime() - System.currentTimeMillis(); checkTransactionTimeout(timeToLive <= 0); return timeToLive; }
/** * Set the transaction rollback-only if the deadline has been reached, * and throw a TransactionTimedOutException. */ private void checkTransactionTimeout(boolean deadlineReached) throws TransactionTimedOutException { if (deadlineReached) { setRollbackOnly(); throw new TransactionTimedOutException("Transaction timed out: deadline was " + this.deadline); } }
protected RuntimeException convertJiniException(Exception exception) { if (exception instanceof LeaseException) { return new RemoteAccessException("Lease denied", exception); } if (exception instanceof TransactionException || exception instanceof net.jini.core.transaction.TransactionException) { return new TransactionSystemException(exception.getMessage(), exception); } if (exception instanceof RemoteException) { // Translate to Spring's unchecked remote access exception return new RemoteAccessException("RemoteException", exception); } if (exception instanceof UnusableEntryException) { return new RemoteAccessException("Unusable entry", exception); } if (exception instanceof RuntimeException) { return (RuntimeException) exception; } if (exception instanceof TimeoutExpiredException) { throw new TransactionTimedOutException("Transaction timed out (either the transaction or commit/abort)", exception); } return new UnexpectedTransactionException(exception); }