-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobDaoImpl.java
More file actions
172 lines (145 loc) · 6.22 KB
/
Copy pathJobDaoImpl.java
File metadata and controls
172 lines (145 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package com.caozj.dao.impl;
import java.util.List;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.caozj.dao.JobDao;
import com.caozj.framework.util.jdbc.Jdbc;
import com.caozj.framework.util.jdbc.Pager;
import com.caozj.framework.util.jdbc.StatementParameter;
import com.caozj.model.Job;
/**
* 任务 Dao实现类
*
* @author caozj
*
*/
@Repository
public class JobDaoImpl implements JobDao {
@Autowired
private Jdbc jdbc;
private static final String table = "job";
@Override
public void add(Job job) {
String sql = "insert into " + table
+ "( name, description, cronExpression, startTime, endTime, exeCount, maxExeCount, status, className, methodName, delayTime, intervalTime) values(?,?,?,?,?,?,?,?,?,?,?,?)";
Number id = jdbc.updateForGeneratedKey(sql, job.getName(), job.getDescription(),
job.getCronExpression(), job.getStartTime(), job.getEndTime(), job.getExeCount(),
job.getMaxExeCount(), job.getStatus(), job.getClassName(), job.getMethodName(),
job.getDelayTime(), job.getIntervalTime());
job.setId(NumberUtils.toInt(id + ""));
}
@Override
public void update(Job job) {
String sql = "update " + table
+ " set name = ? , description = ? , cronExpression = ? , startTime = ? , endTime = ? , exeCount = ? , maxExeCount = ? , status = ? , className = ? , methodName = ? , delayTime = ? , intervalTime = ? where id = ? ";
jdbc.updateForBoolean(sql, job.getName(), job.getDescription(), job.getCronExpression(),
job.getStartTime(), job.getEndTime(), job.getExeCount(), job.getMaxExeCount(),
job.getStatus(), job.getClassName(), job.getMethodName(), job.getDelayTime(),
job.getIntervalTime(), job.getId());
}
@Override
public void updateWithoutExeCount(Job job) {
String sql = "update " + table
+ " set name = ? , description = ? , cronExpression = ? , startTime = ? , endTime = ? ,maxExeCount = ? , status = ? , className = ? , methodName = ? , delayTime = ? , intervalTime = ? where id = ? ";
jdbc.updateForBoolean(sql, job.getName(), job.getDescription(), job.getCronExpression(),
job.getStartTime(), job.getEndTime(), job.getMaxExeCount(), job.getStatus(),
job.getClassName(), job.getMethodName(), job.getDelayTime(), job.getIntervalTime(),
job.getId());
}
@Override
public void delete(int id) {
String sql = "delete from " + table + " where id = ? ";
jdbc.updateForBoolean(sql, id);
}
@Override
public List<Job> page(Pager page) {
String sql = "select * from " + table;
return jdbc.queryForPage(sql, Job.class, page);
}
@Override
public List<Job> listAll() {
String sql = "select * from " + table;
return jdbc.queryForList(sql, Job.class);
}
@Override
public int count() {
String sql = "select count(*) from " + table;
return jdbc.queryForInt(sql);
}
@Override
public Job get(int id) {
String sql = "select * from " + table + " where id = ? ";
return jdbc.query(sql, Job.class, id);
}
@Override
public Job getBy(String field, Object value) {
String sql = "select * from " + table + " where " + field + " = ? ";
return jdbc.query(sql, Job.class, value);
}
@Override
public Job getByAnd(String field1, Object value1, String field2, Object value2) {
String sql = "select * from " + table + " where " + field1 + " = ? and " + field2 + " = ? ";
return jdbc.query(sql, Job.class, value1, value2);
}
@Override
public Job getByOr(String field1, Object value1, String field2, Object value2) {
String sql = "select * from " + table + " where " + field1 + " = ? or " + field2 + " = ? ";
return jdbc.query(sql, Job.class, value1, value2);
}
@Override
public List<Job> listBy(String field, Object value) {
String sql = "select * from " + table + " where " + field + " = ? ";
return jdbc.queryForList(sql, Job.class, value);
}
@Override
public List<Job> listByAnd(String field1, Object value1, String field2, Object value2) {
String sql = "select * from " + table + " where " + field1 + " = ? and " + field2 + " = ? ";
return jdbc.queryForList(sql, Job.class, value1, value2);
}
@Override
public List<Job> listByOr(String field1, Object value1, String field2, Object value2) {
String sql = "select * from " + table + " where " + field1 + " = ? or " + field2 + " = ? ";
return jdbc.queryForList(sql, Job.class, value1, value2);
}
@Override
public List<Job> pageBy(String field, Object value, Pager page) {
String sql = "select * from " + table + " where " + field + " = ? ";
StatementParameter param = new StatementParameter();
param.set(value);
return jdbc.queryForPage(sql, Job.class, page, param);
}
@Override
public List<Job> pageByAnd(String field1, Object value1, String field2, Object value2,
Pager page) {
String sql = "select * from " + table + " where " + field1 + " = ? and " + field2 + " = ? ";
StatementParameter param = new StatementParameter();
param.set(value1);
param.set(value2);
return jdbc.queryForPage(sql, Job.class, page, param);
}
@Override
public List<Job> pageByOr(String field1, Object value1, String field2, Object value2,
Pager page) {
String sql = "select * from " + table + " where " + field1 + " = ? or " + field2 + " = ? ";
StatementParameter param = new StatementParameter();
param.set(value1);
param.set(value2);
return jdbc.queryForPage(sql, Job.class, page, param);
}
@Override
public int countBy(String field, Object value) {
String sql = "select count(*) from " + table + " where " + field + " = ? ";
return jdbc.queryForInt(sql, value);
}
@Override
public void updateStatus(int id, String status) {
String sql = "update " + table + " set status = ? where id = ? ";
jdbc.updateForBoolean(sql, status, id);
}
@Override
public void incrExeCount(int id) {
String sql = "update " + table + " set exeCount = exeCount + 1 where id = ? ";
jdbc.updateForBoolean(sql, id);
}
}