From d439ecb8d01d576310766e497c970bce7eb1db2f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Feb 2023 12:54:50 +0100 Subject: [PATCH] WIP CommonDB Signed-off-by: Lixfel --- src/de/steamwar/sql/BauweltMember.java | 35 ++++++++++++++++++--- src/de/steamwar/sql/SchematicType.java | 18 ++++++----- src/de/steamwar/sql/internal/Statement.java | 4 +-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/sql/BauweltMember.java b/src/de/steamwar/sql/BauweltMember.java index aa3ed93..87393e8 100644 --- a/src/de/steamwar/sql/BauweltMember.java +++ b/src/de/steamwar/sql/BauweltMember.java @@ -21,6 +21,7 @@ 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.Getter; @@ -36,6 +37,12 @@ public class BauweltMember { private static final Table table = new Table<>(BauweltMember.class); private static final SelectStatement getMember = table.select(Table.PRIMARY); private static final SelectStatement 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){ 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){ BauweltMember member = memberCache.get(memberID); - if(member != null) + if(member != null && member.bauweltID == ownerID) return member; return getMember.select(ownerID, memberID); } @@ -63,11 +70,11 @@ public class BauweltMember { @Field(keys = {Table.PRIMARY}) private final int memberID; @Getter - @Field - private final boolean worldEdit; + @Field(def = "0") + private boolean worldEdit; @Getter - @Field - private final boolean world; + @Field(def = "0") + private boolean world; public BauweltMember(int bauweltID, int memberID, boolean worldEdit, boolean world) { this.bauweltID = bauweltID; @@ -76,4 +83,22 @@ public class BauweltMember { this.world = world; 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); + } } diff --git a/src/de/steamwar/sql/SchematicType.java b/src/de/steamwar/sql/SchematicType.java index d87065c..43cfb44 100644 --- a/src/de/steamwar/sql/SchematicType.java +++ b/src/de/steamwar/sql/SchematicType.java @@ -20,6 +20,7 @@ package de.steamwar.sql; import de.steamwar.sql.internal.SqlTypeMapper; +import lombok.Getter; import java.util.*; @@ -51,17 +52,26 @@ public class SchematicType { } private final String name; + @Getter private final String kuerzel; private final Type type; private final SchematicType checkType; + @Getter private final String material; + @Getter + private final Date deadline; 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.kuerzel = kuerzel; this.type = type; this.checkType = checkType; this.material = material; + this.deadline = deadline; } public boolean isAssignable(){ @@ -88,14 +98,6 @@ public class SchematicType { return name; } - public String getKuerzel() { - return kuerzel; - } - - public String getMaterial() { - return material; - } - public String toDB(){ return name.toLowerCase(); } diff --git a/src/de/steamwar/sql/internal/Statement.java b/src/de/steamwar/sql/internal/Statement.java index e842d5f..c29f711 100644 --- a/src/de/steamwar/sql/internal/Statement.java +++ b/src/de/steamwar/sql/internal/Statement.java @@ -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() { synchronized (connections) { @@ -234,7 +234,7 @@ public class Statement implements AutoCloseable { private static Connection aquireConnection() { synchronized (connections) { - while(connections.isEmpty() && connectionBudget == 0) + while(connections.isEmpty() && connectionBudget <= 0) waitOnConnections(); if(!connections.isEmpty()) {