use of com.manydesigns.portofino.database.multitenancy.MultiTenant in project Portofino by ManyDesigns.
the class Persistence method getMultiTenancyImplementation.
protected MultiTenancyImplementation getMultiTenancyImplementation(Database database) {
Optional<MultiTenant> multiTenant = database.getJavaAnnotation(MultiTenant.class);
if (multiTenant.isPresent()) {
Class<? extends MultiTenancyImplementation> implClass = multiTenant.get().strategy();
// TODO injection?
if (!MultiTenancyImplementation.class.isAssignableFrom(implClass)) {
throw new ClassCastException(implClass + " does not extend " + MultiTenancyImplementation.class);
}
try {
MultiTenancyImplementation implementation = multiTenancyImplementationFactory.make(implClass);
MultiTenancyStrategy strategy = implementation.getStrategy();
if (strategy.requiresMultiTenantConnectionProvider()) {
return implementation;
}
} catch (Exception e) {
throw new RuntimeException("Could not instantiate multi tenancy implementation " + implClass + " for " + database, e);
}
}
return null;
}
Aggregations