Skip to content

Commit

Permalink
Merge pull request #194 from MrThreepwood/main
Browse files Browse the repository at this point in the history
Fixing in treating empty lists as a conjunction.
  • Loading branch information
cj848 authored Feb 21, 2023
2 parents 584169d + edab582 commit 0b73c8c
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class InValueSpec<T>(
query: AbstractQuery<*>,
criteriaBuilder: CriteriaBuilder
): Predicate {
if (rights.isEmpty()) return criteriaBuilder.conjunction()
if (rights.isEmpty()) return criteriaBuilder.disjunction()

return criteriaBuilder.`in`(left.toCriteriaExpression(froms, query, criteriaBuilder)).apply {
rights.forEach { value(it) }
Expand All @@ -25,7 +25,7 @@ data class InValueSpec<T>(
query: CriteriaUpdate<*>,
criteriaBuilder: CriteriaBuilder
): Predicate {
if (rights.isEmpty()) return criteriaBuilder.conjunction()
if (rights.isEmpty()) return criteriaBuilder.disjunction()

return criteriaBuilder.`in`(left.toCriteriaExpression(froms, query, criteriaBuilder)).apply {
rights.forEach { value(it) }
Expand All @@ -37,7 +37,7 @@ data class InValueSpec<T>(
query: CriteriaDelete<*>,
criteriaBuilder: CriteriaBuilder
): Predicate {
if (rights.isEmpty()) return criteriaBuilder.conjunction()
if (rights.isEmpty()) return criteriaBuilder.disjunction()

return criteriaBuilder.`in`(left.toCriteriaExpression(froms, query, criteriaBuilder)).apply {
rights.forEach { value(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ internal class InValueSpecTest : WithKotlinJdslAssertions {
// given
val leftExpressionSpec: ExpressionSpec<Int> = mockk()

val emptyPredicate: Predicate = mockk()
val falsePredicate: Predicate = mockk()

every { criteriaBuilder.conjunction() } returns emptyPredicate
every { criteriaBuilder.disjunction() } returns falsePredicate

// when
val actual = InValueSpec(leftExpressionSpec, emptyList())
.toCriteriaPredicate(froms, query, criteriaBuilder)

// then
assertThat(actual).isEqualTo(emptyPredicate)
assertThat(actual).isEqualTo(falsePredicate)

verify(exactly = 1) {
criteriaBuilder.conjunction()
criteriaBuilder.disjunction()
}

confirmVerified(froms, query, criteriaBuilder)
Expand Down Expand Up @@ -126,19 +126,19 @@ internal class InValueSpecTest : WithKotlinJdslAssertions {
// given
val leftExpressionSpec: ExpressionSpec<Int> = mockk()

val emptyPredicate: Predicate = mockk()
val falsePredicate: Predicate = mockk()

every { criteriaBuilder.conjunction() } returns emptyPredicate
every { criteriaBuilder.disjunction() } returns falsePredicate

// when
val actual = InValueSpec(leftExpressionSpec, emptyList())
.toCriteriaPredicate(froms, updateQuery, criteriaBuilder)

// then
assertThat(actual).isEqualTo(emptyPredicate)
assertThat(actual).isEqualTo(falsePredicate)

verify(exactly = 1) {
criteriaBuilder.conjunction()
criteriaBuilder.disjunction()
}

confirmVerified(froms, updateQuery, criteriaBuilder)
Expand Down Expand Up @@ -183,19 +183,19 @@ internal class InValueSpecTest : WithKotlinJdslAssertions {
// given
val leftExpressionSpec: ExpressionSpec<Int> = mockk()

val emptyPredicate: Predicate = mockk()
val falsePredicate: Predicate = mockk()

every { criteriaBuilder.conjunction() } returns emptyPredicate
every { criteriaBuilder.disjunction() } returns falsePredicate

// when
val actual = InValueSpec(leftExpressionSpec, emptyList())
.toCriteriaPredicate(froms, deleteQuery, criteriaBuilder)

// then
assertThat(actual).isEqualTo(emptyPredicate)
assertThat(actual).isEqualTo(falsePredicate)

verify(exactly = 1) {
criteriaBuilder.conjunction()
criteriaBuilder.disjunction()
}

confirmVerified(froms, deleteQuery, criteriaBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data class InValueSpec<T>(
query: AbstractQuery<*>,
criteriaBuilder: CriteriaBuilder
): Predicate {
if (rights.isEmpty()) return criteriaBuilder.conjunction()
if (rights.isEmpty()) return criteriaBuilder.disjunction()

return criteriaBuilder.`in`(left.toCriteriaExpression(froms, query, criteriaBuilder)).apply {
rights.forEach { value(it) }
Expand All @@ -25,7 +25,7 @@ data class InValueSpec<T>(
query: CriteriaUpdate<*>,
criteriaBuilder: CriteriaBuilder
): Predicate {
if (rights.isEmpty()) return criteriaBuilder.conjunction()
if (rights.isEmpty()) return criteriaBuilder.disjunction()

return criteriaBuilder.`in`(left.toCriteriaExpression(froms, query, criteriaBuilder)).apply {
rights.forEach { value(it) }
Expand All @@ -37,7 +37,7 @@ data class InValueSpec<T>(
query: CriteriaDelete<*>,
criteriaBuilder: CriteriaBuilder
): Predicate {
if (rights.isEmpty()) return criteriaBuilder.conjunction()
if (rights.isEmpty()) return criteriaBuilder.disjunction()

return criteriaBuilder.`in`(left.toCriteriaExpression(froms, query, criteriaBuilder)).apply {
rights.forEach { value(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ internal class InValueSpecTest : WithKotlinJdslAssertions {
// given
val leftExpressionSpec: ExpressionSpec<Int> = mockk()

val emptyPredicate: Predicate = mockk()
val falsePredicate: Predicate = mockk()

every { criteriaBuilder.conjunction() } returns emptyPredicate
every { criteriaBuilder.disjunction() } returns falsePredicate

// when
val actual = InValueSpec(leftExpressionSpec, emptyList())
.toCriteriaPredicate(froms, query, criteriaBuilder)

// then
assertThat(actual).isEqualTo(emptyPredicate)
assertThat(actual).isEqualTo(falsePredicate)

verify(exactly = 1) {
criteriaBuilder.conjunction()
criteriaBuilder.disjunction()
}

confirmVerified(froms, query, criteriaBuilder)
Expand Down Expand Up @@ -126,19 +126,19 @@ internal class InValueSpecTest : WithKotlinJdslAssertions {
// given
val leftExpressionSpec: ExpressionSpec<Int> = mockk()

val emptyPredicate: Predicate = mockk()
val falsePredicate: Predicate = mockk()

every { criteriaBuilder.conjunction() } returns emptyPredicate
every { criteriaBuilder.disjunction() } returns falsePredicate

// when
val actual = InValueSpec(leftExpressionSpec, emptyList())
.toCriteriaPredicate(froms, updateQuery, criteriaBuilder)

// then
assertThat(actual).isEqualTo(emptyPredicate)
assertThat(actual).isEqualTo(falsePredicate)

verify(exactly = 1) {
criteriaBuilder.conjunction()
criteriaBuilder.disjunction()
}

confirmVerified(froms, updateQuery, criteriaBuilder)
Expand Down Expand Up @@ -183,19 +183,19 @@ internal class InValueSpecTest : WithKotlinJdslAssertions {
// given
val leftExpressionSpec: ExpressionSpec<Int> = mockk()

val emptyPredicate: Predicate = mockk()
val falsePredicate: Predicate = mockk()

every { criteriaBuilder.conjunction() } returns emptyPredicate
every { criteriaBuilder.disjunction() } returns falsePredicate

// when
val actual = InValueSpec(leftExpressionSpec, emptyList())
.toCriteriaPredicate(froms, deleteQuery, criteriaBuilder)

// then
assertThat(actual).isEqualTo(emptyPredicate)
assertThat(actual).isEqualTo(falsePredicate)

verify(exactly = 1) {
criteriaBuilder.conjunction()
criteriaBuilder.disjunction()
}

confirmVerified(froms, deleteQuery, criteriaBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ abstract class AbstractCriteriaDeleteIntegrationTest : AbstractCriteriaQueryDslI
assertThat(query.resultList).isEmpty()
}

@Test
fun deleteEmptyList() {
// when
val address1 = orderAddress { }

entityManager.run {
persistAll(address1)
flushAndClear()
}

queryFactory.deleteQuery<OrderAddress> {
where(col(OrderAddress::id).`in`(emptyList<Long>()))
}.executeUpdate()

// when
val query = queryFactory.selectQuery<OrderAddress> {
select(entity(OrderAddress::class))
from(entity(OrderAddress::class))
where(col(OrderAddress::id).equal(address1.id))
associate(OrderAddress::class, Address::class, on(OrderAddress::address))
}

// then
assertThat(query.resultList).singleElement()
}

@Test
fun deleteEmbedded() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@ abstract class AbstractCriteriaDeleteIntegrationTest<S> : CriteriaQueryDslIntegr
assertThat(query).isEmpty()
}

@Test
fun deleteInEmptyList() = runBlocking {
// when
val address1 = orderAddress { }

persistAll(address1)

withFactory { queryFactory ->
queryFactory.deleteQuery<OrderAddress> {
where(col(OrderAddress::id).`in`(emptyList<Long>()))
}.executeUpdate()
}

// when
val query = withFactory { queryFactory ->
queryFactory.listQuery<OrderAddress> {
select(entity(OrderAddress::class))
from(entity(OrderAddress::class))
where(col(OrderAddress::id).equal(address1.id))
associate(OrderAddress::class, Address::class, on(OrderAddress::address))
}
}

// then
assertThat(query).singleElement()
}

@Test
fun deleteEmbedded() = runBlocking {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@ abstract class AbstractCriteriaDeleteIntegrationTest<S> : CriteriaQueryDslIntegr
assertThat(query).isEmpty()
}

@Test
fun deleteInEmptyList() = runBlocking {
// when
val address1 = orderAddress { }

persistAll(address1)

withFactory { queryFactory ->
queryFactory.deleteQuery<OrderAddress> {
where(col(OrderAddress::id).`in`(emptyList<Long>()))
}.executeUpdate()
}

// when
val query = withFactory { queryFactory ->
queryFactory.listQuery<OrderAddress> {
select(entity(OrderAddress::class))
from(entity(OrderAddress::class))
where(col(OrderAddress::id).equal(address1.id))
associate(OrderAddress::class, Address::class, on(OrderAddress::address))
}
}

// then
assertThat(query).singleElement()
}

@Test
fun deleteEmbedded() = runBlocking {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ abstract class AbstractCriteriaDeleteIntegrationTest : AbstractCriteriaQueryDslI
assertThat(query.resultList).isEmpty()
}

@Test
fun deleteEmptyList() {
// when
val address1 = orderAddress { }

entityManager.run {
persistAll(address1)
flushAndClear()
}

queryFactory.deleteQuery<OrderAddress> {
where(col(OrderAddress::id).`in`(emptyList<Long>()))
}.executeUpdate()

// when
val query = queryFactory.selectQuery<OrderAddress> {
select(entity(OrderAddress::class))
from(entity(OrderAddress::class))
where(col(OrderAddress::id).equal(address1.id))
associate(OrderAddress::class, Address::class, on(OrderAddress::address))
}

// then
assertThat(query.resultList).singleElement()
}

@Test
fun deleteEmbedded() {
// given
Expand Down

0 comments on commit 0b73c8c

Please sign in to comment.