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