Skip to content

Commit

Permalink
Properly handle different types and null when querying for variable n…
Browse files Browse the repository at this point in the history
…ot equals
  • Loading branch information
filiphr committed Sep 1, 2020
1 parent 9822119 commit 0549bdd
Show file tree
Hide file tree
Showing 18 changed files with 1,501 additions and 79 deletions.
Expand Up @@ -519,17 +519,16 @@
<!-- Match-all variable-names when name is null -->
and A${index}.NAME_= #{queryVariableValue.name}
</if>
<if test="!queryVariableValue.type.equals('null')">
<!-- When operator is not-equals or type of value is null, type doesn't matter! -->
<if test="queryVariableValue.needsTypeCheck()">
and A${index}.TYPE_ = #{queryVariableValue.type}
</if>
<if test="queryVariableValue.textValue != null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
<choose>
<when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">
and lower(A${index}.TEXT_)
and (lower(A${index}.TEXT_)
</when>
<otherwise>
and A${index}.TEXT_
and (A${index}.TEXT_
</otherwise>
</choose>
<choose>
Expand All @@ -540,6 +539,10 @@
<choose>
<when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
</choose>
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.TEXT_ is null
</if>
)
</if>
<if test="queryVariableValue.textValue2 != null">
and A${index}.TEXT2_
Expand All @@ -553,14 +556,22 @@
</choose>
</if>
<if test="queryVariableValue.longValue != null">
and A${index}.LONG_
and (A${index}.LONG_
<include refid="variableOperator" />
#{queryVariableValue.longValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.LONG_ is null
</if>
)
</if>
<if test="queryVariableValue.doubleValue != null">
and A${index}.DOUBLE_
and (A${index}.DOUBLE_
<include refid="variableOperator" />
#{queryVariableValue.doubleValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.DOUBLE_ is null
</if>
)
</if>
<!-- Null variable type -->
<if test="queryVariableValue.textValue == null &amp;&amp; queryVariableValue.textValue2 == null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
Expand Down Expand Up @@ -696,17 +707,16 @@
<!-- Match-all variable-names when name is null -->
and A_OR${orIndex}.NAME_= #{queryVariableValue.name}
</if>
<if test="!queryVariableValue.type.equals('null')">
<!-- When operator is not-equals or type of value is null, type doesn't matter! -->
<if test="queryVariableValue.needsTypeCheck()">
and A_OR${orIndex}.TYPE_ = #{queryVariableValue.type}
</if>
<if test="queryVariableValue.textValue != null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
<choose>
<when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">
and lower(A_OR${orIndex}.TEXT_)
and (lower(A_OR${orIndex}.TEXT_)
</when>
<otherwise>
and A_OR${orIndex}.TEXT_
and (A_OR${orIndex}.TEXT_
</otherwise>
</choose>
<choose>
Expand All @@ -723,6 +733,10 @@
${wildcardEscapeClause}
</when>
</choose>
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A_OR${index}.TEXT_ is null
</if>
)
</if>
<if test="queryVariableValue.textValue2 != null">
and A_OR${orIndex}.TEXT2_
Expand All @@ -738,14 +752,22 @@
</choose>
</if>
<if test="queryVariableValue.longValue != null">
and A_OR${orIndex}.LONG_
and (A_OR${orIndex}.LONG_
<include refid="variableOperator"/>
#{queryVariableValue.longValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A_OR${index}.LONG_ is null
</if>
)
</if>
<if test="queryVariableValue.doubleValue != null">
and A_OR${orIndex}.DOUBLE_
and (A_OR${orIndex}.DOUBLE_
<include refid="variableOperator"/>
#{queryVariableValue.doubleValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A_OR${index}.DOUBLE_ is null
</if>
)
</if>
<!-- Null variable type -->
<if test="queryVariableValue.textValue == null &amp;&amp; queryVariableValue.textValue2 == null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
Expand Down
Expand Up @@ -408,17 +408,16 @@
<!-- Match-all variable-names when name is null -->
and A${index}.NAME_= #{queryVariableValue.name}
</if>
<if test="!queryVariableValue.type.equals('null')">
<!-- When operator is not-equals or type of value is null, type doesn't matter! -->
<if test="queryVariableValue.needsTypeCheck()">
and A${index}.VAR_TYPE_ = #{queryVariableValue.type}
</if>
<if test="queryVariableValue.textValue != null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
<choose>
<when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">
and lower(A${index}.TEXT_)
and (lower(A${index}.TEXT_)
</when>
<otherwise>
and A${index}.TEXT_
and (A${index}.TEXT_
</otherwise>
</choose>
<choose>
Expand All @@ -429,6 +428,10 @@
<choose>
<when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
</choose>
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.TEXT_ is null
</if>
)
</if>
<if test="queryVariableValue.textValue2 != null">
and A${index}.TEXT2_
Expand All @@ -442,14 +445,22 @@
</choose>
</if>
<if test="queryVariableValue.longValue != null">
and A${index}.LONG_
and (A${index}.LONG_
<include refid="variableOperator" />
#{queryVariableValue.longValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.LONG_ is null
</if>
)
</if>
<if test="queryVariableValue.doubleValue != null">
and A${index}.DOUBLE_
and (A${index}.DOUBLE_
<include refid="variableOperator" />
#{queryVariableValue.doubleValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.DOUBLE_ is null
</if>
)
</if>
<!-- Null variable type -->
<if test="queryVariableValue.textValue == null &amp;&amp; queryVariableValue.textValue2 == null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
Expand Down Expand Up @@ -518,17 +529,16 @@
<!-- Match-all variable-names when name is null -->
and A_OR${orIndex}.NAME_= #{queryVariableValue.name}
</if>
<if test="!queryVariableValue.type.equals('null')">
<!-- When operator is not-equals or type of value is null, type doesn't matter! -->
<if test="queryVariableValue.needsTypeCheck()">
and A_OR${orIndex}.VAR_TYPE_ = #{queryVariableValue.type}
</if>
<if test="queryVariableValue.textValue != null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
<choose>
<when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">
and lower(A_OR${orIndex}.TEXT_)
and (lower(A_OR${orIndex}.TEXT_)
</when>
<otherwise>
and A_OR${orIndex}.TEXT_
and (A_OR${orIndex}.TEXT_
</otherwise>
</choose>
<choose>
Expand All @@ -541,6 +551,10 @@
<choose>
<when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
</choose>
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A_OR${index}.TEXT_ is null
</if>
)
</if>
<if test="queryVariableValue.textValue2 != null">
and A_OR${orIndex}.TEXT2_
Expand All @@ -554,14 +568,22 @@
</choose>
</if>
<if test="queryVariableValue.longValue != null">
and A_OR${orIndex}.LONG_
and (A_OR${orIndex}.LONG_
<include refid="variableOperator" />
#{queryVariableValue.longValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A_OR${index}.LONG_ is null
</if>
)
</if>
<if test="queryVariableValue.doubleValue != null">
and A_OR${index}.DOUBLE_
and (A_OR${index}.DOUBLE_
<include refid="variableOperator" />
#{queryVariableValue.doubleValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A_OR${index}.DOUBLE_ is null
</if>
)
</if>
<!-- Null variable type -->
<if test="queryVariableValue.textValue == null &amp;&amp; queryVariableValue.textValue2 == null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
Expand Down
Expand Up @@ -552,17 +552,16 @@
<!-- Match-all variable-names when name is null -->
and A${index}.NAME_= #{queryVariableValue.name}
</if>
<if test="!queryVariableValue.type.equals('null')">
<!-- When operator is not-equals or type of value is null, type doesn't matter! -->
<if test="queryVariableValue.needsTypeCheck()">
and A${index}.TYPE_ = #{queryVariableValue.type}
</if>
<if test="queryVariableValue.textValue != null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
<choose>
<when test="queryVariableValue.operator.equals('EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">
and lower(A${index}.TEXT_)
and (lower(A${index}.TEXT_)
</when>
<otherwise>
and A${index}.TEXT_
and (A${index}.TEXT_
</otherwise>
</choose>
<choose>
Expand All @@ -573,6 +572,10 @@
<choose>
<when test="queryVariableValue.operator.equals('LIKE') || queryVariableValue.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
</choose>
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.TEXT_ is null
</if>
)
</if>
<if test="queryVariableValue.textValue2 != null">
and A${index}.TEXT2_
Expand All @@ -586,14 +589,22 @@
</choose>
</if>
<if test="queryVariableValue.longValue != null">
and A${index}.LONG_
and (A${index}.LONG_
<include refid="variableOperator" />
#{queryVariableValue.longValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.LONG_ is null
</if>
)
</if>
<if test="queryVariableValue.doubleValue != null">
and A${index}.DOUBLE_
and (A${index}.DOUBLE_
<include refid="variableOperator" />
#{queryVariableValue.doubleValue}
<if test="queryVariableValue.operator.equals('NOT_EQUALS') || queryVariableValue.operator.equals('NOT_EQUALS_IGNORE_CASE')">
or A${index}.DOUBLE_ is null
</if>
)
</if>
<!-- Null variable type -->
<if test="queryVariableValue.textValue == null &amp;&amp; queryVariableValue.textValue2 == null &amp;&amp; queryVariableValue.longValue == null &amp;&amp; queryVariableValue.doubleValue == null">
Expand Down

0 comments on commit 0549bdd

Please sign in to comment.