Search in sources :

Example 26 with SirixIOException

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

the class PathSummaryReader method moveTo.

@Override
public Move<? extends PathSummaryReader> moveTo(final long nodeKey) {
    assertNotClosed();
    // Remember old node and fetch new one.
    final StructNode oldNode = mCurrentNode;
    Optional<? extends StructNode> newNode;
    try {
        // Immediately return node from item list if node key negative.
        @SuppressWarnings("unchecked") final Optional<? extends StructNode> node = (Optional<? extends StructNode>) mPageReadTrx.getRecord(nodeKey, PageKind.PATHSUMMARYPAGE, 0);
        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) SirixIOException(org.sirix.exception.SirixIOException) StructNode(org.sirix.node.interfaces.StructNode)

Example 27 with SirixIOException

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

the class BerkeleyStorage method close.

@Override
public void close() throws SirixIOException {
    try {
        mDatabase.close();
        mEnv.close();
    } catch (final DatabaseException exc) {
        throw new SirixIOException(exc);
    }
}
Also used : DatabaseException(com.sleepycat.je.DatabaseException) SirixIOException(org.sirix.exception.SirixIOException)

Example 28 with SirixIOException

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

the class BerkeleyStorage method exists.

@Override
public boolean exists() throws SirixIOException {
    final DatabaseEntry valueEntry = new DatabaseEntry();
    final DatabaseEntry keyEntry = new DatabaseEntry();
    boolean returnVal = false;
    try {
        final Reader reader = new BerkeleyReader(mEnv, mDatabase, mByteHandler);
        TupleBinding.getPrimitiveBinding(Long.class).objectToEntry(-1l, keyEntry);
        final OperationStatus status = mDatabase.get(null, keyEntry, valueEntry, LockMode.DEFAULT);
        if (status == OperationStatus.SUCCESS) {
            returnVal = true;
        }
        reader.close();
    } catch (final DatabaseException exc) {
        throw new SirixIOException(exc);
    }
    return returnVal;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) Reader(org.sirix.io.Reader) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) SirixIOException(org.sirix.exception.SirixIOException)

Example 29 with SirixIOException

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

the class BerkeleyStorageFactory method createStorage.

/**
 * Create a new storage.
 *
 * @param resourceConfig the resource configuration
 * @return the berkeley DB storage
 * @throws NullPointerException if {@link ResourceConfiguration} is {@code null}
 * @throws SirixIOException if the storage couldn't be created because of an I/O exception
 */
public BerkeleyStorage createStorage(final ResourceConfiguration resourceConfig) {
    try {
        final Path repoFile = resourceConfig.mPath.resolve(ResourceConfiguration.ResourcePaths.DATA.getFile());
        if (!Files.exists(repoFile)) {
            Files.createDirectories(repoFile);
        }
        final ByteHandlePipeline byteHandler = checkNotNull(resourceConfig.mByteHandler);
        final DatabaseConfig conf = generateDBConf();
        final EnvironmentConfig config = generateEnvConf();
        final List<Path> path;
        try (final Stream<Path> stream = Files.list(repoFile)) {
            path = stream.collect(toList());
        }
        if (path.isEmpty() || (path.size() == 1 && "sirix.data".equals(path.get(0).getFileName().toString()))) {
            conf.setAllowCreate(true);
            config.setAllowCreate(true);
        }
        final Environment env = new Environment(repoFile.toFile(), config);
        final Database database = env.openDatabase(null, NAME, conf);
        return new BerkeleyStorage(env, database, byteHandler);
    } catch (final DatabaseException | IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : Path(java.nio.file.Path) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) ByteHandlePipeline(org.sirix.io.bytepipe.ByteHandlePipeline) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 30 with SirixIOException

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

the class FileWriter method writeUberPageReference.

@Override
public Writer writeUberPageReference(final PageReference pageReference) throws SirixIOException {
    try {
        write(pageReference);
        mFile.seek(0);
        mFile.writeLong(pageReference.getKey());
        return this;
    } catch (final IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException)

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