com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementation Maven / Gradle / Ivy
package com.manydesigns.portofino.persistence.hibernate.multitenancy;
import org.hibernate.MultiTenancyStrategy;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.spi.*;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* This class has two purposes:
*
* - act as an AbstractMultiTenantConnectionProvider for Hibernate, selecting a different connection provider
* for each tenant;
* - act as a strategy for Portofino to compute the current tenant.
*
* Given that the two purposes have overlapping needs, and we can't use inner classes (because this will be instantiated
* reflectively both by Portofino and by Hibernate), we've settled on a single class even if it's not properly designed
* OO.
* Implementors should keep in mind that two instances will be created to perform the two different tasks,
* and they will not share state.
*/
public abstract class MultiTenancyImplementation extends AbstractMultiTenantConnectionProvider
implements ServiceRegistryAwareService, Configurable, Stoppable {
public static final String CONNECTION_PROVIDER_CLASS = "portofino.persistence.hibernate.multitenancy.connectionProviderClass";
private static final Logger logger = LoggerFactory.getLogger(MultiTenancyImplementation.class);
private Class connectionProviderClass;
private ServiceRegistryImplementor serviceRegistry;
private Map configurationValues;
private final ConcurrentMap
© 2015 - 2024 Weber Informatics LLC | Privacy Policy