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.kernel.util.HtmlUtil;
26  import com.liferay.portal.model.impl.BaseModelImpl;
27  
28  import com.liferay.portlet.messageboards.model.MBMessage;
29  import com.liferay.portlet.messageboards.model.MBMessageSoap;
30  
31  import java.io.Serializable;
32  
33  import java.lang.reflect.Proxy;
34  
35  import java.sql.Types;
36  
37  import java.util.ArrayList;
38  import java.util.Date;
39  import java.util.List;
40  
41  /**
42   * <a href="MBMessageModelImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * <p>
45   * ServiceBuilder generated this class. Modifications in this class will be
46   * overwritten the next time is generated.
47   * </p>
48   *
49   * <p>
50   * This class is a model that represents the <code>MBMessage</code> table
51   * in the database.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   * @see com.liferay.portlet.messageboards.model.MBMessage
57   * @see com.liferay.portlet.messageboards.model.MBMessageModel
58   * @see com.liferay.portlet.messageboards.model.impl.MBMessageImpl
59   *
60   */
61  public class MBMessageModelImpl extends BaseModelImpl {
62      public static final String TABLE_NAME = "MBMessage";
63      public static final Object[][] TABLE_COLUMNS = {
64              { "uuid_", new Integer(Types.VARCHAR) },
65              
66  
67              { "messageId", new Integer(Types.BIGINT) },
68              
69  
70              { "companyId", new Integer(Types.BIGINT) },
71              
72  
73              { "userId", new Integer(Types.BIGINT) },
74              
75  
76              { "userName", new Integer(Types.VARCHAR) },
77              
78  
79              { "createDate", new Integer(Types.TIMESTAMP) },
80              
81  
82              { "modifiedDate", new Integer(Types.TIMESTAMP) },
83              
84  
85              { "categoryId", new Integer(Types.BIGINT) },
86              
87  
88              { "threadId", new Integer(Types.BIGINT) },
89              
90  
91              { "parentMessageId", new Integer(Types.BIGINT) },
92              
93  
94              { "subject", new Integer(Types.VARCHAR) },
95              
96  
97              { "body", new Integer(Types.CLOB) },
98              
99  
100             { "attachments", new Integer(Types.BOOLEAN) },
101             
102 
103             { "anonymous", new Integer(Types.BOOLEAN) }
104         };
105     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)";
106     public static final String TABLE_SQL_DROP = "drop table MBMessage";
107     public static final String DATA_SOURCE = "liferayDataSource";
108     public static final String SESSION_FACTORY = "liferaySessionFactory";
109     public static final String TX_MANAGER = "liferayTransactionManager";
110     public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
111                 "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBMessage"),
112             true);
113 
114     public static MBMessage toModel(MBMessageSoap soapModel) {
115         MBMessage model = new MBMessageImpl();
116 
117         model.setUuid(soapModel.getUuid());
118         model.setMessageId(soapModel.getMessageId());
119         model.setCompanyId(soapModel.getCompanyId());
120         model.setUserId(soapModel.getUserId());
121         model.setUserName(soapModel.getUserName());
122         model.setCreateDate(soapModel.getCreateDate());
123         model.setModifiedDate(soapModel.getModifiedDate());
124         model.setCategoryId(soapModel.getCategoryId());
125         model.setThreadId(soapModel.getThreadId());
126         model.setParentMessageId(soapModel.getParentMessageId());
127         model.setSubject(soapModel.getSubject());
128         model.setBody(soapModel.getBody());
129         model.setAttachments(soapModel.getAttachments());
130         model.setAnonymous(soapModel.getAnonymous());
131 
132         return model;
133     }
134 
135     public static List<MBMessage> toModels(MBMessageSoap[] soapModels) {
136         List<MBMessage> models = new ArrayList<MBMessage>(soapModels.length);
137 
138         for (MBMessageSoap soapModel : soapModels) {
139             models.add(toModel(soapModel));
140         }
141 
142         return models;
143     }
144 
145     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
146                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBMessage"));
147 
148     public MBMessageModelImpl() {
149     }
150 
151     public long getPrimaryKey() {
152         return _messageId;
153     }
154 
155     public void setPrimaryKey(long pk) {
156         setMessageId(pk);
157     }
158 
159     public Serializable getPrimaryKeyObj() {
160         return new Long(_messageId);
161     }
162 
163     public String getUuid() {
164         return GetterUtil.getString(_uuid);
165     }
166 
167     public void setUuid(String uuid) {
168         if ((uuid != null) && (uuid != _uuid)) {
169             _uuid = uuid;
170         }
171     }
172 
173     public long getMessageId() {
174         return _messageId;
175     }
176 
177     public void setMessageId(long messageId) {
178         if (messageId != _messageId) {
179             _messageId = messageId;
180         }
181     }
182 
183     public long getCompanyId() {
184         return _companyId;
185     }
186 
187     public void setCompanyId(long companyId) {
188         if (companyId != _companyId) {
189             _companyId = companyId;
190         }
191     }
192 
193     public long getUserId() {
194         return _userId;
195     }
196 
197     public void setUserId(long userId) {
198         if (userId != _userId) {
199             _userId = userId;
200         }
201     }
202 
203     public String getUserName() {
204         return GetterUtil.getString(_userName);
205     }
206 
207     public void setUserName(String userName) {
208         if (((userName == null) && (_userName != null)) ||
209                 ((userName != null) && (_userName == null)) ||
210                 ((userName != null) && (_userName != null) &&
211                 !userName.equals(_userName))) {
212             _userName = userName;
213         }
214     }
215 
216     public Date getCreateDate() {
217         return _createDate;
218     }
219 
220     public void setCreateDate(Date createDate) {
221         if (((createDate == null) && (_createDate != null)) ||
222                 ((createDate != null) && (_createDate == null)) ||
223                 ((createDate != null) && (_createDate != null) &&
224                 !createDate.equals(_createDate))) {
225             _createDate = createDate;
226         }
227     }
228 
229     public Date getModifiedDate() {
230         return _modifiedDate;
231     }
232 
233     public void setModifiedDate(Date modifiedDate) {
234         if (((modifiedDate == null) && (_modifiedDate != null)) ||
235                 ((modifiedDate != null) && (_modifiedDate == null)) ||
236                 ((modifiedDate != null) && (_modifiedDate != null) &&
237                 !modifiedDate.equals(_modifiedDate))) {
238             _modifiedDate = modifiedDate;
239         }
240     }
241 
242     public long getCategoryId() {
243         return _categoryId;
244     }
245 
246     public void setCategoryId(long categoryId) {
247         if (categoryId != _categoryId) {
248             _categoryId = categoryId;
249         }
250     }
251 
252     public long getThreadId() {
253         return _threadId;
254     }
255 
256     public void setThreadId(long threadId) {
257         if (threadId != _threadId) {
258             _threadId = threadId;
259         }
260     }
261 
262     public long getParentMessageId() {
263         return _parentMessageId;
264     }
265 
266     public void setParentMessageId(long parentMessageId) {
267         if (parentMessageId != _parentMessageId) {
268             _parentMessageId = parentMessageId;
269         }
270     }
271 
272     public String getSubject() {
273         return GetterUtil.getString(_subject);
274     }
275 
276     public void setSubject(String subject) {
277         if (((subject == null) && (_subject != null)) ||
278                 ((subject != null) && (_subject == null)) ||
279                 ((subject != null) && (_subject != null) &&
280                 !subject.equals(_subject))) {
281             _subject = subject;
282         }
283     }
284 
285     public String getBody() {
286         return GetterUtil.getString(_body);
287     }
288 
289     public void setBody(String body) {
290         if (((body == null) && (_body != null)) ||
291                 ((body != null) && (_body == null)) ||
292                 ((body != null) && (_body != null) && !body.equals(_body))) {
293             _body = body;
294         }
295     }
296 
297     public boolean getAttachments() {
298         return _attachments;
299     }
300 
301     public boolean isAttachments() {
302         return _attachments;
303     }
304 
305     public void setAttachments(boolean attachments) {
306         if (attachments != _attachments) {
307             _attachments = attachments;
308         }
309     }
310 
311     public boolean getAnonymous() {
312         return _anonymous;
313     }
314 
315     public boolean isAnonymous() {
316         return _anonymous;
317     }
318 
319     public void setAnonymous(boolean anonymous) {
320         if (anonymous != _anonymous) {
321             _anonymous = anonymous;
322         }
323     }
324 
325     public MBMessage toEscapedModel() {
326         if (isEscapedModel()) {
327             return (MBMessage)this;
328         }
329         else {
330             MBMessage model = new MBMessageImpl();
331 
332             model.setNew(isNew());
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 }