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