Search in sources :

Example 6 with Connexion

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;
}
Also used : Order(enums.Order) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) City(enums.City) Connexion(util.Connexion)

Example 7 with Connexion

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 8 with Connexion

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 9 with Connexion

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;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 10 with Connexion

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);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Aggregations

Connexion (util.Connexion)24 Connection (java.sql.Connection)17 PreparedStatement (java.sql.PreparedStatement)17 SQLException (java.sql.SQLException)17 ResultSet (java.sql.ResultSet)6 IChannel (sx.blah.discord.handle.obj.IChannel)2 City (enums.City)1 Job (enums.Job)1 Language (enums.Language)1 Order (enums.Order)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IGuild (sx.blah.discord.handle.obj.IGuild)1