Fixed connection path. Added DB logging.

This commit is contained in:
Salmonllama 2021-09-11 17:40:08 -04:00
parent 117403d349
commit 89d176ca3a
2 changed files with 48 additions and 6 deletions

View File

@ -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() {

View File

@ -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());