Skip to content

Commit

Permalink
feat(null): adding operators ISNULL and NOTNULL (#32)
Browse files Browse the repository at this point in the history
* feat(isnull-operator): implement ISNULL operator
  • Loading branch information
Yves-MENGELLE-OF authored Mar 27, 2024
1 parent 4fbc96e commit 86140ea
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions querydsl-postgrest/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.ouestfrance.querydsl</groupId>
Expand All @@ -13,7 +14,7 @@
<dependency>
<groupId>fr.ouestfrance.querydsl</groupId>
<artifactId>querydsl</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

import fr.ouestfrance.querydsl.FilterOperation;
import fr.ouestfrance.querydsl.postgrest.model.Filter;
import fr.ouestfrance.querydsl.postgrest.model.impl.QueryFilter;

public class IsNullMapper extends AbstractMapper {

@Override
public Filter getFilter(String field, Object value) {
return QueryFilter.of(field, Boolean.TRUE.equals(value) ? Operators.IS : Operators.IS_NOT, null);
}

@Override
public Class<? extends FilterOperation> operation() {
return FilterOperation.ISNULL.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public final class Operators {
* is operation
*/
public static final String IS = "is";
/**
* is not operation
*/
public static final String IS_NOT = "not.is";
/**
* Contains operation for JSON/Range datatype
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fr.ouestfrance.querydsl.postgrest.mappers;

import fr.ouestfrance.querydsl.FilterOperation;
import fr.ouestfrance.querydsl.model.SimpleFilter;
import fr.ouestfrance.querydsl.postgrest.builders.QueryFilterVisitor;
import fr.ouestfrance.querydsl.postgrest.model.Filter;
import org.junit.jupiter.api.Test;

import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class IsNullMapperTest {

@Test
void shouldMapIsNull() {
IsNullMapper mapper = new IsNullMapper();
assertNotNull(mapper.operation());
Stream.of(Boolean.TRUE, Boolean.FALSE).forEach(value -> {
Filter result = mapper.map(new SimpleFilter("name", FilterOperation.ISNULL.class, false, null), value);
assertNotNull(result);
QueryFilterVisitor visitor = new QueryFilterVisitor();
result.accept(visitor);
assertNotNull(visitor.getValue());
assertEquals(Boolean.TRUE.equals(value) ? "is.null" : "not.is.null", visitor.getValue());
});

}
}

0 comments on commit 86140ea

Please sign in to comment.