jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject svn commit: r1492320 - in /jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc: results/ results/metadata/ results/metadata/columns/ statements/
Date Wed, 12 Jun 2013 18:18:49 GMT
Author: rvesse
Date: Wed Jun 12 18:18:27 2013
New Revision: 1492320

URL: http://svn.apache.org/r1492320
Log:
Some tweaks to support column type re-mapping for SELECT results metadata

Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaResultSet.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/AbstractResultsMetadata.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/SelectResultsMetadata.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/columns/StringColumn.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaResultSet.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaResultSet.java?rev=1492320&r1=1492319&r2=1492320&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaResultSet.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/JenaResultSet.java
Wed Jun 12 18:18:27 2013
@@ -365,7 +365,6 @@ public abstract class JenaResultSet impl
             case Types.BINARY:
             case Types.BIT:
             case Types.BLOB:
-            case Types.CHAR:
             case Types.CLOB:
             case Types.DATALINK:
             case Types.DISTINCT:
@@ -383,7 +382,6 @@ public abstract class JenaResultSet impl
             case Types.SQLXML:
             case Types.STRUCT:
             case Types.VARBINARY:
-            case Types.VARCHAR:
                 throw new SQLException("Unable to marhsal a RDF Node to the declared column
type " + jdbcType);
             case Types.BOOLEAN:
                 return JdbcNodeUtils.toBoolean(n);
@@ -401,6 +399,8 @@ public abstract class JenaResultSet impl
                 return JdbcNodeUtils.toInt(n);
             case Types.JAVA_OBJECT:
                 return n;
+            case Types.CHAR:
+            case Types.VARCHAR:
             case Types.NVARCHAR:
                 return JdbcNodeUtils.toString(n);
             case Types.SMALLINT:

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/AbstractResultsMetadata.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/AbstractResultsMetadata.java?rev=1492320&r1=1492319&r2=1492320&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/AbstractResultsMetadata.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/AbstractResultsMetadata.java
Wed Jun 12 18:18:27 2013
@@ -23,13 +23,14 @@ import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.jena.jdbc.results.metadata.columns.ColumnInfo;
 
 /**
  * Abstract implementation of JDBC result set metadata
- *
+ * 
  */
 public class AbstractResultsMetadata implements ResultSetMetaData {
 
@@ -38,9 +39,13 @@ public class AbstractResultsMetadata imp
 
     /**
      * Abstract implementation of result set metadata
-     * @param results Result Set
-     * @param columns Column information
-     * @throws SQLException Thrown if metadata cannot be created
+     * 
+     * @param results
+     *            Result Set
+     * @param columns
+     *            Column information
+     * @throws SQLException
+     *             Thrown if metadata cannot be created
      */
     public AbstractResultsMetadata(ResultSet results, ColumnInfo[] columns) throws SQLException
{
         if (results == null)
@@ -190,4 +195,14 @@ public class AbstractResultsMetadata imp
         return this.getColumnInfo(column).isWritable();
     }
 
+    /**
+     * Gets a copy of the raw underlying column information
+     * 
+     * @return Column Information
+     * @throws SQLException
+     */
+    public List<ColumnInfo> getJenaColumnInfo() throws SQLException {
+        return new ArrayList<ColumnInfo>(this.columns);
+    }
+
 }
\ No newline at end of file

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/SelectResultsMetadata.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/SelectResultsMetadata.java?rev=1492320&r1=1492319&r2=1492320&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/SelectResultsMetadata.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/SelectResultsMetadata.java
Wed Jun 12 18:18:27 2013
@@ -43,10 +43,9 @@ import com.hp.hpl.jena.sparql.resultset.
  * 
  */
 public class SelectResultsMetadata extends JenaResultsMetadata {
-    
+
     private static final Logger LOGGER = LoggerFactory.getLogger(SelectResultsMetadata.class);
 
-    @SuppressWarnings("unused")
     private ResultSetPeekable innerResults;
 
     /**
@@ -77,49 +76,72 @@ public class SelectResultsMetadata exten
     }
 
     /**
-     * Makes column information for SELECT results 
-     * @param results Result Set
-     * @param rset Underlying SPARQL results
+     * Creates new SELECT results metadata
+     * 
+     * @param metadata Original metadata
+     * @param columns
+     *            Column metadata
+     * @throws SQLException
+     */
+    public SelectResultsMetadata(SelectResultsMetadata metadata, ColumnInfo[] columns) throws
SQLException {
+        super(metadata.getJenaResultSet(), columns);
+        this.innerResults = metadata.innerResults;
+    }
+
+    /**
+     * Makes column information for SELECT results
+     * 
+     * @param results
+     *            Result Set
+     * @param rset
+     *            Underlying SPARQL results
      * @return Column information
-     * @throws SQLException Thrown if the column information cannot be created
+     * @throws SQLException
+     *             Thrown if the column information cannot be created
      */
     private static ColumnInfo[] makeColumns(JenaResultSet results, ResultSetPeekable rset)
throws SQLException {
         List<String> vars = rset.getResultVars();
         ColumnInfo[] columns = new ColumnInfo[vars.size()];
-        
+
         int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel());
         boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level);
         boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level);
-        
+
         Binding b = null;
         if (columnsDetected) {
             if (rset.hasNext()) {
                 b = rset.peekBinding();
             } else {
-                // If we were supposed to detect columns but there is no data available then
we will just fallback to typing everything as strings
+                // If we were supposed to detect columns but there is no data
+                // available then we will just fallback to typing everything as
+                // strings
                 columnsAsStrings = true;
                 columnsDetected = false;
             }
         }
-        
+
         for (int i = 0; i < columns.length; i++) {
             if (!columnsAsStrings && !columnsDetected) {
-                // Low compatibility, report columns as being typed as JAVA_OBJECT with ARQ
Node as the column class
+                // Low compatibility, report columns as being typed as
+                // JAVA_OBJECT with ARQ Node as the column class
                 columns[i] = new SparqlColumnInfo(vars.get(i), Types.JAVA_OBJECT, columnNullable);
                 LOGGER.info("Low JDBC compatibility, column " + vars.get(i) + " is being
typed as Node");
             } else if (columnsAsStrings) {
-                // Medium compatibility, report columns as being typed as NVARCHAR with String
as the column class
+                // Medium compatibility, report columns as being typed as
+                // NVARCHAR with String as the column class
                 columns[i] = new StringColumn(vars.get(i), columnNullable);
                 LOGGER.info("Medium JDBC compatibility, column " + vars.get(i) + " is being
typed as String");
             } else if (columnsDetected) {
-                // High compatibility, detect columns types based on first row of results
+                // High compatibility, detect columns types based on first row
+                // of results
                 columns[i] = JdbcCompatibility.detectColumnType(vars.get(i), b.get(Var.alloc(vars.get(i))),
true);
-                LOGGER.info("High compatibility, column " + vars.get(i) + " was detected
as being of type " + columns[i].getClassName());
+                LOGGER.info("High compatibility, column " + vars.get(i) + " was detected
as being of type "
+                        + columns[i].getClassName());
             } else {
                 throw new SQLFeatureNotSupportedException("Unknown JDBC compatibility level
was set");
             }
         }
-        
+
         return columns;
     }
 }

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/columns/StringColumn.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/columns/StringColumn.java?rev=1492320&r1=1492319&r2=1492320&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/columns/StringColumn.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/results/metadata/columns/StringColumn.java
Wed Jun 12 18:18:27 2013
@@ -23,18 +23,36 @@ import java.sql.Types;
 
 /**
  * Column information for string columns
- *
+ * 
  */
 public class StringColumn extends SparqlColumnInfo {
 
     /**
      * Creates new string column information
-     * @param label Label
-     * @param nullable Nullability
+     * 
+     * @param label
+     *            Label
+     * @param nullable
+     *            Nullability
      * @throws SQLException
      */
     public StringColumn(String label, int nullable) throws SQLException {
-        super(label, Types.NVARCHAR, nullable);
+        this(label, Types.NVARCHAR, nullable);
+    }
+
+    /**
+     * Creates new string column information
+     * 
+     * @param label
+     *            Label
+     * @param sqlType
+     *            SQL Type
+     * @param nullable
+     *            Nullability
+     * @throws SQLException
+     */
+    public StringColumn(String label, int sqlType, int nullable) throws SQLException {
+        super(label, sqlType, nullable);
         this.setClassName(String.class.getName());
     }
 

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java?rev=1492320&r1=1492319&r2=1492320&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java
(original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/statements/JenaPreparedStatement.java
Wed Jun 12 18:18:27 2013
@@ -369,7 +369,6 @@ public abstract class JenaPreparedStatem
             case Types.BINARY:
             case Types.BIT:
             case Types.BLOB:
-            case Types.CHAR:
             case Types.CLOB:
             case Types.DATALINK:
             case Types.DISTINCT:
@@ -387,7 +386,6 @@ public abstract class JenaPreparedStatem
             case Types.SQLXML:
             case Types.STRUCT:
             case Types.VARBINARY:
-            case Types.VARCHAR:
                 throw new SQLException("The provided SQL Target Type cannot be translated
into an appropriate RDF term type");
             case Types.BIGINT:
                 if (value instanceof Long) {
@@ -529,7 +527,9 @@ public abstract class JenaPreparedStatem
                     this.setParameter(parameterIndex, NodeFactory.createLiteral(value.toString()));
                 }
                 break;
+            case Types.CHAR:
             case Types.NVARCHAR:
+            case Types.VARCHAR:
                 this.setParameter(parameterIndex, NodeFactory.createLiteral(value.toString()));
                 break;
             case Types.SMALLINT:



Mime
View raw message