From 89d176ca3a4f36314c96cc194e8a4bf843a7ae88 Mon Sep 17 00:00:00 2001 From: Salmonllama Date: Sat, 11 Sep 2021 17:40:08 -0400 Subject: [PATCH] Fixed connection path. Added DB logging. --- .../fsbot/database/DatabaseProvider.java | 32 +++++++++++++++++-- .../dev/salmonllama/fsbot/database/FSDB.java | 22 +++++++++++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/salmonllama/fsbot/database/DatabaseProvider.java b/src/main/java/dev/salmonllama/fsbot/database/DatabaseProvider.java index a210b94..6233691 100644 --- a/src/main/java/dev/salmonllama/fsbot/database/DatabaseProvider.java +++ b/src/main/java/dev/salmonllama/fsbot/database/DatabaseProvider.java @@ -1,6 +1,22 @@ /* - * Copyright (c) 2020. Aleksei Gryczewski - * All rights reserved. + Copyright (c) 2021 Aleksei Gryczewski + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Heavily inspired by Kaaz's Emily database connection: https://github.com/Kaaz/DiscordBot/tree/master/src/main/java/emily/db @@ -9,8 +25,12 @@ package dev.salmonllama.fsbot.database; import dev.salmonllama.fsbot.exceptions.UnknownParameterException; import dev.salmonllama.fsbot.config.BotConfig; import dev.salmonllama.fsbot.utilities.Constants; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sqlite.javax.SQLiteConnectionPoolDataSource; +import java.nio.file.Path; import java.sql.*; public class DatabaseProvider { @@ -18,9 +38,15 @@ public class DatabaseProvider { private final String DB_NAME; private Connection c; + private final static Logger logger = LoggerFactory.getLogger(DatabaseProvider.class); + public DatabaseProvider(String dbName) { DB_NAME = dbName; - DB_ADDR = "jdbc:sqlite:".concat(Constants.BOT_FOLDER.toString()).concat(BotConfig.DB_ADDR); + Path addr = Path.of(Constants.BOT_FOLDER.toString(), BotConfig.DB_ADDR); + DB_ADDR = "jdbc:sqlite:".concat(addr.toString()); + + logger.info("Initializing database..."); + logger.info(DB_ADDR); } private Connection createConnection() { diff --git a/src/main/java/dev/salmonllama/fsbot/database/FSDB.java b/src/main/java/dev/salmonllama/fsbot/database/FSDB.java index 83f80bd..4226779 100644 --- a/src/main/java/dev/salmonllama/fsbot/database/FSDB.java +++ b/src/main/java/dev/salmonllama/fsbot/database/FSDB.java @@ -1,6 +1,22 @@ /* - * Copyright (c) 2020. Aleksei Gryczewski - * All rights reserved. + Copyright (c) 2021 Aleksei Gryczewski + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Heavily inspired by Kaaz's Emily database connection: https://github.com/Kaaz/DiscordBot/tree/master/src/main/java/emily/db @@ -39,7 +55,7 @@ public class FSDB { private static void prepareTables() { try { get().query(Outfit.schema()); - get().query(ColorRole.schema()); +// get().query(ColorRole.schema()); get().query(GalleryChannel.schema()); get().query(ServerConfig.schema()); get().query(ServerBlacklist.schema());