You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/04/02 00:00:55 UTC

svn commit: r1463313 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/src/test/java/org/apache/jena/jdbc/ jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/ jena-jdbc-driver-tdb/src/test/java/org/ jena-jdbc-driver-tdb/src/test/java/org/apach...

Author: rvesse
Date: Mon Apr  1 22:00:54 2013
New Revision: 1463313

URL: http://svn.apache.org/r1463313
Log:
Include test files missing from prior commit

Added:
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDriver.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java
Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/TDBDriver.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java?rev=1463313&r1=1463312&r2=1463313&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java Mon Apr  1 22:00:54 2013
@@ -45,6 +45,7 @@ public abstract class AbstractJenaJdbcCo
 
     static {
         // Init Log4j
+        BasicConfigurator.resetConfiguration();
         BasicConfigurator.configure();
         Logger.getRootLogger().setLevel(Level.INFO);
 

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java?rev=1463313&r1=1463312&r2=1463313&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcDriverTests.java Mon Apr  1 22:00:54 2013
@@ -22,15 +22,31 @@ package org.apache.jena.jdbc;
 import java.sql.Connection;
 import java.sql.SQLException;
 
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Test;
 
+import com.hp.hpl.jena.query.ARQ;
+
 /**
  * Abstract tests for {@link JenaJdbcDriver} implementations
  * @author rvesse
  *
  */
 public abstract class AbstractJenaJdbcDriverTests {
+    
+    static {
+        // Init Log4j
+        BasicConfigurator.resetConfiguration();
+        BasicConfigurator.configure();
+        Logger.getRootLogger().setLevel(Level.INFO);
+
+        // Init ARQ
+        ARQ.init();
+    }
 
     /**
      * Method which derived classes must implement to return an instance of
@@ -57,6 +73,7 @@ public abstract class AbstractJenaJdbcDr
     @Test
     public void driver_accepts_01() throws SQLException {
         String url = this.getConnectionUrl();
+        Assume.assumeNotNull(url);
         JenaJdbcDriver driver = this.getDriver();
         
         Assert.assertTrue(driver.acceptsURL(url));
@@ -81,6 +98,7 @@ public abstract class AbstractJenaJdbcDr
     @Test
     public void driver_connect_01() throws SQLException {
         String url = this.getConnectionUrl();
+        Assume.assumeNotNull(url);
         JenaJdbcDriver driver = this.getDriver();
         
         Connection conn = driver.connect(url, null);

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/TDBDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/TDBDriver.java?rev=1463313&r1=1463312&r2=1463313&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/TDBDriver.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/TDBDriver.java Mon Apr  1 22:00:54 2013
@@ -18,6 +18,7 @@
 
 package org.apache.jena.jdbc.tdb;
 
+import java.io.File;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
@@ -26,6 +27,8 @@ import java.util.Properties;
 import org.apache.jena.jdbc.JenaJdbcConnection;
 import org.apache.jena.jdbc.JenaJdbcDriver;
 import org.apache.jena.jdbc.mem.JenaJdbcDatasetConnection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.hp.hpl.jena.query.Dataset;
 import com.hp.hpl.jena.tdb.TDBFactory;
@@ -35,11 +38,11 @@ import com.hp.hpl.jena.tdb.TDBFactory;
  * A Jena JDBC driver which creates connections to TDB datasets
  * </p>
  * <h3>
- * Connection URL
- * </h3>
+ * Connection URL</h3>
  * <p>
  * This driver expects a URL of the following form:
  * </p>
+ * 
  * <pre>
  * jdbc:jena:tdb:location=/path/to/dataset;must-exist=false
  * </pre>
@@ -56,24 +59,39 @@ import com.hp.hpl.jena.tdb.TDBFactory;
  * </p>
  */
 public class TDBDriver extends JenaJdbcDriver {
+    private static final Logger LOGGER = LoggerFactory.getLogger(TDBDriver.class);
+    
+    
     
     /**
-     * Constant for the TDB driver prefix, this is appended to the base {@link JenaJdbcDriver#DRIVER_PREFIX} to form the URL prefix for JDBC Connection URLs for this driver 
+     * Constant for the TDB driver prefix, this is appended to the base
+     * {@link JenaJdbcDriver#DRIVER_PREFIX} to form the URL prefix for JDBC
+     * Connection URLs for this driver
      */
     public static final String TDB_DRIVER_PREFIX = "tdb:";
-    
+
     /**
      * Constant for driver parameter that sets the location of the TDB dataset
      */
     public static final String PARAM_LOCATION = "location";
-    
+
+    /**
+     * Constant for special value which may be used as the value of the
+     * {@code location} parameter ({@link #PARAM_LOCATION}) to indicate that a
+     * pure in-memory dataset is desired, this should not be used for anything
+     * other than trivial testing
+     */
+    public static final String LOCATION_MEM = "memory";
+
     /**
-     * Constant for driver parameter that sets whether the TDB dataset must already exist
+     * Constant for driver parameter that sets whether the TDB dataset must
+     * already exist
      */
     public static final String PARAM_MUST_EXIST = "must-exist";
-    
+
     /**
-     * Constant for driver parameter that sets that the TDB dataset is used in transactional mode
+     * Constant for driver parameter that sets that the TDB dataset is used in
+     * transactional mode
      */
     public static final String PARAM_TRANSACTIONAL = "transactional";
 
@@ -87,20 +105,35 @@ public class TDBDriver extends JenaJdbcD
     @Override
     protected Connection connect(Properties props) throws SQLException {
         String location = props.getProperty(PARAM_LOCATION);
-        if (location == null) throw new SQLException("Required connection parameter " + PARAM_LOCATION + " is not present in the connection URL or the provided Properties object");
-        
+        if (location == null)
+            throw new SQLException("Required connection parameter " + PARAM_LOCATION
+                    + " is not present in the connection URL or the provided Properties object");
+
         String mustExist = props.getProperty(PARAM_MUST_EXIST, "false").toLowerCase();
         if ("true".equals(mustExist)) {
             // TODO Ensure the location exists
         }
-        
+
         String transactional = props.getProperty(PARAM_TRANSACTIONAL, "false").toLowerCase();
-        
+
         // Open the TDB dataset
-        Dataset tdb = TDBFactory.createDataset(location);
-        
+        boolean useMem = location.trim().toLowerCase().equals(LOCATION_MEM);
+        File loc = new File(location);
+        if (useMem) {
+            LOGGER.warn("TDB Driver connection string specifies use of a pure in-memory dataset, this is not recommended for anything other than basic testing");
+        } else {
+            if (!loc.isAbsolute()) {
+                LOGGER.warn("TDB Driver connection string specifies location " + loc.getAbsolutePath() + ", if this was not the expected location consider using an absolute instead of a relative path");
+            } else {
+                LOGGER.info("TDB Driver connection string specifies location " + loc.getAbsolutePath());
+            }
+        }
+        Dataset tdb = useMem ? TDBFactory.createDataset() : TDBFactory
+                .createDataset(location);
+
         if ("true".equals(transactional)) {
-            // TODO If transactional is set use the dataset in transactional mode - needs a Transactional connection instance
+            // TODO If transactional is set use the dataset in transactional
+            // mode - needs a Transactional connection instance
             throw new SQLFeatureNotSupportedException("Transactional usage of TDB not yet supported by the Jena JDBC driver");
         } else {
             // Return a JenaJdbcDatasetConnection for the TDB dataset
@@ -108,5 +141,4 @@ public class TDBDriver extends JenaJdbcD
         }
     }
 
-
 }

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java?rev=1463313&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java Mon Apr  1 22:00:54 2013
@@ -0,0 +1,62 @@
+/**
+ * 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.jdbc.tdb;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+import org.apache.jena.jdbc.AbstractJenaJdbcConnectionTests;
+import org.apache.jena.jdbc.JenaJdbcConnection;
+import org.apache.jena.jdbc.mem.JenaJdbcDatasetConnection;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.sparql.core.Quad;
+import com.hp.hpl.jena.tdb.TDBFactory;
+
+/**
+ * Tests for the {@link JenaJdbcDatasetConnection} backed by a purely in-memory testing only TDB dataset
+ *
+ */
+public class TestJenaJdbcTdbDiskConnection extends AbstractJenaJdbcConnectionTests {
+    
+    /**
+     * Temporary directory rule used to guarantee a unique temporary folder for each test method
+     */
+    @Rule
+    public TemporaryFolder tempDir = new TemporaryFolder();
+
+    @Override
+    protected JenaJdbcConnection getConnection() throws SQLException {
+        return new JenaJdbcDatasetConnection(TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath()), JenaJdbcConnection.DEFAULT_HOLDABILITY);
+    }
+
+    @Override
+    protected JenaJdbcConnection getConnection(Dataset ds) throws SQLException {
+        Dataset tdb = TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath());
+        
+        Iterator<Quad> qs = ds.asDatasetGraph().find();
+        while (qs.hasNext()) {
+            tdb.asDatasetGraph().add(qs.next());
+        }
+        return new JenaJdbcDatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+    }
+
+}

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDriver.java?rev=1463313&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDriver.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDriver.java Mon Apr  1 22:00:54 2013
@@ -0,0 +1,40 @@
+/**
+ * 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.jdbc.tdb;
+
+import org.apache.jena.jdbc.AbstractJenaJdbcDriverTests;
+import org.apache.jena.jdbc.JenaJdbcDriver;
+
+/**
+ * Tests for the {@link TDBDriver} implementation
+ *
+ */
+public class TestJenaJdbcTdbDriver extends AbstractJenaJdbcDriverTests {
+
+    @Override
+    protected JenaJdbcDriver getDriver() {
+        return new TDBDriver();
+    }
+
+    @Override
+    protected String getConnectionUrl() {
+        return JenaJdbcDriver.DRIVER_PREFIX + TDBDriver.TDB_DRIVER_PREFIX + TDBDriver.PARAM_LOCATION + "=" + TDBDriver.LOCATION_MEM;
+    }
+
+}

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java?rev=1463313&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java Mon Apr  1 22:00:54 2013
@@ -0,0 +1,54 @@
+/**
+ * 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.jdbc.tdb;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+import org.apache.jena.jdbc.AbstractJenaJdbcConnectionTests;
+import org.apache.jena.jdbc.JenaJdbcConnection;
+import org.apache.jena.jdbc.mem.JenaJdbcDatasetConnection;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.sparql.core.Quad;
+import com.hp.hpl.jena.tdb.TDBFactory;
+
+/**
+ * Tests for the {@link JenaJdbcDatasetConnection} backed by a purely in-memory testing only TDB dataset
+ *
+ */
+public class TestJenaJdbcTdbMemConnection extends AbstractJenaJdbcConnectionTests {
+
+    @Override
+    protected JenaJdbcConnection getConnection() throws SQLException {
+        return new JenaJdbcDatasetConnection(TDBFactory.createDataset(), JenaJdbcConnection.DEFAULT_HOLDABILITY);
+    }
+
+    @Override
+    protected JenaJdbcConnection getConnection(Dataset ds) throws SQLException {
+        Dataset tdb = TDBFactory.createDataset();
+        
+        Iterator<Quad> qs = ds.asDatasetGraph().find();
+        while (qs.hasNext()) {
+            tdb.asDatasetGraph().add(qs.next());
+        }
+        return new JenaJdbcDatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+    }
+
+}