ibatis dynamic sql using two conditions - ibatis

I would like to use a dynamic sql statement that executes only when the variable is not null AND greater than zero. Like this:
<isNotNull prepend="AND" property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
but without prepending two 'AND's.
I have read the documentation but have found no good example.

To work around to this issue I almost never use the "prepend" feature, but instead write an sql like this:
WHERE 1=1
<isNotNull property="ProprietaryId">
<isGreaterThan property="ProprietaryId" compareValue="0">
AND G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>

I just came across this question while looking for the same answer. While effective, this solution kind of bugged me so I studied the iBATIS docs some more and noticed this example:
<dynamic prepend="where">
<isGreaterThan prepend="and" property="id" compareValue="0">
ACC_ID = #id#
</isGreaterThan>
<isNotNull prepend="and" property="lastName">
ACC_LAST_NAME = #lastName#
</isNotNull>
</dynamic>
You'd think that might cause a superfluous "and" to be included within the WHERE clause if only one of the conditions is true, but apparently iBATIS is smart enough to prevent this when using the dynamic tag. It works for me (using iBATIS 2.3.0 in this case).

Its me from the future. Parent elements override the prepend of their first child, so your code will work fine since the isGreaterThan prepend will be overwritten by the parent isNotNull prepend.
From the docs:
The prepend attribute is a part of the code that is free to be overridden by the a parent element's prepend if necessary. In the above example the "where" prepend will override the first true conditional prepend. This is necessary to ensure that the SQL statement is built properly. For example, in the case of the first true condition, there is no need for the AND, and in fact it would break the statement.

<isNotNull property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
just delete the first prepend will work

Related

Can't get Logic App Contains to work with array or comma separated string

I'm trying to look for specific keywords inside of text from a for each loop.
var text = "The lazy fox jumped over the brown dog."
var keywords = "fox,dog,sun";
If true, I want to do something with the text. If false, I want to ignore the text.
Does anyone know how to use an Array filter, Function, Select, Condition or inline code to check for this? If so, specific examples would be great.
By the way, I have a C# function that handles this extremely well in an ASP.net Core app.
UPDATE 1:
This doesn't work.
UPDATE 2:
The Condition is always false after the for each loop even after changing the settings and parallelism to 1.
Azure Logic App Condition does not work in loop if based on changing values
Thanks in advance!
There are so many ways to achieve what you need. Here are the 3 options that came to my mind within a minute.
The first one does use a For each loop, but I wouldn't recommend using it as it's not very efficient.
The For each parameter looks like this:
The Condition parameter looks like this:
The second option is much easier - no need for a loop, just filter the array straight away, then you can check whether it's empty or it has some items:
The Filter array parameters look as follows.
The split function is identical to the one used in option 1.
If you know JavaScript, you might decide to use regular expressions in inline code instead, e.g.:
Then you'd just need to check the output of the inline code. JavaScript code used in the example above:
var text = workflowContext.actions.Compose_text.outputs;
var keywords = workflowContext.actions.Compose_keywords.outputs;
return text.match(new RegExp("(" + keywords.split(",").join("|") + ")", "gi"));
My personal preference is option 2. However, please note that all 3 options above would find "sun" in text "The weather was sunny" even though there's no word "sun" in the text. If you do need "sun" to match only word "sun" - not "sunny", "asunder" or "unsung" - then go for option 3, just use a different, more complex regular expression.
One of the workaround would be use of Condition Connector. I have initialized the sentence in a string and then used Condition Connector which will be checking the conditions.
Finally, In the true section you can add the connectors accordingly.
Placing a Compose behind the for each loop and referencing the Output in the Condition is what finally worked for me. I used the toLower() function in my Compose. The Compose looks like this.
toLower(items('For_each_2')?['day']?['longPhrase'])

Get each item in a collection with one query

I have a collection of slugs and want to get each corresponding page with one query.
Something like ...
Page::whereIn('slug', $slugs)->get();
... does only return the first page matching any slug in the collection.
Currently there is a loop, but that are dozens of queries I want to avoid.
Try using the whereRaw method and imploding your array into a string:
Page::whereRaw('slug IN ("' . $slugs->implode('","') . ')')->get();
As it turned out, whereIn was the right way. There was one minor mistake in my logic, and at the same time insufficient seeding data, that blowed everything up.
If someone does not know: whereRaw should be used with caution. To avoid SQL injection vulnerability, all user-submitted entries have to be passed as parameters.
Page::whereRaw('slug IN (?)', [$slug]);
Beware: Wrapping ? with quotes is a syntax error. The passed data will be single-quoted by default, at least on my machineā„¢.
select * from `pages` where `slug` in ('page');

Verify edge and create edge in the same instruction (gremlin python)

My initial logic of checking if an edge is present and creating an edge needs to query. Im trying to verify and create an edge in one instruction.
This query does not seem to work
ipdb> prop = self._graph.V('pppp').outE('friend').hasId('testEdge').as_('e').inV()
.hasId('dddd').select('e').
coalesce(__.property('testedder', 1111).fold().unfold(),
__.V('dddd'). as_('to_a').V('pppp').addE('friend').to('to_a')).
toList()
1) The first part of the coalesce - updating the property of Edges work fine
2) The second part of the coalesce is either not being called or not working. It is working as an independent query. Does 'as' not work in anonymous traversals?
PS: Im using AWS Neptune
You had the right idea but you needed some simplification. I'll try to do it in steps. First, whenever I see labelled steps, I try to see if there is a way to avoid using them. In this case, they can be factored out:
g.V('pppp').outE('friend').
filter(hasId('testEdge').inV().hasId('dddd')).
coalesce(__.property('testedder', 1111).fold().unfold(),
__.V('dddd'). as_('to_a').V('pppp').addE('friend').to('to_a'))
Readability of the traversal improves on those first two lines because the reader can immediately see that you want to find an edge given some criteria which was only implied by the step labeling approach. Next, I looked at coalesce(). As it stands, if filter() returns no edges then coalesce() will never get a chance to execute and that's why the second part of coalesce() never has an opportunity to work for you. So, let's clean that part up:
g.V(1).outE('knows').
filter(hasId(6).inV().hasId(2)).
fold().
coalesce(unfold().property('testedder', 1111),
V('dddd').as_('to_a').V('pppp').addE('friend').to('to_a'))
If it's not clear why the fold() and unfold() are where they are, you should check out my detailed explanation of the approach here. So, with fold() and unfold() where they should be, the coalesce() should now trigger both conditions depending on whether or not an edge passes the filter(). The first part of the coalesce() is fine, but the second could still use a bit of work as I'd again like to factor out the step labels if the aren't necessary:
g.V('pppp').outE('friend').
filter(hasId('testEdge').inV().hasId('dddd')).
fold().
coalesce(unfold().property('testedder', 1111),
addE('friend').from(V('pppp')).to(V('dddd')))
The above Gremlin assumes that you know "pppp" vertex exists. If you do not then you might try (as suggested by Daniel Kuppitz):
g.V('pppp').
not_(outE('friend').hasId('testEdge').
filter(inV().hasId('dddd')).
property('testedder', 1111)).as('p').
V('dddd').
addE('friend').from('p')

changing variables in loop in Jmeter

I have web request like this
Loop Controller(3)
moreSamples=true
startIndex=0
While Controller(${__javaScript(${moreSamples}==true)})
SOAP/XML-RPC Request(index=${startIndex})
Regular Expression Extractor(startIndex=newIndex,moreSamples=samples)
Now problem is I am not able to initialize moreSamples and startIndex in loop.
I tried two options:
Make moreSamples and startIndex as user defined variables. Now I am able to change their values using Regular Expression Extractor but not able to reinitialize them in outer loop using BeanShell PostProcessor like this:
vars.put("moreSamples","false")
vars.put("startIndex","0")
Make moreSamples and startIndex as User Parameters in preprocessor of of while loop but then I am not able to assign them values using Regular Expression Extractor.
Please suggest the mistakes or some new construct which can fit in.
Screenshot:
#bpsingh,
Can you do following things:
Add UserDefinedVariables on top of your Test Plan with two defined variables:
moreSamples, startIndex (like #ant suggested already)
Under the Download - PersistentSyncScope Sampler, you have two regular expression extractors in which I assume you want to extract some values and place it in these two variables from the above. Add BeanShellPostProcessor under the Download - PersistentSyncScope Sampler.
In BeanShellPostProcessor add following code:
vars.put("moreSamples","${REGEX_EXTRACT1}");
vars.put("startIndex","${REGEX_EXTRACT2}");
These two (moreSamples, startIndex) are global variables and changes on them should be visible outside of the loop.
Do you have to initialize them from the loop? How about adding those to User Defined Variables?
Or you can do it from your loop as well, the reason why it doesn't work for you is either the fact that you forgot to put the semi-colon ; after your expression(s) :
vars.put("moreSamples","false"); // ; <- was missing
vars.put("startIndex","0"); // ; <- was missing
I used BSF Sampler and it worked for me (don't forget to choose the language -> beanshell if you use this one). Here is my debug sampler (relevant part) :
START.HMS=101818
START.MS=1341821898080
START.YMD=20120709
TESTSTART.MS=1341822195274
moreSamples=false
startIndex=0
Update:
You need not to use both BSF Sampler and user defined variables. You can use either, and I see you have more user defined variables, no need for that. Have one of those at the start of your test. I'm still not clear what your problem is and what you're trying to achieve.
Actually problem here is I am using 2 loops and all answers don't take this properly into account.
Since pre/post processors are applied only to samplers not to loops there is no way to reinitialize the variables before while loop. Thus if I add initialize statements in preprocessor, loop run infinitely and if in postprocessor, it never executes. Only way to initialize is adding BSF sampler before while loop but that will spoil the reports as this sampler will also be recorded by listeners.
So only solution I found is run Download - PersistentSyncScope Sampler once and add BSF preprocessor with following scripts
vars.put("moreSamples","false");
vars.put("startIndex","0");
Now add while loop and add Download - PersistentSyncScope Sampler as its child.
That is the only solution till now. Thanks everyone to help me understand the problem.

How can I do a complex IF statement in visualforce?

I'm totally new to this, the task has been thrown at me as important and I've never done anything like this before. I have been given a template containing roughly this:
<apex:column headervalue="Amount"><c2g:CODAFormatterController number="{!IF([some condition],[something],[something else])}"/></apex:column>
I've replaced the statements with condition/something/something else
is there a way to use a function as you'd do in javascript, so something like
number="getNumber(x);"
or do I have to chain some IF statements together somehow? Is there an IF...ELSE?
I don't know what a CODAFormatterController is as it returned 0 results on google.
Any advice would help, I'm afraid I've been thrown in at the deep end here!
The VForce inlines are functional, they must ultimately return a value, be that a simple value or an invocation point for a piece of server side code. They do not support imperative coding and they are being resolved server-side (long before JS comes into play). in that regard the IF(condition,valuetrue,valuefalse) is an equivalent to IF..THEN..ELSE..ENDIF
You are off course free to chain any number of functions provided there is no type mismatch, meaning your valuetrue could itself be a function, including being an IF function itself.
Usually when people encounter these kind of problems there is always a workaround by using a slightly different approach. It all depends on what you are trying to do here...
I stumbled upon this question while doing some work myself on visualforce pages. Anyway, if anybody else sees this question they should know that there's no need to use the complicated nested IF statements, now there is a CASE function available in Salesforce.
Documentation - https://developer.salesforce.com/docs/atlas.en-us.198.0.pages.meta/pages/pages_variables_functions.htm
{!CASE(Opportunity.StageName,
"Prospecting", "1",
"Needs Analysis", "2",
"Proposal/Price Quote", "3",
"default val")} <!-- the last one returns if none of the previous results matched -->

Resources