use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class CmdxIngestData method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
if (!super.contains(argLocation))
throw new CmdException("Required: --loc DIR");
// if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
// if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
super.processModulesAndArgs();
Location tmp = Location.create(tmpdir);
dataFileTriples = super.getValue(argTriplesOut);
if (dataFileTriples == null)
dataFileTriples = tmp.getPath("triples", "tmp");
dataFileQuads = super.getValue(argQuadsOut);
if (dataFileQuads == null)
dataFileQuads = tmp.getPath("quads", "tmp");
if (Objects.equals(dataFileTriples, dataFileQuads))
cmdError("Triples and Quads work files are the same");
if (filenames.isEmpty())
filenames = Arrays.asList("-");
// ---- Checking.
for (String filename : filenames) {
Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS);
if (lang == null)
// Does not happen due to default above.
cmdError("File suffix not recognized: " + filename);
if (!filename.equals("-") && !FileOps.exists(filename))
cmdError("File does not exist: " + filename);
}
}
use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class DatasetAssemblerTDB2 method make.
public static DatasetGraph make(Assembler a, 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 = DatabaseMgr.connectDatasetGraph(loc);
if (root.hasProperty(pUnionDefaultGraph)) {
Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode();
NodeValue nv = NodeValue.makeNode(b);
if (nv.isBoolean())
dsg.getContext().set(TDB2.symUnionDefaultGraph, nv.getBoolean());
else
Log.warn(DatasetAssemblerTDB2.class, "Failed to recognize value for union graph setting (ignored): " + b);
}
/*
<r> rdf:type tdb:DatasetTDB2;
tdb:location "dir";
//ja:context [ ja:cxtName "arq:queryTimeout"; ja:cxtValue "10000" ] ;
tdb:unionGraph true; # or "true"
*/
AssemblerUtils.mergeContext(root, dsg.getContext());
return dsg;
}
use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class TDB2GraphAssembler method createGraph.
public Graph createGraph(Assembler a, Resource root, Mode mode) {
// Make a model - the default model of the TDB dataset
// [] rdf:type tdb:GraphTDB;
// tdb:location "dir";
// Make a named model.
// [] rdf:type tdb:GraphTDB;
// tdb:location "dir";
// tdb:graphName <http://example/name>;
// Location or dataset reference.
String locationDir = getStringValue(root, pLocation);
Resource dataset = getResourceValue(root, pDataset);
if (locationDir != null && dataset != null)
throw new AssemblerException(root, "Both location and dataset given: exactly one required");
if (locationDir == null && dataset == null)
throw new AssemblerException(root, "Must give location or refer to a dataset description");
String graphName = null;
if (root.hasProperty(pGraphName1))
graphName = getAsStringValue(root, pGraphName1);
if (root.hasProperty(pGraphName2))
graphName = getAsStringValue(root, pGraphName2);
if (root.hasProperty(pIndex))
Log.warn(this, "Custom indexes not implemented yet - ignored");
DatasetGraph dsg;
if (locationDir != null) {
Location location = Location.create(locationDir);
dsg = DatabaseMgr.connectDatasetGraph(location);
} else
dsg = DatasetAssemblerTDB2.make(a, dataset);
try {
if (graphName != null)
return dsg.getGraph(NodeFactory.createURI(graphName));
else
return dsg.getDefaultGraph();
} catch (RuntimeException ex) {
ex.printStackTrace(System.err);
throw ex;
}
}
use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class TestDatabaseOps method compact_delete.
@Test
public void compact_delete() {
assumeFalse(Sys.isWindows);
DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable) dsg;
DatasetGraph dsg1 = dsgs.get();
Location loc1 = ((DatasetGraphTDB) dsg1).getLocation();
Txn.executeWrite(dsg, () -> {
dsg.add(quad2);
dsg.add(quad1);
});
DatabaseMgr.compact(dsg, true);
// https://bugs.openjdk.java.net/browse/JDK-4715154
if (!Sys.isWindows)
assertFalse(IO_DB.asFile(loc1).exists());
DatasetGraph dsg2 = dsgs.get();
Location loc2 = ((DatasetGraphTDB) dsg2).getLocation();
assertNotEquals(dsg1, dsg2);
assertNotEquals(loc1, loc2);
Txn.executeRead(dsg, () -> {
assertTrue(dsg.contains(quad2));
assertTrue(dsg.contains(quad1));
});
Txn.executeRead(dsg, () -> assertTrue(dsg.contains(quad2)));
Txn.executeRead(dsg2, () -> assertTrue(dsg2.contains(quad2)));
}
use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class TestDatabaseOps method compact_graph_2.
@Test
public void compact_graph_2() {
// graphs across compaction.
DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
Graph g = dsg.getDefaultGraph();
DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable) dsg;
DatasetGraph dsg1 = dsgs.get();
Location loc1 = ((DatasetGraphTDB) dsg1).getLocation();
Txn.executeWrite(dsg, () -> {
dsg.add(quad2);
dsg.add(quad1);
});
DatabaseMgr.compact(dsg, false);
Txn.executeRead(dsg, () -> {
assertEquals(2, g.size());
assertTrue(g.contains(triple2));
});
// Check is not attached to the old graph.
DatasetGraph dsgOld = StoreConnection.connectCreate(loc1).getDatasetGraph();
Txn.executeWrite(dsgOld, () -> dsgOld.getDefaultGraph().delete(triple2));
Txn.executeRead(dsg, () -> assertTrue(g.contains(triple2)));
Txn.executeWrite(dsg, () -> g.add(triple3));
Txn.executeRead(dsgOld, () -> assertFalse(dsgOld.getDefaultGraph().contains(triple3)));
}
Aggregations