-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Extract query statement iterator logic to common class
- Add internal StatementIterator class with common functionality across ExplainQuery, AbstractQuery, and ReturningStatement
- Loading branch information
Showing
5 changed files
with
57 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/statements/StatementIterator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jetbrains.exposed.sql.statements | ||
|
||
import org.jetbrains.exposed.sql.transactions.TransactionManager | ||
import java.sql.ResultSet | ||
|
||
internal abstract class StatementIterator<T, RR>( | ||
protected val result: ResultSet | ||
) : Iterator<RR> { | ||
protected abstract val fieldIndex: Map<T, Int> | ||
|
||
protected abstract fun createResultRow(): RR | ||
|
||
protected var hasNext = false | ||
set(value) { | ||
field = value | ||
if (!field) { | ||
val statement = result.statement | ||
result.close() | ||
statement?.close() | ||
TransactionManager.current().openResultSetsCount-- | ||
} | ||
} | ||
|
||
override fun hasNext(): Boolean = hasNext | ||
|
||
override operator fun next(): RR { | ||
if (!hasNext) throw NoSuchElementException() | ||
val resultRow = createResultRow() | ||
hasNext = result.next() | ||
return resultRow | ||
} | ||
} |