Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
cms_sys
Project
Project
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
西魏
cms_sys
Commits
8b9cf07b
Commit
8b9cf07b
authored
Nov 03, 2020
by
guwd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
抽取ms-db
parent
14b2d5db
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
4 additions
and
149 deletions
+4
-149
pom.xml
pom.xml
+4
-0
MybatisInterceptorConfig.java
...in/java/net/mingsoft/config/MybatisInterceptorConfig.java
+0
-43
DMInnerInterceptor.java
...ain/java/net/mingsoft/interceptor/DMInnerInterceptor.java
+0
-61
MysqlInnerInterceptor.java
.../java/net/mingsoft/interceptor/MysqlInnerInterceptor.java
+0
-45
No files found.
pom.xml
View file @
8b9cf07b
...
@@ -33,6 +33,10 @@
...
@@ -33,6 +33,10 @@
<groupId>
net.mingsoft
</groupId>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-mpeople
</artifactId>
<artifactId>
ms-mpeople
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
net.mingsoft
</groupId>
<artifactId>
ms-db
</artifactId>
</dependency>
<!-- 此部分是铭飞平台MStroe的客户端(MStore不在铭飞开源产品范围),如果不需要使用MStore可以删除掉 -->
<!-- 此部分是铭飞平台MStroe的客户端(MStore不在铭飞开源产品范围),如果不需要使用MStore可以删除掉 -->
<dependency>
<dependency>
...
...
src/main/java/net/mingsoft/config/MybatisInterceptorConfig.java
deleted
100644 → 0
View file @
14b2d5db
package
net
.
mingsoft
.
config
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler
;
import
com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor
;
import
com.baomidou.mybatisplus.extension.toolkit.JdbcUtils
;
import
net.mingsoft.interceptor.DMInnerInterceptor
;
import
net.mingsoft.interceptor.MysqlInnerInterceptor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.sql.DataSource
;
import
java.sql.SQLException
;
/**
* Mybatis 拦截器配置
*/
@Configuration
public
class
MybatisInterceptorConfig
{
@Bean
public
MybatisPlusInterceptor
mybatisPlusInterceptor
(
DataSource
dataSource
,
@Autowired
(
required
=
false
)
TenantLineHandler
tenantLineHandler
)
{
MybatisPlusInterceptor
interceptor
=
new
MybatisPlusInterceptor
();
if
(
tenantLineHandler
!=
null
){
interceptor
.
addInnerInterceptor
(
new
TenantLineInnerInterceptor
(
tenantLineHandler
));
}
try
{
//mysql 添加转换sql
DbType
dbType
=
JdbcUtils
.
getDbType
(
dataSource
.
getConnection
().
getMetaData
().
getURL
());
if
(
DbType
.
MYSQL
==
dbType
){
interceptor
.
addInnerInterceptor
(
new
MysqlInnerInterceptor
());
}
else
if
(
DbType
.
DM
==
dbType
){
interceptor
.
addInnerInterceptor
(
new
DMInnerInterceptor
());
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
return
interceptor
;
}
}
src/main/java/net/mingsoft/interceptor/DMInnerInterceptor.java
deleted
100644 → 0
View file @
14b2d5db
package
net
.
mingsoft
.
interceptor
;
import
com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper
;
import
com.baomidou.mybatisplus.core.toolkit.PluginUtils
;
import
com.baomidou.mybatisplus.core.toolkit.TableNameParser
;
import
com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
;
import
org.apache.ibatis.executor.Executor
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.SqlCommandType
;
import
org.apache.ibatis.session.ResultHandler
;
import
org.apache.ibatis.session.RowBounds
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
DMInnerInterceptor
implements
InnerInterceptor
{
@Override
public
void
beforeQuery
(
Executor
executor
,
MappedStatement
ms
,
Object
parameter
,
RowBounds
rowBounds
,
ResultHandler
resultHandler
,
BoundSql
boundSql
)
throws
SQLException
{
PluginUtils
.
MPBoundSql
mpBs
=
PluginUtils
.
mpBoundSql
(
boundSql
);
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
mpBs
.
sql
(
this
.
changeTable
(
mpBs
.
sql
()));
}
@Override
public
void
beforePrepare
(
StatementHandler
sh
,
Connection
connection
,
Integer
transactionTimeout
)
{
PluginUtils
.
MPStatementHandler
mpSh
=
PluginUtils
.
mpStatementHandler
(
sh
);
MappedStatement
ms
=
mpSh
.
mappedStatement
();
SqlCommandType
sct
=
ms
.
getSqlCommandType
();
if
(
sct
==
SqlCommandType
.
INSERT
||
sct
==
SqlCommandType
.
UPDATE
||
sct
==
SqlCommandType
.
DELETE
)
{
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
PluginUtils
.
MPBoundSql
mpBs
=
mpSh
.
mPBoundSql
();
mpBs
.
sql
(
this
.
changeTable
(
mpBs
.
sql
()));
}
}
protected
String
changeTable
(
String
sql
)
{
TableNameParser
parser
=
new
TableNameParser
(
sql
);
List
<
TableNameParser
.
SqlToken
>
names
=
new
ArrayList
<>();
parser
.
accept
(
names:
:
add
);
StringBuilder
builder
=
new
StringBuilder
();
int
last
=
0
;
for
(
TableNameParser
.
SqlToken
name
:
names
)
{
int
start
=
name
.
getStart
();
if
(
start
!=
last
)
{
builder
.
append
(
sql
,
last
,
start
);
String
value
=
name
.
getValue
();
builder
.
append
(
String
.
format
(
"\"%s\""
,
value
));
}
last
=
name
.
getEnd
();
}
if
(
last
!=
sql
.
length
())
{
builder
.
append
(
sql
.
substring
(
last
));
}
return
builder
.
toString
();
}
}
src/main/java/net/mingsoft/interceptor/MysqlInnerInterceptor.java
deleted
100644 → 0
View file @
14b2d5db
package
net
.
mingsoft
.
interceptor
;
import
com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper
;
import
com.baomidou.mybatisplus.core.toolkit.PluginUtils
;
import
com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor
;
import
org.apache.ibatis.executor.Executor
;
import
org.apache.ibatis.executor.statement.StatementHandler
;
import
org.apache.ibatis.mapping.BoundSql
;
import
org.apache.ibatis.mapping.MappedStatement
;
import
org.apache.ibatis.mapping.SqlCommandType
;
import
org.apache.ibatis.session.ResultHandler
;
import
org.apache.ibatis.session.RowBounds
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
/**
* Mysql 适配通用拦截器,主要处理不支持的sql语句
*/
public
class
MysqlInnerInterceptor
implements
InnerInterceptor
{
@Override
public
void
beforeQuery
(
Executor
executor
,
MappedStatement
ms
,
Object
parameter
,
RowBounds
rowBounds
,
ResultHandler
resultHandler
,
BoundSql
boundSql
)
throws
SQLException
{
PluginUtils
.
MPBoundSql
mpBs
=
PluginUtils
.
mpBoundSql
(
boundSql
);
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
mpBs
.
sql
(
this
.
changeSql
(
mpBs
.
sql
()));
}
@Override
public
void
beforePrepare
(
StatementHandler
sh
,
Connection
connection
,
Integer
transactionTimeout
)
{
PluginUtils
.
MPStatementHandler
mpSh
=
PluginUtils
.
mpStatementHandler
(
sh
);
MappedStatement
ms
=
mpSh
.
mappedStatement
();
SqlCommandType
sct
=
ms
.
getSqlCommandType
();
if
(
sct
==
SqlCommandType
.
INSERT
||
sct
==
SqlCommandType
.
UPDATE
||
sct
==
SqlCommandType
.
DELETE
)
{
if
(
InterceptorIgnoreHelper
.
willIgnoreDynamicTableName
(
ms
.
getId
()))
return
;
PluginUtils
.
MPBoundSql
mpBs
=
mpSh
.
mPBoundSql
();
mpBs
.
sql
(
this
.
changeSql
(
mpBs
.
sql
()));
}
}
protected
String
changeSql
(
String
sql
)
{
//替换所有"为`
return
sql
.
replaceAll
(
"\""
,
"`"
);
}
}
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