use of util.Connexion in project KaellyBot by Kaysoro.
the class ChannelLanguage method setLanguage.
public synchronized void setLanguage(Language lang) {
this.lang = lang;
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE Channel_Language SET lang = ? WHERE id_chan = ?;");
preparedStatement.setString(1, getLang().getAbrev());
preparedStatement.setString(2, String.valueOf(getChannelId()));
preparedStatement.executeUpdate();
} catch (SQLException e) {
Reporter.report(e, ClientConfig.DISCORD().getChannelByID(getChannelId()).getGuild(), ClientConfig.DISCORD().getChannelByID(getChannelId()));
LOG.error("setLanguage", e);
}
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class CommandForbidden method removeToDatabase.
public synchronized void removeToDatabase() {
if (isSaved) {
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement request = connection.prepareStatement("DELETE FROM Command_Guild WHERE id_guild = ? AND name_command = ?;");
request.setString(1, getGuild().getId());
request.setString(2, getCommand().getName());
request.executeUpdate();
getGuild().getForbiddenCommands().remove(getCommand().getName());
isSaved = false;
} catch (SQLException e) {
Reporter.report(e, ClientConfig.DISCORD().getGuildByID(Long.parseLong(getGuild().getId())));
LOG.error("removeToDatabase", e);
}
}
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class Guild method removeToDatabase.
public synchronized void removeToDatabase() {
if (getGuilds().containsKey(id)) {
getGuilds().remove(id);
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement request = connection.prepareStatement("DELETE FROM Guild WHERE ID = ?;");
request.setString(1, id);
request.executeUpdate();
} catch (SQLException e) {
Reporter.report(e);
LOG.error(e.getMessage());
}
}
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class Guild method addToDatabase.
public synchronized void addToDatabase() {
if (!getGuilds().containsKey(id)) {
getGuilds().put(id, this);
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement request = connection.prepareStatement("INSERT INTO" + " Guild(id, name, prefixe) VALUES (?, ?, ?);");
request.setString(1, id);
request.setString(2, name);
request.setString(3, prefixe);
request.executeUpdate();
for (String portal : Portal.getPortals().keySet()) {
request = connection.prepareStatement("INSERT INTO Portal_Guild" + "(name_portal, id_guild) VALUES (?, ?);");
request.setString(1, portal);
request.setString(2, id);
request.executeUpdate();
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error(e.getMessage());
}
}
portals = Portal.getPortals(this);
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class Guild method getGuilds.
public static synchronized Map<String, Guild> getGuilds() {
if (guilds == null) {
guilds = new ConcurrentHashMap<>();
String id;
String name;
String prefixe;
String server;
String lang;
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT id, name, prefixe, server_dofus, lang FROM Guild");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
id = resultSet.getString("id");
name = resultSet.getString("name");
prefixe = resultSet.getString("prefixe");
server = resultSet.getString("server_dofus");
lang = resultSet.getString("lang");
guilds.put(id, new Guild(id, name, prefixe, Language.valueOf(lang), server));
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error(e.getMessage());
}
}
return guilds;
}
Aggregations