I am implementing a multi-user application with Play Framework 2.0. To do this, I added two adapters to the eban configuration:
public class TenantBeanQueryAdapter implements BeanQueryAdapter {
...
@Override
public void preQuery(BeanQueryRequest<?> beanQueryRequest) {
Query query = beanQueryRequest.getQuery();
query.where().eq(this.tenantManager.getFieldName(),this.tenantManager.getValue().toString());
}
}
public class TenantBeanPersistController implements BeanPersistController{
...
@Override
public boolean preInsert(BeanPersistRequest<?> request) {
try {
Field field = request.getBean().getClass().getDeclaredField(tenantManager.getFieldName());
field.setAccessible(true);
field.set(request.getBean(),tenantManager.getValue());
return true;
} catch (Exception e) {
return false;
}
}
}
These adapters get the tenant ID from the session. Problems with Ebean, it uses Futures to execute some queries. TenantManager gets tenant_id from the session, and the session is stored in ThreadLocal. Result:
java.lang.RuntimeException: There is no HTTP Context available from here.
I do research and I reviewed ExecutorService and InheritableThreadLocal (as the distribution suggested here ), but I think that Play does not allow me to replace Ebean backgroundExecutor and InheritableThreadLocal do not work.
Any suggestion?
Thanks,