From 1fec558a150867c88f60da7e43deed2196f35bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Wed, 29 Sep 2021 10:56:22 +0200 Subject: [PATCH] Remove DatabaseComponent and use Database directly --- .../mailbox/core/db/DatabaseComponent.java | 21 ------------------- .../mailbox/core/db/DatabaseComponentImpl.kt | 18 ---------------- .../mailbox/core/db/DatabaseModule.kt | 6 ------ .../core/lifecycle/LifecycleManager.java | 19 +++++++++-------- .../core/lifecycle/LifecycleManagerImpl.kt | 5 +++-- 5 files changed, 13 insertions(+), 56 deletions(-) delete mode 100644 mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponent.java delete mode 100644 mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponentImpl.kt diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponent.java b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponent.java deleted file mode 100644 index 88e0e248..00000000 --- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponent.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.briarproject.mailbox.core.db; - -import javax.annotation.Nullable; - -/** - * Encapsulates the database implementation and exposes high-level operations - * to other components. - */ -public interface DatabaseComponent { - - /** - * Opens the database and returns true if the database already existed. - */ - boolean open(@Nullable MigrationListener listener); - - /** - * Waits for any open transactions to finish and closes the database. - */ - void close(); - -} diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponentImpl.kt b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponentImpl.kt deleted file mode 100644 index e17f7014..00000000 --- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseComponentImpl.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.briarproject.mailbox.core.db - -import javax.inject.Inject - -class DatabaseComponentImpl<T> @Inject constructor(database: Database<T>) : DatabaseComponent { - - private val db: Database<T>? = null - - override fun open(listener: MigrationListener?): Boolean { - // TODO: implement this - return true - } - - override fun close() { - // TODO: implement this - } - -} diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseModule.kt b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseModule.kt index 84a4e283..50fd36f3 100644 --- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseModule.kt +++ b/mailbox-core/src/main/java/org/briarproject/mailbox/core/db/DatabaseModule.kt @@ -18,10 +18,4 @@ internal class DatabaseModule { return H2Database(config, clock) } - @Provides - @Singleton - fun provideDatabaseComponent(db: Database<Connection>): DatabaseComponent { - return DatabaseComponentImpl(db) - } - } diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.java b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.java index 63719354..84c09ac3 100644 --- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.java +++ b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManager.java @@ -1,6 +1,6 @@ package org.briarproject.mailbox.core.lifecycle; -import org.briarproject.mailbox.core.db.DatabaseComponent; +import org.briarproject.mailbox.core.db.Database; import org.briarproject.mailbox.core.system.Wakeful; import java.util.concurrent.ExecutorService; @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.StateFlow; /** * Manages the lifecycle of the app: opening and closing the - * {@link DatabaseComponent} starting and stopping {@link Service Services}, + * {@link Database} starting and stopping {@link Service Services}, * and shutting down {@link ExecutorService ExecutorServices}. */ public interface LifecycleManager { @@ -29,7 +29,8 @@ public interface LifecycleManager { */ enum LifecycleState { - STOPPED, STARTING, MIGRATING_DATABASE, COMPACTING_DATABASE, STARTING_SERVICES, + STOPPED, STARTING, MIGRATING_DATABASE, COMPACTING_DATABASE, + STARTING_SERVICES, RUNNING, STOPPING; public boolean isAfter(LifecycleState state) { @@ -57,7 +58,7 @@ public interface LifecycleManager { void registerForShutdown(ExecutorService e); /** - * Opens the {@link DatabaseComponent} using the given key and starts any + * Opens the {@link Database} using the given key and starts any * registered {@link Service Services}. */ @Wakeful @@ -66,18 +67,18 @@ public interface LifecycleManager { /** * Stops any registered {@link Service Services}, shuts down any * registered {@link ExecutorService ExecutorServices}, and closes the - * {@link DatabaseComponent}. + * {@link Database}. */ @Wakeful void stopServices(); /** - * Waits for the {@link DatabaseComponent} to be opened before returning. + * Waits for the {@link Database} to be opened before returning. */ void waitForDatabase() throws InterruptedException; /** - * Waits for the {@link DatabaseComponent} to be opened and all registered + * Waits for the {@link Database} to be opened and all registered * {@link Service Services} to start before returning. */ void waitForStartup() throws InterruptedException; @@ -85,7 +86,7 @@ public interface LifecycleManager { /** * Waits for all registered {@link Service Services} to stop, all * registered {@link ExecutorService ExecutorServices} to shut down, and - * the {@link DatabaseComponent} to be closed before returning. + * the {@link Database} to be closed before returning. */ void waitForShutdown() throws InterruptedException; @@ -104,4 +105,4 @@ public interface LifecycleManager { @Wakeful void onDatabaseOpened(); } -} \ No newline at end of file +} diff --git a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt index d5e659d0..4b1f8b91 100644 --- a/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt +++ b/mailbox-core/src/main/java/org/briarproject/mailbox/core/lifecycle/LifecycleManagerImpl.kt @@ -2,7 +2,7 @@ package org.briarproject.mailbox.core.lifecycle import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import org.briarproject.mailbox.core.db.DatabaseComponent +import org.briarproject.mailbox.core.db.Database import org.briarproject.mailbox.core.db.MigrationListener import org.briarproject.mailbox.core.lifecycle.LifecycleManager.LifecycleState import org.briarproject.mailbox.core.lifecycle.LifecycleManager.LifecycleState.COMPACTING_DATABASE @@ -23,6 +23,7 @@ import org.briarproject.mailbox.core.util.LogUtils.logException import org.briarproject.mailbox.core.util.LogUtils.now import org.briarproject.mailbox.core.util.LogUtils.trace import org.slf4j.LoggerFactory.getLogger +import java.sql.Connection import java.util.concurrent.CopyOnWriteArrayList import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService @@ -31,7 +32,7 @@ import javax.annotation.concurrent.ThreadSafe import javax.inject.Inject @ThreadSafe -internal class LifecycleManagerImpl @Inject constructor(private val db: DatabaseComponent) : +internal class LifecycleManagerImpl @Inject constructor(private val db: Database<Connection>) : LifecycleManager, MigrationListener { companion object { -- GitLab