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