You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2025/05/29 12:50:12 UTC
(jena) 02/03: Convert examples from TDB1 to TDB2
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 d89481d42e3c183201355ea5c7618aba31acd401
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri May 23 08:40:20 2025 +0100
Convert examples from TDB1 to TDB2
---
.../src/main/java/tdb1/examples/ExTDB6.java | 127 --------------------
.../java/{tdb1 => tdb2}/examples/ExQuadFilter.java | 42 +++----
.../main/java/{tdb1 => tdb2}/examples/ExTDB1.java | 18 +--
.../main/java/{tdb1 => tdb2}/examples/ExTDB2.java | 14 +--
.../main/java/{tdb1 => tdb2}/examples/ExTDB3.java | 6 +-
.../main/java/{tdb1 => tdb2}/examples/ExTDB4.java | 22 ++--
.../main/java/{tdb1 => tdb2}/examples/ExTDB5.java | 31 ++---
.../src/main/java/tdb2/examples/ExTDB6.java | 132 +++++++++++++++++++++
.../java/{tdb1 => tdb2}/examples/ExTDB_Txn1.java | 14 +--
.../java/{tdb1 => tdb2}/examples/ExTDB_Txn2.java | 8 +-
.../java/{tdb1 => tdb2}/examples/ExTDB_Txn3.java | 14 +--
11 files changed, 211 insertions(+), 217 deletions(-)
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB6.java b/jena-examples/src/main/java/tdb1/examples/ExTDB6.java
deleted file mode 100644
index d715c3a1b7..0000000000
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB6.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tdb1.examples;
-
-import static java.lang.System.out ;
-
-import java.util.Iterator ;
-
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.query.* ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.Property ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.rdf.model.Statement ;
-import org.apache.jena.tdb1.TDB1;
-import org.apache.jena.tdb1.TDB1Factory;
-
-/** Example of single threaded use of TDB working with the Jena RDF API */
-public class ExTDB6
-{
- public static final String MY_NS =
- "x-ns://example.org/ns1/";
-
- public static void main(String[] args) throws Exception {
- /// turn off the "No BGP optimizer warning"
- TDB1.setOptimizerWarningFlag(false);
-
- final String DATASET_DIR_NAME = "data0";
- final Dataset data0 = TDB1Factory.createDataset( DATASET_DIR_NAME );
-
- // show the currently registered names
- for (Iterator<String> it = data0.listNames(); it.hasNext(); ) {
- out.println("NAME="+it.next());
- }
-
- out.println("getting named model...");
- /// this is the OWL portion
- 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( MY_NS +"product/1");
- 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();
- try ( 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));
-
- 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));
- }
- }
- }
- }
- out.println("closing graph");
- graph.close();
- out.println("closing model");
- model.close();
- //out.println("closing DataSetGraph");
- //dsg.close();
- out.println("closing DataSet");
- data0.close();
- }
-}
diff --git a/jena-examples/src/main/java/tdb1/examples/ExQuadFilter.java b/jena-examples/src/main/java/tdb2/examples/ExQuadFilter.java
similarity index 88%
rename from jena-examples/src/main/java/tdb1/examples/ExQuadFilter.java
rename to jena-examples/src/main/java/tdb2/examples/ExQuadFilter.java
index 2fbd635896..eacb813adc 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExQuadFilter.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExQuadFilter.java
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
import java.util.function.Predicate;
@@ -26,16 +26,16 @@ import org.apache.jena.query.* ;
import org.apache.jena.sparql.core.DatasetGraph ;
import org.apache.jena.sparql.core.Quad ;
import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.tdb1.TDB1;
-import org.apache.jena.tdb1.TDB1Factory;
-import org.apache.jena.tdb1.store.NodeId;
-import org.apache.jena.tdb1.sys.SystemTDB;
-import org.apache.jena.tdb1.sys.TDBInternal;
+import org.apache.jena.tdb2.TDB2;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.tdb2.store.NodeId;
+import org.apache.jena.tdb2.sys.SystemTDB;
+import org.apache.jena.tdb2.sys.TDBInternal;
/** Example of how to filter quads as they are accessed at the lowest level.
- * Can be used to exclude data from specific graphs.
+ * Can be used to exclude data from specific graphs.
* This mechanism is not limited to graphs - it works for properties or anything
- * where the visibility of otherwise is determined by the elements of the quad.
+ * where the visibility of otherwise is determined by the elements of the quad.
* See <a href="http://jena.apache.org/documentation/tdb/quadfilter.html">QuadFiltering</a>
* for further details.
*/
@@ -47,17 +47,17 @@ public class ExQuadFilter
public static void main(String ... args)
{
// This also works for default union graph ....
- TDB1.getContext().setTrue(TDB1.symUnionDefaultGraph) ;
-
+ TDB2.getContext().setTrue(TDB2.symUnionDefaultGraph) ;
+
Dataset ds = setup() ;
Predicate<Tuple<NodeId>> filter = createFilter(ds) ;
example(ds, filter) ;
}
-
+
/** Example setup - in-memory dataset with two graphs, one triple in each */
private static Dataset setup()
{
- Dataset ds = TDB1Factory.createDataset() ;
+ Dataset ds = TDB2Factory.createDataset() ;
DatasetGraph dsg = ds.asDatasetGraph() ;
Quad q1 = SSE.parseQuad("(<http://example/g1> <http://example/s> <http://example/p> <http://example/o1>)") ;
Quad q2 = SSE.parseQuad("(<http://example/g2> <http://example/s> <http://example/p> <http://example/o2>)") ;
@@ -65,16 +65,16 @@ public class ExQuadFilter
dsg.add(q2) ;
return ds ;
}
-
+
/** Create a filter to exclude the graph http://example/g2 */
private static Predicate<Tuple<NodeId>> createFilter(Dataset ds)
{
- // Filtering operates at a very low level:
- // Need to know the internal identifier for the graph name.
+ // Filtering operates at a very low level:
+ // Need to know the internal identifier for the graph name.
final NodeId target = TDBInternal.getNodeId(ds, NodeFactory.createURI(graphToHide)) ;
System.out.println("Hide graph: "+graphToHide+" --> "+target) ;
-
+
// Filter for accept/reject as quad as being visible.
// Return true for "accept", false for "reject"
Predicate<Tuple<NodeId>> filter = item ->
@@ -90,10 +90,10 @@ public class ExQuadFilter
//System.out.println("Accept: "+item) ;
return true ;
} ;
-
+
return filter ;
- }
-
+ }
+
private static void example(Dataset ds, Predicate<Tuple<NodeId>> filter)
{
String[] x = {
@@ -102,13 +102,13 @@ public class ExQuadFilter
// This filter does not hide the graph itself, just the quads associated with the graph.
"SELECT * { GRAPH ?g {} }"
} ;
-
+
for ( String qs : x )
{
example(ds, qs, filter) ;
example(ds, qs, null) ;
}
-
+
}
private static void example(Dataset ds, String qs, Predicate<Tuple<NodeId>> filter)
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB1.java b/jena-examples/src/main/java/tdb2/examples/ExTDB1.java
similarity index 89%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB1.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB1.java
index aee4e7e63f..169a1ce3b1 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB1.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB1.java
@@ -16,19 +16,19 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
import org.apache.jena.query.Dataset ;
import org.apache.jena.rdf.model.Model;
-import org.apache.jena.tdb1.TDB1Factory;
+import org.apache.jena.tdb2.TDB2Factory;
/** Example of creating a TDB-backed model.
* The preferred way is to create a dataset then get the mode required from the dataset.
* The dataset can be used for SPARQL query and update
* but the Model (or Graph) can also be used.
- *
+ *
* All the Jena APIs work on the model.
- *
+ *
* Calling TDBFactory is the only place TDB-specific code is needed.
*/
@@ -38,13 +38,13 @@ public class ExTDB1
{
// Direct way: Make a TDB-back Jena model in the named directory.
String directory = "MyDatabases/DB1" ;
- Dataset ds = TDB1Factory.createDataset(directory) ;
+ Dataset ds = TDB2Factory.connectDataset(directory) ;
Model model = ds.getDefaultModel() ;
-
- // ... do work ...
-
+
+ // ... do work ... transactions required ...
+
// Close the dataset.
ds.close();
-
+
}
}
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB2.java b/jena-examples/src/main/java/tdb2/examples/ExTDB2.java
similarity index 86%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB2.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB2.java
index 52a6b8e48e..84c4ae98d6 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB2.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB2.java
@@ -16,16 +16,16 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
import org.apache.jena.query.Dataset ;
-import org.apache.jena.tdb1.TDB1Factory;
+import org.apache.jena.tdb2.TDB2Factory;
/**
* Using an assembler description (see wiki for details of the assembler format for TDB)
* This way, you can change the model being used without changing the code.
* The assembler file is a configuration file.
- * The same assembler description will work as part of a Joseki configuration file.
+ * The same assembler description will work as part of a Joseki configuration file.
*/
public class ExTDB2
@@ -34,10 +34,10 @@ public class ExTDB2
{
String assemblerFile = "Store/tdb-assembler.ttl" ;
- Dataset ds = TDB1Factory.assembleDataset(assemblerFile) ;
-
- // ... do work ...
-
+ Dataset ds = TDB2Factory.assembleDataset(assemblerFile) ;
+
+ // ... do work ... transactions required ...
+
ds.close() ;
}
}
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB3.java b/jena-examples/src/main/java/tdb2/examples/ExTDB3.java
similarity index 94%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB3.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB3.java
index c1e6f536cd..582a2ca549 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB3.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB3.java
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
import org.apache.jena.assembler.Assembler ;
import org.apache.jena.query.Dataset ;
@@ -27,7 +27,7 @@ import org.apache.jena.shared.JenaException ;
import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
import org.apache.jena.sparql.util.TypeNotUniqueException ;
import org.apache.jena.sparql.util.graph.GraphUtils ;
-import org.apache.jena.tdb1.assembler.VocabTDB1;
+import org.apache.jena.tdb2.assembler.VocabTDB2;
/**
* Examples of finding an assembler for a TDB model in a larger collection
@@ -53,7 +53,7 @@ public class ExTDB3
// Alternatively, look for the a single resource of the right type.
try {
// Find the required description - the file can contain descriptions of many different types.
- root = GraphUtils.findRootByType(spec, VocabTDB1.tDatasetTDB) ;
+ root = GraphUtils.findRootByType(spec, VocabTDB2.tDatasetTDB) ;
if ( root == null )
throw new JenaException("Failed to find a suitable root") ;
} catch (TypeNotUniqueException ex)
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB4.java b/jena-examples/src/main/java/tdb2/examples/ExTDB4.java
similarity index 79%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB4.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB4.java
index 4371105451..e01a9b8983 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB4.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB4.java
@@ -16,24 +16,18 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
-import org.apache.jena.query.Dataset ;
-import org.apache.jena.query.Query ;
-import org.apache.jena.query.QueryExecution ;
-import org.apache.jena.query.QueryExecutionFactory ;
-import org.apache.jena.query.QueryFactory ;
-import org.apache.jena.query.ResultSet ;
-import org.apache.jena.query.ResultSetFormatter ;
-import org.apache.jena.tdb1.TDB1Factory;
+import org.apache.jena.query.*;
+import org.apache.jena.tdb2.TDB2Factory;
/** Example of creating a TDB-backed model.
* The preferred way is to create a dataset then get the mode required from the dataset.
* The dataset can be used for SPARQL query and update
* but the Model (or Graph) can also be used.
- *
+ *
* All the Jena APIs work on the model.
- *
+ *
* Calling TDBFactory is the only place TDB-specific code is needed.
*/
@@ -43,12 +37,12 @@ public class ExTDB4
{
// Direct way: Make a TDB-back Jena model in the named directory.
String directory = "MyDatabases/DB1" ;
- Dataset dataset = TDB1Factory.createDataset(directory) ;
-
+ Dataset dataset = TDB2Factory.connectDataset(directory) ;
+
// Potentially expensive query.
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
// See http://incubator.apache.org/jena/documentation/query/app_api.html
-
+
Query query = QueryFactory.create(sparqlQueryString) ;
try ( QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ) {
ResultSet results = qexec.execSelect() ;
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB5.java b/jena-examples/src/main/java/tdb2/examples/ExTDB5.java
similarity index 64%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB5.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB5.java
index 4b94fa7cbc..9daf3c28b7 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB5.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB5.java
@@ -16,16 +16,10 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.query.Query;
-import org.apache.jena.query.QueryExecution;
-import org.apache.jena.query.QueryExecutionFactory;
-import org.apache.jena.query.QueryFactory;
-import org.apache.jena.query.QuerySolution;
-import org.apache.jena.query.ResultSet;
-import org.apache.jena.tdb1.TDB1Factory;
+import org.apache.jena.query.*;
+import org.apache.jena.tdb2.TDB2Factory;
/**
* Example of creating a TDB-backed model. The preferred way is to create a dataset
@@ -39,20 +33,21 @@ public class ExTDB5 {
public static void main(String...argv) {
// Direct way: Make a TDB-back Jena model in the named directory.
String directory = "MyDatabases/DB1";
- Dataset dataset = TDB1Factory.createDataset(directory);
+ Dataset dataset = TDB2Factory.connectDataset(directory);
// Potentially expensive query.
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }";
- // See http://incubator.apache.org/jena/documentation/query/app_api.html
Query query = QueryFactory.create(sparqlQueryString);
- try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
- ResultSet results = qexec.execSelect();
- for ( ; results.hasNext() ; ) {
- QuerySolution soln = results.nextSolution();
- int count = soln.getLiteral("count").getInt();
- System.out.println("count = " + count);
+ dataset.executeRead(()->{
+ try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
+ ResultSet results = qexec.execSelect();
+ for ( ; results.hasNext() ; ) {
+ QuerySolution soln = results.nextSolution();
+ int count = soln.getLiteral("count").getInt();
+ System.out.println("count = " + count);
+ }
}
- }
+ });
}
}
diff --git a/jena-examples/src/main/java/tdb2/examples/ExTDB6.java b/jena-examples/src/main/java/tdb2/examples/ExTDB6.java
new file mode 100644
index 0000000000..6fda2f5642
--- /dev/null
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB6.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tdb2.examples;
+
+import static java.lang.System.out ;
+
+import java.util.Iterator ;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.Property ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.riot.Lang;
+import org.apache.jena.riot.RDFWriter;
+import org.apache.jena.tdb2.TDB2Factory;
+
+/** Example of single threaded use of TDB working with the Jena RDF API */
+public class ExTDB6
+{
+ public static String MY_NS =
+ "x-ns://example.org/ns1/";
+
+ public static void main(String[] args) throws Exception {
+
+ // From an exisiing database...
+// String DATASET_DIR_NAME = "data0";
+// Dataset dataset = TDB2Factory.connectDataset( DATASET_DIR_NAME );
+
+ Dataset dataset = TDB2Factory.createDataset( );
+
+ // show the currently registered names
+ dataset.executeRead(()->{
+ for (Iterator<String> it = dataset.listNames(); it.hasNext(); ) {
+ out.println("NAME="+it.next());
+ }
+ });
+
+ out.println("getting named model...");
+ /// this is the OWL portion
+ Model model = dataset.getNamedModel( MY_NS );
+ dataset.executeRead(()-> {
+ out.println("Model: "+model.size()+" statements");
+ RDFWriter.source(model).lang(Lang.TTL).output(System.out);
+ });
+ out.println("getting graph...");
+ /// this is the DATA in that MODEL
+ Graph graph = model.getGraph();
+ dataset.executeRead(()-> {
+ out.println("Graph: "+model.size()+" triples");
+ RDFWriter.source(graph).lang(Lang.TTL).output(System.out);
+ });
+
+ dataset.executeWrite(()->{
+ if (graph.isEmpty()) {
+ Resource product1 = model.createResource( MY_NS +"product/1");
+ Property hasName = model.createProperty( MY_NS, "#hasName");
+ 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();
+ Query q = QueryFactory.create("""
+ PREFIX exns: <"+MY_NS+"#>
+ PREFIX exprod: <"+MY_NS+"product/>
+ 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+">
+
+ // 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();
+ try ( 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));
+
+ 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(); ) {
+ String name = names.next();
+ out.println("\t"+name+" := "+sol.get(name));
+ }
+ }
+ }
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB_Txn1.java b/jena-examples/src/main/java/tdb2/examples/ExTDB_Txn1.java
similarity index 93%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB_Txn1.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB_Txn1.java
index 6b1d88b4d2..3c9b0011de 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB_Txn1.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB_Txn1.java
@@ -16,11 +16,11 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
import org.apache.jena.query.*;
import org.apache.jena.system.Txn;
-import org.apache.jena.tdb1.TDB1Factory;
+import org.apache.jena.tdb2.TDB2Factory;
/**
* Example of a READ transaction.
@@ -31,12 +31,12 @@ public class ExTDB_Txn1
public static void main(String... argv)
{
String directory = "MyDatabases/DB1";
- Dataset dataset = TDB1Factory.createDataset(directory);
+ Dataset dataset = TDB2Factory.connectDataset(directory);
- // Start READ transaction.
+ // Start READ transaction.
// No updates or changes to the dataset are possible while this
// dataset is used for a read transaction.
- // An application can have other Datasets, in the same JVM,
+ // An application can have other Datasets, in the same JVM,
// tied to the same TDB database performing read or write
// transactions concurrently.
@@ -46,7 +46,7 @@ public class ExTDB_Txn1
// ...
// ... The app can also call dataset.abort() or dataset.commit() here; commit is not necessary
// } finally { dataset.end();}
-
+
// Use Txn.executeRead when the app knows there are no updates.
// Can use Txn.execute when a write is possible.
Txn.executeRead(dataset, ()-> {
@@ -58,7 +58,7 @@ public class ExTDB_Txn1
execQuery(sparqlQueryString2, dataset);
});
}
-
+
public static void execQuery(String sparqlQueryString, Dataset dataset)
{
Query query = QueryFactory.create(sparqlQueryString);
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB_Txn2.java b/jena-examples/src/main/java/tdb2/examples/ExTDB_Txn2.java
similarity index 95%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB_Txn2.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB_Txn2.java
index 79462724b8..8748efddb5 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB_Txn2.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB_Txn2.java
@@ -16,15 +16,15 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
import org.apache.jena.atlas.lib.StrUtils;
import org.apache.jena.query.Dataset;
import org.apache.jena.system.Txn;
-import org.apache.jena.tdb1.TDB1Factory;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.update.UpdateExecution;
import org.apache.jena.update.UpdateExecutionFactory;
import org.apache.jena.update.UpdateFactory;
-import org.apache.jena.update.UpdateExecution;
import org.apache.jena.update.UpdateRequest;
/**
@@ -34,7 +34,7 @@ import org.apache.jena.update.UpdateRequest;
public class ExTDB_Txn2 {
public static void main(String...argv) {
String directory = "MyDatabases/DB1";
- Dataset dataset = TDB1Factory.createDataset(directory);
+ Dataset dataset = TDB2Factory.connectDataset(directory);
// Start WRITE transaction.
// It's possible to read from the dataset inside the write transaction.
diff --git a/jena-examples/src/main/java/tdb1/examples/ExTDB_Txn3.java b/jena-examples/src/main/java/tdb2/examples/ExTDB_Txn3.java
similarity index 90%
rename from jena-examples/src/main/java/tdb1/examples/ExTDB_Txn3.java
rename to jena-examples/src/main/java/tdb2/examples/ExTDB_Txn3.java
index c0de9cd6ba..47a45fb301 100644
--- a/jena-examples/src/main/java/tdb1/examples/ExTDB_Txn3.java
+++ b/jena-examples/src/main/java/tdb2/examples/ExTDB_Txn3.java
@@ -16,38 +16,38 @@
* limitations under the License.
*/
-package tdb1.examples;
+package tdb2.examples;
import org.apache.jena.query.*;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.system.Txn;
-import org.apache.jena.tdb1.TDB1Factory;
+import org.apache.jena.tdb2.DatabaseMgr;
/** Illustration of working at the DatasetGraph level.
* Normally, applications work with {@link Dataset}.
* Occasionally, it's more convenient to work with the
- * TDB-implemented DatasetGraph interface.
+ * TDB-implemented DatasetGraph interface.
*/
public class ExTDB_Txn3
{
public static void main(String... argv)
{
- DatasetGraph dsg = TDB1Factory.createDatasetGraph();
+ DatasetGraph dsg = DatabaseMgr.createDatasetGraph();
- // Start a transaction. It starts in "read" mode and promotes to "write" mode if necessary.
+ // Start a transaction. It starts in "read" mode and promotes to "write" mode if necessary.
Txn.execute(dsg, ()->{
// Do some queries
String sparqlQueryString1 = "SELECT (count(*) AS ?count) { ?s ?p ?o }";
execQuery(sparqlQueryString1, dsg);
});
}
-
+
public static void execQuery(String sparqlQueryString, DatasetGraph dsg)
{
// Add a dataset wrapper to conform with the query interface.
// This should not be very expensive.
Dataset dataset = DatasetFactory.wrap(dsg);
-
+
Query query = QueryFactory.create(sparqlQueryString);
try ( QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ) {
ResultSet results = qexec.execSelect();