public interface DataSourceHolder
| 限定符和类型 | 字段和说明 |
|---|---|
static Map<String,Object> |
caches
运行环境未启动之前注册的数据源参数 缓存
|
static Map<Object,DataSourceHolder> |
instances
驱动类型 与 holder对应关系
DataRuntime, DatabaseType, jdbc协议(jdbc:mysql), DataSource.class, JdbcTemplate.class, 连接池class, Driver.class
最后检测协议 和 adapter(因为不一定唯一,如neo4j会实现两种adapter对应两个holder)
|
static org.slf4j.Logger |
log |
static Map<String,Map<String,Object>> |
params
注册数据源的参数
|
static Map<String,DatabaseType> |
types
数据源对应的数据库类型
|
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
check(String key,
boolean override)
检测是否可注册(没有重复名称或呆以覆盖)
如果已存在但可覆盖 需要把原来的注销掉
|
static boolean |
contains(String datasource)
数据源列表中是否已包含指定数据源
|
static List<String> |
copy() |
static List<String> |
copy(DataRuntime runtime) |
static List<String> |
copy(String datasource)
复制数据源
|
default DataSource |
create(String key,
Connection connection) |
DataSource |
create(String key,
Connection connection,
boolean override) |
String |
create(String key,
DatabaseType type,
String url,
String user,
String password)
注册数据源(生产环境不要调用这个方法,这里只设置几个必需参数用来测试)
|
default String |
create(String key,
Map<String,Object> param) |
default String |
create(String key,
Map<String,Object> param,
boolean override) |
default DataRuntime |
create(String key,
Object datasource) |
default DataRuntime |
create(String key,
Object datasource,
boolean override) |
default DataRuntime |
create(String key,
Object datasource,
DatabaseType type) |
default DataRuntime |
create(String key,
Object datasource,
DatabaseType type,
boolean override) |
default DataRuntime |
create(String key,
Object datasource,
String database,
DatabaseType type,
DriverAdapter adapter,
boolean override) |
String |
create(String key,
String prefix)
根据配置文件创建数据源
|
default String |
create(String key,
String pool,
String driver,
String url,
String user,
String password)
注册数据源(生产环境不要调用这个方法,这里只设置几个必需参数用来测试)
|
static boolean |
destroy(String datasource) |
static DatabaseType |
dialect(String datasource)
数据源对应的数据库类型
|
static void |
dialect(String datasource,
DatabaseType type) |
static boolean |
hit(DataRuntime runtime)
鸡数据源是否可用 如果不可用 会抛出异常
|
static boolean |
hit(String datasource)
鸡数据源是否可用 如果不可用 会抛出异常
|
default String |
inject(String key,
Map params,
boolean over)
根据params创建数据源, 同时注入到spring上下文
|
String |
inject(String key,
String prefix,
Map<String,Object> params,
boolean override)
根据params与配置文件创建数据源, 同时注入到spring上下文
|
static DataSourceHolder |
instance(Class clazz) |
static DataSourceHolder |
instance(DatabaseType type) |
static DataSourceHolder |
instance(DataRuntime runtime) |
static DataSourceHolder |
instance(Object chk) |
static DataSourceHolder |
instance(String check)
根据数据源定义holder
|
static List<String> |
list()
已注册成功的所有数据源
|
static String |
reg(String key,
DatabaseType type,
String url,
String user,
String password)
注册数据源(生产环境不要调用这个方法,这里只设置几个必需参数用来测试)
|
static String |
reg(String key,
Map<String,Object> param) |
static String |
reg(String key,
Map<String,Object> param,
boolean override) |
static DataRuntime |
reg(String key,
Object datasource) |
static DataRuntime |
reg(String key,
Object datasource,
boolean override) |
static DataRuntime |
reg(String key,
Object datasource,
DatabaseType type) |
static DataRuntime |
reg(String key,
Object datasource,
DatabaseType type,
boolean override) |
static DataRuntime |
reg(String key,
Object datasource,
String database) |
static DataRuntime |
reg(String key,
Object datasource,
String database,
boolean override) |
static DataRuntime |
reg(String key,
Object datasource,
String database,
DatabaseType type) |
static DataRuntime |
reg(String key,
Object datasource,
String database,
DatabaseType type,
DriverAdapter adapter,
boolean override) |
static String |
reg(String key,
String pool,
String driver,
String url,
String user,
String password)
注册数据源(生产环境不要调用这个方法,这里只设置几个必需参数用来测试)
|
static void |
register(Object check,
DataSourceHolder holder)
驱动类型与holder对应关系
由holder主动上报
|
default String |
regTransactionManager(String key,
DataSource datasource) |
String |
regTransactionManager(String key,
DataSource datasource,
boolean primary) |
default String |
regTransactionManager(String key,
String datasource) |
default String |
regTransactionManager(String key,
String datasource,
boolean primary) |
default DataRuntime |
runtime(String key,
Object datasource,
boolean override) |
DataRuntime |
runtime(String key,
Object datasource,
String database,
DatabaseType type,
DriverAdapter adapter,
boolean override) |
String |
runtime(String key,
String datasource,
boolean override)
添加数据源,同时添加事务与service
|
default boolean |
validate()
验证当前数据源可用性 如果不可用抛出异常
|
boolean |
validate(DataRuntime runtime)
验证数据源可用性 如果不可用抛出异常
|
default boolean |
validate(String datasource)
验证数据源可用性 如果不可用抛出异常
|
static boolean |
validity(DataRuntime runtime)
鸡数据源是否可用
|
static boolean |
validity(String datasource)
鸡数据源是否可用
|
default <T> T |
value(Map map,
String keys,
Class<T> clazz,
T def) |
default <T> T |
value(String prefix,
String keys,
Class<T> clazz,
T def) |
static final org.slf4j.Logger log
static final Map<Object,DataSourceHolder> instances
static final Map<String,DatabaseType> types
static void register(Object check, DataSourceHolder holder)
check - 驱动类型holder - holderstatic DataSourceHolder instance(DataRuntime runtime)
static DataSourceHolder instance(DatabaseType type)
static DataSourceHolder instance(Class clazz)
static DataSourceHolder instance(String check)
check - 数据源|jdbc协议|driver.class|urlstatic DataSourceHolder instance(Object chk)
static String reg(String key, String pool, String driver, String url, String user, String password) throws Exception
key - 切换数据源依据 默认key=datasourcepool - 连接池类型 如 com.zaxxer.hikari.HikariDataSourcedriver - 驱动类 如 com.mysql.cj.jdbc.Driverurl - urluser - 用户名password - 密码Exception - 异常 Exceptionstatic String reg(String key, DatabaseType type, String url, String user, String password) throws Exception
key - 切换数据源依据 默认key=datasourceurl - urltype - 数据库类型user - 用户名password - 密码Exception - 异常 Exceptionstatic String reg(String key, Map<String,Object> param, boolean override) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource, String database, DatabaseType type, DriverAdapter adapter, boolean override) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource, String database, boolean override) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource, boolean override) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource, String database) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource, DatabaseType type, boolean override) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource, String database, DatabaseType type) throws Exception
Exceptionstatic DataRuntime reg(String key, Object datasource, DatabaseType type) throws Exception
Exceptionstatic void check(String key, boolean override) throws Exception
key - 数据源keyoverride - 是否可覆盖Exception - 如果存在 并 不可覆盖会抛出异常static boolean contains(String datasource)
datasource - 数据源名称static DatabaseType dialect(String datasource)
datasource - 数据源名称static void dialect(String datasource, DatabaseType type)
static boolean validity(String datasource)
datasource - 数据源static boolean validity(DataRuntime runtime)
runtime - 运行环境主要包含驱动适配器 数据源或客户端static boolean hit(DataRuntime runtime) throws Exception
runtime - 运行环境主要包含驱动适配器 数据源或客户端Exception - Exceptionstatic boolean hit(String datasource) throws Exception
datasource - 数据源Exception - Exceptiondefault String create(String key, String pool, String driver, String url, String user, String password) throws Exception
key - 切换数据源依据 默认key=datasourcepool - 连接池类型 如 com.zaxxer.hikari.HikariDataSourcedriver - 驱动类 如 com.mysql.cj.jdbc.Driverurl - urluser - 用户名password - 密码Exception - 异常 ExceptionString create(String key, DatabaseType type, String url, String user, String password) throws Exception
key - 切换数据源依据 默认key=datasourceurl - urltype - 数据库类型user - 用户名password - 密码Exception - 异常 ExceptionString create(String key, String prefix)
key - 数据源keyprefix - 配置文件前缀DataSource create(String key, Connection connection, boolean override)
default String create(String key, Map<String,Object> param, boolean override) throws Exception
Exceptiondefault DataRuntime create(String key, Object datasource, String database, DatabaseType type, DriverAdapter adapter, boolean override) throws Exception
Exceptiondefault DataRuntime create(String key, Object datasource) throws Exception
Exceptiondefault DataRuntime create(String key, Object datasource, boolean override) throws Exception
Exceptiondefault DataRuntime create(String key, Object datasource, DatabaseType type, boolean override) throws Exception
Exceptiondefault DataRuntime create(String key, Object datasource, DatabaseType type) throws Exception
Exceptiondefault DataSource create(String key, Connection connection)
default boolean validate(String datasource) throws Exception
datasource - 数据源Exception - 不可用时抛出异常default boolean validate()
throws Exception
Exception - 不可用时抛出异常boolean validate(DataRuntime runtime) throws Exception
runtime - 数据源Exception - 不可用时抛出异常static List<String> copy(DataRuntime runtime)
default String regTransactionManager(String key, DataSource datasource)
String regTransactionManager(String key, DataSource datasource, boolean primary)
default String regTransactionManager(String key, String datasource, boolean primary)
String runtime(String key, String datasource, boolean override) throws Exception
key - 数据源名称datasource - 数据源bean idoverride - 是否覆盖同名数据源Exception - 异常 ExceptionDataRuntime runtime(String key, Object datasource, String database, DatabaseType type, DriverAdapter adapter, boolean override) throws Exception
Exceptiondefault DataRuntime runtime(String key, Object datasource, boolean override) throws Exception
Exceptiondefault String inject(String key, Map params, boolean over) throws Exception
key - 调用或注销数据源时需要用到 如ServiceProxy.service(key)params - 帐号密码等参数Exception - ExceptionString inject(String key, String prefix, Map<String,Object> params, boolean override) throws Exception
key - 调用或注销数据源时需要用到 如ServiceProxy.service(“sso”)prefix - 配置文件前缀 如 anyline.datasource.ssoparams - map格式参数override - 是否覆盖同名数据源Exception - ExceptionCopyright © 2024. All rights reserved.