use of org.sirix.page.PageReference 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.PageReference 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.PageReference 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.PageReference 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.PageReference in project sirix by sirixdb.
the class PageReadTrxImpl method getPageReferenceForPage.
/**
* Find reference pointing to leaf page of an indirect tree.
*
* @param startReference start reference pointing to the indirect tree
* @param recordPageKey key to look up in the indirect tree
* @return reference denoted by key pointing to the leaf page
*
* @throws SirixIOException if an I/O error occurs
*/
@Nullable
@Override
public final PageReference getPageReferenceForPage(final PageReference startReference, @Nonnegative final long recordPageKey, final int index, final PageKind pageKind) throws SirixIOException {
assertNotClosed();
// Initial state pointing to the indirect page of level 0.
PageReference reference = checkNotNull(startReference);
checkArgument(recordPageKey >= 0, "key must be >= 0!");
checkNotNull(pageKind);
int offset = 0;
long levelKey = recordPageKey;
final int[] inpLevelPageCountExp = mUberPage.getPageCountExp(pageKind);
// Iterate through all levels.
for (int level = 0, height = inpLevelPageCountExp.length; level < height; level++) {
final Page derefPage = dereferenceIndirectPageReference(reference);
if (derefPage == null) {
reference = null;
break;
} else {
offset = (int) (levelKey >> inpLevelPageCountExp[level]);
levelKey -= offset << inpLevelPageCountExp[level];
try {
// assert offset >= 0 && offset < mUberPage.getPageReferenceCount(pageKind);
reference = derefPage.getReference(offset);
} catch (final IndexOutOfBoundsException e) {
throw new SirixIOException("Node key isn't supported, it's too big!");
}
}
}
// Return reference to leaf of indirect tree.
return reference;
}
Aggregations