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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]