类 SohelpDynamicDatasource
java.lang.Object
net.sohelp.boot.admin.core.db.datasource.SohelpDynamicDatasource
动态数据源进行封装 ,集成MagicApi动态数据源
- 从以下版本开始:
- 2024/3/30 11:44
- 作者:
- AaronFung
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明void关闭数据源boolean根据数据源名称判断数据源是否存在获取默认数据库名字getDatabaseName(String key) 根据数据源获取数据库名称获取默认数据源类型getDatabaseType(String key) 根据数据源获取数据库类型getDatasource(String key) 根据数据源Key获取数据源org.springframework.jdbc.core.JdbcTemplategetJdbcTemplate(String key) 根据数据源获取JdbcTemplate接口org.mybatis.spring.SqlSessionTemplategetSessionTemplate(String key) 根据数据源K获取SqlSessionTemplate接口org.apache.ibatis.session.SqlSessionFactorygetSqlSessionFactory(DataSource datasource) 根据Datasource初始化SqlSessionFactorygetTableComment(String key) 根据数据源获取表备注说明getTableField(String key) 获取表字段信息getTableField(String key, String tableName) 获取表结构信息getTypeByDbName(String dbName) 根据数据库名字获取数据库类型list()获取已启动数据源列表voidrefresh()初始化数据源voidreloadTable(String datasource, String tableName) 根据数据源和表名重新加载表结构voidremoveTableCache(String key) 根据数据源删除表缓存void启动数据源
-
构造器详细资料
-
SohelpDynamicDatasource
public SohelpDynamicDatasource()
-
-
方法详细资料
-
removeTableCache
@Comment("\u6839\u636e\u6570\u636e\u6e90\u5220\u9664\u8868\u7f13\u5b58") public void removeTableCache(String key) throws SQLException 根据数据源删除表缓存- 参数:
key- 数据源标识符- 抛出:
SQLException- 当操作数据库出现异常时抛出
-
exist
@Comment("\u6839\u636e\u6570\u636e\u6e90\u540d\u79f0\u5224\u65ad\u6570\u636e\u6e90\u662f\u5426\u5b58\u5728") public boolean exist(String key) 根据数据源名称判断数据源是否存在- 参数:
key- 数据源Key- 返回:
- true表示存在,false表示不存在
-
getDatabaseName
@Comment("\u6839\u636e\u6570\u636e\u6e90\u83b7\u53d6\u6570\u636e\u5e93\u540d\u79f0") public String getDatabaseName(String key) throws SQLException 根据数据源获取数据库名称- 参数:
key- 数据源Key- 返回:
- 数据库名称
- 抛出:
SQLException- 当指定的数据源不存在时抛出
-
getTableComment
@Comment("\u6839\u636e\u6570\u636e\u6e90\u83b7\u53d6\u8868\u5907\u6ce8\u8bf4\u660e") public Map<String,String> getTableComment(String key) throws SQLException 根据数据源获取表备注说明- 参数:
key- 数据源标识符- 返回:
- 包含表名与对应备注的映射关系
- 抛出:
SQLException- 当查询数据库失败或数据源不存在时抛出
-
getTableField
@Comment("\u83b7\u53d6\u8868\u7ed3\u6784\u4fe1\u606f") public Map<String,Map<String, getTableFieldObject>> (String key, String tableName) throws SQLException 获取表结构信息- 参数:
key- 数据源标识符tableName- 表名- 返回:
- 字段名及其详细属性组成的映射
- 抛出:
SQLException- 当查询数据库失败或数据源不存在时抛出
-
getTableField
@Comment("\u83b7\u53d6\u8868\u5b57\u6bb5\u4fe1\u606f") public Map<String,Map<String, getTableFieldMap<String, Object>>> (String key) throws SQLException 获取表字段信息- 参数:
key- 数据源标识符- 返回:
- 每张表对应的字段信息集合
- 抛出:
SQLException- 当查询数据库失败或数据源不存在时抛出
-
getDatabaseType
@Comment("\u6839\u636e\u6570\u636e\u6e90\u83b7\u53d6\u6570\u636e\u5e93\u7c7b\u578b") public String getDatabaseType(String key) throws SQLException 根据数据源获取数据库类型- 参数:
key- 数据源Key- 返回:
- 数据库类型(如mysql、mssql)
- 抛出:
SQLException- 当指定的数据源不存在时抛出
-
getTypeByDbName
@Comment("\u6839\u636e\u6570\u636e\u5e93\u540d\u5b57\u83b7\u53d6\u6570\u636e\u5e93\u7c7b\u578b") public String getTypeByDbName(String dbName) throws SQLException 根据数据库名字获取数据库类型- 参数:
dbName- 数据库名称- 返回:
- 数据库类型(如mysql、mssql)
- 抛出:
SQLException- 当指定的数据库不存在时抛出
-
getDatasource
@Comment("\u6839\u636e\u6570\u636e\u6e90Key\u83b7\u53d6\u6570\u636e\u6e90") public DataSource getDatasource(String key) 根据数据源Key获取数据源- 参数:
key- 数据源Key- 返回:
- 对应的数据源对象
-
reloadTable
@Comment("\u6839\u636e\u6570\u636e\u6e90\u548c\u8868\u540d\u91cd\u65b0\u52a0\u8f7d\u8868\u7ed3\u6784") public void reloadTable(String datasource, String tableName) 根据数据源和表名重新加载表结构- 参数:
datasource- 数据源标识符tableName- 表名
-
getDatabaseName
@Comment("\u83b7\u53d6\u9ed8\u8ba4\u6570\u636e\u5e93\u540d\u5b57") public String getDatabaseName() throws SQLException获取默认数据库名字- 返回:
- 默认数据库名称
- 抛出:
SQLException- 当默认数据源不存在时抛出
-
getDatabaseType
@Comment("\u83b7\u53d6\u9ed8\u8ba4\u6570\u636e\u6e90\u7c7b\u578b") public String getDatabaseType() throws SQLException获取默认数据源类型- 返回:
- 默认数据源类型(如mysql、mssql)
- 抛出:
SQLException- 当默认数据源不存在时抛出
-
list
获取已启动数据源列表- 返回:
- 已注册的所有数据源键值列表
-
getJdbcTemplate
@Comment("\u6839\u636e\u6570\u636e\u6e90\u83b7\u53d6JdbcTemplate\u63a5\u53e3") public org.springframework.jdbc.core.JdbcTemplate getJdbcTemplate(String key) 根据数据源获取JdbcTemplate接口- 参数:
key- 数据源Key- 返回:
- JdbcTemplate实例
-
getSqlSessionFactory
@Comment("\u6839\u636eDatasource\u521d\u59cb\u5316SqlSessionFactory") public org.apache.ibatis.session.SqlSessionFactory getSqlSessionFactory(DataSource datasource) throws SQLException 根据Datasource初始化SqlSessionFactory- 参数:
datasource- 数据源对象- 返回:
- SqlSessionFactory实例
- 抛出:
SQLException- 当创建SqlSessionFactory过程中发生错误时抛出
-
getSessionTemplate
@Comment("\u6839\u636e\u6570\u636e\u6e90K\u83b7\u53d6SqlSessionTemplate\u63a5\u53e3") public org.mybatis.spring.SqlSessionTemplate getSessionTemplate(String key) throws SQLException 根据数据源K获取SqlSessionTemplate接口- 参数:
key- 数据源Key- 返回:
- SqlSessionTemplate实例
- 抛出:
SQLException- 当创建SqlSessionTemplate过程中发生错误时抛出
-
refresh
@PostConstruct @Comment("\u521d\u59cb\u5316\u6570\u636e\u6e90") public void refresh() throws SQLException初始化数据源- 抛出:
SQLException- 当初始化过程中的数据库连接出现问题时抛出
-
start
启动数据源- 参数:
key- 数据源Key- 抛出:
Exception- 当启动过程中发生未知错误时抛出
-
delete
关闭数据源- 参数:
keyName- 数据源Key
-