Search in sources :

Example 1 with Location

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);
    }
}
Also used : CmdException(org.apache.jena.cmd.CmdException) Lang(org.apache.jena.riot.Lang) Location(org.apache.jena.dboe.base.file.Location)

Example 2 with Location

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;
}
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 Location

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;
    }
}
Also used : AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Resource(org.apache.jena.rdf.model.Resource) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Location(org.apache.jena.dboe.base.file.Location)

Example 4 with Location

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)));
}
Also used : DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Location(org.apache.jena.dboe.base.file.Location) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb2.ConfigTest)

Example 5 with Location

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)));
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Location(org.apache.jena.dboe.base.file.Location) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb2.ConfigTest)

Aggregations

Location (org.apache.jena.dboe.base.file.Location)29 Test (org.junit.Test)12 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)10 ConfigTest (org.apache.jena.tdb2.ConfigTest)7 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)7 StoreParams (org.apache.jena.tdb2.params.StoreParams)4 Dataset (org.apache.jena.query.Dataset)3 TDBException (org.apache.jena.tdb2.TDBException)3 Path (java.nio.file.Path)2 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)2 Graph (org.apache.jena.graph.Graph)2 StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)2 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 Timer (org.apache.jena.atlas.lib.Timer)1 TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)1 CmdException (org.apache.jena.cmd.CmdException)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1