jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject svn commit: r1463327 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/src/main/java/org/apache/jena/jdbc/ jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/ jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/ jena-jdbc-driver-remote...
Date Mon, 01 Apr 2013 22:30:16 GMT
Author: rvesse
Date: Mon Apr  1 22:30:16 2013
New Revision: 1463327

URL: http://svn.apache.org/r1463327
Log:
Stub for remote endpoint driver

Added:
    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-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetStatement.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/MemDriver.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java
Removed:
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetConnection.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetStatement.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcMemDriver.java
Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcDriver.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcDatasetConnection.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcMemDriver.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/TDBDriver.java
    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/TestJenaJdbcTdbMemConnection.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcDriver.java?rev=1463327&r1=1463326&r2=1463327&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcDriver.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaJdbcDriver.java
Mon Apr  1 22:30:16 2013
@@ -30,32 +30,41 @@ import java.util.Properties;
 
 /**
  * Abstract implementation of a Jena JDBC driver
- *
+ * 
  */
 public abstract class JenaJdbcDriver implements Driver {
-    
+
     /**
-     * Constant for the primary Jena JDBC Driver prefix, implementations supply an additional
prefix which will form the next portion of the JDBC URL
+     * Constant for the primary Jena JDBC Driver prefix, implementations supply
+     * an additional prefix which will form the next portion of the JDBC URL
      */
     public static final String DRIVER_PREFIX = "jdbc:jena:";
 
     private int majorVer, minorVer;
     private String implPrefix;
-    
+
     /**
      * Creates a new driver
-     * @param majorVer Major Version
-     * @param minorVer Minor Version
-     * @param prefix Implementation specific prefix
+     * 
+     * @param majorVer
+     *            Major Version
+     * @param minorVer
+     *            Minor Version
+     * @param prefix
+     *            Implementation specific prefix
      */
     public JenaJdbcDriver(int majorVer, int minorVer, String prefix) {
         this.majorVer = majorVer;
         this.minorVer = minorVer;
-        
-        if (prefix == null) throw new IllegalArgumentException("Implementation specific prefix
cannot be null");
-        if (!prefix.endsWith(":")) throw new IllegalArgumentException("Implementation specific
prefix must end with a :");
-        //Validate that implPrefix is a valid scheme i.e. [A-Za-z\d\-_]+
-        if (!prefix.matches("[A-Za-z\\d\\-_]+:")) throw new IllegalArgumentException("Implementation
specific prefix must conform to the regular expression [A-Za-z\\d\\-_]+:");
+
+        if (prefix == null)
+            throw new IllegalArgumentException("Implementation specific prefix cannot be
null");
+        if (!prefix.endsWith(":"))
+            throw new IllegalArgumentException("Implementation specific prefix must end with
a :");
+        // Validate that implPrefix is a valid scheme i.e. [A-Za-z\d\-_]+
+        if (!prefix.matches("[A-Za-z\\d\\-_]+:"))
+            throw new IllegalArgumentException(
+                    "Implementation specific prefix must conform to the regular expression
[A-Za-z\\d\\-_]+:");
         this.implPrefix = prefix;
     }
 
@@ -71,14 +80,15 @@ public abstract class JenaJdbcDriver imp
     public Connection connect(String url, Properties props) throws SQLException {
         // Create new empty properties if necessary
         Properties ps = new Properties();
-        
+
         // Parse out the key value pairs from the connection URL
         url = url.substring(DRIVER_PREFIX.length() + this.implPrefix.length());
         String[] kvps = url.split("&|;");
         for (int i = 0; i < kvps.length; i++) {
             String kvp = kvps[i];
-            if (kvp.length() == 0) continue;
-            
+            if (kvp.length() == 0)
+                continue;
+
             // Try to split into key and value
             String key, value;
             if (kvp.contains("=")) {
@@ -89,10 +99,10 @@ public abstract class JenaJdbcDriver imp
                 key = kvp;
                 value = null;
             }
-            
+
             // All keys are normalized to lower case using the English Locale
             key = key.toLowerCase(Locale.ENGLISH);
-            
+
             // Put into properties appropriately
             if (!ps.containsKey(key)) {
                 // Doesn't yet exist, add a string/list as appropriate
@@ -108,7 +118,7 @@ public abstract class JenaJdbcDriver imp
                 Object currValue = ps.get(key);
                 if (currValue instanceof List<?>) {
                     // Can just append to existing list
-                    ((List<Object>)currValue).add(value);
+                    ((List<Object>) currValue).add(value);
                 } else {
                     // Convert to list
                     List<String> values = new ArrayList<String>();
@@ -118,7 +128,7 @@ public abstract class JenaJdbcDriver imp
                 }
             }
         }
-        
+
         // Overwrite connection URL parameters with code provided parameters
         // if applicable
         if (props != null) {
@@ -127,32 +137,41 @@ public abstract class JenaJdbcDriver imp
                 ps.put(e.getKey().toString().toLowerCase(Locale.ENGLISH), e.getValue());
             }
         }
-        
+
         // Try to create the connection
         return this.connect(ps);
     }
-    
+
     /**
      * Gets whether a parameter is allowed to have multiple values
-     * @param key Key
+     * 
+     * @param key
+     *            Key
      * @return True if multiple values are allowed, false otherwise
      */
     protected boolean allowsMultipleValues(String key) {
         return false;
     }
-        
+
     /**
-     * Method which derived classes must implement to create their actual connections
+     * Method which derived classes must implement to create their actual
+     * connections
      * <p>
-     * The driver will already have parsed the connection URL to extract out any connection
parameters and has
-     * added them to the parameters provided in the Properties object.  Parameters which
the implementation
-     * has indicated allow multiple values will be present as {@link List} in the properties,
all other parameters
-     * will be either strings or the original values as injected by the calling code.  Properties
specified in
-     * the {@link Properties} object by the calling code have precedence over the connection
URL parameters.
+     * The driver will already have parsed the connection URL to extract out any
+     * connection parameters and has added them to the parameters provided in
+     * the Properties object. Parameters which the implementation has indicated
+     * allow multiple values will be present as {@link List} in the properties,
+     * all other parameters will be either strings or the original values as
+     * injected by the calling code. Properties specified in the
+     * {@link Properties} object by the calling code have precedence over the
+     * connection URL parameters.
      * </p>
-     * @param props Properties
+     * 
+     * @param props
+     *            Properties
      * @return Connection
-     * @throws SQLException Thrown if a connection cannot be created for any reason
+     * @throws SQLException
+     *             Thrown if a connection cannot be created for any reason
      */
     protected abstract Connection connect(Properties props) throws SQLException;
 
@@ -168,11 +187,15 @@ public abstract class JenaJdbcDriver imp
         return new DriverPropertyInfo[0];
     }
 
-    public boolean jdbcCompliant() {
+    /**
+     * Returns that a Jena JDBC driver is not JDBC compliant since strict JDBC
+     * compliance requires support for SQL-92 and since we are using SPARQL we
+     * don't meet that criteria
+     */
+    public final boolean jdbcCompliant() {
         // This has to be false since we are not JDBC compliant in that
         // we use SPARQL in place of SQL-92
         return false;
     }
 
-
 }

Added: 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=1463327&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetConnection.java
Mon Apr  1 22:30:16 2013
@@ -0,0 +1,151 @@
+/**
+ * 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.mem;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jena.jdbc.JenaJdbcConnection;
+
+import com.hp.hpl.jena.query.Dataset;
+
+/**
+ * Represents a connection to a {@link Dataset} intance
+ *
+ */
+public class DatasetConnection extends JenaJdbcConnection {
+    
+    private Dataset ds;
+    private List<DatasetStatement> statements = new ArrayList<DatasetStatement>();
+    private boolean readonly = false;
+    
+    /**
+     * Creates a new dataset connection
+     * @param ds
+     * @param holdability
+     * @throws SQLException
+     */
+    public DatasetConnection(Dataset ds, int holdability) throws SQLException {
+        super(holdability);
+        this.ds = ds;
+    }
+    
+    /**
+     * Gets the dataset to which this connection pertains
+     * @return Dataset
+     */
+    protected final Dataset getJenaDataset() {
+        return this.ds;
+    }
+
+    @Override
+    public void close() throws SQLException {
+        try {
+            //Close any open statements
+            for (DatasetStatement stmt : this.statements) {
+                stmt.close();
+            }
+            this.ds.close();
+        } finally {
+            this.ds = null;
+        }
+    }
+
+    @Override
+    public Statement createStatement() throws SQLException {
+        return this.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+    }
+
+    @Override
+    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws
SQLException {
+        return this.createStatement(resultSetType, resultSetConcurrency, DEFAULT_HOLDABILITY);
+    }
+
+    @Override
+    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
+        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);
+        this.statements.add(stmt);
+        return stmt;
+    }
+
+    @Override
+    public boolean isClosed() throws SQLException {
+        return this.ds == null;
+    }
+
+    @Override
+    public boolean isReadOnly() throws SQLException {
+        return this.readonly;
+    }
+
+    @Override
+    public boolean isValid(int timeout) throws SQLException {
+        return !this.isClosed();
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql) throws SQLException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
{
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
{
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
{
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability)
+            throws SQLException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setReadOnly(boolean readOnly) throws SQLException {
+        if (this.isClosed()) throw new SQLException("Cannot set read-only mode on a closed
connection");
+        this.readonly = readOnly;
+    }
+
+}

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetStatement.java?rev=1463327&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetStatement.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/DatasetStatement.java
Mon Apr  1 22:30:16 2013
@@ -0,0 +1,90 @@
+/**
+ * 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.mem;
+
+import java.sql.SQLException;
+
+import org.apache.jena.jdbc.JenaJdbcStatement;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.update.GraphStoreFactory;
+import com.hp.hpl.jena.update.UpdateExecutionFactory;
+import com.hp.hpl.jena.update.UpdateProcessor;
+import com.hp.hpl.jena.update.UpdateRequest;
+
+/**
+ * A Jena JDBC statement over a {@link Dataset}
+ *
+ */
+public class DatasetStatement extends JenaJdbcStatement {
+    
+    private DatasetConnection dsConn;
+
+    /**
+     * Creates a new statement
+     * 
+     * @param connection
+     *            Connection
+     * @throws SQLException
+     *             Thrown if there is an error with the statement parameters
+     */
+    public DatasetStatement(DatasetConnection connection) throws SQLException {
+        this(connection, DEFAULT_FETCH_DIRECTION, DEFAULT_FETCH_SIZE, DEFAULT_HOLDABILITY);
+    }
+    
+    /**
+     * Creates a new statement
+     * 
+     * @param connection
+     *            Connection
+     * @param fetchDir
+     *            Fetch Direction
+     * @param fetchSize
+     *            Fetch Size
+     * @param holdability
+     *            Result Set holdability
+     * @throws SQLException
+     *             Thrown if there is an error with the statement parameters
+     * 
+     */
+    public DatasetStatement(DatasetConnection connection, int fetchDir, int fetchSize, int
holdability) throws SQLException {
+        super(connection, fetchDir, fetchSize, holdability);
+        this.dsConn = connection;
+    }
+
+    /**
+     * Creates a query execution over the dataset
+     */
+    @Override
+    protected QueryExecution createQueryExecution(Query q) {
+        return QueryExecutionFactory.create(q, this.dsConn.getJenaDataset());
+    }
+
+    /**
+     * Creates an update execution over the dataset
+     */
+    @Override
+    protected UpdateProcessor createUpdateProcessor(UpdateRequest u) {
+        return UpdateExecutionFactory.create(u, GraphStoreFactory.create(this.dsConn.getJenaDataset()));
+    }
+
+}

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/MemDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/MemDriver.java?rev=1463327&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/MemDriver.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/MemDriver.java
Mon Apr  1 22:30:16 2013
@@ -0,0 +1,120 @@
+/**
+ * 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.mem;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.jena.jdbc.JenaJdbcConnection;
+import org.apache.jena.jdbc.JenaJdbcDriver;
+import org.apache.jena.riot.RDFDataMgr;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetFactory;
+
+/**
+ * <p>
+ * A Jena JDBC driver which creates connections to in-memory datasets
+ * </p>
+ * <h3>
+ * Connection URL
+ * </h3>
+ * <p>
+ * This driver expects a URL of the following form:
+ * </p>
+ * <pre>
+ * jdbc:jena:mem:dataset=file.nq
+ * </pre>
+ * <p>
+ * The {@code dataset} parameter is used to refer to a file containing the
+ * dataset you wish to load. Note that if you are creating the connection in
+ * code you may alternatively opt to provide a {@link Dataset} instance directly
+ * as a property named {@code dataset} to the
+ * {@link #connect(String, Properties)} method instead.
+ * </p>
+ * <p>
+ * If you simply want to start with an empty dataset you may instead set the {@code empty}
+ * parameter to be true e.g.
+ * </p>
+ * <pre>
+ * jdbc:jena:mem:empty=true
+ * </pre>
+ */
+public class MemDriver extends JenaJdbcDriver {
+    
+    /**
+     * Constant for the memory 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 MEM_DRIVER_PREFIX = "mem:";
+    
+    /**
+     * Constant for the connection URL parameter used to specify a dataset file/instance
to use
+     */
+    public static final String PARAM_DATASET = "dataset";
+    
+    /**
+     * Constant for the connection URL parameter used to specify that an empty dataset should
be used.  If {@link #PARAM_DATASET} is present then that parameter has precedence.
+     */
+    public static final String PARAM_EMPTY = "empty";
+    
+    /**
+     * Registers the driver with the JDBC {@link DriverManager}
+     * @throws SQLException Thrown if the driver cannot be registered
+     */
+    public static void register() throws SQLException {
+        DriverManager.registerDriver(new MemDriver());
+    }
+
+    /**
+     * Creates a new driver
+     */
+    public MemDriver() {
+        super(0, 1, MEM_DRIVER_PREFIX);
+    }
+
+    @Override
+    protected Connection connect(Properties props) throws SQLException {
+        Object dsObj = props.get(PARAM_DATASET);
+        String empty = props.getProperty(PARAM_EMPTY);
+        if (empty != null) empty = empty.toLowerCase();
+        if (dsObj == null && empty == null) throw new SQLException("Neither one of
the " + PARAM_DATASET + " or " + PARAM_EMPTY + " connection parameters is not present in the
JDBC Connection URL or the provided Properties object");
+        
+        if (dsObj != null) {
+            if (dsObj instanceof Dataset) {
+                // Dataset provided directly
+                return (Connection) new DatasetConnection((Dataset)dsObj, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+            } else {
+                try {
+                    Dataset ds = DatasetFactory.createMem();
+                    RDFDataMgr.read(ds, dsObj.toString());
+                    return (Connection) new DatasetConnection(ds, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+                } catch (Exception e) {
+                    throw new SQLException("Error occurred while reading from the specified
RDF dataset file - " + dsObj.toString(), e);
+                }
+            }
+        } else if ("true".equals(empty)) {
+            return (Connection) new DatasetConnection(DatasetFactory.createMem(), JenaJdbcConnection.DEFAULT_HOLDABILITY);
+        } else {
+            throw new SQLException("Insufficient parameters to create a Jena JDBC in-memory
connection, please supply a Dataset file/instance via the " + PARAM_DATASET + " parameter
or supply " + PARAM_EMPTY + "=true to connect to a new empty dataset");
+        }
+    }
+
+}

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcDatasetConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcDatasetConnection.java?rev=1463327&r1=1463326&r2=1463327&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcDatasetConnection.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcDatasetConnection.java
Mon Apr  1 22:30:16 2013
@@ -27,7 +27,7 @@ import com.hp.hpl.jena.query.Dataset;
 import com.hp.hpl.jena.query.DatasetFactory;
 
 /**
- * Tests for the {@link JenaJdbcDatasetConnection}
+ * Tests for the {@link DatasetConnection}
  * @author rvesse
  *
  */
@@ -35,12 +35,12 @@ public class TestJenaJdbcDatasetConnecti
 
     @Override
     protected JenaJdbcConnection getConnection() throws SQLException {
-        return new JenaJdbcDatasetConnection(DatasetFactory.createMem(), JenaJdbcConnection.DEFAULT_HOLDABILITY);
+        return new DatasetConnection(DatasetFactory.createMem(), JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 
     @Override
     protected JenaJdbcConnection getConnection(Dataset ds) throws SQLException {
-        return new JenaJdbcDatasetConnection(ds, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+        return new DatasetConnection(ds, JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 
     

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcMemDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcMemDriver.java?rev=1463327&r1=1463326&r2=1463327&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcMemDriver.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/test/java/org/apache/jena/jdbc/mem/TestJenaJdbcMemDriver.java
Mon Apr  1 22:30:16 2013
@@ -22,23 +22,23 @@ import org.apache.jena.jdbc.AbstractJena
 import org.apache.jena.jdbc.JenaJdbcDriver;
 
 /**
- * Tests for the {@link JenaJdbcMemDriver}
+ * Tests for the {@link MemDriver}
  *
  */
 public class TestJenaJdbcMemDriver extends AbstractJenaJdbcDriverTests {
 
     @Override
     protected JenaJdbcDriver getDriver() {
-        return new JenaJdbcMemDriver();
+        return new MemDriver();
     }
 
     @Override
     protected String getConnectionUrl() {
-        return JenaJdbcDriver.DRIVER_PREFIX + JenaJdbcMemDriver.MEM_DRIVER_PREFIX + JenaJdbcMemDriver.PARAM_EMPTY
+ "=true";
+        return JenaJdbcDriver.DRIVER_PREFIX + MemDriver.MEM_DRIVER_PREFIX + MemDriver.PARAM_EMPTY
+ "=true";
     }
 
     @Override
     protected String getBadConnectionUrl() {
-        return JenaJdbcDriver.DRIVER_PREFIX + JenaJdbcMemDriver.MEM_DRIVER_PREFIX + JenaJdbcMemDriver.PARAM_EMPTY
+ "=false";
+        return JenaJdbcDriver.DRIVER_PREFIX + MemDriver.MEM_DRIVER_PREFIX + MemDriver.PARAM_EMPTY
+ "=false";
     }
 }

Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java?rev=1463327&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java
(added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java
Mon Apr  1 22:30:16 2013
@@ -0,0 +1,105 @@
+/**
+ * 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.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+
+import org.apache.jena.jdbc.JenaJdbcDriver;
+
+/**
+ * <p>
+ * A Jena JDBC driver which creates connections to remote endpoints
+ * </p>
+ * <h3>
+ * Connection URL</h3>
+ * <p>
+ * This driver expects a URL of the following form:
+ * </p>
+ * 
+ * <pre>
+ * jdbc:jena:remote:query=http://example.org/query&update=http://example.org/update
+ * </pre>
+ * <p>
+ * The {@code query} parameter is used to refer to a SPARQL query endpoint to
+ * use, the {@code update} parameter is used to refer to a SPARQL update
+ * endpoint to use. At least one of these parameters must be present in order to
+ * make a connection, you may omit the former to get a write only connection or
+ * the latter to get a read only connection.
+ * </p>
+ * <p>
+ * Note that since the {@code &} character is used as a separator for connection
+ * URL parameters if you need your endpoint URLs to include these you should set
+ * the relevant parameters directly on the {@link Properties} object you pass to
+ * the {@link #connect(String, Properties)} method.
+ * </p>
+ */
+public class RemoteEndpointDriver extends JenaJdbcDriver {
+    /**
+     * Constant for the remote 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 REMOTE_DRIVER_PREFIX = "remote:";
+
+    /**
+     * Constant for the connection URL parameter that sets the remote SPARQL
+     * query endpoint to use
+     */
+    public static final String PARAM_QUERY_ENDPOINT = "query";
+
+    /**
+     * Constant for the connection URL parameter that sets the remote SPARQL
+     * update endpoint to use
+     */
+    public static final String PARAM_UPDATE_ENDPOINT = "update";
+
+    /**
+     * Creates a new driver
+     */
+    public RemoteEndpointDriver() {
+        super(0, 1, REMOTE_DRIVER_PREFIX);
+    }
+
+    /**
+     * Registers the driver with the JDBC {@link DriverManager}
+     * 
+     * @throws SQLException
+     *             Thrown if the driver cannot be registered
+     */
+    public static void register() throws SQLException {
+        DriverManager.registerDriver(new RemoteEndpointDriver());
+    }
+
+    @Override
+    protected Connection connect(Properties props) throws SQLException {
+        String queryEndpoint = props.getProperty(PARAM_QUERY_ENDPOINT);
+        String updateEndpoint = props.getProperty(PARAM_UPDATE_ENDPOINT);
+
+        if (queryEndpoint == null && updateEndpoint == null)
+            throw new SQLException("At least one of the " + PARAM_QUERY_ENDPOINT + " or "
+ PARAM_UPDATE_ENDPOINT
+                    + " connection parameters must be specified to make a remote connection");
+
+        throw new SQLFeatureNotSupportedException("Not yet implemented");
+    }
+
+}

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=1463327&r1=1463326&r2=1463327&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:30:16 2013
@@ -26,7 +26,7 @@ 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.apache.jena.jdbc.mem.DatasetConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -149,7 +149,7 @@ public class TDBDriver extends JenaJdbcD
                 throw new SQLFeatureNotSupportedException("Transactional usage of TDB not
yet supported by the Jena JDBC driver");
             } else {
                 // Return a JenaJdbcDatasetConnection for the TDB dataset
-                return (Connection) new JenaJdbcDatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+                return (Connection) new DatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
             }
         } catch (SQLException e) {
             throw e;

Modified: 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=1463327&r1=1463326&r2=1463327&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbDiskConnection.java
Mon Apr  1 22:30:16 2013
@@ -23,7 +23,7 @@ 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.apache.jena.jdbc.mem.DatasetConnection;
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
 
@@ -32,7 +32,7 @@ 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
+ * Tests for the {@link DatasetConnection} backed by a purely in-memory testing only TDB
dataset
  *
  */
 public class TestJenaJdbcTdbDiskConnection extends AbstractJenaJdbcConnectionTests {
@@ -45,7 +45,7 @@ public class TestJenaJdbcTdbDiskConnecti
 
     @Override
     protected JenaJdbcConnection getConnection() throws SQLException {
-        return new JenaJdbcDatasetConnection(TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath()),
JenaJdbcConnection.DEFAULT_HOLDABILITY);
+        return new DatasetConnection(TDBFactory.createDataset(tempDir.getRoot().getAbsolutePath()),
JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 
     @Override
@@ -56,7 +56,7 @@ public class TestJenaJdbcTdbDiskConnecti
         while (qs.hasNext()) {
             tdb.asDatasetGraph().add(qs.next());
         }
-        return new JenaJdbcDatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+        return new DatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 
 }

Modified: 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=1463327&r1=1463326&r2=1463327&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-tdb/src/test/java/org/apache/jena/jdbc/tdb/TestJenaJdbcTdbMemConnection.java
Mon Apr  1 22:30:16 2013
@@ -23,21 +23,21 @@ 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.apache.jena.jdbc.mem.DatasetConnection;
 
 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
+ * Tests for the {@link DatasetConnection} 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);
+        return new DatasetConnection(TDBFactory.createDataset(), JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 
     @Override
@@ -48,7 +48,7 @@ public class TestJenaJdbcTdbMemConnectio
         while (qs.hasNext()) {
             tdb.asDatasetGraph().add(qs.next());
         }
-        return new JenaJdbcDatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
+        return new DatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 
 }



Mime
View raw message