db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Haberman <step...@beachead.com>
Subject Re: Suggestion: A change to Torque (populate & XML)
Date Fri, 10 Jan 2003 16:57:29 GMT
On Fri, Jan 10, 2003 at 10:28:53AM +0000, Alan Hodgkinson wrote:
> 1.1 Populate Torque objects, e.g. objects which extend 
>    BaseObject, automatically from a Map or Hashtable. 

We've already got a way to do this, plus it does validation and is
pretty darn spiff (though a bit fragile). Intake lives in both
Fulcrum (the fragile version I'm familiar with) and also in
Turbine-2 (with a recently refactored version by...Quinton, if I
remember right, that hopefully is a lot better than what is in
Fulcrum).

See:

http://jakarta.apache.org/turbine/fulcrum/howto/intake-service.html

> 1.2 Allow Torque objects to emit SAX events to a
>    Content handler. 
<snip/>
>   This task would be made MUCH easier if there were a 
>   method getFieldNames(), that returns null (or throws an 
>   exception) in BaseObject. It would be over-ridden by all 
>   the Torque generated classes). 

You can get field names by doing:

Torque.getDatabaseMap().getTable(XxxPeer.TABLE_NAME);

With the TableMap, you can get all of the columns and what not as
you were wanting to. (Although the
DatabaseMap/TableMap/ColumnMap...might only be available at runtime,
not compile/generation time, which might not be what you wanted).

> 2.2 Sax events
> 
>   Given the getFieldNames method in BaseObject, it becomes
>   a trivial exercise to implement the SAX event generation
>   directly in BaseObject. It is would also be trivial to 
>   implement a toXml method, that returned the XML as a
>   String. (..and you'd get free Steak Knives too. :)
> 
>   The only problem is to get the table name (for placing in
>   the top-level XML tag). The easiest solution would be to 
>   add a null (or exception-throwing) method getTableName to 
>   BaseObject, which would be overridden by the generated 
>   Torque objects.

Again, XxxPeer.TABLE_NAME should work. Also, if you just have Xxx,
you can do Xxx.getPeer().TABLE_NAME.

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.

Unless you do something like XmlConverter which as a static
toXml(BaseObject obj) method to which uses the runtime-available
XxxMap stuff to spit out XML, either was a String or events or what
not, we could drop it in a util directory.

- Stephen

Mime
View raw message