use of util.Connexion in project KaellyBot by Kaysoro.
the class OrderUser method getOrders.
public static synchronized Map<Quadruple<Long, ServerDofus, City, Order>, OrderUser> getOrders() {
if (orders == null) {
orders = new ConcurrentHashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT id_user, server_dofus, name_city, name_order, level FROM Order_User;");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
Long idUser = resultSet.getLong("id_user");
ServerDofus server = ServerDofus.getServersMap().get(resultSet.getString("server_dofus"));
City city = City.getCity(resultSet.getString("name_city"));
Order order = Order.getOrder(resultSet.getString("name_order"));
int level = resultSet.getInt("level");
orders.put(Quadruple.of(idUser, server, city, order), new OrderUser(idUser, server, city, order, level));
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error("getOrders", e);
}
}
return orders;
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class ServerDofus method initialize.
private static synchronized void initialize() {
initialized = true;
servers = new ArrayList<>();
serversMap = new HashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT name, id_dofus, id_sweet FROM Server");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
ServerDofus sd = new ServerDofus(resultSet.getString("name"), resultSet.getString("id_dofus"), resultSet.getString("id_sweet"));
servers.add(sd);
serversMap.put(sd.getName(), sd);
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error("initialize", e);
}
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class TwitterFinder method removeToDatabase.
public synchronized void removeToDatabase() {
getTwitterChannels().remove(getChannelId());
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement request = connection.prepareStatement("DELETE FROM Twitter WHERE id_chan = ?;");
request.setString(1, String.valueOf(getChannelId()));
request.executeUpdate();
} catch (SQLException e) {
Reporter.report(e, ClientConfig.DISCORD().getGuildByID(getGuildId()), ClientConfig.DISCORD().getChannelByID(getChannelId()));
LOG.error("removeToDatabase", e);
}
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class TwitterFinder method getTwitterChannels.
public static synchronized Map<Long, TwitterFinder> getTwitterChannels() {
if (twitterChannels == null) {
twitterChannels = new ConcurrentHashMap<>();
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement query = connection.prepareStatement("SELECT id_guild, id_chan FROM Twitter");
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
long idChan = Long.parseLong(resultSet.getString("id_chan"));
long idGuild = Long.parseLong(resultSet.getString("id_guild"));
IChannel chan = ClientConfig.DISCORD().getChannelByID(idChan);
if (chan != null && !chan.isDeleted())
twitterChannels.put(chan.getLongID(), new TwitterFinder(idGuild, idChan));
else {
new TwitterFinder(idGuild, idChan).removeToDatabase();
LOG.info("Chan deleted : " + idChan);
}
}
} catch (SQLException e) {
Reporter.report(e);
LOG.error("getTwitterChannels", e);
}
}
return twitterChannels;
}
use of util.Connexion in project KaellyBot by Kaysoro.
the class TwitterFinder method addToDatabase.
public synchronized void addToDatabase() {
if (!getTwitterChannels().containsKey(getChannelId())) {
getTwitterChannels().put(getChannelId(), this);
Connexion connexion = Connexion.getInstance();
Connection connection = connexion.getConnection();
try {
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO Twitter(id_chan, id_guild) VALUES(?, ?);");
preparedStatement.setString(1, String.valueOf(getChannelId()));
preparedStatement.setString(2, String.valueOf(getGuildId()));
preparedStatement.executeUpdate();
} catch (SQLException e) {
Reporter.report(e, ClientConfig.DISCORD().getGuildByID(getGuildId()), ClientConfig.DISCORD().getChannelByID(getChannelId()));
LOG.error("addToDatabase", e);
}
}
}
Aggregations