Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* It gets the connection based on different datasources.
*/
public class MultiTenantConnectionProviderImpl extends AbstractDataSourceBasedMultiTenantConnectionProviderImpl
{
Log logger = LogFactory.getLog(getClass());
private static final long serialVersionUID = 14535345L;
@Autowired
private DataSource defaultDataSource;
@Autowired
private DataSourceLookup dataSourceLookup;
/**
* Select datasources in situations where not tenantId is used (e.g. startup processing).
*/
@Override
protected DataSource selectAnyDataSource() {
logger.trace("Select any dataSource: " + defaultDataSource);
return defaultDataSource;
}
/**
* Obtains a DataSource based on tenantId
*/
@Override
protected DataSource selectDataSource(String tenantIdentifier) {
DataSource ds = dataSourceLookup.getDataSource(tenantIdentifier);
logger.trace("Select dataSource from "+ tenantIdentifier+ ": " + ds);
return ds;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.