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

Add 'Property' class for easier and better Expression creation

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.2.M1
    • 3.2.M1
    • Core Library

    Description

      Project Wonder (WebObjects) has a class which is basically just a wrapper around an attribute or relationship name that gives you a way to create Expressions in type-safe manner and with minimal effort. Also sort orderings can be easily generated. In Wonder, these "property" objects are part of the entity template so they are generated automatically.

      So for example:

      public class _Artist extends CayenneDataObject {
      public static final Property<String> NAME = new Property<String>(NAME_PROPERTY);
      ...
      }

      Then client code can do things like:

      new SelectQuery(Artist.class, NAME.eq("Pablo").andExp(AGE.gt(40)), AGE.descs());

      This would select all artists with name equal to Pablo and age greater than 40 and order them in descending age order.

      This concept has been proven to work incredibly well with WebObjects. It's almost as readable as using plain strings but has complete compile-time checking for the property name and the type of the objects it is compared with.

      A complete implementation is attached. It's very simple since ExpressionFactory does the work. If this is accepted, it would make sense to modify the built-in entity templates to generate Property constants for all of the properties.

      Attachments

        1. Property.java
          5 kB
          John Huss

        Activity

          People

            johnthuss John Huss
            johnthuss John Huss
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: