use of org.eclipse.rdf4j.sail.SailException in project incubator-rya by apache.
the class RdfCloudTripleStoreConnection method getStatementsInternal.
@Override
protected CloseableIteration<? extends Statement, SailException> getStatementsInternal(final Resource subject, final IRI predicate, final Value object, final boolean flag, final Resource... contexts) throws SailException {
// try {
// have to do this to get the inferred values
// TODO: Will this method reduce performance?
final Var subjVar = decorateValue(subject, "s");
final Var predVar = decorateValue(predicate, "p");
final Var objVar = decorateValue(object, "o");
StatementPattern sp = null;
final boolean hasContext = contexts != null && contexts.length > 0;
final Resource context = (hasContext) ? contexts[0] : null;
final Var cntxtVar = decorateValue(context, "c");
// TODO: Only using one context here
sp = new StatementPattern(subjVar, predVar, objVar, cntxtVar);
// return new StoreTripleSource(store.getConf()).getStatements(resource, uri, value, contexts);
final CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate = evaluate(sp, null, null, false);
return new // TODO: Use a util class to do this
CloseableIteration<Statement, SailException>() {
private boolean isClosed = false;
@Override
public void close() throws SailException {
isClosed = true;
try {
evaluate.close();
} catch (final QueryEvaluationException e) {
throw new SailException(e);
}
}
@Override
public boolean hasNext() throws SailException {
try {
return evaluate.hasNext();
} catch (final QueryEvaluationException e) {
throw new SailException(e);
}
}
@Override
public Statement next() throws SailException {
if (!hasNext() || isClosed) {
throw new NoSuchElementException();
}
try {
final BindingSet next = evaluate.next();
final Resource bs_subj = (Resource) ((subjVar.hasValue()) ? subjVar.getValue() : next.getBinding(subjVar.getName()).getValue());
final IRI bs_pred = (IRI) ((predVar.hasValue()) ? predVar.getValue() : next.getBinding(predVar.getName()).getValue());
final Value bs_obj = (objVar.hasValue()) ? objVar.getValue() : next.getBinding(objVar.getName()).getValue();
final Binding b_cntxt = next.getBinding(cntxtVar.getName());
// convert BindingSet to Statement
if (b_cntxt != null) {
return SimpleValueFactory.getInstance().createStatement(bs_subj, bs_pred, bs_obj, (Resource) b_cntxt.getValue());
} else {
return SimpleValueFactory.getInstance().createStatement(bs_subj, bs_pred, bs_obj);
}
} catch (final QueryEvaluationException e) {
throw new SailException(e);
}
}
@Override
public void remove() throws SailException {
try {
evaluate.remove();
} catch (final QueryEvaluationException e) {
throw new SailException(e);
}
}
};
// } catch (QueryEvaluationException e) {
// throw new SailException(e);
// }
}
use of org.eclipse.rdf4j.sail.SailException in project incubator-rya by apache.
the class RdfCloudTripleStoreConnection method clearInternal.
@Override
protected void clearInternal(final Resource... aresource) throws SailException {
try {
final RyaIRI[] graphs = new RyaIRI[aresource.length];
for (int i = 0; i < graphs.length; i++) {
graphs[i] = RdfToRyaConversions.convertResource(aresource[i]);
}
ryaDAO.dropGraph(conf, graphs);
} catch (final RyaDAOException e) {
throw new SailException(e);
}
}
use of org.eclipse.rdf4j.sail.SailException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method addStatement.
/**
* Adds the statement.
*
* @param subject the subject
* @param predicate the predicate
* @param object the object
* @param contexts the contexts
* @throws SailException the sail exception
*/
@Override
public void addStatement(Resource subject, IRI predicate, Value object, Resource... contexts) throws SailException {
try {
String[] predicateParts;
if (predicate != null) {
// predicateParts= predicate.stringValue().split(IntelligentGraphConstants.PATH_QL_REGEX);
predicateParts = decodePredicate(predicate);
switch(predicateParts[0]) {
case PATHQL.addFact:
addFact(subject, predicateParts[1], object, contexts);
break;
default:
super.addStatement(subject, predicate, object, contexts);
checkReificationsChanged(predicate);
}
} else
super.addStatement(subject, predicate, object, contexts);
this.intelligentGraphSail.clearCache();
} catch (Exception e) {
throw new SailException(e);
}
}
use of org.eclipse.rdf4j.sail.SailException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method removeStatement.
/**
* Removes the statement.
*
* @param modify the modify
* @param subj the subj
* @param pred the pred
* @param obj the obj
* @param contexts the contexts
* @throws SailException the sail exception
*/
@Override
public void removeStatement(UpdateContext modify, Resource subj, IRI pred, Value obj, Resource... contexts) throws SailException {
try {
String[] predicateParts;
if (pred != null) {
// predicateParts= pred.stringValue().split(IntelligentGraphConstants.PATH_QL_REGEX);
predicateParts = decodePredicate(pred);
switch(predicateParts[0]) {
case PATHQL.removeFact:
case PATHQL.removeFacts:
deleteFacts(modify, subj, predicateParts[1], obj, contexts);
break;
default:
super.removeStatement(modify, subj, pred, obj, contexts);
checkReificationsChanged(pred);
}
} else {
super.removeStatement(modify, subj, pred, obj, contexts);
}
} catch (Exception e) {
throw new SailException(e);
}
}
use of org.eclipse.rdf4j.sail.SailException in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method removeStatements.
/**
* Removes the statements.
*
* @param subj the subj
* @param pred the pred
* @param obj the obj
* @param contexts the contexts
* @throws SailException the sail exception
*/
@Override
public void removeStatements(Resource subj, IRI pred, Value obj, Resource... contexts) throws SailException {
try {
String[] predicateParts;
if (pred != null) {
predicateParts = decodePredicate(pred);
switch(predicateParts[0]) {
case PATHQL.removeFact:
case PATHQL.removeFacts:
deleteFacts(null, subj, predicateParts[1], obj, contexts);
break;
default:
super.removeStatements(subj, pred, obj, contexts);
checkReificationsChanged(pred);
}
} else {
super.removeStatements(subj, pred, obj, contexts);
}
} catch (Exception e) {
throw new SailException(e);
}
}
Aggregations