Search in sources :

Example 1 with XdmNodeReadTrx

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);
}
Also used : ExceptAxis(org.sirix.service.xml.xpath.expr.ExceptAxis) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) IntersectAxis(org.sirix.service.xml.xpath.expr.IntersectAxis) ModOpAxis(org.sirix.service.xml.xpath.operators.ModOpAxis) RangeAxis(org.sirix.service.xml.xpath.expr.RangeAxis) AddOpAxis(org.sirix.service.xml.xpath.operators.AddOpAxis) ExceptAxis(org.sirix.service.xml.xpath.expr.ExceptAxis) Axis(org.sirix.api.Axis) MulOpAxis(org.sirix.service.xml.xpath.operators.MulOpAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis) IfAxis(org.sirix.service.xml.xpath.expr.IfAxis) IntersectAxis(org.sirix.service.xml.xpath.expr.IntersectAxis) IDivOpAxis(org.sirix.service.xml.xpath.operators.IDivOpAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) PredicateFilterAxis(org.sirix.axis.filter.PredicateFilterAxis) VariableAxis(org.sirix.service.xml.xpath.expr.VariableAxis) ForAxis(org.sirix.axis.ForAxis) SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) SubOpAxis(org.sirix.service.xml.xpath.operators.SubOpAxis) DivOpAxis(org.sirix.service.xml.xpath.operators.DivOpAxis)

Example 2 with XdmNodeReadTrx

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()]);
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) ArrayList(java.util.ArrayList) AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 3 with XdmNodeReadTrx

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)));
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Example 4 with XdmNodeReadTrx

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()]));
}
Also used : Path(java.nio.file.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) ArrayStream(org.brackit.xquery.node.stream.ArrayStream) DocumentException(org.brackit.xquery.xdm.DocumentException) ArrayList(java.util.ArrayList) SirixException(org.sirix.exception.SirixException) ResourceManager(org.sirix.api.ResourceManager)

Example 5 with XdmNodeReadTrx

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);
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) ResourceManager(org.sirix.api.ResourceManager)

Aggregations

XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)150 Test (org.junit.Test)93 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)48 QNm (org.brackit.xquery.atomic.QNm)20 DescendantAxis (org.sirix.axis.DescendantAxis)17 Iterator (java.util.Iterator)16 ResourceManager (org.sirix.api.ResourceManager)14 Axis (org.sirix.api.Axis)13 DBNode (org.sirix.xquery.node.DBNode)12 QueryException (org.brackit.xquery.QueryException)11 FilterAxis (org.sirix.axis.filter.FilterAxis)11 IndexController (org.sirix.access.IndexController)10 IndexDef (org.sirix.index.IndexDef)10 Item (org.brackit.xquery.xdm.Item)7 Database (org.sirix.api.Database)7 SirixException (org.sirix.exception.SirixException)6 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 SirixDeweyID (org.sirix.node.SirixDeweyID)5 Path (java.nio.file.Path)4 AbsAxisTest (org.sirix.axis.AbsAxisTest)4