Dieser Commit ist enthalten in:
Ursprung
f07ad1cbf5
Commit
d6ef17cbe7
@ -34,61 +34,48 @@ public class Script {
|
|||||||
|
|
||||||
private static final Table<Script> table = new Table<>(Script.class);
|
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> byId = table.select(Table.PRIMARY);
|
||||||
private static final SelectStatement<Script> selectNameUser = table.select("nameUser");
|
private static final SelectStatement<Script> byUserName = 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> 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 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 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) {
|
public static Script get(int id) {
|
||||||
return select.select(id);
|
return byId.select(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Script get(SteamwarUser user, String name) {
|
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) {
|
public static Script create(SteamwarUser user, String name, String code) {
|
||||||
int id = insert.insertGetKey(user, name, script);
|
return new Script(insert.insertGetKey(user, name, code), user.getId(), name, code);
|
||||||
return get(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Script> list(SteamwarUser user) {
|
public static List<Script> list(SteamwarUser user) {
|
||||||
return list.listSelect(user);
|
return byUser.listSelect(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Field(keys = Table.PRIMARY, autoincrement = true)
|
@Field(keys = Table.PRIMARY, autoincrement = true)
|
||||||
private final int id;
|
private final int id;
|
||||||
@Field(keys = "nameUser")
|
@Field(keys = "nameUser")
|
||||||
private final SteamwarUser user;
|
private final int userId;
|
||||||
@Field(keys = "nameUser")
|
@Field(keys = "nameUser")
|
||||||
private String name;
|
private String name;
|
||||||
|
@Field
|
||||||
|
private String code;
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
update();
|
updateName.update(name, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getScript() {
|
public void setCode(String code) {
|
||||||
return getScript.select(rs -> {
|
this.code = code;
|
||||||
if(rs.next()) {
|
updateCode.update(code, id);
|
||||||
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 delete() {
|
public void delete() {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren