Merge "Make CoroutineFlowResultBinder extend BaseObservableQueryResultBinder" into androidx-master-dev
diff --git a/buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt b/buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt
index dc8d805..c034033 100644
--- a/buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt
@@ -74,7 +74,7 @@
const val KOTLIN_COROUTINES_TEST =
"org.jetbrains.kotlinx:kotlinx-coroutines-test:$KOTLIN_COROUTINES_VERSION"
-private const val KOTLIN_COROUTINES_PREVIEW_VERSION = "1.3.0-RC"
+private const val KOTLIN_COROUTINES_PREVIEW_VERSION = "1.3.0-RC2"
const val KOTLIN_COROUTINES_PREVIEW =
"org.jetbrains.kotlinx:kotlinx-coroutines-android:$KOTLIN_COROUTINES_PREVIEW_VERSION"
const val KOTLIN_COROUTINES_CORE_PREVIEW =
diff --git a/room/compiler/src/main/kotlin/androidx/room/solver/query/result/CoroutineFlowResultBinder.kt b/room/compiler/src/main/kotlin/androidx/room/solver/query/result/CoroutineFlowResultBinder.kt
index 0968b61..3feb379 100644
--- a/room/compiler/src/main/kotlin/androidx/room/solver/query/result/CoroutineFlowResultBinder.kt
+++ b/room/compiler/src/main/kotlin/androidx/room/solver/query/result/CoroutineFlowResultBinder.kt
@@ -16,18 +16,15 @@
package androidx.room.solver.query.result
-import androidx.room.ext.AndroidTypeNames
import androidx.room.ext.CallableTypeSpecBuilder
import androidx.room.ext.L
import androidx.room.ext.N
import androidx.room.ext.RoomCoroutinesTypeNames
-import androidx.room.ext.RoomTypeNames
import androidx.room.ext.T
import androidx.room.ext.arrayTypeName
import androidx.room.ext.typeName
import androidx.room.solver.CodeGenScope
import com.squareup.javapoet.FieldSpec
-import com.squareup.javapoet.MethodSpec
import javax.lang.model.type.TypeMirror
/**
@@ -37,7 +34,7 @@
val typeArg: TypeMirror,
val tableNames: Set<String>,
adapter: QueryResultAdapter?
-) : QueryResultBinder(adapter) {
+) : BaseObservableQueryResultBinder(adapter) {
override fun convertAndReturn(
roomSQLiteQueryVar: String,
@@ -50,11 +47,14 @@
createRunQueryAndReturnStatements(
builder = this,
roomSQLiteQueryVar = roomSQLiteQueryVar,
- canReleaseQuery = canReleaseQuery,
dbField = dbField,
inTransaction = inTransaction,
scope = scope,
cancellationSignalVar = "null")
+ }.apply {
+ if (canReleaseQuery) {
+ addMethod(createFinalizeMethod(roomSQLiteQueryVar))
+ }
}.build()
scope.builder().apply {
@@ -69,49 +69,4 @@
callableImpl)
}
}
-
- private fun createRunQueryAndReturnStatements(
- builder: MethodSpec.Builder,
- roomSQLiteQueryVar: String,
- canReleaseQuery: Boolean,
- dbField: FieldSpec,
- inTransaction: Boolean,
- scope: CodeGenScope,
- cancellationSignalVar: String
- ) {
- val transactionWrapper = if (inTransaction) {
- builder.transactionWrapper(dbField)
- } else {
- null
- }
- val shouldCopyCursor = adapter?.shouldCopyCursor() == true
- val outVar = scope.getTmpVar("_result")
- val cursorVar = scope.getTmpVar("_cursor")
- transactionWrapper?.beginTransactionWithControlFlow()
- builder.apply {
- addStatement("final $T $L = $T.query($N, $L, $L, $L)",
- AndroidTypeNames.CURSOR,
- cursorVar,
- RoomTypeNames.DB_UTIL,
- dbField,
- roomSQLiteQueryVar,
- if (shouldCopyCursor) "true" else "false",
- cancellationSignalVar)
- beginControlFlow("try").apply {
- val adapterScope = scope.fork()
- adapter?.convert(outVar, cursorVar, adapterScope)
- addCode(adapterScope.builder().build())
- transactionWrapper?.commitTransaction()
- addStatement("return $L", outVar)
- }
- nextControlFlow("finally").apply {
- addStatement("$L.close()", cursorVar)
- if (canReleaseQuery) {
- addStatement("$L.release()", roomSQLiteQueryVar)
- }
- }
- endControlFlow()
- }
- transactionWrapper?.endTransactionWithControlFlow()
- }
}
\ No newline at end of file