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.exception.SystemException;
019    import com.liferay.portal.kernel.json.JSON;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.kernel.util.ProxyUtil;
022    import com.liferay.portal.kernel.util.StringBundler;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.model.CacheModel;
025    import com.liferay.portal.model.impl.BaseModelImpl;
026    import com.liferay.portal.service.ServiceContext;
027    import com.liferay.portal.util.PortalUtil;
028    
029    import com.liferay.portlet.expando.model.ExpandoBridge;
030    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
031    import com.liferay.portlet.polls.model.PollsVote;
032    import com.liferay.portlet.polls.model.PollsVoteModel;
033    import com.liferay.portlet.polls.model.PollsVoteSoap;
034    
035    import java.io.Serializable;
036    
037    import java.sql.Types;
038    
039    import java.util.ArrayList;
040    import java.util.Date;
041    import java.util.HashMap;
042    import java.util.List;
043    import java.util.Map;
044    
045    /**
046     * The base model implementation for the PollsVote service. Represents a row in the "PollsVote" database table, with each column mapped to a property of this class.
047     *
048     * <p>
049     * This implementation and its corresponding interface {@link com.liferay.portlet.polls.model.PollsVoteModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link PollsVoteImpl}.
050     * </p>
051     *
052     * @author Brian Wing Shun Chan
053     * @see PollsVoteImpl
054     * @see com.liferay.portlet.polls.model.PollsVote
055     * @see com.liferay.portlet.polls.model.PollsVoteModel
056     * @generated
057     */
058    @JSON(strict = true)
059    public class PollsVoteModelImpl extends BaseModelImpl<PollsVote>
060            implements PollsVoteModel {
061            /*
062             * NOTE FOR DEVELOPERS:
063             *
064             * Never modify or reference this class directly. All methods that expect a polls vote model instance should use the {@link com.liferay.portlet.polls.model.PollsVote} interface instead.
065             */
066            public static final String TABLE_NAME = "PollsVote";
067            public static final Object[][] TABLE_COLUMNS = {
068                            { "voteId", Types.BIGINT },
069                            { "companyId", Types.BIGINT },
070                            { "userId", Types.BIGINT },
071                            { "userName", Types.VARCHAR },
072                            { "createDate", Types.TIMESTAMP },
073                            { "modifiedDate", Types.TIMESTAMP },
074                            { "questionId", Types.BIGINT },
075                            { "choiceId", Types.BIGINT },
076                            { "voteDate", Types.TIMESTAMP }
077                    };
078            public static final String TABLE_SQL_CREATE = "create table PollsVote (voteId LONG not null primary key,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,questionId LONG,choiceId LONG,voteDate DATE null)";
079            public static final String TABLE_SQL_DROP = "drop table PollsVote";
080            public static final String ORDER_BY_JPQL = " ORDER BY pollsVote.voteId ASC";
081            public static final String ORDER_BY_SQL = " ORDER BY PollsVote.voteId ASC";
082            public static final String DATA_SOURCE = "liferayDataSource";
083            public static final String SESSION_FACTORY = "liferaySessionFactory";
084            public static final String TX_MANAGER = "liferayTransactionManager";
085            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
086                                    "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsVote"),
087                            true);
088            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
089                                    "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsVote"),
090                            true);
091            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
092                                    "value.object.column.bitmask.enabled.com.liferay.portlet.polls.model.PollsVote"),
093                            true);
094            public static long CHOICEID_COLUMN_BITMASK = 1L;
095            public static long QUESTIONID_COLUMN_BITMASK = 2L;
096            public static long USERID_COLUMN_BITMASK = 4L;
097            public static long VOTEID_COLUMN_BITMASK = 8L;
098    
099            /**
100             * Converts the soap model instance into a normal model instance.
101             *
102             * @param soapModel the soap model instance to convert
103             * @return the normal model instance
104             */
105            public static PollsVote toModel(PollsVoteSoap soapModel) {
106                    if (soapModel == null) {
107                            return null;
108                    }
109    
110                    PollsVote model = new PollsVoteImpl();
111    
112                    model.setVoteId(soapModel.getVoteId());
113                    model.setCompanyId(soapModel.getCompanyId());
114                    model.setUserId(soapModel.getUserId());
115                    model.setUserName(soapModel.getUserName());
116                    model.setCreateDate(soapModel.getCreateDate());
117                    model.setModifiedDate(soapModel.getModifiedDate());
118                    model.setQuestionId(soapModel.getQuestionId());
119                    model.setChoiceId(soapModel.getChoiceId());
120                    model.setVoteDate(soapModel.getVoteDate());
121    
122                    return model;
123            }
124    
125            /**
126             * Converts the soap model instances into normal model instances.
127             *
128             * @param soapModels the soap model instances to convert
129             * @return the normal model instances
130             */
131            public static List<PollsVote> toModels(PollsVoteSoap[] soapModels) {
132                    if (soapModels == null) {
133                            return null;
134                    }
135    
136                    List<PollsVote> models = new ArrayList<PollsVote>(soapModels.length);
137    
138                    for (PollsVoteSoap soapModel : soapModels) {
139                            models.add(toModel(soapModel));
140                    }
141    
142                    return models;
143            }
144    
145            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
146                                    "lock.expiration.time.com.liferay.portlet.polls.model.PollsVote"));
147    
148            public PollsVoteModelImpl() {
149            }
150    
151            public long getPrimaryKey() {
152                    return _voteId;
153            }
154    
155            public void setPrimaryKey(long primaryKey) {
156                    setVoteId(primaryKey);
157            }
158    
159            public Serializable getPrimaryKeyObj() {
160                    return _voteId;
161            }
162    
163            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
164                    setPrimaryKey(((Long)primaryKeyObj).longValue());
165            }
166    
167            public Class<?> getModelClass() {
168                    return PollsVote.class;
169            }
170    
171            public String getModelClassName() {
172                    return PollsVote.class.getName();
173            }
174    
175            @Override
176            public Map<String, Object> getModelAttributes() {
177                    Map<String, Object> attributes = new HashMap<String, Object>();
178    
179                    attributes.put("voteId", getVoteId());
180                    attributes.put("companyId", getCompanyId());
181                    attributes.put("userId", getUserId());
182                    attributes.put("userName", getUserName());
183                    attributes.put("createDate", getCreateDate());
184                    attributes.put("modifiedDate", getModifiedDate());
185                    attributes.put("questionId", getQuestionId());
186                    attributes.put("choiceId", getChoiceId());
187                    attributes.put("voteDate", getVoteDate());
188    
189                    return attributes;
190            }
191    
192            @Override
193            public void setModelAttributes(Map<String, Object> attributes) {
194                    Long voteId = (Long)attributes.get("voteId");
195    
196                    if (voteId != null) {
197                            setVoteId(voteId);
198                    }
199    
200                    Long companyId = (Long)attributes.get("companyId");
201    
202                    if (companyId != null) {
203                            setCompanyId(companyId);
204                    }
205    
206                    Long userId = (Long)attributes.get("userId");
207    
208                    if (userId != null) {
209                            setUserId(userId);
210                    }
211    
212                    String userName = (String)attributes.get("userName");
213    
214                    if (userName != null) {
215                            setUserName(userName);
216                    }
217    
218                    Date createDate = (Date)attributes.get("createDate");
219    
220                    if (createDate != null) {
221                            setCreateDate(createDate);
222                    }
223    
224                    Date modifiedDate = (Date)attributes.get("modifiedDate");
225    
226                    if (modifiedDate != null) {
227                            setModifiedDate(modifiedDate);
228                    }
229    
230                    Long questionId = (Long)attributes.get("questionId");
231    
232                    if (questionId != null) {
233                            setQuestionId(questionId);
234                    }
235    
236                    Long choiceId = (Long)attributes.get("choiceId");
237    
238                    if (choiceId != null) {
239                            setChoiceId(choiceId);
240                    }
241    
242                    Date voteDate = (Date)attributes.get("voteDate");
243    
244                    if (voteDate != null) {
245                            setVoteDate(voteDate);
246                    }
247            }
248    
249            @JSON
250            public long getVoteId() {
251                    return _voteId;
252            }
253    
254            public void setVoteId(long voteId) {
255                    _voteId = voteId;
256            }
257    
258            @JSON
259            public long getCompanyId() {
260                    return _companyId;
261            }
262    
263            public void setCompanyId(long companyId) {
264                    _companyId = companyId;
265            }
266    
267            @JSON
268            public long getUserId() {
269                    return _userId;
270            }
271    
272            public void setUserId(long userId) {
273                    _columnBitmask |= USERID_COLUMN_BITMASK;
274    
275                    if (!_setOriginalUserId) {
276                            _setOriginalUserId = true;
277    
278                            _originalUserId = _userId;
279                    }
280    
281                    _userId = userId;
282            }
283    
284            public String getUserUuid() throws SystemException {
285                    return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
286            }
287    
288            public void setUserUuid(String userUuid) {
289                    _userUuid = userUuid;
290            }
291    
292            public long getOriginalUserId() {
293                    return _originalUserId;
294            }
295    
296            @JSON
297            public String getUserName() {
298                    if (_userName == null) {
299                            return StringPool.BLANK;
300                    }
301                    else {
302                            return _userName;
303                    }
304            }
305    
306            public void setUserName(String userName) {
307                    _userName = userName;
308            }
309    
310            @JSON
311            public Date getCreateDate() {
312                    return _createDate;
313            }
314    
315            public void setCreateDate(Date createDate) {
316                    _createDate = createDate;
317            }
318    
319            @JSON
320            public Date getModifiedDate() {
321                    return _modifiedDate;
322            }
323    
324            public void setModifiedDate(Date modifiedDate) {
325                    _modifiedDate = modifiedDate;
326            }
327    
328            @JSON
329            public long getQuestionId() {
330                    return _questionId;
331            }
332    
333            public void setQuestionId(long questionId) {
334                    _columnBitmask |= QUESTIONID_COLUMN_BITMASK;
335    
336                    if (!_setOriginalQuestionId) {
337                            _setOriginalQuestionId = true;
338    
339                            _originalQuestionId = _questionId;
340                    }
341    
342                    _questionId = questionId;
343            }
344    
345            public long getOriginalQuestionId() {
346                    return _originalQuestionId;
347            }
348    
349            @JSON
350            public long getChoiceId() {
351                    return _choiceId;
352            }
353    
354            public void setChoiceId(long choiceId) {
355                    _columnBitmask |= CHOICEID_COLUMN_BITMASK;
356    
357                    if (!_setOriginalChoiceId) {
358                            _setOriginalChoiceId = true;
359    
360                            _originalChoiceId = _choiceId;
361                    }
362    
363                    _choiceId = choiceId;
364            }
365    
366            public long getOriginalChoiceId() {
367                    return _originalChoiceId;
368            }
369    
370            @JSON
371            public Date getVoteDate() {
372                    return _voteDate;
373            }
374    
375            public void setVoteDate(Date voteDate) {
376                    _voteDate = voteDate;
377            }
378    
379            public long getColumnBitmask() {
380                    return _columnBitmask;
381            }
382    
383            @Override
384            public ExpandoBridge getExpandoBridge() {
385                    return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
386                            PollsVote.class.getName(), getPrimaryKey());
387            }
388    
389            @Override
390            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
391                    ExpandoBridge expandoBridge = getExpandoBridge();
392    
393                    expandoBridge.setAttributes(serviceContext);
394            }
395    
396            @Override
397            public PollsVote toEscapedModel() {
398                    if (_escapedModel == null) {
399                            _escapedModel = (PollsVote)ProxyUtil.newProxyInstance(_classLoader,
400                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
401                    }
402    
403                    return _escapedModel;
404            }
405    
406            @Override
407            public Object clone() {
408                    PollsVoteImpl pollsVoteImpl = new PollsVoteImpl();
409    
410                    pollsVoteImpl.setVoteId(getVoteId());
411                    pollsVoteImpl.setCompanyId(getCompanyId());
412                    pollsVoteImpl.setUserId(getUserId());
413                    pollsVoteImpl.setUserName(getUserName());
414                    pollsVoteImpl.setCreateDate(getCreateDate());
415                    pollsVoteImpl.setModifiedDate(getModifiedDate());
416                    pollsVoteImpl.setQuestionId(getQuestionId());
417                    pollsVoteImpl.setChoiceId(getChoiceId());
418                    pollsVoteImpl.setVoteDate(getVoteDate());
419    
420                    pollsVoteImpl.resetOriginalValues();
421    
422                    return pollsVoteImpl;
423            }
424    
425            public int compareTo(PollsVote pollsVote) {
426                    long primaryKey = pollsVote.getPrimaryKey();
427    
428                    if (getPrimaryKey() < primaryKey) {
429                            return -1;
430                    }
431                    else if (getPrimaryKey() > primaryKey) {
432                            return 1;
433                    }
434                    else {
435                            return 0;
436                    }
437            }
438    
439            @Override
440            public boolean equals(Object obj) {
441                    if (obj == null) {
442                            return false;
443                    }
444    
445                    PollsVote pollsVote = null;
446    
447                    try {
448                            pollsVote = (PollsVote)obj;
449                    }
450                    catch (ClassCastException cce) {
451                            return false;
452                    }
453    
454                    long primaryKey = pollsVote.getPrimaryKey();
455    
456                    if (getPrimaryKey() == primaryKey) {
457                            return true;
458                    }
459                    else {
460                            return false;
461                    }
462            }
463    
464            @Override
465            public int hashCode() {
466                    return (int)getPrimaryKey();
467            }
468    
469            @Override
470            public void resetOriginalValues() {
471                    PollsVoteModelImpl pollsVoteModelImpl = this;
472    
473                    pollsVoteModelImpl._originalUserId = pollsVoteModelImpl._userId;
474    
475                    pollsVoteModelImpl._setOriginalUserId = false;
476    
477                    pollsVoteModelImpl._originalQuestionId = pollsVoteModelImpl._questionId;
478    
479                    pollsVoteModelImpl._setOriginalQuestionId = false;
480    
481                    pollsVoteModelImpl._originalChoiceId = pollsVoteModelImpl._choiceId;
482    
483                    pollsVoteModelImpl._setOriginalChoiceId = false;
484    
485                    pollsVoteModelImpl._columnBitmask = 0;
486            }
487    
488            @Override
489            public CacheModel<PollsVote> toCacheModel() {
490                    PollsVoteCacheModel pollsVoteCacheModel = new PollsVoteCacheModel();
491    
492                    pollsVoteCacheModel.voteId = getVoteId();
493    
494                    pollsVoteCacheModel.companyId = getCompanyId();
495    
496                    pollsVoteCacheModel.userId = getUserId();
497    
498                    pollsVoteCacheModel.userName = getUserName();
499    
500                    String userName = pollsVoteCacheModel.userName;
501    
502                    if ((userName != null) && (userName.length() == 0)) {
503                            pollsVoteCacheModel.userName = null;
504                    }
505    
506                    Date createDate = getCreateDate();
507    
508                    if (createDate != null) {
509                            pollsVoteCacheModel.createDate = createDate.getTime();
510                    }
511                    else {
512                            pollsVoteCacheModel.createDate = Long.MIN_VALUE;
513                    }
514    
515                    Date modifiedDate = getModifiedDate();
516    
517                    if (modifiedDate != null) {
518                            pollsVoteCacheModel.modifiedDate = modifiedDate.getTime();
519                    }
520                    else {
521                            pollsVoteCacheModel.modifiedDate = Long.MIN_VALUE;
522                    }
523    
524                    pollsVoteCacheModel.questionId = getQuestionId();
525    
526                    pollsVoteCacheModel.choiceId = getChoiceId();
527    
528                    Date voteDate = getVoteDate();
529    
530                    if (voteDate != null) {
531                            pollsVoteCacheModel.voteDate = voteDate.getTime();
532                    }
533                    else {
534                            pollsVoteCacheModel.voteDate = Long.MIN_VALUE;
535                    }
536    
537                    return pollsVoteCacheModel;
538            }
539    
540            @Override
541            public String toString() {
542                    StringBundler sb = new StringBundler(19);
543    
544                    sb.append("{voteId=");
545                    sb.append(getVoteId());
546                    sb.append(", companyId=");
547                    sb.append(getCompanyId());
548                    sb.append(", userId=");
549                    sb.append(getUserId());
550                    sb.append(", userName=");
551                    sb.append(getUserName());
552                    sb.append(", createDate=");
553                    sb.append(getCreateDate());
554                    sb.append(", modifiedDate=");
555                    sb.append(getModifiedDate());
556                    sb.append(", questionId=");
557                    sb.append(getQuestionId());
558                    sb.append(", choiceId=");
559                    sb.append(getChoiceId());
560                    sb.append(", voteDate=");
561                    sb.append(getVoteDate());
562                    sb.append("}");
563    
564                    return sb.toString();
565            }
566    
567            public String toXmlString() {
568                    StringBundler sb = new StringBundler(31);
569    
570                    sb.append("<model><model-name>");
571                    sb.append("com.liferay.portlet.polls.model.PollsVote");
572                    sb.append("</model-name>");
573    
574                    sb.append(
575                            "<column><column-name>voteId</column-name><column-value><![CDATA[");
576                    sb.append(getVoteId());
577                    sb.append("]]></column-value></column>");
578                    sb.append(
579                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
580                    sb.append(getCompanyId());
581                    sb.append("]]></column-value></column>");
582                    sb.append(
583                            "<column><column-name>userId</column-name><column-value><![CDATA[");
584                    sb.append(getUserId());
585                    sb.append("]]></column-value></column>");
586                    sb.append(
587                            "<column><column-name>userName</column-name><column-value><![CDATA[");
588                    sb.append(getUserName());
589                    sb.append("]]></column-value></column>");
590                    sb.append(
591                            "<column><column-name>createDate</column-name><column-value><![CDATA[");
592                    sb.append(getCreateDate());
593                    sb.append("]]></column-value></column>");
594                    sb.append(
595                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
596                    sb.append(getModifiedDate());
597                    sb.append("]]></column-value></column>");
598                    sb.append(
599                            "<column><column-name>questionId</column-name><column-value><![CDATA[");
600                    sb.append(getQuestionId());
601                    sb.append("]]></column-value></column>");
602                    sb.append(
603                            "<column><column-name>choiceId</column-name><column-value><![CDATA[");
604                    sb.append(getChoiceId());
605                    sb.append("]]></column-value></column>");
606                    sb.append(
607                            "<column><column-name>voteDate</column-name><column-value><![CDATA[");
608                    sb.append(getVoteDate());
609                    sb.append("]]></column-value></column>");
610    
611                    sb.append("</model>");
612    
613                    return sb.toString();
614            }
615    
616            private static ClassLoader _classLoader = PollsVote.class.getClassLoader();
617            private static Class<?>[] _escapedModelInterfaces = new Class[] {
618                            PollsVote.class
619                    };
620            private long _voteId;
621            private long _companyId;
622            private long _userId;
623            private String _userUuid;
624            private long _originalUserId;
625            private boolean _setOriginalUserId;
626            private String _userName;
627            private Date _createDate;
628            private Date _modifiedDate;
629            private long _questionId;
630            private long _originalQuestionId;
631            private boolean _setOriginalQuestionId;
632            private long _choiceId;
633            private long _originalChoiceId;
634            private boolean _setOriginalChoiceId;
635            private Date _voteDate;
636            private long _columnBitmask;
637            private PollsVote _escapedModel;
638    }