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

Update InListOps.kt #2261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -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