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