All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.db.common.ScannerIterator Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.common;

import com.scalar.db.api.Result;
import com.scalar.db.api.Scanner;
import com.scalar.db.exception.storage.ExecutionException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import javax.annotation.concurrent.NotThreadSafe;

@NotThreadSafe
public class ScannerIterator implements Iterator {

  private final Scanner scanner;
  private Result next;

  public ScannerIterator(Scanner scanner) {
    this.scanner = Objects.requireNonNull(scanner);
  }

  @Override
  public boolean hasNext() {
    if (next != null) {
      return true;
    }

    try {
      return (next = scanner.one().orElse(null)) != null;
    } catch (ExecutionException e) {
      throw new RuntimeException(e.getMessage(), e);
    }
  }

  @Override
  public Result next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }

    Result ret = next;
    next = null;
    return ret;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy