Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
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
s_guodong
gjjs-bd-common
Commits
c266a268
Commit
c266a268
authored
May 24, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试多数据源
parent
880890a7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
166 additions
and
9 deletions
+166
-9
pom.xml
gjjs-bd-business/pom.xml
+0
-4
Rcvp.java
...s/src/main/java/com/ceb/gjjs/mda/manager/module/Rcvp.java
+0
-0
application-oracle.yml
gjjs-bd-business/src/main/resources/application-oracle.yml
+47
-2
DataSourceConfiguration.java
...illiance/mda/support/mybatis/DataSourceConfiguration.java
+59
-0
DynamicDataSource.java
...com/brilliance/mda/support/mybatis/DynamicDataSource.java
+19
-0
DynamicDataSourceContextHolder.java
...e/mda/support/mybatis/DynamicDataSourceContextHolder.java
+38
-0
DbExecuteMapper.java
...ance/mda/support/mybatis/dync/mapper/DbExecuteMapper.java
+2
-0
pom.xml
gjjs-bd-runtime/pom.xml
+1
-3
No files found.
gjjs-bd-business/pom.xml
View file @
c266a268
...
...
@@ -79,15 +79,11 @@
<groupId>
com.brilliance
</groupId>
<artifactId>
jrxx-bean
</artifactId>
<version>
0.0.1
</version>
<scope>
system
</scope>
<systemPath>
${pom.basedir}/lib/jrxx-bean.jar
</systemPath>
</dependency>
<dependency>
<groupId>
com.brilliance
</groupId>
<artifactId>
jrxx
</artifactId>
<version>
0.0.1
</version>
<scope>
system
</scope>
<systemPath>
${pom.basedir}/lib/jrxx.jar
</systemPath>
</dependency>
</dependencies>
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/manager/module/Rcvp.java
View file @
c266a268
This diff is collapsed.
Click to expand it.
gjjs-bd-business/src/main/resources/application-oracle.yml
View file @
c266a268
...
...
@@ -45,6 +45,50 @@ spring:
password
:
datasource1
:
driver-class-name
:
oracle.jdbc.driver.OracleDriver
url
:
jdbc:oracle:thin:@114.115.138.98:9400:XE
username
:
TEST
password
:
test
type
:
com.alibaba.druid.pool.DruidDataSource
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
# druid 配置: https://github.com/alibaba/druid/wiki/
#初始化链接数
initialSize
:
1
minIdle
:
1
maxActive
:
20
# 配置获取连接等待超时的时间
maxWait
:
60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis
:
60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis
:
300000
validationQuery
:
select 1 from dual
testWhileIdle
:
true
testOnBorrow
:
false
testOnReturn
:
false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements
:
true
maxPoolPreparedStatementPerConnectionSize
:
20
# 配置监控统计拦截的filters,stat用于监控界面,'wall'用于防火墙防御sql注入, slf4j用于druid记录sql日志
filters
:
stat,slf4j
#,wall
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connectionProperties
:
druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
useGlobalDataSourceStat
:
false
datasource2
:
url
:
jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
username
:
root
password
:
123456
#driverClassName: com.mysql.jdbc.Driver
driver-class-name
:
com.mysql.jdbc.Driver
envConfig
:
rootPath
:
workRoot
cache
:
...
...
@@ -53,4 +97,6 @@ envConfig:
#缓存失效时间(秒)
expireAfterAccess
:
3600
#序列化方式
serializer
:
kryo
\ No newline at end of file
serializer
:
kryo
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/DataSourceConfiguration.java
0 → 100644
View file @
c266a268
package
com
.
brilliance
.
mda
.
support
.
mybatis
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
javax.sql.DataSource
;
import
java.util.HashMap
;
/**
* @Description 注册数据源头
* @Author s_guodong
* @Date 2023/5/24
*/
@Configuration
@EnableAutoConfiguration
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
public
class
DataSourceConfiguration
{
/**
* 数据源1
*/
@Bean
(
name
=
"datasource1"
)
@Qualifier
(
"datasource1"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource1"
)
public
DruidDataSource
datasource1
()
{
return
new
DruidDataSource
();
}
/**
* 数据源2
*/
@Bean
(
name
=
"datasource2"
)
@Qualifier
(
"datasource2"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource2"
)
public
DruidDataSource
datasource2
()
{
return
new
DruidDataSource
();
}
@Bean
(
name
=
"dynamicDataSource"
)
@Primary
public
DataSource
dynamicDataSource
()
{
DynamicDataSource
dynamicDataSource
=
new
DynamicDataSource
();
dynamicDataSource
.
myMap
=
new
HashMap
<>(
2
);
dynamicDataSource
.
myMap
.
put
(
"datasource1"
,
datasource1
());
dynamicDataSource
.
myMap
.
put
(
"datasource2"
,
datasource2
());
dynamicDataSource
.
setTargetDataSources
(
dynamicDataSource
.
myMap
);
dynamicDataSource
.
setDefaultTargetDataSource
(
datasource1
());
DynamicDataSourceContextHolder
.
dataSourceIds
.
addAll
(
dynamicDataSource
.
myMap
.
keySet
());
return
dynamicDataSource
;
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/DynamicDataSource.java
0 → 100644
View file @
c266a268
package
com
.
brilliance
.
mda
.
support
.
mybatis
;
import
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
;
import
java.util.Map
;
/**
* @Description
* @Author s_guodong
* @Date 2023/5/24
*/
public
class
DynamicDataSource
extends
AbstractRoutingDataSource
{
public
Map
<
Object
,
Object
>
myMap
=
null
;
@Override
protected
Object
determineCurrentLookupKey
()
{
return
DynamicDataSourceContextHolder
.
getDataSourceType
();
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/DynamicDataSourceContextHolder.java
0 → 100644
View file @
c266a268
package
com
.
brilliance
.
mda
.
support
.
mybatis
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @Description
* @Author s_guodong
* @Date 2023/5/24
*/
public
class
DynamicDataSourceContextHolder
{
private
static
final
ThreadLocal
<
String
>
contextHolder
=
new
ThreadLocal
<
String
>();
public
static
List
<
Object
>
dataSourceIds
=
new
ArrayList
<
Object
>();
public
static
void
setDataSourceType
(
String
dataSourceType
)
{
contextHolder
.
set
(
dataSourceType
);
}
public
static
String
getDataSourceType
()
{
return
contextHolder
.
get
();
}
public
static
void
clearDataSourceType
()
{
contextHolder
.
remove
();
}
public
static
boolean
containsDataSource
(
String
dataSourceId
)
{
return
dataSourceIds
.
contains
(
dataSourceId
);
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/dync/mapper/DbExecuteMapper.java
View file @
c266a268
package
com
.
brilliance
.
mda
.
support
.
mybatis
.
dync
.
mapper
;
import
com.brilliance.mda.support.mybatis.DynamicDataSourceContextHolder
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -16,6 +17,7 @@ public class DbExecuteMapper {
final
String
FNAME
=
this
.
getClass
().
getName
();
public
List
<
Map
<
String
,
Object
>>
dyncReadForMap
(
Map
<
String
,
Object
>
params
){
DynamicDataSourceContextHolder
.
setDataSourceType
(
"datasource2"
);
return
sqlSessionTemplate
.
selectList
(
FNAME
+
".dyncReadForMap"
,
params
);
}
public
int
dyncUpdateForMap
(
Map
<
String
,
Object
>
params
){
...
...
gjjs-bd-runtime/pom.xml
View file @
c266a268
...
...
@@ -86,9 +86,7 @@
<dependency>
<groupId>
com.oracle
</groupId>
<artifactId>
ojdbc6
</artifactId>
<version>
12.1.0.2
</version>
<scope>
system
</scope>
<systemPath>
${basedir}/../lib/ojdbc6-12.1.0.2.jar
</systemPath>
<version>
11.2.0.3
</version>
</dependency>
</dependencies>
...
...
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