1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.messageboards.model.impl;
16  
17  import com.liferay.portal.SystemException;
18  import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
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.model.impl.BaseModelImpl;
23  import com.liferay.portal.service.ServiceContext;
24  import com.liferay.portal.util.PortalUtil;
25  
26  import com.liferay.portlet.expando.model.ExpandoBridge;
27  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
28  import com.liferay.portlet.messageboards.model.MBThread;
29  import com.liferay.portlet.messageboards.model.MBThreadSoap;
30  
31  import java.io.Serializable;
32  
33  import java.lang.reflect.Proxy;
34  
35  import java.sql.Types;
36  
37  import java.util.ArrayList;
38  import java.util.Date;
39  import java.util.List;
40  
41  /**
42   * <a href="MBThreadModelImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * <p>
45   * ServiceBuilder generated this class. Modifications in this class will be
46   * overwritten the next time is generated.
47   * </p>
48   *
49   * <p>
50   * This interface is a model that represents the MBThread table in the
51   * database.
52   * </p>
53   *
54   * @author    Brian Wing Shun Chan
55   * @see       MBThreadImpl
56   * @see       com.liferay.portlet.messageboards.model.MBThread
57   * @see       com.liferay.portlet.messageboards.model.MBThreadModel
58   * @generated
59   */
60  public class MBThreadModelImpl extends BaseModelImpl<MBThread> {
61      public static final String TABLE_NAME = "MBThread";
62      public static final Object[][] TABLE_COLUMNS = {
63              { "threadId", new Integer(Types.BIGINT) },
64              { "groupId", new Integer(Types.BIGINT) },
65              { "categoryId", new Integer(Types.BIGINT) },
66              { "rootMessageId", new Integer(Types.BIGINT) },
67              { "messageCount", new Integer(Types.INTEGER) },
68              { "viewCount", new Integer(Types.INTEGER) },
69              { "lastPostByUserId", new Integer(Types.BIGINT) },
70              { "lastPostDate", new Integer(Types.TIMESTAMP) },
71              { "priority", new Integer(Types.DOUBLE) }
72          };
73      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)";
74      public static final String TABLE_SQL_DROP = "drop table MBThread";
75      public static final String ORDER_BY_JPQL = " ORDER BY mbThread.priority DESC, mbThread.lastPostDate DESC";
76      public static final String ORDER_BY_SQL = " ORDER BY MBThread.priority DESC, MBThread.lastPostDate DESC";
77      public static final String DATA_SOURCE = "liferayDataSource";
78      public static final String SESSION_FACTORY = "liferaySessionFactory";
79      public static final String TX_MANAGER = "liferayTransactionManager";
80      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
81                  "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
82              true);
83      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
84                  "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
85              true);
86  
87      public static MBThread toModel(MBThreadSoap soapModel) {
88          MBThread model = new MBThreadImpl();
89  
90          model.setThreadId(soapModel.getThreadId());
91          model.setGroupId(soapModel.getGroupId());
92          model.setCategoryId(soapModel.getCategoryId());
93          model.setRootMessageId(soapModel.getRootMessageId());
94          model.setMessageCount(soapModel.getMessageCount());
95          model.setViewCount(soapModel.getViewCount());
96          model.setLastPostByUserId(soapModel.getLastPostByUserId());
97          model.setLastPostDate(soapModel.getLastPostDate());
98          model.setPriority(soapModel.getPriority());
99  
100         return model;
101     }
102 
103     public static List<MBThread> toModels(MBThreadSoap[] soapModels) {
104         List<MBThread> models = new ArrayList<MBThread>(soapModels.length);
105 
106         for (MBThreadSoap soapModel : soapModels) {
107             models.add(toModel(soapModel));
108         }
109 
110         return models;
111     }
112 
113     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
114                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBThread"));
115 
116     public MBThreadModelImpl() {
117     }
118 
119     public long getPrimaryKey() {
120         return _threadId;
121     }
122 
123     public void setPrimaryKey(long pk) {
124         setThreadId(pk);
125     }
126 
127     public Serializable getPrimaryKeyObj() {
128         return new Long(_threadId);
129     }
130 
131     public long getThreadId() {
132         return _threadId;
133     }
134 
135     public void setThreadId(long threadId) {
136         _threadId = threadId;
137     }
138 
139     public long getGroupId() {
140         return _groupId;
141     }
142 
143     public void setGroupId(long groupId) {
144         _groupId = groupId;
145     }
146 
147     public long getCategoryId() {
148         return _categoryId;
149     }
150 
151     public void setCategoryId(long categoryId) {
152         _categoryId = categoryId;
153     }
154 
155     public long getRootMessageId() {
156         return _rootMessageId;
157     }
158 
159     public void setRootMessageId(long rootMessageId) {
160         _rootMessageId = rootMessageId;
161     }
162 
163     public int getMessageCount() {
164         return _messageCount;
165     }
166 
167     public void setMessageCount(int messageCount) {
168         _messageCount = messageCount;
169     }
170 
171     public int getViewCount() {
172         return _viewCount;
173     }
174 
175     public void setViewCount(int viewCount) {
176         _viewCount = viewCount;
177     }
178 
179     public long getLastPostByUserId() {
180         return _lastPostByUserId;
181     }
182 
183     public void setLastPostByUserId(long lastPostByUserId) {
184         _lastPostByUserId = lastPostByUserId;
185     }
186 
187     public String getLastPostByUserUuid() throws SystemException {
188         return PortalUtil.getUserValue(getLastPostByUserId(), "uuid",
189             _lastPostByUserUuid);
190     }
191 
192     public void setLastPostByUserUuid(String lastPostByUserUuid) {
193         _lastPostByUserUuid = lastPostByUserUuid;
194     }
195 
196     public Date getLastPostDate() {
197         return _lastPostDate;
198     }
199 
200     public void setLastPostDate(Date lastPostDate) {
201         _lastPostDate = lastPostDate;
202     }
203 
204     public double getPriority() {
205         return _priority;
206     }
207 
208     public void setPriority(double priority) {
209         _priority = priority;
210     }
211 
212     public MBThread toEscapedModel() {
213         if (isEscapedModel()) {
214             return (MBThread)this;
215         }
216         else {
217             return (MBThread)Proxy.newProxyInstance(MBThread.class.getClassLoader(),
218                 new Class[] { MBThread.class }, new AutoEscapeBeanHandler(this));
219         }
220     }
221 
222     public ExpandoBridge getExpandoBridge() {
223         if (_expandoBridge == null) {
224             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(MBThread.class.getName(),
225                     getPrimaryKey());
226         }
227 
228         return _expandoBridge;
229     }
230 
231     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
232         getExpandoBridge().setAttributes(serviceContext);
233     }
234 
235     public Object clone() {
236         MBThreadImpl clone = new MBThreadImpl();
237 
238         clone.setThreadId(getThreadId());
239         clone.setGroupId(getGroupId());
240         clone.setCategoryId(getCategoryId());
241         clone.setRootMessageId(getRootMessageId());
242         clone.setMessageCount(getMessageCount());
243         clone.setViewCount(getViewCount());
244         clone.setLastPostByUserId(getLastPostByUserId());
245         clone.setLastPostDate(getLastPostDate());
246         clone.setPriority(getPriority());
247 
248         return clone;
249     }
250 
251     public int compareTo(MBThread mbThread) {
252         int value = 0;
253 
254         if (getPriority() < mbThread.getPriority()) {
255             value = -1;
256         }
257         else if (getPriority() > mbThread.getPriority()) {
258             value = 1;
259         }
260         else {
261             value = 0;
262         }
263 
264         value = value * -1;
265 
266         if (value != 0) {
267             return value;
268         }
269 
270         value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
271 
272         value = value * -1;
273 
274         if (value != 0) {
275             return value;
276         }
277 
278         return 0;
279     }
280 
281     public boolean equals(Object obj) {
282         if (obj == null) {
283             return false;
284         }
285 
286         MBThread mbThread = null;
287 
288         try {
289             mbThread = (MBThread)obj;
290         }
291         catch (ClassCastException cce) {
292             return false;
293         }
294 
295         long pk = mbThread.getPrimaryKey();
296 
297         if (getPrimaryKey() == pk) {
298             return true;
299         }
300         else {
301             return false;
302         }
303     }
304 
305     public int hashCode() {
306         return (int)getPrimaryKey();
307     }
308 
309     public String toString() {
310         StringBundler sb = new StringBundler(19);
311 
312         sb.append("{threadId=");
313         sb.append(getThreadId());
314         sb.append(", groupId=");
315         sb.append(getGroupId());
316         sb.append(", categoryId=");
317         sb.append(getCategoryId());
318         sb.append(", rootMessageId=");
319         sb.append(getRootMessageId());
320         sb.append(", messageCount=");
321         sb.append(getMessageCount());
322         sb.append(", viewCount=");
323         sb.append(getViewCount());
324         sb.append(", lastPostByUserId=");
325         sb.append(getLastPostByUserId());
326         sb.append(", lastPostDate=");
327         sb.append(getLastPostDate());
328         sb.append(", priority=");
329         sb.append(getPriority());
330         sb.append("}");
331 
332         return sb.toString();
333     }
334 
335     public String toXmlString() {
336         StringBundler sb = new StringBundler(31);
337 
338         sb.append("<model><model-name>");
339         sb.append("com.liferay.portlet.messageboards.model.MBThread");
340         sb.append("</model-name>");
341 
342         sb.append(
343             "<column><column-name>threadId</column-name><column-value><![CDATA[");
344         sb.append(getThreadId());
345         sb.append("]]></column-value></column>");
346         sb.append(
347             "<column><column-name>groupId</column-name><column-value><![CDATA[");
348         sb.append(getGroupId());
349         sb.append("]]></column-value></column>");
350         sb.append(
351             "<column><column-name>categoryId</column-name><column-value><![CDATA[");
352         sb.append(getCategoryId());
353         sb.append("]]></column-value></column>");
354         sb.append(
355             "<column><column-name>rootMessageId</column-name><column-value><![CDATA[");
356         sb.append(getRootMessageId());
357         sb.append("]]></column-value></column>");
358         sb.append(
359             "<column><column-name>messageCount</column-name><column-value><![CDATA[");
360         sb.append(getMessageCount());
361         sb.append("]]></column-value></column>");
362         sb.append(
363             "<column><column-name>viewCount</column-name><column-value><![CDATA[");
364         sb.append(getViewCount());
365         sb.append("]]></column-value></column>");
366         sb.append(
367             "<column><column-name>lastPostByUserId</column-name><column-value><![CDATA[");
368         sb.append(getLastPostByUserId());
369         sb.append("]]></column-value></column>");
370         sb.append(
371             "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
372         sb.append(getLastPostDate());
373         sb.append("]]></column-value></column>");
374         sb.append(
375             "<column><column-name>priority</column-name><column-value><![CDATA[");
376         sb.append(getPriority());
377         sb.append("]]></column-value></column>");
378 
379         sb.append("</model>");
380 
381         return sb.toString();
382     }
383 
384     private long _threadId;
385     private long _groupId;
386     private long _categoryId;
387     private long _rootMessageId;
388     private int _messageCount;
389     private int _viewCount;
390     private long _lastPostByUserId;
391     private String _lastPostByUserUuid;
392     private Date _lastPostDate;
393     private double _priority;
394     private transient ExpandoBridge _expandoBridge;
395 }