Skip to content
Snippets Groups Projects
Commit fffc1522 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Modification de la méthode setUserSetting pour utiliser bjLoquent, et mise à...

Modification de la méthode setUserSetting pour utiliser bjLoquent, et mise à jour de ce dernier pour l'ajout du support des clés primaires composites.
parent 89c64d3b
Branches
No related tags found
No related merge requests found
Pipeline #112 passed
......@@ -98,11 +98,10 @@
<version>5.4</version>
<scope>provided</scope>
</dependency>
<!-- Version du 22 Avril 2023 -->
<dependency>
<groupId>com.github.SofianeLasri</groupId>
<artifactId>bjLoquent</artifactId>
<version>6729e4b</version>
<version>db12baa</version>
</dependency>
</dependencies>
</project>
......@@ -9,7 +9,7 @@ public class UserSetting extends Model {
public UserSetting() {
super.tableName = "site_userSetting";
super.primaryKeyName = "uuid";
super.primaryKey = new String[]{"uuid", "name"};
}
public String getUuid() {
......
......@@ -2,6 +2,7 @@ package com.slprojects.slcraftplugin.utils;
import com.slprojects.slcraftplugin.models.UserSetting;
import com.slprojects.slcraftplugin.utils.database.Configuration;
import net.luckperms.api.model.user.User;
import org.bjloquent.Connector;
import org.bjloquent.Model;
......@@ -46,36 +47,23 @@ public class Database {
* @param value Valeur de la clé
*/
public static void setUserSetting(String uuid, String key, String value) {
Connection con;
try {
con = bddOpenConn();
} catch (SQLException e) {
ConsoleLog.danger("Impossible d'ouvrir la connexion à la bdd.");
throw new RuntimeException(e);
}
boolean isEntryExists = (getUserSetting(uuid, key) != null);
List<UserSetting> userSettingExists = Model.where(
UserSetting.class,
new String[]{"uuid", "name"},
new String[]{"=", "="},
new String[]{uuid, key}
);
try {
if (isEntryExists) {
PreparedStatement updateEntry = con.prepareStatement("UPDATE " + userSettingsTabName + " SET value = ? WHERE uuid = ? AND name = ?");
updateEntry.setString(1, value);
updateEntry.setString(2, uuid);
updateEntry.setString(3, key);
updateEntry.executeUpdate();
if (userSettingExists.size() == 0) {
UserSetting userSetting = new UserSetting();
userSetting.setUuid(uuid);
userSetting.setName(key);
userSetting.setValue(value);
userSetting.create();
} else {
insertUserSettingEntry(uuid, key, value);
}
} catch (SQLException e) {
ConsoleLog.danger("Erreur lors de l'exécution de la requête sql.");
throw new RuntimeException(e);
}
// On ferme la bdd
try {
con.close();
} catch (SQLException e) {
ConsoleLog.danger("Impossible de fermer la connexion à la bdd.");
throw new RuntimeException(e);
UserSetting userSetting = userSettingExists.get(0);
userSetting.setValue(value);
userSetting.save();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment