use of org.apache.jena.tdb.TDBException in project jena by apache.
the class NodecSSE method encode.
@Override
public int encode(Node node, ByteBuffer bb, PrefixMapping pmap) {
String str = null;
if (node.isURI()) {
// Pesky spaces etc
String x = StrUtils.encodeHex(node.getURI(), MarkerChar, invalidIRIChars);
if (x != node.getURI())
node = NodeFactory.createURI(x);
}
if (node.isLiteral() && NodeUtils.isLangString(node)) {
// Check syntactically valid.
String lang = node.getLiteralLanguage();
if (!LangTag.check(lang))
throw new TDBException("bad language tag: " + node);
}
if (node.isBlank() && !onlySafeBNodeLabels) {
// Special case.
str = "_:" + node.getBlankNodeLabel();
}
// Node->String
if (str == null)
str = NodeFmtLib.str(node, (String) null, pmap0);
// String -> bytes ;
BlockUTF8.fromChars(str, bb);
bb.flip();
return bb.limit();
}
use of org.apache.jena.tdb.TDBException in project jena by apache.
the class NodecSSE method decode.
@Override
public Node decode(ByteBuffer bb, PrefixMapping pmap) {
// Ideally, this would be straight from the byte buffer.
// But currently we go bytes -> string -> node
// Byte -> String
String str = BlockUTF8.toString(bb);
// Easy cases.
if (str.startsWith("_:")) {
// Must be done this way.
// In particular, bnode labels can contain ":" from Jena
// TokenizerText does not recognize these.
str = str.substring(2);
return NodeFactory.createBlankNode(str);
}
if (str.startsWith("<")) {
// Do directly.
// (is it quicker?)
str = str.substring(1, str.length() - 1);
str = StrUtils.unescapeString(str);
str = StrUtils.decodeHex(str, MarkerChar);
return NodeFactory.createURI(str);
}
Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(str);
if (!tokenizer.hasNext())
throw new TDBException("Failed to tokenise: " + str);
Token t = tokenizer.next();
try {
Node n = t.asNode();
if (n == null)
throw new TDBException("Not a node: " + str);
return n;
} catch (RiotException ex) {
throw new TDBException("Bad string for node: " + str);
}
}
use of org.apache.jena.tdb.TDBException in project jena by apache.
the class TupleTable method find.
/** Find all matching tuples - a slot of NodeId.NodeIdAny (or null) means match any */
public Iterator<Tuple<NodeId>> find(Tuple<NodeId> pattern) {
if (tupleLen != pattern.len())
throw new TDBException(format("Mismatch: finding tuple of length %d in a table of tuples of length %d", pattern.len(), tupleLen));
int numSlots = 0;
// Canonical form.
for (int i = 0; i < tupleLen; i++) {
NodeId x = pattern.get(i);
if (!NodeId.isAny(x))
numSlots++;
}
if (numSlots == 0)
return scanAllIndex.all();
int indexNumSlots = 0;
TupleIndex index = null;
for (TupleIndex idx : indexes) {
if (idx != null) {
int w = idx.weight(pattern);
if (w > indexNumSlots) {
indexNumSlots = w;
index = idx;
}
}
}
if (index == null)
// No index at all. Scan.
index = indexes[0];
return index.find(pattern);
}
use of org.apache.jena.tdb.TDBException in project jena by apache.
the class NodeLib method encodeStore.
public static long encodeStore(Node node, ObjectFile file) {
// Buffer pool?
// Nodes can be writtern during reads.
// Make sure this operation is sync'ed.
int maxSize = nodec.maxSize(node);
Block block = file.allocWrite(maxSize);
try {
int len = nodec.encode(node, block.getByteBuffer(), null);
file.completeWrite(block);
return block.getId();
} catch (TDBException ex) {
file.abortWrite(block);
throw ex;
}
}
use of org.apache.jena.tdb.TDBException in project jena by apache.
the class NodeLib method setHash.
public static void setHash(Hash h, Node n) {
NodeType nt = NodeType.lookup(n);
switch(nt) {
case URI:
hash(h, n.getURI(), null, null, nt);
return;
case BNODE:
hash(h, n.getBlankNodeLabel(), null, null, nt);
return;
case LITERAL:
String dt = n.getLiteralDatatypeURI();
if (NodeUtils.isSimpleString(n) || NodeUtils.isLangString(n)) {
// RDF 1.1 : No datatype for:
// xsd:String as simple literals
// rdf:langString and @
dt = null;
}
hash(h, n.getLiteralLexicalForm(), n.getLiteralLanguage(), dt, nt);
return;
case OTHER:
throw new TDBException("Attempt to hash something strange: " + n);
}
throw new TDBException("NodeType broken: " + n);
}
Aggregations