List of usage examples for org.springframework.transaction.interceptor TransactionAspectSupport currentTransactionInfo
@Nullable protected static TransactionInfo currentTransactionInfo() throws NoTransactionException
From source file:com.newmainsoftech.spray.slingong.datastore.AnnotationTransactionOnStaticMethodAspect.java
/** * AspectJ's {@link AfterThrowing} advise to complete transaction after exception during execution * of either static method annotated with @{@link Transactional} annotation or public static method * in class annotated with <code>@Transactional</code> annotation. <br /> * The body of advise is copy from after-throwing-advise of Spring's {@link AbstractTransactionAspect} * aspect.// w w w .jav a 2 s . c om * * @param joinPoint * @param throwable */ @SuppressAjWarnings("adviceDidNotMatch") @AfterThrowing(pointcut = "pointcutAtExecutionOfStaticTransactionalMethod()", throwing = "throwable") public void afterThrowingAdvisedExecutionOfStaticTransactionalMethod(JoinPoint joinPoint, Throwable throwable) { try { completeTransactionAfterThrowing(TransactionAspectSupport.currentTransactionInfo(), throwable); } catch (Throwable throwableObj) { logger.error("Failed to close transaction after throwing in a transactional method", throwableObj); } }
From source file:com.newmainsoftech.spray.slingong.datastore.AnnotationTransactionOnStaticMethodAspect.java
/** * AspectJ's {@link AfterReturning} advise to commit transaction after normal completion of * execution of either static method annotated with @{@link Transactional} annotation or public * static method in class annotated with <code>@Transactional</code> annotation. <br /> * The body of advise is copy from after-returning-advise of Spring's {@link AbstractTransactionAspect} * aspect.//from ww w .ja va2 s. c o m * * @param joinPoint * @param txObject */ @SuppressAjWarnings("adviceDidNotMatch") @AfterReturning(pointcut = "pointcutAtExecutionOfStaticTransactionalMethod()", returning = "txObject") public void afterReturningAdvisedExecutionOfStaticTransactionalMethod(JoinPoint joinPoint, Object txObject) { commitTransactionAfterReturning(TransactionAspectSupport.currentTransactionInfo()); }
From source file:com.newmainsoftech.spray.slingong.datastore.AnnotationTransactionOnStaticMethodAspect.java
/** * AspectJ's {@link After} advise to clean up transaction after execution of either static * method annotated with @{@link Transactional} annotation or public static method in class annotated * with <code>@Transactional</code> annotation. <br /> * The body of advise is copy from after-advise of Spring's {@link AbstractTransactionAspect} * aspect./*from www . java 2 s. c o m*/ * * @param joinPoint */ @SuppressAjWarnings("adviceDidNotMatch") @After("pointcutAtExecutionOfStaticTransactionalMethod()") public void afterAdvisedExecutionOfStaticTransactionalMethod(JoinPoint joinPoint) { cleanupTransactionInfo(TransactionAspectSupport.currentTransactionInfo()); }
From source file:org.alfresco.util.transaction.SpringAwareUserTransaction.java
/** * Gets the current transaction info, or null if none exists. * <p>//from w ww . ja va 2s .c o m * A check is done to ensure that the transaction info on the stack is exactly * the same instance used when this transaction was started. * The internal status is also checked against the transaction info. * These checks ensure that the transaction demarcation is done correctly and that * thread safety is adhered to. * * @return Returns the current transaction */ private TransactionInfo getTransactionInfo() { // a few quick self-checks if (threadId < 0 && internalStatus != Status.STATUS_NO_TRANSACTION) { throw new RuntimeException("Transaction has been started but there is no thread ID"); } else if (threadId >= 0 && internalStatus == Status.STATUS_NO_TRANSACTION) { throw new RuntimeException("Transaction has not been started but a thread ID has been recorded"); } TransactionInfo txnInfo = null; try { txnInfo = TransactionAspectSupport.currentTransactionInfo(); // we are in a transaction } catch (NoTransactionException e) { // No transaction. It is possible that the transaction threw an exception during commit. } // perform checks for active transactions if (internalStatus == Status.STATUS_ACTIVE) { if (Thread.currentThread().getId() != threadId) { // the internally stored transaction info (retrieved in begin()) should match the info // on the thread throw new RuntimeException("UserTransaction may not be accessed by multiple threads"); } else if (txnInfo == null) { // internally we recorded a transaction starting, but there is nothing on the thread throw new RuntimeException("Transaction boundaries have been made to overlap in the stack"); } else if (txnInfo != internalTxnInfo) { // the transaction info on the stack isn't the one we started with throw new RuntimeException("UserTransaction begin/commit mismatch"); } } return txnInfo; }