Bug 144 : ENHANCEMENT: Add support for cancelling a Query .... query.cancel()
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.1.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
19/08/2009
Updated 
19/08/2009
Type 
Bug
 
Attachments 
No attachments

Add cancel() support to the Query and SqlQuery.

There is now a cancel() method on these query objects but possibly more often you will use the "future" queries that return a future object - and call query on that.

 
Rob 19 Aug 12:49
Example

An example executing a query using a background thread... and cancelling it if it didn't finish after 3 seconds.

NB: the future.cancel(timeout) can also be used.

Query<Order> query = Ebean.find(Order.class);

// execute the query using a background thread and 
// return immediately with a FutureList object
FutureList<Order> futureList = query.findFutureList();

// do something else ... but we will just sleep
Thread.sleep(3000);
System.out.println("end of sleep");
		
if (!futureList.isDone()){
    // cancel the query
    futureList.cancel(true);
}

Rob 19 Aug 21:49
Fixed in HEAD

This code to support query.cancel() is now in head.

woResponse

Upload a file