use of org.apache.jena.tdb2.assembler.VocabTDB2.pLocation in project jena by apache.
the class ModTDBDataset method createDataset.
@Override
public Dataset createDataset() {
if (inMemFile != null) {
Dataset ds = TDB2Factory.createDataset();
RDFDataMgr.read(ds, inMemFile);
return ds;
}
if (modAssembler.getAssemblerFile() != null) {
Dataset thing = null;
// (which may go wrong later if TDB2 directly is needed).
try {
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB2.tDatasetTDB);
if (thing != null) {
DatasetGraph dsg = thing.asDatasetGraph();
if (!(dsg instanceof DatasetGraphSwitchable) && !(dsg instanceof DatasetGraphTDB))
Log.warn(this, "Unexpected: Not a TDB2 dataset for type DatasetTDB2");
}
if (thing == null)
// Should use assembler inheritance but how do we assert
// the subclass relationship in a program?
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), DatasetAssemblerVocab.tDataset);
} catch (JenaException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Error creating", ex);
}
return thing;
}
if (modAssembler.getLocation() == null)
throw new CmdException("No assembler file nor location provided");
// No assembler - use location to find a database.
Dataset ds = TDB2Factory.connectDataset(modAssembler.getLocation());
return ds;
}
use of org.apache.jena.tdb2.assembler.VocabTDB2.pLocation 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.tdb2.assembler.VocabTDB2.pLocation in project jena by apache.
the class TestTDBAssembler method testGraph.
private static void testGraph(String assemblerFile, boolean named) {
Object thing = null;
try {
thing = AssemblerUtils.build(assemblerFile, VocabTDB2.tGraphTDB);
} catch (AssemblerException e) {
e.getCause().printStackTrace(System.err);
throw e;
}
assertTrue(thing instanceof Model);
Graph graph = ((Model) thing).getGraph();
assertTrue(graph instanceof GraphViewSwitchable);
DatasetGraphSwitchable dsg = ((GraphViewSwitchable) graph).getDataset();
if (dsg != null)
dsg.close();
}
Aggregations