I have a requirement where I have to read from two different sources, one from a file and the other from a DB, perform some operations in the aggregator and then write the output to a file.
I am able to read the file but after reading the file from database I have to convert the file to a bean. And I am not able to do it.
Below is my code:
Route:
from("file:{{InputFileDir1}}?noop=true")
.routeId("readInputFiles")
.unmarshal()
.bindy(BindyType.Csv,Job9.class)
.enrich("direct:resource", batchLogRecords)
.marshal()
.bindy(BindyType.Csv, ClubbedJob.class)
.to("file:{{OutPutDir}}?fileName={{FinalJoinedFile}}")
.log(LoggingLevel.INFO,"Left Join Complete")
.end();
from("direct:resource")
.setBody(simple("SELECT D.DC LOC,D.DEPT,D.CLASS as CLAS,D.ITEM,D.ITEM_CSPK, 'P' as Dummy FROM db2prod.ITEM_DC D,db2prod.FRTB_ITEM_W E WHERE D.DEPT=E.DEPT AND D.CLASS=E.CLASS AND D.ITEM=E.ITEM AND D.DC_I=E.LOC AND E.ALOC_PRCS='9987' with ur;"))
.to("jdbc:dataSourceDB2?outputClass=com.tgt.fff.beans.LookUpJob9")
.process(convertToObject)
.end();
The above route reads the file and enriches with the resultset returned by the query by converting into an object.
.to("jdbc:dataSourceDB2?outputClass=com.tgt.fff.beans.LookUpJob9")
LookUpJob9.java
@Component
public class LookUpJob9 {
CompositeKey compositeKey;
String itemCspk;
String dummy;
--------getters & setters-----------
}
The CompositeKey is a class which contains 4 fields containing a composite key.
Now the problem is outputClass attribute is not able to do the deep mapping. Its able to map itemCspk and dummy but its not able to map the fields inside the CompositeKey class.
I am getting the below exception:
java.lang.IllegalArgumentException: Cannot map all properties to bean of type class com.tgt.fff.beans.LookUpJob9. There are 4 unmapped properties. {locI=553, deptI=2, clasI=0, itemI=3}
at org.apache.camel.component.jdbc.JdbcProducer.newBeanInstance(JdbcProducer.java:397) ~[camel-jdbc-2.18.2.jar:2.18.2]
at org.apache.camel.component.jdbc.JdbcProducer.extractRows(JdbcProducer.java:350) ~[camel-jdbc-2.18.2.jar:2.18.2]
at org.apache.camel.component.jdbc.JdbcProducer.setResultSet(JdbcProducer.java:332) ~[camel-jdbc-2.18.2.jar:2.18.2]
at org.apache.camel.component.jdbc.JdbcProducer.doCreateAndExecuteSqlStatement(JdbcProducer.java:225) ~[camel-jdbc-2.18.2.jar:2.18.2]
at org.apache.camel.component.jdbc.JdbcProducer.createAndExecuteSqlStatement(JdbcProducer.java:125) ~[camel-jdbc-2.18.2.jar:2.18.2]
at org.apache.camel.component.jdbc.JdbcProducer.processingSqlBySettingAutoCommit(JdbcProducer.java:86) ~[camel-jdbc-2.18.2.jar:2.18.2]
at org.apache.camel.component.jdbc.JdbcProducer.process(JdbcProducer.java:67) ~[camel-jdbc-2.18.2.jar:2.18.2]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145) ~[camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.processor.Enricher.process(Enricher.java:187) [camel-core-2.18.2.jar:2.18.2]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) [camel-core-2.18.2.jar:2.18.2]
When I use the above class with bindy, I use @Link with CompositeKey class to link the two. Is there any similar way by which I can achieve it with JDBC.