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