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