use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class SPARQLConnection method createDeletePatternCommand.
private String createDeletePatternCommand(Resource subject, IRI predicate, Value object, Resource[] contexts) {
StringBuilder qb = new StringBuilder();
qb.append("DELETE WHERE \n");
qb.append("{ \n");
if (contexts.length > 0) {
for (Resource context : contexts) {
if (context != null) {
String namedGraph = context.stringValue();
if (context instanceof BNode) {
// SPARQL does not allow blank nodes as named graph
// identifiers, so we need to skolemize
// the blank node id.
namedGraph = "urn:nodeid:" + context.stringValue();
}
qb.append(" GRAPH <" + namedGraph + "> { \n");
}
createBGP(qb, subject, predicate, object);
if (context != null && context instanceof IRI) {
qb.append(" } \n");
}
}
} else {
createBGP(qb, subject, predicate, object);
}
qb.append("}");
return qb.toString();
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class SPARQLConnection method toStatementIteration.
/**
* Converts a {@link TupleQueryResult} resulting from the {@link #EVERYTHING_WITH_GRAPH} to a statement by
* using the respective values from the {@link BindingSet} or (if provided) the ones from the arguments.
*
* @param iter
* the {@link TupleQueryResult}
* @param subj
* the subject {@link Resource} used as input or <code>null</code> if wildcard was used
* @param pred
* the predicate {@link IRI} used as input or <code>null</code> if wildcard was used
* @param obj
* the object {@link Value} used as input or <code>null</code> if wildcard was used
* @return the converted iteration
*/
protected Iteration<Statement, QueryEvaluationException> toStatementIteration(TupleQueryResult iter, final Resource subj, final IRI pred, final Value obj) {
return new ConvertingIteration<BindingSet, Statement, QueryEvaluationException>(iter) {
@Override
protected Statement convert(BindingSet b) throws QueryEvaluationException {
Resource s = subj == null ? (Resource) b.getValue("s") : subj;
IRI p = pred == null ? (IRI) b.getValue("p") : pred;
Value o = obj == null ? b.getValue("o") : obj;
Resource ctx = (Resource) b.getValue("ctx");
return SimpleValueFactory.getInstance().createStatement(s, p, o, ctx);
}
};
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class SPARQLConnection method getContextIDs.
public RepositoryResult<Resource> getContextIDs() throws RepositoryException {
TupleQueryResult iter = null;
RepositoryResult<Resource> result = null;
boolean allGood = false;
try {
TupleQuery query = prepareTupleQuery(SPARQL, NAMEDGRAPHS, "");
iter = query.evaluate();
result = new RepositoryResult<Resource>(new ExceptionConvertingIteration<Resource, RepositoryException>(new ConvertingIteration<BindingSet, Resource, QueryEvaluationException>(iter) {
@Override
protected Resource convert(BindingSet bindings) throws QueryEvaluationException {
return (Resource) bindings.getValue("_");
}
}) {
@Override
protected RepositoryException convert(Exception e) {
return new RepositoryException(e);
}
});
allGood = true;
return result;
} catch (MalformedQueryException e) {
throw new RepositoryException(e);
} catch (QueryEvaluationException e) {
throw new RepositoryException(e);
} finally {
if (!allGood) {
try {
if (result != null) {
result.close();
}
} finally {
if (iter != null) {
iter.close();
}
}
}
}
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class NotifyingTest method testRemove.
@Test
public void testRemove() throws Exception {
ValueFactory vf = SimpleValueFactory.getInstance();
final IRI uri = vf.createIRI("http://example.com/");
final RepositoryConnection stub = new RepositoryConnectionStub() {
protected void removeWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
}
};
Repository repo = stub.getRepository();
NotifyingRepositoryConnection con = new NotifyingRepositoryConnectionWrapper(repo, stub);
con.addRepositoryConnectionListener(new RepositoryConnectionListenerAdapter() {
public void remove(RepositoryConnection conn, Resource subject, IRI predicate, Value object, Resource... contexts) {
assertEquals(stub, conn);
assertEquals(uri, subject);
assertEquals(uri, predicate);
assertEquals(uri, object);
assertEquals(0, contexts.length);
}
});
con.remove(con.getValueFactory().createStatement(uri, uri, uri));
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class InterceptorTest method testRemove.
@Test
public void testRemove() throws Exception {
ValueFactory vf = SimpleValueFactory.getInstance();
final IRI uri = vf.createIRI("http://example.com/");
final RepositoryConnection stub = new RepositoryConnectionStub() {
protected void removeWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
fail();
}
};
Repository repo = stub.getRepository();
InterceptingRepositoryConnection con = new InterceptingRepositoryConnectionWrapper(repo, stub);
con.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() {
public boolean remove(RepositoryConnection conn, Resource subject, IRI predicate, Value object, Resource... contexts) {
assertEquals(stub, conn);
assertEquals(uri, subject);
assertEquals(uri, predicate);
assertEquals(uri, object);
assertEquals(0, contexts.length);
return true;
}
});
con.remove(con.getValueFactory().createStatement(uri, uri, uri));
}
Aggregations