mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Add criteria operator NOT_EQUALS_OR_IS_NULL
This commit is contained in:
@ -30,6 +30,7 @@ public enum QCriteriaOperator
|
||||
{
|
||||
EQUALS,
|
||||
NOT_EQUALS,
|
||||
NOT_EQUALS_OR_IS_NULL,
|
||||
IN,
|
||||
NOT_IN,
|
||||
IS_NULL_OR_IN,
|
||||
|
@ -131,6 +131,7 @@ public class BackendQueryFilterUtils
|
||||
{
|
||||
case EQUALS -> testEquals(criterion, value);
|
||||
case NOT_EQUALS -> !testEquals(criterion, value);
|
||||
case NOT_EQUALS_OR_IS_NULL -> !testEquals(criterion, value) || testBlank(criterion, value);
|
||||
case IN -> testIn(criterion, value);
|
||||
case NOT_IN -> !testIn(criterion, value);
|
||||
case IS_BLANK -> testBlank(criterion, value);
|
||||
|
@ -113,6 +113,13 @@ class BackendQueryFilterUtilsTest
|
||||
assertFalse(BackendQueryFilterUtils.doesCriteriaMatch(new QFilterCriteria("f", QCriteriaOperator.NOT_IN, "A", "B"), "f", "B"));
|
||||
assertTrue(BackendQueryFilterUtils.doesCriteriaMatch(new QFilterCriteria("f", QCriteriaOperator.NOT_IN, List.of()), "f", "A"));
|
||||
assertTrue(BackendQueryFilterUtils.doesCriteriaMatch(new QFilterCriteria("f", QCriteriaOperator.NOT_IN, ListBuilder.of(null)), "f", "A"));
|
||||
|
||||
///////////////////////////
|
||||
// NOT_EQUALS_OR_IS_NULL //
|
||||
///////////////////////////
|
||||
assertFalse(BackendQueryFilterUtils.doesCriteriaMatch(new QFilterCriteria("f", QCriteriaOperator.NOT_EQUALS_OR_IS_NULL, "A"), "f", "A"));
|
||||
assertTrue(BackendQueryFilterUtils.doesCriteriaMatch(new QFilterCriteria("f", QCriteriaOperator.NOT_EQUALS_OR_IS_NULL, "A"), "f", "B"));
|
||||
assertTrue(BackendQueryFilterUtils.doesCriteriaMatch(new QFilterCriteria("f", QCriteriaOperator.NOT_EQUALS_OR_IS_NULL, "A"), "f", null));
|
||||
}
|
||||
|
||||
|
||||
|
@ -534,6 +534,12 @@ public abstract class AbstractRDBMSAction implements QActionInterface
|
||||
expectedNoOfParams = 1;
|
||||
break;
|
||||
}
|
||||
case NOT_EQUALS_OR_IS_NULL:
|
||||
{
|
||||
clause += " != ? OR " + column + " IS NULL ";
|
||||
expectedNoOfParams = 1;
|
||||
break;
|
||||
}
|
||||
case IN:
|
||||
{
|
||||
if(values.isEmpty())
|
||||
|
@ -148,6 +148,39 @@ public class RDBMSQueryActionTest extends RDBMSActionTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
public void testNotEqualsOrIsNullQuery() throws QException
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 5 rows, 1 has a null salary, 1 has 1,000,000. //
|
||||
// first confirm that query for != returns 3 (the null does NOT come back) //
|
||||
// then, confirm that != or is null gives the (more humanly expected) 4. //
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
QueryInput queryInput = initQueryRequest();
|
||||
queryInput.setFilter(new QQueryFilter()
|
||||
.withCriteria(new QFilterCriteria()
|
||||
.withFieldName("annualSalary")
|
||||
.withOperator(QCriteriaOperator.NOT_EQUALS)
|
||||
.withValues(List.of(1_000_000))));
|
||||
QueryOutput queryOutput = new RDBMSQueryAction().execute(queryInput);
|
||||
assertEquals(3, queryOutput.getRecords().size(), "Expected # of rows");
|
||||
|
||||
queryInput = initQueryRequest();
|
||||
queryInput.setFilter(new QQueryFilter()
|
||||
.withCriteria(new QFilterCriteria()
|
||||
.withFieldName("annualSalary")
|
||||
.withOperator(QCriteriaOperator.NOT_EQUALS_OR_IS_NULL)
|
||||
.withValues(List.of(1_000_000))));
|
||||
queryOutput = new RDBMSQueryAction().execute(queryInput);
|
||||
assertEquals(4, queryOutput.getRecords().size(), "Expected # of rows");
|
||||
Assertions.assertTrue(queryOutput.getRecords().stream().noneMatch(r -> Objects.equals(1_000_000, r.getValueInteger("annualSalary"))), "Should NOT find expected salary");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user