Search in sources :

Example 71 with SirixException

use of org.sirix.exception.SirixException 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 72 with SirixException

use of org.sirix.exception.SirixException 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)

Example 73 with SirixException

use of org.sirix.exception.SirixException in project sirix by sirixdb.

the class DeleteFMSEVisitor method visit.

@Override
public VisitResult visit(final ImmutableElement node) {
    final Long partner = mMatching.partner(node.getNodeKey());
    if (partner == null) {
        VisitResult retVal = delete(node);
        if (node.getNodeKey() == mStartKey) {
            retVal = VisitResultType.TERMINATE;
        }
        return retVal;
    } else {
        mWtx.moveTo(node.getNodeKey());
        final long nodeKey = node.getNodeKey();
        final List<Long> keysToDelete = new ArrayList<>(mWtx.getAttributeCount() + mWtx.getNamespaceCount());
        for (int i = 0, attCount = mWtx.getAttributeCount(); i < attCount; i++) {
            mWtx.moveToAttribute(i);
            final long attNodeKey = mWtx.getNodeKey();
            if (mMatching.partner(attNodeKey) == null) {
                keysToDelete.add(attNodeKey);
            }
            mWtx.moveTo(nodeKey);
        }
        for (int i = 0, nspCount = mWtx.getNamespaceCount(); i < nspCount; i++) {
            mWtx.moveToNamespace(i);
            final long namespNodeKey = mWtx.getNodeKey();
            if (mMatching.partner(namespNodeKey) == null) {
                keysToDelete.add(namespNodeKey);
            }
            mWtx.moveTo(nodeKey);
        }
        for (final long keyToDelete : keysToDelete) {
            mWtx.moveTo(keyToDelete);
            try {
                mWtx.remove();
            } catch (final SirixException e) {
                LOGWRAPPER.error(e.getMessage(), e);
            }
        }
        mWtx.moveTo(nodeKey);
        return VisitResultType.CONTINUE;
    }
}
Also used : ArrayList(java.util.ArrayList) SirixException(org.sirix.exception.SirixException) VisitResult(org.sirix.api.visitor.VisitResult)

Example 74 with SirixException

use of org.sirix.exception.SirixException in project sirix by sirixdb.

the class ModificationVisitor method modify.

/**
 * Determines if a node must be modified. If yes, it is deleted and {@code true} is returned. If
 * it must not be deleted {@code false} is returned. The transaction is moved accordingly in case
 * of a remove-operation such that the {@link DescendantAxis} can move to the next node after a
 * delete occurred.
 *
 * @param node the node to check and possibly delete
 * @return {@code true} if node has been deleted, {@code false} otherwise
 */
private VisitResult modify(final ImmutableNode node) {
    assert node != null;
    if (mNodeIndex % MODIFY_EVERY == 0) {
        mNodeIndex = 1;
        try {
            switch(mRandom.nextInt(4)) {
                case 0:
                    final QNm insert = new QNm("testInsert");
                    final long key = mWtx.getNodeKey();
                    mWtx.insertElementAsLeftSibling(insert);
                    boolean moved = mWtx.moveTo(key).hasMoved();
                    assert moved;
                    return VisitResultType.CONTINUE;
                case 1:
                    if (mWtx.getKind() == Kind.TEXT) {
                        mWtx.setValue("testUpdate");
                    } else if (mWtx.getKind() == Kind.ELEMENT) {
                        mWtx.setName(new QNm("testUpdate"));
                    }
                    return VisitResultType.CONTINUE;
                case 2:
                    return delete();
                case 3:
                    mWtx.replaceNode("<foo/>");
                    return VisitResultType.CONTINUE;
            }
        } catch (final SirixException | IOException | XMLStreamException e) {
            LOGWRAPPER.error(e.getMessage(), e);
            return VisitResultType.TERMINATE;
        }
    } else {
        mNodeIndex++;
        return VisitResultType.CONTINUE;
    }
    return VisitResultType.CONTINUE;
}
Also used : QNm(org.brackit.xquery.atomic.QNm) XMLStreamException(javax.xml.stream.XMLStreamException) SirixException(org.sirix.exception.SirixException) IOException(java.io.IOException)

Aggregations

SirixException (org.sirix.exception.SirixException)74 DocumentException (org.brackit.xquery.xdm.DocumentException)25 IOException (java.io.IOException)18 Database (org.sirix.api.Database)17 JaxRxException (org.jaxrx.core.JaxRxException)14 NodeReadTrx (org.sirix.api.NodeReadTrx)13 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)13 SessionConfiguration (org.sirix.access.conf.SessionConfiguration)12 Session (org.sirix.api.Session)12 ResourceManager (org.sirix.api.ResourceManager)10 WebApplicationException (javax.ws.rs.WebApplicationException)8 Path (java.nio.file.Path)7 XMLStreamException (javax.xml.stream.XMLStreamException)7 QNm (org.brackit.xquery.atomic.QNm)7 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)6 OutputStream (java.io.OutputStream)5 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)5 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)5 StreamingOutput (javax.ws.rs.core.StreamingOutput)4 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)4