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

io.sirix.axis.temporal.NextAxis Maven / Gradle / Ivy

Go to download

SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.

There is a newer version: 0.11.0
Show newest version
package io.sirix.axis.temporal;

import io.sirix.api.NodeCursor;
import io.sirix.api.NodeReadOnlyTrx;
import io.sirix.api.NodeTrx;
import io.sirix.api.ResourceSession;
import io.sirix.axis.AbstractTemporalAxis;

import static java.util.Objects.requireNonNull;

/**
 * Open the next revision and try to move to the node with the given node key.
 *
 * @author Johannes Lichtenberger
 *
 */
public final class NextAxis
    extends AbstractTemporalAxis {

  /** Sirix {@link ResourceSession}. */
  private final ResourceSession resourceSession;

  /** Determines if it's the first call. */
  private boolean first;

  /** The revision number. */
  private int revision;

  /** Node key to lookup and retrieve. */
  private final long nodeKey;

  /**
   * Constructor.
   *
   * @param rtx Sirix {@link NodeReadOnlyTrx}
   */
  public NextAxis(final ResourceSession resourceSession, final R rtx) {
    this.resourceSession = requireNonNull(resourceSession);
    revision = 0;
    nodeKey = rtx.getNodeKey();
    revision = rtx.getRevisionNumber() + 1;
    first = true;
  }

  @Override
  protected R computeNext() {
    if (revision <= resourceSession.getMostRecentRevisionNumber() && first) {
      first = false;

      final R rtx = resourceSession.beginNodeReadOnlyTrx(revision);
      revision++;

      if (rtx.moveTo(nodeKey)) {
        return rtx;
      } else {
        rtx.close();
        return endOfData();
      }
    } else {
      return endOfData();
    }
  }

  @Override
  public ResourceSession getResourceManager() {
    return resourceSession;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy