All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.server.query.QueryFutureList Maven / Gradle / Ivy

There is a newer version: 15.6.0
Show newest version
package io.ebeaninternal.server.query;

import io.ebean.FutureList;
import io.ebean.Query;
import io.ebean.Transaction;

import javax.persistence.PersistenceException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * Default implementation for FutureList.
 */
public class QueryFutureList extends BaseFuture> implements FutureList {

  private final CallableQueryList call;

  public QueryFutureList(CallableQueryList call) {
    super(new FutureTask<>(call));
    this.call = call;
  }

  public FutureTask> getFutureTask() {
    return futureTask;
  }

  public Transaction getTransaction() {
    return call.transaction;
  }

  @Override
  public Query getQuery() {
    return call.query;
  }

  @Override
  public boolean cancel(boolean mayInterruptIfRunning) {
    call.query.cancel();
    return super.cancel(mayInterruptIfRunning);
  }

  @Override
  public List getUnchecked() {
    try {
      return get();

    } catch (InterruptedException e) {
      // restore the interrupted status (so client can check for that)
      Thread.currentThread().interrupt();
      throw new PersistenceException(e);

    } catch (ExecutionException e) {
      throw new PersistenceException(e);
    }
  }

  @Override
  public List getUnchecked(long timeout, TimeUnit unit) throws TimeoutException {
    try {
      return get(timeout, unit);

    } catch (InterruptedException e) {
      // restore the interrupted status (so client can check for that)
      Thread.currentThread().interrupt();
      throw new PersistenceException(e);

    } catch (ExecutionException e) {
      throw new PersistenceException(e);
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy