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
92e9827a
Commit
92e9827a
authored
May 19, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
92bed357
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
DbExecuteImpl.java
.../src/main/java/com/yanzuoguang/db/impl/DbExecuteImpl.java
+13
-12
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbExecuteImpl.java
View file @
92e9827a
...
@@ -11,7 +11,6 @@ import org.springframework.jdbc.core.RowCallbackHandler;
...
@@ -11,7 +11,6 @@ import org.springframework.jdbc.core.RowCallbackHandler;
import
org.springframework.jdbc.support.rowset.SqlRowSet
;
import
org.springframework.jdbc.support.rowset.SqlRowSet
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -69,7 +68,7 @@ public class DbExecuteImpl implements DbExecute {
...
@@ -69,7 +68,7 @@ public class DbExecuteImpl implements DbExecute {
* @param <T> 返回的集合的类型
* @param <T> 返回的集合的类型
*/
*/
@Override
@Override
public
<
T
extends
Object
>
void
query
(
Class
<?>
targetClass
,
Class
<
T
>
cls
,
DbRow
<
T
>
rowHandle
,
String
sqlName
,
String
sql
,
Object
...
paras
)
{
public
<
T
>
void
query
(
Class
<?>
targetClass
,
Class
<
T
>
cls
,
DbRow
<
T
>
rowHandle
,
String
sqlName
,
String
sql
,
Object
...
paras
)
{
SqlInfo
sqlInfo
=
new
SqlInfo
(
targetClass
,
sqlName
,
sql
,
paras
);
SqlInfo
sqlInfo
=
new
SqlInfo
(
targetClass
,
sqlName
,
sql
,
paras
);
executeSql
(
sqlInfo
,
(
row
,
start
)
->
{
executeSql
(
sqlInfo
,
(
row
,
start
)
->
{
RowCallbackHandler
rowCallbackHandler
=
rs
->
{
RowCallbackHandler
rowCallbackHandler
=
rs
->
{
...
@@ -94,14 +93,11 @@ public class DbExecuteImpl implements DbExecute {
...
@@ -94,14 +93,11 @@ public class DbExecuteImpl implements DbExecute {
* @return 集合
* @return 集合
*/
*/
@Override
@Override
public
<
T
extends
Object
>
List
<
T
>
query
(
Class
<?>
targetClass
,
Class
<
T
>
cls
,
String
sqlName
,
String
sql
,
Object
...
paras
)
{
public
<
T
>
List
<
T
>
query
(
Class
<?>
targetClass
,
Class
<
T
>
cls
,
String
sqlName
,
String
sql
,
Object
...
paras
)
{
SqlInfo
sqlInfo
=
new
SqlInfo
(
targetClass
,
sqlName
,
sql
,
paras
);
SqlInfo
sqlInfo
=
new
SqlInfo
(
targetClass
,
sqlName
,
sql
,
paras
);
Ref
<
List
<
T
>>
ret
=
new
Ref
<>(
null
);
Ref
<
List
<
T
>>
ret
=
new
Ref
<>(
null
);
executeSql
(
sqlInfo
,
(
row
,
start
)
->
{
executeSql
(
sqlInfo
,
(
row
,
start
)
->
{
ret
.
value
=
this
.
getJdbc
().
query
(
sqlInfo
.
getSql
(),
sqlInfo
.
getParas
(),
AllBeanRowMapper
.
getInstance
(
cls
,
configDb
));
ret
.
value
=
this
.
getJdbc
().
query
(
sqlInfo
.
getSql
(),
sqlInfo
.
getParas
(),
AllBeanRowMapper
.
getInstance
(
cls
,
configDb
));
if
(
ret
.
value
==
null
)
{
ret
.
value
=
new
ArrayList
<
T
>();
}
row
.
value
=
ret
.
value
.
size
();
row
.
value
=
ret
.
value
.
size
();
});
});
return
ret
.
value
;
return
ret
.
value
;
...
@@ -151,23 +147,28 @@ public class DbExecuteImpl implements DbExecute {
...
@@ -151,23 +147,28 @@ public class DbExecuteImpl implements DbExecute {
* @param sqlFunction 执行函数,传入参数为影响的行数引用和开始执行时间
* @param sqlFunction 执行函数,传入参数为影响的行数引用和开始执行时间
*/
*/
private
void
executeSql
(
SqlInfo
sqlInfo
,
DbSqlFunction
<
Ref
<
Integer
>,
Long
>
sqlFunction
)
{
private
void
executeSql
(
SqlInfo
sqlInfo
,
DbSqlFunction
<
Ref
<
Integer
>,
Long
>
sqlFunction
)
{
Ref
<
Integer
>
row
=
new
Ref
<>(
0
);
// 开始记录日志
String
fullUrl
=
String
.
format
(
"Sql:%s:%s"
,
sqlInfo
.
getTargetClass
().
getSimpleName
(),
sqlInfo
.
getSqlName
());
logCountTime
.
start
(
fullUrl
);
// 开始时间
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
Ref
<
Integer
>
row
=
new
Ref
<>(
0
);
sqlInfo
.
setSql
(
this
.
handleParas
(
sqlInfo
.
getSql
()));
sqlInfo
.
setSql
(
this
.
handleParas
(
sqlInfo
.
getSql
()));
String
fullUrl
=
String
.
format
(
"Sql:%s:%s"
,
sqlInfo
.
getTargetClass
().
getSimpleName
(),
sqlInfo
.
getSqlName
());
logCountTime
.
start
(
fullUrl
);
boolean
isError
=
false
;
boolean
isError
=
false
;
try
{
try
{
YzgTimeout
.
timeOut
(
sqlInfo
.
getTargetClass
(),
sqlInfo
.
getSqlName
(),
()
->
{
YzgTimeout
.
timeOut
(
sqlInfo
.
getTargetClass
(),
sqlInfo
.
getSqlName
(),
()
->
sqlFunction
.
accept
(
row
,
start
);
sqlFunction
.
accept
(
row
,
start
)
}
);
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
isError
=
true
;
isError
=
true
;
throw
ex
;
throw
ex
;
}
finally
{
}
finally
{
// 写入日志
long
time
=
System
.
currentTimeMillis
()
-
start
;
long
time
=
System
.
currentTimeMillis
()
-
start
;
logCountTime
.
finish
(
fullUrl
,
time
,
isError
);
logCountTime
.
finish
(
fullUrl
,
time
,
isError
);
// 打印sql语句
printSql
.
print
(
sqlInfo
,
time
,
row
.
value
);
printSql
.
print
(
sqlInfo
,
time
,
row
.
value
);
}
}
}
}
...
...
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