[hibernate-dev] HSEARCH-615 Support time-constrained queries returning the first available results
Sanne Grinovero
sanne.grinovero at gmail.com
Sat Nov 6 11:50:51 EDT 2010
there's a similar case already:
query.getResultSize() //relates to the last returned list
and so looking at the complexity of proposed alternatives, I'm not
strongly against your original suggestion to provide
a method on the query object.
Alternatively we might consider there might be enough good reasons to
create a new object to
collect information about the executed query.
query.getLastQueryExecutionMetadata().
.hasPartialResults()
.executionTime() //possibly interesting
.getResultSize()
I would be fine too in considering the Query object the right place
for this info (as it currently is) documenting that these methods
refer to the last execution.
Sanne
2010/11/6 Emmanuel Bernard <emmanuel at hibernate.org>:
> The other option I've been thinking about is to get limitFetchTime() / limitTimeAllowedTo() to return a Future object or some equivalent notion say a BooleanHolder.
>
> BooleanHolder hasPartialResults = query.limitTimeAllowedTo(500, MILLISECONDS, hasPartialResults);
> query.list();
> if ( hasPartialResults.get() ) {
> //do stuffs
> }
>
> But:
> - that's a bit weird to get a future in this sync API
> - it breaks the method chaining used in the rest of the API
>
> Another possibility is to optionally let people pass the boolean holder that is populated after the call
>
> BooleanHolder hasPartialResults = new BooleanHolder();
> List results = query.limitTimeAllowedTo(500, MILLISECONDS, hasPartialResults).list();
> if ( hasPartialResults.get() ) {
> //do stuffs
> }
>
> WDYT?
>
> On 6 nov. 2010, at 15:25, Emmanuel Bernard wrote:
>
>> You'll need to extend:
>> - List
>> - Iterator
>> - ScrollableResults
>>
>> Not sure that's a good thing.
>>
>> You can reuse the query as long as you check hasPartialResults() before calling list/iterate/scroll query again.
>>
>> PS: we should add tests about query reusability, I'm not sure it works as expected today.
>>
>>
>> On 6 nov. 2010, at 12:31, Sanne Grinovero wrote:
>>
>>> Hello,
>>> about naming I have no better ideas:
>>> .limitFetchTime() //slightly different, not very happy about it either
>>>
>>> about API, does it really make sense to have hasPartialResults() as a
>>> method of the Query?
>>> It should be a List property I think - I have no strong opinions about
>>> this as I don't like having to extend the List implementation.
>>>
>>> But really Query is something I might want to reuse - unlikely but I'd
>>> expect that to work fine.
>>> So what about:
>>>
>>> SomeNewList results = query.list(500, TimeUnit.MILLISECONDS)
>>> or a batter named method.
>>>
>>> So:
>>>
>>> if ( results.hasPartialResults() ) {
>>> displayWarningToUser();
>>> }
>>>
>>> This is one of those cases in which I miss the option of having a
>>> couple of values from a function.
>>>
>>> Sanne
>>>
>>> 2010/11/5 Emmanuel Bernard <emmanuel at hibernate.org>:
>>>> If you can find better name for the API, please advise. I am not happy with the current version
>>>>
>>>> Query luceneQuery = ...;
>>>> FullTextQuery query = fullTextSession.createFullTextQuery(luceneQuery, User.class);
>>>>
>>>> //define the timeout in seconds
>>>> query.limitFetchingTime(500, TimeUnit.MILLISECONDS);
>>>> List results = query.list();
>>>>
>>>> if ( query.hasPartialResults() ) {
>>>> displayWarningToUser();
>>>> }
>>>>
>>>> Emmanuel
>>>> _______________________________________________
>>>> hibernate-dev mailing list
>>>> hibernate-dev at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>>
>>
>>
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>
>
More information about the hibernate-dev
mailing list