Search in sources :

Example 1 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class Guild method setPrefixe.

public synchronized void setPrefixe(String prefixe) {
    this.prefixe = prefixe;
    Connexion connexion = Connexion.getInstance();
    Connection connection = connexion.getConnection();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement("UPDATE Guild SET prefixe = ? WHERE id = ?;");
        preparedStatement.setString(1, prefixe);
        preparedStatement.setString(2, id);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        Reporter.report(e);
        LOG.error(e.getMessage());
    }
}
Also used : Connexion(util.Connexion)

Example 2 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class Guild method setServer.

public synchronized void setServer(ServerDofus server) {
    this.server = server;
    Connexion connexion = Connexion.getInstance();
    Connection connection = connexion.getConnection();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement("UPDATE Guild SET server_dofus = ? WHERE id = ?;");
        if (server != null)
            preparedStatement.setString(1, server.getName());
        else
            preparedStatement.setNull(1, Types.VARCHAR);
        preparedStatement.setString(2, id);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        Reporter.report(e);
        LOG.error(e.getMessage());
    }
}
Also used : Connexion(util.Connexion)

Example 3 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class JobUser method setLevel.

public synchronized void setLevel(int level) {
    if (level > 200)
        level = 200;
    this.level = level;
    Connexion connexion = Connexion.getInstance();
    Connection connection = connexion.getConnection();
    try {
        PreparedStatement preparedStatement;
        if (level > 0) {
            preparedStatement = connection.prepareStatement("UPDATE Job_User SET level = ?" + "WHERE name_job = ? AND id_user = ? AND server_dofus = ?;");
            preparedStatement.setInt(1, level);
            preparedStatement.setString(2, job.getName());
            preparedStatement.setString(3, String.valueOf(idUser));
            preparedStatement.setString(4, server.getName());
        } else {
            preparedStatement = connection.prepareStatement("DELETE FROM Job_User WHERE name_job = ? AND id_user = ? AND server_dofus = ?;");
            preparedStatement.setString(1, job.getName());
            preparedStatement.setString(2, String.valueOf(idUser));
            preparedStatement.setString(3, server.getName());
        }
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        Reporter.report(e, ClientConfig.DISCORD().getUserByID(idUser));
        LOG.error("setLevel", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 4 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class JobUser method addToDatabase.

/**
 * Ajoute à la base de donnée l'objet si celui-ci n'y est pas déjà.
 */
public synchronized void addToDatabase() {
    if (!getJobs().containsKey(Triple.of(idUser, server, job)) && level > 0) {
        getJobs().put(Triple.of(idUser, server, job), this);
        Connexion connexion = Connexion.getInstance();
        Connection connection = connexion.getConnection();
        try {
            PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO Job_User(name_job, id_user, server_dofus, level) VALUES(?, ?, ?, ?);");
            preparedStatement.setString(1, job.getName());
            preparedStatement.setString(2, String.valueOf(idUser));
            preparedStatement.setString(3, server.getName());
            preparedStatement.setInt(4, level);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            Reporter.report(e, ClientConfig.DISCORD().getUserByID(idUser));
            LOG.error("addToDatabase", e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 5 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class JobUser method getJobs.

private static synchronized Map<Triple<Long, ServerDofus, Job>, JobUser> getJobs() {
    if (jobs == null) {
        jobs = new ConcurrentHashMap<>();
        Connexion connexion = Connexion.getInstance();
        Connection connection = connexion.getConnection();
        try {
            PreparedStatement query = connection.prepareStatement("SELECT id_user, server_dofus, name_job, level FROM Job_User;");
            ResultSet resultSet = query.executeQuery();
            while (resultSet.next()) {
                Long idUser = resultSet.getLong("id_user");
                ServerDofus server = ServerDofus.getServersMap().get(resultSet.getString("server_dofus"));
                Job job = Job.getJob(resultSet.getString("name_job"));
                int level = resultSet.getInt("level");
                jobs.put(Triple.of(idUser, server, job), new JobUser(idUser, server, job, level));
            }
        } catch (SQLException e) {
            Reporter.report(e);
            LOG.error("getJobs", e);
        }
    }
    return jobs;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion) Job(enums.Job)

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