1 package com.guinetik.hexafun.hexa;
2
3 import java.nio.file.DirectoryStream.Filter;
4 import java.util.List;
5
6 import com.guinetik.hexafun.fun.Result;
7
8 /**
9 * Generic repository interface for entity persistence operations.
10 * Provides CRUD (Create, Read, Update, Delete) operations with Result wrappers.
11 *
12 * @param <T> The entity type this repository manages
13 */
14 public interface HexaRepo<T> {
15 //-------------------------------------------------------------------------
16 // Create operations
17 //-------------------------------------------------------------------------
18
19 /**
20 * Saves a single entity to the repository.
21 *
22 * @param entity The entity to save
23 * @return A Result containing the saved entity with any generated values
24 */
25 Result<T> save(T entity);
26
27 /**
28 * Saves multiple entities to the repository in a batch operation.
29 *
30 * @param entities The list of entities to save
31 * @return A Result containing the list of saved entities
32 */
33 Result<List<T>> saveAll(List<T> entities);
34
35 //-------------------------------------------------------------------------
36 // Read operations
37 //-------------------------------------------------------------------------
38
39 /**
40 * Finds an entity by its unique identifier.
41 *
42 * @param id The unique identifier of the entity
43 * @return A Result containing the found entity or an error if not found
44 */
45 Result<T> findById(String id);
46
47 /**
48 * Retrieves all entities from the repository.
49 *
50 * @return A Result containing a list of all entities
51 */
52 Result<List<T>> findAll();
53
54 /**
55 * Retrieves entities that match the given filter criteria.
56 *
57 * @param filter The filter to apply
58 * @return A Result containing a list of matching entities
59 */
60 Result<List<T>> findBy(Filter<T> filter);
61
62 /**
63 * Retrieves a paginated list of entities.
64 *
65 * @param offset The number of entities to skip
66 * @param limit The maximum number of entities to return
67 * @return A Result containing a list of entities within the specified range
68 */
69 Result<List<T>> findAll(int offset, int limit);
70
71 /**
72 * Counts the total number of entities in the repository.
73 *
74 * @return A Result containing the count of entities
75 */
76 Result<Long> count();
77
78 //-------------------------------------------------------------------------
79 // Update operations
80 //-------------------------------------------------------------------------
81
82 /**
83 * Updates an existing entity identified by its ID.
84 *
85 * @param id The ID of the entity to update
86 * @param entity The updated entity data
87 * @return A Result containing the updated entity
88 */
89 Result<T> update(String id, T entity);
90
91 //-------------------------------------------------------------------------
92 // Delete operations
93 //-------------------------------------------------------------------------
94
95 /**
96 * Deletes an entity by its unique identifier.
97 *
98 * @param id The unique identifier of the entity to delete
99 * @return A Result containing a Boolean indicating success
100 */
101 Result<Boolean> deleteById(String id);
102
103 /**
104 * Deletes multiple entities by their IDs in a batch operation.
105 *
106 * @param ids The list of entity IDs to delete
107 * @return A Result indicating the operation outcome
108 */
109 Result<Void> deleteAllById(List<String> ids);
110
111 /**
112 * Removes all entities from the repository.
113 *
114 * @return A Result indicating the operation outcome
115 */
116 Result<Void> clear();
117 }