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 })
62 @Entity
63 @Table(name="KME_PSHDEV_T")
64 public class PushDeviceTuple implements Serializable {
65
66
67 public static final int STATUS_PENDING = 0;
68
69
70 public static final int STATUS_SENT = 1;
71
72
73 public static final int STATUS_WAITING_RETRY = 2;
74
75
76
77
78 public static final int STATUS_FAILED = 3;
79
80
81 private static final long serialVersionUID = 9083352553678796701L;
82
83
84
85
86 @Id
87 @GeneratedValue(strategy = GenerationType.TABLE)
88 @Column(name="ID")
89 private Long tupleId;
90
91
92
93
94 @Column(name="PID")
95 private Long pushId;
96
97
98
99
100 @Column(name="DID")
101 private Long deviceId;
102
103
104
105
106 @Column(name="PST_TS")
107 private Timestamp postedTimestamp;
108
109
110
111
112 @Column(name="STATUS")
113 private int status;
114
115
116
117
118 @Version
119 @Column(name="VER_NBR")
120 private Long versionNumber;
121
122
123
124
125 public PushDeviceTuple(){}
126
127
128
129
130
131 public Long getId() {
132 return tupleId;
133 }
134
135
136
137
138
139
140 public void setId(Long tupleId) {
141 this.tupleId = tupleId;
142 }
143
144
145
146
147
148
149
150 public Long getPushId() {
151 return pushId;
152 }
153
154
155
156
157
158
159
160
161 public void setPushId(Long pushId) {
162 this.pushId = pushId;
163 }
164
165
166
167
168
169
170 public Long getDeviceId() {
171 return deviceId;
172 }
173
174
175
176
177
178
179 public void setDeviceId(Long deviceId) {
180 this.deviceId = deviceId;
181 }
182
183
184
185
186
187
188 public Timestamp getPostedTimestamp() {
189 return postedTimestamp;
190 }
191
192
193
194
195
196
197 public void setPostedTimestamp(Timestamp postedTimestamp) {
198 this.postedTimestamp = postedTimestamp;
199 }
200
201
202
203
204
205
206 public void setStatus(int status){
207 this.status = status;
208 }
209
210
211
212
213
214 public int getStatus(){
215 return this.status;
216 }
217
218
219
220
221
222
223 public void setSent() {
224 this.setStatus(STATUS_SENT);
225 }
226
227
228
229
230
231
232 public boolean isSent() {
233 return this.status == STATUS_SENT;
234 }
235
236
237
238
239
240
241
242 public boolean isWaitingRetry(){
243 return this.status == STATUS_WAITING_RETRY;
244 }
245
246
247
248
249
250
251 public void setWaitingRetry(){
252 this.setStatus(STATUS_WAITING_RETRY);
253 }
254
255
256
257
258
259
260 public Long getVersionNumber() {
261 return versionNumber;
262 }
263
264
265
266
267
268
269 public void setVersionNumber(Long versionNumber) {
270 this.versionNumber = versionNumber;
271 }
272
273
274
275
276
277 @Override
278 public String toString() {
279 String newline = "\r\n";
280
281 String str = newline + "ID: " + this.getId();
282 str = str + newline + "PushID: " + this.getPushId();
283 str = str + newline + "DeviceID: " + this.getDeviceId();
284 str = str + newline + "Sent: " + (this.isSent() ? "True" : "False");
285 str = str + newline + "Timestamp: " + this.getPostedTimestamp();
286 return str;
287 }
288
289
290 }