You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dmcamp <di...@gmail.com> on 2012/12/13 16:59:36 UTC

Camel JPA - Parameterized Queries?

Hello Everyone,

I'm looking for a way to do something like this:
....
to("jpa://com.domain.MyEntity?consumer.query=select x from
com.domain.MyEntity e where e.processDate < ?", new Date())
...
I mean I need a way to pass objects as query parameters. In this case what
I'm trying to do is that each time the jpa endpoint its called it executes a
query which selects the entities that has a processDate that is before or
equal to the current moment.
Is there a simple way to do this?
Thanks!





--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by chatura <sa...@gmail.com>.
That's great, But unfortunately I missed the exact option in the
documentation and ending up as same implementation as you mention.  

Thanks
Chatura



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5741930.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

Since Camel 2.12 there's a 'consumer.parameters' option for this purpose:

http://camel.apache.org/jpa#JPA-Options

I polished it's description a bit to make it clear how to use it. Takes a
while to be updated on the site.

Babak


chatura wrote
> This may be little outdated. But I also had that issue with jpa named
> query dynamic parameters and resolve by extending JpaConsumer with
> override configureParameters method. I really not sure that is the best
> way to go appreciate any comment from camel experts. 
> 
> 
> Thanks
> Chatura





--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5741928.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by chatura <sa...@gmail.com>.
This may be little outdated. But I also had that issue with jpa named query
dynamic parameters and resolve by extending JpaConsumer with override
configureParameters method. I really not sure that is the best way to go
appreciate any comment from camel experts. 


Thanks
Chatura



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5741925.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

In case of a Bean method that comes out-of-the-box through the Camel
Parameter binding:

  http://camel.apache.org/bean-binding.html#BeanBinding-Parameterbinding

And in case of a Camel Processor:

 theExchangeParameterOfTheProcessMethod.getContext();

Babak




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5727045.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by objectorange <br...@briantaylor.us>.
How did you get the context reference?



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5727043.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by Babak Vahdat <ba...@swissonline.ch>.

Am 14.12.12 03:16 schrieb "dmcamp" unter <di...@gmail.com>:

>Yeah sure.
>I just created a custom bean which uses JPA to query what I need. So,
>instead of the jpa endpoint, y use my bean, and that's it.

You can also achieve this easily through two lines of code in a
Processor/Bean etc. as the JpaEndpoint already exposes a JpaTemplate for
such cases:


JpaTemplate jpaTemplate = context.getEndpoint("jpa:" +
MyEntity.class.getName(), JpaEndpoint.class).getTemplate();
List<MyEntity> myEntites = jpaTemplate.find("select x from
com.domain.MyEntity e where e.processDate < ?1", new Date());



Babak

>
>
>
>--
>View this message in context:
>http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp572404
>6p5724061.html
>Sent from the Camel - Users mailing list archive at Nabble.com.



Re: Camel JPA - Parameterized Queries?

Posted by dmcamp <di...@gmail.com>.
Yeah sure.
I just created a custom bean which uses JPA to query what I need. So,
instead of the jpa endpoint, y use my bean, and that's it.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5724061.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by Willem jiang <wi...@gmail.com>.
Hi,

Can you share the work around you got?
It will save lot of time when  the other user hits the same issue like you.
  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Friday, December 14, 2012 at 1:37 AM, dmcamp wrote:

> Hi Babak,
>  
> Thanks for the quick response.
> It's a shame it doesn't support that.
> I already know a work around I can use, but I was just trying to let Camel
> do all the work.
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5724051.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Camel JPA - Parameterized Queries?

Posted by dmcamp <di...@gmail.com>.
Hi Babak,

Thanks for the quick response.
It's a shame it doesn't support that.
I already know a work around I can use, but I was just trying to let Camel
do all the work.




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp5724046p5724051.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JPA - Parameterized Queries?

Posted by Babak Vahdat <ba...@swissonline.ch>.

Am 13.12.12 16:59 schrieb "dmcamp" unter <di...@gmail.com>:

>Hello Everyone,
>
>I'm looking for a way to do something like this:
>....
>to("jpa://com.domain.MyEntity?consumer.query=select x from
>com.domain.MyEntity e where e.processDate < ?", new Date())
>...
>I mean I need a way to pass objects as query parameters. In this case what
>I'm trying to do is that each time the jpa endpoint its called it
>executes a
>query which selects the entities that has a processDate that is before or
>equal to the current moment.
>Is there a simple way to do this?

Hi

No currently this's not possible. A possible solution to this would be to
bind such a JPA Query *object* into the Camel registry from where the
Consumer/Producer would pick it up and use it. Currently all you can do is
to pass in the JPA Queries through their names as *String*.

Feel free to log a JIRA for this.

Babak

>Thanks!
>
>
>
>
>
>--
>View this message in context:
>http://camel.465427.n5.nabble.com/Camel-JPA-Parameterized-Queries-tp572404
>6.html
>Sent from the Camel - Users mailing list archive at Nabble.com.