You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2014/11/10 11:53:15 UTC

[10/50] [abbrv] jena git commit: StoreParams -- syntax naming style is "tdb.a_b_c"

StoreParams -- syntax naming style is "tdb.a_b_c"

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

Branch: refs/heads/JENA-507
Commit: 7f3b9c60e3f83fbcfaca587be7bc0de82ef491b8
Parents: 3f16231
Author: Andy Seaborne <an...@apache.org>
Authored: Tue Nov 4 14:11:03 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Tue Nov 4 14:11:03 2014 +0000

----------------------------------------------------------------------
 .../hpl/jena/tdb/setup/DatasetBuilderBasic.java | 14 +--
 .../hpl/jena/tdb/setup/StoreParamsBuilder.java  | 73 ++++++++--------
 .../hp/hpl/jena/tdb/setup/StoreParamsCodec.java | 92 ++++++++++++--------
 .../hp/hpl/jena/tdb/setup/TestStoreParams.java  |  8 +-
 4 files changed, 103 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/7f3b9c60/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderBasic.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderBasic.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderBasic.java
index ffeb55c..0597652 100644
--- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderBasic.java
+++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/DatasetBuilderBasic.java
@@ -45,7 +45,7 @@ import com.hp.hpl.jena.tdb.sys.DatasetControlMRSW ;
  * @see DatasetBuilderStd
  */ 
 
-public class DatasetBuilderBasic //implements DatasetBuilder
+/*public*/ class DatasetBuilderBasic //implements DatasetBuilder
 {
     private static final Logger log = LoggerFactory.getLogger(DatasetBuilderBasic.class) ;
     
@@ -89,9 +89,9 @@ public class DatasetBuilderBasic //implements DatasetBuilder
         return dsg ;
     }
     
-    protected DatasetControl createConcurrencyPolicy() { return new DatasetControlMRSW() ; }
+    private DatasetControl createConcurrencyPolicy() { return new DatasetControlMRSW() ; }
     
-    protected ReorderTransformation chooseReorderTransformation(Location location)
+    private ReorderTransformation chooseReorderTransformation(Location location)
     {    
         return DatasetBuilderStd.chooseOptimizer(location) ;
     }
@@ -106,7 +106,7 @@ public class DatasetBuilderBasic //implements DatasetBuilder
     }
     
     // ======== Dataset level
-    protected TripleTable makeTripleTable(Location location, NodeTable nodeTable, DatasetControl policy)
+    private TripleTable makeTripleTable(Location location, NodeTable nodeTable, DatasetControl policy)
     {    
         String primary = params.getPrimaryIndexTriples() ;
         String[] indexes = params.getTripleIndexes() ;
@@ -123,7 +123,7 @@ public class DatasetBuilderBasic //implements DatasetBuilder
         return tripleTable ;
     }
     
-    protected QuadTable makeQuadTable(Location location, NodeTable nodeTable, DatasetControl policy)
+    private QuadTable makeQuadTable(Location location, NodeTable nodeTable, DatasetControl policy)
     {    
         String primary = params.getPrimaryIndexQuads() ;
         String[] indexes = params.getQuadIndexes() ;
@@ -140,7 +140,7 @@ public class DatasetBuilderBasic //implements DatasetBuilder
         return quadTable ;
     }
 
-    protected DatasetPrefixesTDB makePrefixTable(Location location, DatasetControl policy)
+    private DatasetPrefixesTDB makePrefixTable(Location location, DatasetControl policy)
     {    
         String primary = params.getPrimaryIndexPrefix() ;
         String[] indexes = params.getPrefixIndexes() ;
@@ -180,7 +180,7 @@ public class DatasetBuilderBasic //implements DatasetBuilder
     }
 
     // ----
-    protected TupleIndex makeTupleIndex(Location location, String name, String primary, String indexOrder)
+    private TupleIndex makeTupleIndex(Location location, String name, String primary, String indexOrder)
     {
         // Commonly,  name == indexOrder.
         // FileSet

http://git-wip-us.apache.org/repos/asf/jena/blob/7f3b9c60/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsBuilder.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsBuilder.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsBuilder.java
index 4c2858b..ca039c7 100644
--- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsBuilder.java
+++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsBuilder.java
@@ -26,62 +26,63 @@ public class StoreParamsBuilder {
     // Initial values are the system defaults.
     
     /** Database and query configuration */ 
+    // Key names are the base name -  encode/decode may add a prefix.
     
-    // public static String fFileMode             = "FileMode" ;
-    private FileMode     fileMode              = SystemTDB.fileMode() ;
+    public static final String fFileMode             = "file_mode" ;
+    private FileMode           fileMode              = SystemTDB.fileMode() ;
 
-    // public static String fReadCacheSize        = "blockReadCacheSize" ;
-    private int          blockReadCacheSize    = SystemTDB.BlockReadCacheSize ;
+    public static final String fBlockReadCacheSize   = "block_read_cache_size" ;
+    private int                blockReadCacheSize    = SystemTDB.BlockReadCacheSize ;
 
-    // public static String fWriteCacheSize       = "blockWriteCacheSize" ;
-    private int          blockWriteCacheSize   = SystemTDB.BlockWriteCacheSize ;
+    public static final String fBlockWriteCacheSize  = "block_write_cache_size" ;
+    private int                blockWriteCacheSize   = SystemTDB.BlockWriteCacheSize ;
 
-    // public static String fNode2NodeIdCacheSize = "Node2NodeIdCacheSize" ;
-    private int          Node2NodeIdCacheSize  = SystemTDB.Node2NodeIdCacheSize ;
+    public static final String fNode2NodeIdCacheSize = "node2nodeid_cache_size" ;
+    private int                Node2NodeIdCacheSize  = SystemTDB.Node2NodeIdCacheSize ;
 
-    // public static String fNodeId2NodeCacheSize = "NodeId2NodeCacheSize" ;
-    private int          NodeId2NodeCacheSize  = SystemTDB.NodeId2NodeCacheSize ;
+    public static final String fNodeId2NodeCacheSize = "nodeid2node_cache_size" ;
+    private int                NodeId2NodeCacheSize  = SystemTDB.NodeId2NodeCacheSize ;
 
-    // public static String fNodeMissCacheSize    = "NodeMissCacheSize" ;
-    private int          NodeMissCacheSize     = SystemTDB.NodeMissCacheSize ;
+    public static final String fNodeMissCacheSize    = "node_miss_cache_size" ;
+    private int                NodeMissCacheSize     = SystemTDB.NodeMissCacheSize ;
 
     /** Database layout - ignored after a database is created */
 
-    // public static String fBlockSize            = "blockSize" ;
-    private int          blockSize             = SystemTDB.BlockSize ;
+    public static final String fBlockSize            = "block_size" ;
+    private int                blockSize             = SystemTDB.BlockSize ;
 
-    // public static String fIndexNode2Id         = "indexNode2Id" ;
-    private String       indexNode2Id          = Names.indexNode2Id ;
+    public static final String fIndexNode2Id         = "index_node2id" ;
+    private String             indexNode2Id          = Names.indexNode2Id ;
 
-    // public static String fIndexId2Node         = "indexId2Node" ;
-    private String       indexId2Node          = Names.indexId2Node ;
+    public static final String fIndexId2Node         = "index_id2node" ;
+    private String             indexId2Node          = Names.indexId2Node ;
 
-    // public static String fPrimaryIndexTriples  = "primaryIndexTriples" ;
-    private String       primaryIndexTriples   = Names.primaryIndexTriples ;
+    public static final String fPrimaryIndexTriples  = "triple_index_primary" ;
+    private String             primaryIndexTriples   = Names.primaryIndexTriples ;
 
-    // public static String fTripleIndexes        = "tripleIndexes" ;
-    private String[]     tripleIndexes         = Names.tripleIndexes ;
+    public static final String fTripleIndexes        = "triple_indexes" ;
+    private String[]           tripleIndexes         = Names.tripleIndexes ;
 
-    // public static String fPrimaryIndexQuads    = "primaryIndexQuads" ;
-    private String       primaryIndexQuads     = Names.primaryIndexQuads ;
+    public static final String fPrimaryIndexQuads    = "quad_index_primary" ;
+    private String             primaryIndexQuads     = Names.primaryIndexQuads ;
 
-    // public static String fQuadIndexes          = "quadIndexes" ;
-    private String[]     quadIndexes           = Names.quadIndexes ;
+    public static final String fQuadIndexes          = "quad_indexes" ;
+    private String[]           quadIndexes           = Names.quadIndexes ;
 
-    // public static String fPrimaryIndexPrefix   = "primaryIndexPrefix" ;
-    private String       primaryIndexPrefix    = Names.primaryIndexPrefix ;
+    public static final String fPrimaryIndexPrefix   = "prefix_index_primary" ;
+    private String             primaryIndexPrefix    = Names.primaryIndexPrefix ;
 
-    // public static String fPrefixIndexes        = "prefixIndexes" ;
-    private String[]     prefixIndexes         = Names.prefixIndexes ;
+    public static final String fPrefixIndexes        = "prefix_indexes" ;
+    private String[]           prefixIndexes         = Names.prefixIndexes ;
 
-    // public static String fIndexPrefix          = "indexPrefix" ;
-    private String       indexPrefix           = Names.indexPrefix ;
+    public static final String fIndexPrefix          = "file_prefix_index" ;
+    private String             indexPrefix           = Names.indexPrefix ;
 
-    // public static String fPrefixNode2Id        = "prefixNode2Id" ;
-    private String       prefixNode2Id         = Names.prefixNode2Id ;
+    public static final String fPrefixNode2Id        = "file_prefix_nodeid" ;
+    private String             prefixNode2Id         = Names.prefixNode2Id ;
 
-    // public static String fPrefixId2Node        = "prefixId2Node" ;
-    private String       prefixId2Node         = Names.prefixId2Node ;
+    public static final String fPrefixId2Node        = "file_prefix_id2node" ;
+    private String             prefixId2Node         = Names.prefixId2Node ;
 
     public static StoreParamsBuilder create() { return new StoreParamsBuilder() ; }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/7f3b9c60/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsCodec.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsCodec.java b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsCodec.java
index a3df300..b4781c4 100644
--- a/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsCodec.java
+++ b/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/setup/StoreParamsCodec.java
@@ -26,6 +26,8 @@ import com.hp.hpl.jena.sparql.util.Utils ;
 import com.hp.hpl.jena.tdb.TDBException ;
 import com.hp.hpl.jena.tdb.base.block.FileMode ;
 
+import static com.hp.hpl.jena.tdb.setup.StoreParamsBuilder.* ;
+
 /** Encode and decode {@linkplain StoreParams} */ 
 public class StoreParamsCodec {
     
@@ -33,51 +35,67 @@ public class StoreParamsCodec {
         JsonBuilder builder = new JsonBuilder() ;
         builder.startObject("StoreParams") ;    // "StoreParams" is an internal alignment marker - not in the JSON.
         
-        encode(builder, "tdb.FileMode",                 params.getFileMode().name()) ;
-        encode(builder, "tdb.BlockSize",                params.getBlockSize()) ;
-        encode(builder, "tdb.BlockReadCacheSize",       params.getBlockReadCacheSize()) ;
-        encode(builder, "tdb.BlockWriteCacheSize",      params.getBlockWriteCacheSize()) ;
-        encode(builder, "tdb.Node2NodeIdCacheSize",     params.getNode2NodeIdCacheSize()) ;
-        encode(builder, "tdb.NodeId2NodeCacheSize",     params.getNodeId2NodeCacheSize()) ;
-        encode(builder, "tdb.NodeMissCacheSize",        params.getNodeMissCacheSize()) ;
-        encode(builder, "tdb.IndexNode2Id",             params.getIndexNode2Id()) ;
-        encode(builder, "tdb.IndexId2Node",             params.getIndexId2Node()) ;
-        encode(builder, "tdb.PrimaryIndexTriples",      params.getPrimaryIndexTriples()) ;
-        encode(builder, "tdb.TripleIndexes",            params.getTripleIndexes()) ;
-        encode(builder, "tdb.PrimaryIndexQuads",        params.getPrimaryIndexQuads()) ;
-        encode(builder, "tdb.QuadIndexes",              params.getQuadIndexes()) ;
-        encode(builder, "tdb.PrimaryIndexPrefix",       params.getPrimaryIndexPrefix()) ;
-        encode(builder, "tdb.PrefixIndexes",            params.getPrefixIndexes()) ;
-        encode(builder, "tdb.IndexPrefix",              params.getIndexPrefix()) ;
-        encode(builder, "tdb.PrefixNode2Id",            params.getPrefixNode2Id()) ;
-        encode(builder, "tdb.PrefixId2Node",            params.getPrefixId2Node()) ;
+        encode(builder, key(fFileMode),                 params.getFileMode().name()) ;
+        encode(builder, key(fBlockSize),                params.getBlockSize()) ;
+        encode(builder, key(fBlockReadCacheSize),       params.getBlockReadCacheSize()) ;
+        encode(builder, key(fBlockWriteCacheSize),      params.getBlockWriteCacheSize()) ;
+        encode(builder, key(fNode2NodeIdCacheSize),     params.getNode2NodeIdCacheSize()) ;
+        encode(builder, key(fNodeId2NodeCacheSize),     params.getNodeId2NodeCacheSize()) ;
+        encode(builder, key(fNodeMissCacheSize),        params.getNodeMissCacheSize()) ;
+        encode(builder, key(fIndexNode2Id),             params.getIndexNode2Id()) ;
+        encode(builder, key(fIndexId2Node),             params.getIndexId2Node()) ;
+        encode(builder, key(fPrimaryIndexTriples),      params.getPrimaryIndexTriples()) ;
+        encode(builder, key(fTripleIndexes),            params.getTripleIndexes()) ;
+        encode(builder, key(fPrimaryIndexQuads),        params.getPrimaryIndexQuads()) ;
+        encode(builder, key(fQuadIndexes),              params.getQuadIndexes()) ;
+        encode(builder, key(fPrimaryIndexPrefix),       params.getPrimaryIndexPrefix()) ;
+        encode(builder, key(fPrefixIndexes),            params.getPrefixIndexes()) ;
+        encode(builder, key(fIndexPrefix),              params.getIndexPrefix()) ;
+        encode(builder, key(fPrefixNode2Id),            params.getPrefixNode2Id()) ;
+        encode(builder, key(fPrefixId2Node),            params.getPrefixId2Node()) ;
+        
         builder.finishObject("StoreParams") ;
         return (JsonObject)builder.build() ;
     }
 
+    private static final String jsonKeyPrefix= "tdb." ;
+    
+    private static String key(String string) {
+        if ( string.startsWith(jsonKeyPrefix))
+            throw new TDBException("Key name already starts with '"+jsonKeyPrefix+"'") ;
+        return jsonKeyPrefix+string ;
+    }
+
+    private static String unkey(String string) {
+        if ( ! string.startsWith(jsonKeyPrefix) )
+            throw new TDBException("JSON key name does not start with '"+jsonKeyPrefix+"'") ;
+        return string.substring(jsonKeyPrefix.length()) ;
+    }
+
     public static StoreParams decode(JsonObject json) {
         StoreParamsBuilder builder = StoreParamsBuilder.create() ;
         
         for ( String key : json.keys() ) {
-            switch(key) {
-                case "tdb.FileMode" :               builder.fileMode(FileMode.valueOf(getString(json, key))) ; break ;
-                case "tdb.BlockSize":               builder.blockSize(getInt(json, key)) ; break ;
-                case "tdb.BlockReadCacheSize":      builder.blockReadCacheSize(getInt(json, key)) ; break ;
-                case "tdb.BlockWriteCacheSize":     builder.blockWriteCacheSize(getInt(json, key)) ; break ;
-                case "tdb.Node2NodeIdCacheSize":    builder.node2NodeIdCacheSize(getInt(json, key)) ; break ;
-                case "tdb.NodeId2NodeCacheSize":    builder.nodeId2NodeCacheSize(getInt(json, key)) ; break ;
-                case "tdb.NodeMissCacheSize":       builder.nodeMissCacheSize(getInt(json, key)) ; break ;
-                case "tdb.IndexNode2Id":            builder.indexNode2Id(getString(json, key)) ; break ;
-                case "tdb.IndexId2Node":            builder.indexId2Node(getString(json, key)) ; break ;
-                case "tdb.PrimaryIndexTriples":     builder.primaryIndexTriples(getString(json, key)) ; break ;
-                case "tdb.TripleIndexes":           builder.tripleIndexes(getStringArray(json, key)) ; break ;
-                case "tdb.PrimaryIndexQuads":       builder.primaryIndexQuads(getString(json, key)) ; break ;
-                case "tdb.QuadIndexes":             builder.quadIndexes(getStringArray(json, key)) ; break ;
-                case "tdb.PrimaryIndexPrefix":      builder.primaryIndexPrefix(getString(json, key)) ; break ;
-                case "tdb.PrefixIndexes":           builder.prefixIndexes(getStringArray(json, key)) ; break ;
-                case "tdb.IndexPrefix":             builder.indexPrefix(getString(json, key)) ; break ;
-                case "tdb.PrefixNode2Id":           builder.prefixNode2Id(getString(json, key)) ; break ;
-                case "tdb.PrefixId2Node":           builder.prefixId2Node(getString(json, key)) ; break ;
+            String short_key = unkey(key) ;
+            switch(short_key) {
+                case fFileMode :               builder.fileMode(FileMode.valueOf(getString(json, key))) ;   break ;
+                case fBlockSize:               builder.blockSize(getInt(json, key)) ;                       break ;
+                case fBlockReadCacheSize:      builder.blockReadCacheSize(getInt(json, key)) ;              break ;
+                case fBlockWriteCacheSize:     builder.blockWriteCacheSize(getInt(json, key)) ;             break ;
+                case fNode2NodeIdCacheSize:    builder.node2NodeIdCacheSize(getInt(json, key)) ;            break ;
+                case fNodeId2NodeCacheSize:    builder.nodeId2NodeCacheSize(getInt(json, key)) ;            break ;
+                case fNodeMissCacheSize:       builder.nodeMissCacheSize(getInt(json, key)) ;               break ;
+                case fIndexNode2Id:            builder.indexNode2Id(getString(json, key)) ;                 break ;
+                case fIndexId2Node:            builder.indexId2Node(getString(json, key)) ;                 break ;
+                case fPrimaryIndexTriples:     builder.primaryIndexTriples(getString(json, key)) ;          break ;
+                case fTripleIndexes:           builder.tripleIndexes(getStringArray(json, key)) ;           break ;
+                case fPrimaryIndexQuads:       builder.primaryIndexQuads(getString(json, key)) ;            break ;
+                case fQuadIndexes:             builder.quadIndexes(getStringArray(json, key)) ;             break ;
+                case fPrimaryIndexPrefix:      builder.primaryIndexPrefix(getString(json, key)) ;           break ;
+                case fPrefixIndexes:           builder.prefixIndexes(getStringArray(json, key)) ;           break ;
+                case fIndexPrefix:             builder.indexPrefix(getString(json, key)) ;                  break ;
+                case fPrefixNode2Id:           builder.prefixNode2Id(getString(json, key)) ;                break ;
+                case fPrefixId2Node:           builder.prefixId2Node(getString(json, key)) ;                break ;
                 default:
                     throw new TDBException("StoreParams key no recognized: "+key) ;
             }

http://git-wip-us.apache.org/repos/asf/jena/blob/7f3b9c60/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/setup/TestStoreParams.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/setup/TestStoreParams.java b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/setup/TestStoreParams.java
index 1be0924..6612be9 100644
--- a/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/setup/TestStoreParams.java
+++ b/jena-tdb/src/test/java/com/hp/hpl/jena/tdb/setup/TestStoreParams.java
@@ -57,7 +57,7 @@ public class TestStoreParams extends BaseTest {
     }
 
     @Test public void store_params_05() {
-        String xs = "{ \"tdb.BlockSize\": 2048 }" ;
+        String xs = "{ \"tdb.block_size\": 2048 }" ;
         JsonObject x = JSON.parse(xs) ;
         StoreParams paramsExpected = StoreParamsBuilder.create().blockSize(2048).build() ;
         StoreParams paramsActual = StoreParamsCodec.decode(x) ;
@@ -65,7 +65,7 @@ public class TestStoreParams extends BaseTest {
     }
 
     @Test public void store_params_06() {
-        String xs = "{ \"tdb.FileMode\": \"direct\" , \"tdb.BlockSize\": 2048 }" ;
+        String xs = "{ \"tdb.file_mode\": \"direct\" , \"tdb.block_size\": 2048 }" ;
         JsonObject x = JSON.parse(xs) ;
         StoreParams paramsExpected = StoreParamsBuilder.create().blockSize(2048).fileMode(FileMode.direct).build() ;
         StoreParams paramsActual = StoreParamsCodec.decode(x) ;
@@ -73,7 +73,7 @@ public class TestStoreParams extends BaseTest {
     }
 
     @Test public void store_params_07() {
-        String xs = "{ \"tdb.TripleIndexes\" : [ \"POS\" , \"PSO\"] } " ; 
+        String xs = "{ \"tdb.triple_indexes\" : [ \"POS\" , \"PSO\"] } " ; 
         JsonObject x = JSON.parse(xs) ;
         StoreParams params = StoreParamsCodec.decode(x) ;
         String[] expected =  { "POS" , "PSO" } ;
@@ -82,7 +82,7 @@ public class TestStoreParams extends BaseTest {
 
     @Test(expected=TDBException.class)
     public void store_params_08() {
-        String xs = "{ \"tdb.TriplesIndexes\" : [ \"POS\" , \"PSO\"] } " ; // Misspelt. 
+        String xs = "{ \"tdb.triples_indexes\" : [ \"POS\" , \"PSO\"] } " ; // Misspelt. 
         JsonObject x = JSON.parse(xs) ;
         StoreParams params = StoreParamsCodec.decode(x) ;
         String[] expected =  { "POS" , "PSO" } ;