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

(NOT) EXIST usability - provide simple expression syntax

    XMLWordPrintableJSON

Details

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

    Description

      Background

      Currently, the syntax for (NOT) EXISTS requires two queries and an explicit correlation expression:

      https://cayenne.apache.org/docs/4.2/cayenne-guide/#subqueries
      https://twitter.com/ApacheCayenne/status/1562702875327082496

      This is great for a general case, but often the "enclosing" expression is simply a relationship from top query root to subquery root. So the syntax can be drastically simplifed, replacing sub ObjectSelect with a simple expression. So this:

      ObjectSelect<Painting> subQuery = ObjectSelect.query(Painting.class)
              .where(Painting.ARTIST.eq(Artist.ARTIST_ID_PK_PROPERTY.enclosing()));
      
      long count = ObjectSelect.query(Artist.class)
              .where(ExpressionFactory.notExists(subQuery))
              .selectCount(context);
      

      becomes this:

      long count = ObjectSelect.query(Artist.class)
              .where(ExpressionFactory.notExists(Artist.PAINTINGS))
              .selectCount(context);
      

      or even better, this:

      long count = ObjectSelect.query(Artist.class)
              .where(Artist.PAINTINGS.notExists())
              .selectCount(context);
      

      Task Scope

      (TODO: break to subtasks?)

      • Implement "ExpressionFactory.exists(Exp)" and "ExpressionFactory.notExists(Exp)". The trick would be to check all paths within the Exp and build the corresponding correlation expressions for the subquery. It may potentially resolve to multiple subqueries (if multiple relationships are specified), or no subqueries (for conditions based on the root query attributes: 'not exists name = "A"' would become 'not (name = "A")' in SQL)
      • Implement parseable exp syntax "exists <exp>" and "not exists <exp>"
      • Implement "exp.exists()" and "exp.notExists()" for fluent syntax

      Attachments

        Activity

          People

            ntimofeev Nikita Timofeev
            andrus Andrus Adamchik
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 10m
                10m