Repository: jena
Updated Branches:
  refs/heads/master d6adcc177 -> 6ef2a1fa3


Add (initially private) test for whether a location is in use by TDB.
Clean-up.

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

Branch: refs/heads/master
Commit: 5d3f29cfe0c132861cbd4d3173d994a54c461593
Parents: 4d1a711
Author: Andy Seaborne <[email protected]>
Authored: Thu Jul 30 18:45:07 2015 +0100
Committer: Andy Seaborne <[email protected]>
Committed: Thu Jul 30 18:45:07 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/jena/tdb/TDBFactory.java    |  17 +-
 .../jena/tdb/setup/DatasetBuilderBasic.java     | 197 -------------------
 .../jena/tdb/setup/DatasetBuilderStd.java       |  27 +--
 .../org/apache/jena/tdb/sys/TDBInternal.java    | 128 +++++++-----
 .../java/org/apache/jena/tdb/sys/TDBMaker.java  |  92 +++------
 5 files changed, 113 insertions(+), 348 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/5d3f29cf/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java 
b/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
index adfdf6d..cf2f94a 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/TDBFactory.java
@@ -26,6 +26,7 @@ import org.apache.jena.tdb.assembler.VocabTDB ;
 import org.apache.jena.tdb.base.file.Location ;
 import org.apache.jena.tdb.setup.StoreParams ;
 import org.apache.jena.tdb.store.DatasetGraphTDB ;
+import org.apache.jena.tdb.sys.TDBInternal ;
 import org.apache.jena.tdb.sys.TDBMaker ;
 import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
 
@@ -92,16 +93,16 @@ public class TDBFactory
         TDBMaker.releaseLocation(location) ;
     }
 
-    /** Return the location of a dataset if it is backed by TDB, else null */ 
+    /** Test whether a dataset is backed by TDB. */ 
     public static boolean isBackedByTDB(Dataset dataset) {
         DatasetGraph dsg = dataset.asDatasetGraph() ;
         return isBackedByTDB(dsg) ;
     }
     
-    /** Return the location of a dataset if it is backed by TDB, else null */ 
+    /** Test whether a dataset is backed by TDB. */ 
     public static boolean isBackedByTDB(DatasetGraph datasetGraph) {
         if ( datasetGraph instanceof DatasetGraphTransaction )
-            // The swicthing "connection" for TDB 
+            // The switching "connection" for TDB 
             return true ;
         if ( datasetGraph instanceof DatasetGraphTDB )
             // A transaction or the base storage.
@@ -123,17 +124,21 @@ public class TDBFactory
             return ((DatasetGraphTransaction)datasetGraph).getLocation() ;
         return null ;
     }
+    
+    /** test whether a location has a TDB database (pragmatic test). */ 
+    private static boolean freshLocation(Location location) {
+        return TDBInternal.isNewDatabaseArea(location) ;
+    }
 
     /** Set the {@link StoreParams} for specific Location.
      *  This call must only be called before a dataset from Location
      *  is created. This operation should be used with care; bad choices
      *  of {@link StoreParams} can reduce performance.
      *  
-     *  <a href="http://jena.apache.org/documentation/tdb/store-paramters.html";
-     *  >See documentation</a>.
+     *  <a 
href="http://jena.apache.org/documentation/tdb/store-parameters.html";>See 
documentation</a>.
      *  
      *  @param location  The persistent storage location
-     *  @param params  StoreParams to use
+     *  @param params    StoreParams to use
      *  @throws IllegalStateException If the dataset has already been setup.
      */
     public static void setup(Location location, StoreParams params) {

http://git-wip-us.apache.org/repos/asf/jena/blob/5d3f29cf/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderBasic.java
----------------------------------------------------------------------
diff --git 
a/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderBasic.java 
b/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderBasic.java
deleted file mode 100644
index c52e3be..0000000
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderBasic.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/**
- * 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 org.apache.jena.tdb.setup;
-
-import org.apache.jena.atlas.lib.ColumnMap ;
-import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.query.ARQ ;
-import org.apache.jena.sparql.engine.main.QC ;
-import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
-import org.apache.jena.tdb.TDBException ;
-import org.apache.jena.tdb.base.file.FileSet ;
-import org.apache.jena.tdb.base.file.Location ;
-import org.apache.jena.tdb.index.IndexBuilder ;
-import org.apache.jena.tdb.index.RangeIndexBuilder ;
-import org.apache.jena.tdb.solver.OpExecutorTDB1 ;
-import org.apache.jena.tdb.store.* ;
-import org.apache.jena.tdb.store.nodetable.NodeTable ;
-import org.apache.jena.tdb.store.nodetupletable.NodeTupleTable ;
-import org.apache.jena.tdb.store.nodetupletable.NodeTupleTableConcrete ;
-import org.apache.jena.tdb.store.tupletable.TupleIndex ;
-import org.apache.jena.tdb.sys.DatasetControl ;
-import org.apache.jena.tdb.sys.DatasetControlMRSW ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-/** A general way to make TDB storage dataset graphs : not for transactional 
datasets.
- * Old code. Unused and made inaccessible.  Kept for now for reference.
- * @see DatasetBuilderStd
- */ 
-
-/*public*/ class DatasetBuilderBasic //implements DatasetBuilder
-{
-    private static final Logger log = 
LoggerFactory.getLogger(DatasetBuilderBasic.class) ;
-    
-    private NodeTableBuilder nodeTableBuilder ;
-    private TupleIndexBuilder tupleIndexBuilder ;
-    private StoreParams params ;
-    
-    private /*public*/ DatasetBuilderBasic(IndexBuilder indexBuilder, 
RangeIndexBuilder rangeIndexBuilder)
-    {
-        ObjectFileBuilder objectFileBuilder = new 
BuilderStdDB.ObjectFileBuilderStd()  ;
-        nodeTableBuilder    = new 
BuilderStdDB.NodeTableBuilderStd(indexBuilder, objectFileBuilder) ;
-        tupleIndexBuilder   = new 
BuilderStdDB.TupleIndexBuilderStd(rangeIndexBuilder) ;
-    }
-
-    //@Override public
-    private DatasetGraphTDB build(Location location, StoreParams config)
-    {
-        DatasetControl policy = createConcurrencyPolicy() ;
-        
-        params = config ;
-        if ( config == null )
-            params = StoreParams.getDftStoreParams() ;
-        
-        NodeTable nodeTable = makeNodeTable(location, 
params.getIndexNode2Id(), params.getIndexId2Node(),
-                                            -1, -1, -1) ; // No caches
-                                            // Small caches 
-                                            //10, 1000, 10) ;
-                                            //params.Node2NodeIdCacheSize, 
params.NodeId2NodeCacheSize, params.NodeMissCacheSize) ;
-        
-        //nodeTable = new NodeTableLogger(null, nodeTable) ;
-        
-        TripleTable tripleTable = makeTripleTable(location, nodeTable, policy) 
; 
-        QuadTable quadTable = makeQuadTable(location, nodeTable, policy) ;
-        DatasetPrefixesTDB prefixes = makePrefixTable(location, policy) ;
-        ReorderTransformation transform  = 
chooseReorderTransformation(location) ;
-        
-        DatasetGraphTDB dsg = new DatasetGraphTDB(tripleTable, quadTable, 
prefixes, transform, null) ;
-        // TDB does filter placement on BGPs itself.
-        dsg.getContext().set(ARQ.optFilterPlacementBGP, false);
-        QC.setFactory(dsg.getContext(), OpExecutorTDB1.OpExecFactoryTDB) ;
-        return dsg ;
-    }
-    
-    private DatasetControl createConcurrencyPolicy() { return new 
DatasetControlMRSW() ; }
-    
-    private ReorderTransformation chooseReorderTransformation(Location 
location)
-    {    
-        return DatasetBuilderStd.chooseOptimizer(location) ;
-    }
-
-    protected NodeTable makeNodeTable(Location location, String indexNode2Id, 
String indexId2Node, 
-                                      int sizeNode2NodeIdCache, int 
sizeNodeId2NodeCache, int sizeNodeMissCache)
-    {
-        FileSet fsNodeToId = new FileSet(location, indexNode2Id) ;
-        FileSet fsId2Node = new FileSet(location, indexId2Node) ;
-        NodeTable nt = nodeTableBuilder.buildNodeTable(fsNodeToId, fsId2Node, 
params) ;
-        return nt ;
-    }
-    
-    // ======== Dataset level
-    private TripleTable makeTripleTable(Location location, NodeTable 
nodeTable, DatasetControl policy)
-    {    
-        String primary = params.getPrimaryIndexTriples() ;
-        String[] indexes = params.getTripleIndexes() ;
-        
-        if ( indexes.length != 3 )
-            error(log, "Wrong number of triple table indexes: 
"+StrUtils.strjoin(",", indexes)) ;
-        log.debug("Triple table: "+primary+" :: "+StrUtils.strjoin(",", 
indexes)) ;
-        
-        TupleIndex tripleIndexes[] = makeTupleIndexes(location, primary, 
indexes) ;
-        
-        if ( tripleIndexes.length != indexes.length )
-            error(log, "Wrong number of triple table tuples indexes: 
"+tripleIndexes.length) ;
-        TripleTable tripleTable = new TripleTable(tripleIndexes, nodeTable, 
policy) ;
-        return tripleTable ;
-    }
-    
-    private QuadTable makeQuadTable(Location location, NodeTable nodeTable, 
DatasetControl policy)
-    {    
-        String primary = params.getPrimaryIndexQuads() ;
-        String[] indexes = params.getQuadIndexes() ;
-        
-        if ( indexes.length != 6 )
-            error(log, "Wrong number of quad table indexes: 
"+StrUtils.strjoin(",", indexes)) ;
-        
-        log.debug("Quad table: "+primary+" :: "+StrUtils.strjoin(",", 
indexes)) ;
-        
-        TupleIndex quadIndexes[] = makeTupleIndexes(location, primary, 
indexes) ;
-        if ( quadIndexes.length != indexes.length )
-            error(log, "Wrong number of quad table tuples indexes: 
"+quadIndexes.length) ;
-        QuadTable quadTable = new QuadTable(quadIndexes, nodeTable, policy) ;
-        return quadTable ;
-    }
-
-    private DatasetPrefixesTDB makePrefixTable(Location location, 
DatasetControl policy)
-    {    
-        String primary = params.getPrimaryIndexPrefix() ;
-        String[] indexes = params.getPrefixIndexes() ;
-        
-        TupleIndex prefixIndexes[] = makeTupleIndexes(location, primary, 
indexes, new String[]{params.getIndexPrefix()}) ;
-        if ( prefixIndexes.length != 1 )
-            error(log, "Wrong number of triple table tuples indexes: 
"+prefixIndexes.length) ;
-        
-        String pnNode2Id = params.getPrefixNode2Id() ;
-        String pnId2Node = params.getPrefixId2Node() ;
-        
-        // No cache - the prefix mapping is a cache
-        NodeTable prefixNodes = makeNodeTable(location, pnNode2Id, pnId2Node, 
-1, -1, -1)  ;
-        NodeTupleTable prefixTable = new 
NodeTupleTableConcrete(primary.length(),
-                                                                prefixIndexes,
-                                                                prefixNodes, 
policy) ;
-        DatasetPrefixesTDB prefixes = new DatasetPrefixesTDB(prefixTable) ; 
-        log.debug("Prefixes: "+primary+" :: "+StrUtils.strjoin(",", indexes)) ;
-        return prefixes ;
-    }
-    
-    private TupleIndex[] makeTupleIndexes(Location location, String primary, 
String[] indexNames)
-    {
-        return makeTupleIndexes(location, primary, indexNames, indexNames) ;
-    }
-    
-    private TupleIndex[] makeTupleIndexes(Location location, String primary, 
String[] indexNames, String[] filenames)
-    {
-        if ( primary.length() != 3 && primary.length() != 4 )
-            error(log, "Bad primary key length: "+primary.length()) ;
-    
-        int indexRecordLen = primary.length()*NodeId.SIZE ;
-        TupleIndex indexes[] = new TupleIndex[indexNames.length] ;
-        for (int i = 0 ; i < indexes.length ; i++)
-            indexes[i] = makeTupleIndex(location, filenames[i], primary, 
indexNames[i]) ;
-        return indexes ;
-    }
-
-    // ----
-    private TupleIndex makeTupleIndex(Location location, String name, String 
primary, String indexOrder)
-    {
-        // Commonly,  name == indexOrder.
-        // FileSet
-        FileSet fs = new FileSet(location, name) ;
-        ColumnMap colMap = new ColumnMap(primary, indexOrder) ;
-        return tupleIndexBuilder.buildTupleIndex(fs, colMap, indexOrder, 
params) ;
-    }
-
-    private static void error(Logger log, String msg)
-    {
-        if ( log != null )
-            log.error(msg) ;
-        throw new TDBException(msg) ;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/5d3f29cf/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderStd.java
----------------------------------------------------------------------
diff --git 
a/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderStd.java 
b/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderStd.java
index 9b8a931..291a81a 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderStd.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/setup/DatasetBuilderStd.java
@@ -19,7 +19,6 @@
 package org.apache.jena.tdb.setup ;
 
 import java.io.File ;
-import java.io.FileFilter ;
 import java.util.Collections ;
 import java.util.HashMap ;
 import java.util.Map ;
@@ -84,7 +83,7 @@ public class DatasetBuilderStd implements DatasetBuilder {
         StoreParams locParams = StoreParamsCodec.read(location) ;
         StoreParams dftParams = StoreParams.getDftStoreParams() ;
         // This can write the chosen parameters if necessary (new database, 
appParams != null, locParams == null)
-        boolean newArea = isNewDatabaseArea(location) ;
+        boolean newArea = TDBInternal.isNewDatabaseArea(location) ;
         StoreParams params = Build.decideStoreParams(location, newArea, 
appParams, locParams, dftParams) ;
         DatasetBuilderStd x = new DatasetBuilderStd() ;
         x.standardSetup() ;
@@ -92,30 +91,6 @@ public class DatasetBuilderStd implements DatasetBuilder {
         return dsg ;
     }
     
-    /** Look at a directory and see if it is a new area */
-    private static boolean isNewDatabaseArea(Location location) {
-        if ( location.isMem() )
-            return true ;
-        File d = new File(location.getDirectoryPath()) ;
-        if ( !d.exists() )
-            return true ;
-        FileFilter ff = fileFilterNewDB ;
-        File[] entries = d.listFiles(ff) ;
-        return entries.length == 0 ;
-    }
-    
-    static FileFilter fileFilterNewDB  = (pathname)->{
-        String fn = pathname.getName() ;
-        if ( fn.equals(".") || fn.equals("..") )
-            return false ;
-        if ( pathname.isDirectory() )
-            return true ;
-
-        if ( fn.equals(StoreParamsConst.TDB_CONFIG_FILE) )
-            return false ;
-        return true ;
-    } ;
-
     public static DatasetGraphTDB create(StoreParams params) {
         // Memory version?
         return create(Location.mem(), params) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/5d3f29cf/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBInternal.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBInternal.java 
b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBInternal.java
index 5bd9e84..2a19c41 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBInternal.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/sys/TDBInternal.java
@@ -18,11 +18,17 @@
 
 package org.apache.jena.tdb.sys;
 
+import java.io.File ;
+import java.io.FileFilter ;
+
 import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.tdb.StoreConnection ;
 import org.apache.jena.tdb.TDBException ;
+import org.apache.jena.tdb.base.file.Location ;
+import org.apache.jena.tdb.setup.StoreParamsConst ;
 import org.apache.jena.tdb.store.DatasetGraphTDB ;
 import org.apache.jena.tdb.store.NodeId ;
 import org.apache.jena.tdb.store.nodetable.NodeTable ;
@@ -33,31 +39,28 @@ import 
org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
  */
 public class TDBInternal
 {
-    /** Return the NodeId for a node.
-     * Returns NodeId.NodeDoesNotExist when the node is not found. 
-     * Returns null when not a TDB-backed dataset.
+    /**
+     * Return the NodeId for a node. Returns NodeId.NodeDoesNotExist when the
+     * node is not found. Returns null when not a TDB-backed dataset.
      */
-    public static NodeId getNodeId(Dataset ds, Node node)
-    {
-        return  getNodeId(ds.asDatasetGraph(), node) ;
+    public static NodeId getNodeId(Dataset ds, Node node) {
+        return getNodeId(ds.asDatasetGraph(), node) ;
     }
-    
-    /** Return the NodeId for a node.
-     * Returns NodeId.NodeDoesNotExist when the node is not found. 
-     * Returns null when not a TDB-backed dataset.
+
+    /**
+     * Return the NodeId for a node. Returns NodeId.NodeDoesNotExist when the
+     * node is not found. Returns null when not a TDB-backed dataset.
      */
-    public static NodeId getNodeId(DatasetGraph ds, Node node)
-    {
+    public static NodeId getNodeId(DatasetGraph ds, Node node) {
         DatasetGraphTDB dsg = getDatasetGraphTDB(ds) ;
         return getNodeId(dsg, node) ;
     }
-    
-    /** Return the NodeId for a node.
-     * Returns NodeId.NodeDoesNotExist when the node is not found. 
-     * Returns null when not a TDB-backed dataset.
+
+    /**
+     * Return the NodeId for a node. Returns NodeId.NodeDoesNotExist when the
+     * node is not found. Returns null when not a TDB-backed dataset.
      */
-    public static NodeId getNodeId(DatasetGraphTDB dsg, Node node)
-    {
+    public static NodeId getNodeId(DatasetGraphTDB dsg, Node node) {
         if ( dsg == null )
             return null ;
         NodeTable nodeTable = 
dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;
@@ -65,28 +68,28 @@ public class TDBInternal
         return nodeId ;
     }
 
-    /** Return the node for a NodeId (if any).
-     *  Returns null if the NodeId does not exist in the dataset. 
+    /**
+     * Return the node for a NodeId (if any). Returns null if the NodeId does
+     * not exist in the dataset.
      */
-    public static Node getNode(Dataset ds, NodeId nodeId)
-    {
+    public static Node getNode(Dataset ds, NodeId nodeId) {
         return getNode(ds.asDatasetGraph(), nodeId) ;
     }
-    
-    /** Return the node for a NodeId (if any).
-     *  Returns null if the NodeId does not exist in the dataset. 
+
+    /**
+     * Return the node for a NodeId (if any). Returns null if the NodeId does
+     * not exist in the dataset.
      */
-    public static Node getNode(DatasetGraph ds, NodeId nodeId)
-    {
+    public static Node getNode(DatasetGraph ds, NodeId nodeId) {
         DatasetGraphTDB dsg = getDatasetGraphTDB(ds) ;
         return getNode(dsg, nodeId) ;
     }
 
-    /** Return the node for a NodeId (if any).
-     *  Returns null if the NodeId does not exist in the dataset. 
+    /**
+     * Return the node for a NodeId (if any). Returns null if the NodeId does
+     * not exist in the dataset.
      */
-    public static Node getNode(DatasetGraphTDB dsg, NodeId nodeId)
-    {
+    public static Node getNode(DatasetGraphTDB dsg, NodeId nodeId) {
         if ( dsg == null )
             return null ;
         NodeTable nodeTable = 
dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;
@@ -97,38 +100,63 @@ public class TDBInternal
     /**
      * Return the DatasetGraphTDB for a Dataset, or null.
      */
-    public static DatasetGraphTDB getDatasetGraphTDB(Dataset ds)
-    {
+    public static DatasetGraphTDB getDatasetGraphTDB(Dataset ds) {
         return getDatasetGraphTDB(ds.asDatasetGraph()) ;
     }
 
-    
     /**
-     * Return the DatasetGraphTDB for a DatasetGraph, or null.
-     * May not be up-to-date.
+     * Return the DatasetGraphTDB for a DatasetGraph, or null. May not be
+     * up-to-date.
      */
-    public static DatasetGraphTDB getDatasetGraphTDB(DatasetGraph dsg)
-    {
+    public static DatasetGraphTDB getDatasetGraphTDB(DatasetGraph dsg) {
         if ( dsg instanceof DatasetGraphTransaction )
             // Latest.
             return ((DatasetGraphTransaction)dsg).getDatasetGraphToQuery() ;
-            // Core.
-            //.getBaseDatasetGraph() ;
-        
+        // Core.
+        // .getBaseDatasetGraph() ;
+
         if ( dsg instanceof DatasetGraphTDB )
             return (DatasetGraphTDB)dsg ;
-        
+
         return null ;
     }
-    
-    /** Return a DatasetGraphTDB that uses the raw storage for tables 
-     * Use with care.
-     */ 
-    public static DatasetGraphTDB getBaseDatasetGraphTDB(DatasetGraph 
datasetGraph)
-    {
+
+    /**
+     * Return a DatasetGraphTDB that uses the raw storage for tables Use with
+     * care.
+     */
+    public static DatasetGraphTDB getBaseDatasetGraphTDB(DatasetGraph 
datasetGraph) {
         if ( datasetGraph instanceof DatasetGraphTransaction )
             return 
((DatasetGraphTransaction)datasetGraph).getBaseDatasetGraph() ;
-        throw new TDBException("Not a suitable DatasetGraph to get it's base 
storage: "+Lib.classShortName(datasetGraph.getClass())) ; 
+        throw new TDBException("Not a suitable DatasetGraph to get it's base 
storage: " + Lib.classShortName(datasetGraph.getClass())) ;
+    }
+
+    /** Look at a directory and see if it is a new area */
+    public static boolean isNewDatabaseArea(Location location) {
+        StoreConnection sConn = StoreConnection.getExisting(location) ;
+        if ( sConn != null )
+            // Already has a StoreConnection
+            return false ;
+        if ( location.isMem() )
+            return true ;
+        File d = new File(location.getDirectoryPath()) ;
+        if ( !d.exists() )
+            return true ;
+        FileFilter ff = fileFilterNewDB ;
+        File[] entries = d.listFiles(ff) ;
+        return entries.length == 0 ;
     }
-}
 
+    static FileFilter fileFilterNewDB = 
+        (pathname) -> {
+            String fn = pathname.getName() ;
+            if ( fn.equals(".") || fn.equals("..") )
+                return false ;
+            if ( pathname.isDirectory() )
+                return true ;
+
+            if ( fn.equals(StoreParamsConst.TDB_CONFIG_FILE) )
+                return false ;
+            return true ;
+        } ;
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/5d3f29cf/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 d3c7c75..1e90606 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,7 @@
 
 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.StoreParams ;
@@ -32,88 +30,44 @@ import 
org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
 public class TDBMaker
 {
     // ---- Transactional
-    // This hides details from the top level TDB Factory 
-    
-    /** Create a DatasetGraph that supports transactions */  
-    public static DatasetGraphTransaction createDatasetGraphTransaction(String 
location)
-    {
+    // This hides details from the top level TDB Factory (e.g. for testing)
+
+    /** Create a DatasetGraph that supports transactions */
+    public static DatasetGraphTransaction createDatasetGraphTransaction(String 
location) {
         return createDatasetGraphTransaction(Location.create(location)) ;
     }
-    
-    /** Create a Dataset that supports transactions */  
-    public static DatasetGraphTransaction 
createDatasetGraphTransaction(Location location)
-    {
+
+    /** Create a Dataset that supports transactions */
+    public static DatasetGraphTransaction 
createDatasetGraphTransaction(Location location) {
         return _create(location) ;
     }
-    
-    /** Create a Dataset that supports transactions but runs in-memory (for 
creating test cases)*/  
-    public static DatasetGraphTransaction createDatasetGraphTransaction()
-    {
+
+    /**
+     * Create a Dataset that supports transactions but runs in-memory (for
+     * creating test cases)
+     */
+    public static DatasetGraphTransaction createDatasetGraphTransaction() {
         return createDatasetGraphTransaction(Location.mem()) ;
     }
 
-    private static DatasetGraphTransaction _create(Location location)
-    {
+    private static DatasetGraphTransaction _create(Location location) {
         // No need to cache StoreConnection does all that.
         return new DatasetGraphTransaction(location) ;
     }
-    
-    public static void releaseLocation(Location location)
-    {
+
+    public static void releaseLocation(Location location) {
         StoreConnection.release(location) ;
     }
 
-    public static void reset()
-    {
+    public static void reset() {
         StoreConnection.reset() ;
     }
     
-    // ---- Base storage.
-    
-    /* The one we are using */
-    private static DatasetGraphMakerTDB builder = new BuilderStd() ;
-    
+    // ---- Raw non-transactional
+    /** Create a non-transactional TDB dataset graph.
+     * Bypasses StoreConnection caching. 
+     * <b>Use at your own risk.</b> 
+     */
     public static DatasetGraphTDB createDatasetGraphTDB(Location loc, 
StoreParams params)
-    { return builder.createDatasetGraph(loc, params) ; }
-
-    /** Interface to maker of the actual implementations of TDB datasets */ 
-    private interface DatasetGraphMakerTDB  
-    {
-        /** Create a TDB-backed dataset at a given location */
-        public DatasetGraphTDB createDatasetGraph(Location location, 
StoreParams params) ;
-    }
-
-    /** Make directly the base DatasetGraphTDB */
-    private static class BuilderStd implements DatasetGraphMakerTDB
-    {
-        @Override
-        public DatasetGraphTDB createDatasetGraph(Location location, 
StoreParams params)
-        {
-            return DatasetBuilderStd.create(location, params) ;
-        }
-    }
-    
-    /** Make by creating the normal, transactional one and finding the base */ 
-    private static class _BuilderBase implements DatasetGraphMakerTDB
-    {
-        @Override
-        public DatasetGraphTDB createDatasetGraph(Location location, 
StoreParams params)
-        {
-            if ( params != null )
-                System.err.println("StoreParams != null : ignored at the 
moment") ;
-            DatasetGraph dsg = TDBFactory.createDatasetGraph(location) ; // , 
params) ;
-            return TDBInternal.getBaseDatasetGraphTDB(dsg) ;
-        }
-    }
-    
-    /** The StoreConnection-cached base DatasetGraphTDB.*/ 
-    private static class BuilderStoreConnectionBase implements 
DatasetGraphMakerTDB
-    {
-        @Override
-        public DatasetGraphTDB createDatasetGraph(Location location, 
StoreParams params)
-        {
-            return StoreConnection.make(location, params).getBaseDataset() ;
-        }
-    }
-    
+    { return DatasetBuilderStd.create(loc, params) ; }
 }

Reply via email to