db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r899733 [2/2] - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ drda/org/apache/derby/impl/drda/ engine/org/apache/derby/catalog/types/ engine/org/apache/derby/iapi/reference/ engine/org/...
Date Fri, 15 Jan 2010 17:54:22 GMT
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java?rev=899733&r1=899732&r2=899733&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/CompatibilitySuite.java
Fri Jan 15 17:54:20 2010
@@ -53,11 +53,16 @@
 	public	static	final	Version	DRB_10_0 = new Version( 10, 0 );
 	public	static	final	Version	DRB_10_1 = new Version( 10, 1 );
 	public	static	final	Version	DRB_10_2 = new Version( 10, 2 );
+	public	static	final	Version	DRB_10_3 = new Version( 10, 3 );
+	public	static	final	Version	DRB_10_4 = new Version( 10, 4 );
+	public	static	final	Version	DRB_10_5 = new Version( 10, 5 );
+	public	static	final	Version	DRB_10_6 = new Version( 10, 6 );
 
 	// Supported VM versions.
 	public	static	final	Version	VM_1_3 = new Version( 1, 3 );
 	public	static	final	Version	VM_1_4 = new Version( 1, 4 );
 	public	static	final	Version	VM_1_5 = new Version( 1, 5 );
+	public	static	final	Version	VM_1_6 = new Version( 1, 6 );
 
 	public	static	final	String	SERVER_VERSION_FUNCTION = "getVMVersion";
 	
@@ -180,6 +185,16 @@
 	 */
 	public	Version	getClientVMVersion() { return _clientVMLevel; }
 
+    /**
+     * <p>
+     *  Report whether the server supports ANSI UDTs.
+     * </p>
+     */
+    public boolean serverSupportsUDTs()
+    {
+        return getServerVersion().atLeast( DRB_10_6 );
+    }
+
 	/////////////////////////////////////////////////////////////
 	//
 	//	DATABASE-SIDE FUNCTIONS

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java?rev=899733&r1=899732&r2=899733&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/JDBCDriverTest.java
Fri Jan 15 17:54:20 2010
@@ -1,4 +1,4 @@
-/*
+/**
 
    Derby - Class org.apache.derbyTesting.functionTests.tests.compatibility.JDBCDriverTest
 
@@ -255,12 +255,245 @@
 		createSchema( conn );
 
 		datatypesTest( conn );
+        udtTest( conn );
 
 		close( conn );
 	}
 	
 	/////////////////////////////////////////////////////////////
 	//
+	//	TEST UDTs
+	//
+	/////////////////////////////////////////////////////////////
+
+	//
+	// Verify the metadata for user defined types.
+	//
+	private	void	udtTest( Connection conn )
+		throws Exception
+	{
+        //
+        // We must expect the wrong metadata in a network configuration
+        // unless both the client and the server are at 10.6 or higher.
+        // See DERBY-4491.
+        //
+        boolean correctBehavior =
+            usingEmbeddedClient() ||
+            (
+             getServerVersion().atLeast( DRB_10_6 ) &&
+             getDriverVersion().atLeast( DRB_10_6 )
+             );
+
+        String query = "select aliasinfo from sys.sysaliases";
+        
+        if ( correctBehavior )
+        {
+            String aliasInfoClassName = "org.apache.derby.catalog.AliasInfo";
+            
+            checkRSMD
+                (
+                 conn,
+                 query,
+                 aliasInfoClassName,
+                 15,
+                 java.sql.Types.JAVA_OBJECT,
+                 aliasInfoClassName,
+                 0,
+                 0
+                 );
+        }
+        else
+        {
+            checkRSMD
+                (
+                 conn,
+                 query,
+                 "byte[]",
+                 65400,
+                 java.sql.Types.LONGVARBINARY,
+                 "LONG VARCHAR FOR BIT DATA",
+                 32700,
+                 0
+                 );
+        }
+
+
+        if ( serverSupportsUDTs() )
+        {
+            query = "select a from t_price";
+            PreparedStatement ps = conn.prepareStatement( query );
+            ResultSet rs = ps.executeQuery();
+            rs.next();
+            Object price = rs.getObject( 1 );
+            String actualClassName = price.getClass().getName();
+            rs.close();
+            ps.close();
+
+            if ( correctBehavior )
+            {
+                String priceClassName = "org.apache.derbyTesting.functionTests.tests.lang.Price";
+                checkRSMD
+                    (
+                     conn,
+                     query,
+                     priceClassName,
+                     15,
+                     java.sql.Types.JAVA_OBJECT,
+                     "\"APP\".\"PRICE\"",
+                     0,
+                     0
+                     );
+
+                assertEquals( priceClassName, actualClassName );
+            }
+            else
+            {
+                checkRSMD
+                    (
+                     conn,
+                     query,
+                     "byte[]",
+                     65400,
+                     java.sql.Types.LONGVARBINARY,
+                     "LONG VARCHAR FOR BIT DATA",
+                     32700,
+                     0
+                     );
+                
+                assertEquals( "java.lang.String", actualClassName );
+            }
+
+            query = "insert into t_price( a ) values ( ? )";
+            
+            if ( correctBehavior )
+            {
+                checkPMD
+                    (
+                     conn,
+                     query,
+                     "org.apache.derbyTesting.functionTests.tests.lang.Price",
+                     java.sql.Types.JAVA_OBJECT,
+                     "\"APP\".\"PRICE\"",
+                     0,
+                     0
+                     );
+            }
+            else
+            {
+                checkPMD
+                    (
+                     conn,
+                     query,
+                     "byte[]",
+                     java.sql.Types.LONGVARBINARY,
+                     "LONG VARCHAR FOR BIT DATA",
+                     32700,
+                     0
+                     );
+            }
+
+            //
+            // Should only be able to stuff an object into the column if both
+            // the client and server are at 10.6 or higher.
+            //
+            ps = conn.prepareStatement( query );
+            byte[] someBytes = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
+            ByteArrayInputStream bais = new ByteArrayInputStream( someBytes );
+            
+            try {
+                ps.setObject( 1, org.apache.derbyTesting.functionTests.tests.lang.Price.makePrice()
);
+                ps.executeUpdate();
+
+                if ( !correctBehavior ) { fail( "setObject( Price ) unexpectedly worked."
); }
+            }
+            catch (SQLException se)
+            {
+                if ( correctBehavior ) { fail( "setObject( Price ) unexpectedly failed."
); }
+            }
+            try {
+                ps.setObject( 1, someBytes );
+                ps.executeUpdate();
+
+                fail( "setObject( byte[] ) unexpectedly worked." );
+            }
+            catch (SQLException se) {}
+            try {
+                ps.setBytes( 1, someBytes );
+                ps.executeUpdate();
+
+                fail( "setBytes( byte[] ) unexpectedly worked." );
+            }
+            catch (SQLException se) {}
+            try {
+                ps.setBinaryStream( 1, bais, 3 );
+                ps.executeUpdate();
+
+                fail( "setBinaryStream( InputStream ) unexpectedly worked." );
+            }
+            catch (SQLException se) {}
+
+            ps.close();
+        }
+    }
+    
+    /**
+     * Check the ResultSetMetaData for a query whose first column is a UDT.
+     */
+    private void checkRSMD
+        (
+         Connection conn,
+         String query,
+         String expectedClassName,
+         int expectedDisplaySize,
+         int expectedJDBCType,
+         String expectedSQLTypeName,
+         int expectedPrecision,
+         int expectedScale
+         ) throws Exception
+    {
+        PreparedStatement ps = conn.prepareStatement( query );
+        ResultSet rs = ps.executeQuery();
+        ResultSetMetaData rsmd = rs.getMetaData();
+
+        assertEquals( expectedClassName, rsmd.getColumnClassName( 1 ) );
+        assertEquals( expectedDisplaySize , rsmd.getColumnDisplaySize( 1 ));
+        assertEquals( expectedJDBCType, rsmd.getColumnType( 1 ) );
+        assertEquals( expectedSQLTypeName, rsmd.getColumnTypeName( 1 ) );
+        assertEquals( expectedPrecision, rsmd.getPrecision( 1 ) );
+        assertEquals( expectedScale, rsmd.getScale( 1 ) );
+
+        rs.close();
+        ps.close();
+    }
+    
+    /**
+     * Check the ParameterMetaData for a statement whose first parameter is a UDT.
+     */
+    private void checkPMD
+        (
+         Connection conn,
+         String query,
+         String expectedClassName,
+         int expectedJDBCType,
+         String expectedSQLTypeName,
+         int expectedPrecision,
+         int expectedScale
+         ) throws Exception
+    {
+        PreparedStatement ps = conn.prepareStatement( query );
+        ParameterMetaData pmd = ps.getParameterMetaData();
+
+        assertEquals( pmd.getParameterClassName( 1 ), expectedClassName );
+        assertEquals( pmd.getParameterType( 1 ), expectedJDBCType );
+        assertEquals( pmd.getParameterTypeName( 1 ), expectedSQLTypeName );
+        assertEquals( pmd.getPrecision( 1 ), expectedPrecision );
+        assertEquals( pmd.getScale( 1 ), expectedScale );
+
+        ps.close();
+    }
+
+	/////////////////////////////////////////////////////////////
+	//
 	//	TEST DATATYPES
 	//
 	/////////////////////////////////////////////////////////////
@@ -799,6 +1032,8 @@
 		throws Exception
 	{
 		createTable( conn, ALL_TYPES_TABLE, ALL_TYPES );
+
+        createUDTObjects( conn );
 	}
 
 	//
@@ -838,6 +1073,33 @@
 		close( ps );
 	}
 
+    //
+    // Create an ANSI UDT and a table with that type of column--
+    // if the server is at 10.6 or higher.
+    //
+    private void createUDTObjects( Connection conn ) throws Exception
+    {
+        if ( !serverSupportsUDTs() ) { return; }
+
+        PreparedStatement ps;
+
+        ps = conn.prepareStatement( "create type price external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        ps.execute();
+        ps.close();
+
+        ps = conn.prepareStatement( "create function makePrice( ) returns price language
java parameter style java no sql external name 'org.apache.derbyTesting.functionTests.tests.lang.Price.makePrice'\n"
);
+        ps.execute();
+        ps.close();
+
+        ps = conn.prepareStatement( "create table t_price( a price )\n" );
+        ps.execute();
+        ps.close();
+
+        ps = conn.prepareStatement( "insert into t_price( a ) values ( makePrice() )\n" );
+        ps.execute();
+        ps.close();
+    }
+
 
 	//
 	// Helper methods for declaring a table.
@@ -864,8 +1126,22 @@
 	private	void	dropSchema( Connection conn )
 	{
 		dropTable( conn, ALL_TYPES_TABLE );
+        dropUDTObjects( conn );
 	}
 
+    //
+    // Drop objects needed by UDT tests. We only do this if the server
+    // is at 10.6 or higher.
+    //
+    private void dropUDTObjects( Connection conn )
+    {
+        if ( !serverSupportsUDTs() ) { return; }
+
+        dropFunction( conn, "MAKEPRICE" );
+        dropTable( conn, "T_PRICE" );
+        dropUDT( conn, "PRICE" );
+    }
+
 	//
 	// Logic for stuffing a data value into a column, given its type.
 	//

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java?rev=899733&r1=899732&r2=899733&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
Fri Jan 15 17:54:20 2010
@@ -23,8 +23,10 @@
 
 import java.math.BigDecimal;
 import java.sql.Connection;
+import java.sql.ParameterMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
 import java.sql.Timestamp;
 
 import junit.framework.Test;
@@ -88,7 +90,7 @@
      */
     public static Test suite()
     {
-        TestSuite suite = (TestSuite) TestConfiguration.embeddedSuite(UDTTest.class);
+        TestSuite suite = (TestSuite) TestConfiguration.defaultSuite(UDTTest.class);
         Test        result = new CleanDatabaseTestSetup( suite );
 
         return result;
@@ -194,10 +196,10 @@
         assertResults
             (
              conn,
-             "select getCurrencyCode( totalPrice ), getAmount( totalPrice ), getTimeInstant(
totalPrice ) from orders",
+             "select getCurrencyCode( totalPrice ), getTimeInstant( totalPrice ) from orders",
              new String[][]
              {
-                 { "USD" ,         "9.99000" ,        "2009-10-16 14:24:43.0" },
+                 { "USD" ,         "2009-10-16 14:24:43.0" },
              },
              false
              );
@@ -644,6 +646,79 @@
 
     }
     
+    /**
+     * <p>
+     * Check result set metadata for UDT columns.
+     * </p>
+     */
+    public void test_09_resultSetMetaData() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement( conn, "create type price_09_a external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        goodStatement( conn, "create table t_09_a( a price_09_a )\n" );
+
+        // ANSI UDT
+        checkRSMD
+            (
+             conn,
+             "select a from t_09_a\n",
+             "org.apache.derbyTesting.functionTests.tests.lang.Price",
+             15,
+             java.sql.Types.JAVA_OBJECT,
+             "\"APP\".\"PRICE_09_A\"",
+             0,
+             0
+             );
+
+        // old-style objects in Derby system tables do not have
+        // schema-qualified type names
+        checkRSMD
+            (
+             conn,
+             "select aliasinfo from sys.sysaliases\n",
+             "org.apache.derby.catalog.AliasInfo",
+             15,
+             java.sql.Types.JAVA_OBJECT,
+             "org.apache.derby.catalog.AliasInfo",
+             0,
+             0
+             );
+    }
+
+    /**
+     * <p>
+     * Check parameter metadata for UDT parameters.
+     * </p>
+     */
+    public void test_10_parameterMetaData() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement( conn, "create type price_10_a external name 'org.apache.derbyTesting.functionTests.tests.lang.Price'
language java\n" );
+        goodStatement( conn, "create table t_10_a( a price_09_a )\n" );
+
+        // ANSI UDT
+        checkPMD
+            (
+             conn,
+             "insert into t_10_a( a ) values ( ? )\n",
+             "org.apache.derbyTesting.functionTests.tests.lang.Price",
+             java.sql.Types.JAVA_OBJECT,
+             "\"APP\".\"PRICE_09_A\"",
+             0,
+             0
+             );
+
+        //
+        // I don't know of any way to create a statement with a parameter
+        // whose type is an old-style object from Derby's system tables.
+        // If you figure out how to trick Derby into letting you do that,
+        // this would be a good place to assert the shape of the parameter
+        // meta data for that statement.
+        //
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // PROCEDURES
@@ -653,6 +728,14 @@
     public static void oneArgPriceProc( Price price1 ) {}
     public static void twoArgPriceProc( Price price1, Price price2 ) {}
 
+    public static void changeCurrencyCode( String newCurrencyCode, Price[] price )
+    {
+        Price oldPrice = price[ 0 ];
+        Price newPrice = new Price( newCurrencyCode, oldPrice.amount, oldPrice.timeInstant
);
+
+        price[ 0 ] = newPrice;
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS
@@ -703,4 +786,60 @@
         return retval;
     }
 
+    /**
+     * Check the ResultSetMetaData for a query whose first column is a UDT.
+     */
+    private void checkRSMD
+        (
+         Connection conn,
+         String query,
+         String expectedClassName,
+         int expectedDisplaySize,
+         int expectedJDBCType,
+         String expectedSQLTypeName,
+         int expectedPrecision,
+         int expectedScale
+         ) throws Exception
+    {
+        PreparedStatement ps = conn.prepareStatement( query );
+        ResultSet rs = ps.executeQuery();
+        ResultSetMetaData rsmd = rs.getMetaData();
+
+        assertEquals( rsmd.getColumnClassName( 1 ), expectedClassName );
+        assertEquals( rsmd.getColumnDisplaySize( 1 ), expectedDisplaySize );
+        assertEquals( rsmd.getColumnType( 1 ), expectedJDBCType );
+        assertEquals( rsmd.getColumnTypeName( 1 ), expectedSQLTypeName );
+        assertEquals( rsmd.getPrecision( 1 ), expectedPrecision );
+        assertEquals( rsmd.getScale( 1 ), expectedScale );
+
+        rs.close();
+        ps.close();
+    }
+    
+    /**
+     * Check the ParameterMetaData for a statement whose first parameter is a UDT.
+     */
+    private void checkPMD
+        (
+         Connection conn,
+         String query,
+         String expectedClassName,
+         int expectedJDBCType,
+         String expectedSQLTypeName,
+         int expectedPrecision,
+         int expectedScale
+         ) throws Exception
+    {
+        PreparedStatement ps = conn.prepareStatement( query );
+        ParameterMetaData pmd = ps.getParameterMetaData();
+
+        assertEquals( pmd.getParameterClassName( 1 ), expectedClassName );
+        assertEquals( pmd.getParameterType( 1 ), expectedJDBCType );
+        assertEquals( pmd.getParameterTypeName( 1 ), expectedSQLTypeName );
+        assertEquals( pmd.getPrecision( 1 ), expectedPrecision );
+        assertEquals( pmd.getScale( 1 ), expectedScale );
+
+        ps.close();
+    }
+
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/DerbyJUnitTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/DerbyJUnitTest.java?rev=899733&r1=899732&r2=899733&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/DerbyJUnitTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/DerbyJUnitTest.java
Fri Jan 15 17:54:20 2010
@@ -65,6 +65,7 @@
 	private	static	final	String	TABLE = "table";
 	private	static	final	String	FUNCTION = "function";
 	private	static	final	String	PROCEDURE = "procedure";
+	private	static	final	String	TYPE = "type";
 	
 	//
 	// These are properties for the Derby connection URL.
@@ -513,7 +514,7 @@
 	 */
 	protected	static	void	dropTable( Connection conn, String name )
 	{
-		dropSchemaObject( conn, TABLE, name );
+		dropSchemaObject( conn, TABLE, name, false );
 	}
 
 	/**
@@ -527,7 +528,7 @@
 	 */
 	protected	static	void	dropFunction( Connection conn, String name )
 	{
-		dropSchemaObject( conn, FUNCTION, name );
+		dropSchemaObject( conn, FUNCTION, name, false );
 	}
 
 	/**
@@ -541,7 +542,21 @@
 	 */
 	protected	static	void	dropProcedure( Connection conn, String name )
 	{
-		dropSchemaObject( conn, PROCEDURE, name );
+		dropSchemaObject( conn, PROCEDURE, name, false );
+	}
+
+	/**
+	 * <p>
+	 * Drop a UDT regardless of whether it exists. If the UDT does
+	 * not exist, don't log an error unless
+	 * running in debug mode. This method is to be used for reinitializing
+	 * a schema in case a previous test run failed to clean up after itself.
+	 * Do not use this method if you need to verify that the UDT really exists.
+	 * </p>
+	 */
+	protected	static	void	dropUDT( Connection conn, String name )
+	{
+		dropSchemaObject( conn, TYPE, name, true );
 	}
 
 	/**
@@ -553,12 +568,14 @@
 	 * Do not use this method if you need to verify that the object really exists.
 	 * </p>
 	 */
-	protected	static	void	dropSchemaObject( Connection conn, String genus, String objectName
)
+	protected	static	void	dropSchemaObject( Connection conn, String genus, String objectName,
boolean restrict )
 	{
 		PreparedStatement	ps = null;
 		
 		try {
-			ps = prepare( conn, "drop " + genus + " " + objectName );
+            String text = "drop " + genus + " " + objectName;
+            if ( restrict ) { text = text + " restrict"; }
+			ps = prepare( conn, text );
 
 			ps.execute();
 		}



Mime
View raw message