Search in sources :

Example 16 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class TDB2StorageBuilder method build.

// public static DatasetGraphTxn build(Location location, StoreParams appParams) {
// StoreParams locParams = StoreParamsCodec.read(location);
// StoreParams dftParams = StoreParams.getDftStoreParams();
// boolean newArea = isNewDatabaseArea(location);
// if ( newArea ) {
// }
// // This can write the chosen parameters if necessary (new database, appParams != null, locParams == null)
// StoreParams params = StoreParamsFactory.decideStoreParams(location, newArea, appParams, locParams, dftParams);
// return create(location, params).build$();
// }
public static DatasetGraphTDB build(Location location, StoreParams appParams) {
    StoreParams locParams = StoreParamsCodec.read(location);
    StoreParams dftParams = StoreParams.getDftStoreParams();
    boolean newArea = isNewDatabaseArea(location);
    if (newArea) {
    }
    // This can write the chosen parameters if necessary (new database, appParams != null, locParams == null)
    StoreParams params = StoreParamsFactory.decideStoreParams(location, newArea, appParams, locParams, dftParams);
    // Builder pattern for adding components.
    TransactionCoordinator txnCoord = buildTransactionCoordinator(location);
    TransactionalSystem txnSystem = new TransactionalBase(txnCoord);
    TDB2StorageBuilder builder = new TDB2StorageBuilder(txnSystem, location, params, new ComponentIdMgr(UUID.randomUUID()));
    StorageTDB storage = builder.buildStorage();
    StoragePrefixes prefixes = builder.buildPrefixes();
    // Finalize.
    builder.components.forEach(txnCoord::add);
    builder.listeners.forEach(txnCoord::addListener);
    // Freezes the TransactionCoordinator components
    txnCoord.start();
    ReorderTransformation reorderTranform = chooseReorderTransformation(location);
    DatasetGraphTDB dsg = new DatasetGraphTDB(location, params, reorderTranform, storage, prefixes, txnSystem);
    // Enable query processing.
    QC.setFactory(dsg.getContext(), OpExecutorTDB2.OpExecFactoryTDB);
    return dsg;
}
Also used : StoreParams(org.apache.jena.tdb2.params.StoreParams) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) StoragePrefixes(org.apache.jena.dboe.storage.StoragePrefixes) ComponentIdMgr(org.apache.jena.tdb2.sys.ComponentIdMgr)

Example 17 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class DatabaseOps method createSwitchable.

private static DatasetGraphSwitchable createSwitchable(Location location, StoreParams params) {
    if (location.isMem()) {
        DatasetGraph dsg = StoreConnection.connectCreate(location).getDatasetGraph();
        return new DatasetGraphSwitchable(null, location, dsg);
    }
    // Exists?
    if (!location.exists())
        throw new TDBException("No such location: " + location);
    Path path = IO_DB.asPath(location);
    // Scan for DBs
    Path db = findLocation(path, dbPrefix);
    if (db == null) {
        db = path.resolve(dbPrefix + SEP + startCount);
        IOX.createDirectory(db);
    }
    Location loc2 = IO_DB.asLocation(db);
    DatasetGraphTDB dsg = StoreConnection.connectCreate(loc2, params).getDatasetGraphTDB();
    DatasetGraphSwitchable appDSG = new DatasetGraphSwitchable(path, location, dsg);
    return appDSG;
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) 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)

Example 18 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class ProcIngestDataX method build.

private static Pair<Long, Long> build(DatasetGraph dsg, ProgressMonitor monitor, OutputStream outputTriples, OutputStream outputQuads, List<String> datafiles) {
    DatasetGraphTDB dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
    outputTriples = IO.ensureBuffered(outputTriples);
    outputQuads = IO.ensureBuffered(outputQuads);
    IngestData sink = new IngestData(dsgtdb, monitor, outputTriples, outputQuads, false);
    Timer timer = new Timer();
    timer.startTimer();
    // [BULK] XXX Start monitor on first item from parser.
    monitor.start();
    sink.startBulk();
    AsyncParser.asyncParse(datafiles, sink);
    // for( String filename : datafiles) {
    // if ( datafiles.size() > 0 )
    // cmdLog.info("Load: "+filename+" -- "+DateTimeUtils.nowAsString());
    // RDFParser.source(filename).parse(sink);
    // }
    sink.finishBulk();
    IO.close(outputTriples);
    IO.close(outputQuads);
    long cTriple = sink.tripleCount();
    long cQuad = sink.quadCount();
    // See Stats class.
    if (sink.getCollector() != null) {
        Location location = dsgtdb.getLocation();
        if (!location.isMem())
            Stats.write(location.getPath(Names.optStats), sink.getCollector().results());
    }
    // ---- Monitor
    monitor.finish();
    long time = timer.endTimer();
    long total = monitor.getTicks();
    float elapsedSecs = time / 1000F;
    float rate = (elapsedSecs != 0) ? total / elapsedSecs : 0;
    // [BULK] End stage.
    String str = String.format("%s Total: %,d tuples : %,.2f seconds : %,.2f tuples/sec [%s]", BulkLoaderX.StepMarker, total, elapsedSecs, rate, DateTimeUtils.nowAsString());
    BulkLoaderX.LOG_Data.info(str);
    return Pair.create(cTriple, cQuad);
}
Also used : Timer(org.apache.jena.atlas.lib.Timer) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB) Location(org.apache.jena.dboe.base.file.Location)

Example 19 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class OpExecutorTDB2 method execute.

@Override
protected QueryIterator execute(OpDatasetNames dsNames, QueryIterator input) {
    DatasetGraphTDB ds = (DatasetGraphTDB) execCxt.getDataset();
    Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
    Node gn = dsNames.getGraphNode();
    if (Var.isVar(gn))
        return SolverLibTDB.graphNames(ds, dsNames.getGraphNode(), input, filter, execCxt);
    else
        return SolverLibTDB.testForGraphName(ds, dsNames.getGraphNode(), input, filter, execCxt);
}
Also used : Node(org.apache.jena.graph.Node) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 20 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.

the class OpExecutorTDB2 method execute.

@Override
protected QueryIterator execute(OpFilter opFilter, QueryIterator input) {
    if (!isForTDB)
        return super.execute(opFilter, input);
    // (filter (bgp ...))
    if (OpBGP.isBGP(opFilter.getSubOp())) {
        // Still may be a TDB graph in a non-TDB dataset (e.g. a named model)
        GraphTDB graph = (GraphTDB) execCxt.getActiveGraph();
        OpBGP opBGP = (OpBGP) opFilter.getSubOp();
        return executeBGP(graph, opBGP, input, opFilter.getExprs(), execCxt);
    }
    // (filter (quadpattern ...))
    if (opFilter.getSubOp() instanceof OpQuadPattern) {
        OpQuadPattern quadPattern = (OpQuadPattern) opFilter.getSubOp();
        DatasetGraphTDB ds = (DatasetGraphTDB) execCxt.getDataset();
        return optimizeExecuteQuads(ds, input, quadPattern.getGraphNode(), quadPattern.getBasicPattern(), opFilter.getExprs(), execCxt);
    }
    // (filter (anything else))
    return super.execute(opFilter, input);
}
Also used : GraphTDB(org.apache.jena.tdb2.store.GraphTDB) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Aggregations

DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)19 Location (org.apache.jena.dboe.base.file.Location)10 Node (org.apache.jena.graph.Node)8 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)8 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)8 Test (org.junit.Test)8 NodeId (org.apache.jena.tdb2.store.NodeId)7 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)7 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)6 StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)4 ConfigTest (org.apache.jena.tdb2.ConfigTest)3 TDBException (org.apache.jena.tdb2.TDBException)3 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)2 FileSet (org.apache.jena.dboe.base.file.FileSet)2 Record (org.apache.jena.dboe.base.record.Record)2 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)2 Graph (org.apache.jena.graph.Graph)2 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)2 ModDataset (arq.cmdline.ModDataset)1