/** * Return the DatasetGraphTDB for a DatasetGraph, or null. * Use the {@link DatasetGraphTDB} with care. */ public static DatasetGraphSwitchable getDatabaseContainer(DatasetGraph dsg) { if ( dsg instanceof DatasetGraphSwitchable ) return (DatasetGraphSwitchable)dsg; throw new TDBException("Not a TDB database container"); }
private static String key(String string) { if ( string.startsWith(jsonKeyPrefix)) throw new TDBException("Key name already starts with '"+jsonKeyPrefix+"'") ; return jsonKeyPrefix+string ; }
private static String unkey(String string) { if ( ! string.startsWith(jsonKeyPrefix) ) throw new TDBException("JSON key name does not start with '"+jsonKeyPrefix+"'") ; return string.substring(jsonKeyPrefix.length()) ; }
/** Block until the pending operations queue is below the given size. */ public void reduceAsyncQueue(int reduceSize) { System.out.println("Reduce: "+outstanding.size()) ; while ( outstanding.size() > reduceSize ) { try { outstanding.take().get() ; } catch (Exception ex) { throw new TDBException("Exception taking from async queue", ex) ; } } }
public static void panic(Class<?> clazz, String string) { Log.error(clazz, string) ; throw new TDBException(string) ; }
/** * Return the DatasetGraphTDB for a DatasetGraph, or throw an exception. */ public static DatasetGraphTDB requireStorage(DatasetGraph dsg) { DatasetGraphTDB dsgtdb = unwrap(dsg); if ( dsgtdb == null ) throw new TDBException("Not a TDB database (argument is neither a switchable nor direct TDB DatasetGraph)"); return dsgtdb; }
@Override protected void syncSub() { try { transport.flush(); } catch (Exception ex) { throw new TDBException("NodeTableTRDF", ex) ; } }
public NodeTupleTableConcrete(int N, TupleIndex[] indexes, NodeTable nodeTable) { if (indexes.length == 0 || indexes[0] == null) throw new TDBException("A primary index is required") ; for (TupleIndex index : indexes) { if (N != index.getTupleLength()) throw new TDBException(format("Inconsistent: TupleTable width is %d but index %s is %d", N, index.getMappingStr(), index.getTupleLength())) ; } this.tupleTable = new TupleTable(N, indexes) ; this.nodeTable = nodeTable ; }
@Override protected void closeSub() { if ( transport.isOpen() ) { try { transport.close() ; } catch (Exception ex) { throw new TDBException("NodeTableTRDF", ex) ; } } }
protected final NodeId idForNode(Node node) { if ( node == null || node == Node.ANY ) return NodeId.NodeIdAny ; if ( node.isVariable() ) throw new TDBException("Can't pass variables to NodeTupleTable.find*") ; return nodeTable.getNodeIdForNode(node) ; }
/** Set index - for code that manipulates internal structures directly - use with care */ public void setTupleIndex(int i, TupleIndex index) { if ( index != null && index.getTupleLength() != tupleLen ) throw new TDBException("Incompatible index: " + index.getMappingStr()) ; indexes[i] = index ; }
@Override public void finishSection() { if ( ! inSection ) throw new TDBException("finishSection: Not in section"); print(" End file: %s (triples/quads = %,d)", label, sectionTickCounter); inSection = false; sectionTimeInMillis = sectionTimer.endTimer(); }
protected DatasetGraphTDB dsgToQuery(DatasetGraph dataset) { try { return TDBInternal.requireStorage(dataset); } catch (TDBException ex) { // Check to a more specific message. throw new TDBException("Internal inconsistency: trying to execute query on unrecognized kind of DatasetGraph: "+Lib.className(dataset)) ; } }
/** Insert a tuple */ public void add(Tuple<NodeId> t) { // A "contains test" could be used to avoid needing to hit all // the indexes when the triple is already present. if ( tupleLen != t.len() ) throw new TDBException(format("Mismatch: inserting tuple of length %d into a table of tuples of length %d", t.len(), tupleLen)) ; for ( int i = 0 ; i < indexes.length ; i++ ) { if ( indexes[i] == null ) continue ; indexes[i].add(t) ; syncNeeded = true ; } }
/** Delete a tuple */ public void delete( Tuple<NodeId> t ) { if ( tupleLen != t.len() ) throw new TDBException(format("Mismatch: deleting tuple of length %d from a table of tuples of length %d", t.len(), tupleLen)) ; for ( TupleIndex index : indexes ) { if ( index == null ) continue; index.delete( t ); } }
private static Integer getInt(JsonObject json, String key) { if ( ! json.hasKey(key) ) throw new TDBException("StoreParamsCodec.getInt: no such key: "+key) ; Integer x = json.get(key).getAsNumber().value().intValue() ; return x ; }
private static NodeId create(int v1, long v2) { if ( !BitsInt.isSet(v1, 32) ) return createPtrLong(v1, v2); int t = v1 >> 24; NodeIdType type = NodeIdType.intToEnum(t); if ( type == NodeIdType.SPECIAL ) throw new TDBException(String.format("Attempt to create a special from a long: 0x%016", v2)); return createNew(type, 0, v2); }
private static String getString(JsonObject json, String key) { if ( ! json.hasKey(key) ) throw new TDBException("StoreParamsCodec.getString: no such key: "+key) ; String x = json.get(key).getAsString().value() ; return x ; }
private static Triple triple(NodeTable nodeTable, Tuple<NodeId> tuple) { if ( tuple.len() != 3 ) throw new TDBException("Tuple is not of length 3: " + tuple); return triple(nodeTable, tuple.get(0), tuple.get(1), tuple.get(2)); }
private static String[] getStringArray(JsonObject json, String key) { if ( ! json.hasKey(key) ) throw new TDBException("StoreParamsCodec.getStringArray: no such key: "+key) ; JsonArray a = json.get(key).getAsArray() ; String[] x = new String[a.size()] ; for ( int i = 0 ; i < a.size() ; i++ ) { x[i] = a.get(i).getAsString().value() ; } return x ; }