mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-22 18:09:06 +00:00

Hikari library to automatically reconnect to database. Thanks to metalshark setting this up.
34 lines
1.0 KiB
Java
34 lines
1.0 KiB
Java
package mineverse.Aust1n46.chat.database;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
import com.zaxxer.hikari.HikariConfig;
|
|
import com.zaxxer.hikari.HikariDataSource;
|
|
|
|
import mineverse.Aust1n46.chat.MineverseChat;
|
|
|
|
//This class initializes the connection to a SQLite database, which has no implementations currently in the plugin.
|
|
public class SQLite extends Database {
|
|
private final String dbLocation;
|
|
|
|
public SQLite(String dbLocation) {
|
|
this.dbLocation = dbLocation;
|
|
}
|
|
|
|
@Override
|
|
public void init() {
|
|
File dataFolder = MineverseChat.getInstance().getDataFolder();
|
|
if (!dataFolder.exists()) dataFolder.mkdirs();
|
|
File databaseFile = new File(dataFolder, dbLocation);
|
|
try {
|
|
if (!databaseFile.exists()) databaseFile.createNewFile();
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
HikariConfig config = new HikariConfig();
|
|
final String jdbcUrl = String.format("jdbc:sqlite:%s", databaseFile);
|
|
config.setJdbcUrl(jdbcUrl);
|
|
dataSource = new HikariDataSource(config);
|
|
}
|
|
} |