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 public boolean isApproved() {
281 if (getStatus() == WorkflowConstants.STATUS_APPROVED) {
282 return true;
283 }
284 else {
285 return false;
286 }
287 }
288
289 public boolean isDraft() {
290 if (getStatus() == WorkflowConstants.STATUS_DRAFT) {
291 return true;
292 }
293 else {
294 return false;
295 }
296 }
297
298 public boolean isExpired() {
299 if (getStatus() == WorkflowConstants.STATUS_EXPIRED) {
300 return true;
301 }
302 else {
303 return false;
304 }
305 }
306
307 public boolean isPending() {
308 if (getStatus() == WorkflowConstants.STATUS_PENDING) {
309 return true;
310 }
311 else {
312 return false;
313 }
314 }
315
316 public MBThread toEscapedModel() {
317 if (isEscapedModel()) {
318 return (MBThread)this;
319 }
320 else {
321 return (MBThread)Proxy.newProxyInstance(MBThread.class.getClassLoader(),
322 new Class[] { MBThread.class }, new AutoEscapeBeanHandler(this));
323 }
324 }
325
326 public ExpandoBridge getExpandoBridge() {
327 if (_expandoBridge == null) {
328 _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
329 MBThread.class.getName(), getPrimaryKey());
330 }
331
332 return _expandoBridge;
333 }
334
335 public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
336 getExpandoBridge().setAttributes(serviceContext);
337 }
338
339 public Object clone() {
340 MBThreadImpl clone = new MBThreadImpl();
341
342 clone.setThreadId(getThreadId());
343 clone.setGroupId(getGroupId());
344 clone.setCategoryId(getCategoryId());
345 clone.setRootMessageId(getRootMessageId());
346 clone.setMessageCount(getMessageCount());
347 clone.setViewCount(getViewCount());
348 clone.setLastPostByUserId(getLastPostByUserId());
349 clone.setLastPostDate(getLastPostDate());
350 clone.setPriority(getPriority());
351 clone.setStatus(getStatus());
352 clone.setStatusByUserId(getStatusByUserId());
353 clone.setStatusByUserName(getStatusByUserName());
354 clone.setStatusDate(getStatusDate());
355
356 return clone;
357 }
358
359 public int compareTo(MBThread mbThread) {
360 int value = 0;
361
362 if (getPriority() < mbThread.getPriority()) {
363 value = -1;
364 }
365 else if (getPriority() > mbThread.getPriority()) {
366 value = 1;
367 }
368 else {
369 value = 0;
370 }
371
372 value = value * -1;
373
374 if (value != 0) {
375 return value;
376 }
377
378 value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
379
380 value = value * -1;
381
382 if (value != 0) {
383 return value;
384 }
385
386 return 0;
387 }
388
389 public boolean equals(Object obj) {
390 if (obj == null) {
391 return false;
392 }
393
394 MBThread mbThread = null;
395
396 try {
397 mbThread = (MBThread)obj;
398 }
399 catch (ClassCastException cce) {
400 return false;
401 }
402
403 long pk = mbThread.getPrimaryKey();
404
405 if (getPrimaryKey() == pk) {
406 return true;
407 }
408 else {
409 return false;
410 }
411 }
412
413 public int hashCode() {
414 return (int)getPrimaryKey();
415 }
416
417 public String toString() {
418 StringBundler sb = new StringBundler(27);
419
420 sb.append("{threadId=");
421 sb.append(getThreadId());
422 sb.append(", groupId=");
423 sb.append(getGroupId());
424 sb.append(", categoryId=");
425 sb.append(getCategoryId());
426 sb.append(", rootMessageId=");
427 sb.append(getRootMessageId());
428 sb.append(", messageCount=");
429 sb.append(getMessageCount());
430 sb.append(", viewCount=");
431 sb.append(getViewCount());
432 sb.append(", lastPostByUserId=");
433 sb.append(getLastPostByUserId());
434 sb.append(", lastPostDate=");
435 sb.append(getLastPostDate());
436 sb.append(", priority=");
437 sb.append(getPriority());
438 sb.append(", status=");
439 sb.append(getStatus());
440 sb.append(", statusByUserId=");
441 sb.append(getStatusByUserId());
442 sb.append(", statusByUserName=");
443 sb.append(getStatusByUserName());
444 sb.append(", statusDate=");
445 sb.append(getStatusDate());
446 sb.append("}");
447
448 return sb.toString();
449 }
450
451 public String toXmlString() {
452 StringBundler sb = new StringBundler(43);
453
454 sb.append("<model><model-name>");
455 sb.append("com.liferay.portlet.messageboards.model.MBThread");
456 sb.append("</model-name>");
457
458 sb.append(
459 "<column><column-name>threadId</column-name><column-value><![CDATA[");
460 sb.append(getThreadId());
461 sb.append("]]></column-value></column>");
462 sb.append(
463 "<column><column-name>groupId</column-name><column-value><![CDATA[");
464 sb.append(getGroupId());
465 sb.append("]]></column-value></column>");
466 sb.append(
467 "<column><column-name>categoryId</column-name><column-value><![CDATA[");
468 sb.append(getCategoryId());
469 sb.append("]]></column-value></column>");
470 sb.append(
471 "<column><column-name>rootMessageId</column-name><column-value><![CDATA[");
472 sb.append(getRootMessageId());
473 sb.append("]]></column-value></column>");
474 sb.append(
475 "<column><column-name>messageCount</column-name><column-value><![CDATA[");
476 sb.append(getMessageCount());
477 sb.append("]]></column-value></column>");
478 sb.append(
479 "<column><column-name>viewCount</column-name><column-value><![CDATA[");
480 sb.append(getViewCount());
481 sb.append("]]></column-value></column>");
482 sb.append(
483 "<column><column-name>lastPostByUserId</column-name><column-value><![CDATA[");
484 sb.append(getLastPostByUserId());
485 sb.append("]]></column-value></column>");
486 sb.append(
487 "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
488 sb.append(getLastPostDate());
489 sb.append("]]></column-value></column>");
490 sb.append(
491 "<column><column-name>priority</column-name><column-value><![CDATA[");
492 sb.append(getPriority());
493 sb.append("]]></column-value></column>");
494 sb.append(
495 "<column><column-name>status</column-name><column-value><![CDATA[");
496 sb.append(getStatus());
497 sb.append("]]></column-value></column>");
498 sb.append(
499 "<column><column-name>statusByUserId</column-name><column-value><![CDATA[");
500 sb.append(getStatusByUserId());
501 sb.append("]]></column-value></column>");
502 sb.append(
503 "<column><column-name>statusByUserName</column-name><column-value><![CDATA[");
504 sb.append(getStatusByUserName());
505 sb.append("]]></column-value></column>");
506 sb.append(
507 "<column><column-name>statusDate</column-name><column-value><![CDATA[");
508 sb.append(getStatusDate());
509 sb.append("]]></column-value></column>");
510
511 sb.append("</model>");
512
513 return sb.toString();
514 }
515
516 private long _threadId;
517 private long _groupId;
518 private long _categoryId;
519 private long _rootMessageId;
520 private int _messageCount;
521 private int _viewCount;
522 private long _lastPostByUserId;
523 private String _lastPostByUserUuid;
524 private Date _lastPostDate;
525 private double _priority;
526 private int _status;
527 private long _statusByUserId;
528 private String _statusByUserUuid;
529 private String _statusByUserName;
530 private Date _statusDate;
531 private transient ExpandoBridge _expandoBridge;
532 }