Trying to implement cursor with FDB

Hi everyone, I am trying to learn FDB currently for use for a school project, and am running into issues that I’m having trouble solving through the documentation. Basically, the project consists of using a cursor to go through a database, and then being able to update/delete records that the cursor is currently pointing at.

I’m trying to create the cursor now, and having some trouble. For example, I’m trying to code the following function:

   * Seek the cursor to the first qualified record.
   * Once the cursor is initialized by getFirst, it can ONLY iterate records using getNext.
   * @param cursor the target cursor
   * @return the first qualified record
  Record getFirst(Cursor cursor);

I have instantiated a cursor that could contain the table name, attribute name, attribute value, a comparison operator, and the mode of the cursor (read vs. read/write).

The idea that I have to implement this method is to use the following function to get the key-value pair, and then go from there:

 public static List<FDBKVPair> getAllKeyValuePairsOfSubdirectory(Database db, Transaction tx, List<String> path) {
    List<FDBKVPair> res = new ArrayList<>();
    if (!doesSubdirectoryExists(tx, path)) {
      return res;

    DirectorySubspace dir = FDBHelper.createOrOpenSubspace(tx, path);
    Range range = dir.range();

    List<KeyValue> kvs = tx.getRange(range).asList().join();
    for (KeyValue kv : kvs) {
      Tuple key = dir.unpack(kv.getKey());
      Tuple value = Tuple.fromBytes(kv.getValue());
      res.add(new FDBKVPair(path, key, value));

    return res;

From there, my plan is to use the AsyncInterable interface interator() method to get an iterator, and then use next() and hasNext() to get the actual record to return in the original function.

I’m really struggling with taking this idea, and implementing it in code, and any help would be greatly appreciated. Once I’m done developing the cursor to go forwards, I’ll also have to add the ability for it to go backwards through the database.

Thanks so much,