33import wtf .casper .storageapi .utils .StorageAPIConstants ;
44
55import java .util .Collection ;
6+ import java .util .List ;
67import java .util .concurrent .CompletableFuture ;
78
89public interface FieldStorage <K , V > {
910
1011 /**
11- * @param field the field to search for.
12- * @param value the value to search for.
12+ * @param query The query to execute
1313 * @return a future that will complete with a collection of all values that match the given field and value.
1414 */
15- default CompletableFuture <Collection <V >> get (final String field , final Object value ) {
16- return get (field , value , ConditionType .EQUALS , SortingType .NONE );
17- }
18-
19- /**
20- * @param field the field to search for.
21- * @param value the value to search for.
22- * @param conditionType the filter type to use.
23- * @param sortingType the sorting type to use.
24- * @return a future that will complete with a collection of all values that match the given field and value.
25- */
26- default CompletableFuture <Collection <V >> get (final String field , final Object value , final ConditionType conditionType , final SortingType sortingType ) {
27- return get (Condition .of (field , value , conditionType , sortingType ));
28- }
29-
30- /**
31- * @param conditions the filters to use.
32- * @return a future that will complete with a collection of all value that match the given filters.
33- */
34- default CompletableFuture <Collection <V >> get (Condition ... conditions ) {
35- return get (-1 , conditions );
36- };
37-
38- /**
39- * @param limit the limit of values to return.
40- * @param conditions the filters to use.
41- * @return a future that will complete with a collection of all value that match the given filters.
42- */
43- default CompletableFuture <Collection <V >> get (int limit , Condition ... conditions ) {
44- return get (0 , limit , conditions );
45- }
46-
47- CompletableFuture <Collection <V >> get (int skip , int limit , Condition ... conditions );
15+ CompletableFuture <Collection <V >> get (Query query );
4816
4917 /**
50- * @param key the key to search for.
51- * @return a future that will complete with the value that matches the given key.
52- * The value may be null if the key is not found.
18+ * @param query The query to remove
5319 */
54- CompletableFuture <V > get (final K key );
20+ CompletableFuture <Void > remove (final Query query );
5521
5622 /**
57- * @param field the field to search for.
58- * @param value the value to search for.
59- * @return a future that will complete with the first value that matches the given field and value.
23+ * Executes an aggregation query on the storage and returns the result as a CompletableFuture.
24+ *
25+ * @param query The query containing aggregation details, such as the fields, functions, and filters to apply.
26+ * @return A CompletableFuture that completes with the result of the aggregation query as an AggregationResult object.
6027 */
61- default CompletableFuture <V > getFirst (final String field , final Object value ) {
62- return getFirst (field , value , ConditionType .EQUALS );
63- }
64-
65- /**
66- * @param field the field to search for.
67- * @param value the value to search for.
68- * @param conditionType the filter type to use.
69- * @return a future that will complete with the first value that matches the given field and value.
70- */
71- default CompletableFuture <V > getFirst (final String field , final Object value , ConditionType conditionType ) {
72- return get (1 , Condition .of (field , value , conditionType , SortingType .NONE )).thenApply ((values ) -> {
73- if (values .isEmpty ()) {
74- return null ;
75- }
76-
77- return values .iterator ().next ();
78- });
79- };
80-
28+ CompletableFuture <List <AggregationResult >> aggregate (final Query query );
8129
8230 /**
8331 * @param value the value to save.
@@ -88,14 +36,10 @@ default CompletableFuture<V> getFirst(final String field, final Object value, Co
8836 * @param values the values to save.
8937 */
9038 default CompletableFuture <Void > saveAll (final Collection <V > values ) {
39+ // designed to be naive approach that is overridden for batched impls
9140 return CompletableFuture .runAsync (() -> values .forEach (v -> save (v ).join ()), StorageAPIConstants .DB_THREAD_POOL );
9241 }
9342
94- /**
95- * @param key the key to remove.
96- */
97- CompletableFuture <Void > remove (final V key );
98-
9943 /**
10044 * Writes the storage to disk.
10145 */
@@ -113,13 +57,6 @@ default CompletableFuture<Void> close() {
11357 return CompletableFuture .completedFuture (null );
11458 }
11559
116- /**
117- * @param field the field to search for.
118- * @param value the value to search for.
119- * @return a future that will complete with a boolean that represents whether the storage contains a value that matches the given field and value.
120- */
121- CompletableFuture <Boolean > contains (final String field , final Object value );
122-
12360 /**
12461 * @param storage the storage to migrate from. The data will be copied from the given storage to this storage.
12562 * @return a future that will complete with a boolean that represents whether the migration was successful.
@@ -141,12 +78,12 @@ default CompletableFuture<Boolean> migrate(final FieldStorage<K, V> storage) {
14178 * @param field the field to add an index for.
14279 * @return a future that will complete when the index has been added.
14380 */
144- CompletableFuture <Void > addIndex (String field );
81+ CompletableFuture <Void > index (String field );
14582
14683 /**
14784 * Removes an index from the storage.
14885 * @param field the field to remove the index for.
14986 * @return a future that will complete when the index has been removed.
15087 */
151- CompletableFuture <Void > removeIndex (String field );
88+ CompletableFuture <Void > unindex (String field );
15289}
0 commit comments