Search in sources :

Example 1 with TDB2

use of org.apache.jena.tdb2.TDB2 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 TDB2

use of org.apache.jena.tdb2.TDB2 in project jena by apache.

the class StageGeneratorDirectTDB method execute.

@Override
public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt) {
    // --- In case this isn't for TDB2
    Graph g = execCxt.getActiveGraph();
    if (g instanceof GraphViewSwitchable) {
        GraphViewSwitchable gvs = (GraphViewSwitchable) g;
        g = gvs.getBaseGraph();
    }
    if (!(g instanceof GraphTDB))
        // Not us - bounce up the StageGenerator chain
        return above.execute(pattern, input, execCxt);
    GraphTDB graph = (GraphTDB) g;
    Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
    return PatternMatchTDB2.execute(graph, pattern, input, filter, execCxt);
}
Also used : Graph(org.apache.jena.graph.Graph) GraphViewSwitchable(org.apache.jena.tdb2.store.GraphViewSwitchable) GraphTDB(org.apache.jena.tdb2.store.GraphTDB) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 3 with TDB2

use of org.apache.jena.tdb2.TDB2 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 4 with TDB2

use of org.apache.jena.tdb2.TDB2 in project jena by apache.

the class SystemTDB method intValue.

private static int intValue(String name, int defaultValue) {
    if (name == null)
        return defaultValue;
    if (name.length() == 0)
        throw new TDBException("Empty string for value name");
    if (properties == null)
        return defaultValue;
    String x = properties.getProperty(name);
    if (x == null)
        return defaultValue;
    TDB2.logInfo.info("Set: " + name + " = " + x);
    int v = Integer.parseInt(x);
    return v;
}
Also used : TDBException(org.apache.jena.tdb2.TDBException)

Example 5 with TDB2

use of org.apache.jena.tdb2.TDB2 in project jena by apache.

the class DatabaseMgr method compact.

/**
 * Compact a datasets which must be a switchable TDB database.
 * This is the normal dataset type for on-disk TDB2 databases.
 *
 * Deletes old database after successful compaction if `shouldDeleteOld` is `true`.
 *
 * @param container
 * @param shouldDeleteOld
 */
public static void compact(DatasetGraph container, boolean shouldDeleteOld) {
    DatasetGraphSwitchable dsg = requireSwitchable(container);
    DatabaseOps.compact(dsg, shouldDeleteOld);
}
Also used : DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable)

Aggregations

DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 TDBException (org.apache.jena.tdb2.TDBException)2 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)2 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)2 ModDataset (arq.cmdline.ModDataset)1 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 CmdException (org.apache.jena.cmd.CmdException)1 Location (org.apache.jena.dboe.base.file.Location)1 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)1 TransactionalSystem (org.apache.jena.dboe.transaction.txn.TransactionalSystem)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)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 StoreParams (org.apache.jena.tdb2.params.StoreParams)1 GraphTDB (org.apache.jena.tdb2.store.GraphTDB)1 GraphViewSwitchable (org.apache.jena.tdb2.store.GraphViewSwitchable)1