use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class AbstractTestStoreConnectionBasics method store_01.
@Test
public void store_01() {
StoreConnection sConn = StoreConnection.connectCreate(location);
assertNotNull(sConn);
StoreConnection.release(location);
StoreConnection sConn2 = StoreConnection.connectExisting(location);
assertNull(sConn2);
StoreConnection sConn3 = StoreConnection.connectCreate(location);
assertNotNull(sConn3);
}
use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class AbstractTestStoreConnectionBasics method store_02.
@Test
public void store_02() {
StoreConnection sConn = StoreConnection.connectCreate(location);
{
// Isolate to stop mix ups on variables.
DatasetGraphTDB dsg = sConn.getDatasetGraphTDB();
Txn.executeWrite(dsg, () -> {
dsg.add(q1);
});
Txn.executeWrite(dsg, () -> {
assertTrue(dsg.contains(q1));
});
Txn.executeRead(dsg, () -> {
assertTrue(dsg.contains(q1));
});
}
{
StoreConnection sConn2 = StoreConnection.connectCreate(location);
DatasetGraphTDB dsg2 = sConn.getDatasetGraphTDB();
Txn.executeRead(dsg2, () -> {
assertTrue(dsg2.contains(q1));
});
}
StoreConnection.release(sConn.getLocation());
sConn = null;
{
if (!location.isMem()) {
StoreConnection sConn2 = StoreConnection.connectCreate(location);
DatasetGraphTDB dsg3 = sConn2.getDatasetGraphTDB();
Txn.executeRead(dsg3, () -> {
assertTrue(dsg3.contains(q1));
});
}
}
}
use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class AbstractTestStoreConnectionBasics method store_05.
@Test
public void store_05() {
StoreConnection sConn = StoreConnection.connectCreate(location);
DatasetGraphTDB dsg = sConn.getDatasetGraphTDB();
Txn.executeWrite(dsg, () -> {
dsg.add(q3);
});
Txn.executeWrite(dsg, () -> {
assertTrue(dsg.contains(q3));
});
}
use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class StoreConnection method make.
/**
* Return a {@code StoreConnection} for a particular location,
* creating it if it does not exist in storage.
*/
private static synchronized StoreConnection make(Location location, StoreParams params) {
StoreConnection sConn = cache.get(location);
if (sConn == null) {
ProcessFileLock lock = null;
// This is a tdb.lock file in the storage database, not the switchable.
if (SystemTDB.DiskLocationMultiJvmUsagePrevention && !location.isMem()) {
lock = lockForLocation(location);
// Take the lock. This is atomic and non-reentrant.
lock.lockEx();
}
// Recovery happens when TransactionCoordinator.start is called
// during the building of the DatasetGraphTDB
DatasetGraphTDB dsg = TDB2StorageBuilder.build(location, params);
sConn = new StoreConnection(dsg, lock);
if (!location.isMemUnique())
cache.put(location, sConn);
}
return sConn;
}
use of org.apache.jena.tdb2.sys.StoreConnection in project jena by apache.
the class DatabaseConnection method build.
private static DatabaseConnection build(Location location, StoreParams params) {
if (location.isMemUnique()) {
throw new TDBException("Can't buildForCache a memory-unique location");
}
ProcessFileLock lock = null;
if (SystemTDB.DiskLocationMultiJvmUsagePrevention && !location.isMem()) {
// Take the lock for the swithable.
// StoreConnection will take a lock for the storage.
lock = lockForLocation(location);
// Take the lock. This is atomic and non-reentrant.
lock.lockEx();
}
// c.f. StoreConnection.make
DatasetGraph dsg = DatabaseOps.create(location, params);
return new DatabaseConnection(dsg, location, lock);
}
Aggregations