db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1064868 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 28 Jan 2011 20:50:44 GMT
Author: rhillegas
Date: Fri Jan 28 20:50:43 2011
New Revision: 1064868

URL: http://svn.apache.org/viewvc?rev=1064868&view=rev
Log:
DERBY-4869: Add JDBC 4.1 changes to DatabaseMetaData.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41DBMD.java
  (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java?rev=1064868&r1=1064867&r2=1064868&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java Fri Jan
28 20:50:43 2011
@@ -2838,6 +2838,54 @@ public abstract class DatabaseMetaData i
         return ps.executeQueryX();
     }
 
+    // ------------------- JDBC 4.1 -------------------------
+
+    /** See DatabaseMetaData javadoc */
+    public  boolean generatedKeyAlwaysReturned() { return true; }
+
+    public java.sql.ResultSet getPseudoColumns
+        ( String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern
)
+        throws SQLException
+    {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry
+                        ( this, "getPseudoColumns", catalog, schemaPattern, tableNamePattern,
columnNamePattern );
+                }
+                return getPseudoColumnsX();
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    private ResultSet getPseudoColumnsX() throws SqlException
+    {
+        checkForClosedConnectionX();
+        String sql =
+            "SELECT \n" +
+            "        CAST(NULL AS VARCHAR(128)) AS TABLE_CAT, \n" +
+            "        CAST(NULL AS VARCHAR(128)) AS TABLE_SCHEM, \n" +
+            "        VARCHAR('', 128) AS TABLE_NAME, \n" +
+            "        VARCHAR('',128) AS COLUMN_NAME, \n" +
+            "        CAST(1 AS INT) AS DATA_TYPE, \n" +
+            "        CAST(1 AS INT) AS COLUMN_SIZE, \n" +
+            "        CAST(NULL AS INT) AS DECIMAL_DIGITS, \n" +
+            "        CAST(NULL AS INT) AS NUM_PREC_RADIX, \n" +
+            "        VARCHAR('',128) AS COLUMN_USAGE, \n" +
+            "        CAST(NULL AS VARCHAR(32672)) AS REMARKS, \n" +
+            "        CAST(NULL AS INT) AS CHAR_OCTET_LENGTH, \n" +
+            "        VARCHAR('NO',128) AS IS_NULLABLE \n" +
+            "    FROM SYSIBM.SYSDUMMY1 WHERE 1=0 WITH UR"
+            ;
+        PreparedStatement ps = connection_.prepareDynamicCatalogQuery(sql);
+        return ps.executeQueryX();
+    }
+
     //----------------------------helper methods----------------------------------
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java?rev=1064868&r1=1064867&r2=1064868&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
Fri Jan 28 20:50:43 2011
@@ -3439,6 +3439,26 @@ public class EmbedDatabaseMetaData exten
         return s.executeQuery();
     }
 
+    /////////////////////////////////////////////////////////////////////////
+    //
+    //  JDBC 4.1 - New public methods
+    //
+    /////////////////////////////////////////////////////////////////////////
+
+    /** See DatabaseMetaData javadoc */
+    public  boolean generatedKeyAlwaysReturned() { return true; }
+
+	/**
+    * See DatabaseMetaData javadoc. Empty ResultSet because Derby does
+    * not support pseudo columns.
+	*/
+	public ResultSet getPseudoColumns
+        ( String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern
)
+        throws SQLException
+	{
+		return getSimpleQuery("getPseudoColumns");
+	}
+
 	//////////////////////////////////////////////////////////////
 	//
 	// MISC 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties?rev=1064868&r1=1064867&r2=1064868&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/metadata.properties Fri Jan
28 20:50:43 2011
@@ -357,7 +357,10 @@ getColumns=\
                 CAST (NULL AS VARCHAR(128)) AS SCOPE_TABLE, \
                 CAST (NULL AS SMALLINT) AS SOURCE_DATA_TYPE, \
                 CAST ((CASE WHEN (AUTOINCREMENTINC is not NULL) THEN 'YES' ELSE 'NO' END)
AS VARCHAR(128)) \
-		 	AS IS_AUTOINCREMENT \
+		 	AS IS_AUTOINCREMENT, \
+		CAST ((CASE WHEN (C.COLUMNDEFAULT IS NOT NULL AND C.COLUMNDEFAULT.toString().startsWith(
'GENERATED ALWAYS AS' ) ) THEN 'YES' \
+					ELSE  'NO' END) AS VARCHAR(128)) \
+			AS IS_GENERATEDCOLUMN \										\
 	FROM SYS.SYSSCHEMAS S, \
 			SYS.SYSTABLES T, \
 			SYS.SYSCOLUMNS C \
@@ -1284,3 +1287,23 @@ getUDTs=\
 	  AND (ALIAS LIKE ?) AND (CAST (java.sql.Types::JAVA_OBJECT AS INTEGER) IN (?)) \
 	  ORDER BY DATA_TYPE, TYPE_SCHEM, TYPE_NAME
 
+#
+# getPseudoColumns
+#
+# Returns an empty result set because Derby does not support pseudo columns.
+#
+getPseudoColumns=SELECT \
+        CAST(NULL AS VARCHAR(128)) AS TABLE_CAT, \
+        CAST(NULL AS VARCHAR(128)) AS TABLE_SCHEM, \
+        VARCHAR('', 128) AS TABLE_NAME, \
+        VARCHAR('',128) AS COLUMN_NAME, \
+        CAST(1 AS INT) AS DATA_TYPE, \
+        CAST(1 AS INT) AS COLUMN_SIZE, \
+        CAST(NULL AS INT) AS DECIMAL_DIGITS, \
+        CAST(NULL AS INT) AS NUM_PREC_RADIX, \
+        VARCHAR('',128) AS COLUMN_USAGE, \
+        CAST(NULL AS VARCHAR(32672)) AS REMARKS, \
+        CAST(NULL AS INT) AS CHAR_OCTET_LENGTH, \
+        VARCHAR('NO',128) AS IS_NULLABLE \
+    FROM SYSIBM.SYSDUMMY1 WHERE 1=0 WITH UR 
+

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=1064868&r1=1064867&r2=1064868&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Fri Jan 28 20:50:43 2011
@@ -893,7 +893,7 @@ public class DatabaseMetaDataTest extend
                 null, null, "1", "",
                 null, null, null, null,
                 "1", "YES", null, null,
-                null, null, "NO"
+                null, null, "NO", "NO"
             },
         };
         JDBC.assertFullResultSet( rs, expectedRows );
@@ -2487,8 +2487,17 @@ public class DatabaseMetaDataTest extend
                 Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
                 Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
                 Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
-                Types.VARCHAR, Types.SMALLINT, Types.VARCHAR
+                Types.VARCHAR, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR
                 };
+        boolean[]   nullability =
+        {
+            false,   false,  false,  false,
+            true,  true,   true,  true,
+            true,   true,   true,  false,
+            true,   true,   true,   true,
+            false,  false,  true,   true,
+            true,   true,   false,  false
+        };
         if (odbc == 1)
         {
             columnTypes[4] = Types.SMALLINT;
@@ -2498,17 +2507,21 @@ public class DatabaseMetaDataTest extend
             columnTypes[13] = Types.SMALLINT;
             columnTypes[14] = Types.SMALLINT;
         }
-        assertMetaDataResultSet(rs,
-                new String[] {
-                "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
-                "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
-                "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
-                "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH",
-                "ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA",
-                "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT"
-               }, columnTypes
-        , null
-              );          
+        assertMetaDataResultSet
+            (
+             rs,
+             new String[]
+             {
+                 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
+                 "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
+                 "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
+                 "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH",
+                 "ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA",
+                 "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN"
+             },
+             columnTypes,
+             nullability
+             );          
     }
 
     /**
@@ -4879,6 +4892,90 @@ public class DatabaseMetaDataTest extend
         return new Integer(i);
     }
 
+    /**
+     * Test methods added by JDBC 4.1
+     */
+    public void test_jdbc4_1() throws Exception
+    {
+        Version dataVersion = getDataVersion( getConnection() );
+        if ( dataVersion.compareTo( new Version( 10, 8, 0, 0 ) ) < 0 ) { return; }
+
+        Statement s = createStatement();
+        DatabaseMetaData dmd = getDMD();
+        println( "Testing JDBC 4.1 methods on a " + dmd.getClass().getName() );
+        Wrapper41DBMD wrapper = new Wrapper41DBMD( dmd );
+
+        //
+        // generatedKeyAlwaysReturned()
+        //
+        assertEquals( true, wrapper.generatedKeyAlwaysReturned() );
+
+        //
+        // getPseudoColumns()
+        //
+        ResultSet   rs = wrapper.getPseudoColumns( null, null, null, null );
+        assertMetaDataResultSet
+            (
+             rs,
+             new String[]
+             {
+                 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
+                 "DATA_TYPE", "COLUMN_SIZE", "DECIMAL_DIGITS", "NUM_PREC_RADIX",
+                 "COLUMN_USAGE", "REMARKS", "CHAR_OCTET_LENGTH", "IS_NULLABLE",
+             },
+             new int[]
+             {
+                 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
+                 Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER,
+                 Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR,
+             },
+             new boolean[]
+             {
+                 true,  true,   false,  false,
+                 false, false,  true,   true,
+                 false, true,   true,   false,
+             }
+             );
+        JDBC.assertFullResultSet( rs, new String[][] {} );
+
+        //
+        // IS_GENERATEDCOLUMN added to ResultSet returned by getColumns()
+        //
+        s.execute( "create table t_jdbc41( a int, b int, c generated always as ( -a ) )"
);
+        ResultSet   rs2 = dmd.getColumns( null, "APP", "T_JDBC41", null );
+        String[][] expectedRows = new String[][]
+        {
+            {
+                "", "APP", "T_JDBC41", "A",
+                "4", "INTEGER", "10", null,
+                "0", "10", "1", "",
+                null, null, null, null,
+                "1", "YES", null, null,
+                null, null, "NO", "NO"
+            },
+            {
+                "", "APP", "T_JDBC41", "B",
+                "4", "INTEGER", "10", null,
+                "0", "10", "1", "",
+                null, null, null, null,
+                "2", "YES", null, null,
+                null, null, "NO", "NO"
+            },
+            {
+                "", "APP", "T_JDBC41", "C",
+                "4", "INTEGER", "10", null,
+                "0", "10", "1", "",
+                "GENERATED ALWAYS AS ( -a )", null, null, null,
+                "3", "YES", null, null,
+                null, null, "NO", "YES"
+            },
+        };
+        JDBC.assertFullResultSet( rs2, expectedRows );
+
+
+        s.execute( "drop table t_jdbc41" );
+    }
+    
     public void testBugFixes() throws SQLException {
         
         Statement s = createStatement();

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41DBMD.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41DBMD.java?rev=1064868&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41DBMD.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41DBMD.java
Fri Jan 28 20:50:43 2011
@@ -0,0 +1,102 @@
+/*
+ 
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.Wrapper41DBMD
+ 
+   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.derbyTesting.functionTests.tests.jdbcapi;
+
+import java.sql.SQLException;
+
+import org.apache.derby.impl.jdbc.EmbedDatabaseMetaData;
+import org.apache.derby.client.am.DatabaseMetaData;
+
+/**
+ * A wrapper around the new DatabaseMetaData methods added by JDBC 4.1.
+ * We can eliminate this class after Java 7 goes GA and we are allowed
+ * to use the Java 7 compiler to build our released versions of derbyTesting.jar.
+ */
+public  class   Wrapper41DBMD
+{
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    private EmbedDatabaseMetaData    _embedded;
+    private DatabaseMetaData      _netclient;
+    
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTORS
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    public Wrapper41DBMD( Object wrapped ) throws Exception
+    {
+        if ( wrapped instanceof EmbedDatabaseMetaData ) { _embedded = (EmbedDatabaseMetaData)
wrapped; }
+        else if ( wrapped instanceof DatabaseMetaData ) { _netclient = (DatabaseMetaData)
wrapped; }
+        else { throw nothingWrapped(); }
+    }
+    
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // JDBC 4.1 BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    public  boolean    generatedKeyAlwaysReturned() throws SQLException
+    {
+        if ( _embedded != null ) { return _embedded.generatedKeyAlwaysReturned(); }
+        else if ( _netclient != null ) { return _netclient.generatedKeyAlwaysReturned();
}
+        else { throw nothingWrapped(); }
+    }
+
+    public  java.sql.ResultSet    getPseudoColumns
+        ( String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern
)
+        throws SQLException
+    {
+        if ( _embedded != null ) { return _embedded.getPseudoColumns( catalog, schemaPattern,
tableNamePattern, columnNamePattern ); }
+        else if ( _netclient != null ) { return _netclient.getPseudoColumns( catalog, schemaPattern,
tableNamePattern, columnNamePattern ); }
+        else { throw nothingWrapped(); }
+    }
+
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // OTHER PUBLIC BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    public java.sql.DatabaseMetaData   getWrappedObject() throws SQLException
+    {
+        if ( _embedded != null ) { return _embedded; }
+        else if ( _netclient != null ) { return _netclient; }
+        else { throw nothingWrapped(); }
+    }
+
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // MINIONS
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    private SQLException nothingWrapped() { return new SQLException( "Nothing wrapped!" );
}
+
+}
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41DBMD.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java?rev=1064868&r1=1064867&r2=1064868&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ViewsTest.java
Fri Jan 28 20:50:43 2011
@@ -828,8 +828,8 @@ public final class ViewsTest extends Bas
         DatabaseMetaData dmd = getConnection().getMetaData();
         ResultSet columns = dmd.getColumns(null, null, "V", null);
         String[][] expectedDBMetaRows = new String[][] {{"","APP","V","DATA","12","VARCHAR","20",null,null,null,"1","",null,null,null
-            ,"40","1","YES",null,null,null,null,"NO"},
-            {"","APP","V","NUM","4","INTEGER","10",null,"0","10","1","",null,null,null,null,"2","YES",null,null,null,null,"NO"}};
 
+            ,"40","1","YES",null,null,null,null,"NO","NO"},
+            {"","APP","V","NUM","4","INTEGER","10",null,"0","10","1","",null,null,null,null,"2","YES",null,null,null,null,"NO","NO"}};
 
         JDBC.assertFullResultSet(columns,expectedDBMetaRows);
         // Make sure ResultSetMetaData is right when selecting from view.
         // This wasn't a problem with DERBY-4230, but checking for good measure.
@@ -874,19 +874,19 @@ public final class ViewsTest extends Bas
 
         String[][] expectedDBMetaRows = new String[][]
             {{"","APP","V1","J","4","INTEGER","10",null,"0","10","1","",
-              null,null,null,null,"1","YES",null,null,null,null,"NO"},
+              null,null,null,null,"1","YES",null,null,null,null,"NO","NO"},
              {"","APP","V1","I","4","INTEGER","10",null,"0","10","1","",
-              null,null,null,null,"2","YES",null,null,null,null,"NO"}};
+              null,null,null,null,"2","YES",null,null,null,null,"NO","NO"}};
 
         JDBC.assertFullResultSet(columns,expectedDBMetaRows);
 
         expectedDBMetaRows = new String[][]
             {{"","APP","V2","X","4","INTEGER","10",null,"0","10","1","",
-              null,null,null,null,"1","YES",null,null,null,null,"NO"},
+              null,null,null,null,"1","YES",null,null,null,null,"NO","NO"},
              {"","APP","V2","Y","4","INTEGER","10",null,"0","10","1","",
-              null,null,null,null,"2","YES",null,null,null,null,"NO"},
+              null,null,null,null,"2","YES",null,null,null,null,"NO","NO"},
              {"","APP","V2","Z","4","INTEGER","10",null,"0","10","1","",
-              null,null,null,null,"3","YES",null,null,null,null,"NO"}};
+              null,null,null,null,"3","YES",null,null,null,null,"NO","NO"}};
 
         columns = dmd.getColumns(null, null, "V2", null);
         JDBC.assertFullResultSet(columns,expectedDBMetaRows);



Mime
View raw message