From bd2a6fa28ec4c3c7675911eb35338bcf20cb3f9c Mon Sep 17 00:00:00 2001 From: webhead1104 Date: Sun, 5 May 2024 20:24:20 -0500 Subject: [PATCH] Update database stuff --- .../java/net/cytonic/cytosis/Cytosis.java | 1 + .../net/cytonic/cytosis/DatabaseManager.java | 34 ------------------- .../cytonic/cytosis/data/DatabaseManager.java | 24 +++++++++++++ 3 files changed, 25 insertions(+), 34 deletions(-) delete mode 100644 src/main/java/net/cytonic/cytosis/DatabaseManager.java create mode 100644 src/main/java/net/cytonic/cytosis/data/DatabaseManager.java diff --git a/src/main/java/net/cytonic/cytosis/Cytosis.java b/src/main/java/net/cytonic/cytosis/Cytosis.java index 61cebd66..e3409412 100644 --- a/src/main/java/net/cytonic/cytosis/Cytosis.java +++ b/src/main/java/net/cytonic/cytosis/Cytosis.java @@ -2,6 +2,7 @@ import net.cytonic.cytosis.commands.CommandHandler; import net.cytonic.cytosis.config.CytosisSettings; +import net.cytonic.cytosis.data.DatabaseManager; import net.cytonic.cytosis.events.EventHandler; import net.cytonic.cytosis.events.ServerEventListeners; import net.cytonic.cytosis.files.FileManager; diff --git a/src/main/java/net/cytonic/cytosis/DatabaseManager.java b/src/main/java/net/cytonic/cytosis/DatabaseManager.java deleted file mode 100644 index 2831affa..00000000 --- a/src/main/java/net/cytonic/cytosis/DatabaseManager.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.cytonic.cytosis; - -import net.cytonic.cytosis.data.Database; -import net.cytonic.cytosis.logging.Logger; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class DatabaseManager { - - private final ExecutorService worker; - private Database database; - - public DatabaseManager() { - this.worker = Executors.newSingleThreadExecutor(Thread.ofVirtual().name("CytosisManagerWorker") - .uncaughtExceptionHandler((t, e) -> Logger.error(STR."An uncaught exception occoured on the thread: \{t.getName()}", e)).factory()); - } - - public void shutdown() { - worker.submit(() -> { - database.disconnect(); - Logger.info("Good night!"); - }); - } - - public void setupDatabase() { - worker.submit(() -> { - database = new Database(); - database.connect(); - database.createChatTable(); - }); - } - - public Database getDatabase() {return database;} -} \ No newline at end of file diff --git a/src/main/java/net/cytonic/cytosis/data/DatabaseManager.java b/src/main/java/net/cytonic/cytosis/data/DatabaseManager.java new file mode 100644 index 00000000..82a93d0f --- /dev/null +++ b/src/main/java/net/cytonic/cytosis/data/DatabaseManager.java @@ -0,0 +1,24 @@ +package net.cytonic.cytosis.data; + +import net.cytonic.cytosis.logging.Logger; + +public class DatabaseManager { + + private Database database; + + public DatabaseManager() { + } + + public void shutdown() { + database.disconnect(); + Logger.info("Good night!"); + } + + public void setupDatabase() { + database = new Database(); + database.connect(); + database.createChatTable(); + } + + public Database getDatabase() {return database;} +} \ No newline at end of file