users@jpa-spec.java.net

[jpa-spec users] Re: JPA_SPEC-99: Add ability to stream the result of a query execution

From: Guillermo González de Agüero <z06.guillermo_at_gmail.com>
Date: Fri, 5 May 2017 07:57:44 +0200

Hi,

Linda: in Hibernate it acts as a ScrollableResult that fetches data
"on-demand". I imagine, in practice, every implementation will use
something like that to provide performance benefits. This is a very
valuable addition.

Lukas: I think that JavaDoc could add an example of the possible things a
vendor may do, like "persistence provider may choose to override this
method to provide additional capabilities, *like cursor-like fetching*".
That would make the purpose clearer.


Regards,

Guillermo González de Agüero.

On Thu, May 4, 2017 at 11:35 PM, Linda DeMichiel <linda.demichiel_at_oracle.com
> wrote:

> Hi,
>
> If the value is mostly in the provider-specific add-ons, then I
> think it would be better to wait and standardize in a later
> release.
>
> What did you have in mind here?
>
> -Linda
>
>
> On 5/4/17, 1:01 PM, Lukas Jungmann wrote:
>
>> Hi,
>>
>> another change I'd like to propose is an addition of
>> getResultStream:Stream method to javax.persistence.Query/TypedQuery
>> interfaces with following javadoc and provided with default
>> implementation:
>>
>> javax.persistence.Query:
>>
>> / /**//
>> // * Execute a SELECT query and return the query results//
>> // * as an untyped <code>java.util.Stream</code>.//
>> // * By default this method delegates to
>> <code>getResultList().stream()</code>,//
>> // * however persistence provider may choose to override this method//
>> // * to provide additional capabilities.//
>> // *//
>> // * @return a stream of the results//
>> // * @throws IllegalStateException if called for a Java//
>> // * Persistence query language UPDATE or DELETE statement//
>> // * @throws QueryTimeoutException if the query execution exceeds//
>> // * the query timeout value set and only the statement is//
>> // * rolled back//
>> // * @throws TransactionRequiredException if a lock mode other than//
>> // * <code>NONE</code> has been set and there is no
>> transaction//
>> // * or the persistence context has not been joined to the
>> transaction//
>> // * @throws PessimisticLockException if pessimistic locking//
>> // * fails and the transaction is rolled back//
>> // * @throws LockTimeoutException if pessimistic locking//
>> // * fails and only the statement is rolled back//
>> // * @throws PersistenceException if the query execution exceeds //
>> // * the query timeout value set and the transaction //
>> // * is rolled back //
>> // * @see Stream//
>> // * @see #getResultList()//
>> // * @since 2.2//
>> // *///
>> // default Stream getResultStream() {//
>> // return getResultList().stream();//
>> // }/
>>
>> similarly to javax.persistence.TypedQuery:
>>
>> / /**//
>> // * Execute a SELECT query and return the query results//
>> // * as a typed <code>java.util.Stream</code>.//
>> // * By default this method delegates to
>> <code>getResultList().stream()</code>,//
>> // * however persistence provider may choose to override this method//
>> // * to provide additional capabilities.//
>> // *//
>> // * @return a stream of the results//
>> // * @throws IllegalStateException if called for a Java//
>> // * Persistence query language UPDATE or DELETE statement//
>> // * @throws QueryTimeoutException if the query execution exceeds//
>> // * the query timeout value set and only the statement is//
>> // * rolled back//
>> // * @throws TransactionRequiredException if a lock mode other than//
>> // * <code>NONE</code> has been set and there is no
>> transaction//
>> // * or the persistence context has not been joined to the
>> transaction//
>> // * @throws PessimisticLockException if pessimistic locking//
>> // * fails and the transaction is rolled back//
>> // * @throws LockTimeoutException if pessimistic locking//
>> // * fails and only the statement is rolled back//
>> // * @throws PersistenceException if the query execution exceeds //
>> // * the query timeout value set and the transaction //
>> // * is rolled back //
>> // * @see Stream//
>> // * @see #getResultList()//
>> // * @since 2.2//
>> // *///
>> // default Stream<X> getResultStream() {//
>> // return getResultList().stream();//
>> // }/
>>
>> Do you think this is OK or does it give providers to big freedom?
>>
>> Thank you,
>> --lukas
>>
>>