Skip to content

Instantly share code, notes, and snippets.

@rowanl
Last active January 17, 2018 22:04
Show Gist options
  • Save rowanl/fdf9c378f33f138207497b064b9bd3bd to your computer and use it in GitHub Desktop.
Save rowanl/fdf9c378f33f138207497b064b9bd3bd to your computer and use it in GitHub Desktop.
playframework-kubernetes - Asynchronous, non-blocking implementation of find all query using Ebean
private final EbeanServer ebeanServer;
private final DatabaseExecutionContext executionContext;
@Inject
public CharityRepository(EbeanConfig ebeanConfig, DatabaseExecutionContext executionContext,
@SuppressWarnings("unused")
EbeanDynamicEvolutions ebeanDynamicEvolutions /* Required for Ebean/DI bug */) {
this.ebeanServer = getServer(ebeanConfig.defaultServer());
this.executionContext = executionContext;
}
private <T> CompletionStage<T> wrapContext(Supplier<T> toRun) {
return supplyAsync(toRun, executionContext);
}
public CompletionStage<List<Charity>> findList() {
return wrapContext(() -> ebeanServer.find(Charity.class).findList());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment