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

Mapping Proposal: Directonless DbRelationship

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • 5.0-M2
    • None
    • None

    Description

      It remains to be seen whether the proposed API gives us more efficient and easy-to-use data structure. More experimentation is needed.

      A pair of DbRelationships between two tables is really a single set of joins, not two independent relationships. We should represent it in Cayenne as such. E.g. [*]:

      public class DbRelationshipSide {
      
          DbEntity entity;
          String name;
      
          // complementary "other" side
          DbRelationshipSide otherSide;
      
          // list of columns that matches the order on the complementary "other" side
          List<String> joinColumns;
      
          boolean toMany;
      }
      
      public class DbRelationship {
      
          Map<String, DbRelationshipSide> sides;
      
          public DbRelationshipSide getSide(String dbEntityName) {
              DbRelationshipSide side = sides.get(dbEntityName);
              return Objects.requireNonNull(side, 
                   () -> "Entity " + dbEntityName + " is not a part of the relationship");
          }
      }
      
      

      A single DbRelationship will be linked to both DbEntities, and we won't need to manage two identical sets of joins. From the perspective of an entity, the relationship becomes directed, by accessing its side that matches the entity name.

      [*] I am omitting "toDepPk" property in the example. Per CAY-2739 it may be renamed to "fk".

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              andrus Andrus Adamchik
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: