cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikita Timofeev <>
Subject API for aggregate and non aggregate SQL functions
Date Fri, 06 Jan 2017 13:08:34 GMT
Hi all,

I would like to present new Cayenne feature in development to you: API
for SQL functions (both aggregate and non aggregate).

When it will be completed it will be possible to use functions in
select queries with pure API calls without writing any custom SQL or
EJBQL queries.
You'll be able to do something like this (though it may be not a final
version of API):

  long totalCount = ObjectSelect.query(Artist.class)

Or make even more complex queries with HAVING clause:

  List<Object[]> result = ObjectSelect.query(Artist.class)
minSalary, namePart)

.where( Date()))
                                        .or(...) // additional
condition in WHERE clause
                                        .or(...) // additional
condition in HAVING clause

  for(Object[] r : result) {
      long count = (long)r[0];
      int min = (int)r[1];
      String name = (String)r[2];

All this queries will rely on custom properties that can be created
ad-hoc for specific query:

  Expression substrExp =
FunctionExpressionFactory.substringExp(Artist.ARTIST_NAME.path(), 10,
  Property<String> namePart = Property.create("namePart", substrExp,

or be defined directly in a model class:

  public static final Property<Long> ARTIST_COUNT =
Property.create("artistCount", FunctionExpressionFactory.countExp(),

You can find additional information and track progress in Apache JIRA:

And of course any feedback will be really appreciated!

Best regards,
Nikita Timofeev

View raw message