Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider supporting isTrue, isFalse query method keywords #40

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading