Uploaded image for project: 'Torque'
  1. Torque
  2. TORQUE-26

Add SetBy* methods that match the GetBy* methods to the OM classes


    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.2
    • Fix Version/s: 3.3
    • Component/s: Generator, Runtime, Test Project
    • Labels:


      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;
      String tableName = oldRecord.getTableMap().getName();
      DatabaseMap dMap = Torque.getDatabaseMap(newDBName);
      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.




            • Assignee:
              tfischer Thomas Fox
              monroe CG Monroe
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: