001
014
015 package com.liferay.portal.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 import com.liferay.portal.model.Image;
021
022 import java.io.Externalizable;
023 import java.io.IOException;
024 import java.io.ObjectInput;
025 import java.io.ObjectOutput;
026
027 import java.util.Date;
028
029
036 public class ImageCacheModel implements CacheModel<Image>, Externalizable {
037 @Override
038 public String toString() {
039 StringBundler sb = new StringBundler(13);
040
041 sb.append("{imageId=");
042 sb.append(imageId);
043 sb.append(", modifiedDate=");
044 sb.append(modifiedDate);
045 sb.append(", type=");
046 sb.append(type);
047 sb.append(", height=");
048 sb.append(height);
049 sb.append(", width=");
050 sb.append(width);
051 sb.append(", size=");
052 sb.append(size);
053 sb.append("}");
054
055 return sb.toString();
056 }
057
058 @Override
059 public Image toEntityModel() {
060 ImageImpl imageImpl = new ImageImpl();
061
062 imageImpl.setImageId(imageId);
063
064 if (modifiedDate == Long.MIN_VALUE) {
065 imageImpl.setModifiedDate(null);
066 }
067 else {
068 imageImpl.setModifiedDate(new Date(modifiedDate));
069 }
070
071 if (type == null) {
072 imageImpl.setType(StringPool.BLANK);
073 }
074 else {
075 imageImpl.setType(type);
076 }
077
078 imageImpl.setHeight(height);
079 imageImpl.setWidth(width);
080 imageImpl.setSize(size);
081
082 imageImpl.resetOriginalValues();
083
084 return imageImpl;
085 }
086
087 @Override
088 public void readExternal(ObjectInput objectInput) throws IOException {
089 imageId = objectInput.readLong();
090 modifiedDate = objectInput.readLong();
091 type = objectInput.readUTF();
092 height = objectInput.readInt();
093 width = objectInput.readInt();
094 size = objectInput.readInt();
095 }
096
097 @Override
098 public void writeExternal(ObjectOutput objectOutput)
099 throws IOException {
100 objectOutput.writeLong(imageId);
101 objectOutput.writeLong(modifiedDate);
102
103 if (type == null) {
104 objectOutput.writeUTF(StringPool.BLANK);
105 }
106 else {
107 objectOutput.writeUTF(type);
108 }
109
110 objectOutput.writeInt(height);
111 objectOutput.writeInt(width);
112 objectOutput.writeInt(size);
113 }
114
115 public long imageId;
116 public long modifiedDate;
117 public String type;
118 public int height;
119 public int width;
120 public int size;
121 }