You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Arvydas <ar...@gmail.com> on 2010/06/09 16:18:41 UTC
camel-ibatis
Hi all.
As a newcomer to camel I would be very grateful if you helped me.
The problem is with camel IBATIS component.
I am making the simple camel ibatis component which selects information from
database table, deletes it from same database table and sends the
information to http provider. All is working but now i need to implement
additional feature - I need to lock the mysql table before selection and
release the lock after removal. I have tried to write four sql statements:
<statement id="lock"> LOCK TABLE vacation WRITE <statement/> - locks the
table
<select id="selectAll" resultMap="VacationResult"/> - selects the data
<delete id="deleteAll" parameterClass="Vacation"> - deletes the data
<statement id="unlock"> UNLOCK TABLES </statement> - unlocks the table
And use them in camel dsl:
<from uri="timer://pollTheDatabase?period=120000" />
<to uri="ibatis:lock?statementType=Update"/>
<to uri="ibatis:selectAll?statementType=QueryForList" />
<to uri="ibatis:deleteAll?statementType=Delete" />
<to uri="ibatis:unlock?statementType=Update" />
...
<inOut
uri="jbi:service:http://org.apache.servicemix/VacationNotification" />
(I use statementType=Update, because statementType is required in DSL)
But first statement locks the table and doesn't unlock it till servicemix
shutdown.
I tried to do it other way - with <transacted/>, but the bad thing is that
then i have two transactionManagers with two dataSources and transaction
isn't working.
One in sqlMapConfig.xml:
<sqlMapConfig>
<transactionManager type="JDBC">
<dataSource type="DBCP">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"></property>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost:3306/simple"/>
<property name="JDBC.Username" value="root"></property>
<property name="JDBC.Password" value="ura"/>
</dataSource>
</transactionManager>
<sqlMap resource="Query.xml"/>
</sqlMapConfig>
And the other in camel-context:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/simple" />
<property name="username" value="root" />
<property name="password" value="ura" />
</bean>
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
I tried to do it in third way - write four sql statements:
<statement id="transaction"> begin <statement/> - locks the table
<select id="selectAll" resultMap="VacationResult">
SELECT * vacation FOR UPDATE;
</select> - selects
the data
<delete id="deleteAll" parameterClass="Vacation"> - deletes the data
<statement id="commit"> commit </statement> - unlocks the table
But it doesn't lock the table between select and delete.
By the way I tested locking by adding a delay in DSL between select and
delete statements and tried to insert into table. No lock was able to
prevent me from doing it :)
Any ideas how implement the locking?
sorry for my english :)
--
View this message in context: http://old.nabble.com/camel-ibatis-tp28831029p28831029.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.