You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2005/08/26 22:02:58 UTC

svn commit: r240328 - in /db/torque: runtime/trunk/src/rttest/org/apache/torque/ runtime/trunk/xdocs/ templates/trunk/src/templates/om/bean/

Author: tfischer
Date: Fri Aug 26 13:02:48 2005
New Revision: 240328

URL: http://svn.apache.org/viewcvs?rev=240328&view=rev
Log:
Made the generated beans serializable. Also added a testcase to the runtimetest which checks that.

Modified:
    db/torque/runtime/trunk/src/rttest/org/apache/torque/BeanTest.java
    db/torque/runtime/trunk/xdocs/changes.xml
    db/torque/templates/trunk/src/templates/om/bean/Bean.vm
    db/torque/templates/trunk/src/templates/om/bean/ExtensionBean.vm
    db/torque/templates/trunk/src/templates/om/bean/MultiExtendBean.vm

Modified: db/torque/runtime/trunk/src/rttest/org/apache/torque/BeanTest.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/rttest/org/apache/torque/BeanTest.java?rev=240328&r1=240327&r2=240328&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/rttest/org/apache/torque/BeanTest.java (original)
+++ db/torque/runtime/trunk/src/rttest/org/apache/torque/BeanTest.java Fri Aug 26 13:02:48 2005
@@ -16,6 +16,10 @@
  * limitations under the License.
  */
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.List;
 
 import org.apache.torque.test.Author;
@@ -84,6 +88,71 @@
         assertTrue("author from bean has Id " + authorFromBean.getAuthorId()
                 + " should be " + author.getAuthorId(),
                 author.getAuthorId() == authorBean.getAuthorId());
+    }
+    
+    /**
+     * tests whether it is possible to serialize/deserialize beans
+     * @throws Exception
+     */
+    public void testSerializeBeans() throws Exception
+    {
+        Author author = new Author();
+        author.setName(AUTHOR_1_NAME);
+        author.setAuthorId(AUTHOR_1_ID);
+
+        AuthorBean authorBean = author.getBean();
+        
+        // serialize the AuthorBean
+        byte[] serializedAuthorBean;
+        {
+            ObjectOutputStream objectOutputStream = null;
+            ByteArrayOutputStream byteArrayOutputStream;
+            try
+            {
+                byteArrayOutputStream 
+                        = new ByteArrayOutputStream();
+                objectOutputStream 
+                        = new ObjectOutputStream(byteArrayOutputStream);
+                objectOutputStream.writeObject(authorBean);
+                serializedAuthorBean 
+                        = byteArrayOutputStream.toByteArray();
+            }
+            finally
+            {
+                if (objectOutputStream != null)
+                {
+                    objectOutputStream.close();
+                }
+            }
+        }
+        // deserialize the AuthorBean again
+        AuthorBean deserializedAuthorBean;
+        {
+            ObjectInputStream objectInputStream = null;
+            ByteArrayInputStream byteArrayInputStream = null;
+            try
+            {
+                byteArrayInputStream 
+                        = new ByteArrayInputStream(serializedAuthorBean);
+                objectInputStream 
+                        = new ObjectInputStream(byteArrayInputStream);
+                deserializedAuthorBean 
+                        = (AuthorBean) objectInputStream.readObject();
+            }
+            finally
+            {
+                if (byteArrayInputStream != null)
+                {
+                    byteArrayInputStream.close();
+                }
+            }
+        }
+        assertEquals("The Name of the deserialized AuthorBean, "
+                + " should equal the Name of AuthorBean",
+                deserializedAuthorBean.getName(), authorBean.getName());
+        assertEquals("The Id of the deserialized AuthorBean, "
+                + " should equal the Id of AuthorBean",
+                deserializedAuthorBean.getAuthorId(), authorBean.getAuthorId());
     }
 
     /**

Modified: db/torque/runtime/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/xdocs/changes.xml?rev=240328&r1=240327&r2=240328&view=diff
==============================================================================
--- db/torque/runtime/trunk/xdocs/changes.xml (original)
+++ db/torque/runtime/trunk/xdocs/changes.xml Fri Aug 26 13:02:48 2005
@@ -27,6 +27,9 @@
 
   <release version="3.2-rc2-dev" date="in SVN">
     <action type="add" dev="tfischer">
+      The generated beans are now serializable.
+    </action>
+    <action type="add" dev="tfischer">
       Added a method getXXX(connection) to retrieve associated objects
       in the n->1 direction, which uses the provided connection
       if a db hit is necessary

Modified: db/torque/templates/trunk/src/templates/om/bean/Bean.vm
URL: http://svn.apache.org/viewcvs/db/torque/templates/trunk/src/templates/om/bean/Bean.vm?rev=240328&r1=240327&r2=240328&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/bean/Bean.vm (original)
+++ db/torque/templates/trunk/src/templates/om/bean/Bean.vm Fri Aug 26 13:02:48 2005
@@ -17,6 +17,7 @@
  *#
 package ${packageBaseBean};
 
+import java.io.Serializable;
 import java.math.BigDecimal;
 import java.sql.Connection;
 import java.util.ArrayList;
@@ -39,6 +40,7 @@
  * extended; all references should be to ${table.JavaName}${beanSuffix}
  */
 public abstract class ${basePrefix}${table.JavaName}${beanSuffix}
+    implements Serializable
 {
 
 ## ----------------

Modified: db/torque/templates/trunk/src/templates/om/bean/ExtensionBean.vm
URL: http://svn.apache.org/viewcvs/db/torque/templates/trunk/src/templates/om/bean/ExtensionBean.vm?rev=240328&r1=240327&r2=240328&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/bean/ExtensionBean.vm (original)
+++ db/torque/templates/trunk/src/templates/om/bean/ExtensionBean.vm Fri Aug 26 13:02:48 2005
@@ -17,6 +17,8 @@
  *#
 package $packageBean;
 
+import java.io.Serializable;
+
 /**
 #if ($addTimeStamp)
  * The skeleton for this class was autogenerated by Torque on:
@@ -30,5 +32,6 @@
  */
 public class $table.JavaName${beanSuffix}
     extends ${packageBaseBean}.${basePrefix}${table.JavaName}${beanSuffix}
+    implements Serializable
 {
 }

Modified: db/torque/templates/trunk/src/templates/om/bean/MultiExtendBean.vm
URL: http://svn.apache.org/viewcvs/db/torque/templates/trunk/src/templates/om/bean/MultiExtendBean.vm?rev=240328&r1=240327&r2=240328&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/bean/MultiExtendBean.vm (original)
+++ db/torque/templates/trunk/src/templates/om/bean/MultiExtendBean.vm Fri Aug 26 13:02:48 2005
@@ -17,6 +17,8 @@
  *#
 package $packageBean;
 
+import java.io.Serializable;
+
 #if ($child.Ancestor)
   ## need to disassemble the qualified name of the ancestor class,
   ## because the bean package is different
@@ -37,6 +39,8 @@
  * application requirements.  This class will only be generated as
  * long as it does not already exist in the output directory.
  */
-public class $child.ClassName${beanSuffix} extends $parent
+public class $child.ClassName${beanSuffix}
+    extends $parent
+    implements Serializable
 {
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: svn commit: r240328 - in /db/torque:

Posted by Thomas Fischer <tf...@apache.org>.
So many new mails, I get confused which to answer first ! starting with 
the easy one...

On Sat, 27 Aug 2005, Henning P. Schmiedehausen wrote:

> tfischer@apache.org writes:
>
>> Made the generated beans serializable. Also added a testcase to the runtimetest which checks that.
>
> I'm not sure that this is a good idea without having a switch to be
> able to turn it on/off.
>

Hm. Bean generation is turned off by default. If you do not want to 
transfer them over a network, you will typically not use them. They are 
of no use if you use them in the same jvm, as they are just a subset of 
the properties of the "normal" Torque object (only that they do know 
nothing of a database). And if you want to transfer them, they 
should be serializable.

> With the beans suddently be serializable, you buy a whole wealth of
> possible problems with e.g. beans ending up in Servlet container
> sessions that in turn get serialized at restart time.
>
> Adding this in a RC is IMHO a bad thing, either. This is 3.3 stuff
> (because it could break existing code in a new and exciting way...).

Beans came in first in 3.2-RC1. I would expect that things which came in 
new can change over the Release process, but maybe I am wrong there.

Henning, if you still think that the serializable should be configurable 
with default to "off", no problem with that. Just reply and I'll do it.

    Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: svn commit: r240328 - in /db/torque:

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
tfischer@apache.org writes:

>Made the generated beans serializable. Also added a testcase to the runtimetest which checks that.

I'm not sure that this is a good idea without having a switch to be
able to turn it on/off.

With the beans suddently be serializable, you buy a whole wealth of
possible problems with e.g. beans ending up in Servlet container
sessions that in turn get serialized at restart time.

Adding this in a RC is IMHO a bad thing, either. This is 3.3 stuff
(because it could break existing code in a new and exciting way...).

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

		      4 - 8 - 15 - 16 - 23 - 42

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org