Add Script SQL-Type #54
90
src/de/steamwar/sql/Script.java
Normale Datei
90
src/de/steamwar/sql/Script.java
Normale Datei
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class Script {
|
||||
Lixfel markierte diese Unterhaltung als gelöst
|
||||
|
||||
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 Statement update = table.updateFields(new String[]{"name"}, Table.PRIMARY);
|
||||
private static final Statement insert = table.insertAll();
|
||||
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);
|
||||
}
|
||||
|
||||
public static Script get(SteamwarUser user, String name) {
|
||||
return selectNameUser.select(user, name);
|
||||
}
|
||||
|
||||
public static Script create(SteamwarUser user, String name, String script) {
|
||||
int id = insert.insertGetKey(user, name, script);
|
||||
return get(id);
|
||||
}
|
||||
|
||||
@Field(keys = Table.PRIMARY, autoincrement = true)
|
||||
private final int id;
|
||||
@Field(keys = "nameUser")
|
||||
private final SteamwarUser user;
|
||||
@Field(keys = "nameUser")
|
||||
private String name;
|
||||
|
||||
Lixfel markierte diese Unterhaltung als gelöst
Veraltet
YoyoNow
hat
Es fehlt irgendwie Code Es fehlt irgendwie Code
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
update();
|
||||
}
|
||||
|
||||
public String getScript() {
|
||||
return getScript.select(rs -> {
|
||||
Lixfel markierte diese Unterhaltung als gelöst
Lixfel
hat
So ist das mit dem neuen System nicht ganz gedacht. Nutze doch SelectStatements. So ist das mit dem neuen System nicht ganz gedacht. Nutze doch SelectStatements.
|
||||
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 delete() {
|
||||
delete.update(id);
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren
Brauchst du nicht noch was womit du alle Scripte eines Users erhälst?