Search in sources :

Example 21 with Location

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

the class tdbgenindex method main.

public static void main(String... argv) {
    // Usage: srcLocation indexName dstLocation indexName
    if (argv.length != 4) {
        System.err.println("Usage: " + Lib.classShortName(tdbgenindex.class) + " srcLocation srcIndex dstLocation dstIndex");
        System.exit(1);
    }
    Location srcLoc = Location.create(argv[0]);
    String srcIndexName = argv[1];
    Location dstLoc = Location.create(argv[2]);
    String dstIndexName = argv[3];
    int readCacheSize = 0;
    int writeCacheSize = -1;
    if (srcIndexName.length() != dstIndexName.length()) {
        System.err.println("srcIndexName.length() != dstIndexName.length() " + srcIndexName + " :: " + dstIndexName);
        System.exit(1);
    }
    String primary;
    int dftKeyLength;
    int dftValueLength;
    if (srcIndexName.length() == 3) {
        primary = Names.primaryIndexTriples;
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
    } else if (srcIndexName.length() == 4) {
        primary = Names.primaryIndexQuads;
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
    } else {
        System.err.println("indexlength != 3 or 4");
        System.exit(1);
        primary = null;
        dftKeyLength = 0;
        dftValueLength = 0;
    }
    TupleIndex srcIdx = SetupTDB.makeTupleIndex(srcLoc, primary, srcIndexName, srcIndexName, dftKeyLength);
    TupleIndex dstIdx = SetupTDB.makeTupleIndex(dstLoc, primary, dstIndexName, dstIndexName, dftKeyLength);
    Iterator<Tuple<NodeId>> iter = srcIdx.all();
    for (; iter.hasNext(); ) {
        Tuple<NodeId> tuple = iter.next();
        dstIdx.add(tuple);
    }
    srcIdx.close();
    dstIdx.close();
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Location(org.apache.jena.tdb.base.file.Location)

Example 22 with Location

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

the class StoreConnection method _makeAndCache.

private static StoreConnection _makeAndCache(DatasetGraphTDB dsg) {
    Location location = dsg.getLocation();
    StoreConnection sConn = cache.get(location);
    if (sConn == null) {
        sConn = new StoreConnection(dsg);
        if (SystemTDB.DiskLocationMultiJvmUsagePrevention) {
            // Obtain the lock ASAP
            LocationLock lock = location.getLock();
            if (lock.canLock()) {
                if (!lock.canObtain())
                    throw new TDBException("Can't open database at location " + location.getDirectoryPath() + " as it is already locked by the process with PID " + lock.getOwner() + ".  TDB databases do not permit concurrent usage across JVMs so in order to prevent possible data corruption you cannot open this location from the JVM that does not own the lock for the dataset");
                lock.obtain();
                // and if not error
                if (!lock.isOwned()) {
                    throw new TDBException("Can't open database at location " + location.getDirectoryPath() + " as it is alread locked by the process with PID " + lock.getOwner() + ".  TDB databases do not permit concurrent usage across JVMs so in order to prevent possible data corruption you cannot open this location from the JVM that does not own the lock for the dataset");
                }
            }
        }
        sConn.forceRecoverFromJournal();
        if (!location.isMemUnique())
            // Don't cache use-once in-memory datasets.
            cache.put(location, sConn);
        String NS = TDB.PATH;
        TransactionInfo txInfo = new TransactionInfo(sConn.transactionManager);
        ARQMgt.register(NS + ".system:type=Transactions", txInfo);
    }
    return sConn;
}
Also used : LocationLock(org.apache.jena.tdb.base.file.LocationLock) Location(org.apache.jena.tdb.base.file.Location)

Example 23 with Location

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

the class TDBGraphAssembler method open.

@Override
public Model open(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");
    final Dataset ds;
    if (locationDir != null) {
        Location location = Location.create(locationDir);
        ds = TDBFactory.createDataset(location);
    } else
        ds = DatasetAssemblerTDB.make(dataset);
    try {
        if (graphName != null)
            return ds.getNamedModel(graphName);
        else
            return ds.getDefaultModel();
    } catch (RuntimeException ex) {
        ex.printStackTrace(System.err);
        throw ex;
    }
}
Also used : AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) VocabTDB.pDataset(org.apache.jena.tdb.assembler.VocabTDB.pDataset) Dataset(org.apache.jena.query.Dataset) VocabTDB.pLocation(org.apache.jena.tdb.assembler.VocabTDB.pLocation) Location(org.apache.jena.tdb.base.file.Location)

Example 24 with Location

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

the class TestTDBFactory method testTDBFresh11.

@Test
public void testTDBFresh11() {
    Location loc = Location.mem();
    boolean b = TDBFactory.inUseLocation(loc);
    assertFalse("Expect false before any creation attempted", b);
}
Also used : Location(org.apache.jena.tdb.base.file.Location) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 25 with Location

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

the class TestStringFileDisk method createStringFile.

@Override
protected StringFile createStringFile() {
    String dir = ConfigTest.getTestingDir();
    clearDirectory(dir);
    Location loc = Location.create(dir);
    fn = loc.getPath("xyz", "node");
    FileOps.delete(fn);
    return FileFactory.createStringFileDisk(fn);
}
Also used : Location(org.apache.jena.tdb.base.file.Location)

Aggregations

Location (org.apache.jena.tdb.base.file.Location)29 Test (org.junit.Test)16 BaseTest (org.apache.jena.atlas.junit.BaseTest)9 LocationLock (org.apache.jena.tdb.base.file.LocationLock)8 ConfigTest (org.apache.jena.tdb.ConfigTest)6 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 StoreConnection (org.apache.jena.tdb.StoreConnection)4 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)4 Record (org.apache.jena.tdb.base.record.Record)3 StoreParams (org.apache.jena.tdb.setup.StoreParams)3 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 Dataset (org.apache.jena.query.Dataset)2 VocabTDB.pLocation (org.apache.jena.tdb.assembler.VocabTDB.pLocation)2 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)2 RangeIndex (org.apache.jena.tdb.index.RangeIndex)2 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)2 ColumnMap (org.apache.jena.tdb.lib.ColumnMap)2