use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class PipelineBuilder method addIntExcExpression.
/**
* Adds a intersect or a exception expression to the pipeline.
*
* @param mTransaction Transaction to operate with.
* @param mIsIntersect true, if expression is an intersection
*/
public void addIntExcExpression(final XdmNodeReadTrx mTransaction, final boolean mIsIntersect) {
assert getPipeStack().size() >= 2;
final XdmNodeReadTrx rtx = mTransaction;
final Axis mOperand2 = getPipeStack().pop().getExpr();
final Axis mOperand1 = getPipeStack().pop().getExpr();
final Axis axis = mIsIntersect ? new IntersectAxis(rtx, mOperand1, mOperand2) : new ExceptAxis(rtx, mOperand1, mOperand2);
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(axis);
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class GeneralComp method atomize.
/**
* {@inheritDoc}
*/
@Override
protected AtomicValue[] atomize(final Axis mOperand) {
final XdmNodeReadTrx rtx = getTrx();
final List<AtomicValue> op = new ArrayList<AtomicValue>();
AtomicValue atomized;
// cast to double, if compatible with XPath 1.0 and <, >, >=, <=
final boolean convert = !(!XPATH_10_COMP || getCompKind() == CompKind.EQ || getCompKind() == CompKind.EQ);
boolean first = true;
do {
if (first) {
first = false;
} else {
mOperand.next();
}
if (convert) {
// cast to double
Function.fnnumber(rtx);
}
atomized = new AtomicValue(rtx.getValue().getBytes(), rtx.getTypeKey());
op.add(atomized);
} while (mOperand.hasNext());
return op.toArray(new AtomicValue[op.size()]);
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class AbstractDiff method emitDiffs.
/**
* Emit diffs for {@code INSERTED} or {@code DELETED} nodes and traverse accordingly.
*
* @param diff kind of diff
*/
private void emitDiffs(final DiffType diff) {
final Revision revision = diff == DiffType.DELETED ? Revision.OLD : Revision.NEW;
final int depth = diff == DiffType.DELETED ? mDepth.getOldDepth() : mDepth.getNewDepth();
final XdmNodeReadTrx rtx = diff == DiffType.DELETED ? mOldRtx : mNewRtx;
do {
final DiffDepth diffDepth = new DiffDepth(mDepth.getNewDepth(), mDepth.getOldDepth());
fireDiff(diff, mNewRtx.getNodeKey(), mOldRtx.getNodeKey(), diffDepth);
emitNonStructuralDiff(mNewRtx, mOldRtx, diffDepth, diff);
} while (moveCursor(rtx, revision, Move.DOCUMENT_ORDER) && ((diff == DiffType.INSERTED && mDepth.getNewDepth() > depth) || (diff == DiffType.DELETED && mDepth.getOldDepth() > depth)));
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class DBCollection method getDocuments.
@Override
public Stream<DBNode> getDocuments(final boolean updatable) throws DocumentException {
final List<Path> resources = mDatabase.listResources();
final List<DBNode> documents = new ArrayList<>(resources.size());
for (final Path resourcePath : resources) {
try {
final String resourceName = resourcePath.getFileName().toString();
final ResourceManager resource = mDatabase.getResourceManager(ResourceManagerConfiguration.newBuilder(resourceName).build());
final XdmNodeReadTrx trx = updatable ? resource.beginNodeWriteTrx() : resource.beginNodeReadTrx();
documents.add(new DBNode(trx, this));
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
return new ArrayStream<DBNode>(documents.toArray(new DBNode[documents.size()]));
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class DBCollection method getDocumentInternal.
private DBNode getDocumentInternal(final ResourceManagerConfiguration resourceManagerConfig, final int revision, final boolean updatable) throws SirixException {
final ResourceManager resource = mDatabase.getResourceManager(resourceManagerConfig);
final int version = revision == -1 ? resource.getMostRecentRevisionNumber() : revision;
final XdmNodeReadTrx trx;
if (updatable) {
if (resource.getAvailableNodeWriteTrx() == 0) {
final Optional<XdmNodeWriteTrx> optionalWriteTrx;
optionalWriteTrx = resource.getXdmNodeWriteTrx();
if (optionalWriteTrx.isPresent()) {
trx = optionalWriteTrx.get();
} else {
trx = resource.beginNodeWriteTrx();
}
} else {
trx = resource.beginNodeWriteTrx();
}
if (version < resource.getMostRecentRevisionNumber())
((XdmNodeWriteTrx) trx).revertTo(version);
} else {
trx = resource.beginNodeReadTrx(version);
}
return new DBNode(trx, this);
}
Aggregations