1
14
15 package com.liferay.portlet.messageboards.model.impl;
16
17 import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portal.kernel.util.DateUtil;
20 import com.liferay.portal.kernel.util.GetterUtil;
21 import com.liferay.portal.kernel.util.StringBundler;
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.kernel.workflow.WorkflowConstants;
24 import com.liferay.portal.model.impl.BaseModelImpl;
25 import com.liferay.portal.service.ServiceContext;
26 import com.liferay.portal.util.PortalUtil;
27
28 import com.liferay.portlet.expando.model.ExpandoBridge;
29 import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
30 import com.liferay.portlet.messageboards.model.MBThread;
31 import com.liferay.portlet.messageboards.model.MBThreadSoap;
32
33 import java.io.Serializable;
34
35 import java.lang.reflect.Proxy;
36
37 import java.sql.Types;
38
39 import java.util.ArrayList;
40 import java.util.Date;
41 import java.util.List;
42
43
62 public class MBThreadModelImpl extends BaseModelImpl<MBThread> {
63 public static final String TABLE_NAME = "MBThread";
64 public static final Object[][] TABLE_COLUMNS = {
65 { "threadId", new Integer(Types.BIGINT) },
66 { "groupId", new Integer(Types.BIGINT) },
67 { "categoryId", new Integer(Types.BIGINT) },
68 { "rootMessageId", new Integer(Types.BIGINT) },
69 { "messageCount", new Integer(Types.INTEGER) },
70 { "viewCount", new Integer(Types.INTEGER) },
71 { "lastPostByUserId", new Integer(Types.BIGINT) },
72 { "lastPostDate", new Integer(Types.TIMESTAMP) },
73 { "priority", new Integer(Types.DOUBLE) },
74 { "status", new Integer(Types.INTEGER) },
75 { "statusByUserId", new Integer(Types.BIGINT) },
76 { "statusByUserName", new Integer(Types.VARCHAR) },
77 { "statusDate", new Integer(Types.TIMESTAMP) }
78 };
79 public static final String TABLE_SQL_CREATE = "create table MBThread (threadId LONG not null primary key,groupId LONG,categoryId LONG,rootMessageId LONG,messageCount INTEGER,viewCount INTEGER,lastPostByUserId LONG,lastPostDate DATE null,priority DOUBLE,status INTEGER,statusByUserId LONG,statusByUserName VARCHAR(75) null,statusDate DATE null)";
80 public static final String TABLE_SQL_DROP = "drop table MBThread";
81 public static final String ORDER_BY_JPQL = " ORDER BY mbThread.priority DESC, mbThread.lastPostDate DESC";
82 public static final String ORDER_BY_SQL = " ORDER BY MBThread.priority DESC, MBThread.lastPostDate DESC";
83 public static final String DATA_SOURCE = "liferayDataSource";
84 public static final String SESSION_FACTORY = "liferaySessionFactory";
85 public static final String TX_MANAGER = "liferayTransactionManager";
86 public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
87 "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
88 true);
89 public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
90 "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
91 true);
92
93 public static MBThread toModel(MBThreadSoap soapModel) {
94 MBThread model = new MBThreadImpl();
95
96 model.setThreadId(soapModel.getThreadId());
97 model.setGroupId(soapModel.getGroupId());
98 model.setCategoryId(soapModel.getCategoryId());
99 model.setRootMessageId(soapModel.getRootMessageId());
100 model.setMessageCount(soapModel.getMessageCount());
101 model.setViewCount(soapModel.getViewCount());
102 model.setLastPostByUserId(soapModel.getLastPostByUserId());
103 model.setLastPostDate(soapModel.getLastPostDate());
104 model.setPriority(soapModel.getPriority());
105 model.setStatus(soapModel.getStatus());
106 model.setStatusByUserId(soapModel.getStatusByUserId());
107 model.setStatusByUserName(soapModel.getStatusByUserName());
108 model.setStatusDate(soapModel.getStatusDate());
109
110 return model;
111 }
112
113 public static List<MBThread> toModels(MBThreadSoap[] soapModels) {
114 List<MBThread> models = new ArrayList<MBThread>(soapModels.length);
115
116 for (MBThreadSoap soapModel : soapModels) {
117 models.add(toModel(soapModel));
118 }
119
120 return models;
121 }
122
123 public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
124 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBThread"));
125
126 public MBThreadModelImpl() {
127 }
128
129 public long getPrimaryKey() {
130 return _threadId;
131 }
132
133 public void setPrimaryKey(long pk) {
134 setThreadId(pk);
135 }
136
137 public Serializable getPrimaryKeyObj() {
138 return new Long(_threadId);
139 }
140
141 public long getThreadId() {
142 return _threadId;
143 }
144
145 public void setThreadId(long threadId) {
146 _threadId = threadId;
147 }
148
149 public long getGroupId() {
150 return _groupId;
151 }
152
153 public void setGroupId(long groupId) {
154 _groupId = groupId;
155 }
156
157 public long getCategoryId() {
158 return _categoryId;
159 }
160
161 public void setCategoryId(long categoryId) {
162 _categoryId = categoryId;
163 }
164
165 public long getRootMessageId() {
166 return _rootMessageId;
167 }
168
169 public void setRootMessageId(long rootMessageId) {
170 _rootMessageId = rootMessageId;
171 }
172
173 public int getMessageCount() {
174 return _messageCount;
175 }
176
177 public void setMessageCount(int messageCount) {
178 _messageCount = messageCount;
179 }
180
181 public int getViewCount() {
182 return _viewCount;
183 }
184
185 public void setViewCount(int viewCount) {
186 _viewCount = viewCount;
187 }
188
189 public long getLastPostByUserId() {
190 return _lastPostByUserId;
191 }
192
193 public void setLastPostByUserId(long lastPostByUserId) {
194 _lastPostByUserId = lastPostByUserId;
195 }
196
197 public String getLastPostByUserUuid() throws SystemException {
198 return PortalUtil.getUserValue(getLastPostByUserId(), "uuid",
199 _lastPostByUserUuid);
200 }
201
202 public void setLastPostByUserUuid(String lastPostByUserUuid) {
203 _lastPostByUserUuid = lastPostByUserUuid;
204 }
205
206 public Date getLastPostDate() {
207 return _lastPostDate;
208 }
209
210 public void setLastPostDate(Date lastPostDate) {
211 _lastPostDate = lastPostDate;
212 }
213
214 public double getPriority() {
215 return _priority;
216 }
217
218 public void setPriority(double priority) {
219 _priority = priority;
220 }
221
222 public int getStatus() {
223 return _status;
224 }
225
226 public void setStatus(int status) {
227 _status = status;
228 }
229
230 public long getStatusByUserId() {
231 return _statusByUserId;
232 }
233
234 public void setStatusByUserId(long statusByUserId) {
235 _statusByUserId = statusByUserId;
236 }
237
238 public String getStatusByUserUuid() throws SystemException {
239 return PortalUtil.getUserValue(getStatusByUserId(), "uuid",
240 _statusByUserUuid);
241 }
242
243 public void setStatusByUserUuid(String statusByUserUuid) {
244 _statusByUserUuid = statusByUserUuid;
245 }
246
247 public String getStatusByUserName() {
248 if (_statusByUserName == null) {
249 return StringPool.BLANK;
250 }
251 else {
252 return _statusByUserName;
253 }
254 }
255
256 public void setStatusByUserName(String statusByUserName) {
257 _statusByUserName = statusByUserName;
258 }
259
260 public Date getStatusDate() {
261 return _statusDate;
262 }
263
264 public void setStatusDate(Date statusDate) {
265 _statusDate = statusDate;
266 }
267
268 public boolean isApproved() {
269 if (getStatus() == WorkflowConstants.STATUS_APPROVED) {
270 return true;
271 }
272 else {
273 return false;
274 }
275 }
276
277 public boolean isDraft() {
278 if (getStatus() == WorkflowConstants.STATUS_DRAFT) {
279 return true;
280 }
281 else {
282 return false;
283 }
284 }
285
286 public boolean isExpired() {
287 if (getStatus() == WorkflowConstants.STATUS_EXPIRED) {
288 return true;
289 }
290 else {
291 return false;
292 }
293 }
294
295 public boolean isPending() {
296 if (getStatus() == WorkflowConstants.STATUS_PENDING) {
297 return true;
298 }
299 else {
300 return false;
301 }
302 }
303
304 public MBThread toEscapedModel() {
305 if (isEscapedModel()) {
306 return (MBThread)this;
307 }
308 else {
309 return (MBThread)Proxy.newProxyInstance(MBThread.class.getClassLoader(),
310 new Class[] { MBThread.class }, new AutoEscapeBeanHandler(this));
311 }
312 }
313
314 public ExpandoBridge getExpandoBridge() {
315 if (_expandoBridge == null) {
316 _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
317 MBThread.class.getName(), getPrimaryKey());
318 }
319
320 return _expandoBridge;
321 }
322
323 public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
324 getExpandoBridge().setAttributes(serviceContext);
325 }
326
327 public Object clone() {
328 MBThreadImpl clone = new MBThreadImpl();
329
330 clone.setThreadId(getThreadId());
331 clone.setGroupId(getGroupId());
332 clone.setCategoryId(getCategoryId());
333 clone.setRootMessageId(getRootMessageId());
334 clone.setMessageCount(getMessageCount());
335 clone.setViewCount(getViewCount());
336 clone.setLastPostByUserId(getLastPostByUserId());
337 clone.setLastPostDate(getLastPostDate());
338 clone.setPriority(getPriority());
339 clone.setStatus(getStatus());
340 clone.setStatusByUserId(getStatusByUserId());
341 clone.setStatusByUserName(getStatusByUserName());
342 clone.setStatusDate(getStatusDate());
343
344 return clone;
345 }
346
347 public int compareTo(MBThread mbThread) {
348 int value = 0;
349
350 if (getPriority() < mbThread.getPriority()) {
351 value = -1;
352 }
353 else if (getPriority() > mbThread.getPriority()) {
354 value = 1;
355 }
356 else {
357 value = 0;
358 }
359
360 value = value * -1;
361
362 if (value != 0) {
363 return value;
364 }
365
366 value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
367
368 value = value * -1;
369
370 if (value != 0) {
371 return value;
372 }
373
374 return 0;
375 }
376
377 public boolean equals(Object obj) {
378 if (obj == null) {
379 return false;
380 }
381
382 MBThread mbThread = null;
383
384 try {
385 mbThread = (MBThread)obj;
386 }
387 catch (ClassCastException cce) {
388 return false;
389 }
390
391 long pk = mbThread.getPrimaryKey();
392
393 if (getPrimaryKey() == pk) {
394 return true;
395 }
396 else {
397 return false;
398 }
399 }
400
401 public int hashCode() {
402 return (int)getPrimaryKey();
403 }
404
405 public String toString() {
406 StringBundler sb = new StringBundler(27);
407
408 sb.append("{threadId=");
409 sb.append(getThreadId());
410 sb.append(", groupId=");
411 sb.append(getGroupId());
412 sb.append(", categoryId=");
413 sb.append(getCategoryId());
414 sb.append(", rootMessageId=");
415 sb.append(getRootMessageId());
416 sb.append(", messageCount=");
417 sb.append(getMessageCount());
418 sb.append(", viewCount=");
419 sb.append(getViewCount());
420 sb.append(", lastPostByUserId=");
421 sb.append(getLastPostByUserId());
422 sb.append(", lastPostDate=");
423 sb.append(getLastPostDate());
424 sb.append(", priority=");
425 sb.append(getPriority());
426 sb.append(", status=");
427 sb.append(getStatus());
428 sb.append(", statusByUserId=");
429 sb.append(getStatusByUserId());
430 sb.append(", statusByUserName=");
431 sb.append(getStatusByUserName());
432 sb.append(", statusDate=");
433 sb.append(getStatusDate());
434 sb.append("}");
435
436 return sb.toString();
437 }
438
439 public String toXmlString() {
440 StringBundler sb = new StringBundler(43);
441
442 sb.append("<model><model-name>");
443 sb.append("com.liferay.portlet.messageboards.model.MBThread");
444 sb.append("</model-name>");
445
446 sb.append(
447 "<column><column-name>threadId</column-name><column-value><![CDATA[");
448 sb.append(getThreadId());
449 sb.append("]]></column-value></column>");
450 sb.append(
451 "<column><column-name>groupId</column-name><column-value><![CDATA[");
452 sb.append(getGroupId());
453 sb.append("]]></column-value></column>");
454 sb.append(
455 "<column><column-name>categoryId</column-name><column-value><![CDATA[");
456 sb.append(getCategoryId());
457 sb.append("]]></column-value></column>");
458 sb.append(
459 "<column><column-name>rootMessageId</column-name><column-value><![CDATA[");
460 sb.append(getRootMessageId());
461 sb.append("]]></column-value></column>");
462 sb.append(
463 "<column><column-name>messageCount</column-name><column-value><![CDATA[");
464 sb.append(getMessageCount());
465 sb.append("]]></column-value></column>");
466 sb.append(
467 "<column><column-name>viewCount</column-name><column-value><![CDATA[");
468 sb.append(getViewCount());
469 sb.append("]]></column-value></column>");
470 sb.append(
471 "<column><column-name>lastPostByUserId</column-name><column-value><![CDATA[");
472 sb.append(getLastPostByUserId());
473 sb.append("]]></column-value></column>");
474 sb.append(
475 "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
476 sb.append(getLastPostDate());
477 sb.append("]]></column-value></column>");
478 sb.append(
479 "<column><column-name>priority</column-name><column-value><![CDATA[");
480 sb.append(getPriority());
481 sb.append("]]></column-value></column>");
482 sb.append(
483 "<column><column-name>status</column-name><column-value><![CDATA[");
484 sb.append(getStatus());
485 sb.append("]]></column-value></column>");
486 sb.append(
487 "<column><column-name>statusByUserId</column-name><column-value><![CDATA[");
488 sb.append(getStatusByUserId());
489 sb.append("]]></column-value></column>");
490 sb.append(
491 "<column><column-name>statusByUserName</column-name><column-value><![CDATA[");
492 sb.append(getStatusByUserName());
493 sb.append("]]></column-value></column>");
494 sb.append(
495 "<column><column-name>statusDate</column-name><column-value><![CDATA[");
496 sb.append(getStatusDate());
497 sb.append("]]></column-value></column>");
498
499 sb.append("</model>");
500
501 return sb.toString();
502 }
503
504 private long _threadId;
505 private long _groupId;
506 private long _categoryId;
507 private long _rootMessageId;
508 private int _messageCount;
509 private int _viewCount;
510 private long _lastPostByUserId;
511 private String _lastPostByUserUuid;
512 private Date _lastPostDate;
513 private double _priority;
514 private int _status;
515 private long _statusByUserId;
516 private String _statusByUserUuid;
517 private String _statusByUserName;
518 private Date _statusDate;
519 private transient ExpandoBridge _expandoBridge;
520 }