use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class SPARQLConnection method getStatementsQuadMode.
private RepositoryResult<Statement> getStatementsQuadMode(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws MalformedQueryException, RepositoryException, QueryEvaluationException {
TupleQueryResult qRes = null;
RepositoryResult<Statement> result = null;
boolean allGood = false;
try {
TupleQuery tupleQuery = prepareTupleQuery(SPARQL, EVERYTHING_WITH_GRAPH);
setBindings(tupleQuery, subj, pred, obj, contexts);
tupleQuery.setIncludeInferred(includeInferred);
qRes = tupleQuery.evaluate();
result = new RepositoryResult<Statement>(new ExceptionConvertingIteration<Statement, RepositoryException>(toStatementIteration(qRes, subj, pred, obj)) {
@Override
protected RepositoryException convert(Exception e) {
return new RepositoryException(e);
}
});
allGood = true;
return result;
} finally {
if (!allGood) {
try {
if (result != null) {
result.close();
}
} finally {
if (qRes != null) {
qRes.close();
}
}
}
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class SPARQLConnection method getStatementsSingleTriple.
private RepositoryResult<Statement> getStatementsSingleTriple(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException {
if (hasStatement(subj, pred, obj, includeInferred, contexts)) {
Statement st = getValueFactory().createStatement(subj, pred, obj);
CloseableIteration<Statement, RepositoryException> cursor;
cursor = new SingletonIteration<Statement, RepositoryException>(st);
return new RepositoryResult<Statement>(cursor);
} else {
return new RepositoryResult<Statement>(new EmptyIteration<Statement, RepositoryException>());
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class RepositoryConfigUtil method getRepositoryIDs.
@Deprecated
public static Set<String> getRepositoryIDs(Repository repository) throws RepositoryException {
RepositoryConnection con = repository.getConnection();
try {
Set<String> idSet = new LinkedHashSet<String>();
RepositoryResult<Statement> idStatementIter = con.getStatements(null, REPOSITORYID, null, true);
try {
while (idStatementIter.hasNext()) {
Statement idStatement = idStatementIter.next();
if (idStatement.getObject() instanceof Literal) {
Literal idLiteral = (Literal) idStatement.getObject();
idSet.add(idLiteral.getLabel());
}
}
} finally {
idStatementIter.close();
}
return idSet;
} finally {
con.close();
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class RepositoryConfigUtil method getIDStatement.
private static Statement getIDStatement(RepositoryConnection con, String repositoryID) throws RepositoryException, RepositoryConfigException {
Literal idLiteral = con.getRepository().getValueFactory().createLiteral(repositoryID);
List<Statement> idStatementList = Iterations.asList(con.getStatements(null, REPOSITORYID, idLiteral, true));
if (idStatementList.size() == 1) {
return idStatementList.get(0);
} else if (idStatementList.isEmpty()) {
return null;
} else {
throw new RepositoryConfigException("Multiple ID-statements for repository ID " + repositoryID);
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class RepositoryConfigUtil method getRepositoryConfig.
@Deprecated
public static RepositoryConfig getRepositoryConfig(Repository repository, String repositoryID) throws RepositoryConfigException, RepositoryException {
RepositoryConnection con = repository.getConnection();
try {
Statement idStatement = getIDStatement(con, repositoryID);
if (idStatement == null) {
// No such config
return null;
}
Resource repositoryNode = idStatement.getSubject();
Resource context = idStatement.getContext();
if (context == null) {
throw new RepositoryException("No configuration context for repository " + repositoryID);
}
Model contextGraph = QueryResults.asModel(con.getStatements(null, null, null, true, context));
return RepositoryConfig.create(contextGraph, repositoryNode);
} finally {
con.close();
}
}
Aggregations