Example usage for org.springframework.transaction.interceptor TransactionAttributeEditor setAsText

List of usage examples for org.springframework.transaction.interceptor TransactionAttributeEditor setAsText

Introduction

In this page you can find the example usage for org.springframework.transaction.interceptor TransactionAttributeEditor setAsText.

Prototype

@Override
public void setAsText(String text) throws IllegalArgumentException 

Source Link

Document

Format is PROPAGATION_NAME,ISOLATION_NAME,readOnly,timeout_NNNN,+Exception1,-Exception2.

Usage

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRollbackTests.java

@Test
public void testOverrideWithoutChangingRollbackRules() throws Exception {
    TransactionAttributeEditor editor = new TransactionAttributeEditor();
    editor.setAsText("-RuntimeException");
    TransactionAttribute attr = (TransactionAttribute) editor.getValue();
    assertTrue(attr.rollbackOn(new RuntimeException("")));
    assertFalse(attr.rollbackOn(new Exception("")));
}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRollbackTests.java

@Test
public void testChangeRollbackRules() throws Exception {
    TransactionAttributeEditor editor = new TransactionAttributeEditor();
    editor.setAsText("+RuntimeException");
    TransactionAttribute attr = (TransactionAttribute) editor.getValue();
    assertFalse(attr.rollbackOn(new RuntimeException("")));
    assertFalse(attr.rollbackOn(new Exception("")));
}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanRollbackTests.java

@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("")));
}

From source file:org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource.java

/**
 * Parses the given properties into a name/attribute map.
 * Expects method names as keys and String attributes definitions as values,
 * parsable into TransactionAttribute instances via TransactionAttributeEditor.
 * @see #setNameMap//from  w w w  . ja  v  a2  s.  c o m
 * @see TransactionAttributeEditor
 */
public void setProperties(Properties transactionAttributes) {
    TransactionAttributeEditor tae = new TransactionAttributeEditor();
    Enumeration<?> propNames = transactionAttributes.propertyNames();
    while (propNames.hasMoreElements()) {
        String methodName = (String) propNames.nextElement();
        String value = transactionAttributes.getProperty(methodName);
        tae.setAsText(value);
        TransactionAttribute attr = (TransactionAttribute) tae.getValue();
        addTransactionalMethod(methodName, attr);
    }
}

From source file:org.springframework.transaction.interceptor.TransactionAttributeSourceEditor.java

public void setAsText(String s) throws IllegalArgumentException {
    MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource();
    if (s == null || "".equals(s)) {
        // Leave value in property editor <code>null</code>
    } else {//  w w w .  j  a  v a2s. com
        // Use properties editor to tokenize the hold string
        PropertiesEditor propertiesEditor = new PropertiesEditor();
        propertiesEditor.setAsText(s);
        Properties props = (Properties) propertiesEditor.getValue();

        // Now we have properties, process each one individually
        TransactionAttributeEditor tae = new TransactionAttributeEditor();
        for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String value = props.getProperty(name);

            // Convert value to a transaction attribute
            tae.setAsText(value);
            TransactionAttribute attr = (TransactionAttribute) tae.getValue();

            // Register name and attribute
            source.addTransactionalMethod(name, attr);
        }
    }
    setValue(source);
}