1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.SystemException;
26  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
27  import com.liferay.portal.kernel.util.DateUtil;
28  import com.liferay.portal.kernel.util.GetterUtil;
29  import com.liferay.portal.kernel.util.StringBundler;
30  import com.liferay.portal.model.impl.BaseModelImpl;
31  import com.liferay.portal.service.ServiceContext;
32  import com.liferay.portal.util.PortalUtil;
33  
34  import com.liferay.portlet.expando.model.ExpandoBridge;
35  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
36  import com.liferay.portlet.messageboards.model.MBThread;
37  import com.liferay.portlet.messageboards.model.MBThreadSoap;
38  
39  import java.io.Serializable;
40  
41  import java.lang.reflect.Proxy;
42  
43  import java.sql.Types;
44  
45  import java.util.ArrayList;
46  import java.util.Date;
47  import java.util.List;
48  
49  /**
50   * <a href="MBThreadModelImpl.java.html"><b><i>View Source</i></b></a>
51   *
52   * <p>
53   * ServiceBuilder generated this class. Modifications in this class will be
54   * overwritten the next time is generated.
55   * </p>
56   *
57   * <p>
58   * This interface is a model that represents the MBThread table in the
59   * database.
60   * </p>
61   *
62   * @author    Brian Wing Shun Chan
63   * @see       MBThreadImpl
64   * @see       com.liferay.portlet.messageboards.model.MBThread
65   * @see       com.liferay.portlet.messageboards.model.MBThreadModel
66   * @generated
67   */
68  public class MBThreadModelImpl extends BaseModelImpl<MBThread> {
69      public static final String TABLE_NAME = "MBThread";
70      public static final Object[][] TABLE_COLUMNS = {
71              { "threadId", new Integer(Types.BIGINT) },
72              { "groupId", new Integer(Types.BIGINT) },
73              { "categoryId", new Integer(Types.BIGINT) },
74              { "rootMessageId", new Integer(Types.BIGINT) },
75              { "messageCount", new Integer(Types.INTEGER) },
76              { "viewCount", new Integer(Types.INTEGER) },
77              { "lastPostByUserId", new Integer(Types.BIGINT) },
78              { "lastPostDate", new Integer(Types.TIMESTAMP) },
79              { "priority", new Integer(Types.DOUBLE) }
80          };
81      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)";
82      public static final String TABLE_SQL_DROP = "drop table MBThread";
83      public static final String ORDER_BY_JPQL = " ORDER BY mbThread.priority DESC, mbThread.lastPostDate DESC";
84      public static final String ORDER_BY_SQL = " ORDER BY MBThread.priority DESC, MBThread.lastPostDate DESC";
85      public static final String DATA_SOURCE = "liferayDataSource";
86      public static final String SESSION_FACTORY = "liferaySessionFactory";
87      public static final String TX_MANAGER = "liferayTransactionManager";
88      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
89                  "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
90              true);
91      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
92                  "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBThread"),
93              true);
94  
95      public static MBThread toModel(MBThreadSoap soapModel) {
96          MBThread model = new MBThreadImpl();
97  
98          model.setThreadId(soapModel.getThreadId());
99          model.setGroupId(soapModel.getGroupId());
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(com.liferay.portal.util.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         _threadId = threadId;
145     }
146 
147     public long getGroupId() {
148         return _groupId;
149     }
150 
151     public void setGroupId(long groupId) {
152         _groupId = groupId;
153     }
154 
155     public long getCategoryId() {
156         return _categoryId;
157     }
158 
159     public void setCategoryId(long categoryId) {
160         _categoryId = categoryId;
161     }
162 
163     public long getRootMessageId() {
164         return _rootMessageId;
165     }
166 
167     public void setRootMessageId(long rootMessageId) {
168         _rootMessageId = rootMessageId;
169     }
170 
171     public int getMessageCount() {
172         return _messageCount;
173     }
174 
175     public void setMessageCount(int messageCount) {
176         _messageCount = messageCount;
177     }
178 
179     public int getViewCount() {
180         return _viewCount;
181     }
182 
183     public void setViewCount(int viewCount) {
184         _viewCount = viewCount;
185     }
186 
187     public long getLastPostByUserId() {
188         return _lastPostByUserId;
189     }
190 
191     public void setLastPostByUserId(long lastPostByUserId) {
192         _lastPostByUserId = lastPostByUserId;
193     }
194 
195     public String getLastPostByUserUuid() throws SystemException {
196         return PortalUtil.getUserValue(getLastPostByUserId(), "uuid",
197             _lastPostByUserUuid);
198     }
199 
200     public void setLastPostByUserUuid(String lastPostByUserUuid) {
201         _lastPostByUserUuid = lastPostByUserUuid;
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 ExpandoBridge getExpandoBridge() {
249         if (_expandoBridge == null) {
250             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(MBThread.class.getName(),
251                     getPrimaryKey());
252         }
253 
254         return _expandoBridge;
255     }
256 
257     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
258         getExpandoBridge().setAttributes(serviceContext);
259     }
260 
261     public Object clone() {
262         MBThreadImpl clone = new MBThreadImpl();
263 
264         clone.setThreadId(getThreadId());
265         clone.setGroupId(getGroupId());
266         clone.setCategoryId(getCategoryId());
267         clone.setRootMessageId(getRootMessageId());
268         clone.setMessageCount(getMessageCount());
269         clone.setViewCount(getViewCount());
270         clone.setLastPostByUserId(getLastPostByUserId());
271         clone.setLastPostDate(getLastPostDate());
272         clone.setPriority(getPriority());
273 
274         return clone;
275     }
276 
277     public int compareTo(MBThread mbThread) {
278         int value = 0;
279 
280         if (getPriority() < mbThread.getPriority()) {
281             value = -1;
282         }
283         else if (getPriority() > mbThread.getPriority()) {
284             value = 1;
285         }
286         else {
287             value = 0;
288         }
289 
290         value = value * -1;
291 
292         if (value != 0) {
293             return value;
294         }
295 
296         value = DateUtil.compareTo(getLastPostDate(), mbThread.getLastPostDate());
297 
298         value = value * -1;
299 
300         if (value != 0) {
301             return value;
302         }
303 
304         return 0;
305     }
306 
307     public boolean equals(Object obj) {
308         if (obj == null) {
309             return false;
310         }
311 
312         MBThread mbThread = null;
313 
314         try {
315             mbThread = (MBThread)obj;
316         }
317         catch (ClassCastException cce) {
318             return false;
319         }
320 
321         long pk = mbThread.getPrimaryKey();
322 
323         if (getPrimaryKey() == pk) {
324             return true;
325         }
326         else {
327             return false;
328         }
329     }
330 
331     public int hashCode() {
332         return (int)getPrimaryKey();
333     }
334 
335     public String toString() {
336         StringBundler sb = new StringBundler(19);
337 
338         sb.append("{threadId=");
339         sb.append(getThreadId());
340         sb.append(", groupId=");
341         sb.append(getGroupId());
342         sb.append(", categoryId=");
343         sb.append(getCategoryId());
344         sb.append(", rootMessageId=");
345         sb.append(getRootMessageId());
346         sb.append(", messageCount=");
347         sb.append(getMessageCount());
348         sb.append(", viewCount=");
349         sb.append(getViewCount());
350         sb.append(", lastPostByUserId=");
351         sb.append(getLastPostByUserId());
352         sb.append(", lastPostDate=");
353         sb.append(getLastPostDate());
354         sb.append(", priority=");
355         sb.append(getPriority());
356         sb.append("}");
357 
358         return sb.toString();
359     }
360 
361     public String toXmlString() {
362         StringBundler sb = new StringBundler(31);
363 
364         sb.append("<model><model-name>");
365         sb.append("com.liferay.portlet.messageboards.model.MBThread");
366         sb.append("</model-name>");
367 
368         sb.append(
369             "<column><column-name>threadId</column-name><column-value><![CDATA[");
370         sb.append(getThreadId());
371         sb.append("]]></column-value></column>");
372         sb.append(
373             "<column><column-name>groupId</column-name><column-value><![CDATA[");
374         sb.append(getGroupId());
375         sb.append("]]></column-value></column>");
376         sb.append(
377             "<column><column-name>categoryId</column-name><column-value><![CDATA[");
378         sb.append(getCategoryId());
379         sb.append("]]></column-value></column>");
380         sb.append(
381             "<column><column-name>rootMessageId</column-name><column-value><![CDATA[");
382         sb.append(getRootMessageId());
383         sb.append("]]></column-value></column>");
384         sb.append(
385             "<column><column-name>messageCount</column-name><column-value><![CDATA[");
386         sb.append(getMessageCount());
387         sb.append("]]></column-value></column>");
388         sb.append(
389             "<column><column-name>viewCount</column-name><column-value><![CDATA[");
390         sb.append(getViewCount());
391         sb.append("]]></column-value></column>");
392         sb.append(
393             "<column><column-name>lastPostByUserId</column-name><column-value><![CDATA[");
394         sb.append(getLastPostByUserId());
395         sb.append("]]></column-value></column>");
396         sb.append(
397             "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
398         sb.append(getLastPostDate());
399         sb.append("]]></column-value></column>");
400         sb.append(
401             "<column><column-name>priority</column-name><column-value><![CDATA[");
402         sb.append(getPriority());
403         sb.append("]]></column-value></column>");
404 
405         sb.append("</model>");
406 
407         return sb.toString();
408     }
409 
410     private long _threadId;
411     private long _groupId;
412     private long _categoryId;
413     private long _rootMessageId;
414     private int _messageCount;
415     private int _viewCount;
416     private long _lastPostByUserId;
417     private String _lastPostByUserUuid;
418     private Date _lastPostDate;
419     private double _priority;
420     private transient ExpandoBridge _expandoBridge;
421 }