1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.push.entity;
17
18 import java.io.Serializable;
19 import java.sql.Timestamp;
20
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.GeneratedValue;
24 import javax.persistence.GenerationType;
25 import javax.persistence.Id;
26 import javax.persistence.NamedQueries;
27 import javax.persistence.NamedQuery;
28 import javax.persistence.Table;
29 import javax.persistence.Version;
30
31
32
33
34
35
36
37
38 @NamedQueries({
39
40
41
42 @NamedQuery(
43 name = "PushDeviceTuple.findUnsent",
44 query="SELECT t FROM PushDeviceTuple t WHERE t.status = 0 OR t.status = 2"
45 ),
46
47
48
49 @NamedQuery(
50 name = "PushDeviceTuple.findPushDevices",
51 query="SELECT d from PushDeviceTuple t, Device d WHERE t.deviceId = d.id and t.pushId = :pushId"
52 ),
53 @NamedQuery(
54 name="PushDeviceTuple.countUnsent",
55 query="select count(t) from PushDeviceTuple t where t.status = 0"
56 ),
57 @NamedQuery(
58 name="PushDeviceTuple.findTuplesForPush",
59 query="select t from PushDeviceTuple t where t.pushId = :pushId"
60 ),
61 @NamedQuery(
62 name="PushDeviceTuple.deleteForStatus",
63 query="DELETE PushDeviceTuple t WHERE t.status = :status"
64 )
65 })
66 @Entity
67 @Table(name="KME_PSHDEV_T")
68 public class PushDeviceTuple implements Serializable {
69
70
71 public static final int STATUS_PENDING = 0;
72
73
74 public static final int STATUS_SENT = 1;
75
76
77 public static final int STATUS_WAITING_RETRY = 2;
78
79
80
81
82 public static final int STATUS_FAILED = 3;
83
84
85 private static final long serialVersionUID = 9083352553678796701L;
86
87
88
89
90 @Id
91 @GeneratedValue(strategy = GenerationType.TABLE)
92 @Column(name="ID")
93 private Long tupleId;
94
95
96
97
98 @Column(name="PID")
99 private Long pushId;
100
101
102
103
104 @Column(name="DID")
105 private Long deviceId;
106
107
108
109
110 @Column(name="PST_TS")
111 private Timestamp postedTimestamp;
112
113
114
115
116 @Column(name="STATUS")
117 private int status;
118
119
120
121
122 @Version
123 @Column(name="VER_NBR")
124 private Long versionNumber;
125
126
127
128
129 public PushDeviceTuple(){}
130
131
132
133
134
135 public Long getId() {
136 return tupleId;
137 }
138
139
140
141
142
143
144 public void setId(Long tupleId) {
145 this.tupleId = tupleId;
146 }
147
148
149
150
151
152
153
154 public Long getPushId() {
155 return pushId;
156 }
157
158
159
160
161
162
163
164
165 public void setPushId(Long pushId) {
166 this.pushId = pushId;
167 }
168
169
170
171
172
173
174 public Long getDeviceId() {
175 return deviceId;
176 }
177
178
179
180
181
182
183 public void setDeviceId(Long deviceId) {
184 this.deviceId = deviceId;
185 }
186
187
188
189
190
191
192 public Timestamp getPostedTimestamp() {
193 return postedTimestamp;
194 }
195
196
197
198
199
200
201 public void setPostedTimestamp(Timestamp postedTimestamp) {
202 this.postedTimestamp = postedTimestamp;
203 }
204
205
206
207
208
209
210 public void setStatus(int status){
211 this.status = status;
212 }
213
214
215
216
217
218 public int getStatus(){
219 return this.status;
220 }
221
222
223
224
225
226
227 public void setSent() {
228 this.setStatus(STATUS_SENT);
229 }
230
231
232
233
234
235
236 public boolean isSent() {
237 return this.status == STATUS_SENT;
238 }
239
240
241
242
243
244
245
246 public boolean isWaitingRetry(){
247 return this.status == STATUS_WAITING_RETRY;
248 }
249
250
251
252
253
254
255 public void setWaitingRetry(){
256 this.setStatus(STATUS_WAITING_RETRY);
257 }
258
259
260
261
262
263
264 public Long getVersionNumber() {
265 return versionNumber;
266 }
267
268
269
270
271
272
273 public void setVersionNumber(Long versionNumber) {
274 this.versionNumber = versionNumber;
275 }
276
277
278
279
280
281 @Override
282 public String toString() {
283 String newline = "\r\n";
284
285 String str = newline + "ID: " + this.getId();
286 str = str + newline + "PushID: " + this.getPushId();
287 str = str + newline + "DeviceID: " + this.getDeviceId();
288 str = str + newline + "Sent: " + (this.isSent() ? "True" : "False");
289 str = str + newline + "Timestamp: " + this.getPostedTimestamp();
290 return str;
291 }
292
293
294 }