Search in sources :

Example 6 with SpringTransactionPolicy

use of org.apache.camel.spring.spi.SpringTransactionPolicy in project camel by apache.

the class TransactionalClientDataSourceAsyncTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new SpringRouteBuilder() {

        public void configure() throws Exception {
            context.addComponent("async", new MyAsyncComponent());
            // use required as transaction policy
            SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
            // configure to use transaction error handler and pass on the required as it will fetch
            // the transaction manager from it that it needs
            errorHandler(transactionErrorHandler(required));
            // on exception is also supported
            onException(IllegalArgumentException.class).handled(false).to("mock:error");
            from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").log("Before thread ${threadName}").to("async:bye:camel").log("After thread ${threadName}").setBody(constant("Elephant in Action")).bean("bookService");
            from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").log("Before thread ${threadName}").to("async:bye:camel").log("After thread ${threadName}").setBody(constant("Donkey in Action")).bean("bookService");
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy) MyAsyncComponent(org.apache.camel.processor.async.MyAsyncComponent)

Example 7 with SpringTransactionPolicy

use of org.apache.camel.spring.spi.SpringTransactionPolicy in project camel by apache.

the class TransactionalClientDataSourceWithOnExceptionHandledAndRollbackTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new SpringRouteBuilder() {

        public void configure() throws Exception {
            // use required as transaction policy
            SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
            // configure to use transaction error handler and pass on the required as it will fetch
            // the transaction manager from it that it needs
            errorHandler(transactionErrorHandler(required));
            onException(IllegalArgumentException.class).handled(true).to("mock:error").rollback();
            from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
            from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy)

Example 8 with SpringTransactionPolicy

use of org.apache.camel.spring.spi.SpringTransactionPolicy in project camel by apache.

the class TransactionalClientDataSourceWithOnExceptionRollbackTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new SpringRouteBuilder() {

        public void configure() throws Exception {
            // use required as transaction policy
            SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
            // configure to use transaction error handler and pass on the required as it will fetch
            // the transaction manager from it that it needs
            errorHandler(transactionErrorHandler(required));
            // on exception is also supported
            onException(IllegalArgumentException.class).handled(false).to("mock:error").rollback();
            from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
            from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy)

Example 9 with SpringTransactionPolicy

use of org.apache.camel.spring.spi.SpringTransactionPolicy in project camel by apache.

the class TransactionalClientDataSourceWithOnExceptionTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new SpringRouteBuilder() {

        public void configure() throws Exception {
            // use required as transaction policy
            SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class);
            // configure to use transaction error handler and pass on the required as it will fetch
            // the transaction manager from it that it needs
            errorHandler(transactionErrorHandler(required));
            // on exception is also supported
            onException(IllegalArgumentException.class).handled(false).to("mock:error");
            from("direct:okay").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Elephant in Action")).bean("bookService");
            from("direct:fail").policy(required).setBody(constant("Tiger in Action")).bean("bookService").setBody(constant("Donkey in Action")).bean("bookService");
        }
    };
}
Also used : SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) SpringTransactionPolicy(org.apache.camel.spring.spi.SpringTransactionPolicy)

Aggregations

SpringTransactionPolicy (org.apache.camel.spring.spi.SpringTransactionPolicy)9 SpringRouteBuilder (org.apache.camel.spring.SpringRouteBuilder)7 JndiRegistry (org.apache.camel.impl.JndiRegistry)1 MyAsyncComponent (org.apache.camel.processor.async.MyAsyncComponent)1 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)1 EmbeddedDatabaseBuilder (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)1