Now really safe wrappers for queries executing
This commit is contained in:
parent
e1e014cd1d
commit
b6bc3c1214
@ -5,25 +5,99 @@ package ru.landgrafhomyak.db.serdha0.user_commons.executors
|
|||||||
import kotlin.contracts.InvocationKind
|
import kotlin.contracts.InvocationKind
|
||||||
import kotlin.contracts.contract
|
import kotlin.contracts.contract
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
|
import ru.landgrafhomyak.db.serdha0.api.LowLevelApi
|
||||||
|
import ru.landgrafhomyak.db.serdha0.api.runtime.InputRow
|
||||||
|
import ru.landgrafhomyak.db.serdha0.api.runtime.OutputRow
|
||||||
|
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal inline fun <R> _safeAutoClose(onAbort: () -> Unit = {}, action: () -> R): R {
|
internal inline fun <R> _safeAutoClose(onAbort: () -> Unit = {}, onSuccess: () -> Unit = {}, action: () -> R): R {
|
||||||
contract {
|
contract {
|
||||||
callsInPlace(action, InvocationKind.EXACTLY_ONCE)
|
callsInPlace(action, InvocationKind.EXACTLY_ONCE)
|
||||||
callsInPlace(onAbort, InvocationKind.AT_MOST_ONCE)
|
callsInPlace(onAbort, InvocationKind.AT_MOST_ONCE)
|
||||||
|
callsInPlace(onSuccess, InvocationKind.EXACTLY_ONCE)
|
||||||
}
|
}
|
||||||
val ret: R
|
val ret: R
|
||||||
|
var wasError = false
|
||||||
try {
|
try {
|
||||||
ret = action()
|
ret = action()
|
||||||
} catch (e1: Throwable) {
|
} catch (e1: Throwable) {
|
||||||
|
wasError = true
|
||||||
try {
|
try {
|
||||||
onAbort()
|
onAbort()
|
||||||
} catch (e2: Throwable) {
|
} catch (e2: Throwable) {
|
||||||
e1.addSuppressed(e2)
|
e1.addSuppressed(e2)
|
||||||
}
|
}
|
||||||
throw e1
|
throw e1
|
||||||
|
} finally {
|
||||||
|
if (!wasError)
|
||||||
|
onSuccess()
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("ClassName")
|
||||||
|
public class _ReturnFromInputError : Error("Returning from outer function from input row initializer block is undefined behaviour")
|
||||||
|
|
||||||
|
@Suppress("FunctionName", "REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||||
|
@LowLevelApi
|
||||||
|
public suspend inline fun <I : InputRow._Scope<*, O>, O : OutputRow._Iterator<*, Unit>> _safeAutoClose_IO(
|
||||||
|
iRow: I,
|
||||||
|
inputAction: suspend (I) -> Unit,
|
||||||
|
outputAction: suspend (O) -> Unit,
|
||||||
|
) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(inputAction, InvocationKind.EXACTLY_ONCE)
|
||||||
|
callsInPlace(outputAction, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
var crossReturned = true
|
||||||
|
_safeAutoClose(
|
||||||
|
onAbort = { iRow._abort() },
|
||||||
|
action = { inputAction(iRow); crossReturned = false },
|
||||||
|
onSuccess = {
|
||||||
|
if (crossReturned) throw _ReturnFromInputError()
|
||||||
|
val oRow = iRow._finish()
|
||||||
|
_safeAutoClose(
|
||||||
|
onAbort = { oRow._abort() },
|
||||||
|
action = { outputAction(oRow) },
|
||||||
|
onSuccess = { oRow._finish() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("FunctionName", "REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||||
|
@LowLevelApi
|
||||||
|
public suspend inline fun <I : InputRow._Scope<*, Unit>> _safeAutoClose_I(
|
||||||
|
iRow: I,
|
||||||
|
inputAction: suspend (I) -> Unit,
|
||||||
|
) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(inputAction, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
_safeAutoClose(
|
||||||
|
onAbort = { iRow._abort() },
|
||||||
|
action = { inputAction(iRow) },
|
||||||
|
onSuccess = { iRow._finish() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("FunctionName", "REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
|
||||||
|
@LowLevelApi
|
||||||
|
public suspend inline fun <O : OutputRow._Iterator<*, Unit>> _safeAutoClose_O(
|
||||||
|
oRow: O,
|
||||||
|
outputAction: suspend (O) -> Unit,
|
||||||
|
) {
|
||||||
|
contract {
|
||||||
|
callsInPlace(outputAction, InvocationKind.EXACTLY_ONCE)
|
||||||
|
}
|
||||||
|
_safeAutoClose(
|
||||||
|
onAbort = { oRow._abort() },
|
||||||
|
action = { outputAction(oRow) },
|
||||||
|
onSuccess = { oRow._finish() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
public fun test() {
|
||||||
|
|
||||||
}
|
}
|
@ -17,38 +17,35 @@ public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrError(
|
|||||||
params: RowProducer0<qUE>,
|
params: RowProducer0<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R {
|
): R {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
if (!oRow._next())
|
||||||
val ret: R
|
throw ExpectedOneRowException()
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
val ret = result.transformRow(oRow)
|
||||||
if (!oRow._next())
|
if (oRow._next())
|
||||||
throw ExpectedOneRowException()
|
throw TooManyRowsException()
|
||||||
ret = result.transformRow(oRow)
|
return ret
|
||||||
if (oRow._next())
|
}
|
||||||
throw TooManyRowsException()
|
)
|
||||||
}
|
|
||||||
oRow._finish()
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrError(
|
public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrError(
|
||||||
compiledQuery: _Query.Void2Table<qUE>,
|
compiledQuery: _Query.Void2Table<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R {
|
): R {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
val ret: R
|
oRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
outputAction = { oRow ->
|
||||||
if (!oRow._next())
|
if (!oRow._next())
|
||||||
throw ExpectedOneRowException()
|
throw ExpectedOneRowException()
|
||||||
ret = result.transformRow(oRow)
|
val ret = result.transformRow(oRow)
|
||||||
if (oRow._next())
|
if (oRow._next())
|
||||||
throw TooManyRowsException()
|
throw TooManyRowsException()
|
||||||
}
|
return ret
|
||||||
oRow._finish()
|
}
|
||||||
return ret
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrNull(
|
public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrNull(
|
||||||
@ -56,76 +53,65 @@ public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrNull(
|
|||||||
params: RowProducer0<qUE>,
|
params: RowProducer0<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R? {
|
): R? {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
if (!oRow._next())
|
||||||
val ret: R?
|
return null
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
val ret = result.transformRow(oRow)
|
||||||
if (!oRow._next()) {
|
if (oRow._next())
|
||||||
ret = null
|
throw TooManyRowsException()
|
||||||
return@_safeAutoClose
|
return ret
|
||||||
}
|
}
|
||||||
ret = result.transformRow(oRow)
|
)
|
||||||
if (oRow._next())
|
|
||||||
throw TooManyRowsException()
|
|
||||||
}
|
|
||||||
oRow._finish()
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrNull(
|
public suspend inline fun <qUE : Any, R> Transaction.selectExactlyOneOrNull(
|
||||||
compiledQuery: _Query.Void2Table<qUE>,
|
compiledQuery: _Query.Void2Table<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R? {
|
): R? {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
val ret: R?
|
oRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
outputAction = { oRow ->
|
||||||
if (!oRow._next()) {
|
if (!oRow._next())
|
||||||
ret = null
|
return null
|
||||||
return@_safeAutoClose
|
val ret = result.transformRow(oRow)
|
||||||
|
if (oRow._next())
|
||||||
|
throw TooManyRowsException()
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
ret = result.transformRow(oRow)
|
)
|
||||||
if (oRow._next())
|
|
||||||
throw TooManyRowsException()
|
|
||||||
}
|
|
||||||
oRow._finish()
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrError(
|
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrError(
|
||||||
compiledQuery: _Query.Params2Table<qUE>,
|
compiledQuery: _Query.Params2Table<qUE>,
|
||||||
params: RowProducer0<qUE>,
|
params: RowProducer0<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R {
|
): R {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
if (!oRow._next())
|
||||||
val ret: R
|
throw ExpectedOneRowException()
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
return result.transformRow(oRow)
|
||||||
if (!oRow._next())
|
}
|
||||||
throw ExpectedOneRowException()
|
)
|
||||||
ret = result.transformRow(oRow)
|
|
||||||
}
|
|
||||||
oRow._finish()
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrError(
|
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrError(
|
||||||
compiledQuery: _Query.Void2Table<qUE>,
|
compiledQuery: _Query.Void2Table<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R {
|
): R {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
val ret: R
|
oRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
outputAction = { oRow ->
|
||||||
if (!oRow._next())
|
if (!oRow._next())
|
||||||
throw ExpectedOneRowException()
|
throw ExpectedOneRowException()
|
||||||
ret = result.transformRow(oRow)
|
return result.transformRow(oRow)
|
||||||
}
|
}
|
||||||
oRow._finish()
|
)
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrNull(
|
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrNull(
|
||||||
@ -133,36 +119,27 @@ public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrNull(
|
|||||||
params: RowProducer0<qUE>,
|
params: RowProducer0<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R? {
|
): R? {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
if (!oRow._next())
|
||||||
val ret: R?
|
return null
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
return result.transformRow(oRow)
|
||||||
if (!oRow._next()) {
|
|
||||||
ret = null
|
|
||||||
return@_safeAutoClose
|
|
||||||
}
|
}
|
||||||
ret = result.transformRow(oRow)
|
)
|
||||||
}
|
|
||||||
oRow._finish()
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrNull(
|
public suspend inline fun <qUE : Any, R> Transaction.selectFirstOrNull(
|
||||||
compiledQuery: _Query.Void2Table<qUE>,
|
compiledQuery: _Query.Void2Table<qUE>,
|
||||||
result: RowConsumer0<qUE, R>
|
result: RowConsumer0<qUE, R>
|
||||||
): R? {
|
): R? {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
val ret: R?
|
oRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
outputAction = { oRow ->
|
||||||
if (!oRow._next()) {
|
if (!oRow._next())
|
||||||
ret = null
|
return null
|
||||||
return@_safeAutoClose
|
return result.transformRow(oRow)
|
||||||
}
|
}
|
||||||
ret = result.transformRow(oRow)
|
)
|
||||||
}
|
|
||||||
oRow._finish()
|
|
||||||
return ret
|
|
||||||
}
|
}
|
@ -14,28 +14,27 @@ public suspend inline fun <qUE : Any> Transaction.select(
|
|||||||
params: RowProducer0<qUE>,
|
params: RowProducer0<qUE>,
|
||||||
transform: RowConsumer0<qUE, Unit>
|
transform: RowConsumer0<qUE, Unit>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
while (oRow._next())
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
transform.transformRow(oRow)
|
||||||
while (oRow._next())
|
}
|
||||||
transform.transformRow(oRow)
|
)
|
||||||
}
|
|
||||||
oRow._finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any> Transaction.select(
|
public suspend inline fun <qUE : Any> Transaction.select(
|
||||||
compiledQuery: _Query.Void2Table<qUE>,
|
compiledQuery: _Query.Void2Table<qUE>,
|
||||||
transform: RowConsumer0<qUE, Unit>
|
transform: RowConsumer0<qUE, Unit>
|
||||||
) {
|
) {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
oRow = this._executeQuery(compiledQuery),
|
||||||
while (oRow._next())
|
outputAction = { oRow ->
|
||||||
transform.transformRow(oRow)
|
while (oRow._next())
|
||||||
}
|
transform.transformRow(oRow)
|
||||||
oRow._finish()
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapRows(
|
public suspend inline fun <qUE : Any, E> Transaction.mapRows(
|
||||||
@ -43,32 +42,31 @@ public suspend inline fun <qUE : Any, E> Transaction.mapRows(
|
|||||||
params: RowProducer0<qUE>,
|
params: RowProducer0<qUE>,
|
||||||
transform: RowConsumer0<qUE, E>
|
transform: RowConsumer0<qUE, E>
|
||||||
): List<E> {
|
): List<E> {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
val dst = ArrayList<E>()
|
||||||
val out = ArrayList<E>()
|
while (oRow._next())
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
dst.add(transform.transformRow(oRow))
|
||||||
while (oRow._next())
|
return dst
|
||||||
out.add(transform.transformRow(oRow))
|
}
|
||||||
}
|
)
|
||||||
oRow._finish()
|
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapRows(
|
public suspend inline fun <qUE : Any, E> Transaction.mapRows(
|
||||||
compiledQuery: _Query.Void2Table<qUE>,
|
compiledQuery: _Query.Void2Table<qUE>,
|
||||||
transform: RowConsumer0<qUE, E>
|
transform: RowConsumer0<qUE, E>
|
||||||
): List<E> {
|
): List<E> {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
val out = ArrayList<E>()
|
oRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
outputAction = { oRow ->
|
||||||
while (oRow._next())
|
val dst = ArrayList<E>()
|
||||||
out.add(transform.transformRow(oRow))
|
while (oRow._next())
|
||||||
}
|
dst.add(transform.transformRow(oRow))
|
||||||
oRow._finish()
|
return dst
|
||||||
return out
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapRowsIndexed(
|
public suspend inline fun <qUE : Any, E> Transaction.mapRowsIndexed(
|
||||||
@ -77,19 +75,17 @@ public suspend inline fun <qUE : Any, E> Transaction.mapRowsIndexed(
|
|||||||
firstIndex: Int = 0,
|
firstIndex: Int = 0,
|
||||||
transform: RowConsumer1<qUE, E>
|
transform: RowConsumer1<qUE, E>
|
||||||
): List<E> {
|
): List<E> {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
val dst = ArrayList<E>()
|
||||||
val out = ArrayList<E>()
|
var i = firstIndex
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
while (oRow._next())
|
||||||
var i = firstIndex
|
dst.add(transform.transformRow(oRow, i++))
|
||||||
while (oRow._next())
|
return dst
|
||||||
out.add(transform.transformRow(oRow, i++))
|
}
|
||||||
}
|
)
|
||||||
oRow._finish()
|
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapRowsIndexed(
|
public suspend inline fun <qUE : Any, E> Transaction.mapRowsIndexed(
|
||||||
@ -97,15 +93,16 @@ public suspend inline fun <qUE : Any, E> Transaction.mapRowsIndexed(
|
|||||||
firstIndex: Int = 0,
|
firstIndex: Int = 0,
|
||||||
transform: RowConsumer1<qUE, E>
|
transform: RowConsumer1<qUE, E>
|
||||||
): List<E> {
|
): List<E> {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
val out = ArrayList<E>()
|
oRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
outputAction = { oRow ->
|
||||||
var i = firstIndex
|
val dst = ArrayList<E>()
|
||||||
while (oRow._next())
|
var i = firstIndex
|
||||||
out.add(transform.transformRow(oRow, i++))
|
while (oRow._next())
|
||||||
}
|
dst.add(transform.transformRow(oRow, i++))
|
||||||
oRow._finish()
|
return dst
|
||||||
return out
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsTo(
|
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsTo(
|
||||||
@ -114,17 +111,15 @@ public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.m
|
|||||||
dst: C,
|
dst: C,
|
||||||
transform: RowConsumer0<qUE, E>
|
transform: RowConsumer0<qUE, E>
|
||||||
): C {
|
): C {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
while (oRow._next())
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
dst.add(transform.transformRow(oRow))
|
||||||
while (oRow._next())
|
return dst
|
||||||
dst.add(transform.transformRow(oRow))
|
}
|
||||||
}
|
)
|
||||||
oRow._finish()
|
|
||||||
return dst
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsTo(
|
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsTo(
|
||||||
@ -132,13 +127,14 @@ public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.m
|
|||||||
dst: C,
|
dst: C,
|
||||||
transform: RowConsumer0<qUE, E>
|
transform: RowConsumer0<qUE, E>
|
||||||
): C {
|
): C {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
oRow = this._executeQuery(compiledQuery),
|
||||||
while (oRow._next())
|
outputAction = { oRow ->
|
||||||
dst.add(transform.transformRow(oRow))
|
while (oRow._next())
|
||||||
}
|
dst.add(transform.transformRow(oRow))
|
||||||
oRow._finish()
|
return dst
|
||||||
return dst
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsIndexedTo(
|
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsIndexedTo(
|
||||||
@ -147,18 +143,16 @@ public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.m
|
|||||||
dst: C, firstIndex: Int = 0,
|
dst: C, firstIndex: Int = 0,
|
||||||
transform: RowConsumer1<qUE, E>
|
transform: RowConsumer1<qUE, E>
|
||||||
): C {
|
): C {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
var i = firstIndex
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
while (oRow._next())
|
||||||
var i = firstIndex
|
dst.add(transform.transformRow(oRow, i++))
|
||||||
while (oRow._next())
|
return dst
|
||||||
dst.add(transform.transformRow(oRow, i++))
|
}
|
||||||
}
|
)
|
||||||
oRow._finish()
|
|
||||||
return dst
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsIndexedTo(
|
public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.mapRowsIndexedTo(
|
||||||
@ -166,14 +160,15 @@ public suspend inline fun <qUE : Any, E, C : MutableCollection<E>> Transaction.m
|
|||||||
dst: C, firstIndex: Int = 0,
|
dst: C, firstIndex: Int = 0,
|
||||||
transform: RowConsumer1<qUE, E>
|
transform: RowConsumer1<qUE, E>
|
||||||
): C {
|
): C {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
oRow = this._executeQuery(compiledQuery),
|
||||||
var i = firstIndex
|
outputAction = { oRow ->
|
||||||
while (oRow._next())
|
var i = firstIndex
|
||||||
dst.add(transform.transformRow(oRow, i++))
|
while (oRow._next())
|
||||||
}
|
dst.add(transform.transformRow(oRow, i++))
|
||||||
oRow._finish()
|
return dst
|
||||||
return dst
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapRowsTo(
|
public suspend inline fun <qUE : Any, E> Transaction.mapRowsTo(
|
||||||
@ -182,18 +177,16 @@ public suspend inline fun <qUE : Any, E> Transaction.mapRowsTo(
|
|||||||
dst: Array<E>, dstOffset: Int = 0,
|
dst: Array<E>, dstOffset: Int = 0,
|
||||||
transform: RowConsumer0<qUE, E>
|
transform: RowConsumer0<qUE, E>
|
||||||
): Array<E> {
|
): Array<E> {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = { oRow ->
|
||||||
val oRow = iRow._finish()
|
var i = dstOffset
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
while (oRow._next())
|
||||||
var i = dstOffset
|
dst[i++] = transform.transformRow(oRow)
|
||||||
while (oRow._next())
|
return dst
|
||||||
dst[i++] = transform.transformRow(oRow)
|
}
|
||||||
}
|
)
|
||||||
oRow._finish()
|
|
||||||
return dst
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapRowsTo(
|
public suspend inline fun <qUE : Any, E> Transaction.mapRowsTo(
|
||||||
@ -201,12 +194,13 @@ public suspend inline fun <qUE : Any, E> Transaction.mapRowsTo(
|
|||||||
dst: Array<E>, dstOffset: Int = 0,
|
dst: Array<E>, dstOffset: Int = 0,
|
||||||
transform: RowConsumer0<qUE, E>
|
transform: RowConsumer0<qUE, E>
|
||||||
): Array<E> {
|
): Array<E> {
|
||||||
val oRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_O(
|
||||||
_safeAutoClose(onAbort = { oRow._abort() }) {
|
oRow = this._executeQuery(compiledQuery),
|
||||||
var i = dstOffset
|
outputAction = { oRow ->
|
||||||
while (oRow._next())
|
var i = dstOffset
|
||||||
dst[i++] = transform.transformRow(oRow)
|
while (oRow._next())
|
||||||
}
|
dst[i++] = transform.transformRow(oRow)
|
||||||
oRow._finish()
|
return dst
|
||||||
return dst
|
}
|
||||||
|
)
|
||||||
}
|
}
|
@ -13,20 +13,19 @@ public suspend inline fun <qUE : Any> Transaction.executeWithParams(
|
|||||||
compiledQuery: _Query.Params2Void<qUE>,
|
compiledQuery: _Query.Params2Void<qUE>,
|
||||||
params: RowProducer0<qUE>
|
params: RowProducer0<qUE>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_I(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow
|
||||||
}
|
)
|
||||||
iRow._finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any> Transaction.executeWithParams(
|
public suspend inline fun <qUE : Any> Transaction.executeWithParams(
|
||||||
compiledQuery: _Query.Params2Table<qUE>,
|
compiledQuery: _Query.Params2Table<qUE>,
|
||||||
params: RowProducer0<qUE>
|
params: RowProducer0<qUE>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_IO(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
params.initializeRow(iRow)
|
inputAction = params::initializeRow,
|
||||||
}
|
outputAction = {}
|
||||||
iRow._finish()._finish()
|
)
|
||||||
}
|
}
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package ru.landgrafhomyak.db.serdha0.user_commons.executors
|
package ru.landgrafhomyak.db.serdha0.user_commons.executors
|
||||||
|
|
||||||
import kotlin.contracts.contract
|
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
import ru.landgrafhomyak.db.serdha0.api.LowLevelApi
|
import ru.landgrafhomyak.db.serdha0.api.LowLevelApi
|
||||||
import ru.landgrafhomyak.db.serdha0.api.queries._Query
|
import ru.landgrafhomyak.db.serdha0.api.queries._Query
|
||||||
@ -15,14 +14,15 @@ public suspend inline fun <qUE : Any, E> Transaction.mapToRows(
|
|||||||
collection: Iterable<E>,
|
collection: Iterable<E>,
|
||||||
transform: RowProducer1<qUE, E>
|
transform: RowProducer1<qUE, E>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_I(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
for (elem in collection) {
|
inputAction = { iRow ->
|
||||||
iRow._next()
|
for (elem in collection) {
|
||||||
transform.transformToRow(iRow, elem)
|
iRow._next()
|
||||||
|
transform.transformToRow(iRow, elem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
iRow._finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
||||||
@ -31,16 +31,16 @@ public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
|||||||
firstIndex: Int = 0,
|
firstIndex: Int = 0,
|
||||||
transform: RowProducer2<qUE, E>
|
transform: RowProducer2<qUE, E>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_I(
|
||||||
var index = firstIndex
|
iRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
inputAction = { iRow ->
|
||||||
for (elem in collection) {
|
var index = firstIndex
|
||||||
iRow._next()
|
for (elem in collection) {
|
||||||
transform.transformToRow(iRow, index, elem)
|
iRow._next()
|
||||||
index++
|
transform.transformToRow(iRow, index++, elem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
iRow._finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapToRows(
|
public suspend inline fun <qUE : Any, E> Transaction.mapToRows(
|
||||||
@ -48,14 +48,15 @@ public suspend inline fun <qUE : Any, E> Transaction.mapToRows(
|
|||||||
sequence: Sequence<E>,
|
sequence: Sequence<E>,
|
||||||
transform: RowProducer1<qUE, E>
|
transform: RowProducer1<qUE, E>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_I(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
for (elem in sequence) {
|
inputAction = { iRow ->
|
||||||
iRow._next()
|
for (elem in sequence) {
|
||||||
transform.transformToRow(iRow, elem)
|
iRow._next()
|
||||||
|
transform.transformToRow(iRow, elem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
iRow._finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
||||||
@ -64,47 +65,48 @@ public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
|||||||
firstIndex: Int = 0,
|
firstIndex: Int = 0,
|
||||||
transform: RowProducer2<qUE, E>
|
transform: RowProducer2<qUE, E>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_I(
|
||||||
var index = firstIndex
|
iRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
inputAction = { iRow ->
|
||||||
for (elem in sequence) {
|
var index = firstIndex
|
||||||
iRow._next()
|
for (elem in sequence) {
|
||||||
transform.transformToRow(iRow, index, elem)
|
iRow._next()
|
||||||
index++
|
transform.transformToRow(iRow, index++, elem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
iRow._finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapToRows(
|
public suspend inline fun <qUE : Any, E> Transaction.mapToRows(
|
||||||
compiledQuery: _Query.Table2Void<qUE>,
|
compiledQuery: _Query.Table2Void<qUE>,
|
||||||
sequence: Array<E>,
|
array: Array<E>,
|
||||||
transform: RowProducer1<qUE, E>
|
transform: RowProducer1<qUE, E>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_I(
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
iRow = this._executeQuery(compiledQuery),
|
||||||
for (elem in sequence) {
|
inputAction = { iRow ->
|
||||||
iRow._next()
|
for (elem in array) {
|
||||||
transform.transformToRow(iRow, elem)
|
iRow._next()
|
||||||
|
transform.transformToRow(iRow, elem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
iRow._finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
public suspend inline fun <qUE : Any, E> Transaction.mapToRowsIndexed(
|
||||||
compiledQuery: _Query.Table2Void<qUE>,
|
compiledQuery: _Query.Table2Void<qUE>,
|
||||||
sequence: Array<E>,
|
array: Array<E>,
|
||||||
firstIndex: Int = 0,
|
firstIndex: Int = 0,
|
||||||
transform: RowProducer2<qUE, E>
|
transform: RowProducer2<qUE, E>
|
||||||
) {
|
) {
|
||||||
val iRow = this._executeQuery(compiledQuery)
|
_safeAutoClose_I(
|
||||||
var index = firstIndex
|
iRow = this._executeQuery(compiledQuery),
|
||||||
_safeAutoClose(onAbort = { iRow._abort() }) {
|
inputAction = { iRow ->
|
||||||
for (elem in sequence) {
|
var index = firstIndex
|
||||||
iRow._next()
|
for (elem in array) {
|
||||||
transform.transformToRow(iRow, index, elem)
|
iRow._next()
|
||||||
index++
|
transform.transformToRow(iRow, index++, elem)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
iRow._finish()
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user