Fix Script class
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-06-05 16:01:34 +02:00
Ursprung f07ad1cbf5
Commit d6ef17cbe7

Datei anzeigen

@ -34,61 +34,48 @@ public class Script {
private static final Table<Script> table = new Table<>(Script.class);
private static final SelectStatement<Script> select = table.select(Table.PRIMARY);
private static final SelectStatement<Script> selectNameUser = table.select("nameUser");
private static final SelectStatement<Script> list = new SelectStatement<>(table, "SELECT Id, User, Name FROM Script WHERE User = ?");
private static final SelectStatement<Script> byId = table.select(Table.PRIMARY);
private static final SelectStatement<Script> byUserName = table.select("nameUser");
private static final SelectStatement<Script> byUser = table.selectFields("user");
private static final Statement update = table.updateFields(new String[]{"name"}, Table.PRIMARY);
private static final Statement insert = table.insertAll();
private static final Statement updateName = table.update(Table.PRIMARY, "name");
private static final Statement updateCode = table.update(Table.PRIMARY, "code");
private static final Statement delete = table.delete(Table.PRIMARY);
private static final Statement getScript = new Statement("SELECT Code FROM Script WHERE id = ?");
private static final Statement updateScript = new Statement("UPDATE Script SET Code = ? WHERE id = ?");
public static Script get(int id) {
return select.select(id);
return byId.select(id);
}
public static Script get(SteamwarUser user, String name) {
return selectNameUser.select(user, name);
return byUserName.select(user, name);
}
public static Script create(SteamwarUser user, String name, String script) {
int id = insert.insertGetKey(user, name, script);
return get(id);
public static Script create(SteamwarUser user, String name, String code) {
return new Script(insert.insertGetKey(user, name, code), user.getId(), name, code);
}
public static List<Script> list(SteamwarUser user) {
return list.listSelect(user);
return byUser.listSelect(user);
}
@Field(keys = Table.PRIMARY, autoincrement = true)
private final int id;
@Field(keys = "nameUser")
private final SteamwarUser user;
private final int userId;
@Field(keys = "nameUser")
private String name;
@Field
private String code;
public void setName(String name) {
this.name = name;
update();
updateName.update(name, id);
}
public String getScript() {
return getScript.select(rs -> {
if(rs.next()) {
return rs.getString("Code");
}
return null;
}, id);
}
public void setScript(String script) {
updateScript.update(script, id);
}
private void update() {
update.update(name, id);
public void setCode(String code) {
this.code = code;
updateCode.update(code, id);
}
public void delete() {