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