use of org.apache.jena.tdb.base.file.Location in project jena by apache.
the class AbstractStoreConnections method store_7.
@Test
public void store_7() {
// No transaction, plain update, then transaction.
// This tests that the dataset is sync'ed when going into transactional mode.
boolean nonTxnData = true;
StoreConnection sConn = getStoreConnection();
Location loc = sConn.getLocation();
DatasetGraph dsg = sConn.getBaseDataset();
if (nonTxnData) {
dsg.add(q);
TDB.sync(dsg);
assertTrue(dsg.contains(q));
}
DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE);
if (nonTxnData)
assertTrue(dsgTxn.contains(q));
dsgTxn.add(q1);
assertTrue(dsgTxn.contains(q1));
if (nonTxnData)
assertTrue(dsgTxn.contains(q));
dsgTxn.commit();
dsgTxn.end();
// Should have flushed to disk.
if (nonTxnData) {
sConn.forceRecoverFromJournal();
assertTrue(dsg.contains(q));
}
assertTrue(dsg.contains(q1));
// release via the transactional machinery
StoreConnection.release(loc);
sConn = null;
StoreConnection sConn2 = StoreConnection.make(loc);
DatasetGraph dsg2 = sConn2.getBaseDataset();
if (nonTxnData)
assertTrue(dsg2.contains(q));
assertTrue(dsg2.contains(q1));
DatasetGraphTxn dsgTxn2 = sConn2.begin(ReadWrite.READ);
if (nonTxnData)
assertTrue(dsgTxn2.contains(q));
assertTrue(dsgTxn2.contains(q1));
dsgTxn2.end();
// Check API methods work.
Dataset ds = TDBFactory.createDataset(loc);
ds.begin(ReadWrite.READ);
Model m = (q.isDefaultGraph() ? ds.getDefaultModel() : ds.getNamedModel("g"));
assertEquals(nonTxnData ? 2 : 1, m.size());
ds.end();
}
use of org.apache.jena.tdb.base.file.Location in project jena by apache.
the class AbstractStoreConnections method store_5.
@Test
public void store_5() {
// No transaction. Make sure StoreConnection.release cleans up OK.
StoreConnection sConn = getStoreConnection();
Location loc = sConn.getLocation();
DatasetGraph dsg = sConn.getBaseDataset();
dsg.add(q);
assertTrue(dsg.contains(q));
StoreConnection.release(loc);
sConn = StoreConnection.make(loc);
dsg = sConn.getBaseDataset();
assertTrue(dsg.contains(q));
}
use of org.apache.jena.tdb.base.file.Location in project jena by apache.
the class TestLocationLockStoreConnection method location_lock_store_connection_01.
@Test
public void location_lock_store_connection_01() {
Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
LocationLock lock = dir.getLock();
Assert.assertTrue(lock.canLock());
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Creating a StoreConnection on the location will obtain the lock
StoreConnection.make(dir);
Assert.assertTrue(lock.isLocked());
Assert.assertTrue(lock.isOwned());
Assert.assertTrue(lock.canObtain());
// Releasing the connection releases the lock
StoreConnection.release(dir);
Assert.assertFalse(lock.isLocked());
Assert.assertFalse(lock.isOwned());
Assert.assertTrue(lock.canObtain());
}
use of org.apache.jena.tdb.base.file.Location in project jena by apache.
the class StoreConnection method reset.
/** Stop managing all locations. Use with great care. */
public static synchronized void reset() {
// Copy to avoid potential CME.
Set<Location> x = new HashSet<>(cache.keySet());
for (Location loc : x) expel(loc, true);
cache.clear();
}
use of org.apache.jena.tdb.base.file.Location in project jena by apache.
the class dumpbpt method exec.
@Override
protected void exec() {
List<String> tripleIndexes = Arrays.asList(Names.tripleIndexes);
List<String> quadIndexes = Arrays.asList(Names.quadIndexes);
Location loc = modLocation.getLocation();
// The name is the order.
for (String indexName : super.getPositional()) {
String primary;
if (indexName.length() == 3) {
primary = Names.primaryIndexTriples;
} else if (indexName.length() == 4) {
primary = Names.primaryIndexQuads;
} else {
cmdError("Wrong length: " + indexName);
primary = null;
}
int keySubLen = SystemTDB.SizeOfNodeId;
int keyUnitLen = indexName.length();
int keyLength = keySubLen * keyUnitLen;
int valueLength = 0;
RecordFactory rf = new RecordFactory(keyLength, valueLength);
RangeIndex rIndex = IndexFactory.buildRangeIndex(loc, indexName, rf);
BPlusTree bpt = (BPlusTree) rIndex;
if (false) {
System.out.println("---- Index structure");
bpt.dump();
}
if (true) {
System.out.println("---- Index contents");
Iterator<Record> iter = bpt.iterator();
if (!iter.hasNext())
System.out.println("<<Empty>>");
for (; iter.hasNext(); ) {
Record r = iter.next();
printRecord("", System.out, r, keyUnitLen);
}
}
// Check.
Iterator<Record> iterCheck = bpt.iterator();
Record r1 = null;
int i = 0;
for (; iterCheck.hasNext(); ) {
Record r2 = iterCheck.next();
i++;
if (r1 != null) {
if (!Record.keyLT(r1, r2)) {
System.err.println("key error@ " + i);
printRecord(" ", System.err, r1, keyUnitLen);
printRecord(" ", System.err, r2, keyUnitLen);
}
}
r1 = r2;
}
if (false) {
// Dump in tuple order.
TupleIndex tupleIndex = new TupleIndexRecord(primary.length(), new ColumnMap(primary, indexName), indexName, rIndex.getRecordFactory(), rIndex);
if (true) {
System.out.println("---- Tuple contents");
Iterator<Tuple<NodeId>> iter2 = tupleIndex.all();
if (!iter2.hasNext())
System.out.println("<<Empty>>");
for (; iter2.hasNext(); ) {
Tuple<NodeId> row = iter2.next();
System.out.println(row);
}
}
}
}
}
Aggregations