Search in sources :

Example 6 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class DBNode method isDocumentOf.

@Override
public boolean isDocumentOf(final Node<?> other) {
    moveRtx();
    boolean retVal = false;
    if (getKind() == Kind.DOCUMENT && other instanceof DBNode) {
        final DBNode node = (DBNode) other;
        assert node.getNodeClassID() == this.getNodeClassID();
        final XdmNodeReadTrx rtx = node.getTrx();
        if (rtx.getRevisionNumber() == mRtx.getRevisionNumber() && rtx.getResourceManager().getResourceConfig().getID() == mRtx.getResourceManager().getResourceConfig().getID()) {
            retVal = true;
        }
    }
    return retVal;
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Example 7 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class DBNode method isFirstOf.

@Override
public boolean isFirstOf(TemporalNode<?> other) {
    moveRtx();
    if (other instanceof DBNode) {
        final DBNode otherNode = (DBNode) other;
        final XdmNodeReadTrx otherTrx = otherNode.getTrx();
        // Revision 0 is just the bootstrap revision and not accessed over here.
        return otherTrx.getRevisionNumber() == 1;
    }
    return false;
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Example 8 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class DBNode method replaceWith.

private DBNode replaceWith(XdmNodeWriteTrx wtx, Node<?> node) throws DocumentException {
    if (node instanceof DBNode) {
        final DBNode other = (DBNode) node;
        try {
            final XdmNodeReadTrx rtx = other.getTrx();
            rtx.moveTo(other.getNodeKey());
            wtx.replaceNode(rtx);
        } catch (final SirixException e) {
            throw new DocumentException(e.getCause());
        }
        return new DBNode(wtx, mCollection);
    } else {
        final SubtreeBuilder builder = createBuilder(wtx);
        node.parse(builder);
        try {
            return replace(builder.getStartNodeKey(), wtx);
        } catch (final SirixException e) {
            throw new DocumentException(e.getCause());
        }
    }
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException)

Example 9 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class FindCASIndex method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final DBNode doc = (DBNode) args[0];
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getRtxIndexController(rtx.getRevisionNumber());
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    final QNm name = new QNm(Namespaces.XS_NSURI, ((Str) args[1]).stringValue());
    final Type type = sctx.getTypes().resolveAtomicType(name);
    final Path<QNm> path = Path.parse(((Str) args[2]).stringValue());
    final Optional<IndexDef> indexDef = controller.getIndexes().findCASIndex(path, type);
    if (indexDef.isPresent())
        return new Int32(indexDef.get().getID());
    return new Int32(-1);
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) Type(org.brackit.xquery.xdm.Type) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Int32(org.brackit.xquery.atomic.Int32) IndexController(org.sirix.access.IndexController) IndexDef(org.sirix.index.IndexDef)

Example 10 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class FindPathIndex method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final DBNode doc = (DBNode) args[0];
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getRtxIndexController(rtx.getRevisionNumber());
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    final Path<QNm> path = Path.parse(((Str) args[1]).stringValue());
    final Optional<IndexDef> indexDef = controller.getIndexes().findPathIndex(path);
    if (indexDef.isPresent())
        return new Int32(indexDef.get().getID());
    return new Int32(-1);
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Int32(org.brackit.xquery.atomic.Int32) IndexController(org.sirix.access.IndexController) IndexDef(org.sirix.index.IndexDef)

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