use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class SPARQLConnection method createDeleteDataCommand.
private String createDeleteDataCommand(Iterable<? extends Statement> statements, Resource... contexts) {
StringBuilder qb = new StringBuilder();
qb.append("DELETE DATA \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");
}
createDataBody(qb, statements, true);
if (context != null) {
qb.append(" } \n");
}
}
} else {
createDataBody(qb, statements, false);
}
qb.append("}");
return qb.toString();
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class SPARQLConnection method setBindings.
/* protected/private methods */
private void setBindings(Query query, Resource subj, IRI pred, Value obj, Resource... contexts) throws RepositoryException {
if (subj != null) {
query.setBinding("s", subj);
}
if (pred != null) {
query.setBinding("p", pred);
}
if (obj != null) {
query.setBinding("o", obj);
}
if (contexts != null && contexts.length > 0) {
SimpleDataset dataset = new SimpleDataset();
for (Resource ctx : contexts) {
if (ctx == null || ctx instanceof IRI) {
dataset.addDefaultGraph((IRI) ctx);
} else {
throw new RepositoryException("Contexts must be URIs");
}
}
query.setDataset(dataset);
}
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class SPARQLRepositoryConfig method export.
@Override
public Resource export(Model m) {
Resource implNode = super.export(m);
m.setNamespace("sparql", NAMESPACE);
if (getQueryEndpointUrl() != null) {
m.add(implNode, QUERY_ENDPOINT, vf.createIRI(getQueryEndpointUrl()));
}
if (getUpdateEndpointUrl() != null) {
m.add(implNode, UPDATE_ENDPOINT, vf.createIRI(getUpdateEndpointUrl()));
}
return implNode;
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class HTTPRepositoryConfig method export.
@Override
public Resource export(Model graph) {
Resource implNode = super.export(graph);
if (url != null) {
graph.setNamespace("http", NAMESPACE);
graph.add(implNode, REPOSITORYURL, SimpleValueFactory.getInstance().createIRI(url));
}
return implNode;
}
use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.
the class RemoteRepositoryManager method addRepositoryConfig.
@Override
public void addRepositoryConfig(RepositoryConfig config) throws RepositoryException, RepositoryConfigException {
try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
String baseURI = Protocol.getRepositoryLocation(serverURL, config.getID());
Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + config.getID());
httpClient.setUsernameAndPassword(username, password);
httpClient.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
Model model = new LinkedHashModel();
config.export(model, ctx);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Rio.write(model, baos, httpClient.getPreferredRDFFormat());
removeRepository(config.getID());
try (InputStream contents = new ByteArrayInputStream(baos.toByteArray())) {
httpClient.upload(contents, baseURI, httpClient.getPreferredRDFFormat(), false, true, ctx);
}
} catch (IOException | QueryEvaluationException | UnauthorizedException ue) {
throw new RepositoryException(ue);
}
}
Aggregations