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;
}
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);
}
}
}
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);
}
}
}
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());
}
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;
}
Aggregations