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());
}
}
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());
}
}
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);
}
}
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);
}
}
}
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;
}
Aggregations