cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Chainable SelectQuery
Date Sat, 15 Nov 2014 10:39:54 GMT

> On Oct 11, 2014, at 4:06 AM, Andrus Adamchik <andrus@objectstyle.org> wrote:
> 
> 1. Instead of drastically redoing good old SelectQuery, we'll create a separate class
called ObjectSelect featuring fluent API. No deprecations in SelectQuery.

> [..]

> Also cases when you need to reset/replace previous settings. So both styles have their
use. 
> 
> 2. Instead of "qualifier" the new query might just use "exp" (in addition to "and" and
"or"). 
> 
> 3. ExpressionFactory.exp(..) and ObjectSelect.exp(..) should allow for both named parameter
binding as well as vararg positional binding.
> 
> 4. Still need to come up with fluent API for orderings and prefetches. Separation from
SelectQuery should simplify this task.
> 
> 5. The last method in a chain doesn't have to be limited to "select" and "selectOne".
It can be query-specific, depending on what operations a given query supports. E.g. we can
have queries with "count(context)", etc. This is something we should explore.
> 
> 6. Corollary to #5, we should explore iterator methods in query chains (need to make
sure that we don't reinvent the wheels invented in Java 8).
> 
> 7. Non-selecting queries should use such API too. E.g. in addition to SQLSelect we might
have SQLOperation with chain terminating with "int update(context)" or "int[] batchUpdate(context)"
or "QueryResponse exec(context)". Same goes for ProcedureQuery.

The new query is checked in. It supports all the options of SelectQuery (including more exotic
ones like generic query of fetching by DbEntity name), and is fully fluent. So you can do
this: 

  List<Artist> artists = 
	ObjectSelect.query(Artist.class)
	.exp(Artist.ARTIST_NAME.eq("me"))
	.orderBy(Artist.DATE_OF_BIRTH.asc(), Artist.ARTIST_NAME.desc())
	.prefetch(Artist.PAINTING_ARRAY.joint())
	.localCache("cg2", "cg1").select(context);

or this (kinda shows why chains are cool) :

  for(Artist a  : ObjectSelect.query(Artist.class).select(context)) {
  	...
  }

or this:

  Artist a = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.eq("me")).selectOne(context);

Also Expression, SQLSelect and SQLTemplate now fully support positional parameters. Items
5,6,7 still need to be explored. 

Enjoy!

Andrus


Mime
View raw message