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
1c1991d3
Commit
1c1991d3
authored
May 19, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
269ffaa3
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
170 additions
and
40 deletions
+170
-40
TestRunnableListAuto.java
yzg-util-base/src/test/java/thread/TestRunnableListAuto.java
+8
-0
DbPrintSql.java
yzg-util-db/src/main/java/com/yanzuoguang/db/DbPrintSql.java
+20
-0
DbPrintSqlExcept.java
...db/src/main/java/com/yanzuoguang/db/DbPrintSqlExcept.java
+20
-0
DbExecuteImpl.java
.../src/main/java/com/yanzuoguang/db/impl/DbExecuteImpl.java
+2
-2
DbExecutePrintSql.java
.../main/java/com/yanzuoguang/db/impl/DbExecutePrintSql.java
+48
-0
DbPrintSqlDefault.java
.../main/java/com/yanzuoguang/db/impl/DbPrintSqlDefault.java
+9
-34
DbPrintSqlExceptDefault.java
...java/com/yanzuoguang/db/impl/DbPrintSqlExceptDefault.java
+34
-0
TestDbExecutePrintSql.java
yzg-util-db/src/test/java/TestDbExecutePrintSql.java
+3
-4
DbPrintExceptByMessage.java
...a/com/yanzuoguang/mq/dao/impl/DbPrintExceptByMessage.java
+26
-0
No files found.
yzg-util-base/src/test/java/thread/TestRunnableListAuto.java
View file @
1c1991d3
...
@@ -38,4 +38,12 @@ public class TestRunnableListAuto {
...
@@ -38,4 +38,12 @@ public class TestRunnableListAuto {
public
void
test1
()
{
public
void
test1
()
{
runTest
(
false
);
runTest
(
false
);
}
}
@Test
public
void
testLong
()
{
long
day
=
1000L
*
60
*
60
*
24
;
System
.
out
.
println
(
Long
.
MAX_VALUE
);
System
.
out
.
println
(
Long
.
MAX_VALUE
/
day
+
"天"
);
System
.
out
.
println
(
Long
.
MAX_VALUE
/
day
/
365
+
"年"
);
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/db/DbPrintSql.java
0 → 100644
View file @
1c1991d3
package
com
.
yanzuoguang
.
db
;
import
com.yanzuoguang.db.impl.SqlInfo
;
/**
* 打印sql语句
*
* @author 颜佐光
*/
public
interface
DbPrintSql
{
/**
* 打印Sql语句
*
* @param sqlInfo Sql语句信息
* @param time Sql语句
* @param row 影响的行数
*/
void
printSql
(
SqlInfo
sqlInfo
,
long
time
,
int
row
);
}
yzg-util-db/src/main/java/com/yanzuoguang/db/DbPrintSqlExcept.java
0 → 100644
View file @
1c1991d3
package
com
.
yanzuoguang
.
db
;
import
com.yanzuoguang.db.impl.SqlInfo
;
/**
* 排除打印的Sql语句
*
* @author 颜佐光
*/
public
interface
DbPrintSqlExcept
{
/**
* 是否过滤打印的Sql语句
*
* @param sqlInfo Sql语句信息
* @param time Sql语句
* @param row 影响的行数
* @return true = 过滤打印(不打印), false = 打印
*/
boolean
isPrintExcept
(
SqlInfo
sqlInfo
,
long
time
,
int
row
);
}
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbExecuteImpl.java
View file @
1c1991d3
...
@@ -22,11 +22,11 @@ import java.util.List;
...
@@ -22,11 +22,11 @@ import java.util.List;
public
class
DbExecuteImpl
implements
DbExecute
{
public
class
DbExecuteImpl
implements
DbExecute
{
private
final
JdbcTemplate
jdbcTemplate
;
private
final
JdbcTemplate
jdbcTemplate
;
private
final
DbPrintSql
printSql
;
private
final
Db
Execute
PrintSql
printSql
;
private
final
ConfigDb
configDb
;
private
final
ConfigDb
configDb
;
private
final
LogCountTime
logCountTime
;
private
final
LogCountTime
logCountTime
;
public
DbExecuteImpl
(
JdbcTemplate
jdbcTemplate
,
DbPrintSql
printSql
,
ConfigDb
configDb
,
LogCountTime
logCountTime
)
{
public
DbExecuteImpl
(
JdbcTemplate
jdbcTemplate
,
Db
Execute
PrintSql
printSql
,
ConfigDb
configDb
,
LogCountTime
logCountTime
)
{
this
.
jdbcTemplate
=
jdbcTemplate
;
this
.
jdbcTemplate
=
jdbcTemplate
;
this
.
printSql
=
printSql
;
this
.
printSql
=
printSql
;
this
.
configDb
=
configDb
;
this
.
configDb
=
configDb
;
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbExecutePrintSql.java
0 → 100755
View file @
1c1991d3
package
com
.
yanzuoguang
.
db
.
impl
;
import
com.yanzuoguang.db.DbPrintSql
;
import
com.yanzuoguang.db.DbPrintSqlExcept
;
import
com.yanzuoguang.util.log.Log
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
/**
* 打印SQL语句日志工具类
*
* @author 颜佐光
*/
@Component
public
class
DbExecutePrintSql
{
private
final
List
<
DbPrintSql
>
dbPrintSqlList
;
private
final
List
<
DbPrintSqlExcept
>
dbPrintSqlExceptList
;
public
DbExecutePrintSql
(
List
<
DbPrintSql
>
dbPrintSqlList
,
List
<
DbPrintSqlExcept
>
dbPrintSqlExceptList
)
{
this
.
dbPrintSqlList
=
dbPrintSqlList
;
this
.
dbPrintSqlExceptList
=
dbPrintSqlExceptList
;
}
/**
* 打印SQL语句
*
* @param sqlInfo sql语句嘻嘻你
* @param time 执行的时间
* @param row SQL语句
*/
public
void
print
(
SqlInfo
sqlInfo
,
long
time
,
int
row
)
{
try
{
for
(
DbPrintSqlExcept
except
:
dbPrintSqlExceptList
)
{
if
(
except
.
isPrintExcept
(
sqlInfo
,
time
,
row
))
{
return
;
}
}
dbPrintSqlList
.
forEach
(
k
->
k
.
printSql
(
sqlInfo
,
time
,
row
)
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
DbExecutePrintSql
.
class
,
ex
);
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
→
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql
Default
.java
100755 → 100644
View file @
1c1991d3
package
com
.
yanzuoguang
.
db
.
impl
;
package
com
.
yanzuoguang
.
db
.
impl
;
import
com.yanzuoguang.db.
ConfigDb
;
import
com.yanzuoguang.db.
DbPrintSql
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.log.Log
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
/**
/**
* 打印S
QL语句日志工具类
* 打印S
ql语句
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
@Component
@Component
public
class
DbPrintSql
{
public
class
DbPrintSql
Default
implements
DbPrintSql
{
private
final
ConfigDb
configDb
;
@Override
public
void
printSql
(
SqlInfo
sqlInfo
,
long
time
,
int
row
)
{
public
DbPrintSql
(
ConfigDb
configDb
)
{
String
sql
=
getStringSql
(
sqlInfo
.
getSql
(),
sqlInfo
.
getParas
());
this
.
configDb
=
configDb
;
// 打印SQL语句
String
tag
=
String
.
format
(
"%d row %d ms %s.%s"
,
row
,
time
,
sqlInfo
.
getTargetClass
().
getSimpleName
(),
sqlInfo
.
getSqlName
());
Log
.
infoTag
(
DbExecutePrintSql
.
class
,
tag
,
sql
);
}
}
/**
/**
...
@@ -59,31 +61,4 @@ public class DbPrintSql {
...
@@ -59,31 +61,4 @@ public class DbPrintSql {
return
sb
.
toString
();
return
sb
.
toString
();
}
}
/**
* 打印SQL语句
*
* @param sqlInfo sql语句嘻嘻你
* @param time 执行的时间
* @param row SQL语句
*/
public
void
print
(
SqlInfo
sqlInfo
,
long
time
,
int
row
)
{
try
{
// 日志表忽略打印
if
(!
configDb
.
isPrintSql
())
{
return
;
}
if
(!
StringHelper
.
isEmpty
(
configDb
.
getPrintSqlFilter
()))
{
if
(
sqlInfo
.
getSql
().
matches
(
configDb
.
getPrintSqlFilter
()))
{
return
;
}
}
String
sql
=
getStringSql
(
sqlInfo
.
getSql
(),
sqlInfo
.
getParas
());
// 打印SQL语句
String
tag
=
String
.
format
(
"%d row %d ms %s.%s"
,
row
,
time
,
sqlInfo
.
getTargetClass
().
getSimpleName
(),
sqlInfo
.
getSqlName
());
Log
.
infoTag
(
DbPrintSql
.
class
,
tag
,
sql
);
}
catch
(
Exception
ex
)
{
Log
.
error
(
DbPrintSql
.
class
,
ex
);
}
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSqlExceptDefault.java
0 → 100644
View file @
1c1991d3
package
com
.
yanzuoguang
.
db
.
impl
;
import
com.yanzuoguang.db.ConfigDb
;
import
com.yanzuoguang.db.DbPrintSqlExcept
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
/**
* 配置打印过滤
*
* @author 颜佐光
*/
@Component
@Order
(-
1
)
public
class
DbPrintSqlExceptDefault
implements
DbPrintSqlExcept
{
private
final
ConfigDb
configDb
;
public
DbPrintSqlExceptDefault
(
ConfigDb
configDb
)
{
this
.
configDb
=
configDb
;
}
@Override
public
boolean
isPrintExcept
(
SqlInfo
sqlInfo
,
long
time
,
int
row
)
{
// 日志表忽略打印
if
(!
configDb
.
isPrintSql
())
{
return
true
;
}
if
(
StringHelper
.
isEmpty
(
configDb
.
getPrintSqlFilter
()))
{
return
false
;
}
return
sqlInfo
.
getSql
().
matches
(
configDb
.
getPrintSqlFilter
())
||
sqlInfo
.
getSqlName
().
matches
(
configDb
.
getPrintSqlFilter
());
}
}
yzg-util-db/src/test/java/TestDbPrintSql.java
→
yzg-util-db/src/test/java/TestDb
Execute
PrintSql.java
View file @
1c1991d3
...
@@ -2,18 +2,17 @@ import com.yanzuoguang.dao.DaoConst;
...
@@ -2,18 +2,17 @@ import com.yanzuoguang.dao.DaoConst;
import
com.yanzuoguang.dao.impl.SqlData
;
import
com.yanzuoguang.dao.impl.SqlData
;
import
com.yanzuoguang.dao.impl.TableSqlCache
;
import
com.yanzuoguang.dao.impl.TableSqlCache
;
import
com.yanzuoguang.dao.impl.TableStruct
;
import
com.yanzuoguang.dao.impl.TableStruct
;
import
com.yanzuoguang.db.ConfigDb
;
import
com.yanzuoguang.db.impl.DbPrintSqlDefault
;
import
com.yanzuoguang.db.impl.DbPrintSql
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
public
class
TestDbPrintSql
{
public
class
TestDb
Execute
PrintSql
{
@Test
@Test
public
void
test
()
{
public
void
test
()
{
DbPrintSql
printSql
=
new
DbPrintSql
(
new
ConfigDb
()
);
DbPrintSql
Default
printSql
=
new
DbPrintSqlDefault
(
);
String
stringSql
=
printSql
.
getStringSql
(
"select * from where id = ? AND name = ? and removeFlag = 0 "
,
"1"
);
String
stringSql
=
printSql
.
getStringSql
(
"select * from where id = ? AND name = ? and removeFlag = 0 "
,
"1"
);
System
.
out
.
println
(
stringSql
);
System
.
out
.
println
(
stringSql
);
}
}
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/dao/impl/DbPrintExceptByMessage.java
0 → 100644
View file @
1c1991d3
package
com
.
yanzuoguang
.
mq
.
dao
.
impl
;
import
com.yanzuoguang.db.DbPrintSqlExcept
;
import
com.yanzuoguang.db.impl.SqlInfo
;
import
org.springframework.stereotype.Component
;
/**
* 过滤Sql语句打印消息
*
* @author 颜佐光
*/
@Component
public
class
DbPrintExceptByMessage
implements
DbPrintSqlExcept
{
/**
* 当前包的Sql语句不打印
*/
private
final
Package
aPackage
=
DbPrintExceptByMessage
.
class
.
getPackage
();
@Override
public
boolean
isPrintExcept
(
SqlInfo
sqlInfo
,
long
time
,
int
row
)
{
if
(
sqlInfo
==
null
||
sqlInfo
.
getTargetClass
().
getPackage
()
==
aPackage
)
{
return
true
;
}
return
false
;
}
}
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