use of org.apache.jena.query.QuerySolution in project jena by apache.
the class FusekiConfig method servicesAndDatasets.
private static List<DataAccessPoint> servicesAndDatasets(Model model) {
// Old style configuration file : server to services.
DatasetDescriptionRegistry dsDescMap = FusekiServer.registryForBuild();
// ---- Services
ResultSet rs = FusekiLib.query("SELECT * { ?s fu:services [ list:member ?service ] }", model);
List<DataAccessPoint> accessPoints = new ArrayList<>();
if (!rs.hasNext())
// No "fu:services ( .... )" so try looking for services directly.
// This means Fuseki2, service configuration files (no server section) work for --conf.
rs = FusekiLib.query("SELECT ?service { ?service a fu:Service }", model);
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
Resource svc = soln.getResource("service");
DataAccessPoint acc = FusekiBuilder.buildDataAccessPoint(svc, dsDescMap);
accessPoints.add(acc);
}
return accessPoints;
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class FusekiConfig method readSystemDatabase.
// ---- System database
/** Read the system database */
public static List<DataAccessPoint> readSystemDatabase(Dataset ds) {
DatasetDescriptionRegistry dsDescMap = FusekiServer.registryForBuild();
String qs = StrUtils.strjoinNL(SystemState.PREFIXES, "SELECT * {", " GRAPH ?g {", " ?s fu:name ?name ;", " fu:status ?status .", " }", "}");
List<DataAccessPoint> refs = new ArrayList<>();
ds.begin(ReadWrite.WRITE);
try {
ResultSet rs = FusekiLib.query(qs, ds);
for (; rs.hasNext(); ) {
QuerySolution row = rs.next();
Resource s = row.getResource("s");
Resource g = row.getResource("g");
Resource rStatus = row.getResource("status");
//String name = row.getLiteral("name").getLexicalForm() ;
DatasetStatus status = DatasetStatus.status(rStatus);
Model m = ds.getNamedModel(g.getURI());
// Rebase the resource of the service description to the containing graph.
Resource svc = m.wrapAsResource(s.asNode());
DataAccessPoint ref = FusekiBuilder.buildDataAccessPoint(svc, dsDescMap);
refs.add(ref);
}
ds.commit();
return refs;
} finally {
ds.end();
}
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class FusekiBuilder method addServiceEP.
private static void addServiceEP(DataService dataService, OperationName opName, Resource svc, Property property) {
String p = "<" + property.getURI() + ">";
ResultSet rs = query("SELECT * { ?svc " + p + " ?ep}", svc.getModel(), "svc", svc);
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
String epName = soln.getLiteral("ep").getLexicalForm();
Endpoint operation = new Endpoint(opName, epName);
addServiceEP(dataService, opName, epName);
//log.info(" " + opName.name + " = " + dataAccessPoint.getName() + "/" + epName) ;
}
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class TextOutput method colWidths.
private int[] colWidths(ResultSetRewindable rs) {
int numCols = rs.getResultVars().size();
int numRows = 0;
int[] colWidths = new int[numCols];
// Widths at least that of the variable name. Assumes we will print col headings.
for (int i = 0; i < numCols; i++) colWidths[i] = (rs.getResultVars().get(i)).length();
// Preparation pass : find the maximum width for each column
for (; rs.hasNext(); ) {
numRows++;
QuerySolution rBind = rs.nextSolution();
int col = -1;
for (String s1 : rs.getResultVars()) {
col++;
String rVar = s1;
String s = getVarValueAsString(rBind, rVar);
if (colWidths[col] < s.length()) {
colWidths[col] = s.length();
}
}
}
rs.reset();
return colWidths;
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class RDFOutput method asRDF.
public Resource asRDF(Model model, ResultSet resultSet, boolean includeRowIndex) {
Resource results = model.createResource();
// This always goes in.
results.addProperty(RDF.type, ResultSetGraphVocab.ResultSet);
for (String vName : resultSet.getResultVars()) results.addProperty(ResultSetGraphVocab.resultVariable, vName);
int count = 0;
for (; resultSet.hasNext(); ) {
count++;
QuerySolution rBind = resultSet.nextSolution();
Resource thisSolution = model.createResource();
if (includeTypeProperties)
thisSolution.addProperty(RDF.type, ResultSetGraphVocab.ResultSolution);
results.addProperty(ResultSetGraphVocab.solution, thisSolution);
if (includeRowIndex) {
// This can lead to equivalent result sets having different graphs
// Best used if and only if query was completely sorted.
Literal x = model.createTypedLiteral(count + "", XSDDatatype.XSDinteger);
thisSolution.addLiteral(ResultSetGraphVocab.index, x);
}
Iterator<String> iter = getAllVars() ? rBind.varNames() : resultSet.getResultVars().iterator();
for (; iter.hasNext(); ) {
Resource thisBinding = model.createResource();
String rVar = iter.next();
RDFNode n = rBind.get(rVar);
if (n == null)
continue;
// }
if (includeTypeProperties)
thisBinding.addProperty(RDF.type, ResultSetGraphVocab.ResultBinding);
thisBinding.addProperty(ResultSetGraphVocab.variable, rVar);
thisBinding.addProperty(ResultSetGraphVocab.value, n);
thisSolution.addProperty(ResultSetGraphVocab.binding, thisBinding);
}
}
results.addProperty(ResultSetGraphVocab.size, model.createTypedLiteral(count));
addPrefixes(model);
return results;
}
Aggregations