use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class SQLiteBackend method saveStatSettings.
@Override
public void saveStatSettings(Minigame minigame, Collection<StatSettings> settings) {
ConnectionHandler handler = null;
try {
handler = pool.getConnection();
handler.beginTransaction();
int minigameId = getMinigameId(handler, minigame);
for (StatSettings setting : settings) {
handler.batchUpdate(saveStatSettings, minigameId, setting.getStat().getName(), setting.getDisplayName(), setting.getFormat().name().toUpperCase());
}
handler.executeBatch(saveStatSettings);
handler.endTransaction();
} catch (SQLException e) {
e.printStackTrace();
handler.endTransactionFail();
} finally {
if (handler != null) {
handler.release();
}
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class MySQLBackend method saveStatSettings.
@Override
public void saveStatSettings(Minigame minigame, Collection<StatSettings> settings) {
ConnectionHandler handler = null;
try {
handler = pool.getConnection();
handler.beginTransaction();
int minigameId = getMinigameId(handler, minigame);
for (StatSettings setting : settings) {
handler.batchUpdate(saveStatSettings, minigameId, setting.getStat().getName(), setting.getDisplayName(), setting.getFormat().name().toUpperCase());
}
handler.executeBatch(saveStatSettings);
handler.endTransaction();
} catch (SQLException e) {
e.printStackTrace();
handler.endTransactionFail();
} finally {
if (handler != null) {
handler.release();
}
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class MySQLBackend method initialize.
@Override
public boolean initialize(ConfigurationSection config) {
try {
Class.forName("com.mysql.jdbc.Driver");
database = config.getString("database", "database");
// Create the pool
String url = String.format("jdbc:mysql://%s/%s", config.getString("host", "localhost:3306"), database);
Properties properties = new Properties();
properties.put("user", config.getString("username", "username"));
properties.put("password", config.getString("password", "password"));
properties.put("useSSL", config.getBoolean("useSSL", false));
pool = new ConnectionPool(url, properties);
createStatements();
// Test the connection
try {
ConnectionHandler handler = pool.getConnection();
ensureTables(handler);
handler.release();
return true;
} catch (SQLException e) {
logger.severe("Failed to connect to the MySQL database. Please check your database settings");
}
} catch (ClassNotFoundException e) {
logger.severe("Failed to find MySQL JDBC driver. This version of craftbukkit is defective.");
}
return false;
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class MySQLStatLoader method loadSingleValue.
public long loadSingleValue(Minigame minigame, MinigameStat stat, StatValueField field, UUID playerId) {
ConnectionHandler handler = null;
try {
handler = backend.getPool().getConnection();
// First get the id
int minigameId = backend.getMinigameId(handler, minigame);
String statName = stat.getName() + field.getSuffix();
ResultSet rs = handler.executeQuery(getSingle, minigameId, playerId.toString(), statName);
try {
if (rs.next()) {
return rs.getLong("value");
} else {
return 0;
}
} finally {
rs.close();
}
} catch (SQLException e) {
logger.log(Level.SEVERE, "Failed to load stat for " + minigame.getName(false) + " " + playerId, e);
return 0;
} finally {
if (handler != null) {
handler.release();
}
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class MySQLStatLoader method loadStatValues.
public List<StoredStat> loadStatValues(Minigame minigame, MinigameStat stat, StatValueField field, ScoreboardOrder order, int offset, int length) {
MinigameUtils.debugMessage("MySQL beginning stat load for " + minigame.getName(false) + ", " + stat + ", " + field);
ConnectionHandler handler = null;
try {
handler = backend.getPool().getConnection();
// First get the id
int minigameId = backend.getMinigameId(handler, minigame);
return loadStats(handler, minigameId, stat, field, order, offset, length);
} catch (SQLException e) {
return Collections.emptyList();
} finally {
if (handler != null) {
handler.release();
}
MinigameUtils.debugMessage("MySQL completed stat load for " + minigame.getName(false));
}
}
Aggregations