Module io.ebean.api
Package io.ebean

Interface FutureMap<K,T>

All Superinterfaces:
Future<Map<K,T>>

public interface FutureMap<K,T> extends Future<Map<K,T>>
FutureMap represents the result of a background query execution that will return a map of entities.

It extends the java.util.concurrent.Future with the ability to cancel the query, check if it is finished and get the resulting list waiting for the query to finish (ie. the standard features of java.util.concurrent.Future).

A simple example:



  // create a query to find all orders
 Query<Long,Order> query = DB.find(Order.class)
 .setMapKey("id");

  // execute the query in a background thread
  // immediately returning the futureMap
 FutureMap<Long,Order> futureMap = query.findFutureMap();

  // do something else ...

 if (!futureMap.isDone()){
 	// we can cancel the query execution. This will cancel
 // the underlying query if that is supported by the JDBC
 // driver and database
 	futureMap.cancel(true);
 }

 if (!futureMap.isCancelled()){
 	// wait for the query to finish and return the map
 	Map<Long,Order> map = futureMap.get();
 	...
 }

 
  • Method Details

    • getQuery

      Query<T> getQuery()
      Return the query that is being executed by a background thread.
    • getUnchecked

      Map<K,T> getUnchecked()
      Same as Future.get() but wraps InterruptedException and ExecutionException in the unchecked PersistenceException.
      Returns:
      The query list result
      Throws:
      jakarta.persistence.PersistenceException - when a InterruptedException or ExecutionException occurs.
    • getUnchecked

      Map<K,T> getUnchecked(long timeout, TimeUnit unit) throws TimeoutException
      Same as Future.get(long, TimeUnit) but wraps InterruptedException and ExecutionException in the unchecked PersistenceException.
      Returns:
      The query list result
      Throws:
      TimeoutException - if the wait timed out
      jakarta.persistence.PersistenceException - if a InterruptedException or ExecutionException occurs.