use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class SPARQLUpdateOperation method execute.
public void execute(RepositoryConnection con) throws RepositoryException {
try {
Update preparedUpdate = con.prepareUpdate(QueryLanguage.SPARQL, getUpdateString(), getBaseURI());
preparedUpdate.setIncludeInferred(isIncludeInferred());
preparedUpdate.setDataset(getDataset());
if (getBindings() != null) {
for (Binding binding : getBindings()) {
preparedUpdate.setBinding(binding.getName(), binding.getValue());
}
}
preparedUpdate.execute();
} catch (MalformedQueryException e) {
throw new RepositoryException(e);
} catch (UpdateExecutionException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class HTTPUpdate method execute.
@Override
public void execute() throws UpdateExecutionException {
try {
if (httpCon.getRepository().useCompatibleMode()) {
if (httpCon.isAutoCommit()) {
// execute update immediately
SPARQLProtocolSession client = getHttpClient();
try {
client.sendUpdate(getQueryLanguage(), getQueryString(), getBaseURI(), dataset, includeInferred, getMaxExecutionTime(), getBindingsArray());
} catch (UnauthorizedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (QueryInterruptedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (MalformedQueryException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (IOException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
}
} else {
// defer execution as part of transaction.
httpCon.scheduleUpdate(this);
}
return;
}
SPARQLProtocolSession client = getHttpClient();
try {
httpCon.flushTransactionState(Action.UPDATE);
client.sendUpdate(getQueryLanguage(), getQueryString(), getBaseURI(), dataset, includeInferred, getMaxExecutionTime(), getBindingsArray());
} catch (UnauthorizedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (QueryInterruptedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (MalformedQueryException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (IOException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
}
} catch (RepositoryException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class SPARQLConnection method clear.
public void clear(Resource... contexts) throws RepositoryException {
OpenRDFUtil.verifyContextNotNull(contexts);
boolean localTransaction = startLocalTransaction();
if (contexts.length == 0) {
sparqlTransaction.append("CLEAR ALL ");
sparqlTransaction.append("; ");
} else {
for (Resource context : contexts) {
if (context == null) {
sparqlTransaction.append("CLEAR DEFAULT ");
sparqlTransaction.append("; ");
} else if (context instanceof IRI) {
sparqlTransaction.append("CLEAR GRAPH <" + context.stringValue() + "> ");
sparqlTransaction.append("; ");
} else {
throw new RepositoryException("SPARQL does not support named graphs identified by blank nodes.");
}
}
}
try {
conditionalCommit(localTransaction);
} catch (RepositoryException e) {
conditionalRollback(localTransaction);
throw e;
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class SPARQLConnection method exportStatements.
public void exportStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException {
try {
GraphQuery query = prepareGraphQuery(SPARQL, EVERYTHING, "");
setBindings(query, subj, pred, obj, contexts);
query.evaluate(handler);
} catch (MalformedQueryException e) {
throw new RepositoryException(e);
} catch (QueryEvaluationException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.repository.RepositoryException 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);
}
}
Aggregations