1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.polls.model.impl;
16  
17  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
18  import com.liferay.portal.kernel.language.LanguageUtil;
19  import com.liferay.portal.kernel.util.GetterUtil;
20  import com.liferay.portal.kernel.util.HtmlUtil;
21  import com.liferay.portal.kernel.util.LocaleUtil;
22  import com.liferay.portal.kernel.util.StringBundler;
23  import com.liferay.portal.kernel.util.Validator;
24  import com.liferay.portal.model.impl.BaseModelImpl;
25  import com.liferay.portal.service.ServiceContext;
26  
27  import com.liferay.portlet.expando.model.ExpandoBridge;
28  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
29  import com.liferay.portlet.polls.model.PollsChoice;
30  import com.liferay.portlet.polls.model.PollsChoiceSoap;
31  
32  import com.liferay.util.LocalizationUtil;
33  
34  import java.io.Serializable;
35  
36  import java.lang.reflect.Proxy;
37  
38  import java.sql.Types;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  import java.util.Locale;
43  import java.util.Map;
44  
45  /**
46   * <a href="PollsChoiceModelImpl.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 interface is a model that represents the PollsChoice table in the
55   * database.
56   * </p>
57   *
58   * @author    Brian Wing Shun Chan
59   * @see       PollsChoiceImpl
60   * @see       com.liferay.portlet.polls.model.PollsChoice
61   * @see       com.liferay.portlet.polls.model.PollsChoiceModel
62   * @generated
63   */
64  public class PollsChoiceModelImpl extends BaseModelImpl<PollsChoice> {
65      public static final String TABLE_NAME = "PollsChoice";
66      public static final Object[][] TABLE_COLUMNS = {
67              { "uuid_", new Integer(Types.VARCHAR) },
68              { "choiceId", new Integer(Types.BIGINT) },
69              { "questionId", new Integer(Types.BIGINT) },
70              { "name", new Integer(Types.VARCHAR) },
71              { "description", new Integer(Types.VARCHAR) }
72          };
73      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 STRING null)";
74      public static final String TABLE_SQL_DROP = "drop table PollsChoice";
75      public static final String ORDER_BY_JPQL = " ORDER BY pollsChoice.questionId ASC, pollsChoice.name ASC";
76      public static final String ORDER_BY_SQL = " ORDER BY PollsChoice.questionId ASC, PollsChoice.name ASC";
77      public static final String DATA_SOURCE = "liferayDataSource";
78      public static final String SESSION_FACTORY = "liferaySessionFactory";
79      public static final String TX_MANAGER = "liferayTransactionManager";
80      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
81                  "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
82              true);
83      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
84                  "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
85              true);
86  
87      public static PollsChoice toModel(PollsChoiceSoap soapModel) {
88          PollsChoice model = new PollsChoiceImpl();
89  
90          model.setUuid(soapModel.getUuid());
91          model.setChoiceId(soapModel.getChoiceId());
92          model.setQuestionId(soapModel.getQuestionId());
93          model.setName(soapModel.getName());
94          model.setDescription(soapModel.getDescription());
95  
96          return model;
97      }
98  
99      public static List<PollsChoice> toModels(PollsChoiceSoap[] soapModels) {
100         List<PollsChoice> models = new ArrayList<PollsChoice>(soapModels.length);
101 
102         for (PollsChoiceSoap 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.polls.model.PollsChoice"));
111 
112     public PollsChoiceModelImpl() {
113     }
114 
115     public long getPrimaryKey() {
116         return _choiceId;
117     }
118 
119     public void setPrimaryKey(long pk) {
120         setChoiceId(pk);
121     }
122 
123     public Serializable getPrimaryKeyObj() {
124         return new Long(_choiceId);
125     }
126 
127     public String getUuid() {
128         return GetterUtil.getString(_uuid);
129     }
130 
131     public void setUuid(String uuid) {
132         _uuid = uuid;
133     }
134 
135     public long getChoiceId() {
136         return _choiceId;
137     }
138 
139     public void setChoiceId(long choiceId) {
140         _choiceId = choiceId;
141     }
142 
143     public long getQuestionId() {
144         return _questionId;
145     }
146 
147     public void setQuestionId(long questionId) {
148         _questionId = questionId;
149 
150         if (!_setOriginalQuestionId) {
151             _setOriginalQuestionId = true;
152 
153             _originalQuestionId = questionId;
154         }
155     }
156 
157     public long getOriginalQuestionId() {
158         return _originalQuestionId;
159     }
160 
161     public String getName() {
162         return GetterUtil.getString(_name);
163     }
164 
165     public void setName(String name) {
166         _name = name;
167 
168         if (_originalName == null) {
169             _originalName = name;
170         }
171     }
172 
173     public String getOriginalName() {
174         return GetterUtil.getString(_originalName);
175     }
176 
177     public String getDescription() {
178         return GetterUtil.getString(_description);
179     }
180 
181     public String getDescription(Locale locale) {
182         String languageId = LocaleUtil.toLanguageId(locale);
183 
184         return getDescription(languageId);
185     }
186 
187     public String getDescription(Locale locale, boolean useDefault) {
188         String languageId = LocaleUtil.toLanguageId(locale);
189 
190         return getDescription(languageId, useDefault);
191     }
192 
193     public String getDescription(String languageId) {
194         String value = LocalizationUtil.getLocalization(getDescription(),
195                 languageId);
196 
197         if (isEscapedModel()) {
198             return HtmlUtil.escape(value);
199         }
200         else {
201             return value;
202         }
203     }
204 
205     public String getDescription(String languageId, boolean useDefault) {
206         String value = LocalizationUtil.getLocalization(getDescription(),
207                 languageId, useDefault);
208 
209         if (isEscapedModel()) {
210             return HtmlUtil.escape(value);
211         }
212         else {
213             return value;
214         }
215     }
216 
217     public Map<Locale, String> getDescriptionMap() {
218         return LocalizationUtil.getLocalizationMap(getDescription());
219     }
220 
221     public void setDescription(String description) {
222         _description = description;
223     }
224 
225     public void setDescription(Locale locale, String description) {
226         String languageId = LocaleUtil.toLanguageId(locale);
227 
228         if (Validator.isNotNull(description)) {
229             setDescription(LocalizationUtil.updateLocalization(
230                     getDescription(), "Description", description, languageId));
231         }
232         else {
233             setDescription(LocalizationUtil.removeLocalization(
234                     getDescription(), "Description", languageId));
235         }
236     }
237 
238     public void setDescriptionMap(Map<Locale, String> descriptionMap) {
239         if (descriptionMap == null) {
240             return;
241         }
242 
243         Locale[] locales = LanguageUtil.getAvailableLocales();
244 
245         for (Locale locale : locales) {
246             String description = descriptionMap.get(locale);
247 
248             setDescription(locale, description);
249         }
250     }
251 
252     public PollsChoice toEscapedModel() {
253         if (isEscapedModel()) {
254             return (PollsChoice)this;
255         }
256         else {
257             PollsChoice model = new PollsChoiceImpl();
258 
259             model.setNew(isNew());
260             model.setEscapedModel(true);
261 
262             model.setUuid(HtmlUtil.escape(getUuid()));
263             model.setChoiceId(getChoiceId());
264             model.setQuestionId(getQuestionId());
265             model.setName(HtmlUtil.escape(getName()));
266             model.setDescription(getDescription());
267 
268             model = (PollsChoice)Proxy.newProxyInstance(PollsChoice.class.getClassLoader(),
269                     new Class[] { PollsChoice.class },
270                     new ReadOnlyBeanHandler(model));
271 
272             return model;
273         }
274     }
275 
276     public ExpandoBridge getExpandoBridge() {
277         if (_expandoBridge == null) {
278             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
279                     PollsChoice.class.getName(), getPrimaryKey());
280         }
281 
282         return _expandoBridge;
283     }
284 
285     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
286         getExpandoBridge().setAttributes(serviceContext);
287     }
288 
289     public Object clone() {
290         PollsChoiceImpl clone = new PollsChoiceImpl();
291 
292         clone.setUuid(getUuid());
293         clone.setChoiceId(getChoiceId());
294         clone.setQuestionId(getQuestionId());
295         clone.setName(getName());
296         clone.setDescription(getDescription());
297 
298         return clone;
299     }
300 
301     public int compareTo(PollsChoice pollsChoice) {
302         int value = 0;
303 
304         if (getQuestionId() < pollsChoice.getQuestionId()) {
305             value = -1;
306         }
307         else if (getQuestionId() > pollsChoice.getQuestionId()) {
308             value = 1;
309         }
310         else {
311             value = 0;
312         }
313 
314         if (value != 0) {
315             return value;
316         }
317 
318         value = getName().compareTo(pollsChoice.getName());
319 
320         if (value != 0) {
321             return value;
322         }
323 
324         return 0;
325     }
326 
327     public boolean equals(Object obj) {
328         if (obj == null) {
329             return false;
330         }
331 
332         PollsChoice pollsChoice = null;
333 
334         try {
335             pollsChoice = (PollsChoice)obj;
336         }
337         catch (ClassCastException cce) {
338             return false;
339         }
340 
341         long pk = pollsChoice.getPrimaryKey();
342 
343         if (getPrimaryKey() == pk) {
344             return true;
345         }
346         else {
347             return false;
348         }
349     }
350 
351     public int hashCode() {
352         return (int)getPrimaryKey();
353     }
354 
355     public String toString() {
356         StringBundler sb = new StringBundler(11);
357 
358         sb.append("{uuid=");
359         sb.append(getUuid());
360         sb.append(", choiceId=");
361         sb.append(getChoiceId());
362         sb.append(", questionId=");
363         sb.append(getQuestionId());
364         sb.append(", name=");
365         sb.append(getName());
366         sb.append(", description=");
367         sb.append(getDescription());
368         sb.append("}");
369 
370         return sb.toString();
371     }
372 
373     public String toXmlString() {
374         StringBundler sb = new StringBundler(19);
375 
376         sb.append("<model><model-name>");
377         sb.append("com.liferay.portlet.polls.model.PollsChoice");
378         sb.append("</model-name>");
379 
380         sb.append(
381             "<column><column-name>uuid</column-name><column-value><![CDATA[");
382         sb.append(getUuid());
383         sb.append("]]></column-value></column>");
384         sb.append(
385             "<column><column-name>choiceId</column-name><column-value><![CDATA[");
386         sb.append(getChoiceId());
387         sb.append("]]></column-value></column>");
388         sb.append(
389             "<column><column-name>questionId</column-name><column-value><![CDATA[");
390         sb.append(getQuestionId());
391         sb.append("]]></column-value></column>");
392         sb.append(
393             "<column><column-name>name</column-name><column-value><![CDATA[");
394         sb.append(getName());
395         sb.append("]]></column-value></column>");
396         sb.append(
397             "<column><column-name>description</column-name><column-value><![CDATA[");
398         sb.append(getDescription());
399         sb.append("]]></column-value></column>");
400 
401         sb.append("</model>");
402 
403         return sb.toString();
404     }
405 
406     private String _uuid;
407     private long _choiceId;
408     private long _questionId;
409     private long _originalQuestionId;
410     private boolean _setOriginalQuestionId;
411     private String _name;
412     private String _originalName;
413     private String _description;
414     private transient ExpandoBridge _expandoBridge;
415 }