use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class TestRemoteEndpointConnectionWithAuth method cleanupTest.
/**
* Clean up after each test by resetting the data
*/
@After
public void cleanupTest() {
DatasetGraph dsg = FusekiTestAuth.getDataset();
Txn.executeWrite(dsg, () -> dsg.clear());
}
use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class TestUtils method copyDataset.
/**
* Copies one dataset to another
*
* @param source
* Source Dataset
* @param target
* Target Dataset
* @param copyDefaultAsQuads
* Whether the default graph should be copied as quads (required
* for TDB datasets)
*
*/
public static void copyDataset(Dataset source, Dataset target, boolean copyDefaultAsQuads) {
// Copy the default graph
if (copyDefaultAsQuads) {
DatasetGraph targetDSG = target.asDatasetGraph();
source.asDatasetGraph().find(defaultGraphIRI, ANY, ANY, ANY).forEachRemaining(targetDSG::add);
} else {
target.setDefaultModel(source.getDefaultModel());
}
// Copy named graphs
source.listNames().forEachRemaining(uri -> target.addNamedModel(uri, source.getNamedModel(uri)));
}
use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class DatasetAssemblerTDB method make.
static Dataset make(Resource root) {
if (!exactlyOneProperty(root, pLocation))
throw new AssemblerException(root, "No location given");
String dir = getStringValue(root, pLocation);
Location loc = Location.create(dir);
DatasetGraph dsg = TDBFactory.createDatasetGraph(loc);
if (root.hasProperty(pUnionDefaultGraph)) {
Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode();
NodeValue nv = NodeValue.makeNode(b);
if (nv.isBoolean())
dsg.getContext().set(TDB.symUnionDefaultGraph, nv.getBoolean());
else
Log.warn(DatasetAssemblerTDB.class, "Failed to recognize value for union graph setting (ignored): " + b);
}
/*
<r> rdf:type tdb:DatasetTDB ;
tdb:location "dir" ;
//ja:context [ ja:cxtName "arq:queryTimeout" ; ja:cxtValue "10000" ] ;
tdb:unionGraph true ; # or "true"
*/
AssemblerUtils.setContext(root, dsg.getContext());
return DatasetFactory.wrap(dsg);
}
use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.
the class AbstractStoreConnections method store_6.
@Test
public void store_6() {
// Transaction - release - reattach
// This tests that the dataset is sync'ed when going into transactional mode.
StoreConnection sConn = getStoreConnection();
Location loc = sConn.getLocation();
DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE);
dsgTxn.add(q1);
assertTrue(dsgTxn.contains(q1));
dsgTxn.commit();
dsgTxn.end();
sConn.forceRecoverFromJournal();
assertTrue(sConn.getBaseDataset().contains(q1));
StoreConnection.release(loc);
sConn = StoreConnection.make(loc);
DatasetGraph dsg2 = sConn.getBaseDataset();
assertTrue(dsg2.contains(q1));
DatasetGraphTxn dsgTxn2 = sConn.begin(ReadWrite.READ);
assertTrue(dsgTxn2.contains(q1));
dsgTxn2.end();
}
use of org.apache.jena.sparql.core.DatasetGraph 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();
}
Aggregations