2017-03-24 56 views
0

我有一個要求,我必須從兩個不同的源文件中讀取數據,一個來自文件,另一個來自數據庫,然後在聚合器中執行一些操作,然後寫入輸出到一個文件。無法在apache駝峯上使用outPutClass進行深度映射

我能夠讀取文件,但從數據庫中讀取文件後,我必須將文件轉換爲一個bean。我無法做到。

下面是我的代碼:

路線:

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(); 

上述路線讀取文件,並用通過轉換成一個對象查詢返回結果集豐富。

.to("jdbc:dataSourceDB2?outputClass=com.tgt.fff.beans.LookUpJob9") 

LookUpJob9.java

@Component 

public class LookUpJob9 { 


    CompositeKey compositeKey; 

    String itemCspk; 

    String dummy; 

    --------getters & setters----------- 

} 

的CompositeKey是包含含有複合鍵4個字段的類。

現在的問題是outputClass屬性無法進行深度映射。 它能夠映射itemCspk和dummy,但無法映射CompositeKey類中的字段。

我收到以下異常:

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] 

當我用bindy上面的類,我用@link與CompositeKey類將兩者結合起來。有沒有什麼類似的方法可以用JDBC來實現它。

回答

0

當前不支持嵌套/深度映射。這需要駝峯-jdbc組件中的一些修改工作來支持這一點。

歡迎您的問題跟蹤 http://camel.apache.org/support.html

+0

由於克勞斯記錄一個JIRA票,我將這樣做。 – Sandy