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