Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
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
曲欣亮
common
Commits
61044206
Commit
61044206
authored
Mar 04, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
99c11b6b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
0 deletions
+37
-0
JdbcTemplate.java
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
+8
-0
AbstractDialect.java
...n/java/com/egolm/common/jdbc/dialect/AbstractDialect.java
+27
-0
Dialect.java
src/main/java/com/egolm/common/jdbc/dialect/Dialect.java
+2
-0
No files found.
src/main/java/com/egolm/common/jdbc/JdbcTemplate.java
View file @
61044206
...
...
@@ -285,6 +285,14 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
return
delete_count
;
}
public
int
batchDelete
(
Object
...
objs
)
{
Sql
desc
=
dialect
.
argsDelete
(
obj
);
}
public
int
batchDelete
(
List
<
Object
>
objs
)
{
return
this
.
batchDelete
(
objs
.
toArray
());
}
public
int
deleteByField
(
Object
obj
,
String
...
byFields
)
{
Desc
desc
=
dialect
.
getDesc
(
obj
.
getClass
());
Map
<
String
,
Object
>
columnsMap
=
dialect
.
getColumnValueByField
(
obj
,
byFields
);
...
...
src/main/java/com/egolm/common/jdbc/dialect/AbstractDialect.java
View file @
61044206
...
...
@@ -124,6 +124,33 @@ public abstract class AbstractDialect implements Dialect {
return
new
Sql
(
sql
,
args
.
toArray
());
}
public
Sql
batchDelete
(
Object
[]
objs
)
{
if
(
objs
.
length
>
0
)
{
Class
<?>
clz
=
objs
[
0
].
getClass
();
Desc
i_table
=
new
Desc
(
clz
);
String
table_name
=
i_table
.
getName
();
String
[]
pk_fields
=
i_table
.
getFieldPkNames
();
String
[]
pk_columns
=
i_table
.
getColumnPkNames
();
Object
[][]
vals
=
new
Object
[
objs
.
length
][];
for
(
int
k
=
0
;
k
<
objs
.
length
;
k
++)
{
Object
obj
=
objs
[
k
];
List
<
Object
>
args
=
new
ArrayList
<
Object
>();
for
(
int
i
=
0
;
i
<
pk_fields
.
length
;
i
++)
{
Object
arg
=
ReflexUtil
.
readField
(
pk_fields
[
i
],
obj
);
if
(
arg
!=
null
&&
arg
instanceof
Date
)
{
arg
=
new
Timestamp
(((
Date
)
arg
).
getTime
());
}
args
.
add
(
arg
);
}
vals
[
k
]
=
args
.
toArray
();
}
String
sql
=
"delete from "
+
table_name
+
StringUtil
.
join
(
" = ? and "
,
" where "
,
" = ?"
,
pk_columns
);
return
new
Sql
(
sql
,
vals
);
}
else
{
throw
new
RuntimeException
(
"DataArray can't be null"
);
}
}
public
Sql
argsUpdate
(
Object
obj
)
{
Class
<?>
clz
=
obj
.
getClass
();
Desc
i_table
=
new
Desc
(
clz
);
...
...
src/main/java/com/egolm/common/jdbc/dialect/Dialect.java
View file @
61044206
...
...
@@ -60,6 +60,8 @@ public interface Dialect {
*/
public
Sql
argsDelete
(
Object
obj
);
public
Sql
batchDelete
(
Object
[]
obj
);
/**
* 生成删除SQL语句
* @param tableName
...
...
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