001
014
015 package com.liferay.portlet.polls.model.impl;
016
017 import com.liferay.portal.LocaleException;
018 import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
019 import com.liferay.portal.kernel.json.JSON;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.LocaleUtil;
022 import com.liferay.portal.kernel.util.LocalizationUtil;
023 import com.liferay.portal.kernel.util.ProxyUtil;
024 import com.liferay.portal.kernel.util.StringBundler;
025 import com.liferay.portal.kernel.util.StringPool;
026 import com.liferay.portal.kernel.util.Validator;
027 import com.liferay.portal.model.CacheModel;
028 import com.liferay.portal.model.impl.BaseModelImpl;
029 import com.liferay.portal.service.ServiceContext;
030
031 import com.liferay.portlet.expando.model.ExpandoBridge;
032 import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
033 import com.liferay.portlet.polls.model.PollsChoice;
034 import com.liferay.portlet.polls.model.PollsChoiceModel;
035 import com.liferay.portlet.polls.model.PollsChoiceSoap;
036
037 import java.io.Serializable;
038
039 import java.sql.Types;
040
041 import java.util.ArrayList;
042 import java.util.HashMap;
043 import java.util.List;
044 import java.util.Locale;
045 import java.util.Map;
046
047
060 @JSON(strict = true)
061 public class PollsChoiceModelImpl extends BaseModelImpl<PollsChoice>
062 implements PollsChoiceModel {
063
068 public static final String TABLE_NAME = "PollsChoice";
069 public static final Object[][] TABLE_COLUMNS = {
070 { "uuid_", Types.VARCHAR },
071 { "choiceId", Types.BIGINT },
072 { "questionId", Types.BIGINT },
073 { "name", Types.VARCHAR },
074 { "description", Types.VARCHAR }
075 };
076 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)";
077 public static final String TABLE_SQL_DROP = "drop table PollsChoice";
078 public static final String ORDER_BY_JPQL = " ORDER BY pollsChoice.questionId ASC, pollsChoice.name ASC";
079 public static final String ORDER_BY_SQL = " ORDER BY PollsChoice.questionId ASC, PollsChoice.name ASC";
080 public static final String DATA_SOURCE = "liferayDataSource";
081 public static final String SESSION_FACTORY = "liferaySessionFactory";
082 public static final String TX_MANAGER = "liferayTransactionManager";
083 public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
084 "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
085 true);
086 public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
087 "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
088 true);
089 public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
090 "value.object.column.bitmask.enabled.com.liferay.portlet.polls.model.PollsChoice"),
091 true);
092 public static long NAME_COLUMN_BITMASK = 1L;
093 public static long QUESTIONID_COLUMN_BITMASK = 2L;
094 public static long UUID_COLUMN_BITMASK = 4L;
095
096
102 public static PollsChoice toModel(PollsChoiceSoap soapModel) {
103 if (soapModel == null) {
104 return null;
105 }
106
107 PollsChoice model = new PollsChoiceImpl();
108
109 model.setUuid(soapModel.getUuid());
110 model.setChoiceId(soapModel.getChoiceId());
111 model.setQuestionId(soapModel.getQuestionId());
112 model.setName(soapModel.getName());
113 model.setDescription(soapModel.getDescription());
114
115 return model;
116 }
117
118
124 public static List<PollsChoice> toModels(PollsChoiceSoap[] soapModels) {
125 if (soapModels == null) {
126 return null;
127 }
128
129 List<PollsChoice> models = new ArrayList<PollsChoice>(soapModels.length);
130
131 for (PollsChoiceSoap soapModel : soapModels) {
132 models.add(toModel(soapModel));
133 }
134
135 return models;
136 }
137
138 public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
139 "lock.expiration.time.com.liferay.portlet.polls.model.PollsChoice"));
140
141 public PollsChoiceModelImpl() {
142 }
143
144 public long getPrimaryKey() {
145 return _choiceId;
146 }
147
148 public void setPrimaryKey(long primaryKey) {
149 setChoiceId(primaryKey);
150 }
151
152 public Serializable getPrimaryKeyObj() {
153 return new Long(_choiceId);
154 }
155
156 public void setPrimaryKeyObj(Serializable primaryKeyObj) {
157 setPrimaryKey(((Long)primaryKeyObj).longValue());
158 }
159
160 public Class<?> getModelClass() {
161 return PollsChoice.class;
162 }
163
164 public String getModelClassName() {
165 return PollsChoice.class.getName();
166 }
167
168 @Override
169 public Map<String, Object> getModelAttributes() {
170 Map<String, Object> attributes = new HashMap<String, Object>();
171
172 attributes.put("uuid", getUuid());
173 attributes.put("choiceId", getChoiceId());
174 attributes.put("questionId", getQuestionId());
175 attributes.put("name", getName());
176 attributes.put("description", getDescription());
177
178 return attributes;
179 }
180
181 @Override
182 public void setModelAttributes(Map<String, Object> attributes) {
183 String uuid = (String)attributes.get("uuid");
184
185 if (uuid != null) {
186 setUuid(uuid);
187 }
188
189 Long choiceId = (Long)attributes.get("choiceId");
190
191 if (choiceId != null) {
192 setChoiceId(choiceId);
193 }
194
195 Long questionId = (Long)attributes.get("questionId");
196
197 if (questionId != null) {
198 setQuestionId(questionId);
199 }
200
201 String name = (String)attributes.get("name");
202
203 if (name != null) {
204 setName(name);
205 }
206
207 String description = (String)attributes.get("description");
208
209 if (description != null) {
210 setDescription(description);
211 }
212 }
213
214 @JSON
215 public String getUuid() {
216 if (_uuid == null) {
217 return StringPool.BLANK;
218 }
219 else {
220 return _uuid;
221 }
222 }
223
224 public void setUuid(String uuid) {
225 if (_originalUuid == null) {
226 _originalUuid = _uuid;
227 }
228
229 _uuid = uuid;
230 }
231
232 public String getOriginalUuid() {
233 return GetterUtil.getString(_originalUuid);
234 }
235
236 @JSON
237 public long getChoiceId() {
238 return _choiceId;
239 }
240
241 public void setChoiceId(long choiceId) {
242 _choiceId = choiceId;
243 }
244
245 @JSON
246 public long getQuestionId() {
247 return _questionId;
248 }
249
250 public void setQuestionId(long questionId) {
251 _columnBitmask = -1L;
252
253 if (!_setOriginalQuestionId) {
254 _setOriginalQuestionId = true;
255
256 _originalQuestionId = _questionId;
257 }
258
259 _questionId = questionId;
260 }
261
262 public long getOriginalQuestionId() {
263 return _originalQuestionId;
264 }
265
266 @JSON
267 public String getName() {
268 if (_name == null) {
269 return StringPool.BLANK;
270 }
271 else {
272 return _name;
273 }
274 }
275
276 public void setName(String name) {
277 _columnBitmask = -1L;
278
279 if (_originalName == null) {
280 _originalName = _name;
281 }
282
283 _name = name;
284 }
285
286 public String getOriginalName() {
287 return GetterUtil.getString(_originalName);
288 }
289
290 @JSON
291 public String getDescription() {
292 if (_description == null) {
293 return StringPool.BLANK;
294 }
295 else {
296 return _description;
297 }
298 }
299
300 public String getDescription(Locale locale) {
301 String languageId = LocaleUtil.toLanguageId(locale);
302
303 return getDescription(languageId);
304 }
305
306 public String getDescription(Locale locale, boolean useDefault) {
307 String languageId = LocaleUtil.toLanguageId(locale);
308
309 return getDescription(languageId, useDefault);
310 }
311
312 public String getDescription(String languageId) {
313 return LocalizationUtil.getLocalization(getDescription(), languageId);
314 }
315
316 public String getDescription(String languageId, boolean useDefault) {
317 return LocalizationUtil.getLocalization(getDescription(), languageId,
318 useDefault);
319 }
320
321 public String getDescriptionCurrentLanguageId() {
322 return _descriptionCurrentLanguageId;
323 }
324
325 @JSON
326 public String getDescriptionCurrentValue() {
327 Locale locale = getLocale(_descriptionCurrentLanguageId);
328
329 return getDescription(locale);
330 }
331
332 public Map<Locale, String> getDescriptionMap() {
333 return LocalizationUtil.getLocalizationMap(getDescription());
334 }
335
336 public void setDescription(String description) {
337 _description = description;
338 }
339
340 public void setDescription(String description, Locale locale) {
341 setDescription(description, locale, LocaleUtil.getDefault());
342 }
343
344 public void setDescription(String description, Locale locale,
345 Locale defaultLocale) {
346 String languageId = LocaleUtil.toLanguageId(locale);
347 String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);
348
349 if (Validator.isNotNull(description)) {
350 setDescription(LocalizationUtil.updateLocalization(
351 getDescription(), "Description", description, languageId,
352 defaultLanguageId));
353 }
354 else {
355 setDescription(LocalizationUtil.removeLocalization(
356 getDescription(), "Description", languageId));
357 }
358 }
359
360 public void setDescriptionCurrentLanguageId(String languageId) {
361 _descriptionCurrentLanguageId = languageId;
362 }
363
364 public void setDescriptionMap(Map<Locale, String> descriptionMap) {
365 setDescriptionMap(descriptionMap, LocaleUtil.getDefault());
366 }
367
368 public void setDescriptionMap(Map<Locale, String> descriptionMap,
369 Locale defaultLocale) {
370 if (descriptionMap == null) {
371 return;
372 }
373
374 setDescription(LocalizationUtil.updateLocalization(descriptionMap,
375 getDescription(), "Description",
376 LocaleUtil.toLanguageId(defaultLocale)));
377 }
378
379 public long getColumnBitmask() {
380 return _columnBitmask;
381 }
382
383 @Override
384 public ExpandoBridge getExpandoBridge() {
385 return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
386 PollsChoice.class.getName(), getPrimaryKey());
387 }
388
389 @Override
390 public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
391 ExpandoBridge expandoBridge = getExpandoBridge();
392
393 expandoBridge.setAttributes(serviceContext);
394 }
395
396 @SuppressWarnings("unused")
397 public void prepareLocalizedFieldsForImport(Locale defaultImportLocale)
398 throws LocaleException {
399 setDescription(getDescription(defaultImportLocale),
400 defaultImportLocale, defaultImportLocale);
401 }
402
403 @Override
404 public PollsChoice toEscapedModel() {
405 if (_escapedModel == null) {
406 _escapedModel = (PollsChoice)ProxyUtil.newProxyInstance(_classLoader,
407 _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
408 }
409
410 return _escapedModel;
411 }
412
413 @Override
414 public Object clone() {
415 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
416
417 pollsChoiceImpl.setUuid(getUuid());
418 pollsChoiceImpl.setChoiceId(getChoiceId());
419 pollsChoiceImpl.setQuestionId(getQuestionId());
420 pollsChoiceImpl.setName(getName());
421 pollsChoiceImpl.setDescription(getDescription());
422
423 pollsChoiceImpl.resetOriginalValues();
424
425 return pollsChoiceImpl;
426 }
427
428 public int compareTo(PollsChoice pollsChoice) {
429 int value = 0;
430
431 if (getQuestionId() < pollsChoice.getQuestionId()) {
432 value = -1;
433 }
434 else if (getQuestionId() > pollsChoice.getQuestionId()) {
435 value = 1;
436 }
437 else {
438 value = 0;
439 }
440
441 if (value != 0) {
442 return value;
443 }
444
445 value = getName().compareTo(pollsChoice.getName());
446
447 if (value != 0) {
448 return value;
449 }
450
451 return 0;
452 }
453
454 @Override
455 public boolean equals(Object obj) {
456 if (obj == null) {
457 return false;
458 }
459
460 PollsChoice pollsChoice = null;
461
462 try {
463 pollsChoice = (PollsChoice)obj;
464 }
465 catch (ClassCastException cce) {
466 return false;
467 }
468
469 long primaryKey = pollsChoice.getPrimaryKey();
470
471 if (getPrimaryKey() == primaryKey) {
472 return true;
473 }
474 else {
475 return false;
476 }
477 }
478
479 @Override
480 public int hashCode() {
481 return (int)getPrimaryKey();
482 }
483
484 @Override
485 public void resetOriginalValues() {
486 PollsChoiceModelImpl pollsChoiceModelImpl = this;
487
488 pollsChoiceModelImpl._originalUuid = pollsChoiceModelImpl._uuid;
489
490 pollsChoiceModelImpl._originalQuestionId = pollsChoiceModelImpl._questionId;
491
492 pollsChoiceModelImpl._setOriginalQuestionId = false;
493
494 pollsChoiceModelImpl._originalName = pollsChoiceModelImpl._name;
495
496 pollsChoiceModelImpl._columnBitmask = 0;
497 }
498
499 @Override
500 public CacheModel<PollsChoice> toCacheModel() {
501 PollsChoiceCacheModel pollsChoiceCacheModel = new PollsChoiceCacheModel();
502
503 pollsChoiceCacheModel.uuid = getUuid();
504
505 String uuid = pollsChoiceCacheModel.uuid;
506
507 if ((uuid != null) && (uuid.length() == 0)) {
508 pollsChoiceCacheModel.uuid = null;
509 }
510
511 pollsChoiceCacheModel.choiceId = getChoiceId();
512
513 pollsChoiceCacheModel.questionId = getQuestionId();
514
515 pollsChoiceCacheModel.name = getName();
516
517 String name = pollsChoiceCacheModel.name;
518
519 if ((name != null) && (name.length() == 0)) {
520 pollsChoiceCacheModel.name = null;
521 }
522
523 pollsChoiceCacheModel.description = getDescription();
524
525 String description = pollsChoiceCacheModel.description;
526
527 if ((description != null) && (description.length() == 0)) {
528 pollsChoiceCacheModel.description = null;
529 }
530
531 return pollsChoiceCacheModel;
532 }
533
534 @Override
535 public String toString() {
536 StringBundler sb = new StringBundler(11);
537
538 sb.append("{uuid=");
539 sb.append(getUuid());
540 sb.append(", choiceId=");
541 sb.append(getChoiceId());
542 sb.append(", questionId=");
543 sb.append(getQuestionId());
544 sb.append(", name=");
545 sb.append(getName());
546 sb.append(", description=");
547 sb.append(getDescription());
548 sb.append("}");
549
550 return sb.toString();
551 }
552
553 public String toXmlString() {
554 StringBundler sb = new StringBundler(19);
555
556 sb.append("<model><model-name>");
557 sb.append("com.liferay.portlet.polls.model.PollsChoice");
558 sb.append("</model-name>");
559
560 sb.append(
561 "<column><column-name>uuid</column-name><column-value><![CDATA[");
562 sb.append(getUuid());
563 sb.append("]]></column-value></column>");
564 sb.append(
565 "<column><column-name>choiceId</column-name><column-value><![CDATA[");
566 sb.append(getChoiceId());
567 sb.append("]]></column-value></column>");
568 sb.append(
569 "<column><column-name>questionId</column-name><column-value><![CDATA[");
570 sb.append(getQuestionId());
571 sb.append("]]></column-value></column>");
572 sb.append(
573 "<column><column-name>name</column-name><column-value><![CDATA[");
574 sb.append(getName());
575 sb.append("]]></column-value></column>");
576 sb.append(
577 "<column><column-name>description</column-name><column-value><![CDATA[");
578 sb.append(getDescription());
579 sb.append("]]></column-value></column>");
580
581 sb.append("</model>");
582
583 return sb.toString();
584 }
585
586 private static ClassLoader _classLoader = PollsChoice.class.getClassLoader();
587 private static Class<?>[] _escapedModelInterfaces = new Class[] {
588 PollsChoice.class
589 };
590 private String _uuid;
591 private String _originalUuid;
592 private long _choiceId;
593 private long _questionId;
594 private long _originalQuestionId;
595 private boolean _setOriginalQuestionId;
596 private String _name;
597 private String _originalName;
598 private String _description;
599 private String _descriptionCurrentLanguageId;
600 private long _columnBitmask;
601 private PollsChoice _escapedModel;
602 }