Search in sources :

Example 1 with VocabTDB2.pLocation

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;
}
Also used : JenaException(org.apache.jena.shared.JenaException) CmdException(org.apache.jena.cmd.CmdException) ModDataset(arq.cmdline.ModDataset) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) CmdException(org.apache.jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 2 with VocabTDB2.pLocation

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;
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Node(org.apache.jena.graph.Node) Location(org.apache.jena.dboe.base.file.Location) VocabTDB2.pLocation(org.apache.jena.tdb2.assembler.VocabTDB2.pLocation) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 3 with VocabTDB2.pLocation

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();
}
Also used : Graph(org.apache.jena.graph.Graph) GraphViewSwitchable(org.apache.jena.tdb2.store.GraphViewSwitchable) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Model(org.apache.jena.rdf.model.Model) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable)

Aggregations

AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)2 ModDataset (arq.cmdline.ModDataset)1 CmdException (org.apache.jena.cmd.CmdException)1 Location (org.apache.jena.dboe.base.file.Location)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 Model (org.apache.jena.rdf.model.Model)1 JenaException (org.apache.jena.shared.JenaException)1 NodeValue (org.apache.jena.sparql.expr.NodeValue)1 VocabTDB2.pLocation (org.apache.jena.tdb2.assembler.VocabTDB2.pLocation)1 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)1 GraphViewSwitchable (org.apache.jena.tdb2.store.GraphViewSwitchable)1