Search in sources :

Example 1 with MultiTenant

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;
}
Also used : MultiTenancyImplementation(com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementation) MultiTenancyStrategy(org.hibernate.MultiTenancyStrategy) MultiTenant(com.manydesigns.portofino.database.multitenancy.MultiTenant) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Aggregations

MultiTenant (com.manydesigns.portofino.database.multitenancy.MultiTenant)1 MultiTenancyImplementation (com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementation)1 IOException (java.io.IOException)1 JAXBException (javax.xml.bind.JAXBException)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 MultiTenancyStrategy (org.hibernate.MultiTenancyStrategy)1