use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class BerkeleyWriter method close.
@Override
public void close() throws SirixIOException {
try {
setLastNodePage(mNodepagekey);
mTxn.commit();
} catch (final DatabaseException exc) {
throw new SirixIOException(exc);
}
}
use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class BerkeleyWriter method getLastNodePage.
/**
* Getting the last nodePage from the persistent storage.
*
* @throws SirixIOException If can't get last Node page
* @return the last nodepage-key
*/
private long getLastNodePage() throws SirixIOException {
final DatabaseEntry keyEntry = new DatabaseEntry();
final DatabaseEntry valueEntry = new DatabaseEntry();
TupleBinding.getPrimitiveBinding(Long.class).objectToEntry(-2l, keyEntry);
try {
final OperationStatus status = mDatabase.get(mTxn, keyEntry, valueEntry, LockMode.DEFAULT);
return status == OperationStatus.SUCCESS ? BerkeleyStorage.DATAINFO_VAL_B.entryToObject(valueEntry) : 0L;
} catch (final DatabaseException exc) {
throw new SirixIOException(exc);
}
}
use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class BerkeleyWriter method write.
@Override
public Writer write(final PageReference pageReference) throws SirixIOException {
final Page page = pageReference.getPage();
final DatabaseEntry valueEntry = new DatabaseEntry();
final DatabaseEntry keyEntry = new DatabaseEntry();
mNodepagekey++;
mPageBinding.objectToEntry(page, valueEntry);
TupleBinding.getPrimitiveBinding(Long.class).objectToEntry(mNodepagekey, keyEntry);
final OperationStatus status = mDatabase.put(mTxn, keyEntry, valueEntry);
if (status != OperationStatus.SUCCESS) {
throw new SirixIOException(new StringBuilder("Write of ").append(pageReference.toString()).append(" failed!").toString());
}
pageReference.setKey(mNodepagekey);
return this;
}
use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class FileReader method read.
@Override
public Page read(@Nonnull final PageReference reference, @Nullable final PageReadTrx pageReadTrx) throws SirixIOException {
try {
// Read page from file.
switch(mType) {
case DATA:
mFile.seek(reference.getKey());
break;
case TRANSACTION_INTENT_LOG:
mFile.seek(reference.getPersistentLogKey());
break;
}
final int dataLength = mFile.readInt();
reference.setLength(dataLength + FileReader.OTHER_BEACON);
final byte[] page = new byte[dataLength];
mFile.read(page);
// Perform byte operations.
final DataInputStream input = new DataInputStream(mByteHandler.deserialize(new ByteArrayInputStream(page)));
// Return reader required to instantiate and deserialize page.
return PagePersistenter.deserializePage(input, pageReadTrx, mType);
} catch (final IOException e) {
throw new SirixIOException(e);
}
}
use of org.sirix.exception.SirixIOException in project sirix by sirixdb.
the class FileReader method readUberPageReference.
@Override
public PageReference readUberPageReference() throws SirixIOException {
final PageReference uberPageReference = new PageReference();
try {
// Read primary beacon.
mFile.seek(0);
uberPageReference.setKey(mFile.readLong());
final UberPage page = (UberPage) read(uberPageReference, null);
uberPageReference.setPage(page);
return uberPageReference;
} catch (final IOException e) {
throw new SirixIOException(e);
}
}
Aggregations