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

ObjectSelect improvement: columns as full entities

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.B1
    • Core Library
    • None

    Description

      Changes in API:

      1. Add new Expression ASTFullObject that will be just a marker for the desired logic.
        This expression can be later (in post 4.0 versions) used in where() and in orderBy() methods to act as ObjectId and
        thus fill another gap where hacks like "db:OBJECT_ID" are used now.
      2. Add new methods in Property:
            static <T extends Persistent> Property<T> createSelf(Class<? super T> type);
        
            <T extends Persistent> Property<T> flat(Class<? super T> tClass)
        
      3. Prohibit direct usage of Properties mapped on toMany relationships, so that the following code will throw a CayenneRuntimeException
        List<Object[]> result = ObjectSelect.query(Artist.class)
                .columns(Artist.ARTIST_NAME, Artist.PAINTING_ARRAY)
                .select(context);
        

      Usage examples:

      1. Selecting root object plus some related fields:
        Property<Artist> artistSelf = Property.createSelf(Artist.class);
        
        List<Object[]> result = ObjectSelect.query(Artist.class)
                .columns(artistSelf, Artist.ARTIST_NAME, Artist.PAINTING_ARRAY.count())
                .select(context);
        
      2. Selecting toOne relationship:
        List<Object[]> result = ObjectSelect.query(Painting.class)
                .columns(Painting.PAINTING_TITLE, Painting.TO_ARTIST, Painting.TO_GALLERY)
                .select(context);
        
      3. Selecting toMany relationship, the result will be as it will be in SQL query
        Property<Artist> artist = Property.createSelf(Artist.class);
        Property<Painting> artistPainting = Artist.PAINTING_ARRAY.flat(Painting.class);
        Property<Gallery> artistPaintingGallery = Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY);
        
        List<Object[]> result = ObjectSelect.query(Artist.class)
                .columns(artist, artistPainting, artistPaintingGallery)
                .select(context);
        

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: