I'm implementing a multy-tenant application with Play Framework 2.0. For that I added to eban configuration two adapters:
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 are getting the tenant id from the session. The problems are with Ebean, it uses Futures to make some queries. The TenantManager gets the tenant_id from the session and the session is stored in a ThreadLocal. The result is:
java.lang.RuntimeException: There is no HTTP Context available from here.
I have been researching and I have considered ExecutorService and InheritableThreadLocal (as it's suggested here propagation) but I think that Play don't let me replace Ebean's backgroundExecutor and InheritableThreadLocal don't work.
Any suggestion?
Thanks,