Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-2669

Ordering of related entities via relationship definition

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 4.1
    • 5.0-M2
    • Core Library, Modeler
    • None

    Description

      Current Situation:

      'Details' entities are related to their 'master' entities as specified by their DB- and  object relationships in Cayenne Modeler. When a list of detail entities is accessed via according methods of the master object, a query is generated according to the defined relationship and executed to resolve the details objects.

      For example, the generated query for retrieving all PAINTINGS of an artist is something like:

       

      SELECT t0.id, t0.name, t0.artist_id, t0.gallery_id FROM PAINTINGS t0 WHERE t0.artist_id = 999;

       

      Feature Request:

      It shall be possible, to optionally define the ordering of the details entities on DB level (by the query) as attribute of the specific relationship by one or more properties of the details entity.

      Cayenne Modeler shall support this relationship attribute (e.g. as additional property of the dialog shown below).

       

      This means, that if no ordering is defined, everything stays as is.

      If an ordering is defined, the relationship query of the example above shall be generated as

       

      SELECT t0.id, t0.name, t0.artist_id, t0.gallery_id FROM PAINTINGS t0 WHERE t0.artist_id = 999 ORDER BY t0.name ASC;

       

      to order the associated paintings by their name.

      When additional details objects are attached to the master object on Java level, the ordering should be maintained, ideally upon the next 'read access' to the ordered list property since the order is typically not relevant for persisting the list.

      Maintaining the ordering upon modification of the properties relevant for ordering is not required, but a programmatic way to restore the defined order on Java level is required.

       

      Benefit:

      Convenience: Currently either 'hacks' or separate queries are required to implement this behavior. A built-in solution, esp. when invloving Cayenne Modeler, is easier to define and to maintain.

      Performance: If not using a separate query it is currently difficult to figure out when the list need to reordered. Separate, explicit queries are a significant extra effort for a feature (modelled relationships) that is 'almost' available and the optimal (as part of object resolution) execution is again not easy to implement (at least without deep knowledge of Cayenne internals). The requested feature psuhes sorting of entities onto DB level (which is typically performant) and is therefore executed only during entity resolution and (lazyly) upon adding additional details object to the list.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sITo Stefan S.
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: