001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
048     * The base model implementation for the PollsChoice service. Represents a row in the "PollsChoice" database table, with each column mapped to a property of this class.
049     *
050     * <p>
051     * This implementation and its corresponding interface {@link com.liferay.portlet.polls.model.PollsChoiceModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link PollsChoiceImpl}.
052     * </p>
053     *
054     * @author Brian Wing Shun Chan
055     * @see PollsChoiceImpl
056     * @see com.liferay.portlet.polls.model.PollsChoice
057     * @see com.liferay.portlet.polls.model.PollsChoiceModel
058     * @generated
059     */
060    @JSON(strict = true)
061    public class PollsChoiceModelImpl extends BaseModelImpl<PollsChoice>
062            implements PollsChoiceModel {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * Never modify or reference this class directly. All methods that expect a polls choice model instance should use the {@link com.liferay.portlet.polls.model.PollsChoice} interface instead.
067             */
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            /**
097             * Converts the soap model instance into a normal model instance.
098             *
099             * @param soapModel the soap model instance to convert
100             * @return the normal model instance
101             */
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            /**
119             * Converts the soap model instances into normal model instances.
120             *
121             * @param soapModels the soap model instances to convert
122             * @return the normal model instances
123             */
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 (_escapedModelProxy == null) {
406                            _escapedModelProxy = (PollsChoice)ProxyUtil.newProxyInstance(_classLoader,
407                                            _escapedModelProxyInterfaces,
408                                            new AutoEscapeBeanHandler(this));
409                    }
410    
411                    return _escapedModelProxy;
412            }
413    
414            @Override
415            public Object clone() {
416                    PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
417    
418                    pollsChoiceImpl.setUuid(getUuid());
419                    pollsChoiceImpl.setChoiceId(getChoiceId());
420                    pollsChoiceImpl.setQuestionId(getQuestionId());
421                    pollsChoiceImpl.setName(getName());
422                    pollsChoiceImpl.setDescription(getDescription());
423    
424                    pollsChoiceImpl.resetOriginalValues();
425    
426                    return pollsChoiceImpl;
427            }
428    
429            public int compareTo(PollsChoice pollsChoice) {
430                    int value = 0;
431    
432                    if (getQuestionId() < pollsChoice.getQuestionId()) {
433                            value = -1;
434                    }
435                    else if (getQuestionId() > pollsChoice.getQuestionId()) {
436                            value = 1;
437                    }
438                    else {
439                            value = 0;
440                    }
441    
442                    if (value != 0) {
443                            return value;
444                    }
445    
446                    value = getName().compareTo(pollsChoice.getName());
447    
448                    if (value != 0) {
449                            return value;
450                    }
451    
452                    return 0;
453            }
454    
455            @Override
456            public boolean equals(Object obj) {
457                    if (obj == null) {
458                            return false;
459                    }
460    
461                    PollsChoice pollsChoice = null;
462    
463                    try {
464                            pollsChoice = (PollsChoice)obj;
465                    }
466                    catch (ClassCastException cce) {
467                            return false;
468                    }
469    
470                    long primaryKey = pollsChoice.getPrimaryKey();
471    
472                    if (getPrimaryKey() == primaryKey) {
473                            return true;
474                    }
475                    else {
476                            return false;
477                    }
478            }
479    
480            @Override
481            public int hashCode() {
482                    return (int)getPrimaryKey();
483            }
484    
485            @Override
486            public void resetOriginalValues() {
487                    PollsChoiceModelImpl pollsChoiceModelImpl = this;
488    
489                    pollsChoiceModelImpl._originalUuid = pollsChoiceModelImpl._uuid;
490    
491                    pollsChoiceModelImpl._originalQuestionId = pollsChoiceModelImpl._questionId;
492    
493                    pollsChoiceModelImpl._setOriginalQuestionId = false;
494    
495                    pollsChoiceModelImpl._originalName = pollsChoiceModelImpl._name;
496    
497                    pollsChoiceModelImpl._columnBitmask = 0;
498            }
499    
500            @Override
501            public CacheModel<PollsChoice> toCacheModel() {
502                    PollsChoiceCacheModel pollsChoiceCacheModel = new PollsChoiceCacheModel();
503    
504                    pollsChoiceCacheModel.uuid = getUuid();
505    
506                    String uuid = pollsChoiceCacheModel.uuid;
507    
508                    if ((uuid != null) && (uuid.length() == 0)) {
509                            pollsChoiceCacheModel.uuid = null;
510                    }
511    
512                    pollsChoiceCacheModel.choiceId = getChoiceId();
513    
514                    pollsChoiceCacheModel.questionId = getQuestionId();
515    
516                    pollsChoiceCacheModel.name = getName();
517    
518                    String name = pollsChoiceCacheModel.name;
519    
520                    if ((name != null) && (name.length() == 0)) {
521                            pollsChoiceCacheModel.name = null;
522                    }
523    
524                    pollsChoiceCacheModel.description = getDescription();
525    
526                    String description = pollsChoiceCacheModel.description;
527    
528                    if ((description != null) && (description.length() == 0)) {
529                            pollsChoiceCacheModel.description = null;
530                    }
531    
532                    return pollsChoiceCacheModel;
533            }
534    
535            @Override
536            public String toString() {
537                    StringBundler sb = new StringBundler(11);
538    
539                    sb.append("{uuid=");
540                    sb.append(getUuid());
541                    sb.append(", choiceId=");
542                    sb.append(getChoiceId());
543                    sb.append(", questionId=");
544                    sb.append(getQuestionId());
545                    sb.append(", name=");
546                    sb.append(getName());
547                    sb.append(", description=");
548                    sb.append(getDescription());
549                    sb.append("}");
550    
551                    return sb.toString();
552            }
553    
554            public String toXmlString() {
555                    StringBundler sb = new StringBundler(19);
556    
557                    sb.append("<model><model-name>");
558                    sb.append("com.liferay.portlet.polls.model.PollsChoice");
559                    sb.append("</model-name>");
560    
561                    sb.append(
562                            "<column><column-name>uuid</column-name><column-value><![CDATA[");
563                    sb.append(getUuid());
564                    sb.append("]]></column-value></column>");
565                    sb.append(
566                            "<column><column-name>choiceId</column-name><column-value><![CDATA[");
567                    sb.append(getChoiceId());
568                    sb.append("]]></column-value></column>");
569                    sb.append(
570                            "<column><column-name>questionId</column-name><column-value><![CDATA[");
571                    sb.append(getQuestionId());
572                    sb.append("]]></column-value></column>");
573                    sb.append(
574                            "<column><column-name>name</column-name><column-value><![CDATA[");
575                    sb.append(getName());
576                    sb.append("]]></column-value></column>");
577                    sb.append(
578                            "<column><column-name>description</column-name><column-value><![CDATA[");
579                    sb.append(getDescription());
580                    sb.append("]]></column-value></column>");
581    
582                    sb.append("</model>");
583    
584                    return sb.toString();
585            }
586    
587            private static ClassLoader _classLoader = PollsChoice.class.getClassLoader();
588            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
589                            PollsChoice.class
590                    };
591            private String _uuid;
592            private String _originalUuid;
593            private long _choiceId;
594            private long _questionId;
595            private long _originalQuestionId;
596            private boolean _setOriginalQuestionId;
597            private String _name;
598            private String _originalName;
599            private String _description;
600            private String _descriptionCurrentLanguageId;
601            private long _columnBitmask;
602            private PollsChoice _escapedModelProxy;
603    }