[
https://issues.apache.org/jira/browse/CAMEL-3803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13024972#comment-13024972
]
Christian Müller commented on CAMEL-3803:
-----------------------------------------
After reading the issue thread again and thinking about it again, if would
prefer (D)... :-)
(D) means:
- Let the jdbc component as it is (sorry Heath) because the only reason I know
we (still) have the camel sql and the camel jdbc component is, because the
camel jdbc component is more lightweight than the camel sql component (which
use spring jdbc, spring transaction, ...).
- I would like to add the improvement Heath made to set the auto commit to
false and execute explicitly a commit/rollback.
- Mention that limitation in the camel jdbc documentation.
- Improve the camel sql component so that we also can sent the sql statement(s)
in the exchange's body.
This provides the user an easy migration path if they use camel jdbc and they
realize some time they need transaction support.
What do you think?
> Component camel-jdbc does not support Transactions
> --------------------------------------------------
>
> Key: CAMEL-3803
> URL: https://issues.apache.org/jira/browse/CAMEL-3803
> Project: Camel
> Issue Type: Improvement
> Components: camel-jdbc
> Reporter: Charles Moulliard
> Fix For: 3.0.0
>
> Attachments: JdbcTransactedRouteTest.java, patch-3808-updated.diff,
> patch-3808.diff
>
>
> The component camel-jdbc does not support transaction as the component
> creates SQL statement but does not handle errors, exceptions generated and
> propagated by TransactionErrorHandler. This is a clear limitation of this
> component (which is not the case with component camel-sql).
> I suggest that :
> (A) we improve this component to provide Transaction support
> OR
> (B) We keep it like now but mention that limitation into Camel documentation
> OR
> (C) we merge it with camel-sql component to have one providing transaction
> support even if it uses behind the scene JDBCTemplate of Spring. Remark : If
> we decided to merge the two components, that should be an excellent idea to
> allow the SQL component to receive the SQL query as an exchange to avoid to
> hard code it in the query parameter of the endpoint.
> I provide hereafter example of code that we can use to reproduce that :
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
> ">
> <!-- Bean generating the error -->
> <bean id="jdbcReportIncident"
> class="org.apache.camel.example.SqlSpringTxReportIncident"/>
> <!-- TransactionManager -->
> <bean id="required"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">
> <property name="transactionManager" ref="txManager"/>
> <property name="propagationBehaviorName"
> value="PROPAGATION_REQUIRED"/>
> </bean>
> <bean id="txManager"
> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
> <property name="dataSource" ref="reportdb"/>
> </bean>
> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
> <!-- Camel Transactional Route with NO rollback -->
> <route id="transaction-non-working-camel-jdbc">
> <from uri="file://target/datainsertnotrollback?moveFailed=failed"/>
> <transacted ref="required"/>
> <split>
> <tokenize token=","/>
> <setBody>
> <simple>INSERT INTO REPORT.T_INCIDENT
> (INCIDENT_REF,INCIDENT_DATE,GIVEN_NAME,FAMILY_NAME,SUMMARY,DETAILS,EMAIL,PHONE)
> VALUES
>
> ('${body}','2011-03-21','Charles','Moulliard','Incident-${body}','This is a
> report incident for camel-${body}','[email protected]','+111 10 20
> 300')
> </simple>
> </setBody>
> <log message=">>> SQL Query : ${body}"/>
> <to uri="jdbc:reportdb"/>
> <bean ref="jdbcReportIncident" method="generateError"/>
> <log message=">>> Result : ${body}"/>
> </split>
> </route>
> <route id="trigger-database">
> <from uri="timer://webinar?delay=20000&period=20000"/>
> <to uri="sql:SELECT * FROM REPORT.T_INCIDENT"/>
> <split>
> <simple>${body}</simple>
> <log message=">>> Select all : ${body}"/>
> </split>
> </route>
> </camelContext>
> <bean id="reportdb"
> class="org.springframework.jdbc.datasource.DriverManagerDataSource">
> <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
> <property name="url" value="jdbc:hsqldb:hsql://localhost/reportdb"/>
> <property name="username" value="sa"/>
> <property name="password" value=""/>
> </bean>
> </beans>
> {code}
> Java class generating the error
> {code}
> public class SqlSpringTxReportIncident {
> public void generateError() throws Exception {
> throw new Exception("Cannot connect to Database ....");
> }
> }
> {code}
> and Script to create DB in HSQLDB
> {code}
> CREATE TABLE PUBLIC.T_INCIDENT (
> INCIDENT_ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT
> NULL PRIMARY KEY,
> INCIDENT_REF VARCHAR(55),
> INCIDENT_DATE TIMESTAMP,
> GIVEN_NAME VARCHAR(35),
> FAMILY_NAME VARCHAR(35),
> SUMMARY VARCHAR(35),
> DETAILS VARCHAR(255),
> EMAIL VARCHAR(60),
> PHONE VARCHAR(35),
> CREATION_DATE TIMESTAMP,
> CREATION_USER VARCHAR(255)
> )
> The key file must only contain data like '001', '002', ...
> {code}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira