jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [28/50] [abbrv] jena git commit: JENA-1396: Merge //github/afs/mantis as subdirectory jena-db/
Date Thu, 28 Sep 2017 11:08:44 GMT
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/main/java/org/seaborne/tdb2/sys/TDBInternal.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/main/java/org/seaborne/tdb2/sys/TDBInternal.java
index 0000000,0000000..0b57de8
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/main/java/org/seaborne/tdb2/sys/TDBInternal.java
@@@ -1,0 -1,0 +1,174 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.sys;
++
++import org.apache.jena.graph.Node;
++import org.apache.jena.query.Dataset;
++import org.apache.jena.sparql.core.DatasetGraph;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.tdb2.TDBException ;
++import org.seaborne.tdb2.store.DatasetGraphSwitchable ;
++import org.seaborne.tdb2.store.DatasetGraphTDB;
++import org.seaborne.tdb2.store.NodeId;
++import org.seaborne.tdb2.store.nodetable.NodeTable;
++
++/**
++ * A collection of helpers to abstract away from calling code knowing the 
++ * internal details of TDB. 
++ * <p>
++ * Use with care.
++ * <p>{@link DatabaseOps#compact Compaction} invalidates any previous objects.
++ * 
++ */
++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.
++     */
++    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.
++     */
++    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.
++     */
++    public static NodeId getNodeId(DatasetGraphTDB dsg, Node node) {
++        if ( dsg == null )
++            return null;
++        NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
++        NodeId nodeId = nodeTable.getNodeIdForNode(node);
++        return nodeId;
++    }
++
++    /**
++     * 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) {
++        return getNode(ds.asDatasetGraph(), nodeId);
++    }
++
++    /**
++     * 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) {
++        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.
++     */
++    public static Node getNode(DatasetGraphTDB dsg, NodeId nodeId) {
++        if ( dsg == null )
++            return null;
++        NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
++        Node node = nodeTable.getNodeForNodeId(nodeId);
++        return node;
++    }
++
++    /**
++     * Return the DatasetGraphTDB for a Dataset, or null.
++     * Use the {@link DatasetGraphTDB} with care.
++     */
++    public static DatasetGraphTDB getDatasetGraphTDB(Dataset ds) {
++        return getDatasetGraphTDB(ds.asDatasetGraph());
++    }
++
++    /**
++     * Return the DatasetGraphTDB for a DatasetGraph, or null.
++     * Use the {@link DatasetGraphTDB} with care.
++     */
++    public static DatasetGraphSwitchable getDatabaseContainer(DatasetGraph dsg) {
++        if ( dsg instanceof DatasetGraphSwitchable )
++            return (DatasetGraphSwitchable)dsg;
++        throw new TDBException("Not a TDB database container");
++    }
++    
++    /**
++     * Return the DatasetGraphTDB for a DatasetGraph, or null.
++     * Use the {@link DatasetGraphTDB} with care.
++     */
++    public static DatasetGraphTDB getDatasetGraphTDB(DatasetGraph dsg) {
++        return unwrap(dsg);
++    }
++
++    /**
++     * Return the DatasetGraphTDB for a DatasetGraph, or throw an exception.
++     */
++    public static DatasetGraphTDB requireStorage(DatasetGraph dsg) {
++        DatasetGraphTDB dsgtdb = unwrap(dsg);
++        if ( dsgtdb == null )
++            throw new TDBException("Not a TDB database (argument is neither a switchable nor direct TDB DatasetGraph)");
++        return dsgtdb;
++    }
++    
++    private static DatasetGraphTDB unwrap(DatasetGraph datasetGraph) {
++        DatasetGraph dsg = datasetGraph;
++        if ( dsg instanceof DatasetGraphSwitchable )
++            dsg = ((DatasetGraphSwitchable)datasetGraph).get();
++        if ( dsg instanceof DatasetGraphTDB )
++            return ((DatasetGraphTDB)dsg);
++        return null;
++    }
++
++    /** Stop managing a DatasetGraph. Use with great care (testing only). */
++    public static synchronized void expel(DatasetGraph dsg) {
++        Location locContainer = null;
++        Location locStorage = null;
++        
++        if ( dsg instanceof DatasetGraphSwitchable ) {
++            locContainer = ((DatasetGraphSwitchable)dsg).getLocation();
++            dsg = ((DatasetGraphSwitchable)dsg).getWrapped();
++        }
++        if ( dsg instanceof DatasetGraphTDB )
++            locStorage = ((DatasetGraphTDB)dsg).getLocation();
++        
++        DatabaseConnection.internalExpel(locContainer, false);
++        StoreConnection.internalExpel(locStorage, false);
++    }
++
++    /** 
++     * Reset the whole TDB system.      
++     * Use with great care.
++     */
++    public static void reset() {
++        DatabaseConnection.internalReset();
++        StoreConnection.internalReset();
++    }
++
++    public static boolean isBackedByTDB(DatasetGraph datasetGraph) {
++        if ( datasetGraph instanceof DatasetGraphSwitchable )
++            return true;
++        if ( datasetGraph instanceof DatasetGraphTDB )
++            return true;
++        return false;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/main/java/org/seaborne/tdb2/sys/Util.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/main/java/org/seaborne/tdb2/sys/Util.java
index 0000000,0000000..3ac6336
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/main/java/org/seaborne/tdb2/sys/Util.java
@@@ -1,0 -1,0 +1,49 @@@
++/*
++ * 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.seaborne.tdb2.sys;
++
++import java.util.List;
++import java.util.NoSuchElementException;
++
++/** Utility code that should go somewhere */
++public class Util {
++    
++    /** Get the last element of a list, or throw NoSuchElementException
++     * @param list
++     * @return T
++     * @throws NoSuchElementException
++     */
++    public static <T> T xgetLast(List<T> list) {
++        T elt = getLastOrNull(list);
++        if ( elt == null )
++            throw new NoSuchElementException();
++        return elt;  
++    }
++    
++    /**
++     * Get the last element of a list, or return null.
++     * @param list
++     * @return T
++     */
++    public static <T> T getLastOrNull(List<T> list) {
++        if ( list.isEmpty() )
++            return null;
++        return list.get(list.size()-1);  
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/main/resources/META-INF/LICENSE
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/main/resources/META-INF/LICENSE
index 0000000,0000000..67db858
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/main/resources/META-INF/LICENSE
@@@ -1,0 -1,0 +1,175 @@@
++
++                                 Apache License
++                           Version 2.0, January 2004
++                        http://www.apache.org/licenses/
++
++   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
++
++   1. Definitions.
++
++      "License" shall mean the terms and conditions for use, reproduction,
++      and distribution as defined by Sections 1 through 9 of this document.
++
++      "Licensor" shall mean the copyright owner or entity authorized by
++      the copyright owner that is granting the License.
++
++      "Legal Entity" shall mean the union of the acting entity and all
++      other entities that control, are controlled by, or are under common
++      control with that entity. For the purposes of this definition,
++      "control" means (i) the power, direct or indirect, to cause the
++      direction or management of such entity, whether by contract or
++      otherwise, or (ii) ownership of fifty percent (50%) or more of the
++      outstanding shares, or (iii) beneficial ownership of such entity.
++
++      "You" (or "Your") shall mean an individual or Legal Entity
++      exercising permissions granted by this License.
++
++      "Source" form shall mean the preferred form for making modifications,
++      including but not limited to software source code, documentation
++      source, and configuration files.
++
++      "Object" form shall mean any form resulting from mechanical
++      transformation or translation of a Source form, including but
++      not limited to compiled object code, generated documentation,
++      and conversions to other media types.
++
++      "Work" shall mean the work of authorship, whether in Source or
++      Object form, made available under the License, as indicated by a
++      copyright notice that is included in or attached to the work
++      (an example is provided in the Appendix below).
++
++      "Derivative Works" shall mean any work, whether in Source or Object
++      form, that is based on (or derived from) the Work and for which the
++      editorial revisions, annotations, elaborations, or other modifications
++      represent, as a whole, an original work of authorship. For the purposes
++      of this License, Derivative Works shall not include works that remain
++      separable from, or merely link (or bind by name) to the interfaces of,
++      the Work and Derivative Works thereof.
++
++      "Contribution" shall mean any work of authorship, including
++      the original version of the Work and any modifications or additions
++      to that Work or Derivative Works thereof, that is intentionally
++      submitted to Licensor for inclusion in the Work by the copyright owner
++      or by an individual or Legal Entity authorized to submit on behalf of
++      the copyright owner. For the purposes of this definition, "submitted"
++      means any form of electronic, verbal, or written communication sent
++      to the Licensor or its representatives, including but not limited to
++      communication on electronic mailing lists, source code control systems,
++      and issue tracking systems that are managed by, or on behalf of, the
++      Licensor for the purpose of discussing and improving the Work, but
++      excluding communication that is conspicuously marked or otherwise
++      designated in writing by the copyright owner as "Not a Contribution."
++
++      "Contributor" shall mean Licensor and any individual or Legal Entity
++      on behalf of whom a Contribution has been received by Licensor and
++      subsequently incorporated within the Work.
++
++   2. Grant of Copyright License. Subject to the terms and conditions of
++      this License, each Contributor hereby grants to You a perpetual,
++      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
++      copyright license to reproduce, prepare Derivative Works of,
++      publicly display, publicly perform, sublicense, and distribute the
++      Work and such Derivative Works in Source or Object form.
++
++   3. Grant of Patent License. Subject to the terms and conditions of
++      this License, each Contributor hereby grants to You a perpetual,
++      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
++      (except as stated in this section) patent license to make, have made,
++      use, offer to sell, sell, import, and otherwise transfer the Work,
++      where such license applies only to those patent claims licensable
++      by such Contributor that are necessarily infringed by their
++      Contribution(s) alone or by combination of their Contribution(s)
++      with the Work to which such Contribution(s) was submitted. If You
++      institute patent litigation against any entity (including a
++      cross-claim or counterclaim in a lawsuit) alleging that the Work
++      or a Contribution incorporated within the Work constitutes direct
++      or contributory patent infringement, then any patent licenses
++      granted to You under this License for that Work shall terminate
++      as of the date such litigation is filed.
++
++   4. Redistribution. You may reproduce and distribute copies of the
++      Work or Derivative Works thereof in any medium, with or without
++      modifications, and in Source or Object form, provided that You
++      meet the following conditions:
++
++      (a) You must give any other recipients of the Work or
++          Derivative Works a copy of this License; and
++
++      (b) You must cause any modified files to carry prominent notices
++          stating that You changed the files; and
++
++      (c) You must retain, in the Source form of any Derivative Works
++          that You distribute, all copyright, patent, trademark, and
++          attribution notices from the Source form of the Work,
++          excluding those notices that do not pertain to any part of
++          the Derivative Works; and
++
++      (d) If the Work includes a "NOTICE" text file as part of its
++          distribution, then any Derivative Works that You distribute must
++          include a readable copy of the attribution notices contained
++          within such NOTICE file, excluding those notices that do not
++          pertain to any part of the Derivative Works, in at least one
++          of the following places: within a NOTICE text file distributed
++          as part of the Derivative Works; within the Source form or
++          documentation, if provided along with the Derivative Works; or,
++          within a display generated by the Derivative Works, if and
++          wherever such third-party notices normally appear. The contents
++          of the NOTICE file are for informational purposes only and
++          do not modify the License. You may add Your own attribution
++          notices within Derivative Works that You distribute, alongside
++          or as an addendum to the NOTICE text from the Work, provided
++          that such additional attribution notices cannot be construed
++          as modifying the License.
++
++      You may add Your own copyright statement to Your modifications and
++      may provide additional or different license terms and conditions
++      for use, reproduction, or distribution of Your modifications, or
++      for any such Derivative Works as a whole, provided Your use,
++      reproduction, and distribution of the Work otherwise complies with
++      the conditions stated in this License.
++
++   5. Submission of Contributions. Unless You explicitly state otherwise,
++      any Contribution intentionally submitted for inclusion in the Work
++      by You to the Licensor shall be under the terms and conditions of
++      this License, without any additional terms or conditions.
++      Notwithstanding the above, nothing herein shall supersede or modify
++      the terms of any separate license agreement you may have executed
++      with Licensor regarding such Contributions.
++
++   6. Trademarks. This License does not grant permission to use the trade
++      names, trademarks, service marks, or product names of the Licensor,
++      except as required for reasonable and customary use in describing the
++      origin of the Work and reproducing the content of the NOTICE file.
++
++   7. Disclaimer of Warranty. Unless required by applicable law or
++      agreed to in writing, Licensor provides the Work (and each
++      Contributor provides its Contributions) on an "AS IS" BASIS,
++      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
++      implied, including, without limitation, any warranties or conditions
++      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
++      PARTICULAR PURPOSE. You are solely responsible for determining the
++      appropriateness of using or redistributing the Work and assume any
++      risks associated with Your exercise of permissions under this License.
++
++   8. Limitation of Liability. In no event and under no legal theory,
++      whether in tort (including negligence), contract, or otherwise,
++      unless required by applicable law (such as deliberate and grossly
++      negligent acts) or agreed to in writing, shall any Contributor be
++      liable to You for damages, including any direct, indirect, special,
++      incidental, or consequential damages of any character arising as a
++      result of this License or out of the use or inability to use the
++      Work (including but not limited to damages for loss of goodwill,
++      work stoppage, computer failure or malfunction, or any and all
++      other commercial damages or losses), even if such Contributor
++      has been advised of the possibility of such damages.
++
++   9. Accepting Warranty or Additional Liability. While redistributing
++      the Work or Derivative Works thereof, You may choose to offer,
++      and charge a fee for, acceptance of support, warranty, indemnity,
++      or other liability obligations and/or rights consistent with this
++      License. However, in accepting such obligations, You may act only
++      on Your own behalf and on Your sole responsibility, not on behalf
++      of any other Contributor, and only if You agree to indemnify,
++      defend, and hold each Contributor harmless for any liability
++      incurred by, or claims asserted against, such Contributor by reason
++      of your accepting any such warranty or additional liability.

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/main/resources/META-INF/NOTICE
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/main/resources/META-INF/NOTICE
index 0000000,0000000..5ba7ec0
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/main/resources/META-INF/NOTICE
@@@ -1,0 -1,0 +1,10 @@@
++Mantis Database Operating Environment
++
++Copyright 2013-2017 Andy Seaborne
++Copyright 2014, 2015 Epimorphics Ltd.
++
++Portions of this software derive from software from Apache Jena:
++  - Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP
++  - Copyright 2010, 2011 Epimorphics Ltd.
++  - Copyright 2010, 2011 Talis Systems Ltd.
++These have been licensed to the Apache Software Foundation under a software grant.

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
index 0000000,0000000..21f02ea
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@@ -1,0 -1,0 +1,1 @@@
++org.seaborne.tdb2.sys.InitTDB2

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/main/resources/org/apache/jena/tdb/tdb-properties.xml
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/main/resources/org/apache/jena/tdb/tdb-properties.xml
index 0000000,0000000..67d8255
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/main/resources/org/apache/jena/tdb/tdb-properties.xml
@@@ -1,0 -1,0 +1,8 @@@
++<?xml version="1.0" encoding="UTF-8"?>
++<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
++<!-- Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0 -->
++<properties version="1.0">
++  <comment>TDB System Properties</comment>
++  <entry key="org.apache.jena.tdb.version">${project.version}</entry>
++  <entry key="org.apache.jena.tdb.build.datetime">${build.time.xsd}</entry>
++</properties>

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/ConfigTest.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/ConfigTest.java
index 0000000,0000000..fc161fd
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/ConfigTest.java
@@@ -1,0 -1,0 +1,95 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2;
++
++import org.apache.jena.atlas.lib.FileOps ;
++import org.seaborne.tdb2.sys.SystemTDB ;
++
++public class ConfigTest
++{
++    private static String testingDataRoot = "testing" ;
++    // Place under target
++    private static final String testingDir = "target/tdb-testing" ;
++    private static final String testingDirDB = "target/tdb-testing/DB" ;
++    static boolean nonDeleteableMMapFiles = SystemTDB.isWindows ;
++    
++    static boolean initialized = false ; 
++    
++    private static void init()
++    {
++        FileOps.ensureDir("target") ;
++        FileOps.ensureDir(testingDir) ;
++        FileOps.ensureDir(testingDirDB) ;
++        initialized = true ;
++    }
++    
++    private static int count = 0 ;
++
++    public static void setTestingDataRoot(String dir) { testingDataRoot = dir ; }
++    public static String getTestingDataRoot() { return testingDataRoot ; }
++    
++    /** return a directory */ 
++    public static final String getCleanDir() {
++        init() ;
++        String dir = nonDeleteableMMapFiles ? getTestingDirUnique() : getTestingDirDB() ;
++        FileOps.ensureDir(dir); 
++        FileOps.clearDirectory(dir) ;
++        return dir ;
++    }
++    /** Get a empty directory name that has not been used before in this JVM */
++    
++    private static final String getTestingDirUnique()
++    {
++        init() ;
++    	String dn = testingDir+"/D-"+(++count) ;
++    	FileOps.ensureDir(dn) ;
++    	FileOps.clearDirectory(dn) ;
++    	return dn ; 
++    }
++    
++    public static final String getTestingDir()
++    {
++        init() ;
++        return testingDir ;
++    }
++    
++    public static final void deleteTestingDir()
++    {
++        if ( ! FileOps.exists(testingDir) )
++            return ;
++        deleteTestingDirDB() ;
++        FileOps.clearDirectory(testingDir) ;
++        FileOps.deleteSilent(testingDir) ;
++    }
++
++    public static final String getTestingDirDB()
++    {
++        init() ;
++        FileOps.ensureDir(testingDirDB) ;
++        return testingDirDB ;
++    }
++    
++    public static final void deleteTestingDirDB()
++    {
++        if ( ! FileOps.exists(testingDirDB) )
++            return ;
++        FileOps.clearDirectory(testingDirDB) ;
++        FileOps.deleteSilent(testingDirDB) ;
++    }
++
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TC_TDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/TC_TDB.java
index 0000000,0000000..8d1a695
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TC_TDB.java
@@@ -1,0 -1,0 +1,80 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2;
++
++import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
++import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
++import org.apache.log4j.Level ;
++import org.apache.log4j.Logger ;
++import org.junit.AfterClass ;
++import org.junit.BeforeClass ;
++import org.junit.runner.RunWith ;
++import org.junit.runners.Suite ;
++import org.seaborne.dboe.base.block.FileMode ;
++import org.seaborne.tdb2.assembler.TS_TDBAssembler ;
++import org.seaborne.tdb2.graph.TS_Graph ;
++import org.seaborne.tdb2.lib.TS_LibTDB ;
++import org.seaborne.tdb2.setup.TS_TDBSetup ;
++import org.seaborne.tdb2.solver.TS_SolverTDB ;
++import org.seaborne.tdb2.store.TS_Store ;
++import org.seaborne.tdb2.store.nodetable.TS_NodeTable ;
++import org.seaborne.tdb2.store.tupletable.TS_TupleTable ;
++import org.seaborne.tdb2.sys.SystemTDB ;
++import org.seaborne.tdb2.sys.TS_Sys ;
++
++// Naming conventions.
++// TS_* - Test sets: collections of testing files (Often Test*)
++// TC_*  - Test collection: sets of TS's and TC's.
++
++@RunWith(Suite.class)
++@Suite.SuiteClasses( {
++    // TDB
++    TS_LibTDB.class
++    , TS_NodeTable.class
++    , TS_TupleTable.class
++    , TS_TDBSetup.class
++    , TS_Store.class
++    , TS_SolverTDB.class
++    , TS_Graph.class
++    , TS_Factory.class
++    , TS_TDBAssembler.class
++    , TS_Sys.class
++} )
++
++public class TC_TDB
++{
++    static {
++        if ( false )
++            SystemTDB.setFileMode(FileMode.direct) ;
++    }
++    static ReorderTransformation dftReorder = null ; 
++        
++    @BeforeClass static public void beforeClass()   
++    {
++        //org.apache.log4j.LogManager.resetConfiguration() ;
++        //org.apache.log4j.PropertyConfigurator.configure("log4j.properties") ;
++        Logger.getLogger("org.apache.jena.tdb.info").setLevel(Level.WARN) ;
++        //Logger.getLogger("org.apache.jena.tdb.exec").setLevel(Level.WARN) ;
++        dftReorder = SystemTDB.defaultReorderTransform ;
++        SystemTDB.defaultReorderTransform = ReorderLib.identity() ;
++    }
++    
++    @AfterClass static public void afterClass() {
++        SystemTDB.defaultReorderTransform = dftReorder ;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TS_Factory.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/TS_Factory.java
index 0000000,0000000..b6dc979
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TS_Factory.java
@@@ -1,0 -1,0 +1,32 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2;
++
++
++import org.junit.runner.RunWith;
++import org.junit.runners.Suite;
++
++@RunWith(Suite.class)
++@Suite.SuiteClasses( {
++    TestDatabaseMgr.class
++    , TestTDBFactory.class
++
++})
++
++public class TS_Factory
++{}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TestDatabaseMgr.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/TestDatabaseMgr.java
index 0000000,0000000..da75494
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TestDatabaseMgr.java
@@@ -1,0 -1,0 +1,89 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2;
++
++import static org.junit.Assert.*;
++import org.apache.jena.atlas.lib.FileOps ;
++import org.apache.jena.sparql.core.DatasetGraph ;
++import org.apache.jena.sparql.core.Quad ;
++import org.apache.jena.sparql.sse.SSE ;
++import org.junit.Test ;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.dboe.jenax.Txn ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++/** Test of DatabaseMgr - the DatasetGraph level API to TDB2 **/
++public class TestDatabaseMgr
++{
++//    String DIRx = ConfigTest.getCleanDir() ;
++//    Location DIR = Location.create(DIRx);
++    
++    static Quad quad1 = SSE.parseQuad("(_ _:a <p> 1)") ;
++    static Quad quad2 = SSE.parseQuad("(_ <s> <p> 1)") ;
++    
++    @Test
++    public void testDatabaseMgr1() {
++        TDBInternal.reset() ; 
++        DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(Location.mem("FOO")) ;
++        DatasetGraph dg2 = DatabaseMgr.connectDatasetGraph(Location.mem("FOO")) ;
++        Txn.executeWrite(dg1, ()->{
++            dg1.add(quad1) ;
++        }) ;
++        Txn.executeRead(dg2, ()->{
++            assertTrue(dg2.contains(quad1)) ;
++        }) ;
++    }
++    
++    @Test
++    public void testDatabaseMgr2() {
++        TDBInternal.reset() ;
++        // The unnamed location is unique each time.
++        DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(Location.mem()) ;
++        DatasetGraph dg2 = DatabaseMgr.connectDatasetGraph(Location.mem()) ;
++        Txn.executeWrite(dg1, ()->{
++            dg1.add(quad1) ;    
++        }) ;
++        Txn.executeRead(dg2, ()->{
++            assertFalse(dg2.contains(quad1)) ;
++        }) ;
++    }
++
++    @Test
++    public void testDatabaseMgrDisk() {
++        TDBInternal.reset() ;
++        // The named disk location
++        String DIRx = ConfigTest.getCleanDir() ;
++        Location LOC = Location.create(DIRx) ;
++        FileOps.clearDirectory(DIRx) ;
++        try {
++            DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(LOC) ;
++            DatasetGraph dg2 = DatabaseMgr.connectDatasetGraph(Location.create(LOC.getDirectoryPath())) ;
++            assertSame(dg1, dg2) ;
++            Txn.executeWrite(dg1, ()-> {
++                dg1.add(quad1) ;
++            }) ;
++            Txn.executeRead(dg2, ()-> {
++                assertTrue(dg2.contains(quad1)) ;
++            }) ;
++        }
++        finally {
++            FileOps.clearDirectory(DIRx) ;
++        }
++
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TestTDBFactory.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/TestTDBFactory.java
index 0000000,0000000..752a95c
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/TestTDBFactory.java
@@@ -1,0 -1,0 +1,130 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2;
++
++import static org.junit.Assert.*;
++import org.apache.jena.atlas.lib.FileOps ;
++import org.apache.jena.datatypes.xsd.XSDDatatype ;
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.rdf.model.Literal ;
++import org.apache.jena.rdf.model.Property ;
++import org.apache.jena.rdf.model.Resource ;
++import org.apache.jena.rdf.model.ResourceFactory ;
++import org.junit.Test ;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.dboe.jenax.Txn ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++/** Test of TDB2Factory - the Dataset level API to TDB2 **/
++public class TestTDBFactory
++{
++    static Resource s1 = ResourceFactory.createResource("http://example/s2");
++    static Resource s2 = ResourceFactory.createResource();
++    static Property p  =  ResourceFactory.createProperty("http://example/ns#", "p");
++    static Literal  o1 =  ResourceFactory.createPlainLiteral("object");
++    static Literal  o2 =  ResourceFactory.createTypedLiteral("1", XSDDatatype.XSDinteger);
++    
++    @Test
++    public void testTDBFactory1() {
++        TDBInternal.reset() ;
++        Dataset ds = TDB2Factory.connectDataset(Location.mem()) ;
++        test(ds);
++    }
++    
++    @Test
++    public void testTDBFactory2() {
++        TDBInternal.reset() ;
++        Dataset ds = TDB2Factory.connectDataset(Location.mem("MEMORY")) ;
++        test(ds);
++    }
++    
++    @Test
++    public void testTDBFactory3() {
++        TDBInternal.reset() ;
++        // Only do disk things for tests that need them (disk takes time!).
++        String DIRx = ConfigTest.getCleanDir() ;
++        Location DIR = Location.create(DIRx);
++        try { 
++            FileOps.clearDirectory(DIRx) ;
++            Dataset ds = TDB2Factory.connectDataset(DIR) ;
++            test(ds);
++        } finally { FileOps.clearDirectory(DIRx) ; }
++    }
++    
++    @Test
++    public void testTDBFactory2DS_1() {
++        TDBInternal.reset() ;
++        Dataset ds1 = TDB2Factory.connectDataset(Location.mem("FOO")) ;
++        Dataset ds2 = TDB2Factory.connectDataset(Location.mem("FOO")) ;
++        Txn.executeWrite(ds1, ()->{
++            ds1.getDefaultModel().add(s1, p, o1);
++        });
++        Txn.executeRead(ds2, ()->{
++            assertTrue(ds2.getDefaultModel().contains(s1, p, o1));
++        });
++    }
++    
++    @Test
++    public void testTDBFactory2DS_2() {
++        TDBInternal.reset() ;
++        // The unnamed location is unique each time.
++        Dataset ds1 = TDB2Factory.connectDataset(Location.mem()) ;
++        Dataset ds2 = TDB2Factory.connectDataset(Location.mem()) ;
++        Txn.executeWrite(ds1, ()->{
++            ds1.getDefaultModel().add(s1, p, o1);
++        });
++        Txn.executeRead(ds2, ()->{
++            assertFalse(ds2.getDefaultModel().contains(s1, p, o1));
++        });
++    }
++    
++    @Test
++    public void testTDBFactory2DS_3() {
++        TDBInternal.reset() ;
++        TDBInternal.reset() ;
++        String DIRx = ConfigTest.getCleanDir() ;
++        Location DIR = Location.create(DIRx);
++        try {
++            Dataset ds1 = TDB2Factory.connectDataset(DIR) ;
++            Dataset ds2 = TDB2Factory.connectDataset(DIR) ;
++            Txn.executeWrite(ds1, ()->{
++                ds1.getDefaultModel().add(s1, p, o1);
++            });
++            Txn.executeRead(ds2, ()->{
++                assertTrue(ds2.getDefaultModel().contains(s1, p, o1));
++            });
++        } finally { FileOps.clearDirectory(DIRx) ; }
++    }
++
++    private static void test(Dataset ds) {
++        Txn.executeWrite(ds, ()->{
++            ds.getDefaultModel().add(s1, p, o1);
++        });
++        Txn.executeRead(ds, ()->{
++            assertTrue(ds.getDefaultModel().contains(s1, p, o1));
++        });
++        Txn.executeWrite(ds, ()->{
++            ds.getDefaultModel().remove(s1, p, o1);
++            ds.getDefaultModel().add(s2, p, o2);
++        });
++        Txn.executeRead(ds, ()->{
++            assertFalse(ds.getDefaultModel().contains(s1, p, o1));
++            assertTrue(ds.getDefaultModel().contains(s2, p, o2));
++        });
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/assembler/TS_TDBAssembler.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/assembler/TS_TDBAssembler.java
index 0000000,0000000..d6f622a
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/assembler/TS_TDBAssembler.java
@@@ -1,0 -1,0 +1,32 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.assembler;
++
++import org.junit.runner.RunWith ;
++import org.junit.runners.Suite ;
++import org.seaborne.tdb2.junit.Base_TS ;
++
++@RunWith(Suite.class)
++@Suite.SuiteClasses( {
++     TestTDBAssembler.class
++})
++
++public class TS_TDBAssembler extends Base_TS
++{
++
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/assembler/TestTDBAssembler.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/assembler/TestTDBAssembler.java
index 0000000,0000000..f1e13e2
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/assembler/TestTDBAssembler.java
@@@ -1,0 -1,0 +1,142 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.assembler;
++
++import org.apache.jena.assembler.JA ;
++import org.apache.jena.assembler.exceptions.AssemblerException ;
++import static org.junit.Assert.*;
++import org.apache.jena.atlas.lib.FileOps ;
++import org.apache.jena.graph.Graph ;
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.rdf.model.Model ;
++import org.apache.jena.rdf.model.Resource ;
++import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
++import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
++import org.junit.AfterClass ;
++import org.junit.Before ;
++import org.junit.BeforeClass ;
++import org.junit.Test ;
++import org.seaborne.tdb2.ConfigTest ;
++import org.seaborne.tdb2.store.DatasetGraphSwitchable ;
++import org.seaborne.tdb2.store.GraphViewSwitchable ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++public class TestTDBAssembler
++{
++    // Can be slow - explicitly closes the dataset.
++    static String dirAssem      = null ;
++    static final String dirDB   = ConfigTest.getTestingDir()+"/DB" ;
++
++    @BeforeClass
++    static public void beforeClass() {
++        dirAssem = ConfigTest.getTestingDataRoot() + "/Assembler" ;
++        FileOps.ensureDir(dirDB) ;
++    }
++
++    @Before
++    public void before() {
++        TDBInternal.reset() ;
++        FileOps.clearDirectory(dirDB) ;
++    }
++
++    @AfterClass
++    static public void afterClass() {
++        TDBInternal.reset() ;
++        FileOps.clearDirectory(dirDB) ;
++    }
++
++    @Test
++    public void createDatasetDirect() {
++        createTest(dirAssem + "/tdb-dataset.ttl", VocabTDB2.tDatasetTDB) ;
++    }
++
++    @Test
++    public void createDatasetEmbed() {
++        createTest(dirAssem + "/tdb-dataset-embed.ttl", DatasetAssemblerVocab.tDataset) ;
++    }
++
++    private void createTest(String filename, Resource type) {
++        Object thing = AssemblerUtils.build(filename, type) ;
++        assertTrue(thing instanceof Dataset) ;
++        Dataset ds = (Dataset)thing ;
++        assertTrue(ds.asDatasetGraph() instanceof DatasetGraphSwitchable) ;
++        assertTrue(ds.supportsTransactions()) ;
++        ds.close() ;
++    }
++
++    @Test
++    public void createGraphDirect() {
++        testGraph(dirAssem + "/tdb-graph.ttl", false) ;
++    }
++
++    @Test
++    public void createGraphEmbed() {
++        String f = dirAssem + "/tdb-graph-embed.ttl" ;
++        Object thing = null ;
++        try {
++            thing = AssemblerUtils.build(f, JA.Model) ;
++        }
++        catch (AssemblerException e) {
++            e.getCause().printStackTrace(System.err) ;
++            throw e ;
++        }
++
++        assertTrue(thing instanceof Model) ;
++        Graph graph = ((Model)thing).getGraph() ;
++        assertTrue(graph instanceof GraphViewSwitchable) ;
++
++        DatasetGraphSwitchable ds = ((GraphViewSwitchable)graph).getDataset() ;
++        if ( ds != null )
++            ds.close() ;
++    }
++
++    @Test
++    public void createNamedGraph1() {
++        testGraph(dirAssem + "/tdb-named-graph-1.ttl", true) ;
++    }
++
++    @Test
++    public void createNamedGraph2() {
++        testGraph(dirAssem + "/tdb-named-graph-2.ttl", true) ;
++    }
++
++    @Test
++    public void createNamedGraphViaDataset() {
++        testGraph(dirAssem + "/tdb-graph-ref-dataset.ttl", false) ;
++    }
++
++    private static void testGraph(String assemblerFile, boolean named) {
++        Object thing = null ;
++        try {
++            thing = AssemblerUtils.build(assemblerFile, VocabTDB2.tGraphTDB) ;
++        }
++        catch (AssemblerException e) {
++            e.getCause().printStackTrace(System.err) ;
++            throw e ;
++        }
++
++        assertTrue(thing instanceof Model) ;
++        Graph graph = ((Model)thing).getGraph() ;
++
++        assertTrue(graph instanceof GraphViewSwitchable) ;
++
++        DatasetGraphSwitchable dsg = ((GraphViewSwitchable)graph).getDataset();
++        if ( dsg != null )
++            dsg.close() ;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/AbstractTestGraphsTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/AbstractTestGraphsTDB.java
index 0000000,0000000..762e8ee
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/AbstractTestGraphsTDB.java
@@@ -1,0 -1,0 +1,50 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
++import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
++import org.apache.jena.sparql.graph.GraphsTests ;
++import org.junit.AfterClass ;
++import org.junit.BeforeClass ;
++import org.junit.Ignore ;
++import org.junit.Test ;
++import org.seaborne.tdb2.sys.SystemTDB ;
++
++public abstract class AbstractTestGraphsTDB extends GraphsTests
++{
++    private static ReorderTransformation reorder  ;
++    
++    @BeforeClass public static void setupClass()
++    {
++        reorder = SystemTDB.defaultReorderTransform ;
++        SystemTDB.defaultReorderTransform = ReorderLib.identity() ;
++    }
++    
++    @AfterClass public static void afterClass() {  SystemTDB.defaultReorderTransform = reorder ; }
++
++    // These don't pass ... not quite clear if the test is right.  Investigate.
++    
++    @Override
++    @Ignore @Test public void graph_count5() {} 
++    
++    @Override
++    @Ignore @Test public void graph_count6() {} 
++    
++
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TS_Graph.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TS_Graph.java
index 0000000,0000000..b6dbdea
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TS_Graph.java
@@@ -1,0 -1,0 +1,35 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.junit.runner.RunWith ;
++import org.junit.runners.Suite ;
++
++@RunWith(Suite.class)
++@Suite.SuiteClasses( {
++    TestPrefixMappingTDB.class
++    , TestDatasetGraphTDB.class
++    , TestGraphsTDB1.class
++    , TestGraphsTDB2.class
++    , TestDatasetGraphAccessorTDB.class
++    , TestGraphOverDatasetTDB.class
++})
++public class TS_Graph
++{
++
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphAccessorTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphAccessorTDB.java
index 0000000,0000000..8184154
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphAccessorTDB.java
@@@ -1,0 -1,0 +1,47 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.apache.jena.query.DatasetAccessorFactory ;
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.core.DatasetGraph ;
++import org.apache.jena.web.AbstractTestDatasetGraphAccessor ;
++import org.apache.jena.web.DatasetGraphAccessor ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.seaborne.tdb2.junit.TL ;
++
++public class TestDatasetGraphAccessorTDB extends AbstractTestDatasetGraphAccessor
++{
++    DatasetGraph dsg = TL.createTestDatasetGraphMem() ;
++    @Before public void before() {
++        dsg.begin(ReadWrite.WRITE);
++    }
++    
++    @After public void after() {
++        dsg.abort();
++        dsg.end();
++        TL.expel(dsg);
++    }
++
++    @Override
++    protected DatasetGraphAccessor getDatasetUpdater()
++    {
++        return DatasetAccessorFactory.make(dsg) ;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphTDB.java
index 0000000,0000000..0cd2bca
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphTDB.java
@@@ -1,0 -1,0 +1,52 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.core.AbstractDatasetGraphTests ;
++import org.apache.jena.sparql.core.DatasetGraph ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.junit.Test ;
++import org.seaborne.tdb2.junit.TL ;
++
++// Quad tests
++public class TestDatasetGraphTDB extends AbstractDatasetGraphTests
++{
++    DatasetGraph dsg = TL.createTestDatasetGraphMem() ;
++    @Before public void before() {
++        dsg.begin(ReadWrite.WRITE);
++    }
++    
++    @After public void after() {
++        dsg.abort();
++        dsg.end();
++        TL.expel(dsg);
++    }
++    
++    @Override
++    protected DatasetGraph emptyDataset() {
++        return dsg ;
++    }
++
++    @Override
++    // Empty graph tests: N/A
++    @Test public void graph_01()
++    {}
++
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphOverDatasetTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphOverDatasetTDB.java
index 0000000,0000000..de01a86
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphOverDatasetTDB.java
@@@ -1,0 -1,0 +1,63 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.apache.jena.graph.Graph ;
++import org.apache.jena.graph.Node ;
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.core.AbstractTestGraphOverDataset ;
++import org.apache.jena.sparql.core.DatasetGraph ;
++import org.junit.After ;
++import org.seaborne.tdb2.junit.TL ;
++
++/** This is the view-graph test suite run over a TDB DatasetGraph to check compatibility */
++public class TestGraphOverDatasetTDB extends AbstractTestGraphOverDataset
++{
++    DatasetGraph dsg = null;
++    @After public void after2() {
++        if ( dsg == null )
++            return;
++        dsg.abort();
++        dsg.end();
++        TL.expel(dsg);
++    }
++    
++    @Override
++    protected DatasetGraph createBaseDSG() {
++        // Called in initialization.
++        if ( dsg == null ) {
++            dsg = TL.createTestDatasetGraphMem() ;
++            dsg.begin(ReadWrite.WRITE);
++        }
++        return dsg ;
++    }
++    
++    @Override
++    protected Graph makeNamedGraph(DatasetGraph dsg, Node gn)
++    {
++        return dsg.getGraph(gn) ;
++    }
++
++    @Override
++    protected Graph makeDefaultGraph(DatasetGraph dsg)
++    {
++        return  dsg.getDefaultGraph() ;
++    }
++
++}
++

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB1.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB1.java
index 0000000,0000000..3f703e5
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB1.java
@@@ -1,0 -1,0 +1,42 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.query.ReadWrite ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.seaborne.tdb2.junit.TL ;
++
++public class TestGraphsTDB1 extends AbstractTestGraphsTDB
++{
++    Dataset ds = TL.createTestDatasetMem();
++    @Before public void before() {
++        ds.begin(ReadWrite.WRITE);
++    }
++    
++    @After public void after() {
++        ds.abort();
++        ds.end();
++        TL.expel(ds);
++    }
++    @Override
++    protected Dataset createDataset() {
++        return ds ;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB2.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB2.java
index 0000000,0000000..ba665f8
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB2.java
@@@ -1,0 -1,0 +1,51 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.query.ReadWrite ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.seaborne.dboe.jenax.Txn ;
++import org.seaborne.tdb2.TDB2Factory ;
++
++public class TestGraphsTDB2 extends AbstractTestGraphsTDB
++{
++    // Transactional.
++    @Before
++    public void before() {
++        getDataset().begin(ReadWrite.READ) ;
++    }
++
++    @After
++    public void after() {
++        getDataset().end() ;
++    }
++
++    @Override
++    protected void fillDataset(Dataset dataset) {
++        Txn.executeWrite(dataset, ()->{
++            super.fillDataset(dataset) ;
++        });
++    }
++    
++    @Override
++    protected Dataset createDataset() {
++        return TDB2Factory.createDataset() ;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestPrefixMappingTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestPrefixMappingTDB.java
index 0000000,0000000..7deaea4
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/graph/TestPrefixMappingTDB.java
@@@ -1,0 -1,0 +1,106 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.graph;
++
++import org.apache.jena.atlas.lib.FileOps ;
++import org.apache.jena.shared.PrefixMapping ;
++import org.apache.jena.sparql.core.DatasetPrefixStorage ;
++import org.apache.jena.sparql.graph.AbstractTestPrefixMapping2 ;
++import org.junit.* ;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.tdb2.ConfigTest ;
++import org.seaborne.tdb2.junit.BuildTestLib ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++public class TestPrefixMappingTDB extends AbstractTestPrefixMapping2
++{
++    static DatasetPrefixStorage last = null ;
++    
++    @BeforeClass public static void beforeClass() {}
++    @AfterClass public static void afterClass()   { TDBInternal.reset() ; ConfigTest.deleteTestingDir() ; }
++
++    @Before public void before() { TDBInternal.reset() ; }
++    @After public  void after()  { }
++
++    
++    @Override
++    protected PrefixMapping create() {
++        last = createTestingMem() ;
++        return view() ;
++    }
++
++    static DatasetPrefixStorage createTestingMem() { 
++        return createTesting(Location.mem()) ;
++    }
++    
++    static DatasetPrefixStorage createTesting(Location location) {
++        return BuildTestLib.makePrefixes(location) ;
++    }
++
++    @Override
++    protected PrefixMapping view() {
++        return last.getPrefixMapping() ; 
++    }
++
++    @Test public void multiple1() {
++        DatasetPrefixStorage prefixes = createTestingMem() ;
++        PrefixMapping pmap1 = prefixes.getPrefixMapping() ;
++        PrefixMapping pmap2 = prefixes.getPrefixMapping("http://graph/") ;
++        pmap1.setNsPrefix("x", "http://foo/") ;
++        assertNull(pmap2.getNsPrefixURI("x")) ;
++        assertNotNull(pmap1.getNsPrefixURI("x")) ;
++    }
++    
++    @Test public void multiple2() {
++        DatasetPrefixStorage prefixes = createTestingMem() ;
++        PrefixMapping pmap1 = prefixes.getPrefixMapping("http://graph/") ;  // Same
++        PrefixMapping pmap2 = prefixes.getPrefixMapping("http://graph/") ;
++        pmap1.setNsPrefix("x", "http://foo/") ;
++        assertNotNull(pmap2.getNsPrefixURI("x")) ;
++        assertNotNull(pmap1.getNsPrefixURI("x")) ;
++    }
++    
++    // Persistent.
++    @Test
++    public void persistent1() {
++        String dir = ConfigTest.getTestingDir() ;
++        FileOps.clearDirectory(dir) ;
++
++        DatasetPrefixStorage prefixes = createTesting(Location.create(dir)) ;
++        PrefixMapping pmap1 = prefixes.getPrefixMapping() ;
++
++        String x = pmap1.getNsPrefixURI("x") ;
++        assertNull(x) ;
++        prefixes.close() ;
++    }
++    
++    // Persistent.
++    @Test
++    public void persistent2() {
++        String dir = ConfigTest.getTestingDir() ;
++        FileOps.clearDirectory(dir) ;
++
++        DatasetPrefixStorage prefixes = createTesting(Location.create(dir)) ;
++        PrefixMapping pmap1 = prefixes.getPrefixMapping() ;
++
++        pmap1.setNsPrefix("x", "http://foo/") ;
++        assertEquals("http://foo/", pmap1.getNsPrefixURI("x")) ;
++        prefixes.close() ;
++    }
++    
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/AbstractTestGraphTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/AbstractTestGraphTDB.java
index 0000000,0000000..bac78a5
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/AbstractTestGraphTDB.java
@@@ -1,0 -1,0 +1,33 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.junit;
++
++import org.apache.jena.graph.test.AbstractTestGraph ;
++
++public abstract class AbstractTestGraphTDB extends AbstractTestGraph
++{
++    public AbstractTestGraphTDB(String name)
++    {
++        super(name) ;
++    }
++    
++    @Override public void testIsomorphismFile() {}
++    
++    // Meaning less - graphs (and hence models) are not indpenedent of their datasets. 
++    @Override public void testCloseSetsIsClosed() {}
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/Base_TS.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/Base_TS.java
index 0000000,0000000..ce2eda1
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/Base_TS.java
@@@ -1,0 -1,0 +1,51 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.junit;
++
++import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
++import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
++import org.apache.log4j.Level ;
++import org.apache.log4j.Logger ;
++import org.junit.AfterClass ;
++import org.junit.BeforeClass ;
++import org.seaborne.tdb2.sys.SystemTDB ;
++
++public class Base_TS
++{
++    static Level level = null ;
++    static ReorderTransformation rt = null ;
++    
++    @BeforeClass static public void beforeClass()   
++    {
++        rt = SystemTDB.defaultReorderTransform ;
++        level = Logger.getLogger("org.apache.jena.tdb.info").getLevel() ;
++        Logger.getLogger("org.apache.jena.tdb.info").setLevel(Level.FATAL) ;
++        Logger.getLogger("org.seaborne.tdb2.info").setLevel(Level.FATAL) ;
++        SystemTDB.defaultReorderTransform = ReorderLib.identity() ;
++        rt = SystemTDB.defaultReorderTransform ;
++    }
++    
++    @AfterClass static public void afterClass()
++    {
++        if ( level != null ) {
++            Logger.getLogger("org.apache.jena.tdb.info").setLevel(level) ;
++            Logger.getLogger("org.seaborne.tdb2.info").setLevel(level) ;
++        }
++        SystemTDB.defaultReorderTransform = rt ;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/BuildTestLib.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/BuildTestLib.java
index 0000000,0000000..171232e
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/BuildTestLib.java
@@@ -1,0 -1,0 +1,81 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.junit;
++
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.core.DatasetPrefixStorage ;
++import org.seaborne.dboe.base.file.* ;
++import org.seaborne.dboe.base.record.RecordFactory ;
++import org.seaborne.dboe.index.Index ;
++import org.seaborne.dboe.index.IndexParams ;
++import org.seaborne.dboe.index.RangeIndex ;
++import org.seaborne.dboe.trans.bplustree.BPlusTree ;
++import org.seaborne.dboe.trans.bplustree.BPlusTreeFactory ;
++import org.seaborne.tdb2.setup.StoreParams ;
++import org.seaborne.tdb2.setup.TDBBuilder ;
++import org.seaborne.tdb2.store.DatasetGraphTDB ;
++import org.seaborne.tdb2.store.nodetable.NodeTable ;
++import org.seaborne.tdb2.store.nodetable.NodeTableCache ;
++import org.seaborne.tdb2.store.nodetable.NodeTableInline ;
++import org.seaborne.tdb2.store.nodetable.NodeTableTRDF ;
++import org.seaborne.tdb2.sys.SystemTDB ;
++
++/** Build things for non-transactional tests.
++ * Sometimes, create a daatset and find the relevant part. 
++ */
++public class BuildTestLib {
++
++    public static RangeIndex buildRangeIndex(FileSet mem, RecordFactory factory, IndexParams indexParams) {
++        BPlusTree bpt = BPlusTreeFactory.makeMem(5, factory.keyLength(), factory.valueLength()) ;
++        bpt.nonTransactional() ;
++        return bpt ; 
++    }
++
++    public static NodeTable makeNodeTable(Location location, String basename, StoreParams params) {
++        NodeTable nt = makeNodeTableBase(location, basename, params) ;
++        nt = NodeTableCache.create(nt, params) ;
++        nt = NodeTableInline.create(nt) ;
++        return nt ;
++    }
++    
++    public static NodeTable makeNodeTableBase(Location location, String basename, StoreParams params) {
++        RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
++        FileSet fs = new FileSet(location, basename) ;
++                
++        Index index = buildRangeIndex(fs, recordFactory, params) ;
++        BinaryDataFile bdf = createBinaryDataFile(location, basename+"-data") ;
++        NodeTable nt = new NodeTableTRDF(index, bdf) ;
++        return nt ;
++    }
++
++    public static DatasetPrefixStorage makePrefixes(Location location) {
++        DatasetGraphTDB ds = (DatasetGraphTDB)TDBBuilder.build(location) ;
++        ds.begin(ReadWrite.WRITE);
++        return ds.getPrefixes() ; 
++    }
++    
++    /** Create a non-thread-safe BinaryDataFile*/ 
++    public static BinaryDataFile createBinaryDataFile(Location loc, String name) {
++        if ( loc.isMem() )
++            return new BinaryDataFileMem() ;
++        String filename = loc.getPath(name) ;
++        return new BinaryDataFileRandomAccess(filename) ;
++    }
++
++}
++

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/QueryTestTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/QueryTestTDB.java
index 0000000,0000000..ef16ed9
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/QueryTestTDB.java
@@@ -1,0 -1,0 +1,192 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.junit;
++
++import java.util.List ;
++
++import org.apache.jena.query.* ;
++import org.apache.jena.rdf.model.Model ;
++import org.apache.jena.sparql.SystemARQ ;
++import org.apache.jena.sparql.engine.QueryEngineFactory ;
++import org.apache.jena.sparql.engine.QueryExecutionBase ;
++import org.apache.jena.sparql.engine.ref.QueryEngineRef ;
++import org.apache.jena.sparql.junit.EarlReport ;
++import org.apache.jena.sparql.junit.EarlTestCase ;
++import org.apache.jena.sparql.junit.TestItem ;
++import org.apache.jena.sparql.resultset.ResultSetCompare ;
++import org.apache.jena.sparql.resultset.SPARQLResult ;
++import org.apache.jena.util.FileManager ;
++import org.seaborne.dboe.jenax.Txn ;
++import org.seaborne.tdb2.TDB2Factory ;
++import org.slf4j.Logger ;
++import org.slf4j.LoggerFactory ;
++
++public class QueryTestTDB extends EarlTestCase
++{
++    // Changed to using in-memory graphs/datasets because this is testing the query
++    // processing.  Physical graph/datsets is in package "store". 
++    
++    private static Logger log = LoggerFactory.getLogger(QueryTestTDB.class) ;
++    private Dataset dataset = null ;
++
++    boolean skipThisTest = false ;
++
++    final List<String> defaultGraphURIs ;
++    final List<String> namedGraphURIs ;
++    final String queryFile ; 
++    final SPARQLResult results ;
++    
++    // Track what's currently loaded in the GraphLocation
++    private static List<String> currentDefaultGraphs = null ;
++    private static List<String> currentNamedGraphs = null ;
++
++    // Old style (Junit3)
++    public QueryTestTDB(String testName, EarlReport report, TestItem item)
++    {
++        this(testName, report, item.getURI(), 
++             item.getDefaultGraphURIs(), item.getNamedGraphURIs(), 
++             item.getResults(), item.getQueryFile()
++             ) ;
++    }
++    
++    public QueryTestTDB(String testName, EarlReport report, 
++                        String uri,
++                        List<String> dftGraphs,
++                        List<String> namedGraphs,
++                        SPARQLResult rs,
++                        String queryFile
++                        )
++    {
++        super(testName, uri, report) ;
++        this.defaultGraphURIs = dftGraphs ;
++        this.namedGraphURIs = namedGraphs ;
++        this.queryFile = queryFile ;
++        this.results = rs ;
++    }
++    
++    boolean oldValueUsePlainGraph = SystemARQ.UsePlainGraph ;
++    
++    @Override public void setUpTest() {
++        dataset = TDB2Factory.createDataset() ;
++        Txn.executeWrite(dataset, ()->{
++            setupData() ;
++        }) ;
++        // Make sure a plain, no sameValueAs graph is used.
++        oldValueUsePlainGraph = SystemARQ.UsePlainGraph ;
++        SystemARQ.UsePlainGraph = true ;
++    }
++    
++    @Override public void tearDownTest()
++    { 
++        if ( dataset != null )
++        {
++            dataset.close() ;
++            dataset = null ;
++        }
++        SystemARQ.UsePlainGraph = oldValueUsePlainGraph ;
++    }
++    
++    public void setupData()
++    {
++        if ( compareLists(defaultGraphURIs, currentDefaultGraphs) &&
++             compareLists(namedGraphURIs, currentNamedGraphs) )
++            return ;
++        
++        if ( defaultGraphURIs == null )
++            throw new TDBTestException("No default graphs given") ;
++
++        //graphLocation.clear() ;
++        
++        for ( String fn : defaultGraphURIs )
++            load(dataset.getDefaultModel(), fn) ;
++        
++        for ( String fn : namedGraphURIs )
++            load(dataset.getNamedModel(fn), fn) ;
++    }
++    
++    
++    @Override
++    protected void runTestForReal() throws Throwable
++    {
++        if ( skipThisTest )
++        {
++            log.info(this.getName()+" : Skipped") ;
++            return ;
++        }
++        
++        Query query = QueryFactory.read(queryFile) ;
++        Dataset ds = DatasetFactory.create(defaultGraphURIs, namedGraphURIs) ;
++        
++        // ---- First, get the expected results by executing in-memory or from a results file.
++        
++        ResultSetRewindable rs1$ = null ;
++        String expectedLabel$ = "" ;
++        if ( results != null )
++        {
++            rs1$ = ResultSetFactory.makeRewindable(results.getResultSet()) ;
++            expectedLabel$ = "Results file" ;
++        }
++        else
++        {
++            QueryEngineFactory f = QueryEngineRef.getFactory() ;
++            try(QueryExecution qExec1 = new QueryExecutionBase(query, ds, null, f)) {
++                rs1$ = ResultSetFactory.makeRewindable(qExec1.execSelect()) ;
++            }
++            expectedLabel$ = "Standard engine" ;
++        }
++        // Effectively final.
++        ResultSetRewindable rs1 = rs1$ ;
++        String expectedLabel = expectedLabel$ ;
++        // ---- Second, execute in persistent graph
++
++        Dataset ds2 = dataset ; //DatasetFactory.create(model) ;
++        Txn.executeRead(ds2, ()->{
++            try(QueryExecution qExec2 = QueryExecutionFactory.create(query, ds2)) {
++                ResultSet rs = qExec2.execSelect() ;
++                ResultSetRewindable rs2 = ResultSetFactory.makeRewindable(rs) ;
++
++                // See if the same.
++                boolean b = ResultSetCompare.equalsByValue(rs1, rs2) ;
++                if ( !b )
++                {
++                    rs1.reset() ;
++                    rs2.reset() ;
++                    System.out.println("------------------- "+this.getName());
++                    System.out.printf("**** Expected (%s)", expectedLabel) ;
++                    ResultSetFormatter.out(System.out, rs1) ; 
++                    System.out.println("**** Got (TDB)") ;
++                    ResultSetFormatter.out(System.out, rs2) ;
++                }
++
++                assertTrue("Results sets not the same", b) ;
++            }
++        }) ;
++    }
++
++    private static void load(Model model, String fn)
++    {
++        FileManager.get().readModel(model, fn) ;
++    }
++    
++    private static boolean compareLists(List<String> list1, List<String> list2)
++    {
++        if ( list1 == null )
++            return ( list2 == null ) ;
++        return list1.equals(list2) ;
++    }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TDBTestException.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TDBTestException.java
index 0000000,0000000..e2e2bcb
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TDBTestException.java
@@@ -1,0 -1,0 +1,28 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.junit;
++
++import org.seaborne.tdb2.TDBException ;
++
++public class TDBTestException extends TDBException
++{
++    public TDBTestException() {}
++    public TDBTestException(String msg) { super(msg) ; }
++    public TDBTestException(Throwable th) { super(th) ;}
++    public TDBTestException(String msg, Throwable th) { super(msg, th) ; }
++}

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TL.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TL.java
index 0000000,0000000..4ff4ae6
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TL.java
@@@ -1,0 -1,0 +1,89 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.junit;
++
++import java.util.function.Consumer ;
++
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.sparql.core.DatasetGraph ;
++import org.apache.jena.system.Txn ;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.tdb2.ConfigTest ;
++import org.seaborne.tdb2.DatabaseMgr ;
++import org.seaborne.tdb2.TDB2Factory ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++/** Support for tests to be less "transaction-y" */
++public class TL {
++    
++    public static void exec(Consumer<Dataset> action) {
++        Dataset dataset = createTestDataset();
++        try { 
++            Txn.executeWrite(dataset, ()->action.accept(dataset));
++            //TDBInternal.reset();
++            
++        } finally { expel(dataset); } 
++    }
++    
++    public static void execMem(Consumer<Dataset> action) {
++        Dataset dataset = createTestDatasetMem() ;
++        Txn.executeWrite(dataset, ()->action.accept(dataset));
++        expel(dataset);
++    }
++    
++    public static void expel(Dataset dataset) {
++        expel(dataset.asDatasetGraph());
++    }
++
++    public static void expel(DatasetGraph dataset) {
++        TDBInternal.expel(dataset);
++    }
++
++    // Or use these for @Before, @After style.
++    
++    public static Location cleanLocation() {
++        // To avoid the problems on MS Windows where memory mapped files
++        // can't be deleted from a running JVM, we use a different, cleaned 
++        // directory each time.
++        String dirname = ConfigTest.getCleanDir() ;
++        Location location = Location.create(dirname) ;
++        return location ;
++    }
++    
++    private static void releaseDataset(Dataset dataset) {
++        dataset.abort() ;
++        expel(dataset);
++    }
++
++    private static Dataset createTestDataset() {
++        Location location = cleanLocation() ;
++        Dataset dataset = TDB2Factory.connectDataset(location) ;
++        return dataset ;
++    }
++    
++    public static Dataset createTestDatasetMem() {
++        Dataset dataset = TDB2Factory.createDataset() ;
++        return dataset ;
++    }
++
++    public static DatasetGraph createTestDatasetGraphMem() {
++        DatasetGraph dataset = DatabaseMgr.createDatasetGraph() ;
++        return dataset ;
++    }
++}
++

http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TestFactoryTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TestFactoryTDB.java
index 0000000,0000000..516de02
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/junit/TestFactoryTDB.java
@@@ -1,0 -1,0 +1,87 @@@
++/*
++ *  Licensed 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.
++ *
++ *  See the NOTICE file distributed with this work for additional
++ *  information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.junit;
++
++import junit.framework.Test ;
++import junit.framework.TestCase ;
++import junit.framework.TestSuite ;
++import org.apache.jena.rdf.model.Resource ;
++import org.apache.jena.sparql.junit.EarlReport ;
++import org.apache.jena.sparql.junit.SurpressedTest ;
++import org.apache.jena.sparql.junit.TestItem ;
++import org.apache.jena.sparql.vocabulary.TestManifestX ;
++import org.apache.jena.util.junit.TestFactoryManifest ;
++
++public class TestFactoryTDB extends TestFactoryManifest
++{
++    public static EarlReport report = null ;
++    
++    public static void make(TestSuite ts, String manifestFile, String testRootName)
++    {
++        // for each graph type do
++        TestSuite ts2 = makeSuite(manifestFile, testRootName) ;
++        ts.addTest(ts2) ;
++    }
++    
++    public static TestSuite makeSuite(String manifestFile, String testRootName)
++    {
++        TestFactoryTDB f = new TestFactoryTDB(testRootName) ;
++        TestSuite ts = f.process(manifestFile) ;
++        if ( testRootName != null )
++            ts.setName(testRootName+ts.getName()) ;
++        return ts ;
++    }
++    
++    // Factory
++    
++    public String testRootName ;
++
++    public TestFactoryTDB(String testRootName)
++    {
++        this.testRootName = testRootName ;
++    }
++    
++    @Override
++    protected Test makeTest(Resource manifest, Resource entry, String testName, Resource action, Resource result)
++    {
++        if ( testRootName != null )
++            testName = testRootName+testName ;
++        
++        TestItem testItem = TestItem.create(entry, null) ;
++        
++        TestCase test = null ;
++        
++        if ( testItem.getTestType() != null )
++        {
++            if ( testItem.getTestType().equals(TestManifestX.TestQuery) )
++                test = new QueryTestTDB(testName, report, testItem) ;
++            
++            if ( testItem.getTestType().equals(TestManifestX.TestSurpressed) )
++                test = new SurpressedTest(testName, report, testItem) ;
++            
++            if ( test == null )
++                System.err.println("Unrecognized test type: "+testItem.getTestType()) ;
++        }
++        // Default 
++        if ( test == null )
++            test = new QueryTestTDB(testName, report, testItem) ;
++
++        return test ;
++    }
++
++}


Mime
View raw message