Condition
Condition is a command which contains some expression and returns boolean result. This result can be used in any other command as a condition whether to execute the command or skip it's execution.
<condition>
Required parameters:
- comment
- name - string
- spel - string, expression
We are using Spring Expression Language (SpEL) to create a boolean expression, so we highly recommend to familiarize with their documentation.
Usage example:
We have a variable which will get the amount of "History of Time" books we have in our stock.
<var comment="Create var for 'History of Time' books amount" name="HOT_AMOUNT">
<sql dbType="MYSQL" alias="SHOPIZER">
<query>
SELECT amount
FROM books
WHERE book_name = 'History of Time'
</query>
</sql>
</var>
This condition will check if HOT_AMOUNT value will be lower then the certain threshold, and if it is not, then the step with this condition won't be executed.
<condition comment="if amount of books in store is lower then 25"
name="DB_RESULT"
spel="{{HOT_AMOUNT}} < 25"/>
In "condition" filed you need to insert the name of <condition> command.
<mysql comment="Execute some command"
alias="SHOPIZER"
file="expected_1.json"
condition="DB_RESULT">
<query>SOME_QUERY</query>
</mysql>
If condition value=true, then <mysql> command will be executed, if 'false', then it will be skipped.
- AND operator which syntactically looks like
&&
. The use of this operator means that in order to perform the step, the both operands (conditions) combined by this operator must be true. - OR operator which syntactically looks like || . The use of this operator means that in order to perform a step, one of the operands (conditions) combined by this operator must be true.
Usage example: we have two conditions, one of which is true, the other is false.
<condition comment="Create fist condition that is true" name="firstCondition" spel="1 == 1"/>
<condition comment="Create second condition that is false" name="secondCondition" spel="1 == 10"/>
Let's consider an example of using these conditions using AND and OR operators:
<mysql comment="Check impossibility to conduct INSERT query using TRUE, FALSE conditions,'AND' operator"
condition="firstCondition && secondCondition"
alias="MYSQL_0"
file="expected_10.json">
<query>
INSERT INTO news (id, newsname, newsnumber, active, createdat)
VALUES (2, 'News2', 2, true, '2023-04-21 10:48:26.096000')
</query>
</mysql>
<mysql comment="Check ability to conduct INSERT query using TRUE, FALSE conditions,'OR' operator"
condition="firstCondition || secondCondition"
alias="MYSQL_0"
file="expected_11.json">
<query>
INSERT INTO news (id, newsname, newsnumber, active, createdat)
VALUES (3, 'News3', 3, true, '2023-04-21 10:48:26.096000')
</query>
</mysql>
In the first case, when using the "TRUE" and "FALSE" conditions and the "&&" operator, the step will not be executed for the reason that the result of the Boolean expression "true AND false" will be FALSE.
In the second case, when using the "TRUE" and "FALSE" conditions and the "||" operator, the step will be executed for the reason that the result of the Boolean expression "true OR false" will be TRUE.
It is possible to use AND and OR operators at the same time:
condition="firstCondition && secondCondition || thirdCondition"
It is also possible to use Boolean expressions instead of separately created conditions. The example below uses the boolean expression "1 == 1":
<mysql comment="Check impossibility to conduct INSERT query using TRUE, FALSE conditions,'AND' operator"
condition="1 == 1 && secondCondition"
alias="MYSQL_0"
file="expected_10.json">
<query>
INSERT INTO news (id, newsname, newsnumber, active, createdat)
VALUES (2, 'News2', 2, true, '2023-04-21 10:48:26.096000')
</query>
</mysql>