You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by "CG Monroe (JIRA)" <ji...@apache.org> on 2006/06/06 22:22:31 UTC
[jira] Updated: (TORQUE-26) Add SetBy* methods that match the
GetBy* methods to the OM classes
[ http://issues.apache.org/jira/browse/TORQUE-26?page=all ]
CG Monroe updated TORQUE-26:
----------------------------
Attachment: BaseObjectSetByMethods.zip
The modified code to impliment this new feature.
> Add SetBy* methods that match the GetBy* methods to the OM classes
> ------------------------------------------------------------------
>
> Key: TORQUE-26
> URL: http://issues.apache.org/jira/browse/TORQUE-26
> Project: Torque
> Type: New Feature
> Components: Generator, Runtime, Test Project
> Versions: 3.2
> Reporter: CG Monroe
> Fix For: 3.2.1
> Attachments: BaseObjectSetByMethods.zip
>
> The attached source zip adds setBy* methods that match the existing getBy*
> methods in the Generated OM record classes. These have the signatures of:
>
> public boolean setByName( String fieldName, Object value )
> throws IllegalArgumentException
> public boolean setByPeerName( String fieldName, Object value )
> throws IllegalArgumentException
> public boolean setByPositon( int position, Object value )
> throws IllegalArgumentException
>
> The boolean will be false if the field can't be set (unknown name or
> field is protected, i.e. readOnly ). IllegalArgumentExceptions will be
> thrown if the Object does not match the fields required type. The
> implimentations handle conversion to primitive if needed.
>
> The BaseObject runtime class now has matching setBy* methods
> that throw "not implemented" exceptions.
>
> Generation of these methods can be turned on and off by the
> existing torque.addGetByNameMethod option. Just because it's easy
> and doesn't impact the build properties. Should there be yet another
> option or should this option name change?
>
> The reason for this is to make it possible to have methods who's parameters
> specify BaseObject fully interact with ANY record object. Currently, the
> only way to set values in a record using a BaseObject defined variable is
> to do a compile time cast and call the appropriate set<Field> method. This
> will allow values to be set, if you have a runtime determined field name and
> a BaseObject handle.
>
> For example, suppose there is the need for a generic import function to
> support something like XML import 8-), or CSV or just transfering records
> from one database schema (Torque or Physical) to another with a matching
> or improved/new revision schema. With this, you can do things like:
>
> void convert( List mixedListOfOldRecords, String newDBName ) {
> ...
> <iterate over mixedListOfRecords>
> ...
> BaseObject oldRecord = mixedListOfOldRecords.get(x);
> String tableName = oldRecord.getTableMap().getName();
> ...
> DatabaseMap dMap = Torque.getDatabaseMap(newDBName);
> dMap.initialize();
> TableMap tMap = dMap.getTable(tableName);
> BaseObject newRecord = tMap.getOMClass().newInstance();
> ColumnMaps[] columns = tMap.getColumns();
> <iterate over columns>
> ...
> String fieldName = column.getJavaName();
> Object value = oldRecord.getByName(fieldName);
> newRecord.setByName(fieldName, value);
> ...
>
> Note that mixedListOfOldRecords could be created with all required
> foreign key records as well as sub-records.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org