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 02:31:55 UTC

svn commit: r1463341 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/src/test/java/org/apache/jena/jdbc/ jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/ jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/ jena-jdbc-driver-...

Author: rvesse
Date: Tue Apr  2 00:31:54 2013
New Revision: 1463341

URL: http://svn.apache.org/r1463341
Log:
Expand tests to cover remote connection implementation, some minor behavioural fixes

Added:
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointConnection.java
Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/AbstractJenaJdbcConnectionTests.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointConnection.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=1463341&r1=1463340&r2=1463341&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 Tue Apr  2 00:31:54 2013
@@ -113,6 +113,38 @@ public abstract class AbstractJenaJdbcCo
         conn.close();
         Assert.assertTrue(conn.isClosed());
     }
+    
+    /**
+     * Trying to retrieve a statement from a closed connection is an error
+     * 
+     * @throws SQLException
+     */
+    @Test(expected=SQLException.class)
+    public void connection_get_statement_02() throws SQLException {
+        JenaJdbcConnection conn = this.getConnection();
+        conn.close();
+        Assert.assertTrue(conn.isClosed());
+        
+        // Trying to create a statement after the connection is closed is an error
+        conn.createStatement();
+    }
+    
+    /**
+     * Trying to use a statement from a closed connection is an error
+     * @throws SQLException
+     */
+    @Test(expected=SQLException.class)
+    public void connection_get_statement_03() throws SQLException {
+        JenaJdbcConnection conn = this.getConnection();
+        Statement stmt = conn.createStatement();
+        Assert.assertNotNull(stmt);
+        Assert.assertFalse(stmt.isClosed());
+        conn.close();
+        Assert.assertTrue(conn.isClosed());
+        
+        // Trying to use a statement after the connection is closed is an error
+        stmt.execute("SELECT * { ?s ?p ?o }");
+    }
 
     /**
      * Runs a SELECT query on an empty database and checks it returns empty

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java?rev=1463341&r1=1463340&r2=1463341&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java Tue Apr  2 00:31:54 2013
@@ -74,16 +74,19 @@ public class DatasetConnection extends J
 
     @Override
     public Statement createStatement() throws SQLException {
+        if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed");
         return this.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     }
 
     @Override
     public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
+        if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed");
         return this.createStatement(resultSetType, resultSetConcurrency, DEFAULT_HOLDABILITY);
     }
 
     @Override
     public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+        if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed");
         if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) throw new SQLException("Jena JDBC only supports forward-only result sets");
         if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) throw new SQLException("Jena JDBC only supports read-only result sets");
         DatasetStatement stmt = new DatasetStatement(this);

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointConnection.java?rev=1463341&r1=1463340&r2=1463341&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointConnection.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointConnection.java Tue Apr  2 00:31:54 2013
@@ -92,16 +92,19 @@ public class RemoteEndpointConnection ex
 
     @Override
     public Statement createStatement() throws SQLException {
+        if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed");
         return this.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     }
 
     @Override
     public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
+        if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed");
         return this.createStatement(resultSetType, resultSetConcurrency, DEFAULT_HOLDABILITY);
     }
 
     @Override
     public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+        if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed");
         if (resultSetType != ResultSet.TYPE_FORWARD_ONLY)
             throw new SQLException("Jena JDBC only supports forward-only result sets");
         if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointConnection.java?rev=1463341&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointConnection.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointConnection.java Tue Apr  2 00:31:54 2013
@@ -0,0 +1,86 @@
+/**
+ * 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.remote;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+import org.apache.jena.fuseki.BaseServerTest;
+import org.apache.jena.fuseki.ServerTest;
+import org.apache.jena.jdbc.AbstractJenaJdbcConnectionTests;
+import org.apache.jena.jdbc.JenaJdbcConnection;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetAccessor;
+import com.hp.hpl.jena.query.DatasetAccessorFactory;
+
+/**
+ * Tests for the {@link RemoteEndpointConnection}
+ *
+ */
+public class TestRemoteEndpointConnection extends AbstractJenaJdbcConnectionTests {
+    
+    /**
+     * Setup for the tests by allocating a Fuseki instance to work with
+     */
+    @BeforeClass
+    public static void setup() {
+        ServerTest.allocServer();
+    }
+    
+    /**
+     * Clean up after each test by resetting the Fuseki instance
+     */
+    @After
+    public void cleanupTest() {
+        ServerTest.resetServer();
+    }
+    
+    /**
+     * Clean up after tests by de-allocating the Fuseki instance
+     */
+    @AfterClass
+    public static void cleanup() {
+        ServerTest.freeServer();
+    }
+
+    @Override
+    protected JenaJdbcConnection getConnection() throws SQLException {
+        return new RemoteEndpointConnection(BaseServerTest.serviceQuery, BaseServerTest.serviceUpdate, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+    }
+
+    @Override
+    protected JenaJdbcConnection getConnection(Dataset ds) throws SQLException {
+        // Set up the dataset
+        DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(BaseServerTest.serviceREST);
+        accessor.putModel(ds.getDefaultModel());
+        Iterator<String> uris = ds.listNames();
+        while (uris.hasNext()) {
+            String uri = uris.next();
+            accessor.putModel(uri, ds.getNamedModel(uri));
+        }
+        
+        return new RemoteEndpointConnection(BaseServerTest.serviceQuery, BaseServerTest.serviceUpdate, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+    }
+
+
+}