public abstract class AbstractRoutingDataSource extends Object implements RoutingDataSource, DataSource, Closeable
| Modifier and Type | Field and Description |
|---|---|
protected DataSource |
defaultTargetDataSource |
protected boolean |
strict
严格模式(启用后在未匹配到指定数据源时候会抛出异常,不启用则使用默认数据源.)
|
protected Map<String,DataSource> |
targetDataSources |
| Constructor and Description |
|---|
AbstractRoutingDataSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected void |
closeDataSource(DataSource ds)
尝试关闭数据源
|
abstract String |
determineCurrentKey()
确定当前数据源键
|
DataSource |
determineCurrentTarget()
确定当前目标数据源
|
Connection |
getConnection() |
Connection |
getConnection(String username,
String password) |
int |
getLoginTimeout() |
PrintWriter |
getLogWriter() |
Logger |
getParentLogger() |
boolean |
isWrapperFor(Class<?> iface) |
void |
setDefaultTargetDataSource(DataSource defaultTargetDataSource)
设置默认目标数据源
|
void |
setLoginTimeout(int seconds) |
void |
setLogWriter(PrintWriter out) |
void |
setStrict(boolean strict)
设置严格模式
|
void |
setTargetDataSources(Map<String,DataSource> targetDataSources)
设置目标数据源集合(替换掉旧的)
|
<T> T |
unwrap(Class<T> iface) |
protected DataSource defaultTargetDataSource
protected Map<String,DataSource> targetDataSources
protected boolean strict
public void setTargetDataSources(Map<String,DataSource> targetDataSources)
public void setDefaultTargetDataSource(DataSource defaultTargetDataSource)
public void setStrict(boolean strict)
public abstract String determineCurrentKey()
public DataSource determineCurrentTarget()
determineCurrentTarget in interface RoutingDataSourcepublic Connection getConnection() throws SQLException
getConnection in interface DataSourceSQLExceptionpublic Connection getConnection(String username, String password) throws SQLException
getConnection in interface DataSourceSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic 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 CommonDataSourceSQLExceptionpublic int getLoginTimeout()
throws SQLException
getLoginTimeout in interface CommonDataSourceSQLExceptionpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface CommonDataSourceSQLFeatureNotSupportedExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprotected void closeDataSource(DataSource ds) throws IOException
IOExceptionCopyright © 2025. All rights reserved.