Вопрос

I have a flow which reads a CSV files and perfrorm CRUD operation in database ... My flow is somewhat like :-

<flow name="CsvToFile" doc:name="CsvToFile">
    <file:inbound-endpoint path="C:\Data" responseTimeout="10000" doc:name="CSV" connector-ref="File">
        <file:filename-wildcard-filter pattern="*.csv" caseSensitive="true"/>
    </file:inbound-endpoint>
    <jdbc-ee:csv-to-maps-transformer delimiter="," mappingFile="src/main/abc.xml" ignoreFirstRecord="true" doc:name="CSVTransformer"/>
    <jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="SelectQuery" queryTimeout="-1" connector-ref="jdbcConnectorGlobal" doc:name="Database">
        <jdbc-ee:query key="SelectQuery" value="Select * FROM DBDATA where ID=#[map-payload:ID]"/>
    </jdbc-ee:outbound-endpoint>
    <set-payload value="#[message.payload]" doc:name="Set Payload"/>
</flow>

Now if I use SELECT SQL statement.. I don't see the result and no data is fetched ... but if I use INSERT like

<jdbc-ee:query key="InsertQuery" value="INSERT INTO DBDATA (ID,NAME,AGE) VALUES(#[map-payload:ID],#[map-payload:NAME],#[map-payload:AGE])"/>

or an UPDATE SQL statement, I can find it's working and data is inserted or updated in dataase.

My question is: how can I read the ID value from .CSV file and use in SELECT query to retrieve values from the database?

Это было полезно?

Решение

You have exchange-pattern="one-way", meaning the jdbc outbound call will not return to the main flow. Use exchange-pattern="request-response" instead to get a return value.

Also <set-payload value="#[message.payload]" doc:name="Set Payload"/> does not make any sense. You need a transformer of some sort to make the return value readable. You can add a logger to see the returned payload.

UPDATE:

Return value of csv-to-maps-transformer is ArrayList, not Map, so you can not use map-payload:ID. Try splitting the ArrayList, or use #[payload[0].ID] if you have just a single entry.

Другие советы

Thanks to Anton.. The final solution is #[payload[0].ID] what I need and working for me

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top