use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class NodeTableNative method accessIndex.
protected final NodeId accessIndex(Node node, boolean create) {
Hash hash = new Hash(nodeHashToId.getRecordFactory().keyLength());
NodeLib.setHash(hash, node);
byte[] k = hash.getBytes();
// Key only.
Record r = nodeHashToId.getRecordFactory().create(k);
synchronized (// Pair to readNodeFromTable.
this) {
// Key and value, or null
Record r2 = nodeHashToId.find(r);
if (r2 != null) {
// Found. Get the NodeId.
NodeId id = NodeIdFactory.get(r2.getValue(), 0);
return id;
}
// Not found.
if (!create)
return NodeId.NodeDoesNotExist;
// Write the node, which allocates an id for it.
syncNeeded = true;
NodeId id = writeNodeToTable(node);
// Update the r record with the new id.
// r.value := id bytes;
NodeIdFactory.set(id, r.getValue(), 0);
// Put in index - may appear because of concurrency
if (!nodeHashToId.insert(r))
throw new TDBException("NodeTableBase::nodeToId - record mysteriously appeared");
return id;
}
}
use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class SystemTDB method intValue.
private static int intValue(String name, int defaultValue) {
if (name == null)
return defaultValue;
if (name.length() == 0)
throw new TDBException("Empty string for value name");
if (properties == null)
return defaultValue;
String x = properties.getProperty(name);
if (x == null)
return defaultValue;
TDB2.logInfo.info("Set: " + name + " = " + x);
int v = Integer.parseInt(x);
return v;
}
use of org.apache.jena.tdb2.TDBException 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.TDBException in project jena by apache.
the class DatabaseConnection method build.
private static DatabaseConnection build(Location location, StoreParams params) {
if (location.isMemUnique()) {
throw new TDBException("Can't buildForCache a memory-unique location");
}
ProcessFileLock lock = null;
if (SystemTDB.DiskLocationMultiJvmUsagePrevention && !location.isMem()) {
// Take the lock for the swithable.
// StoreConnection will take a lock for the storage.
lock = lockForLocation(location);
// Take the lock. This is atomic and non-reentrant.
lock.lockEx();
}
// c.f. StoreConnection.make
DatasetGraph dsg = DatabaseOps.create(location, params);
return new DatabaseConnection(dsg, location, lock);
}
use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class Async method execAsync.
public void execAsync(Runnable action) {
reduceAsyncQueue(pendingQueueLimit);
Future<Void> task = executorService.submit(() -> {
try {
action.run();
} catch (Exception ex) {
throw new TDBException("Unexpected exception: " + ex.getMessage(), ex);
}
return null;
});
outstanding.add(task);
}
Aggregations