Search in sources :

Example 1 with StoreConnection

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);
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) Test(org.junit.Test)

Example 2 with StoreConnection

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));
            });
        }
    }
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) Test(org.junit.Test)

Example 3 with StoreConnection

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));
    });
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) Test(org.junit.Test)

Example 4 with StoreConnection

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;
}
Also used : ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 5 with StoreConnection

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);
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)7 Test (org.junit.Test)7 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)4 Location (org.apache.jena.dboe.base.file.Location)2 TDBException (org.apache.jena.tdb2.TDBException)2 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)2 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)1 TransactionalSystem (org.apache.jena.dboe.transaction.txn.TransactionalSystem)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1