jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1233517 - in /incubator/jena/Jena2/TDB/trunk: src-dev/dev/ src/main/java/com/hp/hpl/jena/tdb/ src/main/java/com/hp/hpl/jena/tdb/base/file/ src/main/java/com/hp/hpl/jena/tdb/transaction/ src/test/java/com/hp/hpl/jena/tdb/migrate/ src/test/j...
Date Thu, 19 Jan 2012 18:29:17 GMT
Author: andy
Date: Thu Jan 19 18:29:16 2012
New Revision: 1233517

URL: http://svn.apache.org/viewvc?rev=1233517&view=rev
Log:
Manage in-memory (testing) datasets better.

Modified:
    incubator/jena/Jena2/TDB/trunk/src-dev/dev/TestTxn.java
    incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java
    incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java
    incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
    incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
    incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java

Modified: incubator/jena/Jena2/TDB/trunk/src-dev/dev/TestTxn.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src-dev/dev/TestTxn.java?rev=1233517&r1=1233516&r2=1233517&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src-dev/dev/TestTxn.java (original)
+++ incubator/jena/Jena2/TDB/trunk/src-dev/dev/TestTxn.java Thu Jan 19 18:29:16 2012
@@ -18,8 +18,11 @@
 
 package dev;
 
+import org.junit.After ;
+import org.junit.Before ;
 import org.junit.Test ;
 import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.atlas.lib.FileOps ;
 
 import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.query.Dataset ;
@@ -27,15 +30,14 @@ import com.hp.hpl.jena.query.DatasetFact
 import com.hp.hpl.jena.query.ReadWrite ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
 import com.hp.hpl.jena.sparql.sse.SSE ;
-import com.hp.hpl.jena.tdb.DatasetGraphTransaction ;
-import com.hp.hpl.jena.tdb.TDBFactory ;
-import com.hp.hpl.jena.tdb.TDBFactoryTxn ;
+import com.hp.hpl.jena.tdb.* ;
+import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
 
 public class TestTxn extends BaseTest
 {
-// static final String DIR = ConfigTest.getTestingDirDB() ; 
-//    
+    static final String DIR = ConfigTest.getTestingDirDB() ; 
+    
 //    @Before public void before()
 //    {
 //        FileOps.clearDirectory(DIR) ; 
@@ -43,13 +45,14 @@ public class TestTxn extends BaseTest
 //    
 //    @After public void after()
 //    {
+//        StoreConnection.reset() ;
 //        FileOps.clearDirectory(DIR) ; 
 //    }
-//    
+    
     protected Dataset create()
     { 
-        DatasetGraph dsg = TDBFactory.createDatasetGraph() ;
-        dsg = TDBFactoryTxn.XcreateDatasetGraph() ;
+        //DatasetGraph dsg = TDBFactory.createDatasetGraph(DIR) ;
+        DatasetGraph dsg = TDBFactoryTxn.XcreateDatasetGraph(Location.mem(DIR)) ;
         
         if ( dsg instanceof DatasetGraphTDB )
             dsg = new DatasetGraphTransaction((DatasetGraphTDB)dsg) ;    
@@ -112,6 +115,7 @@ public class TestTxn extends BaseTest
     {
         Dataset ds1 = create() ;
         Dataset ds2 = create() ;
+        DatasetGraph dsg1 = ds2.asDatasetGraph() ;
         
         ds1.begin(ReadWrite.WRITE) ;
         ds1.getDefaultModel().getGraph().add(triple1) ; 
@@ -121,7 +125,9 @@ public class TestTxn extends BaseTest
         ds2.commit() ;
         
         ds1.commit() ;
-
+        
+        ds1.end() ;
+        ds2.end() ;
         ds2.begin(ReadWrite.READ) ;
         assertFalse(ds2.getDefaultModel().isEmpty()) ;
         assertEquals(1, ds2.getDefaultModel().size()) ;
@@ -129,5 +135,9 @@ public class TestTxn extends BaseTest
 
     }
 
+    // Non-Txn then Txn.
+    
+    
+    
 }
 

Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java?rev=1233517&r1=1233516&r2=1233517&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java
(original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/StoreConnection.java
Thu Jan 19 18:29:16 2012
@@ -161,8 +161,8 @@ public class StoreConnection
         {
             sConn = new StoreConnection(dsg) ;
             JournalControl.recovery(sConn.baseDSG) ;
-            if ( ! location.isMem() )
-                // Don't cache in-memory datasets.
+            if ( ! location.isMemUnique() )
+                // Don't cache use-once in-memory datasets.
                 cache.put(location, sConn) ;
             String NS = TDB.PATH ;
             TransactionInfo txInfo = new TransactionInfo(sConn.getTransMgr()) ;

Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java?rev=1233517&r1=1233516&r2=1233517&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java
(original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java
Thu Jan 19 18:29:16 2012
@@ -20,6 +20,8 @@ package com.hp.hpl.jena.tdb.base.file;
 
 import java.io.File;
 
+import org.openjena.atlas.lib.Lib ;
+
 import com.hp.hpl.jena.tdb.sys.Names;
 
 /** 
@@ -32,46 +34,42 @@ public class Location
 {
     static String pathSeparator = File.separator ;  // Or just "/"
     
-//    // Filename bashing moved to FileOps.
-//    private static Location dirname(String filename)
-//    {
-//        filename = filename.replace('\'', '/') ;
-//        int i = filename.lastIndexOf('/') ;
-//        if ( i == filename.length()-1 )
-//            return new Location(filename) ;
-//        String dirname = filename.substring(0, i) ; // Exclude final /
-//        return new Location(dirname) ;
-//    }
-//    
-//    private static Location ensureDirectory(String dirname)
-//    {
-//        File file = new File(dirname) ;
-//        
-//        if ( ! file.exists() )
-//        {
-//            if ( ! file.mkdirs() )
-//                throw new FileException("Failed to create directory: "+file.getAbsolutePath())
;
-//        }
-//        if ( ! file.isDirectory() )
-//            throw new FileException("Not a directory: "+file.getAbsolutePath()) ;
-//        Location loc = new Location() ;
-//        loc.setPathname(dirname) ;
-//        return loc ;
-//    }
-    
     private String pathname ;
     private MetaFile metafile = null ; 
     private boolean isMem = false ;
+    private boolean isMemUnique = false ;
+    
+    static int memoryCount = 0 ; 
+    
+    /** Return a fresh memory location : always unique, never .equals to another location.
*/  
+    static public Location mem() { return mem(null) ; }
+    
+    /** Return a memory location with a name */  
+    static public Location mem(String name)
+    { 
+        Location loc = new Location();
+        memInit(loc, name) ;
+        return loc ;
+    }
     
-    static Location mem = new Location() ;
-    // Every mem()is a fresh location and importantly fresh metadata.
-    static public Location mem() { return new Location(); } 
     
     private Location()
+    { }
+    
+    private static void memInit(Location location, String name)
     {
-        pathname = Names.memName+pathSeparator ;
-        isMem = true ;
-        metafile = new MetaFile(Names.memName, Names.memName) ;
+        location.pathname = Names.memName ;
+        if ( name != null )
+        {
+            name = name.replace('\\', '/') ;
+            location.pathname = location.pathname+pathSeparator+name ;
+        }
+        else
+            location.isMemUnique = true ;
+        if ( ! location.pathname.endsWith(pathSeparator) )
+            location.pathname = location.pathname+pathSeparator ;
+        location.isMem = true ;
+        location.metafile = new MetaFile(Names.memName, Names.memName) ;
     }
     
     public Location(String rootname)
@@ -79,9 +77,7 @@ public class Location
         super() ;
         if ( rootname.equals(Names.memName) )
         {
-            isMem = true ;
-            pathname = Names.memName + pathSeparator  ;
-            metafile = new MetaFile(Names.memName, Names.memName) ;
+            memInit(this, null) ;
             return ;
         }
         
@@ -109,7 +105,8 @@ public class Location
 
     public String getDirectoryPath()    { return pathname ; }
     public MetaFile getMetaFile()       { return metafile ; }
-    public boolean isMem()              { return isMem ; }
+    public boolean isMem()              { return isMem ; } 
+    public boolean isMemUnique()        { return isMemUnique ; }
     
     public Location getSubLocation(String dirname)
     {
@@ -193,10 +190,8 @@ public class Location
     @Override
     public int hashCode()
     {
-        if ( isMem )
-            return 37 ;
         final int prime = 31 ;
-        int result = 1 ;
+        int result = isMem ? 1 : 2 ;
         result = prime * result + ((pathname == null) ? 0 : pathname.hashCode()) ;
         return result ;
     }
@@ -207,17 +202,12 @@ public class Location
         if (this == obj) return true ;
         if (obj == null) return false ;
         if (getClass() != obj.getClass()) return false ;
+        
         Location other = (Location)obj ;
-        if ( isMem && other.isMem ) return true ;
         if ( isMem && ! other.isMem ) return false ; 
         if ( ! isMem && other.isMem ) return false ; 
-        
-        if (pathname == null)
-        {
-            if (other.pathname != null) return false ;
-        } else
-            if (!pathname.equals(other.pathname)) return false ;
-        return true ;
+
+        return Lib.equal(pathname, other.pathname) ;
     }
 
     @Override

Modified: incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java?rev=1233517&r1=1233516&r2=1233517&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
(original)
+++ incubator/jena/Jena2/TDB/trunk/src/main/java/com/hp/hpl/jena/tdb/transaction/JournalControl.java
Thu Jan 19 18:29:16 2012
@@ -67,7 +67,10 @@ public class JournalControl
     public static void recovery(DatasetGraphTDB dsg)
     {
         if ( dsg instanceof DatasetGraphTxn )
-            throw new TDBTransactionException("Reocery works on the base dataset, not a transactional
one") ; 
+            throw new TDBTransactionException("Recovery works on the base dataset, not a
transactional one") ;
+        // Later we may have ...
+//        if ( dsg instanceof DatasetGraphTransaction )
+//            throw new TDBTransactionException("Recovery works on the base dataset, not
a transactional one") ; 
         
         if ( dsg.getLocation().isMem() )
             return ;

Modified: incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java?rev=1233517&r1=1233516&r2=1233517&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
(original)
+++ incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/migrate/AbstractTestTransaction.java
Thu Jan 19 18:29:16 2012
@@ -31,8 +31,6 @@ public abstract class AbstractTestTransa
     //MIGRATE
     protected abstract Dataset create() ;
     
-    private static Triple triple1 = SSE.parseTriple("(<s> <p> <o>)") ;
 
-
     @Test public void factoryTxn0()
     {
         Dataset ds = create() ;
@@ -87,28 +85,5 @@ public abstract class AbstractTestTransa
         ds.end() ;
         assertFalse(ds.isInTransaction()) ; 
     }
-
-
-    @Test public void factoryTxn10()
-    {
-        Dataset ds1 = create() ;
-        Dataset ds2 = create() ;
-        
-        ds1.begin(ReadWrite.WRITE) ;
-        ds1.getDefaultModel().getGraph().add(triple1) ; 
-        
-        ds2.begin(ReadWrite.READ) ;
-        assertTrue(ds2.getDefaultModel().isEmpty()) ;
-        ds2.commit() ;
-        
-        ds1.commit() ;
-
-        ds2.begin(ReadWrite.READ) ;
-        assertFalse(ds2.getDefaultModel().isEmpty()) ;
-        assertEquals(1, ds2.getDefaultModel().size()) ;
-        ds2.commit() ;
-
-    }
-
 }
 

Modified: incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java?rev=1233517&r1=1233516&r2=1233517&view=diff
==============================================================================
--- incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java
(original)
+++ incubator/jena/Jena2/TDB/trunk/src/test/java/com/hp/hpl/jena/tdb/transaction/TestTransactionTDB.java
Thu Jan 19 18:29:16 2012
@@ -20,9 +20,13 @@ package com.hp.hpl.jena.tdb.transaction;
 
 import org.junit.After ;
 import org.junit.Before ;
+import org.junit.Test ;
 import org.openjena.atlas.lib.FileOps ;
 
+import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.ReadWrite ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
 import com.hp.hpl.jena.tdb.ConfigTest ;
 import com.hp.hpl.jena.tdb.TDBFactory ;
 import com.hp.hpl.jena.tdb.TDBFactoryTxn ;
@@ -48,5 +52,34 @@ public class TestTransactionTDB extends 
         //return TDBFactory.createDataset(DIR) ;
         return TDBFactoryTxn.XcreateDataset(DIR) ;
     }
+    
+    private static Triple triple1 = SSE.parseTriple("(<s> <p> <o>)") ;
 
+
+    
+    @Test public void factoryTxn10()
+    {
+        // This assumes you have two datasets on the same location.
+        // That's not necessarily true for uncached memory datasets, 
+        // where you get two separate datasets so changes to one are
+        // not seen by the other at all.
+        
+        Dataset ds1 = create() ;
+        Dataset ds2 = create() ;
+        
+        ds1.begin(ReadWrite.WRITE) ;
+        ds1.getDefaultModel().getGraph().add(triple1) ; 
+        
+        ds2.begin(ReadWrite.READ) ;
+        assertTrue(ds2.getDefaultModel().isEmpty()) ;
+        ds2.commit() ;
+        
+        ds1.commit() ;
+
+        ds2.begin(ReadWrite.READ) ;
+        assertFalse(ds2.getDefaultModel().isEmpty()) ;
+        assertEquals(1, ds2.getDefaultModel().size()) ;
+        ds2.commit() ;
+    }
+
 }
 



Mime
View raw message