Torque
  1. Torque
  2. TORQUE-26

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

    Details

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

      Description

      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);
      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.

        Activity

        Thomas Vandahl made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Thomas Fox made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Thomas Fischer [ tfischer ]
        Resolution Fixed [ 1 ]
        Hide
        Thomas Fox added a comment -

        Committed patch, with the following changes

        • removed the restriction that protected columns cannot be set by the new methods. "protected" only means that the column's getters and setters are not public but protected. This was mainly doen for people using inheritance, so that they can override the protected methods by public methods only in selected subclasses
        • replaced tabs by spaces in the velocity templates. Please, next time do not use tabs in the velocityx templates. Tabs mess up the code and are thus evil.
        Show
        Thomas Fox added a comment - Committed patch, with the following changes removed the restriction that protected columns cannot be set by the new methods. "protected" only means that the column's getters and setters are not public but protected. This was mainly doen for people using inheritance, so that they can override the protected methods by public methods only in selected subclasses replaced tabs by spaces in the velocity templates. Please, next time do not use tabs in the velocityx templates. Tabs mess up the code and are thus evil.
        CG Monroe made changes -
        Attachment BaseObjectSetByMethods-Changelog.txt [ 12335110 ]
        Hide
        CG Monroe added a comment -

        The change log for the attached source zip (included in the zip as well).

        Show
        CG Monroe added a comment - The change log for the attached source zip (included in the zip as well).
        CG Monroe made changes -
        Field Original Value New Value
        Attachment BaseObjectSetByMethods.zip [ 12335109 ]
        Hide
        CG Monroe added a comment -

        The modified code to impliment this new feature.

        Show
        CG Monroe added a comment - The modified code to impliment this new feature.
        CG Monroe created issue -

          People

          • Assignee:
            Thomas Fox
            Reporter:
            CG Monroe
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development