Using a AbstractMultiTenantConnectionProvider give me some problems. In the case i had 1000 tenants and i want to add more without restarting the webserver, how can i use selectConnectionProvider easily?
@Override
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
if( "xml1".equals(tenantIdentifier) )
return xml1;
if( "xml2".equals(tenantIdentifier) )
return xml2;
return null;
}
As you can see in this example tenants are linked statically. How could i solve this issue. Thanks for any hint or solution! Cheers, t.
Its a follow-up question from here Implement an AbstractMultiTenantConnectionProvider
Make it a registry (as in the pattern) with which you register/deregister tenants as needed (“as needed” is defined by your app/environment). Structurally then the MultiTenantConnectionProvider internally is a Map. You can access the MultiTenantConnectionProvider from the Hibernate SessionFactory using:
Then you would just need to decide how you want to persist the tenants between starts/stops (write to file, etc). Personally I’d persist immediately upon registerTenant/deregisterTenant calls. Alternately you could wait until shutdown (have YourMultiTenantConnectionProviderImpl implement Stoppable), but you would potentially miss writing some out in cases of JVM crashes.