mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-10-23 19:23:05 +02:00
71 lines
1.7 KiB
Java
71 lines
1.7 KiB
Java
package com.eu.habbo.database;
|
|
|
|
import com.eu.habbo.Emulator;
|
|
import com.eu.habbo.core.ConfigurationManager;
|
|
import com.zaxxer.hikari.HikariDataSource;
|
|
|
|
public class Database
|
|
{
|
|
|
|
private HikariDataSource dataSource;
|
|
|
|
|
|
private DatabasePool databasePool;
|
|
|
|
public Database(ConfigurationManager config)
|
|
{
|
|
|
|
long millis = System.currentTimeMillis();
|
|
|
|
boolean SQLException = false;
|
|
|
|
try
|
|
{
|
|
this.databasePool = new DatabasePool();
|
|
if (!this.databasePool.getStoragePooling(config))
|
|
{
|
|
Emulator.getLogging().logStart("Failed to connect to the database. Please check config.ini and make sure the MySQL process is running. Shutting down...");
|
|
SQLException = true;
|
|
return;
|
|
}
|
|
this.dataSource = this.databasePool.getDatabase();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
SQLException = true;
|
|
e.printStackTrace();
|
|
Emulator.getLogging().logStart("Failed to connect to your database.");
|
|
Emulator.getLogging().logStart(e.getMessage());
|
|
}
|
|
finally
|
|
{
|
|
if (SQLException)
|
|
Emulator.prepareShutdown();
|
|
}
|
|
|
|
Emulator.getLogging().logStart("Database -> Connected! (" + (System.currentTimeMillis() - millis) + " MS)");
|
|
}
|
|
|
|
|
|
public void dispose()
|
|
{
|
|
if (this.databasePool != null)
|
|
{
|
|
this.databasePool.getDatabase().close();
|
|
}
|
|
|
|
this.dataSource.close();
|
|
}
|
|
|
|
public HikariDataSource getDataSource()
|
|
{
|
|
return this.dataSource;
|
|
}
|
|
|
|
public DatabasePool getDatabasePool()
|
|
{
|
|
return this.databasePool;
|
|
}
|
|
}
|
|
|