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/23 01:41:03 UTC

svn commit: r1470753 - in /jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata: JenaMetadata.java MetadataSchema.java results/MetaResultSet.java

Author: rvesse
Date: Mon Apr 22 23:41:03 2013
New Revision: 1470753

URL: http://svn.apache.org/r1470753
Log:
Logic fixes to MetaResultSet, implemented some more metadata returns

Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/results/MetaResultSet.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java?rev=1470753&r1=1470752&r2=1470753&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/JenaMetadata.java Mon Apr 22 23:41:03 2013
@@ -156,14 +156,12 @@ public abstract class JenaMetadata imple
 
     @Override
     public ResultSet getClientInfoProperties() throws SQLException {
-        // TODO Auto-generated method stub
-        return null;
+        return new MetaResultSet(MetadataSchema.getClientInfoPropertyColumns());
     }
 
     @Override
     public ResultSet getColumnPrivileges(String arg0, String arg1, String arg2, String arg3) throws SQLException {
-        // TODO Auto-generated method stub
-        return null;
+        return new MetaResultSet(MetadataSchema.getColumnPrivilegeColumns());
     }
 
     @Override
@@ -522,8 +520,7 @@ public abstract class JenaMetadata imple
 
     @Override
     public ResultSet getUDTs(String arg0, String arg1, String arg2, int[] arg3) throws SQLException {
-        // TODO Auto-generated method stub
-        return null;
+        return new MetaResultSet(MetadataSchema.getUdtColumns());
     }
 
     @Override

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java?rev=1470753&r1=1470752&r2=1470753&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/MetadataSchema.java Mon Apr 22 23:41:03 2013
@@ -49,6 +49,12 @@ public class MetadataSchema {
 
     private static ColumnInfo[] CATALOG_COLUMNS;
 
+    private static ColumnInfo[] CLIENT_INFO_PROPERTY_COLUMNS;
+
+    private static ColumnInfo[] COLUMN_PRIVILEGE_COLUMNS;
+
+    private static ColumnInfo[] UDT_COLUMNS;
+
     /**
      * Gets the columns for the
      * {@link DatabaseMetaData#getAttributes(String, String, String, String)}
@@ -81,6 +87,25 @@ public class MetadataSchema {
     }
 
     /**
+     * Gets the columns for the
+     * {@link DatabaseMetaData#getClientInfoProperties()} method
+     * 
+     * @return Column information
+     * 
+     */
+    public static ColumnInfo[] getClientInfoPropertyColumns() {
+        return CLIENT_INFO_PROPERTY_COLUMNS;
+    }
+
+    public static ColumnInfo[] getColumnPrivilegeColumns() {
+        return COLUMN_PRIVILEGE_COLUMNS;
+    }
+
+    public static ColumnInfo[] getUdtColumns() {
+        return UDT_COLUMNS;
+    }
+
+    /**
      * Static initializer, calls private synchronized static initializer to
      * avoid multi-threaded race conditions
      */
@@ -189,8 +214,7 @@ public class MetadataSchema {
                     // where DECIMAL_DIGITS is not applicable.
                     new ShortIntegerColumn("DECIMAL_DIGITS", columnNullable, true),
                     // PSEUDO_COLUMN short => is this a pseudo column like an
-                    // Oracle
-                    // ROWID
+                    // Oracle ROWID
                     // bestRowUnknown - may or may not be pseudo column
                     // bestRowNotPseudo - is NOT a pseudo column
                     // bestRowPseudo - is a pseudo column
@@ -199,6 +223,61 @@ public class MetadataSchema {
             CATALOG_COLUMNS = new ColumnInfo[] {
             // TABLE_CAT String => catalog name
             new StringColumn("TABLE_CAT", columnNoNulls) };
+
+            CLIENT_INFO_PROPERTY_COLUMNS = new ColumnInfo[] {
+                    // NAME String=> The name of the client info property
+                    new StringColumn("NAME", columnNoNulls),
+                    // MAX_LEN int=> The maximum length of the value for the
+                    // property
+                    new IntegerColumn("MAX_LEN", columnNoNulls, true),
+                    // DEFAULT_VALUE String=> The default value of the property
+                    new StringColumn("DEFAULT_VALUE", columnNullable),
+                    // DESCRIPTION String=> A description of the property. This
+                    // will typically contain information as to where this
+                    // property is stored in the database.
+                    new StringColumn("DESCRIPTION", columnNullable) };
+
+            COLUMN_PRIVILEGE_COLUMNS = new ColumnInfo[] {
+                    // TABLE_CAT String => table catalog (may be null)
+                    new StringColumn("TABLE_CAT", columnNullable),
+                    // TABLE_SCHEM String => table schema (may be null)
+                    new StringColumn("TABLE_SCHEM", columnNullable),
+                    // TABLE_NAME String => table name
+                    new StringColumn("TABLE_NAME", columnNoNulls),
+                    // COLUMN_NAME String => column name
+                    new StringColumn("COLUMN_NAME", columnNoNulls),
+                    // GRANTOR String => grantor of access (may be null)
+                    new StringColumn("GRANTOR", columnNullable),
+                    // GRANTEE String => grantee of access
+                    new StringColumn("GRANTEE", columnNullable),
+                    // PRIVILEGE String => name of access (SELECT, INSERT,
+                    // UPDATE, REFRENCES, ...)
+                    new StringColumn("PRIVILEGE", columnNoNulls),
+                    // IS_GRANTABLE String => "YES" if grantee is permitted to
+                    // grant to others; "NO" if not; null if unknown
+                    new StringColumn("IS_GRANTABLE", columnNoNulls) };
+
+            UDT_COLUMNS = new ColumnInfo[] {
+                    // TYPE_CAT String => the type's catalog (may be null)
+                    new StringColumn("TYPE_CAT", columnNullable),
+                    // TYPE_SCHEM String => type's schema (may be null)
+                    new StringColumn("TYPE_SCHEM", columnNullable),
+                    // TYPE_NAME String => type name
+                    new StringColumn("TYPE_NAME", columnNoNulls),
+                    // CLASS_NAME String => Java class name
+                    new StringColumn("CLASS_NAME", columnNoNulls),
+                    // DATA_TYPE int => type value defined in java.sql.Types.
+                    // One of JAVA_OBJECT, STRUCT, or DISTINCT
+                    new IntegerColumn("DATA_TYPE", columnNoNulls, true),
+                    // REMARKS String => explanatory comment on the type
+                    new StringColumn("REMARKS", columnNullable),
+                    // BASE_TYPE short => type code of the source type of a
+                    // DISTINCT type or the type that implements the
+                    // user-generated reference type of the
+                    // SELF_REFERENCING_COLUMN of a structured type as defined
+                    // in java.sql.Types (null if DATA_TYPE is not DISTINCT or
+                    // not STRUCT with REFERENCE_GENERATION = USER_DEFINED)
+                    new ShortIntegerColumn("BASE_TYPE", columnNullable, true) };
         } catch (SQLException e) {
             throw new Error("Fatal error initializing JDBC metadata schema information");
         }

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/results/MetaResultSet.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/results/MetaResultSet.java?rev=1470753&r1=1470752&r2=1470753&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/results/MetaResultSet.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/metadata/results/MetaResultSet.java Mon Apr 22 23:41:03 2013
@@ -78,12 +78,17 @@ public class MetaResultSet implements Re
      */
     public MetaResultSet(ColumnInfo[] columns, Object[][] rows) throws SQLException {
         if (columns == null)
-            throw new IllegalArgumentException("Column information cannot be null");
+            throw new SQLException("Column information cannot be null");
         if (rows == null)
-            throw new IllegalArgumentException("Row data cannot be null");
+            throw new SQLException("Row data cannot be null");
         this.columns = columns;
         this.rows = rows;
         this.metadata = new MetaResultSetMetadata(this, this.columns);
+        
+        // Validate row widths if any rows
+        for (Object[] row : rows) {
+            if (row.length != this.columns.length) throw new SQLException("One of the rows given does not have the expected number of columns");
+        }
     }
 
     @Override
@@ -201,32 +206,33 @@ public class MetaResultSet implements Re
             throw new SQLException("Result set is closed");
         if (this.currRow < 0 || this.currRow >= this.rows.length)
             throw new SQLException("Not currently at a row");
-        if (columnIndex < 1 || columnIndex > this.columns.length)
-            throw new SQLException("Column index is out of bounds");
-
-        // Remember that JDBC uses a 1 based index
-        ColumnInfo info = this.columns[columnIndex - 1];
-
-        // Determine whether the column has a null value
-        Object obj = this.rows[this.currRow][columnIndex];
-        this.wasNull = (obj == null);
-        if (this.wasNull)
-            return nullValue;
-
-        if (info.getType() == expectedType) {
-            // If the column is typed appropriately try and marshal
-            // appropriately
-            if (targetType.isAssignableFrom(obj.getClass())) {
-                try {
-                    return targetType.cast(obj);
-                } catch (ClassCastException e) {
+        if (columnIndex >= 1 && columnIndex <= this.columns.length) {
+            // Remember that JDBC uses a 1 based index
+            ColumnInfo info = this.columns[columnIndex - 1];
+
+            // Determine whether the column has a null value
+            Object obj = this.rows[this.currRow][columnIndex - 1];
+            this.wasNull = (obj == null);
+            if (this.wasNull)
+                return nullValue;
+
+            if (info.getType() == expectedType) {
+                // If the column is typed appropriately try and marshal
+                // appropriately
+                if (targetType.isAssignableFrom(obj.getClass())) {
+                    try {
+                        return targetType.cast(obj);
+                    } catch (ClassCastException e) {
+                        throw new SQLException("Value for this column in the current row is not valid for the column type");
+                    }
+                } else {
                     throw new SQLException("Value for this column in the current row is not valid for the column type");
                 }
             } else {
-                throw new SQLException("Value for this column in the current row is not valid for the column type");
+                throw new SQLException("Given column does not contain decimal values");
             }
         } else {
-            throw new SQLException("Given column does not contain decimal values");
+            throw new SQLException("Column index is out of bounds");
         }
     }