db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1051026 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/
Date Mon, 20 Dec 2010 09:18:53 GMT
Author: kahatlen
Date: Mon Dec 20 09:18:52 2010
New Revision: 1051026

URL: http://svn.apache.org/viewvc?rev=1051026&view=rev
Log:
DERBY-4946: Derby 10.7 DatabaseMetaData.getTypeInfo() should not return BOOLEAN for a soft
upgraded database

Modified:
    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/upgradeTests/Changes10_7.java

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=1051026&r1=1051025&r2=1051026&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
Mon Dec 20 09:18:52 2010
@@ -2693,7 +2693,7 @@ public class EmbedDatabaseMetaData exten
 	 * @exception SQLException thrown on failure.
      */
 	public ResultSet getTypeInfo() throws SQLException {
-		return getSimpleQuery("getTypeInfo");
+		return getTypeInfoMinion("getTypeInfo");
 	}
 
 	/**
@@ -2704,10 +2704,32 @@ public class EmbedDatabaseMetaData exten
 	 * conform to ODBC specifications.
 	 */
 	public ResultSet getTypeInfoForODBC() throws SQLException {
-		return getSimpleQuery("odbc_getTypeInfo");
+		return getTypeInfoMinion("odbc_getTypeInfo");
 	}
 
     /**
+     * Get a description of the standard SQL types supported by this database.
+     *
+     * @param queryName the name of the query that fetches the information
+     * @return a result set with SQL type description
+     */
+    private ResultSet getTypeInfoMinion(String queryName) throws SQLException {
+        try {
+            // DERBY-4946: BOOLEAN data type was introduced in 10.7
+            boolean booleanSupported =
+                    getLanguageConnectionContext().getDataDictionary().
+                    checkVersion(DataDictionary.DD_VERSION_DERBY_10_7, null);
+
+            PreparedStatement ps = getPreparedQuery(queryName);
+            ps.setBoolean(1, booleanSupported);
+            return ps.executeQuery();
+
+        } catch (StandardException se) {
+            throw handleException(se);
+        }
+    }
+
+    /**
      * Get a description of a table's indices and statistics. They are
      * ordered by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION.
      *

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=1051026&r1=1051025&r2=1051026&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 Mon Dec
20 09:18:52 2010
@@ -813,7 +813,9 @@ getTypeInfo=\
 		('XML',2009,CAST (NULL AS INTEGER),CAST (NULL AS CHAR),CAST (NULL AS CHAR),CAST (NULL AS
CHAR), \
 			1,TRUE,0,FALSE,FALSE,FALSE, \
 			CAST (NULL AS INTEGER),CAST (NULL AS INTEGER),CAST (NULL AS INTEGER)) \
-	) AS TYPEINFO(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T14,T15,T18)
+	) AS TYPEINFO(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T14,T15,T18) \
+    WHERE \
+        (T1 <> 'BOOLEAN' OR CAST(? AS SMALLINT) <> 0)
 
 
 # parameter 1 = pattern for catalog name 

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=1051026&r1=1051025&r2=1051026&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
Mon Dec 20 09:18:52 2010
@@ -43,6 +43,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 //import java.util.HashMap;
 //import java.util.Iterator;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.List;
@@ -2075,9 +2076,8 @@ public class DatabaseMetaDataTest extend
     
     /**
      * Test getTypeInfo
-     * @throws SQLException 
      */
-    public void testGetTypeInfo() throws SQLException
+    public void testGetTypeInfo() throws Exception
     {
         // Client returns BOOLEAN type from the engine as SMALLINT
         int BOOLEAN = Types.BOOLEAN;      
@@ -2131,7 +2131,7 @@ public class DatabaseMetaDataTest extend
 	 Derby-2258 Removed 3 data types which are not supported by Derby
 	 and added XML data type which is supported by Derby
 	*/
-        int[] supportedTypes = new int[] {
+        int[] allTypes = new int[] {
           Types.BIGINT, Types.BINARY, Types.BLOB, Types.BOOLEAN,
           Types.CHAR, Types.CLOB, Types.DATE,
           Types.DECIMAL, Types.DOUBLE, Types.FLOAT,
@@ -2140,10 +2140,25 @@ public class DatabaseMetaDataTest extend
           Types.TIME, Types.TIMESTAMP,  Types.VARBINARY,
           Types.VARCHAR, JDBC.SQLXML, Types.JAVA_OBJECT
         };
-        
+
+        ArrayList supportedTypes = new ArrayList();
+        for (int i = 0; i < allTypes.length; i++) {
+            supportedTypes.add(new Integer(allTypes[i]));
+        }
+
+        Version dataVersion = getDataVersion(getConnection());
+        boolean booleanSupported =
+                dataVersion.compareTo(new Version(10, 7, 0, 0)) >= 0;
+        
+        // DERBY-4946: Boolean isn't supported if DB is soft-upgraded from
+        // pre-10.7 version
+        if (!booleanSupported) {
+            supportedTypes.remove(new Integer(Types.BOOLEAN));
+        }
+
         // Rows are returned from getTypeInfo in order of
         // "DATA_TYPE" (which is a constant from java.sql.Types)
-        Arrays.sort(supportedTypes);
+        Collections.sort(supportedTypes);
         
         int offset = 0;
         while (rs.next()) {
@@ -2154,7 +2169,7 @@ public class DatabaseMetaDataTest extend
             // DATA_TYPE (column 2)
             int type = rs.getInt("DATA_TYPE");
             assertFalse(rs.wasNull());
-            if (supportedTypes[offset] != type)
+            if (!supportedTypes.get(offset).equals(new Integer(type)))
             {
                 fail("Unexpected type " + typeName);
             }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_7.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_7.java?rev=1051026&r1=1051025&r2=1051026&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_7.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_7.java
Mon Dec 20 09:18:52 2010
@@ -22,22 +22,15 @@ package org.apache.derbyTesting.function
 
 import org.apache.derbyTesting.junit.SupportFilesSetup;
 
-import org.apache.derbyTesting.junit.JDBCDataSource;
-import java.lang.reflect.Method;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.sql.Connection;
-import java.sql.CallableStatement;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
-
-import javax.sql.DataSource;
+import java.util.HashSet;
+import java.util.Set;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.derby.catalog.types.RoutineAliasInfo;
-import org.apache.derby.catalog.TypeDescriptor;
 import org.apache.derbyTesting.junit.JDBC;
 
 
@@ -124,14 +117,17 @@ public class Changes10_7 extends Upgrade
         {
         case PH_CREATE: // create with old version
         case PH_POST_SOFT_UPGRADE: // soft-downgrade: boot with old version after soft-upgrade
+            assertFalse(getSupportedTypes().contains("BOOLEAN"));
             assertStatementError(  SYNTAX_ERROR, s, booleanValuedFunction );
             break;
 
         case PH_SOFT_UPGRADE: // boot with new version and soft-upgrade
+            assertFalse(getSupportedTypes().contains("BOOLEAN"));
             assertStatementError( UPGRADE_REQUIRED, s, booleanValuedFunction );
             break;
             
         case PH_HARD_UPGRADE: // boot with new version and hard-upgrade
+            assertTrue(getSupportedTypes().contains("BOOLEAN"));
             s.execute( booleanValuedFunction );
             break;
         }
@@ -140,6 +136,23 @@ public class Changes10_7 extends Upgrade
     }
 
     /**
+     * Get the names of all supported types, as reported by
+     * {@code DatabaseMetaData.getTypeInfo()}.
+     *
+     * @return a set with the names of all supported types in the loaded
+     * version of Derby
+     */
+    private Set getSupportedTypes() throws SQLException {
+        HashSet types = new HashSet();
+        ResultSet rs = getConnection().getMetaData().getTypeInfo();
+        while (rs.next()) {
+            types.add(rs.getString("TYPE_NAME"));
+        }
+        rs.close();
+        return types;
+    }
+
+    /**
      * Make sure that DERBY-1482 changes do not break backward compatibility
      */
     public void testTriggers() throws SQLException



Mime
View raw message