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
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 _questionId = questionId;
128
129 if (!_setOriginalQuestionId) {
130 _setOriginalQuestionId = true;
131
132 _originalQuestionId = questionId;
133 }
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 _name = name;
151
152 if (_originalName == null) {
153 _originalName = name;
154 }
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 clone = new PollsChoiceImpl();
267
268 clone.setUuid(getUuid());
269 clone.setChoiceId(getChoiceId());
270 clone.setQuestionId(getQuestionId());
271 clone.setName(getName());
272 clone.setDescription(getDescription());
273
274 return clone;
275 }
276
277 public int compareTo(PollsChoice pollsChoice) {
278 int value = 0;
279
280 if (getQuestionId() < pollsChoice.getQuestionId()) {
281 value = -1;
282 }
283 else if (getQuestionId() > pollsChoice.getQuestionId()) {
284 value = 1;
285 }
286 else {
287 value = 0;
288 }
289
290 if (value != 0) {
291 return value;
292 }
293
294 value = getName().compareTo(pollsChoice.getName());
295
296 if (value != 0) {
297 return value;
298 }
299
300 return 0;
301 }
302
303 public boolean equals(Object obj) {
304 if (obj == null) {
305 return false;
306 }
307
308 PollsChoice pollsChoice = null;
309
310 try {
311 pollsChoice = (PollsChoice)obj;
312 }
313 catch (ClassCastException cce) {
314 return false;
315 }
316
317 long pk = pollsChoice.getPrimaryKey();
318
319 if (getPrimaryKey() == pk) {
320 return true;
321 }
322 else {
323 return false;
324 }
325 }
326
327 public int hashCode() {
328 return (int)getPrimaryKey();
329 }
330
331 public String toString() {
332 StringBundler sb = new StringBundler(11);
333
334 sb.append("{uuid=");
335 sb.append(getUuid());
336 sb.append(", choiceId=");
337 sb.append(getChoiceId());
338 sb.append(", questionId=");
339 sb.append(getQuestionId());
340 sb.append(", name=");
341 sb.append(getName());
342 sb.append(", description=");
343 sb.append(getDescription());
344 sb.append("}");
345
346 return sb.toString();
347 }
348
349 public String toXmlString() {
350 StringBundler sb = new StringBundler(19);
351
352 sb.append("<model><model-name>");
353 sb.append("com.liferay.portlet.polls.model.PollsChoice");
354 sb.append("</model-name>");
355
356 sb.append(
357 "<column><column-name>uuid</column-name><column-value><![CDATA[");
358 sb.append(getUuid());
359 sb.append("]]></column-value></column>");
360 sb.append(
361 "<column><column-name>choiceId</column-name><column-value><![CDATA[");
362 sb.append(getChoiceId());
363 sb.append("]]></column-value></column>");
364 sb.append(
365 "<column><column-name>questionId</column-name><column-value><![CDATA[");
366 sb.append(getQuestionId());
367 sb.append("]]></column-value></column>");
368 sb.append(
369 "<column><column-name>name</column-name><column-value><![CDATA[");
370 sb.append(getName());
371 sb.append("]]></column-value></column>");
372 sb.append(
373 "<column><column-name>description</column-name><column-value><![CDATA[");
374 sb.append(getDescription());
375 sb.append("]]></column-value></column>");
376
377 sb.append("</model>");
378
379 return sb.toString();
380 }
381
382 private String _uuid;
383 private long _choiceId;
384 private long _questionId;
385 private long _originalQuestionId;
386 private boolean _setOriginalQuestionId;
387 private String _name;
388 private String _originalName;
389 private String _description;
390 private transient ExpandoBridge _expandoBridge;
391 }