cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikita Timofeev <>
Subject ColumnSelect API + Persistent objects
Date Tue, 07 Mar 2017 12:12:05 GMT
Hi all,

I'm currently working on some missing parts of ColumnSelect API
introduced in M5.

Idea is simple: select full entities along with arbitrary columns.
It was discussed previously on @dev list, thou without any details.

These entities can be anything that can be resolved against root (root
itself, toOne or toMany relationships)

* The suggested changes in API is following *

1) Add new Expression ASTFullObject (and the corresponding method in
ExpressionFactory) 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 where it can act as ObjectId
and thus fill another gap where hacks with paths like "db:OBJECT_ID"
are used now.

2) Add new factory methods in Property class:

    <T extends Persistent> Property<T> createSelf(Class<? super T> type);
    <T extends Persistent> Property<T> createForRelationship(
                   Property<?> property, Class<? super T> type)

3) Prohibit direct usages of properties mapped on toMany
relationships, so that the following code will throw a

List<Object[]> result = ObjectSelect.query(Artist.class)
        .columns(Artist.ARTIST_NAME, Artist.PAINTING_ARRAY)

* 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())

2) Selecting toOne relationship:

// Here Object[1] will be an Artist, Object[2] will be a Gallery
List<Object[]> result = ObjectSelect.query(Painting.class)
        .columns(Painting.PAINTING_TITLE, Painting.TO_ARTIST,

3) Selecting toMany relationship (this is a questionable feature)
The result will be as it would be in raw SQL query (i.e. flat matrix
of Artists and Paintings)

Property<Artist> artist = Property.createSelf(Artist.class);
Property<Painting> artistPainting =
Property.createForRelationship(Artist.PAINTING_ARRAY, Painting.class);
Property<Gallery> artistPaintingGallery =;

List<Object[]> result = ObjectSelect.query(Artist.class)
        .columns(artist, artistPainting, artistPaintingGallery)

Any comments, usage scenarios, naming suggestions, etc will be really

Here is a link to the corresponding JIRA issue:

Best regards,
Nikita Timofeev

View raw message