use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class NodeTableTRDF method writeNodeToTable.
@Override
protected NodeId writeNodeToTable(Node node) {
RDF_Term term = ThriftConvert.convert(node, true);
try {
long x = diskFile.length();
// Paired : [*]
NodeId nid = NodeIdFactory.createPtr(x);
term.write(protocol);
// transport.flush();
return nid;
} catch (TransactionException ex) {
throw ex;
} catch (Exception ex) {
throw new TDBException("NodeTableThrift/Write", ex);
}
}
use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class NodeTableTRDF method readNodeFromTable.
@Override
protected Node readNodeFromTable(NodeId id) {
try {
// Paired : [*]
long x = id.getPtrLocation();
transport.readPosition(x);
RDF_Term term = new RDF_Term();
term.read(protocol);
Node n = ThriftConvert.convert(term);
return n;
} catch (TException ex) {
throw new TDBException("NodeTableTRDF/Read", ex);
} catch (RiotThriftException ex) {
Log.error(this, "Bad encoding: NodeId = " + id);
throw ex;
}
}
use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class BindingTDB method get1.
@Override
public Node get1(Var var) {
try {
Node n = cacheGet(var);
if (n != null)
return n;
NodeId id = idBinding.get(var);
if (id == null)
return null;
if (NodeId.isDoesNotExist(id))
return null;
n = nodeTable.getNodeForNodeId(id);
if (n == null)
// But there was to put it in the BindingNodeId.
throw new TDBException("No node in NodeTable for NodeId " + id);
// Update cache.
cachePut(var, n);
return n;
} catch (Exception ex) {
Log.error(this, String.format("get1(%s)", var), ex);
return null;
}
}
use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class ProcBuildIndexX method indexBuilder.
private static long indexBuilder(DatasetGraph dsg, InputStream input, String indexName) {
long tickPoint = BulkLoaderX.DataTick;
int superTick = BulkLoaderX.DataSuperTick;
// Location of storage, not the DB.
DatasetGraphTDB dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
Location location = dsgtdb.getLocation();
int keyLength = SystemTDB.SizeOfNodeId * indexName.length();
int valueLength = 0;
// The name is the order.
String primary = indexName;
String primaryOrder;
int dftKeyLength;
int dftValueLength;
int tupleLength = indexName.length();
TupleIndex index;
if (tupleLength == 3) {
primaryOrder = Names.primaryIndexTriples;
dftKeyLength = SystemTDB.LenIndexTripleRecord;
dftValueLength = 0;
// Find index.
index = findIndex(dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
} else if (tupleLength == 4) {
primaryOrder = Names.primaryIndexQuads;
dftKeyLength = SystemTDB.LenIndexQuadRecord;
dftValueLength = 0;
index = findIndex(dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
} else {
throw new TDBException("Index name: " + indexName);
}
TupleMap colMap = TupleMap.create(primaryOrder, indexName);
int readCacheSize = 10;
int writeCacheSize = 100;
int blockSize = SystemTDB.BlockSize;
RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
int blockSizeNodes = blockSize;
int blockSizeRecords = blockSize;
FileSet destination = new FileSet(location, indexName);
BufferChannel blkState = FileFactory.createBufferChannel(destination, Names.extBptState);
BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.extBptTree, blockSizeNodes, readCacheSize, writeCacheSize);
BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.extBptRecords, blockSizeRecords, readCacheSize, writeCacheSize);
int rowBlock = 1000;
Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
// ProgressMonitor.
ProgressMonitor monitor = ProgressMonitorOutput.create(BulkLoaderX.LOG_Index, indexName, tickPoint, superTick);
ProgressIterator<Record> iter2 = new ProgressIterator<>(iter, monitor);
monitor.start();
BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter2, bptParams, recordFactory, blkState, blkMgrNodes, blkMgrRecords);
bpt2.close();
monitor.finish();
// [BULK] End stage.
long count = monitor.getTicks();
return count;
}
use of org.apache.jena.tdb2.TDBException in project jena by apache.
the class ThreadBufferingCache method getOrFill.
@Override
public Value getOrFill(Key key, Callable<Value> callable) {
if (!buffering())
return baseCache.getOrFill(key, callable);
// Not thread safe but this overlay cache is for single-thread use.
Value item = localCache().getIfPresent(key);
if (item != null)
return item;
item = baseCache.getIfPresent(key);
if (item != null)
return item;
// Add to cache so new data hence place in localCache.
try {
item = callable.call();
localCache().put(key, item);
} catch (Exception ex) {
throw new TDBException("Exception filling cache", ex);
}
return item;
}
Aggregations