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  
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.service.model.MBThread
59   * @see com.liferay.portlet.messageboards.service.model.MBThreadModel
60   * @see com.liferay.portlet.messageboards.service.model.impl.MBThreadImpl
61   *
62   */
63  public class MBThreadModelImpl extends BaseModelImpl {
64      public static final String TABLE_NAME = "MBThread";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "threadId", new Integer(Types.BIGINT) },
67              
68  
69              { "categoryId", new Integer(Types.BIGINT) },
70              
71  
72              { "rootMessageId", new Integer(Types.BIGINT) },
73              
74  
75              { "messageCount", new Integer(Types.INTEGER) },
76              
77  
78              { "viewCount", new Integer(Types.INTEGER) },
79              
80  
81              { "lastPostByUserId", new Integer(Types.BIGINT) },
82              
83  
84              { "lastPostDate", new Integer(Types.TIMESTAMP) },
85              
86  
87              { "priority", new Integer(Types.DOUBLE) }
88          };
89      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)";
90      public static final String TABLE_SQL_DROP = "drop table MBThread";
91      public static final String DATA_SOURCE = "liferayDataSource";
92      public static final String SESSION_FACTORY = "liferaySessionFactory";
93      public static final String TX_MANAGER = "liferayTransactionManager";
94      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
95                  "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
96              true);
97  
98      public static MBThread toModel(MBThreadSoap soapModel) {
99          MBThread model = new MBThreadImpl();
100 
101         model.setThreadId(soapModel.getThreadId());
102         model.setCategoryId(soapModel.getCategoryId());
103         model.setRootMessageId(soapModel.getRootMessageId());
104         model.setMessageCount(soapModel.getMessageCount());
105         model.setViewCount(soapModel.getViewCount());
106         model.setLastPostByUserId(soapModel.getLastPostByUserId());
107         model.setLastPostDate(soapModel.getLastPostDate());
108         model.setPriority(soapModel.getPriority());
109 
110         return model;
111     }
112 
113     public static List<MBThread> toModels(MBThreadSoap[] soapModels) {
114         List<MBThread> models = new ArrayList<MBThread>(soapModels.length);
115 
116         for (MBThreadSoap soapModel : soapModels) {
117             models.add(toModel(soapModel));
118         }
119 
120         return models;
121     }
122 
123     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
124                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBThread"));
125 
126     public MBThreadModelImpl() {
127     }
128 
129     public long getPrimaryKey() {
130         return _threadId;
131     }
132 
133     public void setPrimaryKey(long pk) {
134         setThreadId(pk);
135     }
136 
137     public Serializable getPrimaryKeyObj() {
138         return new Long(_threadId);
139     }
140 
141     public long getThreadId() {
142         return _threadId;
143     }
144 
145     public void setThreadId(long threadId) {
146         if (threadId != _threadId) {
147             _threadId = threadId;
148         }
149     }
150 
151     public long getCategoryId() {
152         return _categoryId;
153     }
154 
155     public void setCategoryId(long categoryId) {
156         if (categoryId != _categoryId) {
157             _categoryId = categoryId;
158         }
159     }
160 
161     public long getRootMessageId() {
162         return _rootMessageId;
163     }
164 
165     public void setRootMessageId(long rootMessageId) {
166         if (rootMessageId != _rootMessageId) {
167             _rootMessageId = rootMessageId;
168         }
169     }
170 
171     public int getMessageCount() {
172         return _messageCount;
173     }
174 
175     public void setMessageCount(int messageCount) {
176         if (messageCount != _messageCount) {
177             _messageCount = messageCount;
178         }
179     }
180 
181     public int getViewCount() {
182         return _viewCount;
183     }
184 
185     public void setViewCount(int viewCount) {
186         if (viewCount != _viewCount) {
187             _viewCount = viewCount;
188         }
189     }
190 
191     public long getLastPostByUserId() {
192         return _lastPostByUserId;
193     }
194 
195     public void setLastPostByUserId(long lastPostByUserId) {
196         if (lastPostByUserId != _lastPostByUserId) {
197             _lastPostByUserId = lastPostByUserId;
198         }
199     }
200 
201     public Date getLastPostDate() {
202         return _lastPostDate;
203     }
204 
205     public void setLastPostDate(Date lastPostDate) {
206         if (((lastPostDate == null) && (_lastPostDate != null)) ||
207                 ((lastPostDate != null) && (_lastPostDate == null)) ||
208                 ((lastPostDate != null) && (_lastPostDate != null) &&
209                 !lastPostDate.equals(_lastPostDate))) {
210             _lastPostDate = lastPostDate;
211         }
212     }
213 
214     public double getPriority() {
215         return _priority;
216     }
217 
218     public void setPriority(double priority) {
219         if (priority != _priority) {
220             _priority = priority;
221         }
222     }
223 
224     public MBThread toEscapedModel() {
225         if (isEscapedModel()) {
226             return (MBThread)this;
227         }
228         else {
229             MBThread model = new MBThreadImpl();
230 
231             model.setEscapedModel(true);
232 
233             model.setThreadId(getThreadId());
234             model.setCategoryId(getCategoryId());
235             model.setRootMessageId(getRootMessageId());
236             model.setMessageCount(getMessageCount());
237             model.setViewCount(getViewCount());
238             model.setLastPostByUserId(getLastPostByUserId());
239             model.setLastPostDate(getLastPostDate());
240             model.setPriority(getPriority());
241 
242             model = (MBThread)Proxy.newProxyInstance(MBThread.class.getClassLoader(),
243                     new Class[] { MBThread.class },
244                     new ReadOnlyBeanHandler(model));
245 
246             return model;
247         }
248     }
249 
250     public Object clone() {
251         MBThreadImpl clone = new MBThreadImpl();
252 
253         clone.setThreadId(getThreadId());
254         clone.setCategoryId(getCategoryId());
255         clone.setRootMessageId(getRootMessageId());
256         clone.setMessageCount(getMessageCount());
257         clone.setViewCount(getViewCount());
258         clone.setLastPostByUserId(getLastPostByUserId());
259         clone.setLastPostDate(getLastPostDate());
260         clone.setPriority(getPriority());
261 
262         return clone;
263     }
264 
265     public int compareTo(Object obj) {
266         if (obj == null) {
267             return -1;
268         }
269 
270         MBThreadImpl mbThread = (MBThreadImpl)obj;
271 
272         int value = 0;
273 
274         if (getPriority() < mbThread.getPriority()) {
275             value = -1;
276         }
277         else if (getPriority() > mbThread.getPriority()) {
278             value = 1;
279         }
280         else {
281             value = 0;
282         }
283 
284         value = value * -1;
285 
286         if (value != 0) {
287             return value;
288         }
289 
290         value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
291 
292         value = value * -1;
293 
294         if (value != 0) {
295             return value;
296         }
297 
298         return 0;
299     }
300 
301     public boolean equals(Object obj) {
302         if (obj == null) {
303             return false;
304         }
305 
306         MBThreadImpl mbThread = null;
307 
308         try {
309             mbThread = (MBThreadImpl)obj;
310         }
311         catch (ClassCastException cce) {
312             return false;
313         }
314 
315         long pk = mbThread.getPrimaryKey();
316 
317         if (getPrimaryKey() == pk) {
318             return true;
319         }
320         else {
321             return false;
322         }
323     }
324 
325     public int hashCode() {
326         return (int)getPrimaryKey();
327     }
328 
329     private long _threadId;
330     private long _categoryId;
331     private long _rootMessageId;
332     private int _messageCount;
333     private int _viewCount;
334     private long _lastPostByUserId;
335     private Date _lastPostDate;
336     private double _priority;
337 }