Search in sources :

Example 31 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class FileWriter method write.

/**
 * Write page contained in page reference to storage.
 *
 * @param pageReference page reference to write
 * @throws SirixIOException if errors during writing occur
 */
@Override
public FileWriter write(final PageReference pageReference) throws SirixIOException {
    // Perform byte operations.
    try {
        // Serialize page.
        final Page page = pageReference.getPage();
        assert page != null;
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        final DataOutputStream dataOutput = new DataOutputStream(mReader.mByteHandler.serialize(output));
        PagePersistenter.serializePage(dataOutput, page, mType);
        output.close();
        dataOutput.close();
        final byte[] serializedPage = output.toByteArray();
        final byte[] writtenPage = new byte[serializedPage.length + FileReader.OTHER_BEACON];
        final ByteBuffer buffer = ByteBuffer.allocate(writtenPage.length);
        buffer.putInt(serializedPage.length);
        buffer.put(serializedPage);
        buffer.position(0);
        buffer.get(writtenPage, 0, writtenPage.length);
        // Getting actual offset and appending to the end of the current
        // file.
        final long fileSize = mFile.length();
        final long offset = fileSize == 0 ? FileReader.FIRST_BEACON : fileSize;
        mFile.seek(offset);
        mFile.write(writtenPage);
        // Remember page coordinates.
        switch(mType) {
            case DATA:
                pageReference.setKey(offset);
                break;
            case TRANSACTION_INTENT_LOG:
                pageReference.setPersistentLogKey(offset);
                break;
        }
        pageReference.setLength(writtenPage.length);
        return this;
    } catch (final IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) UberPage(org.sirix.page.UberPage) Page(org.sirix.page.interfaces.Page) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SirixIOException(org.sirix.exception.SirixIOException) ByteBuffer(java.nio.ByteBuffer) SirixIOException(org.sirix.exception.SirixIOException)

Example 32 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class NameIndexBuilder method visit.

@Override
public VisitResult visit(final ImmutableElement node) {
    final QNm name = node.getName();
    final boolean included = (mIncludes.isEmpty() || mIncludes.contains(name));
    final boolean excluded = (!mExcludes.isEmpty() && mExcludes.contains(name));
    if (!included || excluded) {
        return VisitResultType.CONTINUE;
    }
    final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(name, SearchMode.EQUAL);
    try {
        if (textReferences.isPresent()) {
            setNodeReferences(node, textReferences.get(), name);
        } else {
            setNodeReferences(node, new NodeReferences(), name);
        }
    } catch (final SirixIOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return VisitResultType.CONTINUE;
}
Also used : QNm(org.brackit.xquery.atomic.QNm) NodeReferences(org.sirix.index.avltree.keyvalue.NodeReferences) SirixIOException(org.sirix.exception.SirixIOException)

Example 33 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class CreateCASIndex method execute.

@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
    if (args.length != 2 && args.length != 3) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final DBNode doc = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getWtxIndexController(rtx.getRevisionNumber() - 1);
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    Type type = null;
    if (args.length > 1 && args[1] != null) {
        final QNm name = new QNm(Namespaces.XS_NSURI, ((Str) args[1]).stringValue());
        type = sctx.getTypes().resolveAtomicType(name);
    }
    final Set<Path<QNm>> paths = new HashSet<>();
    if (args.length == 3 && args[2] != null) {
        final Iter it = args[2].iterate();
        Item next = it.next();
        while (next != null) {
            paths.add(Path.parse(((Str) next).stringValue()));
            next = it.next();
        }
    }
    final IndexDef idxDef = IndexDefs.createCASIdxDef(false, Optional.fromNullable(type), paths, controller.getIndexes().getNrOfIndexDefsWithType(IndexType.CAS));
    try {
        controller.createIndexes(ImmutableSet.of(idxDef), (XdmNodeWriteTrx) doc.getTrx());
    } catch (final SirixIOException e) {
        throw new QueryException(new QNm("I/O exception: " + e.getMessage()), e);
    }
    return idxDef.materialize();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Path(org.brackit.xquery.util.path.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) IndexController(org.sirix.access.IndexController) SirixIOException(org.sirix.exception.SirixIOException) DBNode(org.sirix.xquery.node.DBNode) Str(org.brackit.xquery.atomic.Str) QNm(org.brackit.xquery.atomic.QNm) Item(org.brackit.xquery.xdm.Item) QueryException(org.brackit.xquery.QueryException) Type(org.brackit.xquery.xdm.Type) IndexType(org.sirix.index.IndexType) Iter(org.brackit.xquery.xdm.Iter) IndexDef(org.sirix.index.IndexDef) HashSet(java.util.HashSet)

Example 34 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class CreateNameIndex method execute.

@Override
public Sequence execute(final StaticContext sctx, final QueryContext ctx, final Sequence[] args) throws QueryException {
    if (args.length != 2 && args.length != 3) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final DBNode doc = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getWtxIndexController(rtx.getRevisionNumber() - 1);
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    final Set<QNm> include = new HashSet<>();
    if (args.length > 1 && args[1] != null) {
        final Iter it = args[1].iterate();
        Item next = it.next();
        while (next != null) {
            include.add((QNm) next);
            next = it.next();
        }
    }
    final IndexDef idxDef = IndexDefs.createSelectiveNameIdxDef(include, controller.getIndexes().getNrOfIndexDefsWithType(IndexType.NAME));
    try {
        controller.createIndexes(ImmutableSet.of(idxDef), (XdmNodeWriteTrx) doc.getTrx());
    } catch (final SirixIOException e) {
        throw new QueryException(new QNm("I/O exception: " + e.getMessage()), e);
    }
    return idxDef.materialize();
}
Also used : DBNode(org.sirix.xquery.node.DBNode) XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) Item(org.brackit.xquery.xdm.Item) QueryException(org.brackit.xquery.QueryException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) IndexController(org.sirix.access.IndexController) Iter(org.brackit.xquery.xdm.Iter) IndexDef(org.sirix.index.IndexDef) SirixIOException(org.sirix.exception.SirixIOException) HashSet(java.util.HashSet)

Example 35 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class CreatePathIndex method execute.

@Override
public Sequence execute(final StaticContext sctx, final QueryContext ctx, final Sequence[] args) throws QueryException {
    if (args.length != 2 && args.length != 3) {
        throw new QueryException(new QNm("No valid arguments specified!"));
    }
    final DBNode doc = ((DBNode) args[0]);
    final XdmNodeReadTrx rtx = doc.getTrx();
    final IndexController controller = rtx.getResourceManager().getWtxIndexController(rtx.getRevisionNumber() - 1);
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    if (controller == null) {
        throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
    }
    if (!(doc.getTrx() instanceof XdmNodeWriteTrx)) {
        throw new QueryException(new QNm("Collection must be updatable!"));
    }
    final Set<Path<QNm>> paths = new HashSet<>();
    if (args.length > 2 && args[2] != null) {
        final Iter it = args[2].iterate();
        Item next = it.next();
        while (next != null) {
            paths.add(Path.parse(((Str) next).stringValue()));
            next = it.next();
        }
    }
    final IndexDef idxDef = IndexDefs.createPathIdxDef(paths, controller.getIndexes().getNrOfIndexDefsWithType(IndexType.PATH));
    try {
        controller.createIndexes(ImmutableSet.of(idxDef), (XdmNodeWriteTrx) doc.getTrx());
    } catch (final SirixIOException e) {
        throw new QueryException(new QNm("I/O exception: " + e.getMessage()), e);
    }
    return idxDef.materialize();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Path(org.brackit.xquery.util.path.Path) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) IndexController(org.sirix.access.IndexController) SirixIOException(org.sirix.exception.SirixIOException) DBNode(org.sirix.xquery.node.DBNode) Str(org.brackit.xquery.atomic.Str) QNm(org.brackit.xquery.atomic.QNm) Item(org.brackit.xquery.xdm.Item) QueryException(org.brackit.xquery.QueryException) Iter(org.brackit.xquery.xdm.Iter) IndexDef(org.sirix.index.IndexDef) HashSet(java.util.HashSet)

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