You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by moj0002 <mo...@hotmail.com> on 2014/04/12 06:37:53 UTC

JDBC component and jboss ds.xml file

I have my data source defined in a jboss ds file (myDB2Database-ds.xml) that
goes either in the jboss deploy directory or ds directory

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
   <local-tx-datasource>
      <jndi-name>myDataSource</jndi-name>
      <connection-url>jdbc:db2://....;</connection-url>
      <driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
... more properties here
  </local-tx-datasource>
</datasources>

In my spring application context I define my route


<import resource="classpath:sql-beans.xml"/>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="timer://foo?fixedRate=true&amp;period=1m"/>
            <to uri="bean://sqlBean"/> 
            <to uri="jdbc://java:myDatasource"/> 


My sqlBean is just a simple

public class SqlBean 
{
       public String toSql() 
      {	
	 return "select current timestamp from sysibm.sysdummy1";            
    }
}

I can't figure out how to reference the jndi data source (myDataSource)
defined in the ds.xml file
<to uri="jdbc://java:myDatasource"/> 
is not working.  

How do I get the data source registered so I can get a handle to it?

Looks like osgi uses <reference> but I am not running in an OSGI container,
just plain JBOSS 5.2 J2EE.





--
View this message in context: http://camel.465427.n5.nabble.com/JDBC-component-and-jboss-ds-xml-file-tp5750137.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JDBC component and jboss ds.xml file

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Apr 14, 2014 at 8:53 PM, moj0002 <mo...@hotmail.com> wrote:
> okay I figured it out I think,
>
> The CamelJdbcUpdateCount contains rows inpacted included rows DELETED, maybe
> it is using a prepared statement behind the scene
>
> I first dumped all the headers <to uri="log:myLog?showHeaders=true"/> and
> found the property in the input header
>
> Then this works
>     <log message="Running Scheduled deletion at  ${date:now:yyyy-MM-dd
> HH:mm:ss z}   Rows deleted: $simple{header.CamelJdbcUpdateCount} "/>
>
> I am still confused as to why I am looking at the input headers and not
> output headers.
>

This page may help a bit
http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/JDBC-component-and-jboss-ds-xml-file-tp5750137p5750227.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: JDBC component and jboss ds.xml file

Posted by moj0002 <mo...@hotmail.com>.
okay I figured it out I think, 

The CamelJdbcUpdateCount contains rows inpacted included rows DELETED, maybe
it is using a prepared statement behind the scene 

I first dumped all the headers <to uri="log:myLog?showHeaders=true"/> and
found the property in the input header 

Then this works
    <log message="Running Scheduled deletion at  ${date:now:yyyy-MM-dd
HH:mm:ss z}   Rows deleted: $simple{header.CamelJdbcUpdateCount} "/>

I am still confused as to why I am looking at the input headers and not
output headers.



--
View this message in context: http://camel.465427.n5.nabble.com/JDBC-component-and-jboss-ds-xml-file-tp5750137p5750227.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JDBC component and jboss ds.xml file

Posted by moj0002 <mo...@hotmail.com>.
Thanks, that was it, I guess my question was not really a Camel question but
rather a Spring question.

Here is what I did and this works

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:camel="http://camel.apache.org/schema/spring" 
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
	http://www.springframework.org/schema/jee 
	http://www.springframework.org/schema/jee/spring-jee-3.2.xsd">

    <jee:jndi-lookup id="myID" jndi-name="java:myDS"
expected-type="javax.sql.DataSource"/>

I do have one additional question:

I am going to delete rows and I want to get the count of deleted rows, the
following seems only to work with update 
            <log message="rows impacted: 
$simple{out.header.CamelJdbcUpdateCount}"/>

Is there a similar header property for rows deleted?
I guess I can do a select before and after but thoguht maybe there was a
cleaner way?





--
View this message in context: http://camel.465427.n5.nabble.com/JDBC-component-and-jboss-ds-xml-file-tp5750137p5750220.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JDBC component and jboss ds.xml file

Posted by Raul Kripalani <ra...@evosent.com>.
This will help you:
http://stackoverflow.com/questions/9183321/how-to-use-jndi-datasource-provided-by-tomcat-in-spring.

Raúl.

> On 12 Apr 2014, at 06:43, moj0002 <mo...@hotmail.com> wrote:
>
> I have my data source defined in a jboss ds file (myDB2Database-ds.xml) that
> goes either in the jboss deploy directory or ds directory
>
> <?xml version="1.0" encoding="UTF-8"?>
> <datasources>
>   <local-tx-datasource>
>      <jndi-name>myDataSource</jndi-name>
>      <connection-url>jdbc:db2://....;</connection-url>
>      <driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
> ... more properties here
>  </local-tx-datasource>
> </datasources>
>
> In my spring application context I define my route
>
>
> <import resource="classpath:sql-beans.xml"/>
>
>    <camelContext xmlns="http://camel.apache.org/schema/spring">
>        <route>
>            <from uri="timer://foo?fixedRate=true&amp;period=1m"/>
>            <to uri="bean://sqlBean"/>
>            <to uri="jdbc://java:myDatasource"/>
>
>
> My sqlBean is just a simple
>
> public class SqlBean
> {
>       public String toSql()
>      {
>     return "select current timestamp from sysibm.sysdummy1";
>    }
> }
>
> I can't figure out how to reference the jndi data source (myDataSource)
> defined in the ds.xml file
> <to uri="jdbc://java:myDatasource"/>
> is not working.
>
> How do I get the data source registered so I can get a handle to it?
>
> Looks like osgi uses <reference> but I am not running in an OSGI container,
> just plain JBOSS 5.2 J2EE.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/JDBC-component-and-jboss-ds-xml-file-tp5750137.html
> Sent from the Camel - Users mailing list archive at Nabble.com.