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

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

Introduction

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

Prototype

public Object getValue() 

Source Link

Document

Gets the value of the property.

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 ww w.  j  a  v a  2 s.  com
 * @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 {//from ww w. j  a va  2s.  c o  m
        // 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);
}