Skip to content

Commit ddb43dd

Browse files
committed
Cleaning up some stuff.
1 parent d3a7e3c commit ddb43dd

File tree

11 files changed

+211
-88
lines changed

11 files changed

+211
-88
lines changed

src/main/java/de/presti/ree6/sql/entities/Blacklist.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.presti.ree6.sql.entities;
22

3+
import de.presti.ree6.sql.keys.GuildAndId;
34
import jakarta.persistence.*;
45

56
/**
@@ -10,18 +11,10 @@
1011
public class Blacklist {
1112

1213
/**
13-
* The PrimaryKey of the Entity.
14+
* The ID of the Entity.
1415
*/
15-
@Id
16-
@GeneratedValue(strategy = GenerationType.IDENTITY)
17-
@Column(name = "id")
18-
private int id;
19-
20-
/**
21-
* The ID of the Guild.
22-
*/
23-
@Column(name = "guildId")
24-
private long guildId;
16+
@EmbeddedId
17+
private GuildAndId guildAndId;
2518

2619
/**
2720
* The blacklisted word.
@@ -42,7 +35,7 @@ public Blacklist() {
4235
* @param word the blacklisted word.
4336
*/
4437
public Blacklist(long guildId, String word) {
45-
this.guildId = guildId;
38+
guildAndId = new GuildAndId(guildId);
4639
this.word = word;
4740
}
4841

@@ -52,7 +45,10 @@ public Blacklist(long guildId, String word) {
5245
* @return {@link String} as GuildID.
5346
*/
5447
public long getGuildId() {
55-
return guildId;
48+
if (guildAndId == null)
49+
return 0;
50+
51+
return guildAndId.getGuildId();
5652
}
5753

5854
/**

src/main/java/de/presti/ree6/sql/entities/Invite.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.presti.ree6.sql.entities;
22

3+
import de.presti.ree6.sql.keys.GuildAndId;
34
import jakarta.persistence.*;
45

56
/**
@@ -12,16 +13,8 @@ public class Invite {
1213
/**
1314
* The PrimaryKey of the Entity.
1415
*/
15-
@Id
16-
@GeneratedValue(strategy = GenerationType.IDENTITY)
17-
@Column(name = "id")
18-
private int id;
19-
20-
/**
21-
* The GuildID of the Invite.
22-
*/
23-
@Column(name = "guildId")
24-
long guild;
16+
@EmbeddedId
17+
GuildAndId guildAndId;
2518

2619
/**
2720
* The UserID of the Invite.
@@ -56,7 +49,7 @@ public Invite() {
5649
* @param code the Code of the Invite.
5750
*/
5851
public Invite(long guild, long userId, long uses, String code) {
59-
this.guild = guild;
52+
this.guildAndId = new GuildAndId(guild);
6053
this.userId = userId;
6154
this.uses = uses;
6255
this.code = code;
@@ -68,7 +61,10 @@ public Invite(long guild, long userId, long uses, String code) {
6861
* @return {@link String} as GuildID.
6962
*/
7063
public long getGuild() {
71-
return guild;
64+
if (guildAndId == null)
65+
return 0;
66+
67+
return guildAndId.getGuildId();
7268
}
7369

7470
/**

src/main/java/de/presti/ree6/sql/entities/Punishments.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.presti.ree6.sql.entities;
22

3+
import de.presti.ree6.sql.keys.GuildAndId;
34
import jakarta.persistence.*;
45
import lombok.AllArgsConstructor;
56
import lombok.Getter;
@@ -18,16 +19,10 @@
1819
public class Punishments {
1920

2021
/**
21-
* The id of the punishment.
22+
* Primary key for the entity.
2223
*/
23-
@Id
24-
@GeneratedValue(strategy = GenerationType.IDENTITY)
25-
long id;
26-
27-
/**
28-
* The guild that it is bound to.
29-
*/
30-
long guildId;
24+
@EmbeddedId
25+
GuildAndId guildAndId;
3126

3227
/**
3328
* The required warnings.

src/main/java/de/presti/ree6/sql/entities/ReactionRole.java

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.presti.ree6.sql.entities;
22

33

4+
import de.presti.ree6.sql.keys.GuildAndId;
45
import jakarta.persistence.*;
56
import lombok.AllArgsConstructor;
67
import lombok.Getter;
@@ -19,18 +20,10 @@
1920
public class ReactionRole {
2021

2122
/**
22-
* The PrimaryKey of the Entity.
23+
* The Key of the Entity.
2324
*/
24-
@Id
25-
@Column(name = "id")
26-
@GeneratedValue(strategy = GenerationType.IDENTITY)
27-
private long id;
28-
29-
/**
30-
* The ID of the Guild.
31-
*/
32-
@Column(name = "guildId")
33-
private long guildId;
25+
@EmbeddedId
26+
GuildAndId guildAndId;
3427

3528
/**
3629
* The ID of the Emote used as reaction.
@@ -66,11 +59,13 @@ public class ReactionRole {
6659
* Constructor for the Reaction role.
6760
* @param guildId the GuildID.
6861
* @param emoteId the EmoteId.
62+
* @param formattedEmote the formatted Emote.
6963
* @param roleId the Role ID.
7064
* @param messageId the Message ID.
7165
*/
7266
public ReactionRole(long guildId, long emoteId, String formattedEmote, long roleId, long messageId) {
73-
this.guildId = guildId;
67+
this.guildAndId = new GuildAndId(guildId);
68+
this.formattedEmote = formattedEmote;
7469
this.emoteId = emoteId;
7570
this.roleId = roleId;
7671
this.messageId = messageId;

src/main/java/de/presti/ree6/sql/entities/ScheduledMessage.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.presti.ree6.sql.entities;
22

33
import de.presti.ree6.sql.entities.webhook.WebhookScheduledMessage;
4+
import de.presti.ree6.sql.keys.GuildAndId;
45
import jakarta.persistence.*;
56
import lombok.AccessLevel;
67
import lombok.Getter;
@@ -20,17 +21,10 @@
2021
public class ScheduledMessage {
2122

2223
/**
23-
* The ID of the entity.
24+
* Key of the Entity.
2425
*/
25-
@Id
26-
@GeneratedValue(strategy = GenerationType.IDENTITY)
27-
long Id;
28-
29-
/**
30-
* The ID of the Guild.
31-
*/
32-
@Column(name = "guild")
33-
long guildId;
26+
@EmbeddedId
27+
GuildAndId guildAndId;
3428

3529
/**
3630
* Special message content.

src/main/java/de/presti/ree6/sql/entities/StreamAction.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.JsonElement;
44
import de.presti.ree6.sql.converter.JsonAttributeConverter;
5+
import de.presti.ree6.sql.keys.GuildAndId;
56
import jakarta.persistence.*;
67
import lombok.Getter;
78
import lombok.Setter;
@@ -13,17 +14,10 @@
1314
public class StreamAction {
1415

1516
/**
16-
* The ID of the entity.
17+
* The Key of the Entity.
1718
*/
18-
@Id
19-
@GeneratedValue(strategy = GenerationType.IDENTITY)
20-
long id;
21-
22-
/**
23-
* The ID of the Guild.
24-
*/
25-
@Column(name = "guildId")
26-
long guildId;
19+
@EmbeddedId
20+
GuildAndId guildAndId;
2721

2822
/**
2923
* The name of the action.

src/main/java/de/presti/ree6/sql/entities/Warning.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.presti.ree6.sql.entities;
22

3+
import de.presti.ree6.sql.keys.GuildUserId;
34
import jakarta.persistence.*;
45
import lombok.AllArgsConstructor;
56
import lombok.Getter;
@@ -18,21 +19,10 @@
1819
public class Warning {
1920

2021
/**
21-
* The id of the warning.
22+
* The primary key for the entity.
2223
*/
23-
@Id
24-
@GeneratedValue(strategy = GenerationType.IDENTITY)
25-
long id;
26-
27-
/**
28-
* The user id its bound to.
29-
*/
30-
long userId;
31-
32-
/**
33-
* The guild id its bound to.
34-
*/
35-
long guildId;
24+
@EmbeddedId
25+
GuildUserId guildUserId;
3626

3727
/**
3828
* The warnings that the user has.

src/main/java/de/presti/ree6/sql/entities/economy/MoneyHolder.java

+44
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,48 @@ public class MoneyHolder {
3535
*/
3636
@Column(name = "bank")
3737
private double bankAmount;
38+
39+
/**
40+
* Set the GuildID of the MoneyHolder.
41+
* @param guildId The GuildID of the MoneyHolder.
42+
*/
43+
public void setGuildId(long guildId) {
44+
if (this.guildUserId == null)
45+
this.guildUserId = new GuildUserId();
46+
47+
this.guildUserId.setGuildId(guildId);
48+
}
49+
50+
/**
51+
* Get the GuildID of the MoneyHolder.
52+
* @return The GuildID of the MoneyHolder.
53+
*/
54+
public long getGuildId() {
55+
if (this.guildUserId == null)
56+
return 0;
57+
58+
return this.guildUserId.getGuildId();
59+
}
60+
61+
/**
62+
* Set the UserID of the MoneyHolder.
63+
* @param userId The UserID of the MoneyHolder.
64+
*/
65+
public void setUserId(long userId) {
66+
if (this.guildUserId == null)
67+
this.guildUserId = new GuildUserId();
68+
69+
this.guildUserId.setUserId(userId);
70+
}
71+
72+
/**
73+
* Get the UserID of the MoneyHolder.
74+
* @return The UserID of the MoneyHolder.
75+
*/
76+
public long getUserId() {
77+
if (this.guildUserId == null)
78+
return 0;
79+
80+
return this.guildUserId.getUserId();
81+
}
3882
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.presti.ree6.sql.entities.webhook.base;
22

3-
import de.presti.ree6.sql.keys.SocialWebhookId;
3+
import de.presti.ree6.sql.keys.GuildAndId;
44
import jakarta.persistence.*;
55
import lombok.AllArgsConstructor;
66
import lombok.Getter;
@@ -21,7 +21,7 @@ public class WebhookSocial {
2121
* The ID of the Entity.
2222
*/
2323
@EmbeddedId
24-
SocialWebhookId socialWebhookId;
24+
GuildAndId guildAndId;
2525

2626
@Column(name = "channel", nullable = false)
2727
long channelId = 0;
@@ -47,7 +47,7 @@ public class WebhookSocial {
4747
* @param token The Token of the Webhook.
4848
*/
4949
public WebhookSocial(long guildId, long channelId, long webhookId, String token) {
50-
this.socialWebhookId = new SocialWebhookId(guildId);
50+
this.guildAndId = new GuildAndId(guildId);
5151
this.channelId = channelId;
5252
this.webhookId = webhookId;
5353
this.token = token;
@@ -58,6 +58,9 @@ public WebhookSocial(long guildId, long channelId, long webhookId, String token)
5858
* @param guildId The GuildID of the Webhook.
5959
*/
6060
public void setGuildId(long guildId) {
61-
this.socialWebhookId.setGuildId(guildId);
61+
if (guildAndId == null)
62+
this.guildAndId = new GuildAndId(guildId);
63+
else
64+
this.guildAndId.setGuildId(guildId);
6265
}
6366
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@Embeddable
1818
@NoArgsConstructor
1919
@AllArgsConstructor
20-
public class SocialWebhookId implements Serializable {
20+
public class GuildAndId implements Serializable {
2121

2222
/**
2323
* Unique ID of the Webhook.
@@ -33,16 +33,16 @@ public class SocialWebhookId implements Serializable {
3333
private long guildId;
3434

3535
/**
36-
* Constructor for the SocialWebhookId.
36+
* Constructor for the GuildAndId.
3737
* @param guildId The Discord Guild ID.
3838
*/
39-
public SocialWebhookId(long guildId) {
39+
public GuildAndId(long guildId) {
4040
this.guildId = guildId;
4141
}
4242

4343
@Override
4444
public boolean equals(Object obj) {
45-
if (obj instanceof SocialWebhookId settingId) {
45+
if (obj instanceof GuildAndId settingId) {
4646
return settingId.getGuildId() == guildId && settingId.getId() == id;
4747
}
4848

0 commit comments

Comments
 (0)