Skip to content

Commit

Permalink
Consider supporting isTrue, isFalse query method keywords
Browse files Browse the repository at this point in the history
Closes gh-39
  • Loading branch information
evgeniycheban committed Jan 9, 2025
1 parent f2494f3 commit eac83e4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ protected Query<?> and(Part part, Query<?> base, Iterator<Object> parameters) {
case IS_NOT_NULL -> base.not().isNull(indexName);
case IS_NULL -> base.isNull(indexName);
case SIMPLE_PROPERTY -> where(base, indexName, Condition.EQ, parameters);
case NEGATING_SIMPLE_PROPERTY -> base.not().where(indexName, Condition.EQ, parameters);
case BETWEEN -> base.where(indexName, Condition.RANGE, getParameterValues(indexName, parameters.next(), parameters.next()));
case NEGATING_SIMPLE_PROPERTY -> where(base.not(), indexName, Condition.EQ, parameters);
case BETWEEN -> base.where(indexName, Condition.RANGE, getParameterValues(indexName, parameters.next(), parameters.next()));
case TRUE -> base.where(indexName, Condition.EQ, true);
case FALSE -> base.where(indexName, Condition.EQ, false);
default -> throw new IllegalArgumentException("Unsupported keyword!");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,26 @@ public void findAllByIdBetween() {
.containsExactly(80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L);
}

@Test
public void findByActiveIsTrue() {
this.repository.save(new TestItem(1L, true));
this.repository.save(new TestItem(2L, true));
this.repository.save(new TestItem(3L, false));
this.repository.save(new TestItem(4L, false));
List<TestItem> foundItems = this.repository.findByActiveIsTrue();
assertThat(foundItems.stream().map(TestItem::getId).toList()).containsOnly(1L, 2L);
}

@Test
public void findByActiveIsFalse() {
this.repository.save(new TestItem(1L, true));
this.repository.save(new TestItem(2L, true));
this.repository.save(new TestItem(3L, false));
this.repository.save(new TestItem(4L, false));
List<TestItem> foundItems = this.repository.findByActiveIsFalse();
assertThat(foundItems.stream().map(TestItem::getId).toList()).containsOnly(3L, 4L);
}

@Configuration
@EnableReindexerRepositories(basePackageClasses = TestItemReindexerRepository.class, considerNestedRepositories = true)
@EnableTransactionManagement
Expand Down Expand Up @@ -1386,6 +1406,10 @@ Optional<TestItem> findOneSqlByNameAndValueManyParams(String name1, String name2
<T> List<T> findDistinctByIdIn(List<Long> ids, Class<T> type);

List<TestItem> findAllByIdBetween(Long start, Long end);

List<TestItem> findByActiveIsTrue();

List<TestItem> findByActiveIsFalse();
}

@Namespace(name = NAMESPACE_NAME)
Expand All @@ -1408,6 +1432,9 @@ public static class TestItem {
@Reindex(name = "testEnumOrdinal")
private TestEnum testEnumOrdinal;

@Reindex(name = "active")
private boolean active;

public TestItem() {
}

Expand All @@ -1417,6 +1444,11 @@ public TestItem(Long id, String name, String value) {
this.value = value;
}

public TestItem(Long id, boolean active) {
this.id = id;
this.active = active;
}

public TestItem(Long id, String name, String value, TestEnum testEnumString, TestEnum testEnumOrdinal) {
this.id = id;
this.name = name;
Expand Down Expand Up @@ -1465,19 +1497,27 @@ public void setTestEnumOrdinal(TestEnum testEnumOrdinal) {
this.testEnumOrdinal = testEnumOrdinal;
}

public boolean isActive() {
return this.active;
}

public void setActive(boolean active) {
this.active = active;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
TestItem testItem = (TestItem) o;
return Objects.equals(id, testItem.id) && Objects.equals(name, testItem.name) && Objects.equals(value, testItem.value)
&& testEnumString == testItem.testEnumString && testEnumOrdinal == testItem.testEnumOrdinal;
&& testEnumString == testItem.testEnumString && testEnumOrdinal == testItem.testEnumOrdinal && active == testItem.active;
}

@Override
public int hashCode() {
return Objects.hash(id, name, value, testEnumString, testEnumOrdinal);
return Objects.hash(id, name, value, testEnumString, testEnumOrdinal, active);
}

@Override
Expand All @@ -1488,6 +1528,7 @@ public String toString() {
", value='" + this.value + '\'' +
", testEnumString=" + this.testEnumString +
", testEnumOrdinal=" + this.testEnumOrdinal +
", active=" + this.active +
'}';
}

Expand Down

0 comments on commit eac83e4

Please sign in to comment.