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