Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-runtime
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
model-driver
gjjs-bd-runtime
Commits
cab46ca7
Commit
cab46ca7
authored
Jan 26, 2023
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交多数据源runtime切换初版
parent
af8e55c1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
1 deletions
+71
-1
pom.xml
pom.xml
+5
-0
DataSourceConfig.java
...m/brilliance/mda/runtime/mda/config/DataSourceConfig.java
+0
-0
DynamicDataSource.java
.../brilliance/mda/runtime/mda/config/DynamicDataSource.java
+14
-0
DataSourceUtil.java
...a/com/brilliance/mda/runtime/mda/util/DataSourceUtil.java
+46
-0
MultiMyBatisDaoSession.java
...rilliance/mda/support/mybatis/MultiMyBatisDaoSession.java
+0
-0
MyBatisDaoSession.java
...com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
+6
-1
No files found.
pom.xml
View file @
cab46ca7
...
...
@@ -155,6 +155,11 @@
<scope>
system
</scope>
<systemPath>
${pom.basedir}/lib/ojdbc6-12.1.0.2.jar
</systemPath>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.1.23
</version>
</dependency>
</dependencies>
...
...
src/main/java/com/brilliance/mda/runtime/mda/config/DataSourceConfig.java
0 → 100644
View file @
cab46ca7
This diff is collapsed.
Click to expand it.
src/main/java/com/brilliance/mda/runtime/mda/config/DynamicDataSource.java
0 → 100644
View file @
cab46ca7
package
com
.
brilliance
.
mda
.
runtime
.
mda
.
config
;
import
com.brilliance.mda.runtime.mda.util.DataSourceUtil
;
import
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
;
/**
* 动态数据源类
*/
public
class
DynamicDataSource
extends
AbstractRoutingDataSource
{
@Override
protected
Object
determineCurrentLookupKey
()
{
return
DataSourceUtil
.
getDB
();
}
}
src/main/java/com/brilliance/mda/runtime/mda/util/DataSourceUtil.java
0 → 100644
View file @
cab46ca7
package
com
.
brilliance
.
mda
.
runtime
.
mda
.
util
;
import
com.brilliance.mda.runtime.mda.util.MdaUtils
;
/**
* 数据源切换工具
*/
public
class
DataSourceUtil
{
/**
* 默认数据源
*/
//TODO 这里默认数据源需要动态生成
public
static
final
String
DEFAULT_DS
=
"eibs"
;
/**
* 数据源属于一个公共的资源
* 采用可以保证在多线程情况下线程隔离
*/
private
static
final
ThreadLocal
<
String
>
contextHolder
=
new
ThreadLocal
<>();
/**
* 设置数据源名
* @param dbType
*/
public
static
void
setDB
(
String
dbType
)
{
contextHolder
.
set
(
dbType
);
}
/**
* 获取数据源名
* @return
*/
public
static
String
getDB
()
{
String
dbName
=
(
contextHolder
.
get
())
;
if
(
MdaUtils
.
isEmpty
(
dbName
))
return
DEFAULT_DS
;
return
dbName
;
}
/**
* 清除数据源名
*/
public
static
void
clearDB
()
{
contextHolder
.
remove
();
}
}
\ No newline at end of file
src/main/java/com/brilliance/mda/support/mybatis/MultiMyBatisDaoSession.java
0 → 100644
View file @
cab46ca7
This diff is collapsed.
Click to expand it.
src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
View file @
cab46ca7
...
...
@@ -49,7 +49,7 @@ import static com.brilliance.mda.support.mybatis.MybatisArgumentAdapter.HOLDER_S
*
* @author hulei
*/
@Component
//
@Component
public
class
MyBatisDaoSession
extends
AbstractDaoSession
implements
IDaoSession
{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
MyBatisDaoSession
.
class
);
...
...
@@ -273,6 +273,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
sqlSessionTemplate
.
getSqlSessionFactory
().
openSession
(
false
);
}
@Override
public
void
dbConnect
(
String
s
)
{
}
@Override
public
void
dbDisconnect
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment