Skip to content

Commit 516d9a5

Browse files
TheMeinerLPtheEvilReaper
authored andcommitted
Refactor models to use UUIDs for identifiers and implement custom UUID generation
1 parent 286385f commit 516d9a5

15 files changed

Lines changed: 135 additions & 92 deletions

build.gradle.kts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ plugins {
22
java
33
jacoco
44
`maven-publish`
5+
`java-library`
56
id("io.micronaut.library") version "4.5.2"
67
}
78

89
group = "net.theevilreaper.vulpes.api"
9-
version = "1.0.1"
10+
version = "1.1.0"
1011

1112
java {
1213
toolchain {
@@ -19,19 +20,12 @@ java {
1920

2021
dependencies {
2122
// Annotation Processors
22-
annotationProcessor(mn.micronaut.serde.processor)
23-
annotationProcessor(mn.micronaut.mongo.core)
2423
annotationProcessor(mn.micronaut.data.processor)
2524

26-
implementation(mn.micronaut.serde.jackson)
27-
implementation(mn.micronaut.data.spring.jpa)
25+
implementation(mn.micronaut.data.processor)
26+
implementation(mn.micronaut.data.jpa)
2827
implementation(mn.micronaut.hibernate.jpa)
29-
implementation(mn.micronaut.hibernate.validator)
30-
implementation(mn.micronaut.data.tx.hibernate)
31-
32-
// Runtime Libraries
33-
implementation(mn.jackson.core)
34-
implementation(mn.jackson.databind)
28+
api(libs.uuid.creator)
3529
}
3630

3731
tasks {

settings.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@ rootProject.name = "vulpes-model"
33
plugins {
44
id("io.micronaut.platform.catalog") version "4.5.2"
55
}
6+
7+
dependencyResolutionManagement {
8+
versionCatalogs {
9+
create("libs") {
10+
version("uuid.creator", "6.1.0")
11+
12+
library("uuid.creator", "com.github.f4b6a3", "uuid-creator").versionRef("uuid.creator")
13+
}
14+
}
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.theevilreaper.vulpes.api.generator;
2+
3+
import com.github.f4b6a3.uuid.UuidCreator;
4+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
5+
import org.hibernate.generator.BeforeExecutionGenerator;
6+
import org.hibernate.generator.EventType;
7+
8+
import java.util.EnumSet;
9+
10+
import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
11+
12+
public final class UuidV7Generator implements BeforeExecutionGenerator {
13+
14+
@Override
15+
public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType) {
16+
return UuidCreator.getTimeOrderedEpoch();
17+
}
18+
19+
@Override
20+
public EnumSet<EventType> getEventTypes() {
21+
return INSERT_ONLY;
22+
}
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.theevilreaper.vulpes.api.generator;
2+
3+
import org.hibernate.annotations.IdGeneratorType;
4+
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.Target;
7+
8+
import static java.lang.annotation.ElementType.FIELD;
9+
import static java.lang.annotation.ElementType.METHOD;
10+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
11+
12+
@IdGeneratorType(UuidV7Generator.class)
13+
@Retention(RUNTIME)
14+
@Target({METHOD,FIELD})
15+
public @interface VulpesGenerator {
16+
}

src/main/java/net/theevilreaper/vulpes/api/model/AttributeModel.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package net.theevilreaper.vulpes.api.model;
22

3-
import io.micronaut.data.annotation.MappedEntity;
4-
import io.micronaut.serde.annotation.Serdeable;
53
import jakarta.persistence.Entity;
64
import jakarta.persistence.GeneratedValue;
75
import jakarta.persistence.GenerationType;
86
import jakarta.persistence.Id;
9-
import jakarta.persistence.Index;
10-
import jakarta.persistence.Table;
7+
import net.theevilreaper.vulpes.api.generator.VulpesGenerator;
8+
9+
import javax.annotation.processing.Generated;
10+
import java.util.UUID;
1111

1212
/**
1313
* Represents an Attribute in the system. This class is used as an entity for persistence
@@ -18,15 +18,13 @@
1818
* are automatically persisted by the JPA and Micronaut Data layers.
1919
* </p>
2020
*/
21-
@Serdeable
2221
@Entity(name = "attributes")
23-
@Table(name = "vulpes_attributes", indexes = @Index(columnList = "id"))
24-
@MappedEntity
2522
public class AttributeModel implements VulpesModel {
2623

2724
@Id
28-
@GeneratedValue(strategy = GenerationType.AUTO)
29-
private String id;
25+
@GeneratedValue(strategy = GenerationType.UUID)
26+
@VulpesGenerator
27+
private UUID id;
3028
private String modelName;
3129
private String name;
3230
private double defaultValue;
@@ -51,7 +49,7 @@ public AttributeModel() {
5149
* @param defaultValue the default value of the attribute
5250
* @param maximumValue the maximum value of the attribute
5351
*/
54-
public AttributeModel(String id, String modelName, String name, double defaultValue, double maximumValue) {
52+
public AttributeModel(UUID id, String modelName, String name, double defaultValue, double maximumValue) {
5553
this.id = id;
5654
this.modelName = modelName;
5755
this.name = name;
@@ -66,7 +64,7 @@ public AttributeModel(String id, String modelName, String name, double defaultVa
6664
*
6765
* @return the unique identifier of the attribute
6866
*/
69-
public String getId() {
67+
public UUID getId() {
7068
return id;
7169
}
7270

@@ -75,7 +73,7 @@ public String getId() {
7573
*
7674
* @param id the unique identifier to set
7775
*/
78-
public void setId(String id) {
76+
public void setId(UUID id) {
7977
this.id = id;
8078
}
8179

src/main/java/net/theevilreaper/vulpes/api/model/FontModel.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package net.theevilreaper.vulpes.api.model;
22

3-
import io.micronaut.data.annotation.MappedEntity;
4-
import io.micronaut.serde.annotation.Serdeable;
53
import jakarta.persistence.ElementCollection;
64
import jakarta.persistence.Entity;
75
import jakarta.persistence.GeneratedValue;
86
import jakarta.persistence.GenerationType;
97
import jakarta.persistence.Id;
10-
import jakarta.persistence.Index;
11-
import jakarta.persistence.Table;
8+
import net.theevilreaper.vulpes.api.generator.VulpesGenerator;
129

1310
import java.util.List;
11+
import java.util.UUID;
1412

1513
/**
1614
* Represents a Font in the system. This class is used as an entity for persistence
@@ -21,15 +19,13 @@
2119
* are automatically persisted by the JPA and Micronaut Data layers.
2220
* </p>
2321
*/
24-
@Serdeable
2522
@Entity(name = "fonts")
26-
@Table(name = "vulpes_fonts", indexes = @Index(columnList = "id"))
27-
@MappedEntity
2823
public class FontModel implements VulpesModel {
2924

3025
@Id
31-
@GeneratedValue(strategy = GenerationType.AUTO)
32-
private String id;
26+
@GeneratedValue(strategy = GenerationType.UUID)
27+
@VulpesGenerator
28+
private UUID id;
3329
private String modelName;
3430
private String name;
3531
private String description;
@@ -64,7 +60,7 @@ public FontModel() {
6460
* @param chars the list of characters included in the font
6561
* @param shift the list of shift values for the font
6662
*/
67-
public FontModel(String id, String modelName, String name, String description, String type, int ascent, int height, List<String> chars, List<Double> shift) {
63+
public FontModel(UUID id, String modelName, String name, String description, String type, int ascent, int height, List<String> chars, List<Double> shift) {
6864
this.id = id;
6965
this.modelName = modelName;
7066
this.name = name;
@@ -83,7 +79,7 @@ public FontModel(String id, String modelName, String name, String description, S
8379
*
8480
* @return the unique identifier of the font
8581
*/
86-
public String getId() {
82+
public UUID getId() {
8783
return id;
8884
}
8985

@@ -92,7 +88,7 @@ public String getId() {
9288
*
9389
* @param id the unique identifier to set
9490
*/
95-
public void setId(String id) {
91+
public void setId(UUID id) {
9692
this.id = id;
9793
}
9894

src/main/java/net/theevilreaper/vulpes/api/model/ItemModel.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package net.theevilreaper.vulpes.api.model;
22

3-
import io.micronaut.serde.annotation.Serdeable;
43
import jakarta.persistence.ElementCollection;
54
import jakarta.persistence.Entity;
65
import jakarta.persistence.GeneratedValue;
76
import jakarta.persistence.GenerationType;
87
import jakarta.persistence.Id;
9-
import jakarta.persistence.Index;
10-
import jakarta.persistence.Table;
8+
import net.theevilreaper.vulpes.api.generator.VulpesGenerator;
119

1210
import java.util.List;
1311
import java.util.Map;
12+
import java.util.UUID;
1413

1514
/**
1615
* Represents an Item in the system. This class is used as an entity for persistence
@@ -21,21 +20,20 @@
2120
* persisted by the JPA and Micronaut Data layers.
2221
* </p>
2322
*/
24-
@Serdeable
2523
@Entity(name = "items")
26-
@Table(name = "vulpes_items", indexes = @Index(columnList = "id"))
2724
public class ItemModel implements VulpesModel {
2825

2926
@Id
30-
@GeneratedValue(strategy = GenerationType.AUTO)
31-
private String id;
27+
@GeneratedValue(strategy = GenerationType.UUID)
28+
@VulpesGenerator
29+
private UUID id;
3230

3331
private String modelName;
3432
private String name;
3533
private String description;
3634
private String displayName;
3735
private String material;
38-
private String group;
36+
private String groupName;
3937
private int customModelData;
4038
private int amount;
4139
@ElementCollection
@@ -64,21 +62,21 @@ public ItemModel() {
6462
* @param description a description of the item
6563
* @param displayName the display name of the item
6664
* @param material the material type associated with the item
67-
* @param group the group to which the item belongs
65+
* @param groupName the group to which the item belongs
6866
* @param customModelData the custom model data for the item
6967
* @param amount the amount of the item
7068
* @param enchantments the enchantments applied to the item
7169
* @param lore the lore associated with the item
7270
* @param flags the flags associated with the item
7371
*/
74-
public ItemModel(String id, String modelName, String name, String description, String displayName, String material, String group, int customModelData, int amount, Map<String, Short> enchantments, List<String> lore, List<String> flags) {
72+
public ItemModel(UUID id, String modelName, String name, String description, String displayName, String material, String groupName, int customModelData, int amount, Map<String, Short> enchantments, List<String> lore, List<String> flags) {
7573
this.id = id;
7674
this.modelName = modelName;
7775
this.name = name;
7876
this.description = description;
7977
this.displayName = displayName;
8078
this.material = material;
81-
this.group = group;
79+
this.groupName = groupName;
8280
this.customModelData = customModelData;
8381
this.amount = amount;
8482
this.enchantments = enchantments;
@@ -93,7 +91,7 @@ public ItemModel(String id, String modelName, String name, String description, S
9391
*
9492
* @return the unique identifier of the item
9593
*/
96-
public String getId() {
94+
public UUID getId() {
9795
return id;
9896
}
9997

@@ -102,7 +100,7 @@ public String getId() {
102100
*
103101
* @param id the unique identifier to set
104102
*/
105-
public void setId(String id) {
103+
public void setId(UUID id) {
106104
this.id = id;
107105
}
108106

@@ -201,17 +199,17 @@ public void setMaterial(String material) {
201199
*
202200
* @return the group of the item
203201
*/
204-
public String getGroup() {
205-
return group;
202+
public String getGroupName() {
203+
return groupName;
206204
}
207205

208206
/**
209207
* Sets the group to which the item belongs.
210208
*
211209
* @param group the group to set
212210
*/
213-
public void setGroup(String group) {
214-
this.group = group;
211+
public void setGroupName(String group) {
212+
this.groupName = group;
215213
}
216214

217215
/**
@@ -318,7 +316,7 @@ public String toString() {
318316
", description='" + description + '\'' +
319317
", displayName='" + displayName + '\'' +
320318
", material='" + material + '\'' +
321-
", group='" + group + '\'' +
319+
", group='" + groupName + '\'' +
322320
", customModelData=" + customModelData +
323321
", amount=" + amount +
324322
", enchantments=" + enchantments +

0 commit comments

Comments
 (0)