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 2011/07/21 21:49:18 UTC

svn commit: r1149338 - in /incubator/jena/Experimental/TxTDB/trunk: src-dev/tx/ src/main/java/com/hp/hpl/jena/tdb/index/ src/main/java/com/hp/hpl/jena/tdb/transaction/ src/test/java/com/hp/hpl/jena/tdb/transaction/

Author: andy
Date: Thu Jul 21 19:49:17 2011
New Revision: 1149338

URL: http://svn.apache.org/viewvc?rev=1149338&view=rev
Log: (empty)

Added:
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java   (with props)
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TransTestLib.java   (with props)
Modified:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSequentialDisk.java

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java?rev=1149338&r1=1149337&r2=1149338&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TxMain.java Thu Jul 21 19:49:17 2011
@@ -10,10 +10,18 @@ import java.io.File ;
 
 import org.openjena.atlas.lib.Bytes ;
 import org.openjena.atlas.lib.FileOps ;
+import org.openjena.atlas.lib.Sink ;
+import org.openjena.atlas.lib.SinkNull ;
+import org.openjena.atlas.lib.SinkWrapper ;
 import org.openjena.atlas.logging.Log ;
+import org.openjena.riot.RiotReader ;
 import org.openjena.riot.RiotWriter ;
+import org.openjena.riot.WebReader ;
+import org.openjena.riot.lang.SinkToGraph ;
+import org.openjena.riot.lang.SinkTriplesToGraph ;
 
 import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.query.DatasetFactory ;
 import com.hp.hpl.jena.query.Query ;
 import com.hp.hpl.jena.query.QueryExecution ;
@@ -66,24 +74,30 @@ public class TxMain
         initFS() ;
         // Named memory locations? OTT
         //StoreConnection sConn = StoreConnection.make(Location.mem()) ; 
-        StoreConnection sConn = StoreConnection.make(DBdir) ;
+        StoreConnection sConn = StoreConnection.make(Location.mem()) ;
         
         
         // ---- Simple
-        if ( false )
+        if ( true )
         {
+            DatasetGraphTxn dsgRead = null ;
+            //dsgRead = sConn.begin(ReadWrite.READ) ;
             DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
-            //load("D.ttl", dsg) ;    // Loads 3 triples
-            dsg.getDefaultGraph().add(SSE.parseTriple("(<s> <p> <o>)")) ;
-            dsg.add(SSE.parseQuad("(<g> <s> <p> 123)")) ;
-            dsg.add(SSE.parseQuad("(_ <s> <p> 123)")) ;
+            // Duplicates.
+            load("tracks.nt", dsg) ;
+            
+            /*
+             * Exception during journal replay
+com.hp.hpl.jena.tdb.base.file.FileException: FileAccessMem: Wrong size block.  Expected=8192 : actual=8156
+    at com.hp.hpl.jena.tdb.base.file.BlockAccessMem.check(BlockAccessMem.java:130)
+    at com.hp.hpl.jena.tdb.base.file.BlockAccessMem.check(BlockAccessMem.java:114)
+             */
+            //load("S.nt", dsg) ;
             
             dsg.commit() ;
             dsg.close() ;
-            DatasetGraphTxn dsgRead = sConn.begin(ReadWrite.READ) ;
-            dump(dsgRead) ;
-            query("SELECT ?g (count(*) AS ?C) { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } } GROUP BY ?g", dsgRead) ;
-            dsgRead.close() ;
+            if ( dsgRead != null ) 
+                dsgRead.close() ;
             exit(0) ;
         }
         
@@ -212,9 +226,26 @@ public class TxMain
         System.out.print("**** ") ;
         System.out.println(label) ;
         System.out.println("Load: "+file) ;
-        Model m = ModelFactory.createModelForGraph(dsg.getDefaultGraph()) ;
-        FileManager.get().readModel(m, file) ;
         
+        Sink<Triple> sink = new SinkTriplesToGraph(dsg.getDefaultGraph()) ;
+        
+        sink = new SinkWrapper<Triple>(sink) {
+            int count = 0 ;
+            @Override
+            public void send(Triple item)
+            {
+                try {
+                sink.send(item) ;
+                count++ ;
+                } catch (RuntimeException ex)
+                {
+                    System.err.println("exception @"+count) ;
+                    throw ex ;
+                }
+            }
+        } ;
+        
+        RiotReader.parseTriples(file, sink) ;
     }
 
     public static void update(String updateStr, DatasetGraph dsg)

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java?rev=1149338&r1=1149337&r2=1149338&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/index/TupleTable.java Thu Jul 21 19:49:17 2011
@@ -9,8 +9,13 @@ package com.hp.hpl.jena.tdb.index;
 
 import static java.lang.String.format ;
 
+import java.io.FileOutputStream ;
+import java.io.IOException ;
+import java.io.OutputStream ;
 import java.util.Iterator ;
 
+import org.openjena.atlas.io.IO ;
+import org.openjena.atlas.io.IndentedWriter ;
 import org.openjena.atlas.lib.Closeable ;
 import org.openjena.atlas.lib.Sync ;
 import org.openjena.atlas.lib.Tuple ;
@@ -18,6 +23,7 @@ import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
 import com.hp.hpl.jena.tdb.TDBException ;
+import com.hp.hpl.jena.tdb.index.bplustree.BPlusTree ;
 import com.hp.hpl.jena.tdb.store.NodeId ;
 
 /** A TupleTable is a set of TupleIndexes.  The first TupleIndex is the "primary" index and must exist */
@@ -58,6 +64,14 @@ public class TupleTable implements Sync,
                     duplicate(t) ;
                     return false ;
                 }
+                try {
+                    OutputStream f = new FileOutputStream("LOG") ;
+                    IndentedWriter w = new IndentedWriter(f) ;
+                    ( (BPlusTree) ((TupleIndexRecord)indexes[i]).getRangeIndex() ).dump(w) ;
+                    w.flush() ;
+                    f.flush() ;
+                    f.close() ;
+                } catch ( IOException ex ) {}
                 throw new TDBException(format("Secondary index duplicate: %s -> %s",indexes[i].getLabel(), t)) ;
             }
         }

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java?rev=1149338&r1=1149337&r2=1149338&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/BlockMgrJournal.java Thu Jul 21 19:49:17 2011
@@ -13,6 +13,7 @@ import java.util.Iterator ;
 import java.util.Map ;
 import java.util.Set ;
 
+import org.openjena.atlas.lib.ByteBufferLib ;
 import org.openjena.atlas.logging.Log ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
@@ -99,17 +100,13 @@ public class BlockMgrJournal implements 
     public Block allocate(int blockSize)
     {
         checkIfClosed() ;
-        
-        // Could allocate ready to go to Journal.
-        // Need to get the id though.
-
         // Might as well allocate now. 
         // This allocates the id.
         Block block = blockMgr.allocate(blockSize) ;
-        
+        // [TxTDB:TODO]
         // But we "copy" it by allocating ByteBuffer space.
-        ByteBuffer byteBuffer = ByteBuffer.allocate(blockSize) ;
-        block = new Block(block.getId(), byteBuffer) ;
+        block = block.replicate( ) ;
+        writeBlocks.put(block.getId(), block) ;
         return block ;
     }
 

Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java?rev=1149338&r1=1149337&r2=1149338&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/AbstractTestTransSeq.java Thu Jul 21 19:49:17 2011
@@ -18,25 +18,12 @@
 
 package com.hp.hpl.jena.tdb.transaction;
 
-import java.util.ArrayList ;
-import java.util.List ;
 
 import org.junit.Test ;
 import org.openjena.atlas.junit.BaseTest ;
 
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.query.DatasetFactory ;
-import com.hp.hpl.jena.query.Query ;
-import com.hp.hpl.jena.query.QueryExecution ;
-import com.hp.hpl.jena.query.QueryExecutionFactory ;
-import com.hp.hpl.jena.query.QueryFactory ;
-import com.hp.hpl.jena.query.ResultSet ;
-import com.hp.hpl.jena.query.Syntax ;
-import com.hp.hpl.jena.sparql.core.DatasetGraph ;
 import com.hp.hpl.jena.sparql.core.Quad ;
-import com.hp.hpl.jena.sparql.core.Var ;
 import com.hp.hpl.jena.sparql.sse.SSE ;
-import com.hp.hpl.jena.tdb.ConfigTest ;
 import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
 import com.hp.hpl.jena.tdb.ReadWrite ;
 import com.hp.hpl.jena.tdb.StoreConnection ;
@@ -51,8 +38,7 @@ public abstract class AbstractTestTransS
     static Quad q3 = SSE.parseQuad("(<g> <s> <p> <o3>)") ;
     static Quad q4 = SSE.parseQuad("(<g> <s> <p> <o4>)") ;
     
-    static final String DIR = ConfigTest.getTestingDirDB() ;
-    
+   
     private StoreConnection sConn ;
 
     protected abstract StoreConnection getStoreConnection() ;
@@ -257,41 +243,20 @@ public abstract class AbstractTestTransS
         DatasetGraphTxn dsg = sConn.begin(ReadWrite.READ) ;
         dsg.add(q) ;
     }
-
-
-    static int count(String queryStr, DatasetGraph dsg)
-    {
-        int counter = 0 ;
-        Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ;
-        QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.create(dsg)) ;
-        try {
-            ResultSet rs = qExec.execSelect() ;
-            for (; rs.hasNext() ; )
-            {
-                rs.nextBinding() ;
-                counter++ ;
-            }
-            return counter ;
-        } finally { qExec.close() ; }
-    }
     
-    // To QueryExecUtils?
-    public static List<Node> query(String queryStr, String var, DatasetGraphTxn dsg)
+    //@Test 
+    public void trans_30()
     {
-        Var v = Var.alloc(var) ;
-        Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ;
-        QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.create(dsg)) ;
-        List<Node> nodes = new ArrayList<Node>() ;
-        try {
-            ResultSet rs = qExec.execSelect() ;
-            for (; rs.hasNext() ; )
-            {
-                Node n = rs.nextBinding().get(v) ;
-                nodes.add(n) ;
-            }
-            return nodes ;
-        } finally { qExec.close() ; }
+        // WRITE lots
+        StoreConnection sConn = getStoreConnection() ;
+        DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
+        for ( int i = 0 ; i < 400 ; i++ )
+        {
+            Quad q = SSE.parseQuad("(_ <s> <p> "+i+")") ;
+            dsg.add(q) ;
+        }
+        dsg.commit() ;
+        dsg.close() ;
     }
-    
 }
 

Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSequentialDisk.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSequentialDisk.java?rev=1149338&r1=1149337&r2=1149338&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSequentialDisk.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSequentialDisk.java Thu Jul 21 19:49:17 2011
@@ -22,12 +22,14 @@ import org.junit.After ;
 import org.junit.Before ;
 import org.openjena.atlas.lib.FileOps ;
 
+import com.hp.hpl.jena.tdb.ConfigTest ;
 import com.hp.hpl.jena.tdb.StoreConnection ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 
 /** Basic tests and tests of ordering (single thread) */
 public class TestTransSequentialDisk extends AbstractTestTransSeq
 {
+    static final String DIR = ConfigTest.getTestingDirDB() ;
     static final Location LOC = new Location(DIR) ;
     
     @Before public void setup()

Added: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java?rev=1149338&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java Thu Jul 21 19:49:17 2011
@@ -0,0 +1,223 @@
+/**
+ * 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 com.hp.hpl.jena.tdb.transaction;
+
+import static com.hp.hpl.jena.tdb.transaction.TransTestLib.count ;
+
+import java.util.Date ;
+import java.util.concurrent.Callable ;
+import java.util.concurrent.ExecutorService ;
+import java.util.concurrent.Executors ;
+import java.util.concurrent.TimeUnit ;
+import java.util.concurrent.atomic.AtomicInteger ;
+
+import org.openjena.atlas.lib.FileOps ;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.tdb.ConfigTest ;
+import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
+import com.hp.hpl.jena.tdb.ReadWrite ;
+import com.hp.hpl.jena.tdb.StoreConnection ;
+
+/** System testing of the transactions. */
+public class TestTransSystem
+{
+    static ExecutorService execService = Executors.newCachedThreadPool() ;
+    static Quad q  = SSE.parseQuad("(_ <s> <p> <o>) ") ;
+    static Quad q1 = SSE.parseQuad("(_ <s> <p> <o1>)") ;
+    static Quad q2 = SSE.parseQuad("(_ <s> <p> <o2>)") ;
+    static Quad q3 = SSE.parseQuad("(_ <s> <p> <o3>)") ;
+    static Quad q4 = SSE.parseQuad("(_ <s> <p> <o4>)") ;
+    
+    static final String DIR = ConfigTest.getTestingDirDB() ;
+    private StoreConnection sConn ;
+    private int initCount = -1 ;
+    static final AtomicInteger gen = new AtomicInteger() ;
+    protected StoreConnection getStoreConnection()
+    {
+        FileOps.clearDirectory(DIR) ;
+        StoreConnection sConn = StoreConnection.make(DIR) ;
+        DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
+        dsg.add(q1) ;
+        dsg.add(q2) ;
+        initCount = 2 ;
+        dsg.commit() ;
+        dsg.close() ;
+        return sConn ;
+    }
+    
+    public static void main(String...args)
+    {
+        System.out.println("Starting: "+new Date()) ;
+        new TestTransSystem().manyReaderAndOneWriter() ;
+        System.out.println("Stopping: "+new Date()) ;
+        
+    }
+    
+    //@Test
+    public void manyRead()
+    {
+        final StoreConnection sConn = getStoreConnection() ;
+        Callable<?> proc = new Reader(sConn, 50, 200)  ;
+
+            
+        for ( int i = 0 ; i < 50 ; i++ )
+            execService.submit(proc) ;
+        try
+        {
+            execService.shutdown() ;
+            execService.awaitTermination(100, TimeUnit.SECONDS) ;
+        } catch (InterruptedException e)
+        {
+            e.printStackTrace();
+        }
+    }
+    
+    //@Test
+    public void manyReaderAndOneWriter()
+    {
+        final StoreConnection sConn = getStoreConnection() ;
+        
+        Callable<?> procR = new Reader(sConn, 5, 200) ;
+        Callable<?> procW = new Writer(sConn, 5, 2, true) {
+            @Override
+            protected int change(DatasetGraphTxn dsg, int id, int i)
+            {
+                int count = 0 ;
+                for ( int j = 0 ; j < 5; j++ )
+                {
+                    Quad q = genQuad(id*1000+100*i+j) ;
+                    if ( ! dsg.contains(q) )
+                    {
+                        dsg.add(q) ;
+                        count++ ;
+                    }
+                }
+                return count ;
+            } } ;
+            
+        for ( int i = 0 ; i < 50 ; i++ )
+        {
+            execService.submit(procR) ;   
+            execService.submit(procW) ;
+        }
+        try
+        {
+            execService.shutdown() ;
+            execService.awaitTermination(100, TimeUnit.SECONDS) ;
+        } catch (InterruptedException e)
+        {
+            e.printStackTrace();
+        } 
+    }
+
+    static class Reader implements Callable<Object>
+    {
+        private final int repeats ;
+        private final int maxpause ;
+        private final StoreConnection sConn ; 
+    
+        Reader(StoreConnection sConn, int number, int pause)
+        {
+            this.repeats = number ;
+            this.maxpause = pause ;
+            this.sConn = sConn ;
+        }
+        
+        @Override
+        public Object call()
+        {
+            int id = gen.incrementAndGet() ;
+            for ( int i = 0 ; i < repeats; i++ )
+            {
+                DatasetGraphTxn dsg = sConn.begin(ReadWrite.READ) ;
+                int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
+                pause(maxpause) ;
+                int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
+                if ( x1 != x2 )
+                    System.err.printf("Change seen: id=%d: i=%d\n", id, i) ;
+                dsg.close() ;
+            }
+            return null ;
+        }
+    }
+
+    static abstract class Writer implements Callable<Object>
+    {
+        private final int repeats ;
+        private final int maxpause ;
+        private final StoreConnection sConn ;
+        private final boolean commit ; 
+    
+        protected Writer(StoreConnection sConn, int number, int pause, boolean commit)
+        {
+            this.repeats = number ;
+            this.maxpause = pause ;
+            this.sConn = sConn ;
+            this.commit = commit ;
+        }
+        
+        @Override
+        public Object call()
+        {
+            int id = gen.incrementAndGet() ;
+            for ( int i = 0 ; i < 10; i++ )
+            {
+                DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
+                int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
+                int z = change(dsg, id, i) ;
+                pause(maxpause) ;
+                int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
+                if ( x1+z != x2 )
+                    System.err.printf("Change seen: id=%d: i=%d\n", id, i) ;
+                if (commit) 
+                    dsg.commit() ;
+                else
+                    dsg.abort() ;
+                dsg.close() ;
+            }
+            return null ; 
+        }
+
+        // return the delta.
+        protected abstract int change(DatasetGraphTxn dsg, int id, int i) ;
+    }
+
+    static long pause(int maxInternal)
+    {
+        return Math.round(Math.random()*maxInternal) ;
+    }
+    
+    static Quad genQuad(int value)
+    {
+        Quad q1 = SSE.parseQuad("(_ <s> <p> <o>)") ;
+        Node g1 = q.getGraph() ;
+        
+        Node g = Quad.defaultGraphNodeGenerated ; // urn:x-arq:DefaultGraphNode
+        Node s = Node.createURI("S") ;
+        Node p = Node.createURI("P") ;
+        Node o = Node.createLiteral(Integer.toString(value), null, XSDDatatype.XSDinteger) ;
+        return new Quad(g,s,p,o) ;
+    }
+    
+}
+

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransSystem.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TransTestLib.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TransTestLib.java?rev=1149338&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TransTestLib.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TransTestLib.java Thu Jul 21 19:49:17 2011
@@ -0,0 +1,74 @@
+/**
+ * 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 com.hp.hpl.jena.tdb.transaction;
+
+import java.util.ArrayList ;
+import java.util.List ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.DatasetFactory ;
+import com.hp.hpl.jena.query.Query ;
+import com.hp.hpl.jena.query.QueryExecution ;
+import com.hp.hpl.jena.query.QueryExecutionFactory ;
+import com.hp.hpl.jena.query.QueryFactory ;
+import com.hp.hpl.jena.query.ResultSet ;
+import com.hp.hpl.jena.query.Syntax ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
+
+public class TransTestLib
+{
+
+    static int count(String queryStr, DatasetGraph dsg)
+    {
+        int counter = 0 ;
+        Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ;
+        QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.create(dsg)) ;
+        try {
+            ResultSet rs = qExec.execSelect() ;
+            for (; rs.hasNext() ; )
+            {
+                rs.nextBinding() ;
+                counter++ ;
+            }
+            return counter ;
+        } finally { qExec.close() ; }
+    }
+
+    // To QueryExecUtils?
+    public static List<Node> query(String queryStr, String var, DatasetGraphTxn dsg)
+    {
+        Var v = Var.alloc(var) ;
+        Query query = QueryFactory.create(queryStr, Syntax.syntaxARQ) ;
+        QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.create(dsg)) ;
+        List<Node> nodes = new ArrayList<Node>() ;
+        try {
+            ResultSet rs = qExec.execSelect() ;
+            for (; rs.hasNext() ; )
+            {
+                Node n = rs.nextBinding().get(v) ;
+                nodes.add(n) ;
+            }
+            return nodes ;
+        } finally { qExec.close() ; }
+    }
+
+}
+

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TransTestLib.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain