jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/8] jena git commit: Deprecate low level non-application operations
Date Sun, 29 Jul 2018 15:37:43 GMT
Deprecate low level non-application operations


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/60131204
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/60131204
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/60131204

Branch: refs/heads/master
Commit: 60131204d1c71c9bda6bd5ba4b55f2d12fa4444e
Parents: 6e85e6c
Author: Andy Seaborne <andy@apache.org>
Authored: Sat Jul 28 15:50:33 2018 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Sat Jul 28 15:50:33 2018 +0100

----------------------------------------------------------------------
 .../org/apache/jena/tdb/StoreConnection.java    |  10 +-
 .../java/org/apache/jena/tdb/sys/TDBMaker.java  |  40 +++++--
 .../org/apache/jena/tdb/TestTDBFactory.java     | 109 +++++++++----------
 .../org/apache/jena/tdb/store/TestLoader.java   |   4 +-
 .../jena/tdb/transaction/TestTransRestart.java  |   5 +-
 5 files changed, 95 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/60131204/jena-tdb/src/main/java/org/apache/jena/tdb/StoreConnection.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/StoreConnection.java b/jena-tdb/src/main/java/org/apache/jena/tdb/StoreConnection.java
index 978ee78..4a6125d 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/StoreConnection.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/StoreConnection.java
@@ -228,10 +228,18 @@ public class StoreConnection
         StoreConnection sConn = cache.get(location) ;
         if (sConn != null) 
             return sConn ;
-        DatasetGraphTDB dsg = DatasetBuilderStd.create(location, params) ;
+        DatasetGraphTDB dsg = build(location, params) ;
         sConn = _makeAndCache(dsg) ;
         return sConn ;
     }
+    
+    /**
+     * Build storage {@link DatasetGraphTDB}.
+     * This operation is the primitive that creates the storage-level DatasetGraphTDB.
+     */
+    private static DatasetGraphTDB build(Location location, StoreParams params) {
+        return DatasetBuilderStd.create(location, params) ;
+    }
 
     /** Make a StoreConnection based on any StoreParams at the location or the system defaults.
*/
     public static StoreConnection make(Location location) {

http://git-wip-us.apache.org/repos/asf/jena/blob/60131204/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBMaker.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBMaker.java b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBMaker.java
index 2d4acde..67fa12d 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBMaker.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBMaker.java
@@ -18,9 +18,11 @@
 
 package org.apache.jena.tdb.sys;
 
+import org.apache.jena.sparql.core.DatasetGraph;
 import org.apache.jena.tdb.StoreConnection ;
+import org.apache.jena.tdb.TDBFactory;
 import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.setup.DatasetBuilderStd ;
+import org.apache.jena.tdb.setup.DatasetBuilderStd;
 import org.apache.jena.tdb.setup.StoreParams ;
 import org.apache.jena.tdb.store.DatasetGraphTDB ;
 import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
@@ -29,7 +31,7 @@ import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
 
 public class TDBMaker
 {
-    // ---- Transactional
+    // ---- Transactional dataset maker.
     // This hides details from the top level TDB Factory (e.g. for testing)
 
     /** Create a DatasetGraph that supports transactions */
@@ -50,24 +52,42 @@ public class TDBMaker
         return createDatasetGraphTransaction(Location.mem()) ;
     }
 
-    private static DatasetGraphTransaction _create(Location location) {
-        // No need to cache StoreConnection does all that.
-        return new DatasetGraphTransaction(location) ;
-    }
-
+    /**
+     * Release a {@code Location}.
+     * Do not use a {@code Dataset} at this location without
+     * remaking it via {@link TDBFactory}.
+     */
     public static void releaseLocation(Location location) {
         StoreConnection.release(location) ;
     }
 
+    /** 
+     * Reset the making and caching of datasets.
+     * Applications should not use this operation.
+     * All dataset must be rebuild with {@link TDBFactory}
+     * after calling this operation.
+     * Use {@link TDBFactory#release(DatasetGraph)} with care.  
+     * @deprecated
+     */
+    @Deprecated
     public static void reset() {
         StoreConnection.reset() ;
     }
     
+    // Make a DatasetGraphTransaction
+    private static DatasetGraphTransaction _create(Location location) {
+        // No need to cache StoreConnection does all that.
+        return new DatasetGraphTransaction(location) ;
+    }
+
     // ---- Raw non-transactional
-    /** Create a non-transactional TDB dataset graph.
-     * Bypasses StoreConnection caching. 
-     * <b>Use at your own risk.</b> 
+    /** 
+     * Create a non-transactional TDB dataset graph.
+     * <b>Use at your own risk.</b>
+     * <i>This function does not attempt to share databases at the same location.</i>

+     * @deprecated Use {@link TDBFactory} or {@link StoreConnection}.
      */
+    @Deprecated
     public static DatasetGraphTDB createDatasetGraphTDB(Location loc, StoreParams params)
     { return DatasetBuilderStd.create(loc, params) ; }
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/60131204/jena-tdb/src/test/java/org/apache/jena/tdb/TestTDBFactory.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/TestTDBFactory.java b/jena-tdb/src/test/java/org/apache/jena/tdb/TestTDBFactory.java
index 35853b7..22c1a5e 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/TestTDBFactory.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/TestTDBFactory.java
@@ -38,74 +38,69 @@ public class TestTDBFactory extends BaseTest
     static Quad quad1 = SSE.parseQuad("(_ <s> <p> 1)") ;
     static Quad quad2 = SSE.parseQuad("(_ <s> <p> 1)") ;
     
-    @Before public void before()
-    {
-        StoreConnection.reset() ;
-        FileOps.clearDirectory(DIR) ; 
+    @Before
+    public void before() {
+        StoreConnection.reset();
+        FileOps.clearDirectory(DIR);
     }
-    
-    @After public void after()
-    {
-        FileOps.clearDirectory(DIR) ; 
+
+    @After
+    public void after() {
+        FileOps.clearDirectory(DIR);
     }
-    
-    @Test public void testTDBFactory1()
-    {
-        TDBMaker.reset() ;
-        DatasetGraph dg1 = TDBFactory.createDatasetGraph(Location.mem("FOO")) ;
-        DatasetGraph dg2 = TDBFactory.createDatasetGraph(Location.mem("FOO")) ;
-        dg1.add(quad1) ;
-        assertTrue(dg2.contains(quad1)) ;
+
+    @Test
+    public void testTDBFactory1() {
+        DatasetGraph dg1 = TDBFactory.createDatasetGraph(Location.mem("FOO"));
+        DatasetGraph dg2 = TDBFactory.createDatasetGraph(Location.mem("FOO"));
+        dg1.add(quad1);
+        assertTrue(dg2.contains(quad1));
     }
-    
-    @Test public void testTDBFactory2()
-    {
-        TDBMaker.reset() ;
+
+    @Test
+    public void testTDBFactory2() {
         // The unnamed location is unique each time.
-        DatasetGraph dg1 = TDBFactory.createDatasetGraph(Location.mem()) ;
-        DatasetGraph dg2 = TDBFactory.createDatasetGraph(Location.mem()) ;
-        dg1.add(quad1) ;
-        assertFalse(dg2.contains(quad1)) ;
+        DatasetGraph dg1 = TDBFactory.createDatasetGraph(Location.mem());
+        DatasetGraph dg2 = TDBFactory.createDatasetGraph(Location.mem());
+        dg1.add(quad1);
+        assertFalse(dg2.contains(quad1));
     }
 
-    @Test public void testTDBMakerTxn1()
-    {
-        TDBMaker.reset() ;
-        DatasetGraph dg1 = TDBMaker.createDatasetGraphTransaction(Location.create(DIR)) ;
-        DatasetGraph dg2 = TDBMaker.createDatasetGraphTransaction(Location.create(DIR)) ;
-        
-        DatasetGraph dgBase1 = ((DatasetGraphTransaction)dg1).getBaseDatasetGraph() ;
-        DatasetGraph dgBase2 = ((DatasetGraphTransaction)dg2).getBaseDatasetGraph() ;
-        
-        assertSame(dgBase1, dgBase2) ;
+    @Test
+    public void testTDBMakerTxn1() {
+        DatasetGraph dg1 = TDBMaker.createDatasetGraphTransaction(Location.create(DIR));
+        DatasetGraph dg2 = TDBMaker.createDatasetGraphTransaction(Location.create(DIR));
+
+        DatasetGraph dgBase1 = ((DatasetGraphTransaction)dg1).getBaseDatasetGraph();
+        DatasetGraph dgBase2 = ((DatasetGraphTransaction)dg2).getBaseDatasetGraph();
+
+        assertSame(dgBase1, dgBase2);
     }
-    
-    @Test public void testTDBMakerTxn2()
-    {
+
+    @Test
+    public void testTDBMakerTxn2() {
         // Named memory locations
-        TDBMaker.reset() ;
-        DatasetGraph dg1 = TDBMaker.createDatasetGraphTransaction(Location.mem("FOO")) ;
-        DatasetGraph dg2 = TDBMaker.createDatasetGraphTransaction(Location.mem("FOO")) ;
-        
-        DatasetGraph dgBase1 = ((DatasetGraphTransaction)dg1).getBaseDatasetGraph() ;
-        DatasetGraph dgBase2 = ((DatasetGraphTransaction)dg2).getBaseDatasetGraph() ;
-        
-        assertSame(dgBase1, dgBase2) ;
+        DatasetGraph dg1 = TDBMaker.createDatasetGraphTransaction(Location.mem("FOO"));
+        DatasetGraph dg2 = TDBMaker.createDatasetGraphTransaction(Location.mem("FOO"));
+
+        DatasetGraph dgBase1 = ((DatasetGraphTransaction)dg1).getBaseDatasetGraph();
+        DatasetGraph dgBase2 = ((DatasetGraphTransaction)dg2).getBaseDatasetGraph();
+
+        assertSame(dgBase1, dgBase2);
     }
-    
-    @Test public void testTDBMakerTxn3()
-    {
+
+    @Test
+    public void testTDBMakerTxn3() {
         // Un-named memory locations
-        TDBMaker.reset() ;
-        DatasetGraph dg1 = TDBMaker.createDatasetGraphTransaction(Location.mem()) ;
-        DatasetGraph dg2 = TDBMaker.createDatasetGraphTransaction(Location.mem()) ;
-        
-        DatasetGraph dgBase1 = ((DatasetGraphTransaction)dg1).getBaseDatasetGraph() ;
-        DatasetGraph dgBase2 = ((DatasetGraphTransaction)dg2).getBaseDatasetGraph() ;
-        
-        assertNotSame(dgBase1, dgBase2) ;
+        DatasetGraph dg1 = TDBMaker.createDatasetGraphTransaction(Location.mem());
+        DatasetGraph dg2 = TDBMaker.createDatasetGraphTransaction(Location.mem());
+
+        DatasetGraph dgBase1 = ((DatasetGraphTransaction)dg1).getBaseDatasetGraph();
+        DatasetGraph dgBase2 = ((DatasetGraphTransaction)dg2).getBaseDatasetGraph();
+
+        assertNotSame(dgBase1, dgBase2);
     }
-    
+
     @Test public void testTDBFresh01() {
         boolean b = TDBFactory.inUseLocation(DIR) ;
         assertFalse("Expect false before any creation attempted", b) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/60131204/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java b/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
index 0ebf6ef..71a11ff 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/store/TestLoader.java
@@ -34,7 +34,7 @@ import org.apache.jena.tdb.ConfigTest ;
 import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.TDBLoader ;
 import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.sys.TDBMaker ;
+import org.apache.jena.tdb.setup.DatasetBuilderStd;
 import org.junit.AfterClass ;
 import org.junit.BeforeClass ;
 import org.junit.Test ;
@@ -60,7 +60,7 @@ public class TestLoader extends BaseTest {
     }
 
     static DatasetGraphTDB fresh() {
-        return TDBMaker.createDatasetGraphTDB(Location.mem(), null) ;
+        return DatasetBuilderStd.create(Location.mem()) ;
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/jena/blob/60131204/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransRestart.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransRestart.java
b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransRestart.java
index e05cbd3..ce1559a 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransRestart.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/transaction/TestTransRestart.java
@@ -33,10 +33,10 @@ import org.apache.jena.tdb.base.block.FileMode ;
 import org.apache.jena.tdb.base.file.FileFactory ;
 import org.apache.jena.tdb.base.file.Location ;
 import org.apache.jena.tdb.base.objectfile.ObjectFile ;
+import org.apache.jena.tdb.setup.DatasetBuilderStd;
 import org.apache.jena.tdb.store.DatasetGraphTDB ;
 import org.apache.jena.tdb.sys.Names ;
 import org.apache.jena.tdb.sys.SystemTDB ;
-import org.apache.jena.tdb.sys.TDBMaker ;
 import org.junit.After ;
 import org.junit.Before ;
 import org.junit.Test ;
@@ -70,14 +70,13 @@ public class TestTransRestart extends BaseTest {
         cleanup() ;
     }
     
-    private static DatasetGraphTDB createPlain(Location location) { return TDBMaker.createDatasetGraphTDB(location,
null) ; }
+    private static DatasetGraphTDB createPlain(Location location) { return DatasetBuilderStd.create(location)
; }
     
     private void setupPlain() {
         // Make without transactions.
         DatasetGraphTDB dsg = createPlain(location) ;
         dsg.add(quad1) ; 
         dsg.close() ;
-        StoreConnection.release(location) ; 
         return ;
     }
 


Mime
View raw message