Search in sources :

Example 1 with TransactionHandleMessageAdvice

use of org.springframework.integration.transaction.TransactionHandleMessageAdvice in project spring-integration by spring-projects.

the class IntegrationNamespaceUtils method configureTransactionAttributes.

/**
 * Parse a "transactional" element and configure a {@link TransactionInterceptor}
 * or {@link TransactionHandleMessageAdvice}
 * with "transactionManager" and other "transactionDefinition" properties.
 * For example, this advisor will be applied on the Polling Task proxy.
 * @param txElement The transactional element.
 * @param handleMessageAdvice flag if to use {@link TransactionHandleMessageAdvice}
 * or regular {@link TransactionInterceptor}
 * @return The bean definition.
 * @see AbstractPollingEndpoint
 */
public static BeanDefinition configureTransactionAttributes(Element txElement, boolean handleMessageAdvice) {
    BeanDefinition txDefinition = configureTransactionDefinition(txElement);
    BeanDefinitionBuilder attributeSourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(MatchAlwaysTransactionAttributeSource.class);
    attributeSourceBuilder.addPropertyValue("transactionAttribute", txDefinition);
    BeanDefinitionBuilder txInterceptorBuilder = BeanDefinitionBuilder.genericBeanDefinition(handleMessageAdvice ? TransactionHandleMessageAdvice.class : TransactionInterceptor.class);
    txInterceptorBuilder.addPropertyReference("transactionManager", txElement.getAttribute("transaction-manager"));
    txInterceptorBuilder.addPropertyValue("transactionAttributeSource", attributeSourceBuilder.getBeanDefinition());
    return txInterceptorBuilder.getBeanDefinition();
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) TransactionHandleMessageAdvice(org.springframework.integration.transaction.TransactionHandleMessageAdvice) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 TransactionHandleMessageAdvice (org.springframework.integration.transaction.TransactionHandleMessageAdvice)1 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)1