Torque
  1. Torque
  2. TORQUE-200

Generate methods in Peer classes to retrieve a single object from a table

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0-beta1
    • Component/s: Templates
    • Labels:
      None

      Description

      Often, one knows that a database query will return at most a single object.
      To get that object, the following code is needed:
      List<Book> bookList = BookPeer.doSelect(criteria);
      Book book = null;
      if (bookList.size > 1)

      { throw new TooManyRowsException("..."); }

      if (!bookList.isEmpty())

      { book = bookList.get(0); }

      There should be methods named doSelectSingleRecord(...) generated in the Peer class which contains teh above code.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        2h 6m 1 Thomas Fox 09/May/12 14:34
        Resolved Resolved Closed Closed
        137d 17h 31m 1 Thomas Fox 24/Sep/12 08:06
        Thomas Fox made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        Thomas Fox added a comment -

        Not really. Criteria.setSingleRecord only makes sure that you get exactly one record, but the return value of doSelect() is still a list
        DoSelectSingleRecord makes sure you have 0 or 1 record and you get the object without any list.
        Of course both can be combined

        Show
        Thomas Fox added a comment - Not really. Criteria.setSingleRecord only makes sure that you get exactly one record, but the return value of doSelect() is still a list DoSelectSingleRecord makes sure you have 0 or 1 record and you get the object without any list. Of course both can be combined
        Hide
        G Monroe added a comment -

        Doesn't the Criteria.setSingleRecord(boolean b) method do the same thing?

        Show
        G Monroe added a comment - Doesn't the Criteria.setSingleRecord(boolean b) method do the same thing?
        Thomas Fox made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 4.0 [ 12312102 ]
        Resolution Fixed [ 1 ]
        Hide
        Thomas Fox added a comment -

        The generation of the new methods can be suppressed by setting the property
        torque.om.addSelectSingleRecordMethods = false
        in the generator options.

        Show
        Thomas Fox added a comment - The generation of the new methods can be suppressed by setting the property torque.om.addSelectSingleRecordMethods = false in the generator options.
        Thomas Fox created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development