Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

TDB, transactions and SELECT FROM or SELECT FROM NAMED

$
0
0
Using apache-jena-libs 2.11.2
I have the following code:

Dataset retval = TDBFactory.createDataset();
retval.begin(ReadWrite.WRITE);
// read <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl>
URL url = ReadTest.class.getResource("/MockRoadmap.ttl");
Model model = retval.getNamedModel(url.toString());
model.read(url.toString(), "TURTLE");
// <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl>
SelectBuilder sBuilder = RoadmapDataset
.setPrefixes(new SelectBuilder())
.addPrefix( "xsd", "http://www.w3.org/2001/XMLSchema#")
.addPrefix( "epm", EndpointMonitor.NAMESPACE )
//.from("file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl")
.addGraph( "?g", new SelectBuilder()
.addWhere("?s", "void:sparqlEndpoint", "?e")

// print the query
System.out.println( sBuilder.build() );
QueryExecution qe2 = QueryExecutionFactory.create(
QueryFactory.create(sBuilder.build()), retval);
ResultSet rs = qe2.execSelect();
while (rs.hasNext())

QuerySolution qs = rs.next();
System.out.println( "result="+qs );

the query it produces is
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX voidext: <http://rdfs.org/ns/void-ext#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX void: <http://rdfs.org/ns/void#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX epm: <http://localhost/endpointMonitor#>
SELECT *
WHERE {
GRAPH ?g {
?s void:sparqlEndpoint ?e .

producing:

result=( ?e = <http://localhost/master/sparql> ) ( ?g =
<file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl> ) ( ?s
= <http://localhost/master> )
result=( ?e = <http://localhost:8083/slave1/sparql> ) ( ?g =
<file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl> ) ( ?s
= <http://localhost:8083/slave1> )
result=( ?e = <http://localhost:8083/slave2/sparql> ) ( ?g =
<file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl> ) ( ?s
= <http://localhost:8083/slave2> )

If I modify the query builder to produce

PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX voidext: <http://rdfs.org/ns/void-ext#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX void: <http://rdfs.org/ns/void#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX epm: <http://localhost/endpointMonitor#>
SELECT *
FROM <file:/home/claude/git/roadmap/target/test-classes/MockRoadmap.ttl>
WHERE {
GRAPH ?g {
?s void:sparqlEndpoint ?e .

I get no output

if I change FROM to FROM NAMED I get no output

if I change the WHERE clause to
WHERE {
?s void:sparqlEndpoint ?e .

with FROM or FROM NAMED or no FROM statement at I get not output.

I am looking for something that will produce the results from the first
query without looking at all the named graphs. Is there a way to do that?
I thought that FROM NAMED would limit the named graphs to query but it
seems to exclude the one I want.
I thought that FROM would make the named graph the default graph but that
doesn't seem to work either.

Any help would be appreciated.

Viewing all articles
Browse latest Browse all 5648

Trending Articles