001
014
015 package com.liferay.portlet.ratings.model.impl;
016
017 import com.liferay.portal.kernel.util.StringBundler;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.portal.model.CacheModel;
020
021 import com.liferay.portlet.ratings.model.RatingsEntry;
022
023 import java.io.Externalizable;
024 import java.io.IOException;
025 import java.io.ObjectInput;
026 import java.io.ObjectOutput;
027
028 import java.util.Date;
029
030
037 public class RatingsEntryCacheModel implements CacheModel<RatingsEntry>,
038 Externalizable {
039 @Override
040 public String toString() {
041 StringBundler sb = new StringBundler(19);
042
043 sb.append("{entryId=");
044 sb.append(entryId);
045 sb.append(", companyId=");
046 sb.append(companyId);
047 sb.append(", userId=");
048 sb.append(userId);
049 sb.append(", userName=");
050 sb.append(userName);
051 sb.append(", createDate=");
052 sb.append(createDate);
053 sb.append(", modifiedDate=");
054 sb.append(modifiedDate);
055 sb.append(", classNameId=");
056 sb.append(classNameId);
057 sb.append(", classPK=");
058 sb.append(classPK);
059 sb.append(", score=");
060 sb.append(score);
061 sb.append("}");
062
063 return sb.toString();
064 }
065
066 public RatingsEntry toEntityModel() {
067 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
068
069 ratingsEntryImpl.setEntryId(entryId);
070 ratingsEntryImpl.setCompanyId(companyId);
071 ratingsEntryImpl.setUserId(userId);
072
073 if (userName == null) {
074 ratingsEntryImpl.setUserName(StringPool.BLANK);
075 }
076 else {
077 ratingsEntryImpl.setUserName(userName);
078 }
079
080 if (createDate == Long.MIN_VALUE) {
081 ratingsEntryImpl.setCreateDate(null);
082 }
083 else {
084 ratingsEntryImpl.setCreateDate(new Date(createDate));
085 }
086
087 if (modifiedDate == Long.MIN_VALUE) {
088 ratingsEntryImpl.setModifiedDate(null);
089 }
090 else {
091 ratingsEntryImpl.setModifiedDate(new Date(modifiedDate));
092 }
093
094 ratingsEntryImpl.setClassNameId(classNameId);
095 ratingsEntryImpl.setClassPK(classPK);
096 ratingsEntryImpl.setScore(score);
097
098 ratingsEntryImpl.resetOriginalValues();
099
100 return ratingsEntryImpl;
101 }
102
103 public void readExternal(ObjectInput objectInput) throws IOException {
104 entryId = objectInput.readLong();
105 companyId = objectInput.readLong();
106 userId = objectInput.readLong();
107 userName = objectInput.readUTF();
108 createDate = objectInput.readLong();
109 modifiedDate = objectInput.readLong();
110 classNameId = objectInput.readLong();
111 classPK = objectInput.readLong();
112 score = objectInput.readDouble();
113 }
114
115 public void writeExternal(ObjectOutput objectOutput)
116 throws IOException {
117 objectOutput.writeLong(entryId);
118 objectOutput.writeLong(companyId);
119 objectOutput.writeLong(userId);
120
121 if (userName == null) {
122 objectOutput.writeUTF(StringPool.BLANK);
123 }
124 else {
125 objectOutput.writeUTF(userName);
126 }
127
128 objectOutput.writeLong(createDate);
129 objectOutput.writeLong(modifiedDate);
130 objectOutput.writeLong(classNameId);
131 objectOutput.writeLong(classPK);
132 objectOutput.writeDouble(score);
133 }
134
135 public long entryId;
136 public long companyId;
137 public long userId;
138 public String userName;
139 public long createDate;
140 public long modifiedDate;
141 public long classNameId;
142 public long classPK;
143 public double score;
144 }