1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging;
17
18 import org.kuali.rice.core.api.config.CoreConfigHelper;
19 import org.kuali.rice.core.api.util.RiceUtilities;
20 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
21 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
22 import org.kuali.rice.ksb.api.messaging.AsynchronousCall;
23 import org.kuali.rice.ksb.service.KSBServiceLocator;
24 import org.kuali.rice.ksb.util.KSBConstants;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.Id;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.Table;
33 import javax.persistence.Transient;
34 import javax.persistence.Version;
35 import java.sql.Timestamp;
36
37
38
39
40
41
42 @Entity
43 @Table(name="KRSB_MSG_QUE_T")
44
45 @NamedQueries({
46 @NamedQuery(name="PersistedMessage.FindAll", query="select pm from PersistedMessageBO pm"),
47 @NamedQuery(name="PersistedMessage.FindByServiceName", query="select pm from PersistedMessage pm where pm.serviceName = :serviceName and pm.methodName = :methodName"),
48 @NamedQuery(name="PersistedMessage.GetNextDocuments", query="select pm from PersistedMessage pm where pm.applicationId = :applicationId and pm.queueStatus <> :queueStatus and pm.ipNumber = :ipNumber order by queuePriority asc, routeQueueId asc, queueDate asc")
49 })
50 public class PersistedMessageBO implements PersistedMessage {
51
52 private static final long serialVersionUID = -7047766894738304195L;
53
54 @Id
55 @GeneratedValue(generator="KRSB_MSG_QUE_S")
56 @Column(name="MSG_QUE_ID")
57 private Long routeQueueId;
58 @Column(name="PRIO")
59 private Integer queuePriority;
60 @Column(name="STAT_CD")
61 private String queueStatus;
62 @Column(name="DT")
63 private Timestamp queueDate;
64 @Column(name="EXP_DT")
65 private Timestamp expirationDate;
66 @Column(name="RTRY_CNT")
67 private Integer retryCount;
68 @Version
69 @Column(name="VER_NBR")
70 private Integer lockVerNbr;
71 @Column(name="IP_NBR")
72 private String ipNumber;
73 @Column(name="SVC_NM")
74 private String serviceName;
75 @Column(name="APPL_ID")
76 private String applicationId;
77 @Column(name="SVC_MTHD_NM")
78 private String methodName;
79 @Transient
80 private AsynchronousCall methodCall;
81 @Transient
82 private PersistedMessagePayload payload;
83 @Column(name="APP_VAL_ONE")
84 private String value1;
85 @Column(name="APP_VAL_TWO")
86 private String value2;
87
88 public PersistedMessageBO() {
89
90 }
91
92 public static PersistedMessageBO buildMessage(ServiceConfiguration serviceConfiguration, AsynchronousCall methodCall) {
93 PersistedMessageBO message = new PersistedMessageBO();
94 message.setPayload(new PersistedMessagePayload(methodCall, message));
95 message.setIpNumber(RiceUtilities.getIpNumber());
96 message.setServiceName(serviceConfiguration.getServiceName().toString());
97 message.setQueueDate(new Timestamp(System.currentTimeMillis()));
98 if (serviceConfiguration.getPriority() == null) {
99 message.setQueuePriority(KSBConstants.ROUTE_QUEUE_DEFAULT_PRIORITY);
100 } else {
101 message.setQueuePriority(serviceConfiguration.getPriority());
102 }
103 message.setQueueStatus(KSBConstants.ROUTE_QUEUE_QUEUED);
104 message.setRetryCount(0);
105 if (serviceConfiguration.getMillisToLive() > 0) {
106 message.setExpirationDate(new Timestamp(System.currentTimeMillis() + serviceConfiguration.getMillisToLive()));
107 }
108 message.setApplicationId(CoreConfigHelper.getApplicationId());
109 message.setMethodName(methodCall.getMethodName());
110 return message;
111 }
112
113
114 public void beforeInsert(){
115 OrmUtils.populateAutoIncValue(this, KSBServiceLocator.getMessageEntityManagerFactory().createEntityManager());
116 }
117
118 @Override
119 public String getApplicationId() {
120 return this.applicationId;
121 }
122
123 public void setApplicationId(String applicationId) {
124 this.applicationId = applicationId;
125 }
126
127 @Override
128 public String getIpNumber() {
129 return this.ipNumber;
130 }
131
132 public void setIpNumber(String ipNumber) {
133 this.ipNumber = ipNumber;
134 }
135
136 @Override
137 public Timestamp getQueueDate() {
138 return this.queueDate;
139 }
140
141 @Override
142 public Integer getQueuePriority() {
143 return this.queuePriority;
144 }
145
146 @Override
147 public String getQueueStatus() {
148 return this.queueStatus;
149 }
150
151 @Override
152 public Integer getRetryCount() {
153 return this.retryCount;
154 }
155
156
157 public void setQueueDate(Timestamp timestamp) {
158 this.queueDate = timestamp;
159 }
160
161 public void setQueuePriority(Integer integer) {
162 this.queuePriority = integer;
163 }
164
165 public void setQueueStatus(String string) {
166 this.queueStatus = string;
167 }
168
169 public void setRetryCount(Integer integer) {
170 this.retryCount = integer;
171 }
172
173
174 public Integer getLockVerNbr() {
175 return this.lockVerNbr;
176 }
177
178 public void setLockVerNbr(Integer lockVerNbr) {
179 this.lockVerNbr = lockVerNbr;
180 }
181
182 @Override
183 public Long getRouteQueueId() {
184 return this.routeQueueId;
185 }
186
187 public void setRouteQueueId(Long queueSequence) {
188 this.routeQueueId = queueSequence;
189 }
190
191 @Override
192 public String getServiceName() {
193 return this.serviceName;
194 }
195
196 public void setServiceName(String serviceName) {
197 this.serviceName = serviceName;
198 }
199
200 public String toString() {
201 return "[RouteQueue: " + ", routeQueueId=" + this.routeQueueId + ", ipNumber=" + this.ipNumber
202 + "applicationId=" + this.applicationId + ", serviceName=" + this.serviceName + ", methodName=" + methodName
203 + ", queueStatus=" + this.queueStatus + ", queuePriority=" + this.queuePriority
204 + ", queueDate=" + this.queueDate + "]";
205 }
206
207 @Override
208 public AsynchronousCall getMethodCall() {
209 return this.methodCall;
210 }
211
212 public void setMethodCall(AsynchronousCall methodCall) {
213 this.methodCall = methodCall;
214 }
215
216 @Override
217 public String getMethodName() {
218 return this.methodName;
219 }
220
221 public void setMethodName(String methodName) {
222 this.methodName = methodName;
223 }
224
225 @Override
226 public Timestamp getExpirationDate() {
227 return this.expirationDate;
228 }
229
230 public void setExpirationDate(Timestamp expirationDate) {
231 this.expirationDate = expirationDate;
232 }
233
234 @Override
235 public PersistedMessagePayload getPayload() {
236 if (this.payload == null) {
237 if (this.getRouteQueueId() == null) {
238 return null;
239 } this.payload = KSBServiceLocator.getMessageQueueService().findByPersistedMessageByRouteQueueId(this.getRouteQueueId());
240 }
241 return this.payload;
242 }
243
244 public void setPayload(PersistedMessagePayload payload) {
245 this.payload = payload;
246 }
247
248 @Override
249 public String getValue1() {
250 return this.value1;
251 }
252
253 public void setValue1(String value1) {
254 this.value1 = value1;
255 }
256
257 @Override
258 public String getValue2() {
259 return this.value2;
260 }
261
262 public void setValue2(String value2) {
263 this.value2 = value2;
264 }
265
266 }