final Model model = data0.getNamedModel( MY_NS );
out.println("Model := "+model);
out.println("getting graph...");
/// this is the DATA in that MODEL
final Graph graph = model.getGraph();
out.println("Graph := "+graph);
if (graph.isEmpty()) {
final Resource product1 = model.createResource(
iriFactory.construct( MY_NS +"product/1" )
.toString() );
final Property hasName = model.createProperty( MY_NS, "#hasName");
final Statement stmt = model.createStatement(
product1, hasName, model.createLiteral("Beach Ball","en") );
out.println("Statement = " + stmt);
model.add(stmt);
// just for fun
out.println("Triple := " + stmt.asTriple().toString());
} else {
out.println("Graph is not Empty; it has "+graph.size()+" Statements");
long t0, t1;
t0 = System.currentTimeMillis();
final Query q = QueryFactory.create(
"PREFIX exns: <"+MY_NS+"#>\n"+
"PREFIX exprod: <"+MY_NS+"product/>\n"+
" SELECT * "
// if you don't provide the Model to the
// QueryExecutionFactory below, then you'll need
// to specify the FROM;
// you *can* always specify it, if you want
// +" FROM <"+MY_NS+">\n"
// +" WHERE { ?node <"+MY_NS+"#hasName> ?name }"
// +" WHERE { ?node exns:hasName ?name }"
// +" WHERE { exprod:1 exns:hasName ?name }"
+" WHERE { ?res ?pred ?obj }"
);
out.println("Query := "+q);
t1 = System.currentTimeMillis();
out.println("QueryFactory.TIME="+(t1 - t0));
t0 = System.currentTimeMillis();
final QueryExecution qExec = QueryExecutionFactory
// if you query the whole DataSet,
// you have to provide a FROM in the SparQL
//.create(q, data0);
.create(q, model);
t1 = System.currentTimeMillis();
out.println("QueryExecutionFactory.TIME="+(t1 - t0));
try {
t0 = System.currentTimeMillis();
ResultSet rs = qExec.execSelect();
t1 = System.currentTimeMillis();
out.println("executeSelect.TIME="+(t1 - t0));
while (rs.hasNext()) {
QuerySolution sol = rs.next();
out.println("Solution := "+sol);
for (Iterator<String> names = sol.varNames(); names.hasNext(); ) {
final String name = names.next();
out.println("\t"+name+" := "+sol.get(name));
}
}
} finally {
qExec.close();
}
}
out.println("closing graph");
graph.close();
out.println("closing model");
model.close();
//out.println("closing DataSetGraph");
//dsg.close();
out.println("closing DataSet");