> There are three workarounds :
> - construct a bean info which gives the association (getCOD, setCOD) 
> for the
> StringKey version and suppress the setter for the String version
>

Ok, here's my patch to obtain useful beanInfo in Torque (to 3.0b3)

It's doing more than you need maybe; I'm worrying about the XMLEncoder. 
Feel free to rip it apart to remove what you don't need.
People who do not care about persistence will still benefit from my 
patch, but nearer the end of my mail. Do read on.

First, I added this persistence field to the ForeignKey attribute in 
database.dtd:

<!ATTLIST foreign-key
   foreignTable CDATA #REQUIRED
   name CDATA #IMPLIED
   onUpdate (cascade|setnull|restrict|none) "none"
   onDelete (cascade|setnull|restrict|none) "none"
   persist (forward|backward|both|none) "none"
 >

Values mean
"none" (default): Do not follow this link
"forward": Follow a link from this object to the foreignTable object
"backward": Follow a link from the foreignTable object to a List of 
objects of this table
"both": i.e. forward and backward (obviously dangerous, as this is the 
pathological case that got me started.)

Then, of course, accessors for this in the ForeignKey class:

src/java/org/apache/torque/engine/database/model/ForeignKey.java~ 
src/java/org/apache/torque/engine/database/model/ForeignKey.java
*** src/java/org/apache/torque/engine/database/model/ForeignKey.java~   
Wed Jul 17 16:41:11 2002
--- src/java/org/apache/torque/engine/database/model/ForeignKey.java    
Fri Aug  2 19:29:11 2002
***************
*** 75,80 ****
--- 75,82 ----
       private Table parentTable;
       private List localColumns = new ArrayList(3);
       private List foreignColumns = new ArrayList(3);
+               private boolean persistForwards = false;
+               private boolean persistBackwards = false;

       // the uppercase equivalent of the onDelete/onUpdate values in the 
dtd
       private final String NONE    = "NONE";
***************
*** 98,103 ****
--- 100,108 ----
           onDelete = attrib.getValue("onDelete");
           onUpdate = normalizeFKey(onUpdate);
           onDelete = normalizeFKey(onDelete);
+                               String persist = 
attrib.getValue("persist");
+                               persistForwards = 
persist.equals("forward") || persist.equals("both");
+                               persistBackwards = 
persist.equals("backward") || persist.equals("both");
       }

       /**
***************
*** 149,154 ****
--- 154,173 ----
       {
          return onDelete;
       }
+
+     /**
+      * returns the persistForwards attribute
+      */
+               public boolean isPersistForwards() {
+                               return persistForwards;
+               }
+
+     /**
+      * returns the persistBackwards attribute
+      */
+               public boolean isPersistBackwards() {
+                               return persistBackwards;
+               }

       /**
        * sets the onDelete attribute



Note that persistance backwards requires the
List getXXXX() methods to have setters...

So

*** templates/om/Object.vm      Fri Aug  2 21:28:36 2002
--- templates/om/Object.vm~   Sun Aug  4 09:20:47 2002
***************
*** 432,437 ****
--- 432,447 ----
           return $collName;
       }

+
+               /**
+                * Sets the value of the collection. Do not use: results 
are unpredictable.
+                * Implemeneted for beans completeness.
+                */
+               public void set${relCol}(List l)
+               {
+                               $collName = l;
+               }
+
       /**
        * If this collection has already been initialized with
        * an identical criteria, it returns the collection.


Finally,
The templates/om/ObjectBeanInfo.vm:

Attachment: ObjectBeanInfo.vm
Description: Binary data



Oh, and you have to tell Torque to generate it:

*** templates/om/Control.vm~ Fri Aug  2 00:29:29 2002
--- templates/om/Control.vm  Sun Aug  4 08:36:14 2002
***************
*** 74,79 ****
--- 74,83 ----
       #set ( $path = "${strings.getPackageAsPath($pkbase)}$fname" )
       $generator.parse("om/Object.vm",$path,"table",$tbl)

+     #set ( $fname = "${basePrefix}${firstcap}BeanInfo.java" )
+     #set ( $path = "${strings.getPackageAsPath($pkbase)}$fname" )
+     $generator.parse("om/ObjectBeanInfo.vm",$path,"table",$tbl)
+
   #end

       #set ( $fname = "${firstcap}.java" )

If you do not care about XMLEncoder, only modify Control.vm, and remove 
the following sections from my ObjectBeanInfo.vm:
All the loop starting from
  #foreach ($fk in $table.Referrers)
(lines 75 to 109, incl.)
And the check for transience in lines 66-68.

This gives you a very nice BeanInfo for your BaseXXX.vm classes.
It works for me, and incidentally gives me very nice XML.


Enjoy,
Marc-Antoine Parent

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to