1   /**
2    * Copyright (c) 2000-2008 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  import com.liferay.portal.util.PropsUtil;
30  
31  import com.liferay.portlet.messageboards.model.MBThread;
32  import com.liferay.portlet.messageboards.model.MBThreadSoap;
33  
34  import java.io.Serializable;
35  
36  import java.lang.reflect.Proxy;
37  
38  import java.sql.Types;
39  
40  import java.util.ArrayList;
41  import java.util.Date;
42  import java.util.List;
43  
44  /**
45   * <a href="MBThreadModelImpl.java.html"><b><i>View Source</i></b></a>
46   *
47   * <p>
48   * ServiceBuilder generated this class. Modifications in this class will be
49   * overwritten the next time is generated.
50   * </p>
51   *
52   * <p>
53   * This class is a model that represents the <code>MBThread</code> table
54   * in the database.
55   * </p>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   * @see com.liferay.portlet.messageboards.service.model.MBThread
60   * @see com.liferay.portlet.messageboards.service.model.MBThreadModel
61   * @see com.liferay.portlet.messageboards.service.model.impl.MBThreadImpl
62   *
63   */
64  public class MBThreadModelImpl extends BaseModelImpl {
65      public static final String TABLE_NAME = "MBThread";
66      public static final Object[][] TABLE_COLUMNS = {
67              { "threadId", new Integer(Types.BIGINT) },
68              
69  
70              { "categoryId", new Integer(Types.BIGINT) },
71              
72  
73              { "rootMessageId", new Integer(Types.BIGINT) },
74              
75  
76              { "messageCount", new Integer(Types.INTEGER) },
77              
78  
79              { "viewCount", new Integer(Types.INTEGER) },
80              
81  
82              { "lastPostByUserId", new Integer(Types.BIGINT) },
83              
84  
85              { "lastPostDate", new Integer(Types.TIMESTAMP) },
86              
87  
88              { "priority", new Integer(Types.DOUBLE) }
89          };
90      public static final String TABLE_SQL_CREATE = "create table MBThread (threadId LONG not null primary key,categoryId LONG,rootMessageId LONG,messageCount INTEGER,viewCount INTEGER,lastPostByUserId LONG,lastPostDate DATE null,priority DOUBLE)";
91      public static final String TABLE_SQL_DROP = "drop table MBThread";
92      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
93                  "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
94              true);
95  
96      public static MBThread toModel(MBThreadSoap soapModel) {
97          MBThread model = new MBThreadImpl();
98  
99          model.setThreadId(soapModel.getThreadId());
100         model.setCategoryId(soapModel.getCategoryId());
101         model.setRootMessageId(soapModel.getRootMessageId());
102         model.setMessageCount(soapModel.getMessageCount());
103         model.setViewCount(soapModel.getViewCount());
104         model.setLastPostByUserId(soapModel.getLastPostByUserId());
105         model.setLastPostDate(soapModel.getLastPostDate());
106         model.setPriority(soapModel.getPriority());
107 
108         return model;
109     }
110 
111     public static List<MBThread> toModels(MBThreadSoap[] soapModels) {
112         List<MBThread> models = new ArrayList<MBThread>(soapModels.length);
113 
114         for (MBThreadSoap soapModel : soapModels) {
115             models.add(toModel(soapModel));
116         }
117 
118         return models;
119     }
120 
121     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
122                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBThread"));
123 
124     public MBThreadModelImpl() {
125     }
126 
127     public long getPrimaryKey() {
128         return _threadId;
129     }
130 
131     public void setPrimaryKey(long pk) {
132         setThreadId(pk);
133     }
134 
135     public Serializable getPrimaryKeyObj() {
136         return new Long(_threadId);
137     }
138 
139     public long getThreadId() {
140         return _threadId;
141     }
142 
143     public void setThreadId(long threadId) {
144         if (threadId != _threadId) {
145             _threadId = threadId;
146         }
147     }
148 
149     public long getCategoryId() {
150         return _categoryId;
151     }
152 
153     public void setCategoryId(long categoryId) {
154         if (categoryId != _categoryId) {
155             _categoryId = categoryId;
156         }
157     }
158 
159     public long getRootMessageId() {
160         return _rootMessageId;
161     }
162 
163     public void setRootMessageId(long rootMessageId) {
164         if (rootMessageId != _rootMessageId) {
165             _rootMessageId = rootMessageId;
166         }
167     }
168 
169     public int getMessageCount() {
170         return _messageCount;
171     }
172 
173     public void setMessageCount(int messageCount) {
174         if (messageCount != _messageCount) {
175             _messageCount = messageCount;
176         }
177     }
178 
179     public int getViewCount() {
180         return _viewCount;
181     }
182 
183     public void setViewCount(int viewCount) {
184         if (viewCount != _viewCount) {
185             _viewCount = viewCount;
186         }
187     }
188 
189     public long getLastPostByUserId() {
190         return _lastPostByUserId;
191     }
192 
193     public void setLastPostByUserId(long lastPostByUserId) {
194         if (lastPostByUserId != _lastPostByUserId) {
195             _lastPostByUserId = lastPostByUserId;
196         }
197     }
198 
199     public Date getLastPostDate() {
200         return _lastPostDate;
201     }
202 
203     public void setLastPostDate(Date lastPostDate) {
204         if (((lastPostDate == null) && (_lastPostDate != null)) ||
205                 ((lastPostDate != null) && (_lastPostDate == null)) ||
206                 ((lastPostDate != null) && (_lastPostDate != null) &&
207                 !lastPostDate.equals(_lastPostDate))) {
208             _lastPostDate = lastPostDate;
209         }
210     }
211 
212     public double getPriority() {
213         return _priority;
214     }
215 
216     public void setPriority(double priority) {
217         if (priority != _priority) {
218             _priority = priority;
219         }
220     }
221 
222     public MBThread toEscapedModel() {
223         if (isEscapedModel()) {
224             return (MBThread)this;
225         }
226         else {
227             MBThread model = new MBThreadImpl();
228 
229             model.setEscapedModel(true);
230 
231             model.setThreadId(getThreadId());
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.setCategoryId(getCategoryId());
253         clone.setRootMessageId(getRootMessageId());
254         clone.setMessageCount(getMessageCount());
255         clone.setViewCount(getViewCount());
256         clone.setLastPostByUserId(getLastPostByUserId());
257         clone.setLastPostDate(getLastPostDate());
258         clone.setPriority(getPriority());
259 
260         return clone;
261     }
262 
263     public int compareTo(Object obj) {
264         if (obj == null) {
265             return -1;
266         }
267 
268         MBThreadImpl mbThread = (MBThreadImpl)obj;
269 
270         int value = 0;
271 
272         if (getPriority() < mbThread.getPriority()) {
273             value = -1;
274         }
275         else if (getPriority() > mbThread.getPriority()) {
276             value = 1;
277         }
278         else {
279             value = 0;
280         }
281 
282         value = value * -1;
283 
284         if (value != 0) {
285             return value;
286         }
287 
288         value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
289 
290         value = value * -1;
291 
292         if (value != 0) {
293             return value;
294         }
295 
296         return 0;
297     }
298 
299     public boolean equals(Object obj) {
300         if (obj == null) {
301             return false;
302         }
303 
304         MBThreadImpl mbThread = null;
305 
306         try {
307             mbThread = (MBThreadImpl)obj;
308         }
309         catch (ClassCastException cce) {
310             return false;
311         }
312 
313         long pk = mbThread.getPrimaryKey();
314 
315         if (getPrimaryKey() == pk) {
316             return true;
317         }
318         else {
319             return false;
320         }
321     }
322 
323     public int hashCode() {
324         return (int)getPrimaryKey();
325     }
326 
327     private long _threadId;
328     private long _categoryId;
329     private long _rootMessageId;
330     private int _messageCount;
331     private int _viewCount;
332     private long _lastPostByUserId;
333     private Date _lastPostDate;
334     private double _priority;
335 }