db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r671619 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/iapi/types/DataTypeDescriptor.java testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
Date Wed, 25 Jun 2008 18:20:56 GMT
Author: mamta
Date: Wed Jun 25 11:20:55 2008
New Revision: 671619

URL: http://svn.apache.org/viewvc?rev=671619&view=rev
Log:
Backporting (revision 670778 from trunk) for DERBY-3718 into 10.4 codeline. The fix involved
using type
name rather than it's Types.xxx value to construct the TypeId object. The reason for not using
Types.xxx is that for internal Derby types like REF, we do not associated correct Types.xxx
with it,
instead we just use Types.OTHER for it. It is not enough to use Types.OTHER to find the correct
TypeId and that's why we will be using the name rather than Types.xxx to construct TypeId.
More
information can be found in commit comments of revision 670778.



Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java?rev=671619&r1=671618&r2=671619&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
Wed Jun 25 11:20:55 2008
@@ -1036,7 +1036,7 @@
 	 */
 	public	String		getTypeName()
 	{
-		return typeId.getSQLTypeName();
+		return typeDescriptor.getTypeName();
 	}
 
 	/**
@@ -1753,7 +1753,7 @@
 	{
 		typeDescriptor = (TypeDescriptorImpl) in.readObject();
         
-        typeId = TypeId.getBuiltInTypeId(this.getJDBCTypeId());
+        typeId = TypeId.getBuiltInTypeId(this.getTypeName());
         
         collationDerivation = in.readInt();
 	}

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java?rev=671619&r1=671618&r2=671619&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
Wed Jun 25 11:20:55 2008
@@ -399,6 +399,46 @@
     {
         ((List) TRIGGER_INFO.get()).add(info);  
     }
+
+    /** 
+     * Test for DERBY-3718 NPE when a trigger is fired
+     * 
+     * @throws SQLException
+     * @throws IOException
+     */
+    public void testNPEinTriggerFire() throws SQLException
+    {
+        Statement s = createStatement();
+        
+    	String sql = " CREATE TABLE TRADE(ID INT PRIMARY KEY GENERATED "+
+    	"BY DEFAULT AS IDENTITY (START WITH 1000), BUYID INT NOT NULL," +
+    	"QTY FLOAT(2) NOT NULL)";
+        s.executeUpdate(sql);
+
+        sql = "CREATE TABLE TOTAL(BUYID INT NOT NULL, TOTALQTY FLOAT(2) NOT NULL)";
+        s.executeUpdate(sql);
+        
+        sql = "CREATE TRIGGER TRADE_INSERT AFTER INSERT ON TRADE REFERENCING "+ 
+        "NEW AS NEWROW FOR EACH ROW MODE DB2SQL UPDATE TOTAL SET TOTALQTY "+
+        "= NEWROW.QTY WHERE BUYID = NEWROW.BUYID"; 
+        s.executeUpdate(sql);
+        
+        s.executeUpdate("INSERT INTO TOTAL VALUES (1, 0)");
+        //Before DERBY-3718 was fixed, following would cause NPE in 10.4 and 
+        //trunk. This happened because starting 10.4, rather than saving the
+        //TypeId of the DataTypeDescriptor (in writeExternal method), we rely
+        //on reconstructing TypeId (in readExternal) by using the Types.xxx 
+        //information(DERBY-2917 revision r619995). This approach does not
+        //work for internal datatype REF, because we use Types.OTHER for REF
+        //datatypes. Types.OTHER is not enough to know that the type to be 
+        //constructed is REF. 
+        //To get around the problem, for reconstructing TypeId, we will
+        //use the type name rather than Types.xxx. Since we have the correct
+        //type name for internal datatype REF, we can successfully reconstruct
+        //REF datatype. 
+        s.executeUpdate("INSERT INTO TRADE VALUES(1, 1, 10)");
+        commit();      
+    }
     
     /** 
      * Test for DERBY-3238 trigger fails with IOException if triggering table has large lob.



Mime
View raw message