In Ibatis, how does one write a nested Iterate tag to loop through a two-dimensional array? - ibatis

I was troubleshooting the following code and was unable to find an answer, so I figured I would document my solution.
The problem was:
<iterate property="twoDimArray" prepend="and (" close=")" conjunction="or">
<iterate property="twoDimArray[]" open="(" close=")" conjunction="and">
$twoDimArray[][].columnName$ = #twoDimArray[][].value#
</iterate>
</iterate>
Resulted in an error:
There is no READABLE property named 'columnName' ...

I found that I needed to reference the second array as a property of the first:
$twoDimArray[].[].columnName$ = #twoDimArray[].[].value#

Related

How to use in operator in camel simple xml dsl?

I am using Camel 2.17.0. I have a need to use in operator in the simple language in the blueprint.xml file as the following
<choice id="_choice3">
<when id="_when3">
<simple>${header.STATUS} in 'Draft,Review'</simple>
......
However, It doesn't work and throws following exception:
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-A5668784-61983-1579873128661-9-6]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1706)
at org.apache.camel.builder.SimpleBuilder.createPredicate(SimpleBuilder.java:104)
at org.apache.camel.builder.SimpleBuilder.matches(SimpleBuilder.java:83)
By the way, I have been using choice/when condition for a long time. Then I tried to use || and or operator as followings:
<simple>(${header.STATUS.contains("Draft")} or ${header.STATUS.contains("Review")})</simple>
<simple>(${header.STATUS} contains 'Draft' || ${header.STATUS} contains 'Review')</simple>
<simple>(${header.STATUS} contains 'Draft' or ${header.STATUS} contains 'Review')</simple>
In all cases, it throws the same exception. Please help. Thanks in advance
you might lose those extra "()" (brackets) at the end.
Could you try something like this
<simple>${header.STATUS} contains'Draft' or ${header.STATUS} contains 'Review'</simple>
I pre-assume that you are setting the Draft (String) value in the Header.
I hope it helps. :)

Getting an error in output when passing dynamic variable in ElFileBody in Gatling 3.0.3

I am using Gatling 3.0.3 and Java home is set to Jdk9. I am getting an error when running my script using 'ElFileBody' and I am passing a dynamic variable Session_ID in the ElFileBody .txt file. Below is my code
.exec(http("TEAMXPRESS_INIT")
.post("/WEBXPAPIT/api/Common/wxRequestHandlerJSON")
.headers(headers_7)
.body(ElFileBody("bodies/resources/TeamXPLoginUnSchShift_0021_request.txt")).sJson
.check( jsonPath( "$" ).saveAs( "TEAMXP_INIT_RESPONSE_DATA" ) )
.check(status.in(200))
.check(jsonPath("$.pcResult").is("OK")))
bodies/resources/TeamXPLoginUnSchShift_0021_request.txt file is
{"pcwxSessionID":"${Session_ID)","pcServiceName":"TeamXpressInit","pcContextString":"{\"ttContext\":[{\"contextName\":\"pcToken\",\"contextValue\":null,\"contextGroup\":\"PARAM\",\"contextOperator\":\"\",\"contextType\":\"\"},{\"contextName\":\"pcPlatform\",\"contextValue\":null,\"contextGroup\":\"PARAM\",\"contextOperator\":\"\",\"contextType\":\"\"}]}","piClientVersion":"20190414001","pcIODataSetString":""}
Error I am getting is
Caused by: java.util.concurrent.CompletionException: io.gatling.core.session.el.ElParserException: Failed to parse {"pcwxSessionID":"${Session_ID)","pcServiceName":"TeamXpressInit","pcContextString":"{\"ttContext\":[{\"contextName\":\"pcToken\",\"contextValue\":null,\"contextGroup\":\"PARAM\",\"contextOperator\":\"\",\"contextType\":\"\"},{\"contextName\":\"pcPlatform\",\"contextValue\":null,\"contextGroup\":\"PARAM\",\"contextOperator\":\"\",\"contextType\":\"\"}]}","piClientVersion":"20190414001","pcIODataSetString":""} with error ''}' expected but ')' found'
at com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache.lambda$new$0(BoundedLocalCache.java:3373)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.lambda$doComputeIfAbsent$14(BoundedLocalCache.java:2039)
at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1922)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.doComputeIfAbsent(BoundedLocalCache.java:2037)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.computeIfAbsent(BoundedLocalCache.java:2020)
at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:112)
at com.github.benmanes.caffeine.cache.LocalLoadingCache.get(LocalLoadingCache.java:67)
at io.gatling.core.body.ElFileBodies.asBytesSeq(ElFileBodies.scala:71)
at io.gatling.core.body.ElFileBody$.apply(Body.scala:34)
at teamXPLogin.TeamXPLoginUnSchShift.<init>(TeamXPLoginUnSchShift.scala:86)
What wrong am I doing here. If I pass the post request body manually using StringBody method then it works fine. Please help.
I figured out the silly mistake I have done. Instead of passing dynamic variable ${Session_ID} like this, I have passed ${Session_ID).

How to pass a dynamic delimiter to csv marshalling in camel?

i want to pass a dynamic delimiter to the csv marshalling like below.
<marshal>
<csv delimiter="${header.FIELD_DELIMITER}"/>
</marshal>
when i try as above i am getting this exception:
Caused by: java.lang.IllegalArgumentException: Delimiter must have a length of one!
at org.apache.camel.model.dataformat.CsvDataFormat.configureDataFormat(CsvDataFormat.java:138)
at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:88)
at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:80)
at org.apache.camel.model.MarshalDefinition.createProcessor(MarshalDefinition.java:158)
at org.apache.camel.model.ProcessorDefinition.createProcessor(ProcessorDefinition.java:460)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:429)
at org.apache.camel.model.TryDefinition.createProcessor(TryDefinition.java:73)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:500)t
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:213)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:909)
... 19 more
Instead of doing this
<marshal>
<csv delimiter="${header.FIELD_DELIMITER}"/>
</marshal>
You need to do this:
<toD uri="dataformat:csv:marshal?delimiter=${header.FIELD_DELIMITER}"/>
This is dynamic routing and you will need to use this whenever you want to create URIs on runtime based on runtime values.
You cannot do that with marshal. However you can use the dataformat endpoint and the dynamic to pattern. See more details at:
http://camel.apache.org/dataformat-component.html
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

ibatis - where to place the <cacheModel> tag?

I have the map config file like this
<sqlMap ..............>
<alias>
<typeAlias ......../>
</alias>
<statements>
....
<sql>....</sql>
<select cacheModel="cache-select-all">....</select>
<update>...</update>
<procedure>...</procedure>
.....
</statements>
<parameterMaps>
<parameterMap>....</parameterMap>
</parameterMaps>
<cacheModel id="cache-select-all" type="LRU" readOnly="true" serialize="false">
<flushInterval hours="24"/>
<flushOnExecute statement="InsertIOs"/>
<!--<property name="CacheSize" value="1000"/>-->
</cacheModel>
</sqlMap>
I am using ibatis (.net, if that matters) and i have one question: where to place the tags? is There a or because placing it like i did, in the statements seems not to work. What am i doing wrong?
You must reference the cacheModel you defined inside a statement tag as shown in the following link:
http://ibatis.apache.org/docs/dotnet/datamapper/ch03s08.html
Before you use it in the select statement. Order does matter here. Otherwise sql map parser wouldn't be able to validate your sql map.

how to insert html tag inside sql in Liquibase migration?

I need to update my data that have html tag inside so wrote this on liquibase
<sql> update table_something set table_content = " something <br/> in the next line " </sql>
it apparently doesn't work on liquibase ( i got loooong errors .. and meaningless). I tried to remove <br/> and it works.
my question is, is it possible to insert / update something that contains xml tag in Liquibase ?
I am using liquibase 1.9.3 with Grails 1.1.1
edited: forgot to set code sample tag in my examples.
As the liquibase author mentions here you'll need to add CDATA section inside <sql>.
In your particular example that would become:
<sql><![CDATA[ update table_something set table_content = " something <br/> in the next line " ]]></sql>
Even better not to use a <sql> tag at all (I added the where clause ...):
<changeSet author="author" id="table_something_1">
<update tableName="table_something">
<column name="table_content"><![CDATA[ something <br/> in the next line ]]></column>
<where>id=1</where>
</update>
<rollback />
</changeSet>

Resources