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
d7974868
Commit
d7974868
authored
Jul 01, 2023
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交数据库配置初始化模板mybatis.properties
parent
4255bc56
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
32 deletions
+73
-32
Acdopn.java
...siness/src/main/java/com/ceb/gjjs/mda/manager/Acdopn.java
+1
-0
MyBatisDaoSession.java
...com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
+46
-25
MybatisDbUtil.java
.../brilliance/mda/support/mybatis/config/MybatisDbUtil.java
+23
-4
mybatis.properties
...-bd-mybatis-support/src/main/resources/mybatis.properties
+3
-3
No files found.
gjjs-bd-business/src/main/java/com/ceb/gjjs/mda/manager/Acdopn.java
View file @
d7974868
...
...
@@ -185,6 +185,7 @@ public class Acdopn extends AbstractTransaction{
//Object resMsg = MdaUtils.invoke("com.brilliance.eibs.main.Client","scall","w414","w414",new Object[]{yymap});
Object
resMsg
=
new
ResultMsg
();
Map
retMap
=
new
HashMap
();
retMap
.
put
(
"code"
,
"000000"
);
ResultMsg
retMsg
=
(
ResultMsg
)
resMsg
;
retMsg
.
setContent
(
retMap
);
resMsg
=
retMsg
;
...
...
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/MyBatisDaoSession.java
View file @
d7974868
...
...
@@ -8,6 +8,7 @@ import com.brilliance.mda.runtime.mda.impl.Argument;
import
com.brilliance.mda.runtime.mda.impl.ModuleList
;
import
com.brilliance.mda.runtime.mda.util.MdaUtils
;
import
com.brilliance.mda.runtime.request.BaseVO
;
import
com.brilliance.mda.support.mybatis.config.MybatisDbUtil
;
import
com.brilliance.mda.support.mybatis.count.CounterService
;
import
com.brilliance.mda.support.mybatis.dync.mapper.DbExecuteMapper
;
import
com.github.pagehelper.PageHelper
;
...
...
@@ -71,6 +72,8 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
private
static
final
String
SQLID_SELECTBYID
=
"selectByInr"
;
private
static
final
String
SQLID_SELECTBYPRIMARYKEY
=
"selectByPrimaryKey"
;
private
static
boolean
isMultiDb
=
MybatisDbUtil
.
isMultilDb
();
@Autowired
CounterService
counter
;
...
...
@@ -104,40 +107,50 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
<
T
extends
IModule
>
int
dbInsert
(
T
module
)
{
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
String
sqlId
=
getSqlId
(
module
.
getClass
(),
SQLID_INSERT
);
return
executeUpdate
(
sqlId
,
module
);
}
@Override
public
<
T
extends
IModule
>
int
dbUpdate
(
T
module
)
{
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
String
sqlId
=
getSqlId
(
module
.
getClass
(),
SQLID_UPDATE
);
return
executeUpdate
(
sqlId
,
module
);
}
@Override
public
<
T
extends
IModule
>
int
dbDelete
(
T
module
)
{
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
String
sqlId
=
getSqlId
(
module
.
getClass
(),
SQLID_DELETE
);
return
executeUpdate
(
sqlId
,
module
);
}
@Override
public
<
T
extends
IModule
>
int
dbDelete
(
T
m
,
Argument
...
args
)
{
String
moduleDB
=
MdaUtils
.
getModuleDB
(
m
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleDB
(
m
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
Class
<
T
>
clazz
=
(
Class
<
T
>)
m
.
getClass
();
MybatisArgumentAdapter
adapter
=
new
MybatisArgumentAdapter
(
DELETE
,
clazz
,
args
);
return
executeUpdate
(
getSqlId
(
clazz
,
SQLID_DYNCDEL
),
adapter
.
getSqlParams
());
}
public
<
T
extends
IModule
>
int
dbDelete
(
T
module
,
Serializable
...
id
)
{
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
Class
<
T
>
clazz
=
(
Class
<
T
>)
module
.
getClass
();
String
sqlId
=
getSqlId
(
clazz
,
SQLID_DELBYIDS
);
return
executeUpdate
(
sqlId
,
Arrays
.
asList
(
id
));
...
...
@@ -154,8 +167,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
<
T
extends
IModule
>
T
dbRead
(
T
module
,
Argument
...
args
)
{
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
MybatisArgumentAdapter
adapter
=
new
MybatisArgumentAdapter
(
SELECT
,
module
.
getClass
(),
args
);
T
entity
=
this
.
dyncReadOne
(
module
.
getClass
(),
adapter
);
...
...
@@ -167,8 +182,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
<
T
extends
IModule
>
T
dbReadByInr
(
T
module
,
String
inr
)
{
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleDB
(
module
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
Map
<
String
,
Object
>
dyncMap
=
new
HashMap
<>();
dyncMap
.
put
(
"inr"
,
inr
);
T
entity
=
this
.
dyncReadByInr
(
module
.
getClass
(),
dyncMap
);
...
...
@@ -197,9 +214,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
<
T
extends
IModule
>
int
dbReadset
(
IModuleList
<
T
>[]
lists
,
CacheOption
cacheOption
,
String
whereSql
,
Object
[]
param
)
{
String
moduleDB
=
MdaUtils
.
getModuleListsDB
(
lists
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleListsDB
(
lists
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
if
(
cacheOption
!=
null
)
{
IContext
ctx
=
MdaEnv
.
getContext
();
BaseVO
baseVO
=
ctx
.
getVo
();
...
...
@@ -226,9 +244,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
<
T
extends
IModule
>
int
dbReadset
(
IModuleList
<
T
>
list
,
Argument
...
args
)
{
String
moduleDB
=
MdaUtils
.
getModuleListDB
(
list
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleListDB
(
list
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
list
.
clear
();
MybatisArgumentAdapter
adapter
=
new
MybatisArgumentAdapter
(
SELECT
,
list
.
getDataClass
(),
args
);
List
<
T
>
result
=
this
.
dyncRead
(
list
.
getDataClass
(),
adapter
);
...
...
@@ -282,9 +301,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
<
T
extends
IModule
>
int
dbReadset
(
IModuleList
<
T
>
list
,
String
whereSql
,
Object
[]
objects
)
{
if
(
isMultiDb
){
String
moduleDB
=
MdaUtils
.
getModuleListDB
(
list
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
moduleDB
);
}
list
.
clear
();
MybatisArgumentAdapter
adapter
=
new
MybatisArgumentAdapter
(
SELECT
,
list
.
getDataClass
(),
whereSql
,
objects
);
List
<
T
>
result
=
this
.
dyncRead
(
list
.
getDataClass
(),
adapter
);
...
...
@@ -307,10 +327,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public
void
dbExecuteSQL
(
String
sql
,
Object
...
objects
)
{
String
tableName
=
MdaUtils
.
getTableNameFromSQL
(
sql
);
String
tableDB
=
MdaUtils
.
getTableDB
(
tableName
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
tableDB
);
if
(
isMultiDb
){
String
tableName
=
MdaUtils
.
getTableNameFromSQL
(
sql
);
String
tableDB
=
MdaUtils
.
getTableDB
(
tableName
);
DynamicDataSourceContextHolder
.
setDataSourceType
(
tableDB
);
}
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
if
(
objects
!=
null
)
{
sql
=
MybatisArgumentAdapter
.
convertPlaceHolder
(
sql
,
objects
,
map
);
...
...
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/config/MybatisDbUtil.java
View file @
d7974868
...
...
@@ -6,11 +6,30 @@ import org.apache.commons.beanutils.PropertyUtils;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Properties
;
public
class
MybatisDbUtil
{
private
static
Properties
properties
=
new
Properties
();
static
{
try
{
InputStream
inputStream
=
MybatisDbUtil
.
class
.
getResourceAsStream
(
"/mybatis.properties"
);
properties
.
load
(
inputStream
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
boolean
isMultilDb
()
{
//不加/会从当前包进行寻找,加上/会从src开始找
String
pro
=
properties
.
getProperty
(
"multidb"
);
return
pro
==
null
?
false
:
Boolean
.
valueOf
(
pro
);
}
// private static Map
static
{
// PropertyUtils
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
System
.
out
.
println
(
isMultilDb
());
}
}
gjjs-bd-mybatis-support/src/main/resources/mybatis.properties
View file @
d7974868
#数据库相关配置信息
dbinfo.multidb
=
false
dbinfo.name
=
ipsnew
\ No newline at end of file
#是否是多数据库true false
multidb
=
false
\ No newline at end of file
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