1   /**
2    * Copyright (c) 2000-2008 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.kernel.util.HtmlUtil;
29  import com.liferay.portal.model.impl.BaseModelImpl;
30  import com.liferay.portal.util.PropsUtil;
31  
32  import com.liferay.portlet.messageboards.model.MBMessage;
33  import com.liferay.portlet.messageboards.model.MBMessageSoap;
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="MBMessageModelImpl.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>MBMessage</code> table
55   * in the database.
56   * </p>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   * @see com.liferay.portlet.messageboards.service.model.MBMessage
61   * @see com.liferay.portlet.messageboards.service.model.MBMessageModel
62   * @see com.liferay.portlet.messageboards.service.model.impl.MBMessageImpl
63   *
64   */
65  public class MBMessageModelImpl extends BaseModelImpl {
66      public static final String TABLE_NAME = "MBMessage";
67      public static final Object[][] TABLE_COLUMNS = {
68              { "uuid_", new Integer(Types.VARCHAR) },
69              
70  
71              { "messageId", new Integer(Types.BIGINT) },
72              
73  
74              { "companyId", new Integer(Types.BIGINT) },
75              
76  
77              { "userId", new Integer(Types.BIGINT) },
78              
79  
80              { "userName", new Integer(Types.VARCHAR) },
81              
82  
83              { "createDate", new Integer(Types.TIMESTAMP) },
84              
85  
86              { "modifiedDate", new Integer(Types.TIMESTAMP) },
87              
88  
89              { "categoryId", new Integer(Types.BIGINT) },
90              
91  
92              { "threadId", new Integer(Types.BIGINT) },
93              
94  
95              { "parentMessageId", new Integer(Types.BIGINT) },
96              
97  
98              { "subject", new Integer(Types.VARCHAR) },
99              
100 
101             { "body", new Integer(Types.CLOB) },
102             
103 
104             { "attachments", new Integer(Types.BOOLEAN) },
105             
106 
107             { "anonymous", new Integer(Types.BOOLEAN) }
108         };
109     public static final String TABLE_SQL_CREATE = "create table MBMessage (uuid_ VARCHAR(75) null,messageId LONG not null primary key,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,categoryId LONG,threadId LONG,parentMessageId LONG,subject VARCHAR(75) null,body TEXT null,attachments BOOLEAN,anonymous BOOLEAN)";
110     public static final String TABLE_SQL_DROP = "drop table MBMessage";
111     public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
112                 "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBMessage"),
113             true);
114 
115     public static MBMessage toModel(MBMessageSoap soapModel) {
116         MBMessage model = new MBMessageImpl();
117 
118         model.setUuid(soapModel.getUuid());
119         model.setMessageId(soapModel.getMessageId());
120         model.setCompanyId(soapModel.getCompanyId());
121         model.setUserId(soapModel.getUserId());
122         model.setUserName(soapModel.getUserName());
123         model.setCreateDate(soapModel.getCreateDate());
124         model.setModifiedDate(soapModel.getModifiedDate());
125         model.setCategoryId(soapModel.getCategoryId());
126         model.setThreadId(soapModel.getThreadId());
127         model.setParentMessageId(soapModel.getParentMessageId());
128         model.setSubject(soapModel.getSubject());
129         model.setBody(soapModel.getBody());
130         model.setAttachments(soapModel.getAttachments());
131         model.setAnonymous(soapModel.getAnonymous());
132 
133         return model;
134     }
135 
136     public static List<MBMessage> toModels(MBMessageSoap[] soapModels) {
137         List<MBMessage> models = new ArrayList<MBMessage>(soapModels.length);
138 
139         for (MBMessageSoap soapModel : soapModels) {
140             models.add(toModel(soapModel));
141         }
142 
143         return models;
144     }
145 
146     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
147                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBMessage"));
148 
149     public MBMessageModelImpl() {
150     }
151 
152     public long getPrimaryKey() {
153         return _messageId;
154     }
155 
156     public void setPrimaryKey(long pk) {
157         setMessageId(pk);
158     }
159 
160     public Serializable getPrimaryKeyObj() {
161         return new Long(_messageId);
162     }
163 
164     public String getUuid() {
165         return GetterUtil.getString(_uuid);
166     }
167 
168     public void setUuid(String uuid) {
169         if ((uuid != null) && (uuid != _uuid)) {
170             _uuid = uuid;
171         }
172     }
173 
174     public long getMessageId() {
175         return _messageId;
176     }
177 
178     public void setMessageId(long messageId) {
179         if (messageId != _messageId) {
180             _messageId = messageId;
181         }
182     }
183 
184     public long getCompanyId() {
185         return _companyId;
186     }
187 
188     public void setCompanyId(long companyId) {
189         if (companyId != _companyId) {
190             _companyId = companyId;
191         }
192     }
193 
194     public long getUserId() {
195         return _userId;
196     }
197 
198     public void setUserId(long userId) {
199         if (userId != _userId) {
200             _userId = userId;
201         }
202     }
203 
204     public String getUserName() {
205         return GetterUtil.getString(_userName);
206     }
207 
208     public void setUserName(String userName) {
209         if (((userName == null) && (_userName != null)) ||
210                 ((userName != null) && (_userName == null)) ||
211                 ((userName != null) && (_userName != null) &&
212                 !userName.equals(_userName))) {
213             _userName = userName;
214         }
215     }
216 
217     public Date getCreateDate() {
218         return _createDate;
219     }
220 
221     public void setCreateDate(Date createDate) {
222         if (((createDate == null) && (_createDate != null)) ||
223                 ((createDate != null) && (_createDate == null)) ||
224                 ((createDate != null) && (_createDate != null) &&
225                 !createDate.equals(_createDate))) {
226             _createDate = createDate;
227         }
228     }
229 
230     public Date getModifiedDate() {
231         return _modifiedDate;
232     }
233 
234     public void setModifiedDate(Date modifiedDate) {
235         if (((modifiedDate == null) && (_modifiedDate != null)) ||
236                 ((modifiedDate != null) && (_modifiedDate == null)) ||
237                 ((modifiedDate != null) && (_modifiedDate != null) &&
238                 !modifiedDate.equals(_modifiedDate))) {
239             _modifiedDate = modifiedDate;
240         }
241     }
242 
243     public long getCategoryId() {
244         return _categoryId;
245     }
246 
247     public void setCategoryId(long categoryId) {
248         if (categoryId != _categoryId) {
249             _categoryId = categoryId;
250         }
251     }
252 
253     public long getThreadId() {
254         return _threadId;
255     }
256 
257     public void setThreadId(long threadId) {
258         if (threadId != _threadId) {
259             _threadId = threadId;
260         }
261     }
262 
263     public long getParentMessageId() {
264         return _parentMessageId;
265     }
266 
267     public void setParentMessageId(long parentMessageId) {
268         if (parentMessageId != _parentMessageId) {
269             _parentMessageId = parentMessageId;
270         }
271     }
272 
273     public String getSubject() {
274         return GetterUtil.getString(_subject);
275     }
276 
277     public void setSubject(String subject) {
278         if (((subject == null) && (_subject != null)) ||
279                 ((subject != null) && (_subject == null)) ||
280                 ((subject != null) && (_subject != null) &&
281                 !subject.equals(_subject))) {
282             _subject = subject;
283         }
284     }
285 
286     public String getBody() {
287         return GetterUtil.getString(_body);
288     }
289 
290     public void setBody(String body) {
291         if (((body == null) && (_body != null)) ||
292                 ((body != null) && (_body == null)) ||
293                 ((body != null) && (_body != null) && !body.equals(_body))) {
294             _body = body;
295         }
296     }
297 
298     public boolean getAttachments() {
299         return _attachments;
300     }
301 
302     public boolean isAttachments() {
303         return _attachments;
304     }
305 
306     public void setAttachments(boolean attachments) {
307         if (attachments != _attachments) {
308             _attachments = attachments;
309         }
310     }
311 
312     public boolean getAnonymous() {
313         return _anonymous;
314     }
315 
316     public boolean isAnonymous() {
317         return _anonymous;
318     }
319 
320     public void setAnonymous(boolean anonymous) {
321         if (anonymous != _anonymous) {
322             _anonymous = anonymous;
323         }
324     }
325 
326     public MBMessage toEscapedModel() {
327         if (isEscapedModel()) {
328             return (MBMessage)this;
329         }
330         else {
331             MBMessage model = new MBMessageImpl();
332 
333             model.setEscapedModel(true);
334 
335             model.setUuid(HtmlUtil.escape(getUuid()));
336             model.setMessageId(getMessageId());
337             model.setCompanyId(getCompanyId());
338             model.setUserId(getUserId());
339             model.setUserName(HtmlUtil.escape(getUserName()));
340             model.setCreateDate(getCreateDate());
341             model.setModifiedDate(getModifiedDate());
342             model.setCategoryId(getCategoryId());
343             model.setThreadId(getThreadId());
344             model.setParentMessageId(getParentMessageId());
345             model.setSubject(HtmlUtil.escape(getSubject()));
346             model.setBody(HtmlUtil.escape(getBody()));
347             model.setAttachments(getAttachments());
348             model.setAnonymous(getAnonymous());
349 
350             model = (MBMessage)Proxy.newProxyInstance(MBMessage.class.getClassLoader(),
351                     new Class[] { MBMessage.class },
352                     new ReadOnlyBeanHandler(model));
353 
354             return model;
355         }
356     }
357 
358     public Object clone() {
359         MBMessageImpl clone = new MBMessageImpl();
360 
361         clone.setUuid(getUuid());
362         clone.setMessageId(getMessageId());
363         clone.setCompanyId(getCompanyId());
364         clone.setUserId(getUserId());
365         clone.setUserName(getUserName());
366         clone.setCreateDate(getCreateDate());
367         clone.setModifiedDate(getModifiedDate());
368         clone.setCategoryId(getCategoryId());
369         clone.setThreadId(getThreadId());
370         clone.setParentMessageId(getParentMessageId());
371         clone.setSubject(getSubject());
372         clone.setBody(getBody());
373         clone.setAttachments(getAttachments());
374         clone.setAnonymous(getAnonymous());
375 
376         return clone;
377     }
378 
379     public int compareTo(Object obj) {
380         if (obj == null) {
381             return -1;
382         }
383 
384         MBMessageImpl mbMessage = (MBMessageImpl)obj;
385 
386         int value = 0;
387 
388         value = DateUtil.compareTo(getCreateDate(), mbMessage.getCreateDate());
389 
390         if (value != 0) {
391             return value;
392         }
393 
394         if (getMessageId() < mbMessage.getMessageId()) {
395             value = -1;
396         }
397         else if (getMessageId() > mbMessage.getMessageId()) {
398             value = 1;
399         }
400         else {
401             value = 0;
402         }
403 
404         if (value != 0) {
405             return value;
406         }
407 
408         return 0;
409     }
410 
411     public boolean equals(Object obj) {
412         if (obj == null) {
413             return false;
414         }
415 
416         MBMessageImpl mbMessage = null;
417 
418         try {
419             mbMessage = (MBMessageImpl)obj;
420         }
421         catch (ClassCastException cce) {
422             return false;
423         }
424 
425         long pk = mbMessage.getPrimaryKey();
426 
427         if (getPrimaryKey() == pk) {
428             return true;
429         }
430         else {
431             return false;
432         }
433     }
434 
435     public int hashCode() {
436         return (int)getPrimaryKey();
437     }
438 
439     private String _uuid;
440     private long _messageId;
441     private long _companyId;
442     private long _userId;
443     private String _userName;
444     private Date _createDate;
445     private Date _modifiedDate;
446     private long _categoryId;
447     private long _threadId;
448     private long _parentMessageId;
449     private String _subject;
450     private String _body;
451     private boolean _attachments;
452     private boolean _anonymous;
453 }