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 2012/01/20 20:13:40 UTC
svn commit: r1234081 - in /incubator/jena/Jena2/TDB/trunk:
src-examples/tdb/examples/ExTDB_Txn3.java
src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java
Author: andy
Date: Fri Jan 20 19:13:39 2012
New Revision: 1234081
URL: http://svn.apache.org/viewvc?rev=1234081&view=rev
Log:
Copy context from base dataset into transactional view.
Added:
incubator/jena/Jena2/TDB/trunk/src-examples/tdb/examples/ExTDB_Txn3.java
Modified:
incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java
Added: incubator/jena/Jena2/TDB/trunk/src-examples/tdb/examples/ExTDB_Txn3.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src-examples/tdb/examples/ExTDB_Txn3.java?rev=1234081&view=auto
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src-examples/tdb/examples/ExTDB_Txn3.java (added)
+++ incubator/jena/Jena2/TDB/trunk/src-examples/tdb/examples/ExTDB_Txn3.java Fri Jan 20 19:13:39 2012
@@ -0,0 +1,71 @@
+/**
+ * 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 tdb.examples;
+
+import com.hp.hpl.jena.query.* ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.tdb.TDBFactory ;
+import com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction ;
+
+/** Illustraion 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.
+ */
+public class ExTDB_Txn3
+{
+ public static void main(String... argv)
+ {
+ DatasetGraphTransaction dsg = (DatasetGraphTransaction)TDBFactory.createDatasetGraph() ;
+
+ // Start READ transaction.
+ dsg.begin(ReadWrite.READ) ;
+
+ try
+ {
+ // Do some queries
+ String sparqlQueryString1 = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
+ execQuery(sparqlQueryString1, dsg) ;
+ } finally
+ {
+ dsg.end() ;
+ }
+ }
+
+ public static void execQuery(String sparqlQueryString, DatasetGraph dsg)
+ {
+ // Add a datset wrapper to conform with the query interface.
+ // This shoudl not be very expensive.
+ Dataset dataset = DatasetFactory.create(dsg) ;
+
+ Query query = QueryFactory.create(sparqlQueryString) ;
+ QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
+ try {
+ ResultSet results = qexec.execSelect() ;
+ for ( ; results.hasNext() ; )
+ {
+ QuerySolution soln = results.nextSolution() ;
+ int count = soln.getLiteral("count").getInt() ;
+ System.out.println("count = "+count) ;
+ }
+ } finally { qexec.close() ; }
+ }
+
+}
+
Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java?rev=1234081&r1=1234080&r2=1234081&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/DatasetBuilderTxn.java Fri Jan 20 19:13:39 2012
@@ -44,6 +44,12 @@ import com.hp.hpl.jena.tdb.sys.SystemTDB
public class DatasetBuilderTxn
{
+ // Duplicate context.
+ // Don't make a DatasetGraphTDB to pass to new DatasetGraphTxn as it rips it apart.
+ // And fails to copy context.
+ // XXX 1/ DatasetGraphTDB clone constructor needs to handle context.
+ // XXX 2/ DatasetBuilderTxn needs to build a DatasetGraphTxn directly, not via
+
// Context for the build.
private TransactionManager txnMgr ;
private Map<FileRef, BlockMgr> blockMgrs ;
@@ -59,22 +65,28 @@ public class DatasetBuilderTxn
this.nodeTables = dsg.getConfig().nodeTables ;
this.txn = transaction ;
this.dsg = dsg ;
+
+ DatasetGraphTDB dsgTxn ;
switch(mode)
{
- case READ : return buildReadonly() ;
- case WRITE : return buildWritable() ;
- default: return null ; // Silly Java.
+ case READ : dsgTxn = buildReadonly() ; break ;
+ case WRITE : dsgTxn = buildWritable() ; break ;
+ default: dsgTxn = null ; // Silly Java.
}
+
+ dsgTxn = new DatasetGraphTxn(dsgTxn, txn) ;
+ dsgTxn.getContext().putAll(dsg.getContext()) ;
+ return dsgTxn ;
}
- private DatasetGraphTxn buildReadonly()
+ private DatasetGraphTDB buildReadonly()
{
BlockMgrBuilder blockMgrBuilder = new BlockMgrBuilderReadonly() ;
NodeTableBuilder nodeTableBuilder = new NodeTableBuilderReadonly() ;
DatasetBuilderStd x = new DatasetBuilderStd(blockMgrBuilder, nodeTableBuilder) ;
DatasetGraphTDB dsg2 = x.build(dsg.getLocation(), dsg.getConfig().params) ;
- return new DatasetGraphTxn(dsg2, txn) ;
+ return dsg2 ;
}
private DatasetGraphTDB buildWritable()
@@ -83,7 +95,7 @@ public class DatasetBuilderTxn
NodeTableBuilder nodeTableBuilder = new NodeTableBuilderTx() ;
DatasetBuilderStd x = new DatasetBuilderStd(blockMgrBuilder, nodeTableBuilder) ;
DatasetGraphTDB dsg2 = x.build(dsg.getLocation(), dsg.getConfig().params) ;
- return new DatasetGraphTxn(dsg2, txn) ;
+ return dsg2 ;
}
// ---- Add logging to a BlockMgr when built.