Search in sources :

Example 1 with PathException

use of org.brackit.xquery.util.path.PathException in project sirix by sirixdb.

the class CASIndexBuilder method process.

private VisitResult process(final ImmutableNode node) {
    try {
        if (node.getKind() == Kind.TEXT) {
            mRtx.moveTo(node.getParentKey());
        }
        final long PCR = mRtx.isDocumentRoot() ? 0 : mRtx.getNameNode().getPathNodeKey();
        if (mPaths.isEmpty() || mPathSummaryReader.getPCRsForPaths(mPaths).contains(PCR)) {
            final Str strValue = new Str(((ImmutableValueNode) node).getValue());
            boolean isOfType = false;
            try {
                if (mType != Type.STR)
                    AtomicUtil.toType(strValue, mType);
                isOfType = true;
            } catch (final SirixRuntimeException e) {
            }
            if (isOfType) {
                final CASValue value = new CASValue(strValue, mType, PCR);
                final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(value, SearchMode.EQUAL);
                if (textReferences.isPresent()) {
                    setNodeReferences(node, textReferences.get(), value);
                } else {
                    setNodeReferences(node, new NodeReferences(), value);
                }
            }
        }
        mRtx.moveTo(node.getNodeKey());
    } catch (final PathException | SirixIOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return VisitResultType.CONTINUE;
}
Also used : Str(org.brackit.xquery.atomic.Str) SirixRuntimeException(org.sirix.exception.SirixRuntimeException) PathException(org.brackit.xquery.util.path.PathException) CASValue(org.sirix.index.avltree.keyvalue.CASValue) NodeReferences(org.sirix.index.avltree.keyvalue.NodeReferences) SirixIOException(org.sirix.exception.SirixIOException)

Example 2 with PathException

use of org.brackit.xquery.util.path.PathException in project sirix by sirixdb.

the class CASIndexListener method listen.

@Override
public void listen(final ChangeType type, final ImmutableNode node, final long pathNodeKey) throws SirixIOException {
    if (node instanceof ValueNode) {
        final ValueNode valueNode = ((ValueNode) node);
        mPathSummaryReader.moveTo(pathNodeKey);
        try {
            switch(type) {
                case INSERT:
                    if (mPathSummaryReader.getPCRsForPaths(mPaths).contains(pathNodeKey)) {
                        insert(valueNode, pathNodeKey);
                    }
                    break;
                case DELETE:
                    if (mPathSummaryReader.getPCRsForPaths(mPaths).contains(pathNodeKey)) {
                        mAVLTreeWriter.remove(new CASValue(new Str(valueNode.getValue()), mType, pathNodeKey), node.getNodeKey());
                    }
                    break;
                default:
            }
        } catch (final PathException e) {
            throw new SirixIOException(e);
        }
    }
}
Also used : Str(org.brackit.xquery.atomic.Str) PathException(org.brackit.xquery.util.path.PathException) CASValue(org.sirix.index.avltree.keyvalue.CASValue) ValueNode(org.sirix.node.interfaces.ValueNode) SirixIOException(org.sirix.exception.SirixIOException)

Example 3 with PathException

use of org.brackit.xquery.util.path.PathException in project sirix by sirixdb.

the class PCRCollectorImpl method getPCRsForPaths.

@Override
public PCRValue getPCRsForPaths(Set<Path<QNm>> paths) {
    try (final PathSummaryReader reader = mRtx instanceof XdmNodeWriteTrx ? ((XdmNodeWriteTrx) mRtx).getPathSummary() : mRtx.getResourceManager().openPathSummary(mRtx.getRevisionNumber())) {
        final long maxPCR = reader.getMaxNodeKey();
        final Set<Long> pathClassRecords = reader.getPCRsForPaths(paths);
        return PCRValue.getInstance(maxPCR, pathClassRecords);
    } catch (final PathException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return PCRValue.getEmptyInstance();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) PathException(org.brackit.xquery.util.path.PathException) PathSummaryReader(org.sirix.index.path.summary.PathSummaryReader)

Aggregations

PathException (org.brackit.xquery.util.path.PathException)3 Str (org.brackit.xquery.atomic.Str)2 SirixIOException (org.sirix.exception.SirixIOException)2 CASValue (org.sirix.index.avltree.keyvalue.CASValue)2 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)1 NodeReferences (org.sirix.index.avltree.keyvalue.NodeReferences)1 PathSummaryReader (org.sirix.index.path.summary.PathSummaryReader)1 ValueNode (org.sirix.node.interfaces.ValueNode)1