This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new f47d38ef0 Update code examples to use latest features
f47d38ef0 is described below

commit f47d38ef0f0306d39aa1219412557ff33f875a89
Author: Nikita Timofeev <stari...@gmail.com>
AuthorDate: Fri Aug 2 12:58:38 2024 +0400

    Update code examples to use latest features
---
 .../_cayenne-guide/part2/queries/objectselect.adoc | 31 +++++++++++++++-------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git 
a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/queries/objectselect.adoc
 
b/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/queries/objectselect.adoc
index d6a8f6dae..73514c339 100644
--- 
a/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/queries/objectselect.adoc
+++ 
b/docs/asciidoc/cayenne-guide/src/docs/asciidoc/_cayenne-guide/part2/queries/objectselect.adoc
@@ -36,7 +36,7 @@ INFO: === returned 5 row. - took 5 ms.
 
 This SQL was generated by Cayenne from the `ObjectSelect` above.
 `ObjectSelect` can have a qualifier to select only the data matching specific 
criteria.
-Qualifier is simply an Expression (Expressions where discussed in the previous 
chapter),
+Qualifier is simply an Expression (Expressions where discussed in the 
<<Expressions,previous chapter>>),
 appended to the query using "where" method. If you only want artists whose 
name begins with 'Pablo',
 you might use the following qualifier expression:
 
@@ -114,10 +114,10 @@ But you can use aggregates in more cases, even combine 
selecting individual prop
 
 [source, java]
 ----
-// this is artificial property signaling that we want to get full object
-Property<Artist> artistProperty = Property.createSelf(Artist.class);
-
-List<Object[]> artistAndPaintingCount = ObjectSelect.columnQuery(Artist.class, 
artistProperty, Artist.PAINTING_ARRAY.count())
+// Artist.SELF - is a special property that denotes a full object in this case
+List<Object[]> artistAndPaintingCount = ObjectSelect.columnQuery(Artist.class,
+        Artist.SELF,
+        Artist.PAINTING_ARRAY.count())
     .where(Artist.ARTIST_NAME.like("a%"))
     .having(Artist.PAINTING_ARRAY.count().lt(5L))
     .orderBy(Artist.PAINTING_ARRAY.count().desc(), Artist.ARTIST_NAME.asc())
@@ -144,14 +144,25 @@ ORDER BY COUNT(t1.PAINTING_ID) DESC, t0.ARTIST_NAME
 
 ===== Subqueries
 
-Since Cayenne 4.2 `ObjectSelect` supports subqueries.
-Here is a simple example of `NOT EXISTS` subquery:
+Since Cayenne 4.2 `ObjectSelect` supports subqueries, and since 5.0 subqueries 
API is greatly improved.
+Here is an example of a basic `NOT EXISTS` subquery:
 
 [source, java]
 ----
-ObjectSelect<Painting> subQuery = ObjectSelect.query(Painting.class)
-        
.where(Painting.TO_ARTIST.eq(Artist.ARTIST_ID_PK_PROPERTY.enclosing()));
 long count = ObjectSelect.query(Artist.class)
-        .where(ExpressionFactory.notExists(subQuery))
+        .where(Artist.PAINTING_ARRAY.notExists())
         .selectCount(context);
 ----
+
+And here's a generated `SQL`:
+
+[source, SQL]
+----
+SELECT COUNT( * )
+FROM ARTIST t0
+WHERE
+    NOT EXISTS (SELECT t1.PAINTING_ID
+                FROM PAINTING t1
+                WHERE t1.ARTIST_ID = t0.ARTIST_ID
+    )
+----
\ No newline at end of file

Reply via email to