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