Skip to content

Commit f7bc192

Browse files
Merge pull request #48 from OneLiteFeatherNET/beta
feat: Improve entity queries and documentation
2 parents c3a5155 + 7b457ae commit f7bc192

File tree

12 files changed

+173
-15
lines changed

12 files changed

+173
-15
lines changed

src/main/java/net/onelitefeather/vulpes/api/generator/UuidV7Generator.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,34 @@
99

1010
import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
1111

12+
/**
13+
* The {@link UuidV7Generator} class implements a generator that creates time-ordered UUIDs (version 7) for new entities.
14+
*
15+
* @author TheMeinerLP
16+
* @version 1.0.0
17+
* @since 0.1.0
18+
*/
1219
public final class UuidV7Generator implements BeforeExecutionGenerator {
1320

21+
/**
22+
* Generates a time-ordered UUID (version 7) for the given entity.
23+
*
24+
* @param session the session in which the entity is being created
25+
* @param owner the owner of the entity
26+
* @param currentValue the current value of the UUID field (not used)
27+
* @param eventType the type of event triggering this generation (should be INSERT)
28+
* @return a new time-ordered UUID
29+
*/
1430
@Override
1531
public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType) {
1632
return UuidCreator.getTimeOrderedEpoch();
1733
}
1834

35+
/**
36+
* Returns the set of event types for which this generator is applicable.
37+
*
38+
* @return an EnumSet containing the INSERT_ONLY event type
39+
*/
1940
@Override
2041
public EnumSet<EventType> getEventTypes() {
2142
return INSERT_ONLY;

src/main/java/net/onelitefeather/vulpes/api/generator/VulpesGenerator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,22 @@
99
import static java.lang.annotation.ElementType.METHOD;
1010
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1111

12+
/**
13+
* Annotation to mark a field or method for UUIDv7-based ID generation within the Vulpes model.
14+
* <p>
15+
* This annotation is a specialization that applies {@link UuidV7Generator} as the ID generation strategy.
16+
* It can be applied to fields or methods to instruct the persistence framework to generate a UUIDv7
17+
* when persisting the entity.
18+
* </p>
19+
*
20+
* @author TheMeinerLP
21+
* @version 1.0.0
22+
* @see UuidV7Generator
23+
* @see IdGeneratorType
24+
* @since 0.1.0
25+
*/
1226
@IdGeneratorType(UuidV7Generator.class)
1327
@Retention(RUNTIME)
14-
@Target({METHOD,FIELD})
28+
@Target({METHOD, FIELD})
1529
public @interface VulpesGenerator {
1630
}

src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public FontEntity() {
5555
* @param variableName the variable name of the font
5656
* @param provider the provider of the font
5757
* @param texturePath the path to the texture of the font
58+
* @param comment a comment or description for the font
5859
* @param height the height of the font
5960
* @param ascent the ascent of the font
6061
* @param chars the list of characters included in the font

src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ public NotificationEntity() {
4444
/**
4545
* Constructs a new {@link NotificationEntity} with the specified values.
4646
*
47-
* @param id the unique identifier of the notification
48-
* @param comment a comment for the description
49-
* @param material the material type associated with the notification
50-
* @param frameType the frame type associated with the notification
51-
* @param title the title of the notification
47+
* @param id the unique identifier of the notification
48+
* @param uiName the user interface name of the notification
49+
* @param variableName the variable name of the notification
50+
* @param comment a comment for the description
51+
* @param material the material type associated with the notification
52+
* @param frameType the frame type associated with the notification
53+
* @param title the title of the notification
5254
*/
5355
public NotificationEntity(UUID id, String uiName, String variableName, String comment, String material, String frameType, String title) {
5456
this.id = id;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
package net.onelitefeather.vulpes.api.model;
22

3+
/**
4+
* Marker interface for classes that are part of the Vulpes model definition.
5+
* <p>
6+
* This interface is used to restrict certain functionality or behavior to classes
7+
* that explicitly implement it, serving as a means of semantic grouping within the model layer.
8+
* </p>
9+
*
10+
* @author theEvilReaper
11+
* @version 1.0.0
12+
* @since 0.1.0
13+
*/
314
public interface VulpesModel {
415
}

src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.onelitefeather.vulpes.api.model.sound;
22

3+
import jakarta.persistence.Column;
34
import jakarta.persistence.Entity;
45
import jakarta.persistence.GeneratedValue;
56
import jakarta.persistence.GenerationType;
@@ -33,6 +34,7 @@ public class SoundEventEntity implements VulpesModel {
3334
private String uiName;
3435
private String variableName;
3536
private String keyName;
37+
@Column(name = "replace_flag")
3638
@ColumnDefault("false")
3739
private boolean replace;
3840
@ColumnDefault("null")

src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import jakarta.persistence.GeneratedValue;
55
import jakarta.persistence.GenerationType;
66
import jakarta.persistence.Id;
7+
import jakarta.persistence.JoinColumn;
8+
import jakarta.persistence.ManyToOne;
79
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
810
import net.onelitefeather.vulpes.api.model.VulpesModel;
911
import org.hibernate.annotations.ColumnDefault;
@@ -38,9 +40,13 @@ public class SoundFileSource implements VulpesModel {
3840
private int attenuationDistance;
3941
@ColumnDefault("false")
4042
private boolean preload;
41-
@ColumnDefault("file")
43+
@ColumnDefault("'type_file'")
4244
private String type;
4345

46+
@ManyToOne
47+
@JoinColumn(name = "sound_event_id")
48+
private SoundEventEntity soundEvent;
49+
4450
/**
4551
* Default constructor for JPA and Micronaut Data.
4652
* <p>
@@ -232,6 +238,14 @@ public boolean isStreamable() {
232238
return stream;
233239
}
234240

241+
public SoundEventEntity getSoundEvent() {
242+
return soundEvent;
243+
}
244+
245+
public void setSoundEvent(SoundEventEntity soundEvent) {
246+
this.soundEvent = soundEvent;
247+
}
248+
235249
@Override
236250
public boolean equals(Object o) {
237251
if (o == null || getClass() != o.getClass()) return false;

src/main/java/net/onelitefeather/vulpes/api/repository/AttributeRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
import java.util.UUID;
88

9+
/**
10+
* The {@link AttributeRepository} interface inherits from {@link PageableRepository} and provides methods to manage {@link AttributeEntity} objects.
11+
*
12+
* @author theEvilReaper
13+
* @version 1.0.0
14+
* @since 0.1.0
15+
*/
916
@Repository
1017
public interface AttributeRepository extends PageableRepository<AttributeEntity, UUID> {
1118
}

src/main/java/net/onelitefeather/vulpes/api/repository/FontRepository.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
import io.micronaut.data.annotation.Query;
44
import io.micronaut.data.annotation.Repository;
5+
import io.micronaut.data.model.Pageable;
56
import io.micronaut.data.repository.PageableRepository;
67
import net.onelitefeather.vulpes.api.model.FontEntity;
78

89
import java.util.List;
910
import java.util.UUID;
1011

12+
/**
13+
* The {@link FontRepository} interface inherits from {@link PageableRepository} and provides methods to manage {@link FontEntity} objects.
14+
*
15+
* @author theEvilReaper
16+
* @version 1.0.0
17+
* * @since 0.1.0
18+
*/
1119
@Repository
1220
public interface FontRepository extends PageableRepository<FontEntity, UUID> {
1321

@@ -17,6 +25,17 @@ public interface FontRepository extends PageableRepository<FontEntity, UUID> {
1725
* @param id the unique identifier of the font
1826
* @return a list of characters associated with the font
1927
*/
20-
@Query("SELECT c FROM fonts f JOIN f.chars c WHERE f.id = :id")
21-
List<String> findCharsByFontId(UUID id);
28+
@Query(
29+
value = "SELECT c FROM fonts f JOIN f.chars c WHERE f.id = :id",
30+
countQuery = "SELECT COUNT(c) FROM fonts f JOIN f.chars c WHERE f.id = :id"
31+
)
32+
List<String> findCharsByFontId(UUID id, Pageable pageable);
33+
34+
/**
35+
* Retrieves all fonts along with their associated characters.
36+
*
37+
* @return a list of all FontEntity objects with their characters
38+
*/
39+
@Query("select f from fonts f JOIN FETCH f.chars")
40+
List<FontEntity> findAll();
2241
}

src/main/java/net/onelitefeather/vulpes/api/repository/ItemRepository.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
import io.micronaut.data.annotation.Query;
44
import io.micronaut.data.annotation.Repository;
5+
import io.micronaut.data.model.Pageable;
56
import io.micronaut.data.repository.PageableRepository;
67
import net.onelitefeather.vulpes.api.model.ItemEntity;
78

89
import java.util.List;
910
import java.util.Map;
1011
import java.util.UUID;
1112

13+
/**
14+
* The {@link ItemRepository} interface inherits from {@link PageableRepository} and provides methods to manage {@link ItemEntity} objects.
15+
*
16+
* @author theEvilReaper
17+
* @version 1.0.0
18+
* @since 0.1.0
19+
*/
1220
@Repository
1321
public interface ItemRepository extends PageableRepository<ItemEntity, UUID> {
1422

@@ -18,24 +26,42 @@ public interface ItemRepository extends PageableRepository<ItemEntity, UUID> {
1826
* @param id the unique identifier of the item
1927
* @return a map of enchantment names and their levels associated with the item
2028
*/
21-
@Query("SELECT e FROM items i JOIN i.enchantments e WHERE i.id = :id")
22-
Map<String, Short> findEnchantmentsById(UUID id);
29+
@Query(value = "SELECT e FROM items i JOIN i.enchantments e WHERE i.id = :id",
30+
countQuery = "SELECT count(e) FROM items i JOIN i.enchantments e WHERE i.id = :id"
31+
)
32+
Map<String, Short> findEnchantmentsById(UUID id, Pageable pageable);
2333

2434
/**
2535
* Retrieves the lore associated with an item by its ID.
2636
*
2737
* @param id the unique identifier of the item
2838
* @return a list of lore strings associated with the item
2939
*/
30-
@Query("SELECT l FROM items i JOIN i.enchantments l WHERE i.id = :id")
31-
List<String> findLoreById(UUID id);
40+
@Query(value = "SELECT l FROM items i JOIN i.lore l WHERE i.id = :id",
41+
countQuery = "SELECT count(l) FROM items i JOIN i.lore l WHERE i.id = :id"
42+
)
43+
List<String> findLoreById(UUID id, Pageable pageable);
3244

3345
/**
3446
* Retrieves the flags associated with an item by its ID.
3547
*
3648
* @param id the unique identifier of the item
3749
* @return a list of flags associated with the item
3850
*/
39-
@Query("SELECT f FROM items i JOIN i.enchantments f WHERE i.id = :id")
40-
List<String> findFlagsById(UUID id);
51+
@Query(value = "SELECT f FROM items i JOIN i.flags f WHERE i.id = :id",
52+
countQuery = "SELECT count(f) FROM items i JOIN i.flags f WHERE i.id = :id"
53+
)
54+
List<String> findFlagsById(UUID id, Pageable pageable);
55+
56+
57+
/**
58+
* Retrieves all items along with their associated enchantments, lore, and flags.
59+
*
60+
* @return a list of all ItemEntity objects with their enchantments, lore, and flags
61+
*/
62+
@Query(
63+
value = "SELECT i FROM items i LEFT JOIN FETCH i.enchantments LEFT JOIN FETCH i.lore LEFT JOIN FETCH i.flags",
64+
countQuery = "SELECT count(i) FROM items i"
65+
)
66+
List<ItemEntity> findAllWithFetches(Pageable pageable);
4167
}

0 commit comments

Comments
 (0)