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