io.sirix.axis.temporal.FutureAxis 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 io.sirix.axis.IncludeSelf;
import static java.util.Objects.requireNonNull;
/**
* Retrieve a node by node key in all future 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 FutureAxis
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;
/**
* Constructor.
*
* @param rtx Sirix {@link XmlNodeReadOnlyTrx}
*/
public FutureAxis(final ResourceSession resourceSession, final R rtx) {
// Using telescope pattern instead of builder (only one optional parameter).
this(resourceSession, rtx, IncludeSelf.NO);
}
/**
* Constructor.
*
* @param resourceSession the resource manager
* @param rtx the transactional read only cursor
* @param includeSelf determines if current revision must be included or not
*/
public FutureAxis(final ResourceSession resourceSession, final R rtx, final IncludeSelf includeSelf) {
this.resourceSession = requireNonNull(resourceSession);
nodeKey = rtx.getNodeKey();
revision = requireNonNull(includeSelf) == IncludeSelf.YES
? rtx.getRevisionNumber()
: rtx.getRevisionNumber() + 1;
}
@Override
protected R computeNext() {
// != a little bit faster?
if (revision <= resourceSession.getMostRecentRevisionNumber()) {
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