Cayenne
  1. Cayenne
  2. CAY-1213

Cayenne should support enum types in qualifier statements/expression handling

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0M5
    • Fix Version/s: 3.1M1
    • Component/s: Core Library
    • Labels:
      None

      Description

      Currently, cayenne doesn't support java enums in its expression syntax and, by extension, in qualifier statements. This makes it impossible to use an enum type as a class descriminator for inheritance.

      Enum expressions would look like:

      propertyName = some.package.Type.CONSTANT

      to make it consistent with JPA.

      1. CAY-1213.patch
        17 kB
        Andrei Veprev
      2. CAY-1213-ejbql.patch
        19 kB
        Andrei Veprev
      3. CAY-1213-in-memory.patch
        3 kB
        Andrei Veprev

        Activity

        Hide
        Andrus Adamchik added a comment -

        Ksenia looked at this a bit , and it turns out that:

        1. Our EJBQL implementation doesn't process enums properly.
        2. In Expression API (unless we decide to add a special prefix for enums), there is a syntactic ambiguity between a relationship path and an enum.

        For now the plan is to fix #1 and keep the #2 ambiguity, resolving it when expression is processed. I.e. ASTPath can be a path or an enum.

        Show
        Andrus Adamchik added a comment - Ksenia looked at this a bit , and it turns out that: 1. Our EJBQL implementation doesn't process enums properly. 2. In Expression API (unless we decide to add a special prefix for enums), there is a syntactic ambiguity between a relationship path and an enum. For now the plan is to fix #1 and keep the #2 ambiguity, resolving it when expression is processed. I.e. ASTPath can be a path or an enum.
        Hide
        Andrei Veprev added a comment -

        Here is the patch that implements enum and constant (static final) values in expressions. To specify const value in expression user have to provide full path to it: some.package.Type.CONSTANT.
        This patch doesn't implement such functionality for EJBQL.
        There is problem with null values: in case if constant value is null wrong qualifier is generated for SQL statement (such as "someField = NULL" instead of "someField IS NULL").

        Show
        Andrei Veprev added a comment - Here is the patch that implements enum and constant (static final) values in expressions. To specify const value in expression user have to provide full path to it: some.package.Type.CONSTANT. This patch doesn't implement such functionality for EJBQL. There is problem with null values: in case if constant value is null wrong qualifier is generated for SQL statement (such as "someField = NULL" instead of "someField IS NULL").
        Hide
        Andrus Adamchik added a comment -

        Andrei, before I look closer at the patch, a few high level observations:

        • would be nice to collapse multiple git revisions into one in a patch. (not that I can't do it myself on my end )
        • In the test cases, let's rename entity User to something less common that can't potentially be a DB keyword, etc.
        Show
        Andrus Adamchik added a comment - Andrei, before I look closer at the patch, a few high level observations: would be nice to collapse multiple git revisions into one in a patch. (not that I can't do it myself on my end ) In the test cases, let's rename entity User to something less common that can't potentially be a DB keyword, etc.
        Hide
        Andrei Veprev added a comment -

        Ok, here it is.
        Renamed User entity to Cons1Entity. And "one-commit" patch.

        Show
        Andrei Veprev added a comment - Ok, here it is. Renamed User entity to Cons1Entity. And "one-commit" patch.
        Hide
        Andrus Adamchik added a comment -

        Andrei, I applied the patch. Looks good. One thing that I had to change is the use of StringUtils. Looks like commons-lange library leaked into Cayenne via Velocity, although Cayenne itself doesn't (and shouldn't) have a dependency on commons-lang. So I replaced with with a simple 'indexOf' lookup, which should also perform better, as it doesn't do cloning or regex matching, just a simple substring.

        Show
        Andrus Adamchik added a comment - Andrei, I applied the patch. Looks good. One thing that I had to change is the use of StringUtils. Looks like commons-lange library leaked into Cayenne via Velocity, although Cayenne itself doesn't (and shouldn't) have a dependency on commons-lang. So I replaced with with a simple 'indexOf' lookup, which should also perform better, as it doesn't do cloning or regex matching, just a simple substring.
        Hide
        Andrei Veprev added a comment -

        Ok, got it

        Show
        Andrei Veprev added a comment - Ok, got it
        Hide
        Andrei Veprev added a comment -

        Here is new patch. It implements requared functionality for EJBQL queries.

        Show
        Andrei Veprev added a comment - Here is new patch. It implements requared functionality for EJBQL queries.
        Hide
        Andrei Veprev added a comment -

        And small patch for in-memory evaluation implementation.

        Show
        Andrei Veprev added a comment - And small patch for in-memory evaluation implementation.
        Hide
        Andrus Adamchik added a comment -

        Andrei, thanks for the patches. I applied them pretty much unchanged, and everything works correctly.

        A note on Cayenne code conventions (since I don't have any substantial comments on the actual patch contents ) - any new public or protected API (such as new methods), we tag with major Cayenne version when it was added. So I added "@since 3.1" to a few new public methods.

        Show
        Andrus Adamchik added a comment - Andrei, thanks for the patches. I applied them pretty much unchanged, and everything works correctly. A note on Cayenne code conventions (since I don't have any substantial comments on the actual patch contents ) - any new public or protected API (such as new methods), we tag with major Cayenne version when it was added. So I added "@since 3.1" to a few new public methods.

          People

          • Assignee:
            Andrus Adamchik
            Reporter:
            Robert Zeigler
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development