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 2015/07/31 15:11:55 UTC

[1/4] jena git commit: Add (initially private) test for whether a location is in use by TDB. Clean-up.

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 <an...@apache.org>
Authored: Thu Jul 30 18:45:07 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
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) ; }
 }


[3/4] jena git commit: Remove blank lines after refactoring.

Posted by an...@apache.org.
Remove blank lines after refactoring.

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

Branch: refs/heads/master
Commit: 3244ad99aef8f0e6838d5448e4a8ff4aa054b267
Parents: 7e9a76e
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Jul 31 14:11:25 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Jul 31 14:11:25 2015 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java   | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/3244ad99/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
index 4f53269..6629299 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
@@ -397,8 +397,6 @@ public class ActionDatasets extends ActionContainerItem {
         return stmt ;
     }
     
-    
-    
     // XXX Merge with Upload.incomingData
     
     private static void bodyAsGraph(HttpAction action, StreamRDF dest) {


[4/4] jena git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/jena

Posted by an...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/jena


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

Branch: refs/heads/master
Commit: 6ef2a1fa3ae80bcd8132a2587d7a8f9b3e6f2992
Parents: 3244ad9 d6adcc1
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Jul 31 14:11:44 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Jul 31 14:11:44 2015 +0100

----------------------------------------------------------------------
 .../sparql/pfunction/PropertyFunctionBase.java  |  25 +-
 .../org/apache/jena/query/text/TextQueryPF.java | 914 +++++++++++--------
 2 files changed, 538 insertions(+), 401 deletions(-)
----------------------------------------------------------------------



[2/4] jena git commit: Configuration utils to FusekiEnv.

Posted by an...@apache.org.
Configuration utils to FusekiEnv.

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

Branch: refs/heads/master
Commit: 7e9a76e11ed9f86e8146cf4606e3fe20e550a913
Parents: 5d3f29c
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Jul 31 14:10:53 2015 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Jul 31 14:10:53 2015 +0100

----------------------------------------------------------------------
 .../apache/jena/fuseki/mgt/ActionDatasets.java  | 55 ++------------------
 .../apache/jena/fuseki/server/FusekiEnv.java    | 53 ++++++++++++++++++-
 2 files changed, 55 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/7e9a76e1/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
index 7a972d9..4f53269 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
@@ -24,9 +24,6 @@ import java.io.IOException ;
 import java.io.InputStream ;
 import java.io.OutputStream ;
 import java.io.StringReader ;
-import java.nio.file.DirectoryStream ;
-import java.nio.file.Files ;
-import java.nio.file.Path ;
 import java.util.* ;
 
 import javax.servlet.ServletOutputStream ;
@@ -173,8 +170,8 @@ public class ActionDatasets extends ActionContainerItem {
                 // And abort.
                 ServletOps.error(HttpSC.CONFLICT_409, "Name already registered "+datasetPath) ;
             
-            configFile = generateConfigurationFilename(datasetPath) ;
-            List<String> existing = existingConfigurationFile(datasetPath) ;
+            configFile = FusekiEnv.generateConfigurationFilename(datasetPath) ;
+            List<String> existing = FusekiEnv.existingConfigurationFile(datasetPath) ;
             if ( ! existing.isEmpty() )
                 ServletOps.error(HttpSC.CONFLICT_409, "Configuration file for "+datasetPath+" already exists") ;
 
@@ -323,7 +320,7 @@ public class ActionDatasets extends ActionContainerItem {
             DataAccessPointRegistry.get().remove(name) ;
             // Delete configuration file.
             // Should be only one, undo damage if multiple.
-            existingConfigurationFile(name).stream().forEach(FileOps::deleteSilent);
+            FusekiEnv.existingConfigurationFile(name).stream().forEach(FileOps::deleteSilent);
             
             // Find graph associated with this dataset name.
             // (Statically configured databases aren't in the system database.)
@@ -400,53 +397,7 @@ public class ActionDatasets extends ActionContainerItem {
         return stmt ;
     }
     
-    /** Dataset set name to configuration file name. */
-    private String datasetNameToConfigurationFile(HttpAction action, String dsName) {
-        List<String> existing = existingConfigurationFile(dsName) ;
-        if ( ! existing.isEmpty() ) {
-            if ( existing.size() > 1 ) {
-                action.log.warn(format("[%d] Multiple existing configuration files for %s : %s",
-                                       action.id, dsName, existing));
-                ServletOps.errorBadRequest("Multiple existing configuration files for "+dsName);
-                return null ;
-            }
-            return existing.get(0) ;
-        }
-        
-        return generateConfigurationFilename(dsName) ;
-    }
     
-        
-    // TODO To a library place and use for all ref->filename
-    private String generateConfigurationFilename(String dsName) {
-        String filename = dsName ;
-        // Without "/"
-        if ( filename.startsWith("/"))
-            filename = filename.substring(1) ;
-        filename = FusekiServer.dirConfiguration.resolve(filename).toString()+".ttl" ;
-        return filename ;
-    }
-    
-    /** Return the filenames of all matching files in the configuration directory */  
-    private List<String> existingConfigurationFile(String baseFilename) {
-        // TODO To a library place and use for all ref->filename
-        try { 
-            // Basename glob.
-            List<String> paths = new ArrayList<>() ;
-
-            try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiServer.dirConfiguration, baseFilename+"*") ) {
-                stream.forEach((p)-> paths.add(p.getFileName().toString())) ;
-            }
-//            DirectoryStream.Filter<Path> matchingFiles = (entry) -> {
-//                String fn = entry.getFileName().toString() ;
-//                return fn.startsWith(baseFilename) ;
-//            } ;
-//            try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiServer.dirConfiguration, matchingFiles)) {
-            return paths ;
-        } catch (IOException ex) {
-            throw new InternalErrorException("Failed to read configuration directory "+FusekiServer.dirConfiguration) ;
-        }
-    }
     
     // XXX Merge with Upload.incomingData
     

http://git-wip-us.apache.org/repos/asf/jena/blob/7e9a76e1/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
index c5e269d..603fbe7 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiEnv.java
@@ -18,8 +18,19 @@
 
 package org.apache.jena.fuseki.server;
 
+import static java.lang.String.format ;
+
+import java.io.IOException ;
+import java.nio.file.DirectoryStream ;
+import java.nio.file.Files ;
 import java.nio.file.Path ;
 import java.nio.file.Paths ;
+import java.util.ArrayList ;
+import java.util.List ;
+
+import org.apache.jena.atlas.lib.InternalErrorException ;
+import org.apache.jena.fuseki.servlets.HttpAction ;
+import org.apache.jena.fuseki.servlets.ServletOps ;
 
 /** 
  * Separate initialization for FUSEKI_HOME and FUSEKI_BASE so that 
@@ -93,8 +104,9 @@ public class FusekiEnv {
     }
  
     public static final String   ENV_runArea     = "run" ;
-
     private static boolean       initialized     = false ;
+    
+    /** Initialize the server */
     public static synchronized void setEnvironment() {
         if ( initialized )
             return ;
@@ -160,5 +172,44 @@ public class FusekiEnv {
         return x ;
     }
 
+    /** Dataset set name to configuration file name. */
+    public static String datasetNameToConfigurationFile(HttpAction action, String dsName) {
+        List<String> existing = existingConfigurationFile(dsName) ;
+        if ( ! existing.isEmpty() ) {
+            if ( existing.size() > 1 ) {
+                action.log.warn(format("[%d] Multiple existing configuration files for %s : %s",
+                                       action.id, dsName, existing));
+                ServletOps.errorBadRequest("Multiple existing configuration files for "+dsName);
+                return null ;
+            }
+            return existing.get(0) ;
+        }
+        
+        return generateConfigurationFilename(dsName) ;
+    }
+
+    /** Choose a configuration file name - existign one or ".ttl" form if new */
+    public static String generateConfigurationFilename(String dsName) {
+        String filename = dsName ;
+        // Without "/"
+        if ( filename.startsWith("/"))
+            filename = filename.substring(1) ;
+        filename = FusekiServer.dirConfiguration.resolve(filename).toString()+".ttl" ;
+        return filename ;
+    }
+
+    /** Return the filenames of all matching files in the configuration directory */  
+    public static List<String> existingConfigurationFile(String baseFilename) {
+        try { 
+            List<String> paths = new ArrayList<>() ;
+            try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiServer.dirConfiguration, baseFilename+"*") ) {
+                stream.forEach((p)-> paths.add(p.getFileName().toString())) ;
+            }
+            return paths ;
+        } catch (IOException ex) {
+            throw new InternalErrorException("Failed to read configuration directory "+FusekiServer.dirConfiguration) ;
+        }
+    }
+
 }