Search in sources :

Example 1 with UberPage

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);
    }
}
Also used : PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) SirixIOException(org.sirix.exception.SirixIOException)

Example 2 with UberPage

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);
    }
}
Also used : PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException)

Example 3 with UberPage

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();
}
Also used : PageReference(org.sirix.page.PageReference) UberPage(org.sirix.page.UberPage)

Example 4 with UberPage

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();
        }
    }
}
Also used : PageReference(org.sirix.page.PageReference) FileStorage(org.sirix.io.file.FileStorage) RAMStorage(org.sirix.io.ram.RAMStorage) UberPage(org.sirix.page.UberPage) Test(org.testng.annotations.Test)

Example 5 with UberPage

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;
}
Also used : PostCommitHook(org.sirix.api.PostCommitHook) UberPage(org.sirix.page.UberPage) PreCommitHook(org.sirix.api.PreCommitHook)

Aggregations

UberPage (org.sirix.page.UberPage)11 PageReference (org.sirix.page.PageReference)6 SirixIOException (org.sirix.exception.SirixIOException)3 IOException (java.io.IOException)2 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 DatabaseException (com.sleepycat.je.DatabaseException)1 OperationStatus (com.sleepycat.je.OperationStatus)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 PostCommitHook (org.sirix.api.PostCommitHook)1 PreCommitHook (org.sirix.api.PreCommitHook)1 ResourceManager (org.sirix.api.ResourceManager)1 Reader (org.sirix.io.Reader)1 Storage (org.sirix.io.Storage)1 Writer (org.sirix.io.Writer)1 FileStorage (org.sirix.io.file.FileStorage)1 RAMStorage (org.sirix.io.ram.RAMStorage)1 Record (org.sirix.node.interfaces.Record)1