From 57028c694b74371db11887ec4baaf01326f775ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Wed, 13 Oct 2021 15:27:33 +0200 Subject: [PATCH] Some code cleanup --- .../briarproject/mailbox/core/db/JdbcDatabase.kt | 14 +++++++------- .../briarproject/mailbox/core/db/Transaction.kt | 5 ++--- .../mailbox/core/db/JdbcDatabaseTest.kt | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/JdbcDatabase.kt b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/JdbcDatabase.kt index b46c2d34..b907191f 100644 --- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/JdbcDatabase.kt +++ b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/JdbcDatabase.kt @@ -353,7 +353,7 @@ abstract class JdbcDatabase(private val dbTypes: DatabaseTypes, private val cloc @Throws(DbException::class) override fun getSettings(txn: Transaction, namespace: String): Settings { - val connection: Connection = txn.unbox() as Connection + val connection: Connection = txn.unbox() return getSettings(connection, namespace) } @@ -384,7 +384,7 @@ abstract class JdbcDatabase(private val dbTypes: DatabaseTypes, private val cloc @Throws(DbException::class) override fun mergeSettings(txn: Transaction, s: Settings, namespace: String) { - val connection: Connection = txn.unbox() as Connection + val connection: Connection = txn.unbox() mergeSettings(connection, s, namespace) } @@ -442,7 +442,7 @@ abstract class JdbcDatabase(private val dbTypes: DatabaseTypes, private val cloc @Throws(DbException::class) override fun addContact(txn: Transaction, contact: Contact) { - val connection: Connection = txn.unbox() as Connection + val connection: Connection = txn.unbox() var ps: PreparedStatement? = null try { val sql = """INSERT INTO contacts (contactId, token, inbox, outbox) @@ -464,7 +464,7 @@ abstract class JdbcDatabase(private val dbTypes: DatabaseTypes, private val cloc @Throws(DbException::class) override fun getContact(txn: Transaction, id: Int): Contact? { - val connection: Connection = txn.unbox() as Connection + val connection: Connection = txn.unbox() var ps: PreparedStatement? = null var rs: ResultSet? = null try { @@ -490,7 +490,7 @@ abstract class JdbcDatabase(private val dbTypes: DatabaseTypes, private val cloc @Throws(DbException::class) override fun removeContact(txn: Transaction, id: Int) { - val connection: Connection = txn.unbox() as Connection + val connection: Connection = txn.unbox() var ps: PreparedStatement? = null try { val sql = "DELETE FROM contacts WHERE contactId = ?" @@ -510,7 +510,7 @@ abstract class JdbcDatabase(private val dbTypes: DatabaseTypes, private val cloc */ @Throws(DbException::class) private fun commitTransaction(txn: Transaction) { - val connection: Connection = txn.unbox() as Connection + val connection: Connection = txn.unbox() check(!txn.isCommitted) txn.setCommitted() commitTransaction(connection) @@ -524,7 +524,7 @@ abstract class JdbcDatabase(private val dbTypes: DatabaseTypes, private val cloc */ private fun endTransaction(txn: Transaction) { try { - val connection: Connection = txn.unbox() as Connection + val connection: Connection = txn.unbox() if (!txn.isCommitted) { abortTransaction(connection) } diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/Transaction.kt b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/Transaction.kt index 81176661..45c17a37 100644 --- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/Transaction.kt +++ b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/Transaction.kt @@ -17,8 +17,7 @@ class Transaction( private set /** - * Returns the database transaction. The type of the returned object - * depends on the database implementation. + * Returns the database connection. */ fun unbox(): Connection { return txn @@ -26,7 +25,7 @@ class Transaction( /** * Marks the transaction as committed. This method should only be called - * by the DatabaseComponent. It must not be called more than once. + * by the Database. It must not be called more than once. */ fun setCommitted() { check(!isCommitted) diff --git a/mailbox-core/src/test/java/org/briarproject/mailbox/core/db/JdbcDatabaseTest.kt b/mailbox-core/src/test/java/org/briarproject/mailbox/core/db/JdbcDatabaseTest.kt index b711dcb0..1fb11411 100644 --- a/mailbox-core/src/test/java/org/briarproject/mailbox/core/db/JdbcDatabaseTest.kt +++ b/mailbox-core/src/test/java/org/briarproject/mailbox/core/db/JdbcDatabaseTest.kt @@ -93,7 +93,7 @@ abstract class JdbcDatabaseTest { merged["baz"] = "qux" var db: Database = open(false) - var txn = db.transaction(false) { txn -> + db.transaction(false) { txn -> // store 'before' db.mergeSettings(txn, before, "namespace") assertEquals(before, db.getSettings(txn, "namespace")) -- GitLab