Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
c1703d87
Commit
c1703d87
authored
Apr 08, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理SQL语句
parent
f995b489
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
19 deletions
+34
-19
DbExecuteImpl.java
.../src/main/java/com/yanzuoguang/db/Impl/DbExecuteImpl.java
+4
-4
DbPrintSql.java
...-db/src/main/java/com/yanzuoguang/db/Impl/DbPrintSql.java
+30
-15
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/db/Impl/DbExecuteImpl.java
View file @
c1703d87
...
...
@@ -50,7 +50,7 @@ public class DbExecuteImpl implements DbExecute {
row
=
jdbc
.
update
(
sql
,
paras
);
return
row
;
}
finally
{
printSql
.
print
(
targetClass
,
sqlName
,
row
,
sql
,
paras
,
start
);
printSql
.
print
(
targetClass
,
sqlName
,
start
,
row
,
sql
,
paras
);
}
}
...
...
@@ -81,7 +81,7 @@ public class DbExecuteImpl implements DbExecute {
}
});
}
finally
{
printSql
.
print
(
targetClass
,
sqlName
,
row
.
value
,
sql
,
paras
,
start
);
printSql
.
print
(
targetClass
,
sqlName
,
start
,
row
.
value
,
sql
,
paras
);
}
}
...
...
@@ -109,7 +109,7 @@ public class DbExecuteImpl implements DbExecute {
row
=
ret
.
size
();
return
ret
;
}
finally
{
printSql
.
print
(
targetClass
,
sqlName
,
row
,
sql
,
paras
,
start
);
printSql
.
print
(
targetClass
,
sqlName
,
start
,
row
,
sql
,
paras
);
}
}
...
...
@@ -147,7 +147,7 @@ public class DbExecuteImpl implements DbExecute {
}
return
null
;
}
finally
{
printSql
.
print
(
targetClass
,
sqlName
,
row
,
sql
,
paras
,
start
);
printSql
.
print
(
targetClass
,
sqlName
,
start
,
row
,
sql
,
paras
);
}
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/Impl/DbPrintSql.java
View file @
c1703d87
...
...
@@ -14,23 +14,13 @@ public class DbPrintSql {
private
ConfigDb
configDb
;
/**
*
打印
SQL语句
*
获取参数处理之后的
SQL语句
*
* @param targetClass 触发类
* @param sqlName SQL语句名称
* @param sql SQL语句
* @param sql 带参数的SQL语句
* @param paras 参数
* @return 不带参数的SQL语句
*/
public
void
print
(
Class
targetClass
,
String
sqlName
,
int
row
,
String
sql
,
Object
...
paras
)
{
// 日志表忽略打印
if
(!
configDb
.
isPrintSql
())
{
return
;
}
if
(!
StringHelper
.
isEmpty
(
configDb
.
getPrintSqlFilter
()))
{
if
(
sql
.
matches
(
configDb
.
getPrintSqlFilter
()))
{
return
;
}
}
public
String
getStringSql
(
String
sql
,
Object
...
paras
)
{
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
for
(
Object
item
:
paras
)
{
String
str
=
StringHelper
.
toString
(
item
);
...
...
@@ -40,12 +30,37 @@ public class DbPrintSql {
}
else
{
sql
=
sql
.
replaceFirst
(
"\\?"
,
str
);
}
}
else
{
sql
=
sql
.
replaceFirst
(
"\\?"
,
"'"
+
str
.
replace
(
"'"
,
"''"
)
+
"'"
);
}
}
return
sql
;
}
/**
* 打印SQL语句
*
* @param targetClass 触发类
* @param sqlName SQL语句名称
* @param start 开始执行的语句
* @param row SQL语句
* @param sql SQL语句
* @param paras 参数
*/
public
void
print
(
Class
targetClass
,
String
sqlName
,
long
start
,
int
row
,
String
sql
,
Object
...
paras
)
{
// 日志表忽略打印
if
(!
configDb
.
isPrintSql
())
{
return
;
}
if
(!
StringHelper
.
isEmpty
(
configDb
.
getPrintSqlFilter
()))
{
if
(
sql
.
matches
(
configDb
.
getPrintSqlFilter
()))
{
return
;
}
}
sql
=
getStringSql
(
sql
,
paras
);
// 打印SQL语句
Log
.
infoTag
(
DbPrintSql
.
class
,
String
.
format
(
"%d row %s.%s"
,
row
,
targetClass
.
getSimpleName
(),
sqlName
),
sql
);
}
}
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