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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations