001
014
015 package com.liferay.portlet.messageboards.model.impl;
016
017 import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.DateUtil;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.StringBundler;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.workflow.WorkflowConstants;
024 import com.liferay.portal.model.impl.BaseModelImpl;
025 import com.liferay.portal.service.ServiceContext;
026 import com.liferay.portal.util.PortalUtil;
027
028 import com.liferay.portlet.expando.model.ExpandoBridge;
029 import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
030 import com.liferay.portlet.messageboards.model.MBThread;
031 import com.liferay.portlet.messageboards.model.MBThreadModel;
032 import com.liferay.portlet.messageboards.model.MBThreadSoap;
033
034 import java.io.Serializable;
035
036 import java.lang.reflect.Proxy;
037
038 import java.sql.Types;
039
040 import java.util.ArrayList;
041 import java.util.Date;
042 import java.util.List;
043
044
061 public class MBThreadModelImpl extends BaseModelImpl<MBThread>
062 implements MBThreadModel {
063 public static final String TABLE_NAME = "MBThread";
064 public static final Object[][] TABLE_COLUMNS = {
065 { "threadId", new Integer(Types.BIGINT) },
066 { "groupId", new Integer(Types.BIGINT) },
067 { "categoryId", new Integer(Types.BIGINT) },
068 { "rootMessageId", new Integer(Types.BIGINT) },
069 { "messageCount", new Integer(Types.INTEGER) },
070 { "viewCount", new Integer(Types.INTEGER) },
071 { "lastPostByUserId", new Integer(Types.BIGINT) },
072 { "lastPostDate", new Integer(Types.TIMESTAMP) },
073 { "priority", new Integer(Types.DOUBLE) },
074 { "status", new Integer(Types.INTEGER) },
075 { "statusByUserId", new Integer(Types.BIGINT) },
076 { "statusByUserName", new Integer(Types.VARCHAR) },
077 { "statusDate", new Integer(Types.TIMESTAMP) }
078 };
079 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)";
080 public static final String TABLE_SQL_DROP = "drop table MBThread";
081 public static final String ORDER_BY_JPQL = " ORDER BY mbThread.priority DESC, mbThread.lastPostDate DESC";
082 public static final String ORDER_BY_SQL = " ORDER BY MBThread.priority DESC, MBThread.lastPostDate DESC";
083 public static final String DATA_SOURCE = "liferayDataSource";
084 public static final String SESSION_FACTORY = "liferaySessionFactory";
085 public static final String TX_MANAGER = "liferayTransactionManager";
086 public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
087 "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
088 true);
089 public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
090 "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
091 true);
092
093
099 public static MBThread toModel(MBThreadSoap soapModel) {
100 MBThread model = new MBThreadImpl();
101
102 model.setThreadId(soapModel.getThreadId());
103 model.setGroupId(soapModel.getGroupId());
104 model.setCategoryId(soapModel.getCategoryId());
105 model.setRootMessageId(soapModel.getRootMessageId());
106 model.setMessageCount(soapModel.getMessageCount());
107 model.setViewCount(soapModel.getViewCount());
108 model.setLastPostByUserId(soapModel.getLastPostByUserId());
109 model.setLastPostDate(soapModel.getLastPostDate());
110 model.setPriority(soapModel.getPriority());
111 model.setStatus(soapModel.getStatus());
112 model.setStatusByUserId(soapModel.getStatusByUserId());
113 model.setStatusByUserName(soapModel.getStatusByUserName());
114 model.setStatusDate(soapModel.getStatusDate());
115
116 return model;
117 }
118
119
125 public static List<MBThread> toModels(MBThreadSoap[] soapModels) {
126 List<MBThread> models = new ArrayList<MBThread>(soapModels.length);
127
128 for (MBThreadSoap soapModel : soapModels) {
129 models.add(toModel(soapModel));
130 }
131
132 return models;
133 }
134
135 public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
136 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBThread"));
137
138 public MBThreadModelImpl() {
139 }
140
141 public long getPrimaryKey() {
142 return _threadId;
143 }
144
145 public void setPrimaryKey(long pk) {
146 setThreadId(pk);
147 }
148
149 public Serializable getPrimaryKeyObj() {
150 return new Long(_threadId);
151 }
152
153 public long getThreadId() {
154 return _threadId;
155 }
156
157 public void setThreadId(long threadId) {
158 _threadId = threadId;
159 }
160
161 public long getGroupId() {
162 return _groupId;
163 }
164
165 public void setGroupId(long groupId) {
166 _groupId = groupId;
167 }
168
169 public long getCategoryId() {
170 return _categoryId;
171 }
172
173 public void setCategoryId(long categoryId) {
174 _categoryId = categoryId;
175 }
176
177 public long getRootMessageId() {
178 return _rootMessageId;
179 }
180
181 public void setRootMessageId(long rootMessageId) {
182 _rootMessageId = rootMessageId;
183 }
184
185 public int getMessageCount() {
186 return _messageCount;
187 }
188
189 public void setMessageCount(int messageCount) {
190 _messageCount = messageCount;
191 }
192
193 public int getViewCount() {
194 return _viewCount;
195 }
196
197 public void setViewCount(int viewCount) {
198 _viewCount = viewCount;
199 }
200
201 public long getLastPostByUserId() {
202 return _lastPostByUserId;
203 }
204
205 public void setLastPostByUserId(long lastPostByUserId) {
206 _lastPostByUserId = lastPostByUserId;
207 }
208
209 public String getLastPostByUserUuid() throws SystemException {
210 return PortalUtil.getUserValue(getLastPostByUserId(), "uuid",
211 _lastPostByUserUuid);
212 }
213
214 public void setLastPostByUserUuid(String lastPostByUserUuid) {
215 _lastPostByUserUuid = lastPostByUserUuid;
216 }
217
218 public Date getLastPostDate() {
219 return _lastPostDate;
220 }
221
222 public void setLastPostDate(Date lastPostDate) {
223 _lastPostDate = lastPostDate;
224 }
225
226 public double getPriority() {
227 return _priority;
228 }
229
230 public void setPriority(double priority) {
231 _priority = priority;
232 }
233
234 public int getStatus() {
235 return _status;
236 }
237
238 public void setStatus(int status) {
239 _status = status;
240 }
241
242 public long getStatusByUserId() {
243 return _statusByUserId;
244 }
245
246 public void setStatusByUserId(long statusByUserId) {
247 _statusByUserId = statusByUserId;
248 }
249
250 public String getStatusByUserUuid() throws SystemException {
251 return PortalUtil.getUserValue(getStatusByUserId(), "uuid",
252 _statusByUserUuid);
253 }
254
255 public void setStatusByUserUuid(String statusByUserUuid) {
256 _statusByUserUuid = statusByUserUuid;
257 }
258
259 public String getStatusByUserName() {
260 if (_statusByUserName == null) {
261 return StringPool.BLANK;
262 }
263 else {
264 return _statusByUserName;
265 }
266 }
267
268 public void setStatusByUserName(String statusByUserName) {
269 _statusByUserName = statusByUserName;
270 }
271
272 public Date getStatusDate() {
273 return _statusDate;
274 }
275
276 public void setStatusDate(Date statusDate) {
277 _statusDate = statusDate;
278 }
279
280
283 public boolean getApproved() {
284 return isApproved();
285 }
286
287 public boolean isApproved() {
288 if (getStatus() == WorkflowConstants.STATUS_APPROVED) {
289 return true;
290 }
291 else {
292 return false;
293 }
294 }
295
296 public boolean isDraft() {
297 if (getStatus() == WorkflowConstants.STATUS_DRAFT) {
298 return true;
299 }
300 else {
301 return false;
302 }
303 }
304
305 public boolean isExpired() {
306 if (getStatus() == WorkflowConstants.STATUS_EXPIRED) {
307 return true;
308 }
309 else {
310 return false;
311 }
312 }
313
314 public boolean isPending() {
315 if (getStatus() == WorkflowConstants.STATUS_PENDING) {
316 return true;
317 }
318 else {
319 return false;
320 }
321 }
322
323 public MBThread toEscapedModel() {
324 if (isEscapedModel()) {
325 return (MBThread)this;
326 }
327 else {
328 return (MBThread)Proxy.newProxyInstance(MBThread.class.getClassLoader(),
329 new Class[] { MBThread.class }, new AutoEscapeBeanHandler(this));
330 }
331 }
332
333 public ExpandoBridge getExpandoBridge() {
334 if (_expandoBridge == null) {
335 _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
336 MBThread.class.getName(), getPrimaryKey());
337 }
338
339 return _expandoBridge;
340 }
341
342 public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
343 getExpandoBridge().setAttributes(serviceContext);
344 }
345
346 public Object clone() {
347 MBThreadImpl clone = new MBThreadImpl();
348
349 clone.setThreadId(getThreadId());
350 clone.setGroupId(getGroupId());
351 clone.setCategoryId(getCategoryId());
352 clone.setRootMessageId(getRootMessageId());
353 clone.setMessageCount(getMessageCount());
354 clone.setViewCount(getViewCount());
355 clone.setLastPostByUserId(getLastPostByUserId());
356 clone.setLastPostDate(getLastPostDate());
357 clone.setPriority(getPriority());
358 clone.setStatus(getStatus());
359 clone.setStatusByUserId(getStatusByUserId());
360 clone.setStatusByUserName(getStatusByUserName());
361 clone.setStatusDate(getStatusDate());
362
363 return clone;
364 }
365
366 public int compareTo(MBThread mbThread) {
367 int value = 0;
368
369 if (getPriority() < mbThread.getPriority()) {
370 value = -1;
371 }
372 else if (getPriority() > mbThread.getPriority()) {
373 value = 1;
374 }
375 else {
376 value = 0;
377 }
378
379 value = value * -1;
380
381 if (value != 0) {
382 return value;
383 }
384
385 value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
386
387 value = value * -1;
388
389 if (value != 0) {
390 return value;
391 }
392
393 return 0;
394 }
395
396 public boolean equals(Object obj) {
397 if (obj == null) {
398 return false;
399 }
400
401 MBThread mbThread = null;
402
403 try {
404 mbThread = (MBThread)obj;
405 }
406 catch (ClassCastException cce) {
407 return false;
408 }
409
410 long pk = mbThread.getPrimaryKey();
411
412 if (getPrimaryKey() == pk) {
413 return true;
414 }
415 else {
416 return false;
417 }
418 }
419
420 public int hashCode() {
421 return (int)getPrimaryKey();
422 }
423
424 public String toString() {
425 StringBundler sb = new StringBundler(27);
426
427 sb.append("{threadId=");
428 sb.append(getThreadId());
429 sb.append(", groupId=");
430 sb.append(getGroupId());
431 sb.append(", categoryId=");
432 sb.append(getCategoryId());
433 sb.append(", rootMessageId=");
434 sb.append(getRootMessageId());
435 sb.append(", messageCount=");
436 sb.append(getMessageCount());
437 sb.append(", viewCount=");
438 sb.append(getViewCount());
439 sb.append(", lastPostByUserId=");
440 sb.append(getLastPostByUserId());
441 sb.append(", lastPostDate=");
442 sb.append(getLastPostDate());
443 sb.append(", priority=");
444 sb.append(getPriority());
445 sb.append(", status=");
446 sb.append(getStatus());
447 sb.append(", statusByUserId=");
448 sb.append(getStatusByUserId());
449 sb.append(", statusByUserName=");
450 sb.append(getStatusByUserName());
451 sb.append(", statusDate=");
452 sb.append(getStatusDate());
453 sb.append("}");
454
455 return sb.toString();
456 }
457
458 public String toXmlString() {
459 StringBundler sb = new StringBundler(43);
460
461 sb.append("<model><model-name>");
462 sb.append("com.liferay.portlet.messageboards.model.MBThread");
463 sb.append("</model-name>");
464
465 sb.append(
466 "<column><column-name>threadId</column-name><column-value><![CDATA[");
467 sb.append(getThreadId());
468 sb.append("]]></column-value></column>");
469 sb.append(
470 "<column><column-name>groupId</column-name><column-value><![CDATA[");
471 sb.append(getGroupId());
472 sb.append("]]></column-value></column>");
473 sb.append(
474 "<column><column-name>categoryId</column-name><column-value><![CDATA[");
475 sb.append(getCategoryId());
476 sb.append("]]></column-value></column>");
477 sb.append(
478 "<column><column-name>rootMessageId</column-name><column-value><![CDATA[");
479 sb.append(getRootMessageId());
480 sb.append("]]></column-value></column>");
481 sb.append(
482 "<column><column-name>messageCount</column-name><column-value><![CDATA[");
483 sb.append(getMessageCount());
484 sb.append("]]></column-value></column>");
485 sb.append(
486 "<column><column-name>viewCount</column-name><column-value><![CDATA[");
487 sb.append(getViewCount());
488 sb.append("]]></column-value></column>");
489 sb.append(
490 "<column><column-name>lastPostByUserId</column-name><column-value><![CDATA[");
491 sb.append(getLastPostByUserId());
492 sb.append("]]></column-value></column>");
493 sb.append(
494 "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
495 sb.append(getLastPostDate());
496 sb.append("]]></column-value></column>");
497 sb.append(
498 "<column><column-name>priority</column-name><column-value><![CDATA[");
499 sb.append(getPriority());
500 sb.append("]]></column-value></column>");
501 sb.append(
502 "<column><column-name>status</column-name><column-value><![CDATA[");
503 sb.append(getStatus());
504 sb.append("]]></column-value></column>");
505 sb.append(
506 "<column><column-name>statusByUserId</column-name><column-value><![CDATA[");
507 sb.append(getStatusByUserId());
508 sb.append("]]></column-value></column>");
509 sb.append(
510 "<column><column-name>statusByUserName</column-name><column-value><![CDATA[");
511 sb.append(getStatusByUserName());
512 sb.append("]]></column-value></column>");
513 sb.append(
514 "<column><column-name>statusDate</column-name><column-value><![CDATA[");
515 sb.append(getStatusDate());
516 sb.append("]]></column-value></column>");
517
518 sb.append("</model>");
519
520 return sb.toString();
521 }
522
523 private long _threadId;
524 private long _groupId;
525 private long _categoryId;
526 private long _rootMessageId;
527 private int _messageCount;
528 private int _viewCount;
529 private long _lastPostByUserId;
530 private String _lastPostByUserUuid;
531 private Date _lastPostDate;
532 private double _priority;
533 private int _status;
534 private long _statusByUserId;
535 private String _statusByUserUuid;
536 private String _statusByUserName;
537 private Date _statusDate;
538 private transient ExpandoBridge _expandoBridge;
539 }