|
9 | 9 | import com.cosmian.jna.findex.ffi.FindexNativeWrapper.DeleteCallback; |
10 | 10 | import com.cosmian.jna.findex.ffi.FindexNativeWrapper.DumpTokensCallback; |
11 | 11 | import com.cosmian.jna.findex.ffi.FindexNativeWrapper.FetchCallback; |
| 12 | +import com.cosmian.jna.findex.ffi.FindexNativeWrapper.InsertCallback; |
12 | 13 | import com.cosmian.jna.findex.ffi.FindexNativeWrapper.UpsertCallback; |
13 | 14 | import com.cosmian.jna.findex.serde.Leb128Reader; |
14 | 15 | import com.cosmian.jna.findex.serde.Tuple; |
@@ -63,6 +64,17 @@ public interface EntryTableDatabase { |
63 | 64 | public Map<Uid32, EntryTableValue> upsert(Map<Uid32, EntryTableValues> uidsAndValues) |
64 | 65 | throws CloudproofException; |
65 | 66 |
|
| 67 | + /** |
| 68 | + * Insert the given lines in the Chain Table. |
| 69 | + * <p> |
| 70 | + * Implementation of this method is only required to perform additions, deletions or compact operations on the |
| 71 | + * index. |
| 72 | + * |
| 73 | + * @param uidsAndValues a {@link Map} of {@link Uid32} to {@link EntryTableValue} |
| 74 | + * @throws CloudproofException if anything goes wrong |
| 75 | + */ |
| 76 | + public void insert(Map<Uid32, EntryTableValue> uidsAndValues) throws CloudproofException; |
| 77 | + |
66 | 78 | /** |
67 | 79 | * Delete the lines with the given UIDs. |
68 | 80 | * |
@@ -156,6 +168,40 @@ public int callback(Pointer outputs, |
156 | 168 | }; |
157 | 169 | } |
158 | 170 |
|
| 171 | + /** |
| 172 | + * Return the appropriate insert callback (with input/output serialization). |
| 173 | + */ |
| 174 | + default InsertCallback insertCallback() { |
| 175 | + return new InsertCallback() { |
| 176 | + @Override |
| 177 | + public int callback(Pointer items, |
| 178 | + int itemsLength) { |
| 179 | + try { |
| 180 | + // |
| 181 | + // Read `items` until `itemsLength` |
| 182 | + // |
| 183 | + byte[] itemsBytes = new byte[itemsLength]; |
| 184 | + items.read(0, itemsBytes, 0, itemsLength); |
| 185 | + |
| 186 | + // |
| 187 | + // Deserialize the chain table items |
| 188 | + // |
| 189 | + Map<Uid32, EntryTableValue> uidsAndValues = |
| 190 | + Leb128Reader.deserializeMap(Uid32.class, EntryTableValue.class, itemsBytes); |
| 191 | + |
| 192 | + // |
| 193 | + // Insert in database |
| 194 | + // |
| 195 | + insert(uidsAndValues); |
| 196 | + |
| 197 | + return 0; |
| 198 | + } catch (CloudproofException e) { |
| 199 | + return FindexCallbackException.record(e); |
| 200 | + } |
| 201 | + } |
| 202 | + }; |
| 203 | + } |
| 204 | + |
159 | 205 | /** |
160 | 206 | * Return the appropriate upsert callback (with input/output serialization). |
161 | 207 | */ |
|
0 commit comments