Search in sources :

Example 11 with Location

use of org.apache.jena.dboe.base.file.Location in project jena by apache.

the class StoreConnection method internalReset.

/**
 * Stop managing all locations.
 * Use with extreme care.
 * This is intended to support internal testing.
 */
public static synchronized void internalReset() {
    // Copy to avoid potential CME.
    Set<Location> x = Set.copyOf(cache.keySet());
    for (Location loc : x) internalExpel(loc, true);
    cache.clear();
    ChannelManager.reset();
}
Also used : Location(org.apache.jena.dboe.base.file.Location)

Example 12 with Location

use of org.apache.jena.dboe.base.file.Location 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 13 with Location

use of org.apache.jena.dboe.base.file.Location 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 14 with Location

use of org.apache.jena.dboe.base.file.Location in project jena by apache.

the class TestTDBFactory method testTDBFactory3.

@Test
public void testTDBFactory3() {
    TDBInternal.reset();
    // Only do disk things for tests that need them (disk takes time!).
    String DIRx = ConfigTest.getCleanDir();
    Location DIR = Location.create(DIRx);
    try {
        FileOps.clearDirectory(DIRx);
        Dataset ds = TDB2Factory.connectDataset(DIR);
        test(ds);
    } finally {
        FileOps.clearDirectory(DIRx);
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) Location(org.apache.jena.dboe.base.file.Location) Test(org.junit.Test)

Example 15 with Location

use of org.apache.jena.dboe.base.file.Location in project jena by apache.

the class TestDatabaseConnection method testStoreConnectionTxn1.

@Test
public void testStoreConnectionTxn1() {
    TDBInternal.reset();
    // Only do disk things for test that need them (disk takes time!).
    String DIRx = ConfigTest.getCleanDir();
    Location DIR = Location.create(DIRx);
    FileOps.clearDirectory(DIRx);
    try {
        DatasetGraph dg1 = DatabaseConnection.connectCreate(DIR).getDatasetGraph();
        DatasetGraph dg2 = DatabaseConnection.connectCreate(DIR).getDatasetGraph();
        assertSame(dg1, dg2);
    } finally {
        FileOps.clearDirectory(DIRx);
    }
}
Also used : Location(org.apache.jena.dboe.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) ConfigTest(org.apache.jena.tdb2.ConfigTest) Test(org.junit.Test)

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