Skip to content

Commit fde7979

Browse files
TheMeinerLPtheEvilReaper
authored andcommitted
Refactor models to use UUIDs for identifiers and implement custom UUID generation
1 parent c7a71f0 commit fde7979

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

settings.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ dependencyResolutionManagement {
1313
}
1414
}
1515
}
16+
17+
dependencyResolutionManagement {
18+
versionCatalogs {
19+
create("libs") {
20+
version("uuid.creator", "6.1.0")
21+
22+
library("uuid.creator", "com.github.f4b6a3", "uuid-creator").versionRef("uuid.creator")
23+
}
24+
}
25+
}
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+
}

0 commit comments

Comments
 (0)