public class TenantAwareDataSource extends Object implements DataSource
DataSource implementation that switches the currently used datasource based on the
current values of the TenantInfoHolder.
When a Connection is requested from this DataSource, the correct DataSource
for the current tenant will be determined and used.
Heavily influenced and inspired by Spring's AbstractRoutingDataSource.| Modifier and Type | Field and Description |
|---|---|
protected Map<Object,DataSource> |
dataSources |
protected TenantInfoHolder |
tenantInfoHolder |
| Constructor and Description |
|---|
TenantAwareDataSource(TenantInfoHolder tenantInfoHolder) |
| Modifier and Type | Method and Description |
|---|---|
void |
addDataSource(Object key,
DataSource dataSource) |
Connection |
getConnection() |
Connection |
getConnection(String username,
String password) |
protected DataSource |
getCurrentDataSource() |
Map<Object,DataSource> |
getDataSources() |
int |
getLoginTimeout() |
PrintWriter |
getLogWriter() |
Logger |
getParentLogger() |
boolean |
isWrapperFor(Class<?> iface) |
void |
removeDataSource(Object key) |
void |
setDataSources(Map<Object,DataSource> dataSources) |
void |
setLoginTimeout(int seconds) |
void |
setLogWriter(PrintWriter out) |
<T> T |
unwrap(Class<T> iface) |
protected TenantInfoHolder tenantInfoHolder
protected Map<Object,DataSource> dataSources
public TenantAwareDataSource(TenantInfoHolder tenantInfoHolder)
public void addDataSource(Object key, DataSource dataSource)
public void removeDataSource(Object key)
public Connection getConnection() throws SQLException
getConnection in interface DataSourceSQLExceptionpublic Connection getConnection(String username, String password) throws SQLException
getConnection in interface DataSourceSQLExceptionprotected DataSource getCurrentDataSource()
public int getLoginTimeout()
throws SQLException
getLoginTimeout in interface CommonDataSourceSQLExceptionpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface CommonDataSourceSQLFeatureNotSupportedExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic Map<Object,DataSource> getDataSources()
public void setDataSources(Map<Object,DataSource> dataSources)
public PrintWriter getLogWriter() throws SQLException
getLogWriter in interface CommonDataSourceSQLExceptionpublic void setLogWriter(PrintWriter out) throws SQLException
setLogWriter in interface CommonDataSourceSQLExceptionpublic void setLoginTimeout(int seconds)
throws SQLException
setLoginTimeout in interface CommonDataSourceSQLExceptionCopyright © 2016 Alfresco. All rights reserved.