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