001
014
015 package com.liferay.portlet.polls.model.impl;
016
017 import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
018 import com.liferay.portal.kernel.json.JSON;
019 import com.liferay.portal.kernel.language.LanguageUtil;
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
036 import java.io.Serializable;
037
038 import java.sql.Types;
039
040 import java.util.Locale;
041 import java.util.Map;
042
043
056 public class PollsChoiceModelImpl extends BaseModelImpl<PollsChoice>
057 implements PollsChoiceModel {
058
063 public static final String TABLE_NAME = "PollsChoice";
064 public static final Object[][] TABLE_COLUMNS = {
065 { "uuid_", Types.VARCHAR },
066 { "choiceId", Types.BIGINT },
067 { "questionId", Types.BIGINT },
068 { "name", Types.VARCHAR },
069 { "description", Types.VARCHAR }
070 };
071 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)";
072 public static final String TABLE_SQL_DROP = "drop table PollsChoice";
073 public static final String ORDER_BY_JPQL = " ORDER BY pollsChoice.questionId ASC, pollsChoice.name ASC";
074 public static final String ORDER_BY_SQL = " ORDER BY PollsChoice.questionId ASC, PollsChoice.name ASC";
075 public static final String DATA_SOURCE = "liferayDataSource";
076 public static final String SESSION_FACTORY = "liferaySessionFactory";
077 public static final String TX_MANAGER = "liferayTransactionManager";
078 public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079 "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
080 true);
081 public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082 "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
083 true);
084 public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
085 "value.object.column.bitmask.enabled.com.liferay.portlet.polls.model.PollsChoice"),
086 true);
087 public static long NAME_COLUMN_BITMASK = 1L;
088 public static long QUESTIONID_COLUMN_BITMASK = 2L;
089 public static long UUID_COLUMN_BITMASK = 4L;
090 public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
091 "lock.expiration.time.com.liferay.portlet.polls.model.PollsChoice"));
092
093 public PollsChoiceModelImpl() {
094 }
095
096 public long getPrimaryKey() {
097 return _choiceId;
098 }
099
100 public void setPrimaryKey(long primaryKey) {
101 setChoiceId(primaryKey);
102 }
103
104 public Serializable getPrimaryKeyObj() {
105 return new Long(_choiceId);
106 }
107
108 public void setPrimaryKeyObj(Serializable primaryKeyObj) {
109 setPrimaryKey(((Long)primaryKeyObj).longValue());
110 }
111
112 public Class<?> getModelClass() {
113 return PollsChoice.class;
114 }
115
116 public String getModelClassName() {
117 return PollsChoice.class.getName();
118 }
119
120 public String getUuid() {
121 if (_uuid == null) {
122 return StringPool.BLANK;
123 }
124 else {
125 return _uuid;
126 }
127 }
128
129 public void setUuid(String uuid) {
130 if (_originalUuid == null) {
131 _originalUuid = _uuid;
132 }
133
134 _uuid = uuid;
135 }
136
137 public String getOriginalUuid() {
138 return GetterUtil.getString(_originalUuid);
139 }
140
141 public long getChoiceId() {
142 return _choiceId;
143 }
144
145 public void setChoiceId(long choiceId) {
146 _choiceId = choiceId;
147 }
148
149 public long getQuestionId() {
150 return _questionId;
151 }
152
153 public void setQuestionId(long questionId) {
154 _columnBitmask = -1L;
155
156 if (!_setOriginalQuestionId) {
157 _setOriginalQuestionId = true;
158
159 _originalQuestionId = _questionId;
160 }
161
162 _questionId = questionId;
163 }
164
165 public long getOriginalQuestionId() {
166 return _originalQuestionId;
167 }
168
169 public String getName() {
170 if (_name == null) {
171 return StringPool.BLANK;
172 }
173 else {
174 return _name;
175 }
176 }
177
178 public void setName(String name) {
179 _columnBitmask = -1L;
180
181 if (_originalName == null) {
182 _originalName = _name;
183 }
184
185 _name = name;
186 }
187
188 public String getOriginalName() {
189 return GetterUtil.getString(_originalName);
190 }
191
192 public String getDescription() {
193 if (_description == null) {
194 return StringPool.BLANK;
195 }
196 else {
197 return _description;
198 }
199 }
200
201 public String getDescription(Locale locale) {
202 String languageId = LocaleUtil.toLanguageId(locale);
203
204 return getDescription(languageId);
205 }
206
207 public String getDescription(Locale locale, boolean useDefault) {
208 String languageId = LocaleUtil.toLanguageId(locale);
209
210 return getDescription(languageId, useDefault);
211 }
212
213 public String getDescription(String languageId) {
214 return LocalizationUtil.getLocalization(getDescription(), languageId);
215 }
216
217 public String getDescription(String languageId, boolean useDefault) {
218 return LocalizationUtil.getLocalization(getDescription(), languageId,
219 useDefault);
220 }
221
222 public String getDescriptionCurrentLanguageId() {
223 return _descriptionCurrentLanguageId;
224 }
225
226 @JSON
227 public String getDescriptionCurrentValue() {
228 Locale locale = getLocale(_descriptionCurrentLanguageId);
229
230 return getDescription(locale);
231 }
232
233 public Map<Locale, String> getDescriptionMap() {
234 return LocalizationUtil.getLocalizationMap(getDescription());
235 }
236
237 public void setDescription(String description) {
238 _description = description;
239 }
240
241 public void setDescription(String description, Locale locale) {
242 setDescription(description, locale, LocaleUtil.getDefault());
243 }
244
245 public void setDescription(String description, Locale locale,
246 Locale defaultLocale) {
247 String languageId = LocaleUtil.toLanguageId(locale);
248 String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);
249
250 if (Validator.isNotNull(description)) {
251 setDescription(LocalizationUtil.updateLocalization(
252 getDescription(), "Description", description, languageId,
253 defaultLanguageId));
254 }
255 else {
256 setDescription(LocalizationUtil.removeLocalization(
257 getDescription(), "Description", languageId));
258 }
259 }
260
261 public void setDescriptionCurrentLanguageId(String languageId) {
262 _descriptionCurrentLanguageId = languageId;
263 }
264
265 public void setDescriptionMap(Map<Locale, String> descriptionMap) {
266 setDescriptionMap(descriptionMap, LocaleUtil.getDefault());
267 }
268
269 public void setDescriptionMap(Map<Locale, String> descriptionMap,
270 Locale defaultLocale) {
271 if (descriptionMap == null) {
272 return;
273 }
274
275 Locale[] locales = LanguageUtil.getAvailableLocales();
276
277 for (Locale locale : locales) {
278 String description = descriptionMap.get(locale);
279
280 setDescription(description, locale, defaultLocale);
281 }
282 }
283
284 public long getColumnBitmask() {
285 return _columnBitmask;
286 }
287
288 @Override
289 public PollsChoice toEscapedModel() {
290 if (_escapedModelProxy == null) {
291 _escapedModelProxy = (PollsChoice)ProxyUtil.newProxyInstance(_classLoader,
292 _escapedModelProxyInterfaces,
293 new AutoEscapeBeanHandler(this));
294 }
295
296 return _escapedModelProxy;
297 }
298
299 @Override
300 public ExpandoBridge getExpandoBridge() {
301 if (_expandoBridge == null) {
302 _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
303 PollsChoice.class.getName(), getPrimaryKey());
304 }
305
306 return _expandoBridge;
307 }
308
309 @Override
310 public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
311 getExpandoBridge().setAttributes(serviceContext);
312 }
313
314 @Override
315 public Object clone() {
316 PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
317
318 pollsChoiceImpl.setUuid(getUuid());
319 pollsChoiceImpl.setChoiceId(getChoiceId());
320 pollsChoiceImpl.setQuestionId(getQuestionId());
321 pollsChoiceImpl.setName(getName());
322 pollsChoiceImpl.setDescription(getDescription());
323
324 pollsChoiceImpl.resetOriginalValues();
325
326 return pollsChoiceImpl;
327 }
328
329 public int compareTo(PollsChoice pollsChoice) {
330 int value = 0;
331
332 if (getQuestionId() < pollsChoice.getQuestionId()) {
333 value = -1;
334 }
335 else if (getQuestionId() > pollsChoice.getQuestionId()) {
336 value = 1;
337 }
338 else {
339 value = 0;
340 }
341
342 if (value != 0) {
343 return value;
344 }
345
346 value = getName().compareTo(pollsChoice.getName());
347
348 if (value != 0) {
349 return value;
350 }
351
352 return 0;
353 }
354
355 @Override
356 public boolean equals(Object obj) {
357 if (obj == null) {
358 return false;
359 }
360
361 PollsChoice pollsChoice = null;
362
363 try {
364 pollsChoice = (PollsChoice)obj;
365 }
366 catch (ClassCastException cce) {
367 return false;
368 }
369
370 long primaryKey = pollsChoice.getPrimaryKey();
371
372 if (getPrimaryKey() == primaryKey) {
373 return true;
374 }
375 else {
376 return false;
377 }
378 }
379
380 @Override
381 public int hashCode() {
382 return (int)getPrimaryKey();
383 }
384
385 @Override
386 public void resetOriginalValues() {
387 PollsChoiceModelImpl pollsChoiceModelImpl = this;
388
389 pollsChoiceModelImpl._originalUuid = pollsChoiceModelImpl._uuid;
390
391 pollsChoiceModelImpl._originalQuestionId = pollsChoiceModelImpl._questionId;
392
393 pollsChoiceModelImpl._setOriginalQuestionId = false;
394
395 pollsChoiceModelImpl._originalName = pollsChoiceModelImpl._name;
396
397 pollsChoiceModelImpl._columnBitmask = 0;
398 }
399
400 @Override
401 public CacheModel<PollsChoice> toCacheModel() {
402 PollsChoiceCacheModel pollsChoiceCacheModel = new PollsChoiceCacheModel();
403
404 pollsChoiceCacheModel.uuid = getUuid();
405
406 String uuid = pollsChoiceCacheModel.uuid;
407
408 if ((uuid != null) && (uuid.length() == 0)) {
409 pollsChoiceCacheModel.uuid = null;
410 }
411
412 pollsChoiceCacheModel.choiceId = getChoiceId();
413
414 pollsChoiceCacheModel.questionId = getQuestionId();
415
416 pollsChoiceCacheModel.name = getName();
417
418 String name = pollsChoiceCacheModel.name;
419
420 if ((name != null) && (name.length() == 0)) {
421 pollsChoiceCacheModel.name = null;
422 }
423
424 pollsChoiceCacheModel.description = getDescription();
425
426 String description = pollsChoiceCacheModel.description;
427
428 if ((description != null) && (description.length() == 0)) {
429 pollsChoiceCacheModel.description = null;
430 }
431
432 return pollsChoiceCacheModel;
433 }
434
435 @Override
436 public String toString() {
437 StringBundler sb = new StringBundler(11);
438
439 sb.append("{uuid=");
440 sb.append(getUuid());
441 sb.append(", choiceId=");
442 sb.append(getChoiceId());
443 sb.append(", questionId=");
444 sb.append(getQuestionId());
445 sb.append(", name=");
446 sb.append(getName());
447 sb.append(", description=");
448 sb.append(getDescription());
449 sb.append("}");
450
451 return sb.toString();
452 }
453
454 public String toXmlString() {
455 StringBundler sb = new StringBundler(19);
456
457 sb.append("<model><model-name>");
458 sb.append("com.liferay.portlet.polls.model.PollsChoice");
459 sb.append("</model-name>");
460
461 sb.append(
462 "<column><column-name>uuid</column-name><column-value><![CDATA[");
463 sb.append(getUuid());
464 sb.append("]]></column-value></column>");
465 sb.append(
466 "<column><column-name>choiceId</column-name><column-value><![CDATA[");
467 sb.append(getChoiceId());
468 sb.append("]]></column-value></column>");
469 sb.append(
470 "<column><column-name>questionId</column-name><column-value><![CDATA[");
471 sb.append(getQuestionId());
472 sb.append("]]></column-value></column>");
473 sb.append(
474 "<column><column-name>name</column-name><column-value><![CDATA[");
475 sb.append(getName());
476 sb.append("]]></column-value></column>");
477 sb.append(
478 "<column><column-name>description</column-name><column-value><![CDATA[");
479 sb.append(getDescription());
480 sb.append("]]></column-value></column>");
481
482 sb.append("</model>");
483
484 return sb.toString();
485 }
486
487 private static ClassLoader _classLoader = PollsChoice.class.getClassLoader();
488 private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
489 PollsChoice.class
490 };
491 private String _uuid;
492 private String _originalUuid;
493 private long _choiceId;
494 private long _questionId;
495 private long _originalQuestionId;
496 private boolean _setOriginalQuestionId;
497 private String _name;
498 private String _originalName;
499 private String _description;
500 private String _descriptionCurrentLanguageId;
501 private transient ExpandoBridge _expandoBridge;
502 private long _columnBitmask;
503 private PollsChoice _escapedModelProxy;
504 }