Skip to content

Commit 33a0c00

Browse files
committed
Actually made an ID System instead of using Random.
1 parent 04f4628 commit 33a0c00

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>de.ree6</groupId>
88
<artifactId>Ree6-SQL</artifactId>
99
<description>This is the SQL-Module for Ree6!</description>
10-
<version>2.2.4</version>
10+
<version>2.2.5</version>
1111

1212
<properties>
1313
<sonar.organization>ree6-applications</sonar.organization>

src/main/java/de/presti/ree6/sql/SQLWorker.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import de.presti.ree6.sql.entities.stats.Statistics;
1414
import de.presti.ree6.sql.entities.webhook.*;
1515
import de.presti.ree6.sql.entities.webhook.base.Webhook;
16+
import de.presti.ree6.sql.entities.webhook.base.WebhookSocial;
1617
import de.presti.ree6.sql.util.SettingsManager;
1718
import io.sentry.Sentry;
1819
import jakarta.persistence.PersistenceException;
@@ -1712,7 +1713,7 @@ public void addChatProtectorWord(long guildId, String word) {
17121713
*/
17131714
public void removeChatProtectorWord(long guildId, String word) {
17141715
Blacklist blacklist =
1715-
getEntity(new Blacklist(), "FROM Blacklist WHERE guildAndId.guildId = :gid AND guildAndName.name = :word",
1716+
getEntity(new Blacklist(), "FROM Blacklist WHERE guildAndName.guildId = :gid AND guildAndName.name = :word",
17161717
Map.of("gid", guildId, "word", word));
17171718

17181719
// Check if there is no entry for it.
@@ -2220,6 +2221,24 @@ public <R> R updateEntity(R r) {
22202221
}
22212222
}
22222223

2224+
// TODO:: Need a better way to handle this.
2225+
if (r instanceof Punishments punishments) {
2226+
if (punishments.getId() <= 0) {
2227+
long maxId = (Long) getEntityList(r, "select max(guildAndId.id) from " + r.getClass().getName(), null, false, 1).get(0);
2228+
((Punishments)r).getGuildAndId().setId(maxId + 1);
2229+
}
2230+
} else if (r instanceof ScheduledMessage scheduledMessage) {
2231+
if (scheduledMessage.getId() <= 0) {
2232+
long maxId = (Long) getEntityList(r, "select max(guildAndId.id) from " + r.getClass().getName(), null, false, 1).get(0);
2233+
((ScheduledMessage)r).getGuildAndId().setId(maxId + 1);
2234+
}
2235+
} else if (r instanceof WebhookSocial webhookSocial) {
2236+
if (webhookSocial.getId() <= 0) {
2237+
long maxId = (Long) getEntityList(r, "select max(guildAndId.id) from " + r.getClass().getName(), null, false, 1).get(0);
2238+
((WebhookSocial)r).getGuildAndId().setId(maxId + 1);
2239+
}
2240+
}
2241+
22232242
try (Session session = SQLSession.getSessionFactory().openSession()) {
22242243

22252244
session.beginTransaction();

src/main/java/de/presti/ree6/sql/entities/webhook/base/WebhookSocial.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ public WebhookSocial(long guildId, long channelId, long webhookId, String token)
5353
this.token = token;
5454
}
5555

56+
/**
57+
* Get the ID of the Webhook.
58+
* @return The ID of the Webhook.
59+
*/
60+
public long getId() {
61+
if (guildAndId == null)
62+
return -1;
63+
64+
return guildAndId.getId();
65+
}
66+
5667
/**
5768
* Set the GuildID of the Webhook.
5869
* @param guildId The GuildID of the Webhook.

src/main/java/de/presti/ree6/sql/keys/GuildAndId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class GuildAndId implements Serializable {
3838
* @param guildId The Discord Guild ID.
3939
*/
4040
public GuildAndId(long guildId) {
41-
this.id = ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
41+
this.id = -1;
4242
this.guildId = guildId;
4343
}
4444

src/test/java/Main.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import de.presti.ree6.sql.DatabaseTyp;
22
import de.presti.ree6.sql.SQLSession;
3+
import de.presti.ree6.sql.entities.webhook.WebhookYouTube;
34
import de.presti.ree6.sql.util.SQLConfig;
45

56
import java.sql.ResultSet;
@@ -31,6 +32,9 @@ public static void main(String[] args) throws SQLException {
3132
}
3233
}
3334

35+
WebhookYouTube hook = new WebhookYouTube(-1, "test", "test", -1, -1, "test");
36+
SQLSession.getSqlConnector().getSqlWorker().updateEntity(hook);
37+
3438
SQLSession.getSqlConnector().getSqlWorker().getEntityList(new de.presti.ree6.sql.entities.Warning(), "", null);
3539
SQLSession.getSqlConnector().getSqlWorker().getEntityList(new de.presti.ree6.sql.entities.Giveaway(), "", null);
3640
SQLSession.getSqlConnector().getSqlWorker().getEntityList(new de.presti.ree6.sql.entities.roles.AutoRole(), "", null);

0 commit comments

Comments
 (0)