1   /**
2    * Copyright (c) 2000-2009 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.GetterUtil;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.model.impl.BaseModelImpl;
29  import com.liferay.portal.util.PortalUtil;
30  
31  import com.liferay.portlet.expando.model.ExpandoBridge;
32  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
33  import com.liferay.portlet.messageboards.model.MBDiscussion;
34  import com.liferay.portlet.messageboards.model.MBDiscussionSoap;
35  
36  import java.io.Serializable;
37  
38  import java.lang.reflect.Proxy;
39  
40  import java.sql.Types;
41  
42  import java.util.ArrayList;
43  import java.util.List;
44  
45  /**
46   * <a href="MBDiscussionModelImpl.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>MBDiscussion</code> table
55   * in the database.
56   * </p>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   * @see com.liferay.portlet.messageboards.model.MBDiscussion
61   * @see com.liferay.portlet.messageboards.model.MBDiscussionModel
62   * @see com.liferay.portlet.messageboards.model.impl.MBDiscussionImpl
63   *
64   */
65  public class MBDiscussionModelImpl extends BaseModelImpl {
66      public static final String TABLE_NAME = "MBDiscussion";
67      public static final Object[][] TABLE_COLUMNS = {
68              { "discussionId", new Integer(Types.BIGINT) },
69              
70  
71              { "classNameId", new Integer(Types.BIGINT) },
72              
73  
74              { "classPK", new Integer(Types.BIGINT) },
75              
76  
77              { "threadId", new Integer(Types.BIGINT) }
78          };
79      public static final String TABLE_SQL_CREATE = "create table MBDiscussion (discussionId LONG not null primary key,classNameId LONG,classPK LONG,threadId LONG)";
80      public static final String TABLE_SQL_DROP = "drop table MBDiscussion";
81      public static final String DATA_SOURCE = "liferayDataSource";
82      public static final String SESSION_FACTORY = "liferaySessionFactory";
83      public static final String TX_MANAGER = "liferayTransactionManager";
84      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
85                  "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBDiscussion"),
86              true);
87  
88      public static MBDiscussion toModel(MBDiscussionSoap soapModel) {
89          MBDiscussion model = new MBDiscussionImpl();
90  
91          model.setDiscussionId(soapModel.getDiscussionId());
92          model.setClassNameId(soapModel.getClassNameId());
93          model.setClassPK(soapModel.getClassPK());
94          model.setThreadId(soapModel.getThreadId());
95  
96          return model;
97      }
98  
99      public static List<MBDiscussion> toModels(MBDiscussionSoap[] soapModels) {
100         List<MBDiscussion> models = new ArrayList<MBDiscussion>(soapModels.length);
101 
102         for (MBDiscussionSoap soapModel : soapModels) {
103             models.add(toModel(soapModel));
104         }
105 
106         return models;
107     }
108 
109     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
110                 "lock.expiration.time.com.liferay.portlet.messageboards.model.MBDiscussion"));
111 
112     public MBDiscussionModelImpl() {
113     }
114 
115     public long getPrimaryKey() {
116         return _discussionId;
117     }
118 
119     public void setPrimaryKey(long pk) {
120         setDiscussionId(pk);
121     }
122 
123     public Serializable getPrimaryKeyObj() {
124         return new Long(_discussionId);
125     }
126 
127     public long getDiscussionId() {
128         return _discussionId;
129     }
130 
131     public void setDiscussionId(long discussionId) {
132         if (discussionId != _discussionId) {
133             _discussionId = discussionId;
134         }
135     }
136 
137     public String getClassName() {
138         if (getClassNameId() <= 0) {
139             return StringPool.BLANK;
140         }
141 
142         return PortalUtil.getClassName(getClassNameId());
143     }
144 
145     public long getClassNameId() {
146         return _classNameId;
147     }
148 
149     public void setClassNameId(long classNameId) {
150         if (classNameId != _classNameId) {
151             _classNameId = classNameId;
152         }
153     }
154 
155     public long getClassPK() {
156         return _classPK;
157     }
158 
159     public void setClassPK(long classPK) {
160         if (classPK != _classPK) {
161             _classPK = classPK;
162         }
163     }
164 
165     public long getThreadId() {
166         return _threadId;
167     }
168 
169     public void setThreadId(long threadId) {
170         if (threadId != _threadId) {
171             _threadId = threadId;
172         }
173     }
174 
175     public MBDiscussion toEscapedModel() {
176         if (isEscapedModel()) {
177             return (MBDiscussion)this;
178         }
179         else {
180             MBDiscussion model = new MBDiscussionImpl();
181 
182             model.setNew(isNew());
183             model.setEscapedModel(true);
184 
185             model.setDiscussionId(getDiscussionId());
186             model.setClassNameId(getClassNameId());
187             model.setClassPK(getClassPK());
188             model.setThreadId(getThreadId());
189 
190             model = (MBDiscussion)Proxy.newProxyInstance(MBDiscussion.class.getClassLoader(),
191                     new Class[] { MBDiscussion.class },
192                     new ReadOnlyBeanHandler(model));
193 
194             return model;
195         }
196     }
197 
198     public ExpandoBridge getExpandoBridge() {
199         if (_expandoBridge == null) {
200             _expandoBridge = new ExpandoBridgeImpl(MBDiscussion.class.getName(),
201                     getPrimaryKey());
202         }
203 
204         return _expandoBridge;
205     }
206 
207     public Object clone() {
208         MBDiscussionImpl clone = new MBDiscussionImpl();
209 
210         clone.setDiscussionId(getDiscussionId());
211         clone.setClassNameId(getClassNameId());
212         clone.setClassPK(getClassPK());
213         clone.setThreadId(getThreadId());
214 
215         return clone;
216     }
217 
218     public int compareTo(Object obj) {
219         if (obj == null) {
220             return -1;
221         }
222 
223         MBDiscussionImpl mbDiscussion = (MBDiscussionImpl)obj;
224 
225         long pk = mbDiscussion.getPrimaryKey();
226 
227         if (getPrimaryKey() < pk) {
228             return -1;
229         }
230         else if (getPrimaryKey() > pk) {
231             return 1;
232         }
233         else {
234             return 0;
235         }
236     }
237 
238     public boolean equals(Object obj) {
239         if (obj == null) {
240             return false;
241         }
242 
243         MBDiscussionImpl mbDiscussion = null;
244 
245         try {
246             mbDiscussion = (MBDiscussionImpl)obj;
247         }
248         catch (ClassCastException cce) {
249             return false;
250         }
251 
252         long pk = mbDiscussion.getPrimaryKey();
253 
254         if (getPrimaryKey() == pk) {
255             return true;
256         }
257         else {
258             return false;
259         }
260     }
261 
262     public int hashCode() {
263         return (int)getPrimaryKey();
264     }
265 
266     private long _discussionId;
267     private long _classNameId;
268     private long _classPK;
269     private long _threadId;
270     private transient ExpandoBridge _expandoBridge;
271 }