Package org.springframework.transaction.interceptor

Examples of org.springframework.transaction.interceptor.RuleBasedTransactionAttribute


    Method method = TestBean6.class.getMethod("getAge", (Class[]) null);

    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean6.class);

    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    rbta.getRollbackRules().add(new NoRollbackRuleAttribute(IOException.class));
    assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
  }
View Full Code Here


    Method method = TestBean7.class.getMethod("getAge", (Class[]) null);

    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean7.class);

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

    assertTrue(actual.isReadOnly());
  }
View Full Code Here

    Method method = TestBean8.class.getMethod("getAge", (Class[]) null);

    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean8.class);

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

    assertTrue(actual.isReadOnly());
  }
View Full Code Here

    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean9.class);
    assertNotNull("Retrieved TransactionAttribute for TestBean9", actual);

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

    assertTrue(actual.isReadOnly());
  }
View Full Code Here

    AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
    TransactionAttribute actual = atas.getTransactionAttribute(method, TestBean10.class);
    assertNotNull("Retrieved TransactionAttribute for TestBean10", actual);

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

    assertTrue(actual.isReadOnly());
  }
View Full Code Here

      return null;
    }
  }

  public TransactionAttribute parseTransactionAnnotation(Transactional ann) {
    RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
    rbta.setPropagationBehavior(ann.propagation().value());
    rbta.setIsolationLevel(ann.isolation().value());
    rbta.setTimeout(ann.timeout());
    rbta.setReadOnly(ann.readOnly());
    rbta.setQualifier(ann.value());
    ArrayList<RollbackRuleAttribute> rollBackRules = new ArrayList<RollbackRuleAttribute>();
    Class[] rbf = ann.rollbackFor();
    for (Class rbRule : rbf) {
      RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
      rollBackRules.add(rule);
    }
    String[] rbfc = ann.rollbackForClassName();
    for (String rbRule : rbfc) {
      RollbackRuleAttribute rule = new RollbackRuleAttribute(rbRule);
      rollBackRules.add(rule);
    }
    Class[] nrbf = ann.noRollbackFor();
    for (Class rbRule : nrbf) {
      NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
      rollBackRules.add(rule);
    }
    String[] nrbfc = ann.noRollbackForClassName();
    for (String rbRule : nrbfc) {
      NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(rbRule);
      rollBackRules.add(rule);
    }
    rbta.getRollbackRules().addAll(rollBackRules);
    return rbta;
  }
View Full Code Here

    for (Element methodEle : methods) {
      String name = methodEle.getAttribute("name");
      TypedStringValue nameHolder = new TypedStringValue(name);
      nameHolder.setSource(parserContext.extractSource(methodEle));

      RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
      String propagation = methodEle.getAttribute(PROPAGATION);
      String isolation = methodEle.getAttribute(ISOLATION);
      String timeout = methodEle.getAttribute(TIMEOUT);
      String readOnly = methodEle.getAttribute(READ_ONLY);
      if (StringUtils.hasText(propagation)) {
        attribute.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation);
      }
      if (StringUtils.hasText(isolation)) {
        attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation);
      }
      if (StringUtils.hasText(timeout)) {
        try {
          attribute.setTimeout(Integer.parseInt(timeout));
        }
        catch (NumberFormatException ex) {
          parserContext.getReaderContext().error("Timeout must be an integer value: [" + timeout + "]", methodEle);
        }
      }
      if (StringUtils.hasText(readOnly)) {
        attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY)));
      }

      List<RollbackRuleAttribute> rollbackRules = new LinkedList<RollbackRuleAttribute>();
      if (methodEle.hasAttribute(ROLLBACK_FOR)) {
        String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR);
        addRollbackRuleAttributesTo(rollbackRules,rollbackForValue);
      }
      if (methodEle.hasAttribute(NO_ROLLBACK_FOR)) {
        String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR);
        addNoRollbackRuleAttributesTo(rollbackRules,noRollbackForValue);
      }
      attribute.setRollbackRules(rollbackRules);

      transactionAttributeMap.put(nameHolder, attribute);
    }

    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchTransactionAttributeSource.class);
View Full Code Here

  @Test
  public void testNonDefaultRollbackRules() throws Exception {
    TransactionAttributeEditor editor = new TransactionAttributeEditor();
    editor.setAsText("+RuntimeException,+SkippableException");
    RuleBasedTransactionAttribute attr = (RuleBasedTransactionAttribute) editor.getValue();
    attr.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
    assertTrue(attr.rollbackOn(new Exception("")));
    assertFalse(attr.rollbackOn(new RuntimeException("")));
    assertFalse(attr.rollbackOn(new SkippableException("")));
  }
View Full Code Here

            return null;
        }
    }

    public TransactionAttribute parseTransactionAnnotation(Transactional ann) {
        RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();

        attribute.setPropagationBehavior(SpringTransactionManager.springPropagationCode(ann.propagation()));
        attribute.setIsolationLevel(SpringTransactionManager.springIsolationCode(ann.isolation()));

        if (ann.retries() != 0)
            throw new IllegalStateException("Retries not supported for Spring-managed transactions.");

        return attribute;
View Full Code Here

TOP

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

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.