From 8f95056e31caaa6ebcd6916335f8f6b91162e92c Mon Sep 17 00:00:00 2001 From: ceze88 Date: Thu, 29 Dec 2022 13:49:04 +0100 Subject: [PATCH] A little database utility --- .../com/songoda/core/database/DataManagerAbstract.java | 9 +++++++++ .../com/songoda/core/database/DatabaseConnector.java | 2 ++ .../java/com/songoda/core/database/DatabaseType.java | 8 ++++++++ .../java/com/songoda/core/database/MariaDBConnector.java | 5 +++++ .../java/com/songoda/core/database/MySQLConnector.java | 5 +++++ .../java/com/songoda/core/database/SQLiteConnector.java | 5 +++++ 6 files changed, 34 insertions(+) create mode 100644 Core/src/main/java/com/songoda/core/database/DatabaseType.java diff --git a/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java b/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java index c6fcf188..78435c7d 100644 --- a/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java +++ b/Core/src/main/java/com/songoda/core/database/DataManagerAbstract.java @@ -21,6 +21,7 @@ import java.util.function.Consumer; public class DataManagerAbstract { protected final DatabaseConnector databaseConnector; protected final Plugin plugin; + protected final DatabaseType type; protected final ExecutorService asyncPool = Executors.newSingleThreadExecutor(); @@ -30,6 +31,7 @@ public class DataManagerAbstract { public DataManagerAbstract(DatabaseConnector databaseConnector, Plugin plugin) { this.databaseConnector = databaseConnector; this.plugin = plugin; + this.type = databaseConnector.getType(); } /** @@ -196,4 +198,11 @@ public class DataManagerAbstract { }); }); } + + public String getSyntax(String string, DatabaseType type) { + if (this.type == type) { + return string; + } + return ""; + } } diff --git a/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java b/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java index 7d0c0ff2..2be85c25 100644 --- a/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java +++ b/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java @@ -31,4 +31,6 @@ public interface DatabaseConnector { } Connection getConnection(); + + DatabaseType getType(); } diff --git a/Core/src/main/java/com/songoda/core/database/DatabaseType.java b/Core/src/main/java/com/songoda/core/database/DatabaseType.java new file mode 100644 index 00000000..e7ac08d6 --- /dev/null +++ b/Core/src/main/java/com/songoda/core/database/DatabaseType.java @@ -0,0 +1,8 @@ +package com.songoda.core.database; + +public enum DatabaseType { + + MARIADB, + MYSQL, + SQLITE +} diff --git a/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java b/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java index 061191df..7a507a5c 100644 --- a/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java +++ b/Core/src/main/java/com/songoda/core/database/MariaDBConnector.java @@ -62,4 +62,9 @@ public class MariaDBConnector implements DatabaseConnector { } return null; } + + @Override + public DatabaseType getType() { + return DatabaseType.MARIADB; + } } diff --git a/Core/src/main/java/com/songoda/core/database/MySQLConnector.java b/Core/src/main/java/com/songoda/core/database/MySQLConnector.java index 1b2fe4c1..910c8836 100644 --- a/Core/src/main/java/com/songoda/core/database/MySQLConnector.java +++ b/Core/src/main/java/com/songoda/core/database/MySQLConnector.java @@ -61,4 +61,9 @@ public class MySQLConnector implements DatabaseConnector { } return null; } + + @Override + public DatabaseType getType() { + return DatabaseType.MYSQL; + } } diff --git a/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java b/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java index 7ffbbf22..6882e2c5 100644 --- a/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java +++ b/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java @@ -65,4 +65,9 @@ public class SQLiteConnector implements DatabaseConnector { } return this.connection; } + + @Override + public DatabaseType getType() { + return DatabaseType.SQLITE; + } }