This content has been marked as final.
Show 3 replies
-
1. Re: Can Camel SQL Gateway be configured to store entire object in a table
splatch Oct 19, 2012 3:42 AM (in response to jeffdelong)Hey Jeff,
The quickstart is really simple, but logic behind in Camel is not really complicated. Camel converts message payload to Iterator and binds parameters using 0...n position. If your object have more than one field then you need a custom type converter. Detailed instructions you can find in Camel docs: http://camel.apache.org/type-converter, but example can be really easy:
@Converter public class MyConverter { @Converter public static Iterator toInputStream(MyPOJO pojo) { return new MyPOJOIterator(pojo); } } class MyPojoIterator implements Iterator { private int position = 0; private MyPOJO pojo; public Object next() { switch (object++) { case 0: return pojo.getId(); case 1: return pojo.getName(); case 2: return pojo.getDate(); } }
Remember to add META-INF/services/org/apache/camel/TypeConverter with MyConverter class name.
Kind regards,
Lukasz
-
2. Re: Can Camel SQL Gateway be configured to store entire object in a table
jeffdelong Nov 12, 2012 12:01 PM (in response to splatch)Thanks Lukasz.
So what would the camel query string look like in this case?
Thanks
-
3. Re: Can Camel SQL Gateway be configured to store entire object in a table
splatch Nov 12, 2012 12:24 PM (in response to jeffdelong)Hey Jeff
Query then will look like this
<camel:query>INSERT INTO greetings (name,person,age) VALUES (#,#,#)</camel:query>
Iterator should return values in same order as parameters are used (name, person, age).