Search in sources :

Example 1 with Str

use of org.brackit.xquery.atomic.Str 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 Str

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

the class CASIndexListener method insert.

private void insert(final ValueNode node, final long pathNodeKey) throws SirixIOException {
    final Str strValue = new Str(node.getValue());
    boolean isOfType = false;
    try {
        AtomicUtil.toType(strValue, mType);
        isOfType = true;
    } catch (final SirixRuntimeException e) {
    }
    if (isOfType) {
        final CASValue indexValue = new CASValue(strValue, mType, pathNodeKey);
        final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(indexValue, SearchMode.EQUAL);
        if (textReferences.isPresent()) {
            setNodeReferences(node, textReferences.get(), indexValue);
        } else {
            setNodeReferences(node, new NodeReferences(), indexValue);
        }
    }
}
Also used : Str(org.brackit.xquery.atomic.Str) SirixRuntimeException(org.sirix.exception.SirixRuntimeException) CASValue(org.sirix.index.avltree.keyvalue.CASValue) NodeReferences(org.sirix.index.avltree.keyvalue.NodeReferences)

Example 3 with Str

use of org.brackit.xquery.atomic.Str 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 4 with Str

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

the class Serialize method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    final Sequence sequence = args[0];
    if (sequence == null) {
        return Int32.ZERO;
    }
    final boolean format = FunUtil.getBoolean(args, 1, "prettyPrint", false, false);
    final String file = FunUtil.getString(args, 2, "file", null, null, false);
    final PrintStream buf;
    if (file == null) {
        buf = IOUtils.createBuffer();
    } else {
        try {
            buf = new PrintStream(new FileOutputStream(new File(file)));
        } catch (final FileNotFoundException e) {
            throw new QueryException(SDBFun.ERR_FILE_NOT_FOUND, e);
        }
    }
    new StringSerializer(buf).setFormat(format).serialize(sequence);
    return new Str(buf.toString());
}
Also used : Str(org.brackit.xquery.atomic.Str) PrintStream(java.io.PrintStream) QueryException(org.brackit.xquery.QueryException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Sequence(org.brackit.xquery.xdm.Sequence) File(java.io.File) StringSerializer(org.brackit.xquery.util.serialize.StringSerializer)

Example 5 with Str

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

the class GetPath 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();
    if (rtx.getResourceManager().getResourceConfig().mPathSummary) {
        try (final PathSummaryReader pathSummaryReader = rtx.getResourceManager().openPathSummary(rtx.getRevisionNumber())) {
            pathSummaryReader.moveTo(rtx.getPathNodeKey());
            return new Str(pathSummaryReader.getPathNode().getPath(pathSummaryReader).toString());
        }
    }
    return null;
}
Also used : DBNode(org.sirix.xquery.node.DBNode) Str(org.brackit.xquery.atomic.Str) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) PathSummaryReader(org.sirix.index.path.summary.PathSummaryReader)

Aggregations

Str (org.brackit.xquery.atomic.Str)8 QueryException (org.brackit.xquery.QueryException)4 SirixIOException (org.sirix.exception.SirixIOException)4 QNm (org.brackit.xquery.atomic.QNm)3 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)3 CASValue (org.sirix.index.avltree.keyvalue.CASValue)3 DBNode (org.sirix.xquery.node.DBNode)3 HashSet (java.util.HashSet)2 Path (org.brackit.xquery.util.path.Path)2 PathException (org.brackit.xquery.util.path.PathException)2 Item (org.brackit.xquery.xdm.Item)2 Iter (org.brackit.xquery.xdm.Iter)2 IndexController (org.sirix.access.IndexController)2 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)2 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)2 IndexDef (org.sirix.index.IndexDef)2 NodeReferences (org.sirix.index.avltree.keyvalue.NodeReferences)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1