Search in sources :

Example 11 with SirixIOException

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;
}
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 12 with SirixIOException

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);
        }
    }
}
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 13 with SirixIOException

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();
    }
}
Also used : Optional(java.util.Optional) Node(org.sirix.node.interfaces.Node) NullNode(org.sirix.node.NullNode) ImmutableNode(org.sirix.node.interfaces.immutable.ImmutableNode) DocumentRootNode(org.sirix.node.DocumentRootNode) StructNode(org.sirix.node.interfaces.StructNode) SirixIOException(org.sirix.exception.SirixIOException)

Example 14 with SirixIOException

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();
    }
}
Also used : ImmutableNode(org.sirix.node.interfaces.immutable.ImmutableNode) SirixIOException(org.sirix.exception.SirixIOException)

Example 15 with SirixIOException

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;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DocumentException(org.brackit.xquery.xdm.DocumentException) SirixException(org.sirix.exception.SirixException) SirixIOException(org.sirix.exception.SirixIOException) IOException(java.io.IOException) Indexes(org.sirix.index.Indexes) SirixIOException(org.sirix.exception.SirixIOException) IndexDef(org.sirix.index.IndexDef) FileInputStream(java.io.FileInputStream)

Aggregations

SirixIOException (org.sirix.exception.SirixIOException)42 IOException (java.io.IOException)14 DatabaseException (com.sleepycat.je.DatabaseException)9 DatabaseEntry (com.sleepycat.je.DatabaseEntry)7 UberPage (org.sirix.page.UberPage)6 OperationStatus (com.sleepycat.je.OperationStatus)5 Path (java.nio.file.Path)5 QNm (org.brackit.xquery.atomic.QNm)5 PageReference (org.sirix.page.PageReference)5 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)5 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Str (org.brackit.xquery.atomic.Str)4 Page (org.sirix.page.interfaces.Page)4 UncheckedIOException (java.io.UncheckedIOException)3 HashSet (java.util.HashSet)3 QueryException (org.brackit.xquery.QueryException)3 Item (org.brackit.xquery.xdm.Item)3 Iter (org.brackit.xquery.xdm.Iter)3 IndexController (org.sirix.access.IndexController)3