Example usage for org.springframework.transaction.interceptor DefaultTransactionAttribute setPropagationBehavior

List of usage examples for org.springframework.transaction.interceptor DefaultTransactionAttribute setPropagationBehavior

Introduction

In this page you can find the example usage for org.springframework.transaction.interceptor DefaultTransactionAttribute setPropagationBehavior.

Prototype

public final void setPropagationBehavior(int propagationBehavior) 

Source Link

Document

Set the propagation behavior.

Usage

From source file:org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean.java

@SuppressWarnings("serial")
private void configureTaskletStep(TaskletStep ts) {
    configureAbstractStep(ts);/* w w  w. ja va 2 s . co  m*/
    if (listeners != null) {
        List<ChunkListener> newListeners = new ArrayList<ChunkListener>();
        for (StepListener listener : listeners) {
            if (listener instanceof ChunkListener) {
                newListeners.add((ChunkListener) listener);
            }
        }
        ts.setChunkListeners(newListeners.toArray(new ChunkListener[0]));
    }
    if (tasklet != null) {
        ts.setTasklet(tasklet);
    }
    if (taskExecutor != null) {
        TaskExecutorRepeatTemplate repeatTemplate = new TaskExecutorRepeatTemplate();
        repeatTemplate.setTaskExecutor(taskExecutor);
        if (throttleLimit != null) {
            repeatTemplate.setThrottleLimit(throttleLimit);
        }
        ts.setStepOperations(repeatTemplate);
    }
    if (transactionManager != null) {
        ts.setTransactionManager(transactionManager);
    }
    if (transactionTimeout != null || propagation != null || isolation != null
            || noRollbackExceptionClasses != null) {
        DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
        if (propagation != null) {
            attribute.setPropagationBehavior(propagation.value());
        }
        if (isolation != null) {
            attribute.setIsolationLevel(isolation.value());
        }
        if (transactionTimeout != null) {
            attribute.setTimeout(transactionTimeout);
        }
        Collection<Class<? extends Throwable>> exceptions = noRollbackExceptionClasses == null
                ? new HashSet<Class<? extends Throwable>>()
                : noRollbackExceptionClasses;
        final BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(exceptions, false);
        ts.setTransactionAttribute(new DefaultTransactionAttribute(attribute) {
            @Override
            public boolean rollbackOn(Throwable ex) {
                return classifier.classify(ex);
            }
        });
    }
}

From source file:org.springframework.batch.core.step.factory.SimpleStepFactoryBean.java

/**
 * Getter for the {@link TransactionAttribute} for subclasses only.
 * @return the transactionAttribute/*  w  ww.j a  va  2 s .com*/
 */
@SuppressWarnings("serial")
protected TransactionAttribute getTransactionAttribute() {

    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setPropagationBehavior(propagation.value());
    attribute.setIsolationLevel(isolation.value());
    attribute.setTimeout(transactionTimeout);
    return new DefaultTransactionAttribute(attribute) {

        /**
         * Ignore the default behaviour and rollback on all exceptions that bubble up to the tasklet level. The
         * tasklet has to deal with the rollback rules internally.
         */
        @Override
        public boolean rollbackOn(Throwable ex) {
            return true;
        }

    };

}

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

/**
 * Getter for the {@link TransactionAttribute} for subclasses only.
 * @return the transactionAttribute/*from ww w  .  j a v a 2  s .  c o m*/
 */
@SuppressWarnings("serial")
protected TransactionAttribute getTransactionAttribute() {

    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setPropagationBehavior(propagation.value());
    attribute.setIsolationLevel(isolation.value());
    attribute.setTimeout(transactionTimeout);
    return new DefaultTransactionAttribute(attribute) {

        /**
         * Ignore the default behaviour and rollback on all exceptions that
         * bubble up to the tasklet level. The tasklet has to deal with the
         * rollback rules internally.
         */
        @Override
        public boolean rollbackOn(Throwable ex) {
            return true;
        }

    };

}