use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class MySQLBackend method loadStatSettings.
@Override
public Map<MinigameStat, StatSettings> loadStatSettings(Minigame minigame) {
ConnectionHandler handler = null;
try {
handler = pool.getConnection();
int minigameId = getMinigameId(handler, minigame);
ResultSet rs = handler.executeQuery(loadStatSettings, minigameId);
Map<MinigameStat, StatSettings> settings = Maps.newHashMap();
try {
while (rs.next()) {
String statName = rs.getString("stat");
String rawFormat = rs.getString("format");
String displayName = rs.getString("display_name");
MinigameStat stat = MinigameStats.getStat(statName);
if (stat == null) {
// Just ignore it
continue;
}
// Decode format
StatFormat format = null;
for (StatFormat f : StatFormat.values()) {
if (f.name().equalsIgnoreCase(rawFormat)) {
format = f;
break;
}
}
if (format == null) {
format = stat.getFormat();
}
StatSettings setting = new StatSettings(stat, format, displayName);
settings.put(stat, setting);
}
return settings;
} finally {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
return Collections.emptyMap();
} finally {
if (handler != null) {
handler.release();
}
}
}
use of au.com.mineauz.minigames.backend.ConnectionHandler in project Minigames by AddstarMC.
the class SQLiteBackend method initialize.
@Override
public boolean initialize(ConfigurationSection config) {
try {
Class.forName("org.sqlite.JDBC");
// Create the pool
File path = new File(Minigames.plugin.getDataFolder(), "minigames.db");
String url = String.format("jdbc:sqlite:" + path.getAbsolutePath());
Properties properties = new Properties();
properties.put("username", "");
properties.put("password", "");
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 SQLite database. Please check your database settings");
}
} catch (ClassNotFoundException e) {
logger.severe("Failed to find sqlite JDBC driver. This version of craftbukkit is defective.");
}
return false;
}
Aggregations