WIP CommonDB
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2023-02-04 12:54:50 +01:00
Ursprung fca45b084e
Commit d439ecb8d0
3 geänderte Dateien mit 42 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.sql;
import de.steamwar.sql.internal.Field; import de.steamwar.sql.internal.Field;
import de.steamwar.sql.internal.SelectStatement; import de.steamwar.sql.internal.SelectStatement;
import de.steamwar.sql.internal.Statement;
import de.steamwar.sql.internal.Table; import de.steamwar.sql.internal.Table;
import lombok.Getter; import lombok.Getter;
@ -36,6 +37,12 @@ public class BauweltMember {
private static final Table<BauweltMember> table = new Table<>(BauweltMember.class); private static final Table<BauweltMember> table = new Table<>(BauweltMember.class);
private static final SelectStatement<BauweltMember> getMember = table.select(Table.PRIMARY); private static final SelectStatement<BauweltMember> getMember = table.select(Table.PRIMARY);
private static final SelectStatement<BauweltMember> getMembers = table.selectFields("BauweltID"); private static final SelectStatement<BauweltMember> getMembers = table.selectFields("BauweltID");
private static final Statement update = table.insertAll();
private static final Statement delete = table.delete(Table.PRIMARY);
public static void addMember(UUID ownerID, UUID memberID) {
new BauweltMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId(), false, false).updateDB();
}
public static BauweltMember getBauMember(UUID ownerID, UUID memberID){ public static BauweltMember getBauMember(UUID ownerID, UUID memberID){
return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId()); return getBauMember(SteamwarUser.get(ownerID).getId(), SteamwarUser.get(memberID).getId());
@ -43,7 +50,7 @@ public class BauweltMember {
public static BauweltMember getBauMember(int ownerID, int memberID){ public static BauweltMember getBauMember(int ownerID, int memberID){
BauweltMember member = memberCache.get(memberID); BauweltMember member = memberCache.get(memberID);
if(member != null) if(member != null && member.bauweltID == ownerID)
return member; return member;
return getMember.select(ownerID, memberID); return getMember.select(ownerID, memberID);
} }
@ -63,11 +70,11 @@ public class BauweltMember {
@Field(keys = {Table.PRIMARY}) @Field(keys = {Table.PRIMARY})
private final int memberID; private final int memberID;
@Getter @Getter
@Field @Field(def = "0")
private final boolean worldEdit; private boolean worldEdit;
@Getter @Getter
@Field @Field(def = "0")
private final boolean world; private boolean world;
public BauweltMember(int bauweltID, int memberID, boolean worldEdit, boolean world) { public BauweltMember(int bauweltID, int memberID, boolean worldEdit, boolean world) {
this.bauweltID = bauweltID; this.bauweltID = bauweltID;
@ -76,4 +83,22 @@ public class BauweltMember {
this.world = world; this.world = world;
memberCache.put(memberID, this); memberCache.put(memberID, this);
} }
public void setWorldEdit(boolean worldEdit) {
this.worldEdit = worldEdit;
updateDB();
}
public void setWorld(boolean world) {
this.world = world;
updateDB();
}
private void updateDB(){
update.update(bauweltID, memberID, worldEdit, world);
}
public void remove(){
delete.update(bauweltID, memberID);
}
} }

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.sql; package de.steamwar.sql;
import de.steamwar.sql.internal.SqlTypeMapper; import de.steamwar.sql.internal.SqlTypeMapper;
import lombok.Getter;
import java.util.*; import java.util.*;
@ -51,17 +52,26 @@ public class SchematicType {
} }
private final String name; private final String name;
@Getter
private final String kuerzel; private final String kuerzel;
private final Type type; private final Type type;
private final SchematicType checkType; private final SchematicType checkType;
@Getter
private final String material; private final String material;
@Getter
private final Date deadline;
SchematicType(String name, String kuerzel, Type type, SchematicType checkType, String material){ SchematicType(String name, String kuerzel, Type type, SchematicType checkType, String material){
this(name, kuerzel, type, checkType, material, null);
}
SchematicType(String name, String kuerzel, Type type, SchematicType checkType, String material, Date deadline){
this.name = name; this.name = name;
this.kuerzel = kuerzel; this.kuerzel = kuerzel;
this.type = type; this.type = type;
this.checkType = checkType; this.checkType = checkType;
this.material = material; this.material = material;
this.deadline = deadline;
} }
public boolean isAssignable(){ public boolean isAssignable(){
@ -88,14 +98,6 @@ public class SchematicType {
return name; return name;
} }
public String getKuerzel() {
return kuerzel;
}
public String getMaterial() {
return material;
}
public String toDB(){ public String toDB(){
return name.toLowerCase(); return name.toLowerCase();
} }

Datei anzeigen

@ -95,7 +95,7 @@ public class Statement implements AutoCloseable {
} }
} }
private static int connectionBudget = MAX_CONNECTIONS; private static volatile int connectionBudget = MAX_CONNECTIONS;
public static void closeAll() { public static void closeAll() {
synchronized (connections) { synchronized (connections) {
@ -234,7 +234,7 @@ public class Statement implements AutoCloseable {
private static Connection aquireConnection() { private static Connection aquireConnection() {
synchronized (connections) { synchronized (connections) {
while(connections.isEmpty() && connectionBudget == 0) while(connections.isEmpty() && connectionBudget <= 0)
waitOnConnections(); waitOnConnections();
if(!connections.isEmpty()) { if(!connections.isEmpty()) {