A little database utility

This commit is contained in:
ceze88 2022-12-29 13:49:04 +01:00
parent f38296e4b1
commit 8f95056e31
6 changed files with 34 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import java.util.function.Consumer;
public class DataManagerAbstract { public class DataManagerAbstract {
protected final DatabaseConnector databaseConnector; protected final DatabaseConnector databaseConnector;
protected final Plugin plugin; protected final Plugin plugin;
protected final DatabaseType type;
protected final ExecutorService asyncPool = Executors.newSingleThreadExecutor(); protected final ExecutorService asyncPool = Executors.newSingleThreadExecutor();
@ -30,6 +31,7 @@ public class DataManagerAbstract {
public DataManagerAbstract(DatabaseConnector databaseConnector, Plugin plugin) { public DataManagerAbstract(DatabaseConnector databaseConnector, Plugin plugin) {
this.databaseConnector = databaseConnector; this.databaseConnector = databaseConnector;
this.plugin = plugin; 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 "";
}
} }

View File

@ -31,4 +31,6 @@ public interface DatabaseConnector {
} }
Connection getConnection(); Connection getConnection();
DatabaseType getType();
} }

View File

@ -0,0 +1,8 @@
package com.songoda.core.database;
public enum DatabaseType {
MARIADB,
MYSQL,
SQLITE
}

View File

@ -62,4 +62,9 @@ public class MariaDBConnector implements DatabaseConnector {
} }
return null; return null;
} }
@Override
public DatabaseType getType() {
return DatabaseType.MARIADB;
}
} }

View File

@ -61,4 +61,9 @@ public class MySQLConnector implements DatabaseConnector {
} }
return null; return null;
} }
@Override
public DatabaseType getType() {
return DatabaseType.MYSQL;
}
} }

View File

@ -65,4 +65,9 @@ public class SQLiteConnector implements DatabaseConnector {
} }
return this.connection; return this.connection;
} }
@Override
public DatabaseType getType() {
return DatabaseType.SQLITE;
}
} }