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.polls.model.impl;
21  
22  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
23  import com.liferay.portal.kernel.util.GetterUtil;
24  import com.liferay.portal.kernel.util.HtmlUtil;
25  import com.liferay.portal.model.impl.BaseModelImpl;
26  
27  import com.liferay.portlet.expando.model.ExpandoBridge;
28  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
29  import com.liferay.portlet.polls.model.PollsChoice;
30  import com.liferay.portlet.polls.model.PollsChoiceSoap;
31  
32  import java.io.Serializable;
33  
34  import java.lang.reflect.Proxy;
35  
36  import java.sql.Types;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  /**
42   * <a href="PollsChoiceModelImpl.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>PollsChoice</code> table
51   * in the database.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   * @see com.liferay.portlet.polls.model.PollsChoice
57   * @see com.liferay.portlet.polls.model.PollsChoiceModel
58   * @see com.liferay.portlet.polls.model.impl.PollsChoiceImpl
59   *
60   */
61  public class PollsChoiceModelImpl extends BaseModelImpl<PollsChoice> {
62      public static final String TABLE_NAME = "PollsChoice";
63      public static final Object[][] TABLE_COLUMNS = {
64              { "uuid_", new Integer(Types.VARCHAR) },
65              
66  
67              { "choiceId", new Integer(Types.BIGINT) },
68              
69  
70              { "questionId", new Integer(Types.BIGINT) },
71              
72  
73              { "name", new Integer(Types.VARCHAR) },
74              
75  
76              { "description", new Integer(Types.VARCHAR) }
77          };
78      public static final String TABLE_SQL_CREATE = "create table PollsChoice (uuid_ VARCHAR(75) null,choiceId LONG not null primary key,questionId LONG,name VARCHAR(75) null,description VARCHAR(1000) null)";
79      public static final String TABLE_SQL_DROP = "drop table PollsChoice";
80      public static final String DATA_SOURCE = "liferayDataSource";
81      public static final String SESSION_FACTORY = "liferaySessionFactory";
82      public static final String TX_MANAGER = "liferayTransactionManager";
83      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
84                  "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
85              true);
86      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
87                  "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
88              true);
89  
90      public static PollsChoice toModel(PollsChoiceSoap soapModel) {
91          PollsChoice model = new PollsChoiceImpl();
92  
93          model.setUuid(soapModel.getUuid());
94          model.setChoiceId(soapModel.getChoiceId());
95          model.setQuestionId(soapModel.getQuestionId());
96          model.setName(soapModel.getName());
97          model.setDescription(soapModel.getDescription());
98  
99          return model;
100     }
101 
102     public static List<PollsChoice> toModels(PollsChoiceSoap[] soapModels) {
103         List<PollsChoice> models = new ArrayList<PollsChoice>(soapModels.length);
104 
105         for (PollsChoiceSoap soapModel : soapModels) {
106             models.add(toModel(soapModel));
107         }
108 
109         return models;
110     }
111 
112     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
113                 "lock.expiration.time.com.liferay.portlet.polls.model.PollsChoice"));
114 
115     public PollsChoiceModelImpl() {
116     }
117 
118     public long getPrimaryKey() {
119         return _choiceId;
120     }
121 
122     public void setPrimaryKey(long pk) {
123         setChoiceId(pk);
124     }
125 
126     public Serializable getPrimaryKeyObj() {
127         return new Long(_choiceId);
128     }
129 
130     public String getUuid() {
131         return GetterUtil.getString(_uuid);
132     }
133 
134     public void setUuid(String uuid) {
135         _uuid = uuid;
136     }
137 
138     public long getChoiceId() {
139         return _choiceId;
140     }
141 
142     public void setChoiceId(long choiceId) {
143         _choiceId = choiceId;
144     }
145 
146     public long getQuestionId() {
147         return _questionId;
148     }
149 
150     public void setQuestionId(long questionId) {
151         _questionId = questionId;
152 
153         if (!_setOriginalQuestionId) {
154             _setOriginalQuestionId = true;
155 
156             _originalQuestionId = questionId;
157         }
158     }
159 
160     public long getOriginalQuestionId() {
161         return _originalQuestionId;
162     }
163 
164     public String getName() {
165         return GetterUtil.getString(_name);
166     }
167 
168     public void setName(String name) {
169         _name = name;
170 
171         if (_originalName == null) {
172             _originalName = name;
173         }
174     }
175 
176     public String getOriginalName() {
177         return GetterUtil.getString(_originalName);
178     }
179 
180     public String getDescription() {
181         return GetterUtil.getString(_description);
182     }
183 
184     public void setDescription(String description) {
185         _description = description;
186     }
187 
188     public PollsChoice toEscapedModel() {
189         if (isEscapedModel()) {
190             return (PollsChoice)this;
191         }
192         else {
193             PollsChoice model = new PollsChoiceImpl();
194 
195             model.setNew(isNew());
196             model.setEscapedModel(true);
197 
198             model.setUuid(HtmlUtil.escape(getUuid()));
199             model.setChoiceId(getChoiceId());
200             model.setQuestionId(getQuestionId());
201             model.setName(HtmlUtil.escape(getName()));
202             model.setDescription(HtmlUtil.escape(getDescription()));
203 
204             model = (PollsChoice)Proxy.newProxyInstance(PollsChoice.class.getClassLoader(),
205                     new Class[] { PollsChoice.class },
206                     new ReadOnlyBeanHandler(model));
207 
208             return model;
209         }
210     }
211 
212     public ExpandoBridge getExpandoBridge() {
213         if (_expandoBridge == null) {
214             _expandoBridge = new ExpandoBridgeImpl(PollsChoice.class.getName(),
215                     getPrimaryKey());
216         }
217 
218         return _expandoBridge;
219     }
220 
221     public Object clone() {
222         PollsChoiceImpl clone = new PollsChoiceImpl();
223 
224         clone.setUuid(getUuid());
225         clone.setChoiceId(getChoiceId());
226         clone.setQuestionId(getQuestionId());
227         clone.setName(getName());
228         clone.setDescription(getDescription());
229 
230         return clone;
231     }
232 
233     public int compareTo(PollsChoice pollsChoice) {
234         int value = 0;
235 
236         if (getQuestionId() < pollsChoice.getQuestionId()) {
237             value = -1;
238         }
239         else if (getQuestionId() > pollsChoice.getQuestionId()) {
240             value = 1;
241         }
242         else {
243             value = 0;
244         }
245 
246         if (value != 0) {
247             return value;
248         }
249 
250         value = getName().compareTo(pollsChoice.getName());
251 
252         if (value != 0) {
253             return value;
254         }
255 
256         return 0;
257     }
258 
259     public boolean equals(Object obj) {
260         if (obj == null) {
261             return false;
262         }
263 
264         PollsChoice pollsChoice = null;
265 
266         try {
267             pollsChoice = (PollsChoice)obj;
268         }
269         catch (ClassCastException cce) {
270             return false;
271         }
272 
273         long pk = pollsChoice.getPrimaryKey();
274 
275         if (getPrimaryKey() == pk) {
276             return true;
277         }
278         else {
279             return false;
280         }
281     }
282 
283     public int hashCode() {
284         return (int)getPrimaryKey();
285     }
286 
287     public String toString() {
288         StringBuilder sb = new StringBuilder();
289 
290         sb.append("{uuid=");
291         sb.append(getUuid());
292         sb.append(", choiceId=");
293         sb.append(getChoiceId());
294         sb.append(", questionId=");
295         sb.append(getQuestionId());
296         sb.append(", name=");
297         sb.append(getName());
298         sb.append(", description=");
299         sb.append(getDescription());
300         sb.append("}");
301 
302         return sb.toString();
303     }
304 
305     public String toXmlString() {
306         StringBuilder sb = new StringBuilder();
307 
308         sb.append("<model><model-name>");
309         sb.append("com.liferay.portlet.polls.model.PollsChoice");
310         sb.append("</model-name>");
311 
312         sb.append(
313             "<column><column-name>uuid</column-name><column-value><![CDATA[");
314         sb.append(getUuid());
315         sb.append("]]></column-value></column>");
316         sb.append(
317             "<column><column-name>choiceId</column-name><column-value><![CDATA[");
318         sb.append(getChoiceId());
319         sb.append("]]></column-value></column>");
320         sb.append(
321             "<column><column-name>questionId</column-name><column-value><![CDATA[");
322         sb.append(getQuestionId());
323         sb.append("]]></column-value></column>");
324         sb.append(
325             "<column><column-name>name</column-name><column-value><![CDATA[");
326         sb.append(getName());
327         sb.append("]]></column-value></column>");
328         sb.append(
329             "<column><column-name>description</column-name><column-value><![CDATA[");
330         sb.append(getDescription());
331         sb.append("]]></column-value></column>");
332 
333         sb.append("</model>");
334 
335         return sb.toString();
336     }
337 
338     private String _uuid;
339     private long _choiceId;
340     private long _questionId;
341     private long _originalQuestionId;
342     private boolean _setOriginalQuestionId;
343     private String _name;
344     private String _originalName;
345     private String _description;
346     private transient ExpandoBridge _expandoBridge;
347 }