use of org.openrdf.sail.SailException in project backstage by zepheira.
the class Database method internalBuildPropertyRecords.
private void internalBuildPropertyRecords(SailConnection sc) {
_propertyRecords = new LinkedList<PropertyRecord>();
_propertyIDToRecord = new HashMap<String, PropertyRecord>();
CloseableIteration<? extends Statement, SailException> i;
try {
i = sc.getStatements(null, null, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to get property records", e);
return;
}
Set<URI> predicates = new HashSet<URI>();
try {
while (i.hasNext()) {
Statement s = i.next();
predicates.add(s.getPredicate());
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
for (URI predicate : predicates) {
PropertyRecord r = createPropertyRecord(predicate, sc);
if (r != null) {
_propertyRecords.add(r);
_propertyIDToRecord.put(r.id, r);
}
}
}
use of org.openrdf.sail.SailException in project backstage by zepheira.
the class Database method createPropertyRecord.
private PropertyRecord createPropertyRecord(URI predicate, SailConnection sc) {
String id = getPropertyId(predicate, sc);
String label = SailUtilities.getStringObject(sc, predicate, RDFS.LABEL, id);
String valueType = SailUtilities.getStringObject(sc, predicate, ExhibitOntology.VALUE_TYPE, "text");
Properties properties = new Properties();
CloseableIteration<? extends Statement, SailException> i = null;
try {
i = sc.getStatements(predicate, null, null, true);
} catch (SailException e) {
_logger.error("Failed to get all statements in order to get property record", e);
return null;
}
if (i != null) {
try {
while (i.hasNext()) {
Statement s = i.next();
URI p = s.getPredicate();
Value o = s.getObject();
if (!p.equals(RDFS.LABEL) && !p.equals(ExhibitOntology.ID) && !p.equals(ExhibitOntology.VALUE_TYPE)) {
properties.put(p.getLocalName(), SailUtilities.valueToString(o));
}
}
} catch (SailException e) {
_logger.warn("Failed to iterate through statements", e);
} finally {
try {
i.close();
} catch (SailException e) {
_logger.warn("Failed to close statement iterator", e);
}
}
}
return new PropertyRecord(predicate, id, label, valueType, properties);
}
use of org.openrdf.sail.SailException in project backstage by zepheira.
the class Database method getItemLabel.
public String getItemLabel(String itemID) {
String label = _itemIdToLabel.get(itemID);
if (label == null) {
getRepository();
URI itemURI = _itemIdToUri.get(itemID);
if (itemURI != null) {
try {
SailConnection sc = _sail.getConnection();
try {
CloseableIteration<? extends Statement, SailException> i = sc.getStatements(itemURI, RDFS.LABEL, null, true);
try {
if (i.hasNext()) {
label = Utilities.valueToString(i.next().getObject());
}
} finally {
i.close();
}
} finally {
sc.close();
}
} catch (SailException e) {
}
}
if (label == null) {
label = itemID;
}
_itemIdToLabel.put(itemID, label);
}
return label;
}
use of org.openrdf.sail.SailException in project blueprints by tinkerpop.
the class PropertyGraphSailConnection method evaluateInternal.
protected CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluateInternal(final TupleExpr query, final Dataset dataset, final BindingSet bindings, final boolean includeInferred) throws SailException {
try {
TripleSource tripleSource = new SailConnectionTripleSource(this, context.valueFactory, includeInferred);
EvaluationStrategyImpl strategy = new EvaluationStrategyImpl(tripleSource, dataset);
return strategy.evaluate(query, bindings);
} catch (QueryEvaluationException e) {
throw new SailException(e);
}
}
use of org.openrdf.sail.SailException in project blueprints by tinkerpop.
the class PropertyGraphSailConnection method getStatements_xPO.
private CloseableIteration<Statement, SailException> getStatements_xPO(final URI predicate, final Value object) throws SailException {
if (predicate.equals(RDF.TYPE)) {
if (object.equals(PropertyGraphSail.VERTEX)) {
Source<Vertex> s = new Source<Vertex>(context.graph.getVertices().iterator(), vertexTypes);
return new StatementIteration(s);
} else if (object.equals(PropertyGraphSail.EDGE) && firstClassEdges) {
Source<Edge> s = new Source<Edge>(context.graph.getEdges().iterator(), edgeTypes);
return new StatementIteration(s);
} else {
return new StatementIteration();
}
} else if (predicate.equals(PropertyGraphSail.ID)) {
Object id = literalToObject(object);
if (null == id) {
return new StatementIteration();
} else {
Vertex v = context.graph.getVertex(id);
Edge e = firstClassEdges ? context.graph.getEdge(id) : null;
if (null == v && null == e) {
return new StatementIteration();
} else {
Collection<Statement> s = new LinkedList<Statement>();
if (null != v) {
vertexIds.generate(v, s);
}
if (null != e) {
edgeIds.generate(e, s);
}
return new SimpleCloseableIteration<Statement, SailException>(s.iterator());
}
}
} else if (predicate.equals(PropertyGraphSail.LABEL)) {
if (!firstClassEdges) {
return new StatementIteration();
}
// TODO: find edges faster using indices
Object label = literalToObject(object);
if (null == label || !(label instanceof String)) {
return new StatementIteration();
} else {
Source<Edge> edges = new Source<Edge>(context.graph.getEdges().iterator(), matchingLabels((String) label, object));
return new StatementIteration(edges);
}
} else if (predicate.equals(PropertyGraphSail.HEAD)) {
if (!firstClassEdges) {
return new StatementIteration();
}
Vertex v = object instanceof URI ? vertexForURI((URI) object) : null;
if (null == v) {
return new StatementIteration();
} else {
Iterator<Edge> edgeIterator = v.getEdges(Direction.IN).iterator();
Source<Edge> edges = new Source<Edge>(edgeIterator, heads);
return new StatementIteration(edges);
}
} else if (predicate.equals(PropertyGraphSail.TAIL)) {
if (!firstClassEdges) {
return new StatementIteration();
}
Vertex v = object instanceof URI ? vertexForURI((URI) object) : null;
if (null == v) {
return new StatementIteration();
} else {
Iterator<Edge> edgeIterator = v.getEdges(Direction.OUT).iterator();
Source<Edge> edges = new Source<Edge>(edgeIterator, tails);
return new StatementIteration(edges);
}
} else if (isPropertyPredicate(predicate)) {
Object value = literalToObject(object);
if (null == value) {
return new StatementIteration();
} else {
// TODO: lookup matching vertices and edges faster using indices
String key = keyFromPredicate(predicate);
Source<Vertex> vertices = new Source<Vertex>(context.graph.getVertices().iterator(), vertexPropertiesWithKeyAndValue(key, predicate, value, (Literal) object));
if (firstClassEdges) {
Source<Edge> edges = new Source<Edge>(context.graph.getEdges().iterator(), edgePropertiesWithKeyAndValue(key, predicate, value, (Literal) object));
return new StatementIteration(vertices, edges);
} else {
return new StatementIteration(vertices);
}
}
} else if (isRelationPredicate(predicate)) {
if (!(object instanceof URI)) {
return new StatementIteration();
} else {
String label = labelForRelationPredicate(predicate);
Vertex vObj = vertexForURI((URI) object);
if (null != vObj) {
Source<Vertex> s = new Source<Vertex>(new SingleItemIterator<Vertex>(vObj), new RelationGenerator(label, true));
return new StatementIteration(s);
} else {
return new StatementIteration();
}
}
} else {
return new StatementIteration();
}
}
Aggregations