Search in sources :

Example 6 with TDBException

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;
    }
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId) Record(org.apache.jena.dboe.base.record.Record) Hash(org.apache.jena.tdb2.store.Hash)

Example 7 with TDBException

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;
}
Also used : TDBException(org.apache.jena.tdb2.TDBException)

Example 8 with TDBException

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;
}
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 9 with TDBException

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);
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) ProcessFileLock(org.apache.jena.dboe.base.file.ProcessFileLock) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 10 with TDBException

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);
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) TDBException(org.apache.jena.tdb2.TDBException)

Aggregations

TDBException (org.apache.jena.tdb2.TDBException)20 NodeId (org.apache.jena.tdb2.store.NodeId)6 Node (org.apache.jena.graph.Node)4 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)4 Location (org.apache.jena.dboe.base.file.Location)3 Record (org.apache.jena.dboe.base.record.Record)3 RiotThriftException (org.apache.jena.riot.thrift.RiotThriftException)2 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 TException (org.apache.thrift.TException)2 ArrayList (java.util.ArrayList)1 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1 FileSet (org.apache.jena.dboe.base.file.FileSet)1 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)1 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)1 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)1