jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject svn commit: r1458030 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/ jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/ jena-jdbc-driver-tdb/src/main/java/org/apache/jena/jdbc/tdb/
Date Mon, 18 Mar 2013 21:49:06 GMT
Author: rvesse
Date: Mon Mar 18 21:49:06 2013
New Revision: 1458030

URL: http://svn.apache.org/r1458030
Log:
Refactor to account for NodeFactory -> NodeFactoryExtra, initial stub for TDB driver

Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java
    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-tdb/src/main/java/org/apache/jena/jdbc/tdb/TDBDriver.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java?rev=1458030&r1=1458029&r2=1458030&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/utils/JenaJdbcNodeUtils.java
Mon Mar 18 21:49:06 2013
@@ -28,6 +28,7 @@ import java.util.Set;
 import com.hp.hpl.jena.graph.Node;
 import com.hp.hpl.jena.sparql.expr.NodeValue;
 import com.hp.hpl.jena.sparql.util.NodeFactory;
+import com.hp.hpl.jena.sparql.util.NodeFactoryExtra;
 import com.hp.hpl.jena.vocabulary.XSD;
 
 /**
@@ -123,7 +124,7 @@ public class JenaJdbcNodeUtils {
         try {
             if (n == null) return 0;
             if (n.isLiteral()) {
-                return NodeFactory.nodeToInt(n);
+                return NodeFactoryExtra.nodeToInt(n);
             } else {
                 throw new SQLException("Unable to marshal a non-literal to an integer");
             }
@@ -146,7 +147,7 @@ public class JenaJdbcNodeUtils {
         try {
             if (n == null) return 0;
             if (n.isLiteral()) {
-                return NodeFactory.nodeToLong(n);
+                return NodeFactoryExtra.nodeToLong(n);
             } else {
                 throw new SQLException("Unable to marshal a non-literal to a long integer");
             }
@@ -169,7 +170,7 @@ public class JenaJdbcNodeUtils {
         try {
             if (n == null) return 0;
             if (n.isLiteral()) {
-                return NodeFactory.nodeToFloat(n);
+                return NodeFactoryExtra.nodeToFloat(n);
             } else {
                 throw new SQLException("Unable to marshal a non-literal to a float");
             }
@@ -192,7 +193,7 @@ public class JenaJdbcNodeUtils {
         try {
             if (n == null) return 0;
             if (n.isLiteral()) {
-                return NodeFactory.nodeToDouble(n);
+                return NodeFactoryExtra.nodeToDouble(n);
             } else {
                 throw new SQLException("Unable to marshal a non-literal to a double");
             }

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetConnection.java?rev=1458030&r1=1458029&r2=1458030&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetConnection.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-mem/src/main/java/org/apache/jena/jdbc/mem/JenaJdbcDatasetConnection.java
Mon Mar 18 21:49:06 2013
@@ -65,6 +65,7 @@ public class JenaJdbcDatasetConnection e
             for (JenaJdbcDatasetStatement stmt : this.statements) {
                 stmt.close();
             }
+            this.ds.close();
         } finally {
             this.ds = 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=1458030&r1=1458029&r2=1458030&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 Mar 18 21:49:06 2013
@@ -22,9 +22,13 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Properties;
 
+import org.apache.jena.jdbc.JenaJdbcConnection;
 import org.apache.jena.jdbc.JenaJdbcDriver;
+import org.apache.jena.jdbc.mem.JenaJdbcDatasetConnection;
 
 import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.DatasetFactory;
+import com.hp.hpl.jena.tdb.TDBFactory;
 
 /**
  * <p>
@@ -37,19 +41,28 @@ import com.hp.hpl.jena.query.Dataset;
  * This driver expects a URL of the following form:
  * </p>
  * <pre>
- * jdbc:jena:mem:dataset=file.nq
+ * jdbc:jena:tdb:location=/path/to/dataset;must-exist=false
  * </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.
+ * The {@code location} parameter is used to refer to a folder containing the
+ * TDB dataset you wish to load. The {@code must-exist} parameter indicates
+ * whether the TDB dataset must already exist, if false then the driver will
+ * create a new empty TDB dataset in that location if a TDB dataset does not
+ * already exist.
  * </p>
  */
 public class TDBDriver extends JenaJdbcDriver {
     
+    /**
+     * 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:";
+    
+    public static final String PARAM_LOCATION = "location";
+    
+    public static final String PARAM_MUST_EXIST = "must-exist";
+    
+    public static final String PARAM_TRANSACTIONAL = "transactional";
 
     /**
      * Creates a new TDB driver
@@ -60,8 +73,22 @@ public class TDBDriver extends JenaJdbcD
 
     @Override
     protected Connection connect(Properties props) throws SQLException {
-        // TODO Auto-generated method stub
-        return null;
+        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");
+        
+        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);
+        
+        // TODO If transactional is set use the dataset in transactional mode - needs a Transactional
connection instance
+        // Return a JenaJdbcDatasetConnection for the TDB dataset
+        return (Connection) new JenaJdbcDatasetConnection(tdb, JenaJdbcConnection.DEFAULT_HOLDABILITY);
     }
 
 



Mime
View raw message