db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Hodgkinson <a...@softxs.ch>
Subject Re: Suggestion: A change to Torque (populate & XML)
Date Mon, 13 Jan 2003 10:19:39 GMT

Dear Stephen,

Thanks for your tips regarding the accessing of table and field
names. You suggestions were helpful and almost works in my case.

> {Use] ..Intake.. [for populating your objects].

Thanks. I hadn't seen that. Exactly how 'fragile' is it?
> You can get field names by doing:
> Torque.getDatabaseMap().getTable(XxxPeer.TABLE_NAME);
> ..if you just have Xxx, you can do Xxx.getPeer().TABLE_NAME.

I just have Xxx, which in my case, is of type BaseObject. 
Unfortunately, BaseObject doesn't define a stub for getPeer, so
my code won't even complile. Note that I use BaseObject 
because I need my code to be generic and can't be coding for 
a particular database table.

Failing some other better idea, could we add a 'not-implemented 
exception throwing' stub for getPeer to BaseObject.java?

[I can't help feeling that I'm going run into other problems 
caused by BaseObject not defining a 'non-implemented' stub for 
the methods that are generated in the XxxBase objects. ]

> As far as the toXml method, I'd rather not see the code go into
> Torque, especially the generation templates, as Torque is complex
> enough as it is.

Your choice. I'll work up a separate class, most likely using 
some of your and the others suggestions (BeanUtils, Castor, etc.)

That aside, and having looked at the code, I am pleasently surprised 
to see how simple it really is. This is not to take anything away 
from Torque, just merely to say that the code seems reasonably 
well organized and easy to read.

BEst wishes,


P.S. The entire diff to implement the table name method and the
field name list is only:

<     public synchronized List getFieldNames()
>     public static synchronized List getFieldNames()
<     }
<     /** 
<       * Get the database table name associate with this 
<       * class: E.g.: $table.Name 
<       * @return the database table name.
<       */
<     public String getTableName() 
<     { 
<         return "$table.Name"; 

< import java.util.List;
<     }
<     /**
<      * Retrieves a list of the field names from the object. 
<      * Must be overridden if called.
<      * BaseObject's implementation will throw an Error.
<      *
<      * @return list of field names.
<      *
<      */
<     public synchronized List getFieldNames() { 
<         throw new Error("BaseObject.getFieldNames: " +
<     }
<     /**
<      * Retrieves the object's database table.  
<      * Must be overridden if called.
<      * BaseObject's implementation will throw an Error.
<      *
<      * @return list of field names.
<      *
<      */
<     public String getTableName()
<     {   // We'd like this to be static, but then it cannot be
<         throw new Error("BaseObject.getTableName: " +
<     }


View raw message