001    /**
002     * Copyright (c) 2000-2011 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.language.LanguageUtil;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.HtmlUtil;
021    import com.liferay.portal.kernel.util.LocaleUtil;
022    import com.liferay.portal.kernel.util.LocalizationUtil;
023    import com.liferay.portal.kernel.util.StringBundler;
024    import com.liferay.portal.kernel.util.StringPool;
025    import com.liferay.portal.kernel.util.Validator;
026    import com.liferay.portal.model.impl.BaseModelImpl;
027    import com.liferay.portal.service.ServiceContext;
028    
029    import com.liferay.portlet.expando.model.ExpandoBridge;
030    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
031    import com.liferay.portlet.polls.model.PollsChoice;
032    import com.liferay.portlet.polls.model.PollsChoiceModel;
033    
034    import java.io.Serializable;
035    
036    import java.lang.reflect.Proxy;
037    
038    import java.sql.Types;
039    
040    import java.util.Locale;
041    import java.util.Map;
042    
043    /**
044     * 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.
045     *
046     * <p>
047     * 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}.
048     * </p>
049     *
050     * <p>
051     * 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.
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    public class PollsChoiceModelImpl extends BaseModelImpl<PollsChoice>
061            implements PollsChoiceModel {
062            public static final String TABLE_NAME = "PollsChoice";
063            public static final Object[][] TABLE_COLUMNS = {
064                            { "uuid_", new Integer(Types.VARCHAR) },
065                            { "choiceId", new Integer(Types.BIGINT) },
066                            { "questionId", new Integer(Types.BIGINT) },
067                            { "name", new Integer(Types.VARCHAR) },
068                            { "description", new Integer(Types.VARCHAR) }
069                    };
070            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)";
071            public static final String TABLE_SQL_DROP = "drop table PollsChoice";
072            public static final String ORDER_BY_JPQL = " ORDER BY pollsChoice.questionId ASC, pollsChoice.name ASC";
073            public static final String ORDER_BY_SQL = " ORDER BY PollsChoice.questionId ASC, PollsChoice.name ASC";
074            public static final String DATA_SOURCE = "liferayDataSource";
075            public static final String SESSION_FACTORY = "liferaySessionFactory";
076            public static final String TX_MANAGER = "liferayTransactionManager";
077            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
078                                    "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
079                            true);
080            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
081                                    "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
082                            true);
083            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
084                                    "lock.expiration.time.com.liferay.portlet.polls.model.PollsChoice"));
085    
086            public PollsChoiceModelImpl() {
087            }
088    
089            public long getPrimaryKey() {
090                    return _choiceId;
091            }
092    
093            public void setPrimaryKey(long pk) {
094                    setChoiceId(pk);
095            }
096    
097            public Serializable getPrimaryKeyObj() {
098                    return new Long(_choiceId);
099            }
100    
101            public String getUuid() {
102                    if (_uuid == null) {
103                            return StringPool.BLANK;
104                    }
105                    else {
106                            return _uuid;
107                    }
108            }
109    
110            public void setUuid(String uuid) {
111                    _uuid = uuid;
112            }
113    
114            public long getChoiceId() {
115                    return _choiceId;
116            }
117    
118            public void setChoiceId(long choiceId) {
119                    _choiceId = choiceId;
120            }
121    
122            public long getQuestionId() {
123                    return _questionId;
124            }
125    
126            public void setQuestionId(long questionId) {
127                    if (!_setOriginalQuestionId) {
128                            _setOriginalQuestionId = true;
129    
130                            _originalQuestionId = _questionId;
131                    }
132    
133                    _questionId = questionId;
134            }
135    
136            public long getOriginalQuestionId() {
137                    return _originalQuestionId;
138            }
139    
140            public String getName() {
141                    if (_name == null) {
142                            return StringPool.BLANK;
143                    }
144                    else {
145                            return _name;
146                    }
147            }
148    
149            public void setName(String name) {
150                    if (_originalName == null) {
151                            _originalName = _name;
152                    }
153    
154                    _name = name;
155            }
156    
157            public String getOriginalName() {
158                    return GetterUtil.getString(_originalName);
159            }
160    
161            public String getDescription() {
162                    if (_description == null) {
163                            return StringPool.BLANK;
164                    }
165                    else {
166                            return _description;
167                    }
168            }
169    
170            public String getDescription(Locale locale) {
171                    String languageId = LocaleUtil.toLanguageId(locale);
172    
173                    return getDescription(languageId);
174            }
175    
176            public String getDescription(Locale locale, boolean useDefault) {
177                    String languageId = LocaleUtil.toLanguageId(locale);
178    
179                    return getDescription(languageId, useDefault);
180            }
181    
182            public String getDescription(String languageId) {
183                    String value = LocalizationUtil.getLocalization(getDescription(),
184                                    languageId);
185    
186                    if (isEscapedModel()) {
187                            return HtmlUtil.escape(value);
188                    }
189                    else {
190                            return value;
191                    }
192            }
193    
194            public String getDescription(String languageId, boolean useDefault) {
195                    String value = LocalizationUtil.getLocalization(getDescription(),
196                                    languageId, useDefault);
197    
198                    if (isEscapedModel()) {
199                            return HtmlUtil.escape(value);
200                    }
201                    else {
202                            return value;
203                    }
204            }
205    
206            public Map<Locale, String> getDescriptionMap() {
207                    return LocalizationUtil.getLocalizationMap(getDescription());
208            }
209    
210            public void setDescription(String description) {
211                    _description = description;
212            }
213    
214            public void setDescription(Locale locale, String description) {
215                    String languageId = LocaleUtil.toLanguageId(locale);
216    
217                    if (Validator.isNotNull(description)) {
218                            setDescription(LocalizationUtil.updateLocalization(
219                                            getDescription(), "Description", description, languageId));
220                    }
221                    else {
222                            setDescription(LocalizationUtil.removeLocalization(
223                                            getDescription(), "Description", languageId));
224                    }
225            }
226    
227            public void setDescriptionMap(Map<Locale, String> descriptionMap) {
228                    if (descriptionMap == null) {
229                            return;
230                    }
231    
232                    Locale[] locales = LanguageUtil.getAvailableLocales();
233    
234                    for (Locale locale : locales) {
235                            String description = descriptionMap.get(locale);
236    
237                            setDescription(locale, description);
238                    }
239            }
240    
241            public PollsChoice toEscapedModel() {
242                    if (isEscapedModel()) {
243                            return (PollsChoice)this;
244                    }
245                    else {
246                            return (PollsChoice)Proxy.newProxyInstance(PollsChoice.class.getClassLoader(),
247                                    new Class[] { PollsChoice.class },
248                                    new AutoEscapeBeanHandler(this));
249                    }
250            }
251    
252            public ExpandoBridge getExpandoBridge() {
253                    if (_expandoBridge == null) {
254                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
255                                            PollsChoice.class.getName(), getPrimaryKey());
256                    }
257    
258                    return _expandoBridge;
259            }
260    
261            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
262                    getExpandoBridge().setAttributes(serviceContext);
263            }
264    
265            public Object clone() {
266                    PollsChoiceImpl pollsChoiceImpl = new PollsChoiceImpl();
267    
268                    pollsChoiceImpl.setUuid(getUuid());
269    
270                    pollsChoiceImpl.setChoiceId(getChoiceId());
271    
272                    pollsChoiceImpl.setQuestionId(getQuestionId());
273    
274                    PollsChoiceModelImpl pollsChoiceModelImpl = pollsChoiceImpl;
275    
276                    pollsChoiceModelImpl._originalQuestionId = pollsChoiceModelImpl._questionId;
277    
278                    pollsChoiceModelImpl._setOriginalQuestionId = false;
279                    pollsChoiceImpl.setName(getName());
280    
281                    pollsChoiceModelImpl._originalName = pollsChoiceModelImpl._name;
282    
283                    pollsChoiceImpl.setDescription(getDescription());
284    
285                    return pollsChoiceImpl;
286            }
287    
288            public int compareTo(PollsChoice pollsChoice) {
289                    int value = 0;
290    
291                    if (getQuestionId() < pollsChoice.getQuestionId()) {
292                            value = -1;
293                    }
294                    else if (getQuestionId() > pollsChoice.getQuestionId()) {
295                            value = 1;
296                    }
297                    else {
298                            value = 0;
299                    }
300    
301                    if (value != 0) {
302                            return value;
303                    }
304    
305                    value = getName().compareTo(pollsChoice.getName());
306    
307                    if (value != 0) {
308                            return value;
309                    }
310    
311                    return 0;
312            }
313    
314            public boolean equals(Object obj) {
315                    if (obj == null) {
316                            return false;
317                    }
318    
319                    PollsChoice pollsChoice = null;
320    
321                    try {
322                            pollsChoice = (PollsChoice)obj;
323                    }
324                    catch (ClassCastException cce) {
325                            return false;
326                    }
327    
328                    long pk = pollsChoice.getPrimaryKey();
329    
330                    if (getPrimaryKey() == pk) {
331                            return true;
332                    }
333                    else {
334                            return false;
335                    }
336            }
337    
338            public int hashCode() {
339                    return (int)getPrimaryKey();
340            }
341    
342            public String toString() {
343                    StringBundler sb = new StringBundler(11);
344    
345                    sb.append("{uuid=");
346                    sb.append(getUuid());
347                    sb.append(", choiceId=");
348                    sb.append(getChoiceId());
349                    sb.append(", questionId=");
350                    sb.append(getQuestionId());
351                    sb.append(", name=");
352                    sb.append(getName());
353                    sb.append(", description=");
354                    sb.append(getDescription());
355                    sb.append("}");
356    
357                    return sb.toString();
358            }
359    
360            public String toXmlString() {
361                    StringBundler sb = new StringBundler(19);
362    
363                    sb.append("<model><model-name>");
364                    sb.append("com.liferay.portlet.polls.model.PollsChoice");
365                    sb.append("</model-name>");
366    
367                    sb.append(
368                            "<column><column-name>uuid</column-name><column-value><![CDATA[");
369                    sb.append(getUuid());
370                    sb.append("]]></column-value></column>");
371                    sb.append(
372                            "<column><column-name>choiceId</column-name><column-value><![CDATA[");
373                    sb.append(getChoiceId());
374                    sb.append("]]></column-value></column>");
375                    sb.append(
376                            "<column><column-name>questionId</column-name><column-value><![CDATA[");
377                    sb.append(getQuestionId());
378                    sb.append("]]></column-value></column>");
379                    sb.append(
380                            "<column><column-name>name</column-name><column-value><![CDATA[");
381                    sb.append(getName());
382                    sb.append("]]></column-value></column>");
383                    sb.append(
384                            "<column><column-name>description</column-name><column-value><![CDATA[");
385                    sb.append(getDescription());
386                    sb.append("]]></column-value></column>");
387    
388                    sb.append("</model>");
389    
390                    return sb.toString();
391            }
392    
393            private String _uuid;
394            private long _choiceId;
395            private long _questionId;
396            private long _originalQuestionId;
397            private boolean _setOriginalQuestionId;
398            private String _name;
399            private String _originalName;
400            private String _description;
401            private transient ExpandoBridge _expandoBridge;
402    }