Search in sources :

Example 11 with Connexion

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

Example 12 with Connexion

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

Example 13 with Connexion

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());
        }
    }
}
Also used : Connexion(util.Connexion)

Example 14 with Connexion

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);
}
Also used : Connexion(util.Connexion)

Example 15 with Connexion

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;
}
Also used : Connexion(util.Connexion) IGuild(sx.blah.discord.handle.obj.IGuild)

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