public void close() { if (getTransaction() != null) { try { abortTransaction(); } catch (final Exception e2) { LOG.error("failure during abort", e2); } } session = null; }
/** * Creates a new transaction and saves, to be accessible in {@link #getTransaction()}. */ protected final T createTransaction() { this.transaction = createTransaction(createMessageBroker(), createUpdateNotifier()); return transaction; }
public <Q> Q executeWithinTransaction(TransactionalClosureWithReturn<Q> closure) { boolean initiallyInTransaction = inTransaction(); if(!initiallyInTransaction) { startTransaction(); } try { closure.preExecute(); Q retVal = closure.execute(); closure.onSuccess(); if(!initiallyInTransaction) { endTransaction(); } return retVal; } catch (RuntimeException ex) { closure.onFailure(); if(!initiallyInTransaction) { abortTransaction(); } throw ex; } }
/** * Convenience method returning the {@link UpdateNotifier} * of the {@link #getTransaction() current transaction}. */ protected UpdateNotifier getUpdateNotifier() { return getTransaction().getUpdateNotifier(); }
public void executeWithinTransaction(TransactionalClosure closure) { boolean initiallyInTransaction = inTransaction(); if(!initiallyInTransaction) { startTransaction(); } try { closure.preExecute(); closure.execute(); closure.onSuccess(); if(!initiallyInTransaction) { endTransaction(); } } catch (RuntimeException ex) { closure.onFailure(); if(!initiallyInTransaction) { // temp TODO fix swallowing of exception // System.out.println(ex.getMessage()); // ex.printStackTrace(); try { abortTransaction(); } catch (Exception e) { LOG.error("Abort failure after exception", e); // System.out.println(e.getMessage()); // e.printStackTrace(); throw new NakedObjectTransactionManagerException("Abort failure: " + e.getMessage(), ex); } } throw ex; } }
/** * Convenience method returning the {@link MessageBroker} * of the {@link #getTransaction() current transaction}. */ protected MessageBroker getMessageBroker() { return getTransaction().getMessageBroker(); }
public void debugData(final DebugString debug) { debug.appendln("Transaction", getTransaction()); }
public boolean inTransaction() { return getTransaction() != null && !getTransaction().getState().isComplete(); }
protected void ensureTransactionNotInProgress() { ensureThatState( getTransaction() != null && !getTransaction().getState().isComplete(), is(false), "Transaction in progress"); }
protected void ensureTransactionInProgress() { ensureThatState( getTransaction() != null && !getTransaction().getState().isComplete(), is(true), "No transaction in progress"); }