List of usage examples for org.springframework.transaction.interceptor TransactionAttribute getName
@Nullable
default String getName()
From source file:com.newmainsoftech.spray.slingong.datastore.Slim3PlatformTransactionManagerTest.java
@Test public void testTransactionalAttributesOnStaticMethod1() throws Throwable { try {//from w w w . j a v a 2 s . c o m Method createNewAuthorStaticMethod = Author.class.getDeclaredMethod("createNewAuthor", new Class[] { String.class }); TransactionAttributeSource transactionAttributeSource // = new AnnotationTransactionAttributeSource( false); = annotationTransactionAspect.getTransactionAttributeSource(); TransactionAttribute transactionAttribute = transactionAttributeSource .getTransactionAttribute(createNewAuthorStaticMethod, Author.class); /* Made addition to ExtendedAnnotationTransactionAspect, so no matter of attribute value of * @Transactional annotation, noRollBack method instead of rollback method of * Slim3PlatformTransactionManager class will be called when encountering * ConcurrentModificationException exception and DeadlineExceededException exception. Assert.assertFalse( transactionAttribute.rollbackOn( new ConcurrentModificationException())); Assert.assertFalse( transactionAttribute.rollbackOn( new DeadlineExceededException())); */ String name = transactionAttribute.getName(); String message = String.format( "Attribution values of @Transactional annotation on %1$s:" + "%n%2$cvalue=\"%3$s\"", createNewAuthorStaticMethod.toString(), '\t', (name == null ? "" : name)); int isolationLevel = transactionAttribute.getIsolationLevel(); Assert.assertEquals(TransactionAttribute.ISOLATION_DEFAULT, isolationLevel); switch (isolationLevel) { case TransactionAttribute.ISOLATION_DEFAULT: message = message + String.format("%n%1$cisolation=ISOLATION_DEFAULT", '\t'); break; case TransactionAttribute.ISOLATION_READ_COMMITTED: message = message + String.format("%n%1$cisolation=ISOLATION_READ_COMMITTED", '\t'); break; case TransactionAttribute.ISOLATION_READ_UNCOMMITTED: message = message + String.format("%n%1$cisolation=ISOLATION_READ_UNCOMMITTED", '\t'); break; case TransactionAttribute.ISOLATION_REPEATABLE_READ: message = message + String.format("%n%1$cisolation=ISOLATION_REPEATABLE_READ", '\t'); break; case TransactionAttribute.ISOLATION_SERIALIZABLE: message = message + String.format("%n%1$cisolation=ISOLATION_SERIALIZABLE", '\t'); break; default: Assert.fail("Unrecognizable isolation level."); } // switch int propagationBehavior = transactionAttribute.getPropagationBehavior(); //Default propagation behavior seems to be TransactionAttribute.PROPAGATION_REQUIRED Assert.assertEquals(TransactionAttribute.PROPAGATION_REQUIRED, propagationBehavior); switch (propagationBehavior) { case TransactionAttribute.PROPAGATION_MANDATORY: message = message + String.format("%n%1$cpropagation=PROPAGATION_MANDATORY", '\t'); break; case TransactionAttribute.PROPAGATION_NESTED: message = message + String.format("%n%1$cpropagation=PROPAGATION_NESTED", '\t'); break; case TransactionAttribute.PROPAGATION_NEVER: message = message + String.format("%n%1$cpropagation=PROPAGATION_NEVER", '\t'); break; case TransactionAttribute.PROPAGATION_NOT_SUPPORTED: message = message + String.format("%n%1$cpropagation=PROPAGATION_NOT_SUPPORTED", '\t'); break; case TransactionAttribute.PROPAGATION_REQUIRED: message = message + String.format("%n%1$cpropagation=PROPAGATION_REQUIRED", '\t'); break; case TransactionAttribute.PROPAGATION_REQUIRES_NEW: message = message + String.format("%n%1$cpropagation=PROPAGATION_REQUIRES_NEW", '\t'); break; case TransactionAttribute.PROPAGATION_SUPPORTS: message = message + String.format("%n%1$cpropagation=PROPAGATION_SUPPORTS", '\t'); break; default: Assert.fail("Unrecognizable propagation behavior."); } // switch String qualifier = transactionAttribute.getQualifier(); message = message + String.format("%n%1$cqualifier=%2$s", '\t', qualifier); int timeout = transactionAttribute.getTimeout(); Assert.assertEquals(TransactionAttribute.TIMEOUT_DEFAULT, timeout); message = message + String.format("%n%1$ctimeout=%2$d", '\t', timeout); boolean readOnlyFlag = transactionAttribute.isReadOnly(); Assert.assertFalse(readOnlyFlag); message = message + String.format("%n%1$creadOnly=%2$s", '\t', String.valueOf(readOnlyFlag)); if (logger.isDebugEnabled()) { logger.debug(message); } } catch (Throwable throwable) { throw throwable; } }
From source file:org.springframework.transaction.interceptor.TransactionAspectSupport.java
/** * Create a transaction if necessary based on the given TransactionAttribute. * <p>Allows callers to perform custom TransactionAttribute lookups through * the TransactionAttributeSource./* w w w.jav a2 s . c om*/ * @param txAttr the TransactionAttribute (may be {@code null}) * @param joinpointIdentification the fully qualified method name * (used for monitoring and logging purposes) * @return a TransactionInfo object, whether or not a transaction was created. * The {@code hasTransaction()} method on TransactionInfo can be used to * tell if there was a transaction created. * @see #getTransactionAttributeSource() */ @SuppressWarnings("serial") protected TransactionInfo createTransactionIfNecessary(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, final String joinpointIdentification) { // If no name specified, apply method identification as transaction name. if (txAttr != null && txAttr.getName() == null) { txAttr = new DelegatingTransactionAttribute(txAttr) { @Override public String getName() { return joinpointIdentification; } }; } TransactionStatus status = null; if (txAttr != null) { if (tm != null) { status = tm.getTransaction(txAttr); } else { if (logger.isDebugEnabled()) { logger.debug("Skipping transactional joinpoint [" + joinpointIdentification + "] because no transaction manager has been configured"); } } } return prepareTransactionInfo(tm, txAttr, joinpointIdentification, status); }