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 DataSource
SQLException
public Connection getConnection(String username, String password) throws SQLException
getConnection
in interface DataSource
SQLException
protected DataSource getCurrentDataSource()
public int getLoginTimeout() throws SQLException
getLoginTimeout
in interface CommonDataSource
SQLException
public Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger
in interface CommonDataSource
SQLFeatureNotSupportedException
public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
SQLException
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
SQLException
public Map<Object,DataSource> getDataSources()
public void setDataSources(Map<Object,DataSource> dataSources)
public PrintWriter getLogWriter() throws SQLException
getLogWriter
in interface CommonDataSource
SQLException
public void setLogWriter(PrintWriter out) throws SQLException
setLogWriter
in interface CommonDataSource
SQLException
public void setLoginTimeout(int seconds) throws SQLException
setLoginTimeout
in interface CommonDataSource
SQLException
Copyright © 2016 Alfresco. All rights reserved.