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
802230ad
Commit
802230ad
authored
Jan 12, 2023
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交多数据源切换基础版本
parent
56ef0c88
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
442 additions
and
210 deletions
+442
-210
pom.xml
gjjs-bd-business/pom.xml
+12
-8
Bd2poinnewApplication.java
...java/com/brilliance/bd2poinnew/Bd2poinnewApplication.java
+4
-1
MyBatisDaoSession.java
...com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
+74
-15
DbExecuteMapper.java
...ance/mda/support/mybatis/dync/mapper/DbExecuteMapper.java
+0
-38
DataSourceUtil.java
...src/main/java/com/brilliance/mda/util/DataSourceUtil.java
+45
-0
DataSourceConfig.java
...c/main/java/com/ceb/gjjs/mda/config/DataSourceConfig.java
+125
-0
DataSourceConfiguration.java
...java/com/ceb/gjjs/mda/config/DataSourceConfiguration.java
+0
-45
DataSourceConfiguration2.java
...ava/com/ceb/gjjs/mda/config/DataSourceConfiguration2.java
+0
-54
DynamicDataSource.java
.../main/java/com/ceb/gjjs/mda/config/DynamicDataSource.java
+13
-0
JsonConfig.java
...ess/src/main/java/com/ceb/gjjs/mda/config/JsonConfig.java
+0
-45
RolMapper.java
...usiness/src/main/java/com/ceb/gjjs/mda/dao/RolMapper.java
+4
-0
Rcvp.java
...s/src/main/java/com/ceb/gjjs/mda/manager/module/Rcvp.java
+4
-2
DbarolServiceImpl.java
...java/com/ceb/gjjs/mda/service/impl/DbarolServiceImpl.java
+6
-0
RcvselVO.java
...-business/src/main/java/com/ceb/gjjs/mda/vo/RcvselVO.java
+7
-1
countermapper.xml.bak
...src/main/resources/META-INF/orm/mda/countermapper.xml.bak
+0
-0
dbexecutemapper.xml.bak
...c/main/resources/META-INF/orm/mda/dbexecutemapper.xml.bak
+0
-0
application-pg.yml
gjjs-bd-business/src/main/resources/application-pg.yml
+63
-0
application.yml
gjjs-bd-business/src/main/resources/application.yml
+1
-1
DataSourceTest.java
.../test/java/com/ceb/gjjs/mda/junitTest/DataSourceTest.java
+15
-0
DbTest.java
...ness/src/test/java/com/ceb/gjjs/mda/junitTest/DbTest.java
+54
-0
User.java
...siness/src/test/java/com/ceb/gjjs/mda/junitTest/User.java
+15
-0
No files found.
gjjs-bd-business/pom.xml
View file @
802230ad
...
...
@@ -65,14 +65,14 @@
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency
>
<groupId>
com.fasterxml.jackson.core
</groupId
>
<artifactId>
jackson-databind
</artifactId
>
</dependency
>
<dependency
>
<groupId>
com.fasterxml.jackson.core
</groupId
>
<artifactId>
jackson-annotations
</artifactId
>
</dependency
>
<!-- <dependency>--
>
<!-- <groupId>com.fasterxml.jackson.core</groupId>--
>
<!-- <artifactId>jackson-databind</artifactId>--
>
<!-- </dependency>--
>
<!-- <dependency>--
>
<!-- <groupId>com.fasterxml.jackson.core</groupId>--
>
<!-- <artifactId>jackson-annotations</artifactId>--
>
<!-- </dependency>--
>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
...
...
@@ -133,6 +133,10 @@
<artifactId>
mysql-connector-java
</artifactId>
<version>
8.0.30
</version>
</dependency>
<dependency>
<groupId>
jakarta.activation
</groupId>
<artifactId>
jakarta.activation-api
</artifactId>
</dependency>
</dependencies>
...
...
gjjs-bd-business/src/main/java/com/brilliance/bd2poinnew/Bd2poinnewApplication.java
View file @
802230ad
...
...
@@ -3,8 +3,11 @@ package com.brilliance.bd2poinnew;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
@SpringBootApplication
(
scanBasePackages
=
{
"com.brilliance.mda"
,
"com.ceb.gjjs.mda"
})
//移除默认数据库配置类
@SpringBootApplication
(
scanBasePackages
=
{
"com.brilliance.mda"
,
"com.ceb.gjjs.mda"
},
exclude
=
{
DataSourceAutoConfiguration
.
class
})
//@SpringBootApplication(scanBasePackages = {"com.brilliance.mda", "com.ceb.gjjs.mda"})
@MapperScan
({
"com.ceb.gjjs.mda.dao"
})
public
class
Bd2poinnewApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
gjjs-bd-business/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
View file @
802230ad
...
...
@@ -16,6 +16,7 @@ import com.brilliance.mda.runtime.mda.impl.Argument;
import
com.brilliance.mda.support.mybatis.MybatisArgumentAdapter.AdaType
;
import
com.brilliance.mda.support.mybatis.count.CounterService
;
import
com.brilliance.mda.support.mybatis.dync.mapper.DbExecuteMapper
;
import
com.brilliance.mda.util.DataSourceUtil
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -32,6 +33,8 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
static
com
.
brilliance
.
mda
.
support
.
mybatis
.
MybatisArgumentAdapter
.
HOLDER_SQL
;
@Component
public
class
MyBatisDaoSession
extends
AbstractDaoSession
implements
IDaoSession
{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
MyBatisDaoSession
.
class
);
...
...
@@ -44,16 +47,19 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
private
static
final
String
SQLID_DYNCDEL
=
"dyncDelete"
;
@Autowired
CounterService
counter
;
@Autowired
DbExecuteMapper
dbExecuteMapper
;
@Autowired
@Resource
(
name
=
"sqlSessionTemplate"
)
@Resource
(
name
=
"sqlSessionTemplate
1
"
)
SqlSessionTemplate
sqlSessionTemplate
;
@Autowired
@Resource
(
name
=
"sqlSessionTemplate2"
)
SqlSessionTemplate
sqlSessionTemplate2
;
private
String
namespacePackage
=
"com.ceb.gjjs.mapper"
;
private
String
sqlIdTemplate
=
"%s.%sMapper.%s"
;
...
...
@@ -220,12 +226,49 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
}
public
void
dbConnect
()
{
this
.
sqlSessionTemplate
.
getSqlSessionFactory
().
openSession
(
false
);
//this.sqlSessionTemplate.getSqlSessionFactory().openSession(false);
this
.
getSqlSessionTemplate
(
null
).
getSqlSessionFactory
().
openSession
(
false
);
}
// @Override
// public void dbConnect(String dbName) {
// //切换数据库
// DataSourceUtil.setDB(dbName);
// }
public
SqlSessionTemplate
getSqlSessionTemplate
(
String
dbName
)
{
SqlSessionTemplate
sqlSessionTemplate
=
this
.
sqlSessionTemplate
;
if
(
"dataSource"
.
equals
(
dbName
))
{
sqlSessionTemplate
=
this
.
sqlSessionTemplate
;
}
if
(
"dataSource2"
.
equals
(
dbName
))
{
sqlSessionTemplate
=
this
.
sqlSessionTemplate2
;
}
return
sqlSessionTemplate
;
}
public
<
T
>
T
dyncReadOneTest
(
String
dbName
,
Class
<?
extends
IModule
>
clazz
,
MybatisArgumentAdapter
adapter
)
{
SqlSessionTemplate
sqlSessionTemplate
=
getSqlSessionTemplate
(
dbName
);
String
sqlId
=
this
.
getSqlId
(
clazz
,
"dyncRead"
);
T
entity
=
sqlSessionTemplate
.
selectOne
(
sqlId
,
adapter
.
getSqlParams
());
if
(
entity
==
null
)
{
this
.
setNoMoreRow
();
}
return
entity
;
}
public
void
dbDisconnect
()
{
try
{
this
.
sqlSessionTemplate
.
getConnection
().
close
();
this
.
getSqlSessionTemplate
(
null
)
.
getConnection
().
close
();
}
catch
(
SQLException
var2
)
{
var2
.
printStackTrace
();
}
...
...
@@ -239,26 +282,42 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
}
public
String
dbName
()
{
return
this
.
sqlSessionTemplate
.
getConfiguration
().
getDatabaseId
();
return
this
.
getSqlSessionTemplate
(
null
)
.
getConfiguration
().
getDatabaseId
();
}
public
void
dbExecuteSQL
(
String
sql
,
Object
...
objects
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
();
// Map<String, Object> map = new HashMap();
// if (objects != null) {
// sql = MybatisArgumentAdapter.convertPlaceHolder(sql, objects, map);
// }
//
// map.put("sql", sql);
// if (sql.toUpperCase().startsWith("SELECT")) {
// List<Map<String, Object>> result = this.dbExecuteMapper.dyncReadForMap(map);
// if (result == null || result.size() == 0) {
// this.setNoMoreRow();
// return;
// }
//
// resultLocal.set(new ResultSet(result));
// } else {
// this.dbExecuteMapper.dyncUpdateForMap(map);
// }
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
if
(
objects
!=
null
)
{
sql
=
MybatisArgumentAdapter
.
convertPlaceHolder
(
sql
,
objects
,
map
);
}
map
.
put
(
"sql"
,
sql
);
map
.
put
(
HOLDER_SQL
,
sql
);
if
(
sql
.
toUpperCase
().
startsWith
(
"SELECT"
))
{
List
<
Map
<
String
,
Object
>>
result
=
this
.
dbExecuteMapper
.
dyncReadForMap
(
map
);
List
<
Map
<
String
,
Object
>>
result
=
dbExecuteMapper
.
dyncReadForMap
(
map
);
if
(
result
==
null
||
result
.
size
()
==
0
)
{
this
.
setNoMoreRow
();
setNoMoreRow
();
return
;
}
resultLocal
.
set
(
new
ResultSet
(
result
));
}
else
{
this
.
dbExecuteMapper
.
dyncUpdateForMap
(
map
);
int
cnt
=
dbExecuteMapper
.
dyncUpdateForMap
(
map
);
}
}
...
...
@@ -340,7 +399,7 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
private
<
T
>
T
dyncReadOne
(
Class
<?
extends
IModule
>
clazz
,
MybatisArgumentAdapter
adapter
)
{
String
sqlId
=
this
.
getSqlId
(
clazz
,
"dyncRead"
);
T
entity
=
this
.
sqlSessionTemplate
.
selectOne
(
sqlId
,
adapter
.
getSqlParams
());
T
entity
=
this
.
getSqlSessionTemplate
(
null
)
.
selectOne
(
sqlId
,
adapter
.
getSqlParams
());
if
(
entity
==
null
)
{
this
.
setNoMoreRow
();
}
...
...
@@ -350,7 +409,7 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
private
<
T
>
List
<
T
>
dyncRead
(
Class
<
T
>
clazz
,
MybatisArgumentAdapter
adapter
)
{
String
sqlId
=
this
.
getSqlId
(
clazz
,
"dyncRead"
);
List
<
T
>
list
=
this
.
sqlSessionTemplate
.
selectList
(
sqlId
,
adapter
.
getSqlParams
());
List
<
T
>
list
=
this
.
getSqlSessionTemplate
(
null
)
.
selectList
(
sqlId
,
adapter
.
getSqlParams
());
if
(
list
==
null
||
list
.
size
()
==
0
)
{
this
.
setNoMoreRow
();
}
...
...
@@ -360,7 +419,7 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
private
<
T
>
List
<
T
>
dyncRead
(
Class
<
T
>
clazz
,
Map
params
)
{
String
sqlId
=
this
.
getSqlId
(
clazz
,
"dyncRead"
);
List
<
T
>
list
=
this
.
sqlSessionTemplate
.
selectList
(
sqlId
,
params
);
List
<
T
>
list
=
this
.
getSqlSessionTemplate
(
null
)
.
selectList
(
sqlId
,
params
);
if
(
list
==
null
||
list
.
size
()
==
0
)
{
this
.
setNoMoreRow
();
}
...
...
@@ -373,7 +432,7 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
}
private
int
executeUpdate
(
String
mybatisSqlId
,
Object
params
)
{
int
cnt
=
this
.
sqlSessionTemplate
.
update
(
mybatisSqlId
,
params
);
int
cnt
=
this
.
getSqlSessionTemplate
(
null
)
.
update
(
mybatisSqlId
,
params
);
return
cnt
;
}
...
...
gjjs-bd-business/src/main/java/com/brilliance/mda/support/mybatis/dync/mapper/DbExecuteMapper.java
deleted
100644 → 0
View file @
56ef0c88
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package
com
.
brilliance
.
mda
.
support
.
mybatis
.
dync
.
mapper
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
DbExecuteMapper
{
@Autowired
@Resource
(
name
=
"sqlSessionTemplate"
)
SqlSessionTemplate
sqlSessionTemplate
;
@Autowired
@Resource
(
name
=
"sqlSessionTemplate2"
)
SqlSessionTemplate
sqlSessionTemplate2
;
final
String
FNAME
=
this
.
getClass
().
getName
();
public
DbExecuteMapper
()
{
}
public
List
<
Map
<
String
,
Object
>>
dyncReadForMap
(
Map
<
String
,
Object
>
params
)
{
return
this
.
sqlSessionTemplate
.
selectList
(
this
.
FNAME
+
".dyncReadForMap"
,
params
);
}
public
int
dyncUpdateForMap
(
Map
<
String
,
Object
>
params
)
{
return
this
.
sqlSessionTemplate
.
update
(
this
.
FNAME
+
".dyncUpdateForMap"
,
params
);
}
}
gjjs-bd-business/src/main/java/com/brilliance/mda/util/DataSourceUtil.java
0 → 100644
View file @
802230ad
package
com
.
brilliance
.
mda
.
util
;
import
com.brilliance.mda.runtime.mda.util.MdaUtils
;
/**
* 数据源切换工具
*/
public
class
DataSourceUtil
{
/**
* 默认数据源
*/
public
static
final
String
DEFAULT_DS
=
"datasource"
;
/**
* 数据源属于一个公共的资源
* 采用可以保证在多线程情况下线程隔离
*/
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
();
}
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/DataSourceConfig.java
0 → 100644
View file @
802230ad
package
com
.
ceb
.
gjjs
.
mda
.
config
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.SqlSessionFactoryBean
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.jdbc.DataSourceBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
javax.sql.DataSource
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 数据库配置
*/
@Configuration
public
class
DataSourceConfig
{
/**
* 数据源1
* spring.datasource.db1:application.properteis中对应属性的前缀
* @return
*/
@Bean
(
name
=
"dataSource"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource.druid"
)
// @Bean(name = "db1")
// @ConfigurationProperties(prefix = "spring.datasource.db1")
public
DataSource
dataSourceOne
()
{
return
DataSourceBuilder
.
create
().
build
();
}
/**
* 数据源2
* spring.datasource.db2:application.properteis中对应属性的前缀
* @return
*/
//@Bean(name = "db2")
//@ConfigurationProperties(prefix = "spring.datasource.db2")
@Bean
(
name
=
"dataSource2"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource2"
)
public
DataSource
dataSourceTwo
()
{
return
DataSourceBuilder
.
create
().
build
();
}
/**
* 动态数据源: 通过AOP在不同数据源之间动态切换
* @return
*/
@Primary
@Bean
(
name
=
"dynamicDataSource"
)
public
DataSource
dynamicDataSource
()
{
DynamicDataSource
dynamicDataSource
=
new
DynamicDataSource
();
// 默认数据源
dynamicDataSource
.
setDefaultTargetDataSource
(
dataSourceOne
());
// 配置多数据源
Map
<
Object
,
Object
>
dsMap
=
new
HashMap
<>();
dsMap
.
put
(
"dataSource"
,
dataSourceOne
());
dsMap
.
put
(
"dataSource2"
,
dataSourceTwo
());
dynamicDataSource
.
setTargetDataSources
(
dsMap
);
return
dynamicDataSource
;
}
/**
* 配置多数据源后IOC中存在多个数据源了,事务管理器需要重新配置,不然器不知道选择哪个数据源
* 事务管理器此时管理的数据源将是动态数据源dynamicDataSource
* 配置@Transactional注解
* @return
*/
@Bean
public
PlatformTransactionManager
transactionManager
()
{
return
new
DataSourceTransactionManager
(
dynamicDataSource
());
}
@Bean
(
name
=
"sqlSessionFactory1"
)
@Primary
public
SqlSessionFactory
getSqlSessionFactory1
(
@Qualifier
(
"dataSource"
)
DataSource
dataSource
)
throws
Exception
{
SqlSessionFactoryBean
sqlfb
=
new
SqlSessionFactoryBean
();
sqlfb
.
setDataSource
(
dataSource
);
// sqlfb.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
sqlfb
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
"classpath:META-INF/orm/mda/*.xml"
));
return
sqlfb
.
getObject
();
}
@Bean
(
name
=
"transactionManager"
)
@Primary
public
DataSourceTransactionManager
getTransactionManager1
(
@Qualifier
(
"dataSource"
)
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
@Bean
(
name
=
"sqlSessionTemplate1"
)
@Primary
public
SqlSessionTemplate
getSqlSessionTemplate1
(
@Qualifier
(
"sqlSessionFactory1"
)
SqlSessionFactory
sqlSessionFactory
)
throws
Exception
{
return
new
SqlSessionTemplate
(
sqlSessionFactory
);
}
//-----------------------------------------
@Bean
(
name
=
"sqlSessionFactory2"
)
public
SqlSessionFactory
getSqlSessionFactory2
(
@Qualifier
(
"dataSource2"
)
DataSource
dataSource
)
throws
Exception
{
SqlSessionFactoryBean
sqlfb
=
new
SqlSessionFactoryBean
();
sqlfb
.
setDataSource
(
dataSource
);
// sqlfb.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
sqlfb
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
"classpath:META-INF/orm/mda/*.xml"
));
return
sqlfb
.
getObject
();
}
@Bean
(
name
=
"transactionManager2"
)
public
DataSourceTransactionManager
getTransactionManager2
(
@Qualifier
(
"dataSource2"
)
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
@Bean
(
name
=
"sqlSessionTemplate2"
)
public
SqlSessionTemplate
getSqlSessionTemplate2
(
@Qualifier
(
"sqlSessionFactory2"
)
SqlSessionFactory
sqlSessionFactory
)
throws
Exception
{
return
new
SqlSessionTemplate
(
sqlSessionFactory
);
}
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/DataSourceConfiguration.java
deleted
100644 → 0
View file @
56ef0c88
package
com
.
ceb
.
gjjs
.
mda
.
config
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.SqlSessionFactoryBean
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.beans.factory.annotation.Qualifier
;
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
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
javax.sql.DataSource
;
import
java.sql.SQLException
;
@Configuration
@MapperScan
(
basePackages
=
"com.ceb.gjjs.mda.dao"
,
sqlSessionTemplateRef
=
"sqlSessionTemplate"
)
public
class
DataSourceConfiguration
{
@Primary
@Bean
(
name
=
"dataSource"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource.druid"
)
public
DataSource
getDataSource
()
throws
SQLException
{
return
new
DruidDataSource
();
}
@Bean
(
name
=
"sqlSessionFactory"
)
public
SqlSessionFactory
getSqlSessionFactory
(
@Qualifier
(
"dataSource"
)
DataSource
dataSource
)
throws
Exception
{
SqlSessionFactoryBean
sqlfb
=
new
SqlSessionFactoryBean
();
sqlfb
.
setDataSource
(
dataSource
);
// sqlfb.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
sqlfb
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
"classpath:META-INF/orm/mda/*.xml"
));
return
sqlfb
.
getObject
();
}
@Bean
(
name
=
"transactionManager"
)
public
DataSourceTransactionManager
getTransactionManager
(
@Qualifier
(
"dataSource"
)
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
@Bean
(
name
=
"sqlSessionTemplate"
)
public
SqlSessionTemplate
getSqlSessionTemplate
(
@Qualifier
(
"sqlSessionFactory"
)
SqlSessionFactory
sqlSessionFactory
)
throws
Exception
{
return
new
SqlSessionTemplate
(
sqlSessionFactory
);
}
}
\ No newline at end of file
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/DataSourceConfiguration2.java
deleted
100644 → 0
View file @
56ef0c88
package
com
.
ceb
.
gjjs
.
mda
.
config
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.SqlSessionFactoryBean
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.beans.factory.annotation.Qualifier
;
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
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
javax.sql.DataSource
;
import
java.sql.SQLException
;
@Configuration
@MapperScan
(
basePackages
=
"com.ceb.gjjs.mda.dao"
,
sqlSessionTemplateRef
=
"sqlSessionTemplate2"
)
public
class
DataSourceConfiguration2
{
@Bean
(
name
=
"dataSource2"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource2"
)
public
DataSource
getDataSource
()
throws
SQLException
{
return
new
DruidDataSource
();
}
@Bean
(
name
=
"sqlSessionFactory2"
)
@Primary
public
SqlSessionFactory
getSqlSessionFactory
(
@Qualifier
(
"dataSource2"
)
DataSource
dataSource
)
throws
Exception
{
SqlSessionFactoryBean
sqlfb
=
new
SqlSessionFactoryBean
();
sqlfb
.
setDataSource
(
dataSource
);
// sqlfb.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
sqlfb
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
"classpath:META-INF/orm/mda/*.xml"
));
return
sqlfb
.
getObject
();
}
@Bean
(
name
=
"transactionManager2"
)
@Primary
public
DataSourceTransactionManager
getTransactionManager
(
@Qualifier
(
"dataSource2"
)
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
}
@Bean
(
name
=
"sqlSessionTemplate2"
)
@Primary
public
SqlSessionTemplate
getSqlSessionTemplate
(
@Qualifier
(
"sqlSessionFactory2"
)
SqlSessionFactory
sqlSessionFactory
)
throws
Exception
{
return
new
SqlSessionTemplate
(
sqlSessionFactory
);
}
}
\ No newline at end of file
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/DynamicDataSource.java
0 → 100644
View file @
802230ad
package
com
.
ceb
.
gjjs
.
mda
.
config
;
import
com.brilliance.mda.util.DataSourceUtil
;
import
org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource
;
/**
* 动态数据源类
*/
public
class
DynamicDataSource
extends
AbstractRoutingDataSource
{
@Override
protected
Object
determineCurrentLookupKey
()
{
return
DataSourceUtil
.
getDB
();
}
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/config/JsonConfig.java
deleted
100644 → 0
View file @
56ef0c88
package
com
.
ceb
.
gjjs
.
mda
.
config
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter
;
import
com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
;
@Configuration
public
class
JsonConfig
{
/**
* 返回至前端的数据序列化实例
* @param builder
* @return
*/
@Bean
public
ObjectMapper
getJacksonObjectMapper
(
Jackson2ObjectMapperBuilder
builder
)
{
ObjectMapper
objectMapper
=
builder
.
createXmlMapper
(
false
).
build
();
// 序列换成json时,将所有的long变成string.因为js中得数字类型不能包含所有的java long值,超过16位后会出现精度丢失
SimpleModule
simpleModule
=
new
SimpleModule
();
simpleModule
.
addSerializer
(
Long
.
class
,
com
.
fasterxml
.
jackson
.
databind
.
ser
.
std
.
ToStringSerializer
.
instance
);
simpleModule
.
addSerializer
(
Long
.
TYPE
,
com
.
fasterxml
.
jackson
.
databind
.
ser
.
std
.
ToStringSerializer
.
instance
);
objectMapper
.
registerModule
(
simpleModule
);
// 反序列化的时候如果多了其他属性,不抛出异常
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
// 日期格式处理
// objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
SimpleFilterProvider
filterProvider
=
new
SimpleFilterProvider
();
SimpleBeanPropertyFilter
fieldFilter
=
SimpleBeanPropertyFilter
.
serializeAllExcept
(
"attrMaps"
);
filterProvider
.
addFilter
(
"fieldFilter"
,
fieldFilter
);
objectMapper
.
setFilterProvider
(
filterProvider
);
return
objectMapper
;
}
}
\ No newline at end of file
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/dao/RolMapper.java
View file @
802230ad
...
...
@@ -2,12 +2,16 @@ package com.ceb.gjjs.mda.dao;
import
org.apache.ibatis.annotations.Mapper
;
import
com.ceb.gjjs.mda.bo.Rol
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.Collection
;
import
java.util.Map
;
import
java.util.List
;
@Mapper
public
interface
RolMapper
{
// @Select("select count(*) from rol")
// public int counter();
int
insert
(
Rol
record
);
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/manager/module/Rcvp.java
View file @
802230ad
...
...
@@ -2429,8 +2429,8 @@ public class Rcvp extends AbstractModule{
Platform.setValues($subtyp,getFmtList());
Platform.setModified($subtyp);
}*/
MdaUtils
.
setValues
(
this
,
"cur"
,
getSysCurList
());
MdaUtils
.
setValues
(
this
,
"chnipt"
,
getChnList
());
//
MdaUtils.setValues(this,"cur",getSysCurList());
//
MdaUtils.setValues(this,"chnipt",getChnList());
//$msgtyp = "sf2";//L改动
List
<
CodetableItem
>
lst
=
new
ArrayList
<
CodetableItem
>();
...
...
@@ -2500,6 +2500,8 @@ public class Rcvp extends AbstractModule{
MdaUtils
.
clear
(
this
.
getMsggrp
().
getRcvlst
());
}
System
.
out
.
println
(
this
.
getMsggrp
().
getRcvlst
());
System
.
out
.
println
(
111
);
return
true
;
}
...
...
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/service/impl/DbarolServiceImpl.java
View file @
802230ad
package
com
.
ceb
.
gjjs
.
mda
.
service
.
impl
;
import
com.ceb.gjjs.mda.dao.RolMapper
;
import
com.ceb.gjjs.mda.service.DbarolService
;
import
com.ceb.gjjs.mda.service.AbstractCommonProcess
;
import
com.ceb.gjjs.mda.vo.DbarolVO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.activation.DataSource
;
@Service
(
"dbarol"
)
public
class
DbarolServiceImpl
extends
AbstractCommonProcess
<
DbarolVO
>
implements
DbarolService
{
}
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/vo/RcvselVO.java
View file @
802230ad
...
...
@@ -17,9 +17,15 @@ import lombok.Data;
@Data
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@JsonIgnoreProperties
(
value
=
{
"hibernateLazyInitializer"
,
"handler"
},
ignoreUnknown
=
true
)
//@JsonIgnoreProperties(ignoreUnknown = true)
public
class
RcvselVO
extends
BaseVO
implements
Serializable
{
public
RcvselVO
()
{
}
@JsonIgnore
private
static
final
long
serialVersionUID
=
1L
;
...
...
gjjs-bd-business/src/main/resources/META-INF/orm/mda/countermapper.xml
→
gjjs-bd-business/src/main/resources/META-INF/orm/mda/countermapper.xml
.bak
View file @
802230ad
File moved
gjjs-bd-business/src/main/resources/META-INF/orm/mda/dbexecutemapper.xml
→
gjjs-bd-business/src/main/resources/META-INF/orm/mda/dbexecutemapper.xml
.bak
View file @
802230ad
File moved
gjjs-bd-business/src/main/resources/application-pg.yml
0 → 100644
View file @
802230ad
server
:
port
:
8088
servlet
:
context-path
:
/gjjs/business
spring
:
datasource
:
druid
:
driver-class-name
:
oracle.jdbc.driver.OracleDriver
jdbc-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
redis
:
host
:
127.0.0.1
database
:
0
port
:
6379
password
:
datasource2
:
driver-class-name
:
oracle.jdbc.driver.OracleDriver
jdbc-url
:
jdbc:oracle:thin:@114.115.138.98:9400:XE
username
:
TEST
password
:
test
envConfig
:
rootPath
:
workRoot
cache
:
#缓存类型(guava/redis)
type
:
redis
#缓存失效时间(秒)
expireAfterAccess
:
3600
#序列化方式
serializer
:
kryo
\ No newline at end of file
gjjs-bd-business/src/main/resources/application.yml
View file @
802230ad
spring
:
profiles
:
active
:
oracle
active
:
pg
logging
:
config
:
classpath:logback.xml
...
...
gjjs-bd-business/src/test/java/com/ceb/gjjs/mda/junitTest/DataSourceTest.java
0 → 100644
View file @
802230ad
package
com
.
ceb
.
gjjs
.
mda
.
junitTest
;
import
org.junit.jupiter.api.Test
;
public
class
DataSourceTest
{
@Test
public
void
test
()
{
}
}
gjjs-bd-business/src/test/java/com/ceb/gjjs/mda/junitTest/DbTest.java
0 → 100644
View file @
802230ad
package
com
.
ceb
.
gjjs
.
mda
.
junitTest
;
import
com.brilliance.jrxx.utils.FastJsonUtil
;
import
com.ceb.gjjs.mda.service.DbarolService
;
import
com.ceb.gjjs.mda.service.impl.DbarolServiceImpl
;
import
com.fasterxml.jackson.annotation.JsonFilter
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter
;
import
com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.SpringBootConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
@SpringBootConfiguration
public
class
DbTest
{
// @Autowired
// DbarolService dbarolService;
//
// @org.junit.jupiter.api.Test
// void contextLoads() {
// System.out.println("userService.master() = " + dbarolService.master());
// System.out.println("userService.slave() = " + dbarolService.slave());
// }
@Test
public
void
test
()
throws
JsonProcessingException
{
SimpleFilterProvider
filterProvider
=
new
SimpleFilterProvider
();
filterProvider
.
addFilter
(
"userFilter"
,
//添加过滤器名称
SimpleBeanPropertyFilter
.
serializeAllExcept
(
"username"
,
"password"
));
//这里指定不序列化的属性
/* Set exclude = new HashSet();
exclude.add("username");
exclude.add("password");
filterProvider.addFilter("userFilter",
SimpleBeanPropertyFilter.serializeAllExcept(exclude)); //这里指定不序列化的属性也可以放到Set集合里面
filterProvider.addFilter("userFilter",
SimpleBeanPropertyFilter.serializeAll()); // serializeAll()序列化所有属性,
filterProvider.addFilter("userFilter",
SimpleBeanPropertyFilter.filterOutAllExcept("age")); //只序列化这里包含的属性*/
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
setFilterProvider
(
filterProvider
);
User
user
=
new
User
();
user
.
setUsername
(
"小明"
);
user
.
setPassword
(
"123"
);
user
.
setAge
(
18
);
String
s
=
mapper
.
writer
().
withDefaultPrettyPrinter
().
writeValueAsString
(
user
);
System
.
out
.
println
(
"我是序列化"
+
s
);
User
user1
=
mapper
.
readValue
(
"{\"username\":\"小明\",\"password\":\"123\",\"age\":18}"
,
User
.
class
);
System
.
out
.
println
(
"我是反序列化"
+
FastJsonUtil
.
toJSONString
(
user1
));
//这里注意只是在序列化的时候过滤字段,在反序列化的时候是不过滤的
}
}
gjjs-bd-business/src/test/java/com/ceb/gjjs/mda/junitTest/User.java
0 → 100644
View file @
802230ad
package
com
.
ceb
.
gjjs
.
mda
.
junitTest
;
import
com.fasterxml.jackson.annotation.JsonFilter
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
@JsonFilter
(
"userFilter"
)
//在这里加注解并且指定过滤器的名称
public
class
User
{
private
String
username
;
private
String
password
;
private
Integer
age
;
}
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