Skip to content
Snippets Groups Projects
Commit bed41bb9 authored by Sebastian's avatar Sebastian
Browse files

Remove DatabaseComponent and use Database directly

parent 37b77b35
No related branches found
No related tags found
1 merge request!19Resolve "Store contacts in mailbox DB"
Pipeline #7640 passed
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();
}
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
}
}
......@@ -18,10 +18,4 @@ internal class DatabaseModule {
return H2Database(config, clock)
}
@Provides
@Singleton
fun provideDatabaseComponent(db: Database<Connection>): DatabaseComponent {
return DatabaseComponentImpl(db)
}
}
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
}
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment