Hi Savva,

This looks pretty cool.  I could also see having:

Select.select(ObjectContext context, int size);

Then selectFirst would just call it with a size = 1.  This would give you
an easy way to support fetching the top 5 (or 10 or any other number)
newest/hottest/etc news articles (to use your example).  Heck, we could
even have selectOne call it with a size = 2 and if more than 1 result comes
back, throw the exception.

Also, maybe I'm misreading the JavaDocs, but for Select.selectOne, it says:
Essentially the inversion of "ObjectContext.selectOne(Select)".

I don't think inversion is the correct word, since it means opposite, and
they aren't opposites.  A couple others use the word inversion, too, when I
don't think that is what is meant.

Thoughts?

Thanks,

mrg


On Tue, Apr 7, 2015 at 7:13 AM, Savva Kolbachev <s.kolbac...@gmail.com>
wrote:

> 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.
>

Reply via email to