cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Savva Kolbachev <s.kolbac...@gmail.com>
Subject New features in Select API
Date Tue, 07 Apr 2015 11:13:51 GMT
Hi All! It's a pleasure for me to introduce to you some new features in
Select API. I'd be thrilled if you could have a look and give us your
feedback.

1. I've implemented the following methods for Select queries:

   -

   select(ObjectContext);
   -

   selectOne(ObjectContext);
   -

   iterate(ObjectContext, ResultIteratorCallback);
   -

   iterator(ObjectContext);


So, now you can use these methods directly from your queries based on the
provided context, for example:

// Returns all Artists directly to artistList

List<Artist> artistList = SelectQuery.query(Artist.class).select(context);

2. Also I’ve implemented selectFirst() method in both Select and
ObjectContext.

This method selects a single object regardless of how many objects are
matched by query. This makes 'selectFirst' different from ‘selectOne’,
which would throw exception in this situation. ‘selectFirst’ is useful e.g.
when the query is ordered and we only want to see the first object (e.g.
"most recent news article"):

SelectQuery<Article> query = new SelectQuery(Article.class);

// Add ordering

query.addOrdering(new Ordering(Article.PUBLISHED.getName()));

// Select most recent news article

Article article = query.selectFirst(context);

Selecting the first object via "Select.selectFirst(ObjectContext)" is more
comprehensible than selecting via "ObjectContext.selectFirst(Select)",
because implementations of "Select" usually set fetch size limit to one.

3. I’ve added ResultBatchIterator which allows iterating through results by
micro-batches. For example:


try(ResultBatchIterator<Artist> it =
SelectQuery.query(Artist.class).batchIterator(context, 5)) {

for (List<Artist> artistList : it) {

 // something to do

}

}

4. As you can see above ResultBatchIterator implements java.io.Closeable.
ResultIterator now also implements it. So you are able to use
try-with-resources for Java 1.7 and higher.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message