Skip to content

Commit

Permalink
Update InListOps.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgCantor committed Sep 26, 2024
1 parent 0b952dd commit 3ac5dfe
Showing 1 changed file with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,34 @@ abstract class InListOrNotInListBaseOp<V>(

override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder {
val iterator = list.iterator()
if (!iterator.hasNext()) {
if (isInList) {
+FALSE
} else {
+TRUE
}
val hasElements = iterator.hasNext()

if (!hasElements) {
+if (isInList) FALSE else TRUE
return
}

if (columnTypes.size == 1) {
append(columnTypes.first())
} else {
val singleColumn = columnTypes.singleOrNull()
if (singleColumn != null) {
append(singleColumn)
} else {
columnTypes.appendTo(prefix = "(", postfix = ")") { +it }
}
columnTypes.appendTo(prefix = "(", postfix = ")") { +it }
}

val firstValue = iterator.next()
val firstValue = iterator.next()
appendOperator(isInList)
registerValues(firstValue)

if (!iterator.hasNext() && currentDialectIfAvailable !is OracleDialect) {
when {
isInList -> append(" = ")
else -> append(" != ")
}
registerValues(firstValue)
} else {
when {
isInList -> append(" IN (")
else -> append(" NOT IN (")
}
registerValues(firstValue)
iterator.forEach { value ->
append(", ")
registerValues(value)
}
append(')')
if (hasElements) {
iterator.forEach { value ->
append(", ")
registerValues(value)
}
}
append(')')
}
}

private fun QueryBuilder.appendOperator(isInList: Boolean) {
append(if (isInList) " IN (" else " NOT IN (")
}

protected abstract fun QueryBuilder.registerValues(values: V)
Expand Down

0 comments on commit 3ac5dfe

Please sign in to comment.