[ http://issues.apache.org/jira/browse/TORQUE-26?page=all ]
Thomas Vandahl closed TORQUE-26. -------------------------------- > 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 > Issue Type: New Feature > Components: Runtime, Generator, Test Project > Affects Versions: 3.2 > Reporter: CG Monroe > Assigned To: Thomas Fischer > Fix For: 3.3 > > Attachments: BaseObjectSetByMethods-Changelog.txt, > 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]