This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit 95f582869f9f7d3767bf8dd4f22a03586ef421d1 Author: Andy Seaborne <[email protected]> AuthorDate: Sun Apr 5 20:09:33 2026 +0100 Avoid deprecated constructor --- .../src/main/java/arq/examples/ExProg1.java | 44 +++++++++++----------- .../src/main/java/arq/examples/ExProg2.java | 2 +- .../src/main/java/arq/examples/ExQuerySelect1.java | 32 ++++++++-------- .../src/main/java/arq/examples/ExQuerySelect2.java | 36 +++++++++--------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/jena-examples/src/main/java/arq/examples/ExProg1.java b/jena-examples/src/main/java/arq/examples/ExProg1.java index 40cf815116..7e1084e00b 100644 --- a/jena-examples/src/main/java/arq/examples/ExProg1.java +++ b/jena-examples/src/main/java/arq/examples/ExProg1.java @@ -32,62 +32,62 @@ import org.apache.jena.sparql.syntax.ElementGroup ; import org.apache.jena.vocabulary.DC ; /** Example : Build a query syntax programmatically. - * + * * Note: it is often better to build and execute an algebra expression. See other examples. */ public class ExProg1 { - static public final String NL = System.getProperty("line.separator") ; - + static public final String NL = System.getProperty("line.separator") ; + public static void main(String[] args) { Model model = createModel() ; - + Query query = QueryFactory.make() ; query.setQuerySelectType() ; - + // Build pattern - + ElementGroup elg = new ElementGroup() ; - + Var varTitle = Var.alloc("title") ; Var varX = Var.alloc("x") ; - + Triple t1 = Triple.create(varX, DC.title.asNode(), varTitle) ; elg.addTriplePattern(t1) ; - + // Don't use bNodes for anon variables. The conversion is done in parsing. // BNodes here are assumed to be values from the target graph. Triple t2 = Triple.create(varX, DC.description.asNode(), Var.alloc("desc")) ; elg.addTriplePattern(t2) ; - - // Attach the group to query. + + // Attach the group to query. query.setQueryPattern(elg) ; // Choose what we want - SELECT * //query.setQueryResultStar(true) ; query.addResultVar(varTitle) ; - + // Print query with line numbers // Prefix mapping just helps serialization query.getPrefixMapping().setNsPrefix("dc" , DC.getURI()) ; - query.serialize(new IndentedWriter(System.out,true)) ; + query.serialize(IndentedWriter.stdout.clone().setLineNumbers(true)) ; System.out.println() ; - + try ( QueryExecution qexec = QueryExecutionFactory.create(query, model) ) { // Assumption: it's a SELECT query. ResultSet rs = qexec.execSelect() ; - + // The order of results is undefined. System.out.println("Titles: ") ; for ( ; rs.hasNext() ; ) { QuerySolution rb = rs.nextSolution() ; - + // Get title - variable names do not include the '?' (or '$') RDFNode x = rb.get("title") ; - + // Check the type of the result value if ( x instanceof Literal ) { @@ -96,22 +96,22 @@ public class ExProg1 } else System.out.println("Strange - not a literal: "+x) ; - + } } } - + public static Model createModel() { Model model = ModelFactory.createDefaultModel() ; - + Resource r1 = model.createResource("http://example.org/book#1") ; Resource r2 = model.createResource("http://example.org/book#2") ; Resource r3 = model.createResource("http://example.org/book#3") ; - + r1.addProperty(DC.title, "SPARQL - the book") .addProperty(DC.description, "A book about SPARQL") ; - + r2.addProperty(DC.title, "Advanced techniques for SPARQL") ; r3.addProperty(DC.title, "Jena - an RDF framework for Java") diff --git a/jena-examples/src/main/java/arq/examples/ExProg2.java b/jena-examples/src/main/java/arq/examples/ExProg2.java index fbbbbebb86..81402a8a07 100644 --- a/jena-examples/src/main/java/arq/examples/ExProg2.java +++ b/jena-examples/src/main/java/arq/examples/ExProg2.java @@ -72,7 +72,7 @@ public class ExProg2 // Print query with line numbers // Prefix mapping just helps serialization query.getPrefixMapping().setNsPrefix("dc", DC.getURI()); - query.serialize(new IndentedWriter(System.out, true)); + query.serialize(IndentedWriter.stdout.clone().setLineNumbers(true)) ; System.out.println(); try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) { diff --git a/jena-examples/src/main/java/arq/examples/ExQuerySelect1.java b/jena-examples/src/main/java/arq/examples/ExQuerySelect1.java index fa5c30e4d9..1fd6b1cea2 100644 --- a/jena-examples/src/main/java/arq/examples/ExQuerySelect1.java +++ b/jena-examples/src/main/java/arq/examples/ExQuerySelect1.java @@ -33,29 +33,29 @@ import org.apache.jena.vocabulary.DC ; public class ExQuerySelect1 { - static public final String NL = System.getProperty("line.separator") ; - + static public final String NL = System.getProperty("line.separator") ; + public static void main(String[] args) { // Create the data. // This wil be the background (unnamed) graph in the dataset. Model model = createModel() ; - - // First part or the query string + + // First part or the query string String prolog = "PREFIX dc: <"+DC.getURI()+">" ; - + // Query string. String queryString = prolog + NL + - "SELECT ?title WHERE {?x dc:title ?title}" ; - + "SELECT ?title WHERE {?x dc:title ?title}" ; + Query query = QueryFactory.create(queryString) ; // Print with line numbers - query.serialize(new IndentedWriter(System.out,true)) ; + query.serialize(IndentedWriter.stdout.clone().setLineNumbers(true)) ; System.out.println() ; - + // Create a single execution of this query, apply to a model // which is wrapped up as a Dataset - + try(QueryExecution qexec = QueryExecutionFactory.create(query, model)){ // Or QueryExecutionFactory.create(queryString, model) ; @@ -64,7 +64,7 @@ public class ExQuerySelect1 // Assumption: it's a SELECT query. ResultSet rs = qexec.execSelect() ; - // The order of results is undefined. + // The order of results is undefined. for ( ; rs.hasNext() ; ) { QuerySolution rb = rs.nextSolution() ; @@ -84,19 +84,19 @@ public class ExQuerySelect1 } } } - + public static Model createModel() { Model m = ModelFactory.createDefaultModel() ; - + Resource r1 = m.createResource("http://example.org/book#1") ; Resource r2 = m.createResource("http://example.org/book#2") ; - + r1.addProperty(DC.title, "SPARQL - the book") .addProperty(DC.description, "A book about SPARQL") ; - + r2.addProperty(DC.title, "Advanced techniques for SPARQL") ; - + return m ; } } diff --git a/jena-examples/src/main/java/arq/examples/ExQuerySelect2.java b/jena-examples/src/main/java/arq/examples/ExQuerySelect2.java index f0cbb76bcf..2d55dad73b 100644 --- a/jena-examples/src/main/java/arq/examples/ExQuerySelect2.java +++ b/jena-examples/src/main/java/arq/examples/ExQuerySelect2.java @@ -31,60 +31,60 @@ import org.apache.jena.rdf.model.Resource ; import org.apache.jena.vocabulary.DC ; /** Example 2 : Execute a simple SELECT query on a model - * to find the DC titles contained in a model. + * to find the DC titles contained in a model. * Show how to print results twice. */ public class ExQuerySelect2 { - static public final String NL = System.getProperty("line.separator") ; - + static public final String NL = System.getProperty("line.separator") ; + public static void main(String[] args) { // Create the data. // This wil be the background (unnamed) graph in the dataset. Model model = createModel() ; - - // First part or the query string + + // First part or the query string String prolog = "PREFIX dc: <"+DC.getURI()+">" ; - + // Query string. String queryString = prolog + NL + - "SELECT ?title WHERE {?x dc:title ?title}" ; - + "SELECT ?title WHERE {?x dc:title ?title}" ; + Query query = QueryFactory.create(queryString) ; // Print with line numbers - query.serialize(new IndentedWriter(System.out,true)) ; + query.serialize(IndentedWriter.stdout.clone().setLineNumbers(true)) ; System.out.println() ; - + // Create a single execution of this query, apply to a model // which is wrapped up as a Dataset - - // Or QueryExecutionFactory.create(queryString, model) ; + + // Or QueryExecutionFactory.create(queryString, model) ; try(QueryExecution qexec = QueryExecutionFactory.create(query, model)) { // A ResultSet is an iterator - any query solutions returned by .next() // are not accessible again. // Create a ResultSetRewindable that can be reset to the beginning. // Do before first use. - + ResultSetRewindable rewindable = qexec.execSelect().rewindable(); ResultSetFormatter.out(rewindable) ; rewindable.reset() ; ResultSetFormatter.out(rewindable) ; } } - + public static Model createModel() { Model m = ModelFactory.createDefaultModel() ; - + Resource r1 = m.createResource("http://example.org/book#1") ; Resource r2 = m.createResource("http://example.org/book#2") ; - + r1.addProperty(DC.title, "SPARQL - the book") .addProperty(DC.description, "A book about SPARQL") ; - + r2.addProperty(DC.title, "Advanced techniques for SPARQL") ; - + return m ; } }
