Search in sources :

Example 1 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId in project jena by apache.

the class TestTransBlobPersistent method transBlobFile_1.

@Test
public void transBlobFile_1() throws Exception {
    Journal journal = Journal.create(Location.create(DIR));
    BufferChannel chan = BufferChannelFile.create(DATA);
    ComponentId cid = ComponentId.allocLocal();
    TransBlob transBlob = new TransBlob(cid, chan);
    Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob);
    String str = "Hello";
    TestTransBlob.write(transactional, transBlob, str);
    chan.close();
    journal.close();
    String s = FileUtils.readWholeFileAsUTF8(DATA);
    assertEquals(str, s);
}
Also used : BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) Transactional(org.apache.jena.dboe.transaction.Transactional)

Example 2 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId in project jena by apache.

the class TestTransBlobPersistent method transBlobFile_2.

@Test
public void transBlobFile_2() throws Exception {
    Journal journal = Journal.create(Location.create(DIR));
    BufferChannel chan = BufferChannelFile.create(DATA);
    ComponentId cid = ComponentId.allocLocal();
    TransBlob transBlob = new TransBlob(cid, chan);
    Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob);
    String str = "Hello1";
    Txn.executeWrite(transactional, () -> {
        transBlob.setString("one");
    });
    Txn.executeWrite(transactional, () -> {
        transBlob.setString("two");
    });
    chan.close();
    journal.close();
    String s = FileUtils.readWholeFileAsUTF8(DATA);
    assertEquals("two", s);
}
Also used : BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) Transactional(org.apache.jena.dboe.transaction.Transactional)

Example 3 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId in project jena by apache.

the class TestRecovery method recoverBlobFile_2.

@Test
public void recoverBlobFile_2() throws Exception {
    String str1 = "Recovery One";
    String str2 = "Recovery Two";
    ComponentId cid1 = ComponentId.allocLocal();
    ComponentId cid2 = ComponentId.allocLocal();
    // Write out a journal for two components.
    {
        Journal journal = Journal.create(Location.create(dir.getRoot().getAbsolutePath()));
        journal.write(JournalEntryType.REDO, cid1, IO.stringToByteBuffer(str1));
        journal.write(JournalEntryType.REDO, cid2, IO.stringToByteBuffer(str2));
        journal.writeJournal(JournalEntry.COMMIT);
        journal.close();
    }
    Journal journal = Journal.create(Location.create(dir.getRoot().getAbsolutePath()));
    BufferChannel chan = BufferChannelFile.create(data);
    TransBlob tBlob1 = new TransBlob(cid1, chan);
    TransBlob tBlob2 = new TransBlob(cid2, chan);
    TransactionCoordinator coord = new TransactionCoordinator(journal, Arrays.asList(tBlob1, tBlob2));
    coord.start();
    ByteBuffer blob1 = tBlob1.getBlob();
    assertNotNull(blob1);
    String s1 = IO.byteBufferToString(blob1);
    assertEquals(str1, s1);
    ByteBuffer blob2 = tBlob2.getBlob();
    assertNotNull(blob2);
    String s2 = IO.byteBufferToString(blob2);
    assertEquals(str2, s2);
    assertNotEquals(str1, str2);
    coord.shutdown();
}
Also used : TransBlob(org.apache.jena.dboe.trans.data.TransBlob) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) TransactionCoordinator(org.apache.jena.dboe.transaction.txn.TransactionCoordinator) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) ByteBuffer(java.nio.ByteBuffer)

Example 4 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId in project jena by apache.

the class TestTransBinaryDataFile method before.

@Before
public void before() {
    // XXX Builder.
    journal = Journal.create(Location.mem());
    baseBinData = new BinaryDataFileMem();
    BufferChannel chan = FileFactory.createBufferChannelMem();
    ComponentId cid = ComponentId.allocLocal();
    transBinData = new TransBinaryDataFile(baseBinData, cid, chan);
    transBinData.open();
    transactional = TransactionalFactory.createTransactional(journal, transBinData);
}
Also used : ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) Before(org.junit.Before)

Example 5 with ComponentId

use of org.apache.jena.dboe.transaction.txn.ComponentId in project jena by apache.

the class ComponentIdMgr method getComponentId.

public ComponentId getComponentId(String name) {
    // log.info("Name '"+name+"'");
    if (!names.containsKey(name))
        log.error("Name '" + name + "' is not registered");
    if (allocated.containsKey(name)) {
        log.error("ComponentId for '" + name + "' has already been allocated");
        return allocated.get(name);
    }
    ComponentId cid = ComponentId.alloc(name, base, names.get(name));
    allocated.put(name, cid);
    return cid;
}
Also used : ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId)

Aggregations

ComponentId (org.apache.jena.dboe.transaction.txn.ComponentId)10 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)6 Journal (org.apache.jena.dboe.transaction.txn.journal.Journal)4 ByteBuffer (java.nio.ByteBuffer)3 TransBlob (org.apache.jena.dboe.trans.data.TransBlob)2 Transactional (org.apache.jena.dboe.transaction.Transactional)2 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)2 Before (org.junit.Before)2 Adler32 (java.util.zip.Adler32)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 TransactionException (org.apache.jena.dboe.transaction.txn.TransactionException)1