Search in sources :

Example 81 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class CreatePathIndex method execute.

@Override
public Sequence execute(final StaticContext sctx, final QueryContext ctx, final Sequence[] args) throws QueryException {
    if (args.length != 2 && args.length != 3) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final DBNode doc = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getWtxIndexController(rtx.getRevisionNumber() - 1);
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    final Set<Path<QNm>> paths = new HashSet<>();
    if (args.length > 2 && args[2] != null) {
        final Iter it = args[2].iterate();
        Item next = it.next();
        while (next != null) {
            paths.add(Path.parse(((Str) next).stringValue()));
            next = it.next();
        }
    }
    final IndexDef idxDef = IndexDefs.createPathIdxDef(paths, controller.getIndexes().getNrOfIndexDefsWithType(IndexType.PATH));
    try {
        controller.createIndexes(ImmutableSet.of(idxDef), (XdmNodeWriteTrx) doc.getTrx());
    } catch (final SirixIOException e) {
        throw new QueryException(new QNm("I/O exception: " + e.getMessage()), e);
    }
    return idxDef.materialize();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Path(org.brackit.xquery.util.path.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) IndexController(org.sirix.access.IndexController) SirixIOException(org.sirix.exception.SirixIOException) DBNode(org.sirix.xquery.node.DBNode) Str(org.brackit.xquery.atomic.Str) QNm(org.brackit.xquery.atomic.QNm) Item(org.brackit.xquery.xdm.Item) QueryException(org.brackit.xquery.QueryException) Iter(org.brackit.xquery.xdm.Iter) IndexDef(org.sirix.index.IndexDef) HashSet(java.util.HashSet)

Example 82 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class SelectNode method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final DBNode node = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = node.getTrx();
    final long nodeKey = FunUtil.getLong(args, 1, "nodeKey", 0, null, true);
    if (rtx.moveTo(nodeKey).hasMoved()) {
        return new DBNode(rtx, node.getCollection());
    } else {
        throw new QueryException(new QNm("Couldn't select node."));
    }
}
Also used : DBNode(org.sirix.xquery.node.DBNode) QNm(org.brackit.xquery.atomic.QNm) QueryException(org.brackit.xquery.QueryException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Example 83 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class HierarchyFileVisitor method visitFile.

/**
 * <p>
 * Inserts a {@code file-element} with a {@code name-attribute} for the file which is visited.
 * </p>
 * <p>
 * An optional visitor can be used to add further attributes or metadata. The sirix
 * {@link XdmNodeWriteTrx} is located on the new directory before and after using a pluggable
 * visitor.
 * </p>
 *
 * @throws NullPointerException if {@code pDir} or {@code pAttrs} is {@code null}
 */
@Override
public FileVisitResult visitFile(final Path pFile, final BasicFileAttributes pAttrs) throws IOException {
    checkNotNull(pFile);
    checkNotNull(pAttrs);
    try {
        if (Files.isRegularFile(pFile) | Files.isSymbolicLink(pFile)) {
            mIndex.put(pFile, org.sirix.fs.FileSystemPath.ISFILE);
            processEmptyElement(new QNm("file"));
            mWtx.insertAttribute(new QNm("name"), pFile.getFileName().toString());
            mWtx.moveToParent();
            final long nodeKey = mWtx.getNodeKey();
            processFile(mVisitor, mWtx, pFile, pAttrs);
            mWtx.moveTo(nodeKey);
        }
    } catch (SirixException e) {
        LOGWRAPPER.error(e.getMessage(), e);
    }
    return FileVisitResult.CONTINUE;
}
Also used : QNm(org.brackit.xquery.atomic.QNm) SirixException(org.sirix.exception.SirixException)

Example 84 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class HierarchyFileVisitor method postVisitDirectory.

@Override
public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
    checkNotNull(dir);
    if (exc != null) {
        LOGWRAPPER.debug(exc.getMessage(), exc);
    }
    processEndTag(new QNm(""));
    return FileVisitResult.CONTINUE;
}
Also used : QNm(org.brackit.xquery.atomic.QNm)

Example 85 with QNm

use of org.brackit.xquery.atomic.QNm in project sirix by sirixdb.

the class HierarchyFileVisitor method preVisitDirectory.

/**
 * <p>
 * Invoked for a directory before directory contents are visited.
 * </p>
 * <p>
 * Inserts a {@code dir-element} with a {@code name-attribute} for the directory to visit.
 * </p>
 * <p>
 * An optional visitor can be used to add further attributes or metadata. The sirix
 * {@link XdmNodeWriteTrx} is located on the new directory before and after using a pluggable
 * visitor.
 * </p>
 *
 * @throws NullPointerException if {@code pDir} or {@code pAttrs} is {@code null}
 */
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
    checkNotNull(dir);
    checkNotNull(attrs);
    try {
        mIndex.put(dir, org.sirix.fs.FileSystemPath.ISDIRECTORY);
        processStartTag(new QNm("dir"));
        mWtx.insertAttribute(new QNm("name"), dir.getFileName().toString());
        mWtx.moveToParent();
        final long nodeKey = mWtx.getNodeKey();
        processDirectory(mVisitor, mWtx, dir, attrs);
        mWtx.moveTo(nodeKey);
    } catch (SirixException e) {
        LOGWRAPPER.error(e.getMessage(), e);
    }
    return FileVisitResult.CONTINUE;
}
Also used : QNm(org.brackit.xquery.atomic.QNm) SirixException(org.sirix.exception.SirixException)

Aggregations

QNm (org.brackit.xquery.atomic.QNm)89 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)20 Test (org.junit.Test)18 QueryException (org.brackit.xquery.QueryException)15 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)15 DBNode (org.sirix.xquery.node.DBNode)12 QName (javax.xml.namespace.QName)11 PathSummaryReader (org.sirix.index.path.summary.PathSummaryReader)11 IndexController (org.sirix.access.IndexController)10 IndexDef (org.sirix.index.IndexDef)10 Item (org.brackit.xquery.xdm.Item)7 Axis (org.sirix.api.Axis)7 DescendantAxis (org.sirix.axis.DescendantAxis)7 SirixException (org.sirix.exception.SirixException)7 Attribute (javax.xml.stream.events.Attribute)5 Namespace (javax.xml.stream.events.Namespace)5 DocumentException (org.brackit.xquery.xdm.DocumentException)5 SirixIOException (org.sirix.exception.SirixIOException)5 Ignore (org.junit.Ignore)4 SirixUsageException (org.sirix.exception.SirixUsageException)4