Dieser Commit ist enthalten in:
Ursprung
66fc131803
Commit
9b22e77f9b
81
src/de/steamwar/sql/Token.java
Normale Datei
81
src/de/steamwar/sql/Token.java
Normale Datei
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class Token {
|
||||
private static final Table<Token> table = new Table<>(Token.class);
|
||||
private static final Statement insert = table.insertFields(true, "Name", "Owner", "Hash");
|
||||
private static final SelectStatement<Token> get = table.select(Table.PRIMARY);
|
||||
private static final SelectStatement<Token> listUser = table.selectFields("owner");
|
||||
private static final SelectStatement<Token> getHash = table.selectFields("hash");
|
||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
||||
|
||||
public static Token create(String name, SteamwarUser owner, String hash) {
|
||||
int id = insert.insertGetKey(name, owner, hash);
|
||||
return get(id);
|
||||
}
|
||||
|
||||
public static Token get(int id) {
|
||||
return get.select(id);
|
||||
}
|
||||
|
||||
public static List<Token> listUser(SteamwarUser owner) {
|
||||
return listUser.listSelect(owner);
|
||||
}
|
||||
|
||||
public static Token get(String hash) {
|
||||
return getHash.select(hash);
|
||||
}
|
||||
|
||||
public static void delete(Token id) {
|
||||
delete.update(id.getId());
|
||||
}
|
||||
|
||||
@Field(keys = Table.PRIMARY, autoincrement = true)
|
||||
private final int id;
|
||||
@Field(keys = "NameOwner")
|
||||
private final String name;
|
||||
@Field(keys = "NameOwner")
|
||||
private final int owner;
|
||||
@Field
|
||||
private final Timestamp created;
|
||||
@Field
|
||||
private final String hash;
|
||||
|
||||
public void delete() {
|
||||
delete(this);
|
||||
}
|
||||
|
||||
public SteamwarUser getOwner() {
|
||||
return SteamwarUser.get(owner);
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren