List of usage examples for org.springframework.transaction.interceptor TransactionAttribute isReadOnly
default boolean isReadOnly()
From source file:com.newmainsoftech.spray.slingong.datastore.Slim3PlatformTransactionManagerTest.java
@Test public void testTransactionalAttributesOnStaticMethod1() throws Throwable { try {/* w w w.j a va2s .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:ome.security.basic.EventHandler.java
/** * checks method (and as a fallback the class) for the Spring * {@link Transactional} annotation./*from w w w . j a v a 2s. c om*/ * * @param mi * Non-null method invocation. * @return true if the {@link Transactional} annotation lists this method as * read-only, or if no annotation is found. */ boolean checkReadOnly(MethodInvocation mi) { TransactionAttribute ta = txSource.getTransactionAttribute(mi.getMethod(), mi.getThis().getClass()); return ta == null ? true : ta.isReadOnly(); }