use of org.sirix.page.UberPage in project sirix by sirixdb.
the class BerkeleyReader method readUberPageReference.
@Override
public PageReference readUberPageReference() throws SirixIOException {
final DatabaseEntry valueEntry = new DatabaseEntry();
final DatabaseEntry keyEntry = new DatabaseEntry();
TupleBinding.getPrimitiveBinding(Long.class).objectToEntry(-1l, keyEntry);
try {
final OperationStatus status = mDatabase.get(mTxn, keyEntry, valueEntry, LockMode.DEFAULT);
PageReference uberPageReference = new PageReference();
if (status == OperationStatus.SUCCESS) {
uberPageReference.setKey(TupleBinding.getPrimitiveBinding(Long.class).entryToObject(valueEntry));
}
final UberPage page = (UberPage) read(uberPageReference, null);
if (uberPageReference != null) {
uberPageReference.setPage(page);
}
return uberPageReference;
} catch (final DatabaseException e) {
throw new SirixIOException(e);
}
}
use of org.sirix.page.UberPage 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);
}
}
use of org.sirix.page.UberPage in project sirix by sirixdb.
the class IOTestHelper method testReadWriteFirstRef.
/**
* Test reading/writing the first reference.
*
* @param resourceConf {@link ResourceConfiguration} reference
* @throws SirixException if something went wrong
*/
public static void testReadWriteFirstRef(final ResourceConfiguration resourceConf) throws SirixException {
final Storage fac = StorageType.getStorage(resourceConf);
final PageReference pageRef1 = new PageReference();
final UberPage page1 = new UberPage();
pageRef1.setPage(page1);
// same instance check
final Writer writer = fac.createWriter();
writer.writeUberPageReference(pageRef1);
final PageReference pageRef2 = writer.readUberPageReference();
assertEquals(((UberPage) pageRef1.getPage()).getRevisionCount(), ((UberPage) pageRef2.getPage()).getRevisionCount());
writer.close();
// new instance check
final Reader reader = fac.createReader();
final PageReference pageRef3 = reader.readUberPageReference();
assertEquals(((UberPage) pageRef1.getPage()).getRevisionCount(), ((UberPage) pageRef3.getPage()).getRevisionCount());
reader.close();
fac.close();
}
use of org.sirix.page.UberPage in project sirix by sirixdb.
the class StorageTest method testFirstRef.
/**
* Test method for {@link org.ByteHandler.io.bytepipe.IByteHandler#deserialize(byte[])} and for
* {@link org.ByteHandler.io.bytepipe.IByteHandler#serialize(byte[])}.
*
* @throws SirixIOException
*/
@Test(dataProvider = "instantiateStorages")
public void testFirstRef(final Class<Storage> clazz, final Storage[] storages) throws SirixException {
for (final Storage handler : storages) {
try {
final PageReference pageRef1 = new PageReference();
final UberPage page1 = new UberPage();
pageRef1.setPage(page1);
// same instance check
final PageReference pageRef2;
try (final Writer writer = handler.createWriter()) {
pageRef2 = writer.writeUberPageReference(pageRef1).readUberPageReference();
assertEquals(new StringBuilder("Check for ").append(handler.getClass()).append(" failed.").toString(), ((UberPage) pageRef1.getPage()).getRevisionCount(), ((UberPage) pageRef2.getPage()).getRevisionCount());
}
// new instance check
try (final Reader reader = handler.createReader()) {
final PageReference pageRef3 = reader.readUberPageReference();
assertEquals(new StringBuilder("Check for ").append(handler.getClass()).append(" failed.").toString(), pageRef2.getKey(), pageRef3.getKey());
assertEquals(new StringBuilder("Check for ").append(handler.getClass()).append(" failed.").toString(), ((UberPage) pageRef2.getPage()).getRevisionCount(), ((UberPage) pageRef3.getPage()).getRevisionCount());
}
} finally {
handler.close();
}
}
}
use of org.sirix.page.UberPage in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method commit.
@Override
public XdmNodeWriteTrx commit() {
mNodeReader.assertNotClosed();
// Execute pre-commit hooks.
for (final PreCommitHook hook : mPreCommitHooks) {
hook.preCommit(this);
}
// Reset modification counter.
mModificationCount = 0L;
// Optionally lock while commiting and assigning new instances.
acquireLock();
try {
final UberPage uberPage = getPageTransaction().commit();
// Remember succesfully committed uber page in resource manager.
mNodeReader.mResourceManager.setLastCommittedUberPage(uberPage);
// Reinstantiate everything.
reInstantiate(getId(), getRevisionNumber());
} finally {
unLock();
}
// Execute post-commit hooks.
for (final PostCommitHook hook : mPostCommitHooks) {
hook.postCommit(this);
}
return this;
}
Aggregations