CBE Examples on GitHub

Cayenne by Example

Illustrating some of the major features of the Apache Cayenne ORM framework using simple examples.

Download this project as a .zip file Download this project as a tar.gz file

Aggregate Functions

Cayenne Version 3.0.2
Project Directory FetchingObjects/Aggregates
Source Directory FetchingObjects/Aggregates/src/main/java
Resource Directory FetchingObjects/Aggregates/src/main/resources
Inputs N/A
Compiling/Running cd FetchingObjects/Aggregates
mvn clean compile
mvn exec:java -Dexec.mainClass=cbe.fetching.Aggregates
View/Edit Model mvn cayenne-modeler:run
Status Code: Mostly Done
Documentation: Needs work

Cayenne doesn't natively support aggregate database functions, but you can incorporate this example into your application if you need this functionality.

This example is a bit different in that it doesn't illustrate native Cayenne functionality, but uses a custom AggregatesUtil class to implement the functionality. The documentation is more about showing how to use AggregatesUtil than explaining how it works, but you can certainly explore the class to learn more about working with Cayenne at a lower level (custom SQL is generated).

The AggregatesUtil class includes methods to perform a COUNT(*), SUM(column), AVG(column), MIN(column), and MAX(column) of database records using a Cayenne query. These methods return long or BigDecimal results instead of normal Cayenne objects.

TBD...more to come.

The AggregatesUtil class (and supporting classes) was inspired by Andrey Razumovsky (where "inspired by" means "mostly stolen from") who posted the original code on the Cayenne mailing list.