Package org.springframework.transaction.interceptor

Examples of org.springframework.transaction.interceptor.TransactionAttribute


     * @param ae the annotated method or class
     * @return TransactionAttribute the configured transaction attribute, or <code>null</code> if none was found
     */
    protected TransactionAttribute determineTransactionAttribute(AnnotatedElement ae) {
      for (TransactionAnnotationParser annotationParser : this.annotationParsers) {
        TransactionAttribute attr = annotationParser.parseTransactionAnnotation(ae);
        if (attr != null) {
          return attr;
        }
      }
      return null;
View Full Code Here


        } else {
          return (TransactionAttribute) cached;
        }
      } else {
        // We need to work it out.
        TransactionAttribute txAtt = computeTransactionAttribute(method, targetClass);
        // Put it in the cache.
        if (txAtt == null) {
          this.attributeCache.put(cacheKey, NULL_TRANSACTION_ATTRIBUTE);
        } else {
          if (logger.isDebugEnabled()) {
View Full Code Here

      // If the target class is null, the method will be unchanged.
      Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass);
      // If we are dealing with method with generic parameters, find the original method.
      specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

      TransactionAttribute txAtt = null;

      if (specificMethod != method) {
        // Fallback is to look at the original method.
        txAtt = findTransactionAttribute(method);
        if (txAtt != null) {
View Full Code Here

  @Test
  public void usesCustomTransactionConfigurationOnInterface() throws SecurityException, NoSuchMethodException {

    CustomAnnotationTransactionAttributeSource source = new TransactionalRepositoryProxyPostProcessor.CustomAnnotationTransactionAttributeSource();

    TransactionAttribute attribute = source.getTransactionAttribute(Bar.class.getMethod("bar", Object.class),
        FooImpl.class);
    assertThat(attribute.isReadOnly(), is(false));

    attribute = source.getTransactionAttribute(Bar.class.getMethod("foo"), FooImpl.class);
    assertThat(attribute.isReadOnly(), is(false));
  }
View Full Code Here

    when(repositoryInformation.getTargetClassMethod(repositorySaveMethod)).thenReturn(implementationClassMethod);

    CustomAnnotationTransactionAttributeSource attributeSource = new CustomAnnotationTransactionAttributeSource();
    attributeSource.setRepositoryInformation(repositoryInformation);

    TransactionAttribute attribute = attributeSource.getTransactionAttribute(repositorySaveMethod,
        SampleImplementation.class);

    assertThat(attribute, Matchers.is(Matchers.notNullValue()));
  }
View Full Code Here

  TransactionAttributeSource transactionAttributeSouce;
 
  @Around("this(loxia.dao.ReadWriteSupport)")
  public Object doQuery(ProceedingJoinPoint pjp) throws Throwable
    MethodSignature ms = (MethodSignature)pjp.getSignature();
    TransactionAttribute ta = transactionAttributeSouce.getTransactionAttribute(ms.getMethod(), pjp.getTarget().getClass());
    if(ta == null || (ReadWriteStatusHolder.getReadWriteStatus() != null && ta.getPropagationBehavior() != TransactionDefinition.PROPAGATION_REQUIRES_NEW)){
      return pjp.proceed(pjp.getArgs());
    }
   
    logger.debug("determine datasource for query:{}.{}",ms.getDeclaringType().getName(),ms.getMethod().getName());   
    logger.debug("Current operation's transaction status: {}", ta == null ? "null": ta.toString());
   
    String currentStatus = ReadWriteStatusHolder.getReadWriteStatus();
    if(ta != null){
      if(ta.getPropagationBehavior() == TransactionDefinition.PROPAGATION_REQUIRES_NEW){
        logger.debug("New writable connection is required for new transaction.");
        ReadWriteStatusHolder.setReadWriteStatus(ReadWriteSupport.WRITE);
      }else
        ReadWriteStatusHolder.setReadWriteStatus((ta != null && ta.isReadOnly()) ? ReadWriteSupport.READ: ReadWriteSupport.WRITE);
    }
    try {
      Object rtn = pjp.proceed(pjp.getArgs());
      return rtn;
    } catch (Throwable e) {
      throw e;
    } finally {
      if(ta != null){
        if(ta.getPropagationBehavior() == TransactionDefinition.PROPAGATION_REQUIRES_NEW){
          logger.debug("Fallback to previous Read/Write Status: {}", currentStatus);
          if(currentStatus == null)
            ReadWriteStatusHolder.clearReadWriteStatus();
          else
            ReadWriteStatusHolder.setReadWriteStatus(currentStatus);
View Full Code Here

   */
  public void testTransactionAttributeDeclaredOnClassMethod() throws Exception {
    Method classMethod = ITestBean.class.getMethod("getAge", (Class[]) null);
   
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(classMethod, TestBean1.class);
   
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
  }
View Full Code Here

   */
  public void testTransactionAttributeDeclaredOnInterfaceMethodOnly() throws Exception {
    Method interfaceMethod = ITestBean2.class.getMethod("getAge", (Class[]) null);

    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(interfaceMethod, TestBean2.class);
   
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
      assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
  }
View Full Code Here

  public void testTransactionAttributeOnTargetClassMethodOverridesAttributeOnInterfaceMethod() throws Exception {
    Method interfaceMethod = ITestBean3.class.getMethod("getAge", (Class[]) null);
    Method interfaceMethod2 = ITestBean3.class.getMethod("getName", (Class[]) null);

    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(interfaceMethod, TestBean3.class);
    assertEquals(TransactionAttribute.PROPAGATION_REQUIRES_NEW, actual.getPropagationBehavior());
    assertEquals(TransactionAttribute.ISOLATION_REPEATABLE_READ, actual.getIsolationLevel());
    assertEquals(5, actual.getTimeout());
    assertTrue(actual.isReadOnly());

    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());

    TransactionAttribute actual2 = atas.getTransactionAttribute(interfaceMethod2, TestBean3.class);
    assertEquals(TransactionAttribute.PROPAGATION_REQUIRED, actual2.getPropagationBehavior());
  }
View Full Code Here

 
  public void testRollbackRulesAreApplied() throws Exception {
    Method method = TestBean3.class.getMethod("getAge", (Class[]) null);
   
    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean3.class);

    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute("java.lang.Exception"));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));

    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.rollbackOn(new Exception()));
    assertFalse(actual.rollbackOn(new IOException()));
   
    actual = atas.getTransactionAttribute(method, method.getDeclaringClass());

    rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute("java.lang.Exception"));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
   
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
    assertTrue(actual.rollbackOn(new Exception()));
    assertFalse(actual.rollbackOn(new IOException()));
  }
View Full Code Here

TOP

Related Classes of org.springframework.transaction.interceptor.TransactionAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.