io.sirix.axis.temporal.AllTimeAxis Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirix-core Show documentation
Show all versions of sirix-core Show documentation
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.
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.api.xml.XmlNodeReadOnlyTrx;
import io.sirix.axis.AbstractTemporalAxis;
import static java.util.Objects.requireNonNull;
/**
* Retrieve a node by node key in all revisions. In each revision a {@link XmlNodeReadOnlyTrx} is
* opened which is moved to the node with the given node key if it exists. Otherwise the iterator
* has no more elements (the {@link XmlNodeReadOnlyTrx} moved to the node by it's node key).
*
* @author Johannes Lichtenberger
*
*/
public final class AllTimeAxis
extends AbstractTemporalAxis {
/** The revision number. */
private int revision;
/** Sirix {@link ResourceSession}. */
private final ResourceSession resourceSession;
/** Node key to lookup and retrieve. */
private final long nodeKey;
/** Determines if node has been found before and now has been deleted. */
private boolean hasMoved;
/**
* Constructor.
*
* @param resourceSession the resource manager
* @param rtx the read only transactional cursor
*/
public AllTimeAxis(final ResourceSession resourceSession, final R rtx) {
this.resourceSession = requireNonNull(resourceSession);
revision = 1;
nodeKey = rtx.getNodeKey();
}
@Override
protected R computeNext() {
while (revision <= resourceSession.getMostRecentRevisionNumber()) {
final R rtx = resourceSession.beginNodeReadOnlyTrx(revision);
revision++;
if (rtx.moveTo(nodeKey)) {
hasMoved = true;
return rtx;
} else if (hasMoved) {
rtx.close();
return endOfData();
}
}
return endOfData();
}
@Override
public ResourceSession getResourceManager() {
return resourceSession;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy