Last active
September 30, 2017 03:30
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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