1
14
15 package com.liferay.portlet.polls.model.impl;
16
17 import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
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.LocalizationUtil;
23 import com.liferay.portal.kernel.util.StringBundler;
24 import com.liferay.portal.kernel.util.StringPool;
25 import com.liferay.portal.kernel.util.Validator;
26 import com.liferay.portal.model.impl.BaseModelImpl;
27 import com.liferay.portal.service.ServiceContext;
28
29 import com.liferay.portlet.expando.model.ExpandoBridge;
30 import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
31 import com.liferay.portlet.polls.model.PollsChoice;
32 import com.liferay.portlet.polls.model.PollsChoiceSoap;
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
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 if (_uuid == null) {
129 return StringPool.BLANK;
130 }
131 else {
132 return _uuid;
133 }
134 }
135
136 public void setUuid(String uuid) {
137 _uuid = uuid;
138 }
139
140 public long getChoiceId() {
141 return _choiceId;
142 }
143
144 public void setChoiceId(long choiceId) {
145 _choiceId = choiceId;
146 }
147
148 public long getQuestionId() {
149 return _questionId;
150 }
151
152 public void setQuestionId(long questionId) {
153 _questionId = questionId;
154
155 if (!_setOriginalQuestionId) {
156 _setOriginalQuestionId = true;
157
158 _originalQuestionId = questionId;
159 }
160 }
161
162 public long getOriginalQuestionId() {
163 return _originalQuestionId;
164 }
165
166 public String getName() {
167 if (_name == null) {
168 return StringPool.BLANK;
169 }
170 else {
171 return _name;
172 }
173 }
174
175 public void setName(String name) {
176 _name = name;
177
178 if (_originalName == null) {
179 _originalName = name;
180 }
181 }
182
183 public String getOriginalName() {
184 return GetterUtil.getString(_originalName);
185 }
186
187 public String getDescription() {
188 if (_description == null) {
189 return StringPool.BLANK;
190 }
191 else {
192 return _description;
193 }
194 }
195
196 public String getDescription(Locale locale) {
197 String languageId = LocaleUtil.toLanguageId(locale);
198
199 return getDescription(languageId);
200 }
201
202 public String getDescription(Locale locale, boolean useDefault) {
203 String languageId = LocaleUtil.toLanguageId(locale);
204
205 return getDescription(languageId, useDefault);
206 }
207
208 public String getDescription(String languageId) {
209 String value = LocalizationUtil.getLocalization(getDescription(),
210 languageId);
211
212 if (isEscapedModel()) {
213 return HtmlUtil.escape(value);
214 }
215 else {
216 return value;
217 }
218 }
219
220 public String getDescription(String languageId, boolean useDefault) {
221 String value = LocalizationUtil.getLocalization(getDescription(),
222 languageId, useDefault);
223
224 if (isEscapedModel()) {
225 return HtmlUtil.escape(value);
226 }
227 else {
228 return value;
229 }
230 }
231
232 public Map<Locale, String> getDescriptionMap() {
233 return LocalizationUtil.getLocalizationMap(getDescription());
234 }
235
236 public void setDescription(String description) {
237 _description = description;
238 }
239
240 public void setDescription(Locale locale, String description) {
241 String languageId = LocaleUtil.toLanguageId(locale);
242
243 if (Validator.isNotNull(description)) {
244 setDescription(LocalizationUtil.updateLocalization(
245 getDescription(), "Description", description, languageId));
246 }
247 else {
248 setDescription(LocalizationUtil.removeLocalization(
249 getDescription(), "Description", languageId));
250 }
251 }
252
253 public void setDescriptionMap(Map<Locale, String> descriptionMap) {
254 if (descriptionMap == null) {
255 return;
256 }
257
258 Locale[] locales = LanguageUtil.getAvailableLocales();
259
260 for (Locale locale : locales) {
261 String description = descriptionMap.get(locale);
262
263 setDescription(locale, description);
264 }
265 }
266
267 public PollsChoice toEscapedModel() {
268 if (isEscapedModel()) {
269 return (PollsChoice)this;
270 }
271 else {
272 return (PollsChoice)Proxy.newProxyInstance(PollsChoice.class.getClassLoader(),
273 new Class[] { PollsChoice.class },
274 new AutoEscapeBeanHandler(this));
275 }
276 }
277
278 public ExpandoBridge getExpandoBridge() {
279 if (_expandoBridge == null) {
280 _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
281 PollsChoice.class.getName(), getPrimaryKey());
282 }
283
284 return _expandoBridge;
285 }
286
287 public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
288 getExpandoBridge().setAttributes(serviceContext);
289 }
290
291 public Object clone() {
292 PollsChoiceImpl clone = new PollsChoiceImpl();
293
294 clone.setUuid(getUuid());
295 clone.setChoiceId(getChoiceId());
296 clone.setQuestionId(getQuestionId());
297 clone.setName(getName());
298 clone.setDescription(getDescription());
299
300 return clone;
301 }
302
303 public int compareTo(PollsChoice pollsChoice) {
304 int value = 0;
305
306 if (getQuestionId() < pollsChoice.getQuestionId()) {
307 value = -1;
308 }
309 else if (getQuestionId() > pollsChoice.getQuestionId()) {
310 value = 1;
311 }
312 else {
313 value = 0;
314 }
315
316 if (value != 0) {
317 return value;
318 }
319
320 value = getName().compareTo(pollsChoice.getName());
321
322 if (value != 0) {
323 return value;
324 }
325
326 return 0;
327 }
328
329 public boolean equals(Object obj) {
330 if (obj == null) {
331 return false;
332 }
333
334 PollsChoice pollsChoice = null;
335
336 try {
337 pollsChoice = (PollsChoice)obj;
338 }
339 catch (ClassCastException cce) {
340 return false;
341 }
342
343 long pk = pollsChoice.getPrimaryKey();
344
345 if (getPrimaryKey() == pk) {
346 return true;
347 }
348 else {
349 return false;
350 }
351 }
352
353 public int hashCode() {
354 return (int)getPrimaryKey();
355 }
356
357 public String toString() {
358 StringBundler sb = new StringBundler(11);
359
360 sb.append("{uuid=");
361 sb.append(getUuid());
362 sb.append(", choiceId=");
363 sb.append(getChoiceId());
364 sb.append(", questionId=");
365 sb.append(getQuestionId());
366 sb.append(", name=");
367 sb.append(getName());
368 sb.append(", description=");
369 sb.append(getDescription());
370 sb.append("}");
371
372 return sb.toString();
373 }
374
375 public String toXmlString() {
376 StringBundler sb = new StringBundler(19);
377
378 sb.append("<model><model-name>");
379 sb.append("com.liferay.portlet.polls.model.PollsChoice");
380 sb.append("</model-name>");
381
382 sb.append(
383 "<column><column-name>uuid</column-name><column-value><![CDATA[");
384 sb.append(getUuid());
385 sb.append("]]></column-value></column>");
386 sb.append(
387 "<column><column-name>choiceId</column-name><column-value><![CDATA[");
388 sb.append(getChoiceId());
389 sb.append("]]></column-value></column>");
390 sb.append(
391 "<column><column-name>questionId</column-name><column-value><![CDATA[");
392 sb.append(getQuestionId());
393 sb.append("]]></column-value></column>");
394 sb.append(
395 "<column><column-name>name</column-name><column-value><![CDATA[");
396 sb.append(getName());
397 sb.append("]]></column-value></column>");
398 sb.append(
399 "<column><column-name>description</column-name><column-value><![CDATA[");
400 sb.append(getDescription());
401 sb.append("]]></column-value></column>");
402
403 sb.append("</model>");
404
405 return sb.toString();
406 }
407
408 private String _uuid;
409 private long _choiceId;
410 private long _questionId;
411 private long _originalQuestionId;
412 private boolean _setOriginalQuestionId;
413 private String _name;
414 private String _originalName;
415 private String _description;
416 private transient ExpandoBridge _expandoBridge;
417 }