db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gareth Boden <gareth.bo...@egsgroup.com>
Subject Re: Suggestion: A change to Torque (populate & XML)
Date Tue, 14 Jan 2003 12:30:32 GMT
>> You can get field names by doing:
>> Torque.getDatabaseMap().getTable(XxxPeer.TABLE_NAME);
> <snip/>
>> ..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.

Simple reflection can sort that, something along the lines of (without 
having the exact method names to hand) :
	Method getPeer = Xxx.getClass().getMethod("getPeer", new Class[0]);
	Object peer = getPeer.invoke(Xxx);
	Field tableNameField = peer.getClass().getField("TABLE_NAME");
	Object tableName = tableNameField.getValue();

However, I believe I'm right in thinking that the DatabaseMap does not 
concern itself with the method names on the data objects - so although 
you can find all the column names for a table, you still can't find 
their values on an arbitrary object in order to turn it to XML. I could 
be wrong... but if I'm not, something new still has to go into the 
generated code.


View raw message