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.expando.model.ExpandoBridge;
31  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
32  import com.liferay.portlet.messageboards.model.MBThread;
33  import com.liferay.portlet.messageboards.model.MBThreadSoap;
34  
35  import java.io.Serializable;
36  
37  import java.lang.reflect.Proxy;
38  
39  import java.sql.Types;
40  
41  import java.util.ArrayList;
42  import java.util.Date;
43  import java.util.List;
44  
45  /**
46   * <a href="MBThreadModelImpl.java.html"><b><i>View Source</i></b></a>
47   *
48   * <p>
49   * ServiceBuilder generated this class. Modifications in this class will be
50   * overwritten the next time is generated.
51   * </p>
52   *
53   * <p>
54   * This class is a model that represents the <code>MBThread</code> table
55   * in the database.
56   * </p>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   * @see com.liferay.portlet.messageboards.model.MBThread
61   * @see com.liferay.portlet.messageboards.model.MBThreadModel
62   * @see com.liferay.portlet.messageboards.model.impl.MBThreadImpl
63   *
64   */
65  public class MBThreadModelImpl extends BaseModelImpl<MBThread> {
66      public static final String TABLE_NAME = "MBThread";
67      public static final Object[][] TABLE_COLUMNS = {
68              { "threadId", new Integer(Types.BIGINT) },
69              
70  
71              { "groupId", new Integer(Types.BIGINT) },
72              
73  
74              { "categoryId", new Integer(Types.BIGINT) },
75              
76  
77              { "rootMessageId", new Integer(Types.BIGINT) },
78              
79  
80              { "messageCount", new Integer(Types.INTEGER) },
81              
82  
83              { "viewCount", new Integer(Types.INTEGER) },
84              
85  
86              { "lastPostByUserId", new Integer(Types.BIGINT) },
87              
88  
89              { "lastPostDate", new Integer(Types.TIMESTAMP) },
90              
91  
92              { "priority", new Integer(Types.DOUBLE) }
93          };
94      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)";
95      public static final String TABLE_SQL_DROP = "drop table MBThread";
96      public static final String DATA_SOURCE = "liferayDataSource";
97      public static final String SESSION_FACTORY = "liferaySessionFactory";
98      public static final String TX_MANAGER = "liferayTransactionManager";
99      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
100                 "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
101             true);
102     public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
103                 "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
104             true);
105 
106     public static MBThread toModel(MBThreadSoap soapModel) {
107         MBThread model = new MBThreadImpl();
108 
109         model.setThreadId(soapModel.getThreadId());
110         model.setGroupId(soapModel.getGroupId());
111         model.setCategoryId(soapModel.getCategoryId());
112         model.setRootMessageId(soapModel.getRootMessageId());
113         model.setMessageCount(soapModel.getMessageCount());
114         model.setViewCount(soapModel.getViewCount());
115         model.setLastPostByUserId(soapModel.getLastPostByUserId());
116         model.setLastPostDate(soapModel.getLastPostDate());
117         model.setPriority(soapModel.getPriority());
118 
119         return model;
120     }
121 
122     public static List<MBThread> toModels(MBThreadSoap[] soapModels) {
123         List<MBThread> models = new ArrayList<MBThread>(soapModels.length);
124 
125         for (MBThreadSoap soapModel : soapModels) {
126             models.add(toModel(soapModel));
127         }
128 
129         return models;
130     }
131 
132     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
133                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBThread"));
134 
135     public MBThreadModelImpl() {
136     }
137 
138     public long getPrimaryKey() {
139         return _threadId;
140     }
141 
142     public void setPrimaryKey(long pk) {
143         setThreadId(pk);
144     }
145 
146     public Serializable getPrimaryKeyObj() {
147         return new Long(_threadId);
148     }
149 
150     public long getThreadId() {
151         return _threadId;
152     }
153 
154     public void setThreadId(long threadId) {
155         _threadId = threadId;
156     }
157 
158     public long getGroupId() {
159         return _groupId;
160     }
161 
162     public void setGroupId(long groupId) {
163         _groupId = groupId;
164     }
165 
166     public long getCategoryId() {
167         return _categoryId;
168     }
169 
170     public void setCategoryId(long categoryId) {
171         _categoryId = categoryId;
172     }
173 
174     public long getRootMessageId() {
175         return _rootMessageId;
176     }
177 
178     public void setRootMessageId(long rootMessageId) {
179         _rootMessageId = rootMessageId;
180     }
181 
182     public int getMessageCount() {
183         return _messageCount;
184     }
185 
186     public void setMessageCount(int messageCount) {
187         _messageCount = messageCount;
188     }
189 
190     public int getViewCount() {
191         return _viewCount;
192     }
193 
194     public void setViewCount(int viewCount) {
195         _viewCount = viewCount;
196     }
197 
198     public long getLastPostByUserId() {
199         return _lastPostByUserId;
200     }
201 
202     public void setLastPostByUserId(long lastPostByUserId) {
203         _lastPostByUserId = lastPostByUserId;
204     }
205 
206     public Date getLastPostDate() {
207         return _lastPostDate;
208     }
209 
210     public void setLastPostDate(Date lastPostDate) {
211         _lastPostDate = lastPostDate;
212     }
213 
214     public double getPriority() {
215         return _priority;
216     }
217 
218     public void setPriority(double priority) {
219         _priority = priority;
220     }
221 
222     public MBThread toEscapedModel() {
223         if (isEscapedModel()) {
224             return (MBThread)this;
225         }
226         else {
227             MBThread model = new MBThreadImpl();
228 
229             model.setNew(isNew());
230             model.setEscapedModel(true);
231 
232             model.setThreadId(getThreadId());
233             model.setGroupId(getGroupId());
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 ExpandoBridge getExpandoBridge() {
251         if (_expandoBridge == null) {
252             _expandoBridge = new ExpandoBridgeImpl(MBThread.class.getName(),
253                     getPrimaryKey());
254         }
255 
256         return _expandoBridge;
257     }
258 
259     public Object clone() {
260         MBThreadImpl clone = new MBThreadImpl();
261 
262         clone.setThreadId(getThreadId());
263         clone.setGroupId(getGroupId());
264         clone.setCategoryId(getCategoryId());
265         clone.setRootMessageId(getRootMessageId());
266         clone.setMessageCount(getMessageCount());
267         clone.setViewCount(getViewCount());
268         clone.setLastPostByUserId(getLastPostByUserId());
269         clone.setLastPostDate(getLastPostDate());
270         clone.setPriority(getPriority());
271 
272         return clone;
273     }
274 
275     public int compareTo(MBThread mbThread) {
276         int value = 0;
277 
278         if (getPriority() < mbThread.getPriority()) {
279             value = -1;
280         }
281         else if (getPriority() > mbThread.getPriority()) {
282             value = 1;
283         }
284         else {
285             value = 0;
286         }
287 
288         value = value * -1;
289 
290         if (value != 0) {
291             return value;
292         }
293 
294         value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
295 
296         value = value * -1;
297 
298         if (value != 0) {
299             return value;
300         }
301 
302         return 0;
303     }
304 
305     public boolean equals(Object obj) {
306         if (obj == null) {
307             return false;
308         }
309 
310         MBThread mbThread = null;
311 
312         try {
313             mbThread = (MBThread)obj;
314         }
315         catch (ClassCastException cce) {
316             return false;
317         }
318 
319         long pk = mbThread.getPrimaryKey();
320 
321         if (getPrimaryKey() == pk) {
322             return true;
323         }
324         else {
325             return false;
326         }
327     }
328 
329     public int hashCode() {
330         return (int)getPrimaryKey();
331     }
332 
333     public String toString() {
334         StringBuilder sb = new StringBuilder();
335 
336         sb.append("{threadId=");
337         sb.append(getThreadId());
338         sb.append(", groupId=");
339         sb.append(getGroupId());
340         sb.append(", categoryId=");
341         sb.append(getCategoryId());
342         sb.append(", rootMessageId=");
343         sb.append(getRootMessageId());
344         sb.append(", messageCount=");
345         sb.append(getMessageCount());
346         sb.append(", viewCount=");
347         sb.append(getViewCount());
348         sb.append(", lastPostByUserId=");
349         sb.append(getLastPostByUserId());
350         sb.append(", lastPostDate=");
351         sb.append(getLastPostDate());
352         sb.append(", priority=");
353         sb.append(getPriority());
354         sb.append("}");
355 
356         return sb.toString();
357     }
358 
359     public String toXmlString() {
360         StringBuilder sb = new StringBuilder();
361 
362         sb.append("<model><model-name>");
363         sb.append("com.liferay.portlet.messageboards.model.MBThread");
364         sb.append("</model-name>");
365 
366         sb.append(
367             "<column><column-name>threadId</column-name><column-value><![CDATA[");
368         sb.append(getThreadId());
369         sb.append("]]></column-value></column>");
370         sb.append(
371             "<column><column-name>groupId</column-name><column-value><![CDATA[");
372         sb.append(getGroupId());
373         sb.append("]]></column-value></column>");
374         sb.append(
375             "<column><column-name>categoryId</column-name><column-value><![CDATA[");
376         sb.append(getCategoryId());
377         sb.append("]]></column-value></column>");
378         sb.append(
379             "<column><column-name>rootMessageId</column-name><column-value><![CDATA[");
380         sb.append(getRootMessageId());
381         sb.append("]]></column-value></column>");
382         sb.append(
383             "<column><column-name>messageCount</column-name><column-value><![CDATA[");
384         sb.append(getMessageCount());
385         sb.append("]]></column-value></column>");
386         sb.append(
387             "<column><column-name>viewCount</column-name><column-value><![CDATA[");
388         sb.append(getViewCount());
389         sb.append("]]></column-value></column>");
390         sb.append(
391             "<column><column-name>lastPostByUserId</column-name><column-value><![CDATA[");
392         sb.append(getLastPostByUserId());
393         sb.append("]]></column-value></column>");
394         sb.append(
395             "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
396         sb.append(getLastPostDate());
397         sb.append("]]></column-value></column>");
398         sb.append(
399             "<column><column-name>priority</column-name><column-value><![CDATA[");
400         sb.append(getPriority());
401         sb.append("]]></column-value></column>");
402 
403         sb.append("</model>");
404 
405         return sb.toString();
406     }
407 
408     private long _threadId;
409     private long _groupId;
410     private long _categoryId;
411     private long _rootMessageId;
412     private int _messageCount;
413     private int _viewCount;
414     private long _lastPostByUserId;
415     private Date _lastPostDate;
416     private double _priority;
417     private transient ExpandoBridge _expandoBridge;
418 }