db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject svn commit: r448085 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby/iapi/types/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ testi...
Date Wed, 20 Sep 2006 06:14:30 GMT
Author: suresht
Date: Tue Sep 19 23:14:29 2006
New Revision: 448085

URL: http://svn.apache.org/viewvc?view=rev&rev=448085
Log:
DERBY-1718 ( creating an after insert trigger with trigger action involving 
xml datatype throws java.io.NottSerializableException)

Patch contributed by Yip Ng.

The fix basically implements the Formatable interface for SqlXmlUtil class. 
Currently, it writes out the query expression string instead of the XPath 
object(its serializable I think), and then later recompiles the query once 
at evaluation time. The reason behind this is that I don't want the stored 
form to be tied to a particular XML implementation.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java?view=diff&rev=448085&r1=448084&r2=448085
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
Tue Sep 19 23:14:29 2006
@@ -525,5 +525,6 @@
         /* 461 */   "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
         /* 462 */   "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
         /* 463 */   "org.apache.derby.impl.sql.catalog.CoreDDFinderClassInfo",
+        /* 464 */   "org.apache.derby.iapi.types.SqlXmlUtil",        
 };
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java?view=diff&rev=448085&r1=448084&r2=448085
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/StoredFormatIds.java
Tue Sep 19 23:14:29 2006
@@ -491,6 +491,12 @@
                 (MIN_ID_2 + 456);
         
         /**
+         	class org.apache.derby.iapi.types.SqlXmlUtil
+        */
+        static public final int SQL_XML_UTIL_V01_ID =
+                (MIN_ID_2 + 464);
+        
+        /**
             class org.apache.derby.iapi.types.JSQLType
          */
         static public final int JSQLTYPEIMPL_ID =
@@ -1853,7 +1859,7 @@
          * Make sure this is updated when a new module is added
          */
         public static final int MAX_ID_2 =
-                (MIN_ID_2 + 463);
+                (MIN_ID_2 + 464);
 
         // DO NOT USE 4 BYTE IDS ANYMORE
         static public final int MAX_ID_4 =

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java?view=diff&rev=448085&r1=448084&r2=448085
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SqlXmlUtil.java Tue Sep 19
23:14:29 2006
@@ -23,11 +23,16 @@
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.services.io.Formatable;
+import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
 import java.util.Properties;
 import java.util.ArrayList;
 
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
 import java.io.StringReader;
 
 // -- JDBC 3.0 JAXP API classes.
@@ -109,7 +114,7 @@
  *       _if_ s/he is trying to access or operate on XML values.
  */
 
-public class SqlXmlUtil 
+public class SqlXmlUtil implements Formatable
 {
     // Used to parse a string into an XML value (DOM); checks
     // the well-formedness of the string while parsing.
@@ -124,6 +129,12 @@
     private XPath query;
     private XPathContext xpContext;
 
+    // Used to recompile the XPath expression when this formatable
+    // object is reconstructed.  e.g.:  SPS 
+    private String queryExpr;
+    private String opName;
+    private boolean recompileQuery;
+    
     /**
      * Constructor: Initializes objects required for parsing
      * and serializing XML values.  Since most XML operations
@@ -256,6 +267,10 @@
             query = new XPath(queryExpr, null,
                 new PrefixResolverDefault(dBuilder.newDocument()),
                 XPath.SELECT);
+            
+            this.queryExpr = queryExpr;
+            this.opName = opName;
+            this.recompileQuery = false;
 
         } catch (Throwable te) {
 
@@ -510,6 +525,12 @@
     protected ArrayList evalXQExpression(XMLDataValue xmlContext,
         boolean returnResults, int [] resultXType) throws Exception
     {
+        // if this object is in an SPS, we need to recompile the query
+        if (recompileQuery)
+        {
+        	compileXQExpr(queryExpr, opName);
+        }
+
         // Make sure we have a compiled query.
         if (SanityManager.DEBUG) {
             SanityManager.ASSERT(
@@ -668,6 +689,58 @@
         // Load the serializer with the correct properties.
         serializer = SerializerFactory.getSerializer(props);
         return;
+    }
+
+    /* ****
+     * Formatable interface implementation
+     * */
+
+    /** 
+     * @see java.io.Externalizable#writeExternal 
+     * 
+     * @exception IOException on error
+     */
+    public void writeExternal(ObjectOutput out) 
+        throws IOException
+    {
+        // query may be null
+        if (query == null)
+        {
+            out.writeBoolean(false);
+        }
+        else
+        {
+            out.writeBoolean(true);
+            out.writeObject(queryExpr);
+            out.writeObject(opName);
+        }
+    }
+
+    /** 
+     * @see java.io.Externalizable#readExternal 
+     *
+     * @exception IOException on error
+     * @exception ClassNotFoundException on error
+     */
+    public void readExternal(ObjectInput in) 
+        throws IOException, ClassNotFoundException
+    {
+        if (in.readBoolean())
+        {
+            queryExpr = (String)in.readObject();
+            opName = (String)in.readObject();
+            recompileQuery = true;
+	    }
+    }
+
+    /**
+     * Get the formatID which corresponds to this class.
+     *
+     * @return	the formatID of this class
+     */
+    public int getTypeFormatId()
+    { 
+        return StoredFormatIds.SQL_XML_UTIL_V01_ID;
     }
 
     /*

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out?view=diff&rev=448085&r1=448084&r2=448085
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/xml_general.out
Tue Sep 19 23:14:29 2006
@@ -1199,6 +1199,66 @@
 -----
 4.4                                               
 1 two le 3 trois                                  
+ij> -- DERBY-1718
+----- create trigger fails when SPS contains XML related op.
+create table t9 (i int, x xml);
+0 rows inserted/updated/deleted
+ij> create table t10 (i int, x xml);
+0 rows inserted/updated/deleted
+ij> insert into t9 values (1, xmlparse(document '<name> john </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, xmlparse(document '<name> jane </name>' preserve
whitespace));
+0 rows inserted/updated/deleted
+ij> insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I |2                   
+-----
+1 |<name> john </name> 
+2 |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I |2                   
+-----
+1 |<name> jane </name> 
+ij> insert into t9 select * from t9;
+2 rows inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I |2                   
+-----
+1 |<name> john </name> 
+2 |<name> ally </name> 
+1 |<name> john </name> 
+2 |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I |2                   
+-----
+1 |<name> jane </name> 
+1 |<name> jane </name> 
+ij> drop trigger tx;
+0 rows inserted/updated/deleted
+ij> delete from t9;
+4 rows inserted/updated/deleted
+ij> delete from t10;
+2 rows inserted/updated/deleted
+ij> insert into t9 values (1, xmlparse(document '<name> john </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, (select xmlquery('.' passing by ref x returning sequence empty
on empty) from t9 where i = 1));
+0 rows inserted/updated/deleted
+ij> insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I |2                   
+-----
+1 |<name> john </name> 
+2 |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I |2                   
+-----
+1 |<name> john </name> 
+ij> drop trigger tx;
+0 rows inserted/updated/deleted
 ij> -- clean up.
 drop table t0;
 0 rows inserted/updated/deleted
@@ -1217,5 +1277,9 @@
 ij> drop table t7;
 0 rows inserted/updated/deleted
 ij> drop table t8;
+0 rows inserted/updated/deleted
+ij> drop table t9;
+0 rows inserted/updated/deleted
+ij> drop table t10;
 0 rows inserted/updated/deleted
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out?view=diff&rev=448085&r1=448084&r2=448085
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/xml_general.out
Tue Sep 19 23:14:29 2006
@@ -1200,6 +1200,66 @@
 -----
 4.4                                               
 1 two le 3 trois                                  
+ij> -- DERBY-1718
+----- create trigger fails when SPS contains XML related op.
+create table t9 (i int, x xml);
+0 rows inserted/updated/deleted
+ij> create table t10 (i int, x xml);
+0 rows inserted/updated/deleted
+ij> insert into t9 values (1, xmlparse(document '<name> john </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, xmlparse(document '<name> jane </name>' preserve
whitespace));
+0 rows inserted/updated/deleted
+ij> insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I |2                   
+-----
+1 |<name> john </name> 
+2 |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I |2                   
+-----
+1 |<name> jane </name> 
+ij> insert into t9 select * from t9;
+2 rows inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I |2                   
+-----
+1 |<name> john </name> 
+2 |<name> ally </name> 
+1 |<name> john </name> 
+2 |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I |2                   
+-----
+1 |<name> jane </name> 
+1 |<name> jane </name> 
+ij> drop trigger tx;
+0 rows inserted/updated/deleted
+ij> delete from t9;
+4 rows inserted/updated/deleted
+ij> delete from t10;
+2 rows inserted/updated/deleted
+ij> insert into t9 values (1, xmlparse(document '<name> john </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, (select xmlquery('.' passing by ref x returning sequence empty
on empty) from t9 where i = 1));
+0 rows inserted/updated/deleted
+ij> insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I |2                   
+-----
+1 |<name> john </name> 
+2 |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I |2                   
+-----
+1 |<name> john </name> 
+ij> drop trigger tx;
+0 rows inserted/updated/deleted
 ij> -- clean up.
 drop table t0;
 0 rows inserted/updated/deleted
@@ -1218,5 +1278,9 @@
 ij> drop table t7;
 0 rows inserted/updated/deleted
 ij> drop table t8;
+0 rows inserted/updated/deleted
+ij> drop table t9;
+0 rows inserted/updated/deleted
+ij> drop table t10;
 0 rows inserted/updated/deleted
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out?view=diff&rev=448085&r1=448084&r2=448085
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/xml_general.out
Tue Sep 19 23:14:29 2006
@@ -1227,6 +1227,66 @@
 --------------------------------------------------
 4.4                                               
 1 two le 3 trois                                  
+ij> -- DERBY-1718
+-- create trigger fails when SPS contains XML related op.
+create table t9 (i int, x xml);
+0 rows inserted/updated/deleted
+ij> create table t10 (i int, x xml);
+0 rows inserted/updated/deleted
+ij> insert into t9 values (1, xmlparse(document '<name> john </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, xmlparse(document '<name> jane </name>' preserve
whitespace));
+0 rows inserted/updated/deleted
+ij> insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I          |2                   
+--------------------------------
+1          |<name> john </name> 
+2          |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I          |2                   
+--------------------------------
+1          |<name> jane </name> 
+ij> insert into t9 select * from t9;
+2 rows inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I          |2                   
+--------------------------------
+1          |<name> john </name> 
+2          |<name> ally </name> 
+1          |<name> john </name> 
+2          |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I          |2                   
+--------------------------------
+1          |<name> jane </name> 
+1          |<name> jane </name> 
+ij> drop trigger tx;
+0 rows inserted/updated/deleted
+ij> delete from t9;
+4 rows inserted/updated/deleted
+ij> delete from t10;
+2 rows inserted/updated/deleted
+ij> insert into t9 values (1, xmlparse(document '<name> john </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, (select xmlquery('.' passing by ref x returning sequence empty
on empty) from t9 where i = 1));
+0 rows inserted/updated/deleted
+ij> insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve
whitespace));
+1 row inserted/updated/deleted
+ij> select i, xmlserialize(x as varchar(20)) from t9;
+I          |2                   
+--------------------------------
+1          |<name> john </name> 
+2          |<name> ally </name> 
+ij> select i, xmlserialize(x as varchar(20)) from t10;
+I          |2                   
+--------------------------------
+1          |<name> john </name> 
+ij> drop trigger tx;
+0 rows inserted/updated/deleted
 ij> -- clean up.
 drop table t0;
 0 rows inserted/updated/deleted
@@ -1245,5 +1305,9 @@
 ij> drop table t7;
 0 rows inserted/updated/deleted
 ij> drop table t8;
+0 rows inserted/updated/deleted
+ij> drop table t9;
+0 rows inserted/updated/deleted
+ij> drop table t10;
 0 rows inserted/updated/deleted
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql?view=diff&rev=448085&r1=448084&r2=448085
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/xml_general.sql
Tue Sep 19 23:14:29 2006
@@ -697,6 +697,30 @@
 from t1
 where xmlexists('//@*' passing by ref x);
 
+-- DERBY-1718
+-- create trigger fails when SPS contains XML related op.
+create table t9 (i int, x xml);
+create table t10 (i int, x xml);
+
+insert into t9 values (1, xmlparse(document '<name> john </name>' preserve whitespace));
+create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, xmlparse(document '<name> jane </name>' preserve
whitespace));
+insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve whitespace));
+select i, xmlserialize(x as varchar(20)) from t9;
+select i, xmlserialize(x as varchar(20)) from t10;
+insert into t9 select * from t9;
+select i, xmlserialize(x as varchar(20)) from t9;
+select i, xmlserialize(x as varchar(20)) from t10;
+drop trigger tx;
+delete from t9;
+delete from t10;
+insert into t9 values (1, xmlparse(document '<name> john </name>' preserve whitespace));
+create trigger tx after insert on t9 for each statement mode db2sql
+   insert into t10 values (1, (select xmlquery('.' passing by ref x returning sequence empty
on empty) from t9 where i = 1));
+insert into t9 values (2, xmlparse(document '<name> ally </name>' preserve whitespace));
+select i, xmlserialize(x as varchar(20)) from t9;
+select i, xmlserialize(x as varchar(20)) from t10;  
+drop trigger tx;
 -- clean up.
 drop table t0;
 drop table t1;
@@ -707,3 +731,5 @@
 drop table t6;
 drop table t7;
 drop table t8;
+drop table t9;
+drop table t10;
\ No newline at end of file



Mime
View raw message