use of org.sirix.exception.SirixIOException 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.sirix.exception.SirixIOException 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.sirix.exception.SirixIOException in project sirix by sirixdb.
the class AVLTreeReader method moveTo.
@Override
public Move<AVLTreeReader<K, V>> moveTo(final long nodeKey) {
assertNotClosed();
if (nodeKey == Fixed.NULL_NODE_KEY.getStandardProperty()) {
return Move.notMoved();
}
// Remember old node and fetch new one.
final Node oldNode = mCurrentNode;
Optional<? extends Node> newNode;
try {
// Immediately return node from item list if node key negative.
@SuppressWarnings("unchecked") final Optional<? extends Node> node = (Optional<? extends Node>) mPageReadTrx.getRecord(nodeKey, mPageKind, mIndex);
newNode = node;
} catch (final SirixIOException e) {
newNode = Optional.empty();
}
if (newNode.isPresent()) {
mCurrentNode = newNode.get();
return Move.moved(this);
} else {
mCurrentNode = oldNode;
return Move.notMoved();
}
}
use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method moveTo.
@Override
public Move<? extends XdmNodeReadTrx> moveTo(final long nodeKey) {
assertNotClosed();
// Remember old node and fetch new one.
final ImmutableNode oldNode = mCurrentNode;
Optional<? extends Record> newNode;
try {
// Immediately return node from item list if node key negative.
if (nodeKey < 0) {
if (mItemList.size() > 0) {
newNode = mItemList.getItem(nodeKey);
} else {
newNode = Optional.empty();
}
} else {
final Optional<? extends Record> node = mPageReadTrx.getRecord(nodeKey, PageKind.RECORDPAGE, -1);
newNode = node;
}
} catch (final SirixIOException e) {
newNode = Optional.empty();
}
if (newNode.isPresent()) {
mCurrentNode = (Node) newNode.get();
return Move.moved(this);
} else {
mCurrentNode = oldNode;
return Move.notMoved();
}
}
use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class IndexController method containsIndex.
/**
* Determines if an index of the specified type is available.
*
* @param type type of index to lookup
* @param resourceManager the {@link ResourceManager} this index controller is bound to
* @return {@code true} if an index of the specified type exists, {@code false} otherwise
* @throws SirixIOException if an I/O exception occurs while deserializing the index configuration
* for the specified {@code revision}
*/
public boolean containsIndex(final IndexType type, final ResourceManager resourceManager, final int revision) throws SirixIOException {
final Indexes indexes = new Indexes();
final java.nio.file.Path indexesFile = resourceManager.getResourceConfig().mPath.resolve(ResourceConfiguration.ResourcePaths.INDEXES.getFile() + String.valueOf(revision) + ".xml");
try {
if (Files.exists(indexesFile) && Files.size(indexesFile) > 0) {
try (final InputStream in = new FileInputStream(indexesFile.toFile())) {
indexes.init(deserialize(in).getFirstChild());
}
}
} catch (IOException | DocumentException | SirixException e) {
throw new SirixIOException("Index definitions couldn't be deserialized!", e);
}
for (final IndexDef indexDef : indexes.getIndexDefs()) {
if (indexDef.getType() == type)
return true;
}
return false;
}
Aggregations