1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.messageboards.model.impl;
24  
25  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
26  import com.liferay.portal.kernel.util.DateUtil;
27  import com.liferay.portal.kernel.util.GetterUtil;
28  import com.liferay.portal.model.impl.BaseModelImpl;
29  
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  /**
44   * <a href="MBThreadModelImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * <p>
47   * ServiceBuilder generated this class. Modifications in this class will be
48   * overwritten the next time is generated.
49   * </p>
50   *
51   * <p>
52   * This class is a model that represents the <code>MBThread</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portlet.messageboards.model.MBThread
59   * @see com.liferay.portlet.messageboards.model.MBThreadModel
60   * @see com.liferay.portlet.messageboards.model.impl.MBThreadImpl
61   *
62   */
63  public class MBThreadModelImpl extends BaseModelImpl<MBThread> {
64      public static final String TABLE_NAME = "MBThread";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "threadId", new Integer(Types.BIGINT) },
67              
68  
69              { "groupId", new Integer(Types.BIGINT) },
70              
71  
72              { "categoryId", new Integer(Types.BIGINT) },
73              
74  
75              { "rootMessageId", new Integer(Types.BIGINT) },
76              
77  
78              { "messageCount", new Integer(Types.INTEGER) },
79              
80  
81              { "viewCount", new Integer(Types.INTEGER) },
82              
83  
84              { "lastPostByUserId", new Integer(Types.BIGINT) },
85              
86  
87              { "lastPostDate", new Integer(Types.TIMESTAMP) },
88              
89  
90              { "priority", new Integer(Types.DOUBLE) }
91          };
92      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)";
93      public static final String TABLE_SQL_DROP = "drop table MBThread";
94      public static final String DATA_SOURCE = "liferayDataSource";
95      public static final String SESSION_FACTORY = "liferaySessionFactory";
96      public static final String TX_MANAGER = "liferayTransactionManager";
97      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
98                  "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
99              true);
100     public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
101                 "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
102             true);
103 
104     public static MBThread toModel(MBThreadSoap soapModel) {
105         MBThread model = new MBThreadImpl();
106 
107         model.setThreadId(soapModel.getThreadId());
108         model.setGroupId(soapModel.getGroupId());
109         model.setCategoryId(soapModel.getCategoryId());
110         model.setRootMessageId(soapModel.getRootMessageId());
111         model.setMessageCount(soapModel.getMessageCount());
112         model.setViewCount(soapModel.getViewCount());
113         model.setLastPostByUserId(soapModel.getLastPostByUserId());
114         model.setLastPostDate(soapModel.getLastPostDate());
115         model.setPriority(soapModel.getPriority());
116 
117         return model;
118     }
119 
120     public static List<MBThread> toModels(MBThreadSoap[] soapModels) {
121         List<MBThread> models = new ArrayList<MBThread>(soapModels.length);
122 
123         for (MBThreadSoap soapModel : soapModels) {
124             models.add(toModel(soapModel));
125         }
126 
127         return models;
128     }
129 
130     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
131                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBThread"));
132 
133     public MBThreadModelImpl() {
134     }
135 
136     public long getPrimaryKey() {
137         return _threadId;
138     }
139 
140     public void setPrimaryKey(long pk) {
141         setThreadId(pk);
142     }
143 
144     public Serializable getPrimaryKeyObj() {
145         return new Long(_threadId);
146     }
147 
148     public long getThreadId() {
149         return _threadId;
150     }
151 
152     public void setThreadId(long threadId) {
153         _threadId = threadId;
154     }
155 
156     public long getGroupId() {
157         return _groupId;
158     }
159 
160     public void setGroupId(long groupId) {
161         _groupId = groupId;
162     }
163 
164     public long getCategoryId() {
165         return _categoryId;
166     }
167 
168     public void setCategoryId(long categoryId) {
169         _categoryId = categoryId;
170     }
171 
172     public long getRootMessageId() {
173         return _rootMessageId;
174     }
175 
176     public void setRootMessageId(long rootMessageId) {
177         _rootMessageId = rootMessageId;
178     }
179 
180     public int getMessageCount() {
181         return _messageCount;
182     }
183 
184     public void setMessageCount(int messageCount) {
185         _messageCount = messageCount;
186     }
187 
188     public int getViewCount() {
189         return _viewCount;
190     }
191 
192     public void setViewCount(int viewCount) {
193         _viewCount = viewCount;
194     }
195 
196     public long getLastPostByUserId() {
197         return _lastPostByUserId;
198     }
199 
200     public void setLastPostByUserId(long lastPostByUserId) {
201         _lastPostByUserId = lastPostByUserId;
202     }
203 
204     public Date getLastPostDate() {
205         return _lastPostDate;
206     }
207 
208     public void setLastPostDate(Date lastPostDate) {
209         _lastPostDate = lastPostDate;
210     }
211 
212     public double getPriority() {
213         return _priority;
214     }
215 
216     public void setPriority(double priority) {
217         _priority = priority;
218     }
219 
220     public MBThread toEscapedModel() {
221         if (isEscapedModel()) {
222             return (MBThread)this;
223         }
224         else {
225             MBThread model = new MBThreadImpl();
226 
227             model.setNew(isNew());
228             model.setEscapedModel(true);
229 
230             model.setThreadId(getThreadId());
231             model.setGroupId(getGroupId());
232             model.setCategoryId(getCategoryId());
233             model.setRootMessageId(getRootMessageId());
234             model.setMessageCount(getMessageCount());
235             model.setViewCount(getViewCount());
236             model.setLastPostByUserId(getLastPostByUserId());
237             model.setLastPostDate(getLastPostDate());
238             model.setPriority(getPriority());
239 
240             model = (MBThread)Proxy.newProxyInstance(MBThread.class.getClassLoader(),
241                     new Class[] { MBThread.class },
242                     new ReadOnlyBeanHandler(model));
243 
244             return model;
245         }
246     }
247 
248     public Object clone() {
249         MBThreadImpl clone = new MBThreadImpl();
250 
251         clone.setThreadId(getThreadId());
252         clone.setGroupId(getGroupId());
253         clone.setCategoryId(getCategoryId());
254         clone.setRootMessageId(getRootMessageId());
255         clone.setMessageCount(getMessageCount());
256         clone.setViewCount(getViewCount());
257         clone.setLastPostByUserId(getLastPostByUserId());
258         clone.setLastPostDate(getLastPostDate());
259         clone.setPriority(getPriority());
260 
261         return clone;
262     }
263 
264     public int compareTo(MBThread mbThread) {
265         int value = 0;
266 
267         if (getPriority() < mbThread.getPriority()) {
268             value = -1;
269         }
270         else if (getPriority() > mbThread.getPriority()) {
271             value = 1;
272         }
273         else {
274             value = 0;
275         }
276 
277         value = value * -1;
278 
279         if (value != 0) {
280             return value;
281         }
282 
283         value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
284 
285         value = value * -1;
286 
287         if (value != 0) {
288             return value;
289         }
290 
291         return 0;
292     }
293 
294     public boolean equals(Object obj) {
295         if (obj == null) {
296             return false;
297         }
298 
299         MBThread mbThread = null;
300 
301         try {
302             mbThread = (MBThread)obj;
303         }
304         catch (ClassCastException cce) {
305             return false;
306         }
307 
308         long pk = mbThread.getPrimaryKey();
309 
310         if (getPrimaryKey() == pk) {
311             return true;
312         }
313         else {
314             return false;
315         }
316     }
317 
318     public int hashCode() {
319         return (int)getPrimaryKey();
320     }
321 
322     public String toString() {
323         StringBuilder sb = new StringBuilder();
324 
325         sb.append("{threadId=");
326         sb.append(getThreadId());
327         sb.append(", groupId=");
328         sb.append(getGroupId());
329         sb.append(", categoryId=");
330         sb.append(getCategoryId());
331         sb.append(", rootMessageId=");
332         sb.append(getRootMessageId());
333         sb.append(", messageCount=");
334         sb.append(getMessageCount());
335         sb.append(", viewCount=");
336         sb.append(getViewCount());
337         sb.append(", lastPostByUserId=");
338         sb.append(getLastPostByUserId());
339         sb.append(", lastPostDate=");
340         sb.append(getLastPostDate());
341         sb.append(", priority=");
342         sb.append(getPriority());
343         sb.append("}");
344 
345         return sb.toString();
346     }
347 
348     public String toXmlString() {
349         StringBuilder sb = new StringBuilder();
350 
351         sb.append("<model><model-name>");
352         sb.append("com.liferay.portlet.messageboards.model.MBThread");
353         sb.append("</model-name>");
354 
355         sb.append(
356             "<column><column-name>threadId</column-name><column-value><![CDATA[");
357         sb.append(getThreadId());
358         sb.append("]]></column-value></column>");
359         sb.append(
360             "<column><column-name>groupId</column-name><column-value><![CDATA[");
361         sb.append(getGroupId());
362         sb.append("]]></column-value></column>");
363         sb.append(
364             "<column><column-name>categoryId</column-name><column-value><![CDATA[");
365         sb.append(getCategoryId());
366         sb.append("]]></column-value></column>");
367         sb.append(
368             "<column><column-name>rootMessageId</column-name><column-value><![CDATA[");
369         sb.append(getRootMessageId());
370         sb.append("]]></column-value></column>");
371         sb.append(
372             "<column><column-name>messageCount</column-name><column-value><![CDATA[");
373         sb.append(getMessageCount());
374         sb.append("]]></column-value></column>");
375         sb.append(
376             "<column><column-name>viewCount</column-name><column-value><![CDATA[");
377         sb.append(getViewCount());
378         sb.append("]]></column-value></column>");
379         sb.append(
380             "<column><column-name>lastPostByUserId</column-name><column-value><![CDATA[");
381         sb.append(getLastPostByUserId());
382         sb.append("]]></column-value></column>");
383         sb.append(
384             "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
385         sb.append(getLastPostDate());
386         sb.append("]]></column-value></column>");
387         sb.append(
388             "<column><column-name>priority</column-name><column-value><![CDATA[");
389         sb.append(getPriority());
390         sb.append("]]></column-value></column>");
391 
392         sb.append("</model>");
393 
394         return sb.toString();
395     }
396 
397     private long _threadId;
398     private long _groupId;
399     private long _categoryId;
400     private long _rootMessageId;
401     private int _messageCount;
402     private int _viewCount;
403     private long _lastPostByUserId;
404     private Date _lastPostDate;
405     private double _priority;
406 }