rankin <[EMAIL PROTECTED]> writes:
You might want to check the TORQUE_3_1_HENNING branch from the db-torque CVS.
In a nutshell: Yes. I fell into the same trap and this Torque branch has a
method in the MapBuilder to initialize all the tables of a database map.
Regards
Henning
>A further problem in implementing this:
>It seems the DatabaseMap object is "lazily-built"; that is, tables are
>only added to the map after they're specifically requested. When this
>app first comes up, all I see in the table drop down are: TURBINE_USER,
>GROUP, etc. If I use a particular table thru some other template, it
>will appear in that drop down next time.
>Does anyone know of a property in TR.props which will cause the
>DatabaseMap to be built out upon initialization, or of any method which
>can be called to cause the same thing to occur, or do I have to get a
>connection to the database and go get this metadata myself?
>Thanks, in advance.
>rankin wrote:
>> Thanks for the reply, I was unaware of beanutils. It looks to be an
>> improvement over the less generalized reflection I've been poking at:
>>
>> public List list(String ofWhat){
>> String peerName = MODEL_CLASS_PREFIX + ofWhat + "Peer";
>> try{
>> Class peer = Class.forName(peerName);
>> Object o = peer.newInstance();
>> return ((BasePeer)o).doSelect(new Criteria());
>> } catch (Exception e){/*do something*/;}
>> return null;
>> }
>>
>> I'll look into it & try it.
>>
>> But I was assuming there was some simpler method of accomplishing the
>> same goal where one doesn't need to know this kind of stuff. This would
>> seem to be a question that would crop up often, especially at the
>> beginning of a project or for proof-of-concept work.
>>
>>
>> Russell Edens wrote:
>>
>>> Rankin said:
>>>
>>>> I have many tables, which for the moment are separately defined. I want
>>>> one template, DisplayTable.vm, to display any one of these tables. So,
>>>> DisplayTable.java has:
>>>>
>>>> public void doBuildTemplate(){
>>>> ...
>>>> String tablename = data.getParameters().getString("tablename",null);
>>>> Criteria crit = new Criteria();
>>>> List list = [**tablename**]Peer.doSelect(crit);
>>>> context.put("list", list);
>>>> TableMap tmap = Torque.getDatabaseMap("mydb").getTable(tablename);
>>>> ColumnMap[] cMap = tmap.getColumns();
>>>> Vector names;
>>>> for(int i = cMap.length -1; i >=0; i--)
>>>> names.add(cMap[i].getColumnName());
>>>> context.put("columnNames", names.toArray());
>>>> ...
>>>> }
>>>>
>>>> and DisplayTable.vm has
>>>>
>>>> <tr>
>>>> #foreach ($columName in $columnNames)
>>>> <th>$columnName</th>
>>>> #end
>>>> </tr>
>>>> #foreach ($item in $itemList)
>>>> <TR>
>>>> #foreach ($attribute in $columnNames)
>>>> <TD>$!{item.$attribute}</TD>
>>>> #end
>>>> </TR>
>>>> #end
>>>>
>>>> I'm sure this has been done many times far more easily and other
>>>> suggestions would be greatly appreciated ... However - how does one do
>>>> the "[tablename]Peer.doSelect(crit)" bit?
>>>>
>>>> Suggestions??
>>>>
>>>
>>>
>>> If you want to do it generically reflection is your best bet.
>>>
>>> You might consider the org.apache.commons.beanutils.MethodUtils class for
>>> making these calls. Un-tested example:
>>>
>>> private List invokeDoSelect(String
>>> fullyQualifiedTorquePeerObjectName,
>>> Criteria crit)
>>> {
>>> final Class[] doSelectParamTypes = { Criteria.class };
>>> final Object[] doSelectParams = { crit };
>>> Object results = null;
>>> try
>>> {
>>> Class peerClass =
>>> Class.forName(fullyQualifiedTorquePeerObjectName);
>>> results = MethodUtils.invokeExactMethod(peerClass, "doSelect",
>>> doSelectParams, doSelectParamTypes);
>>> }
>>> catch (NoSuchMethodException e)
>>> {
>>> // TODO handle this
>>> }
>>> catch (IllegalAccessException e)
>>> {
>>> // TODO handle this
>>> }
>>> catch (InvocationTargetException e)
>>> {
>>> // TODO handle this
>>> }
>>> catch (ClassNotFoundException e)
>>> {
>>> // TODO handle this
>>> }
>>>
>>> return (List)results;
>>> }
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
--
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH
[EMAIL PROTECTED] +49 9131 50 654 0 http://www.intermeta.de/
RedHat Certified Engineer -- Jakarta Turbine Development -- hero for hire
Linux, Java, perl, Solaris -- Consulting, Training, Development
What is more important to you...
[ ] Product Security
or [ ] Quality of Sales and Marketing Support
-- actual question from a Microsoft customer survey
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]