1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.ratings.model.impl;
24  
25  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
26  import com.liferay.portal.kernel.util.GetterUtil;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.model.impl.BaseModelImpl;
29  import com.liferay.portal.util.PortalUtil;
30  
31  import com.liferay.portlet.expando.model.ExpandoBridge;
32  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
33  import com.liferay.portlet.ratings.model.RatingsStats;
34  import com.liferay.portlet.ratings.model.RatingsStatsSoap;
35  
36  import java.io.Serializable;
37  
38  import java.lang.reflect.Proxy;
39  
40  import java.sql.Types;
41  
42  import java.util.ArrayList;
43  import java.util.List;
44  
45  /**
46   * <a href="RatingsStatsModelImpl.java.html"><b><i>View Source</i></b></a>
47   *
48   * <p>
49   * ServiceBuilder generated this class. Modifications in this class will be
50   * overwritten the next time is generated.
51   * </p>
52   *
53   * <p>
54   * This class is a model that represents the <code>RatingsStats</code> table
55   * in the database.
56   * </p>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   * @see com.liferay.portlet.ratings.model.RatingsStats
61   * @see com.liferay.portlet.ratings.model.RatingsStatsModel
62   * @see com.liferay.portlet.ratings.model.impl.RatingsStatsImpl
63   *
64   */
65  public class RatingsStatsModelImpl extends BaseModelImpl<RatingsStats> {
66      public static final String TABLE_NAME = "RatingsStats";
67      public static final Object[][] TABLE_COLUMNS = {
68              { "statsId", new Integer(Types.BIGINT) },
69              
70  
71              { "classNameId", new Integer(Types.BIGINT) },
72              
73  
74              { "classPK", new Integer(Types.BIGINT) },
75              
76  
77              { "totalEntries", new Integer(Types.INTEGER) },
78              
79  
80              { "totalScore", new Integer(Types.DOUBLE) },
81              
82  
83              { "averageScore", new Integer(Types.DOUBLE) }
84          };
85      public static final String TABLE_SQL_CREATE = "create table RatingsStats (statsId LONG not null primary key,classNameId LONG,classPK LONG,totalEntries INTEGER,totalScore DOUBLE,averageScore DOUBLE)";
86      public static final String TABLE_SQL_DROP = "drop table RatingsStats";
87      public static final String DATA_SOURCE = "liferayDataSource";
88      public static final String SESSION_FACTORY = "liferaySessionFactory";
89      public static final String TX_MANAGER = "liferayTransactionManager";
90      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
91                  "value.object.entity.cache.enabled.com.liferay.portlet.ratings.model.RatingsStats"),
92              true);
93      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
94                  "value.object.finder.cache.enabled.com.liferay.portlet.ratings.model.RatingsStats"),
95              true);
96  
97      public static RatingsStats toModel(RatingsStatsSoap soapModel) {
98          RatingsStats model = new RatingsStatsImpl();
99  
100         model.setStatsId(soapModel.getStatsId());
101         model.setClassNameId(soapModel.getClassNameId());
102         model.setClassPK(soapModel.getClassPK());
103         model.setTotalEntries(soapModel.getTotalEntries());
104         model.setTotalScore(soapModel.getTotalScore());
105         model.setAverageScore(soapModel.getAverageScore());
106 
107         return model;
108     }
109 
110     public static List<RatingsStats> toModels(RatingsStatsSoap[] soapModels) {
111         List<RatingsStats> models = new ArrayList<RatingsStats>(soapModels.length);
112 
113         for (RatingsStatsSoap soapModel : soapModels) {
114             models.add(toModel(soapModel));
115         }
116 
117         return models;
118     }
119 
120     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
121                 "lock.expiration.time.com.liferay.portlet.ratings.model.RatingsStats"));
122 
123     public RatingsStatsModelImpl() {
124     }
125 
126     public long getPrimaryKey() {
127         return _statsId;
128     }
129 
130     public void setPrimaryKey(long pk) {
131         setStatsId(pk);
132     }
133 
134     public Serializable getPrimaryKeyObj() {
135         return new Long(_statsId);
136     }
137 
138     public long getStatsId() {
139         return _statsId;
140     }
141 
142     public void setStatsId(long statsId) {
143         _statsId = statsId;
144     }
145 
146     public String getClassName() {
147         if (getClassNameId() <= 0) {
148             return StringPool.BLANK;
149         }
150 
151         return PortalUtil.getClassName(getClassNameId());
152     }
153 
154     public long getClassNameId() {
155         return _classNameId;
156     }
157 
158     public void setClassNameId(long classNameId) {
159         _classNameId = classNameId;
160 
161         if (!_setOriginalClassNameId) {
162             _setOriginalClassNameId = true;
163 
164             _originalClassNameId = classNameId;
165         }
166     }
167 
168     public long getOriginalClassNameId() {
169         return _originalClassNameId;
170     }
171 
172     public long getClassPK() {
173         return _classPK;
174     }
175 
176     public void setClassPK(long classPK) {
177         _classPK = classPK;
178 
179         if (!_setOriginalClassPK) {
180             _setOriginalClassPK = true;
181 
182             _originalClassPK = classPK;
183         }
184     }
185 
186     public long getOriginalClassPK() {
187         return _originalClassPK;
188     }
189 
190     public int getTotalEntries() {
191         return _totalEntries;
192     }
193 
194     public void setTotalEntries(int totalEntries) {
195         _totalEntries = totalEntries;
196     }
197 
198     public double getTotalScore() {
199         return _totalScore;
200     }
201 
202     public void setTotalScore(double totalScore) {
203         _totalScore = totalScore;
204     }
205 
206     public double getAverageScore() {
207         return _averageScore;
208     }
209 
210     public void setAverageScore(double averageScore) {
211         _averageScore = averageScore;
212     }
213 
214     public RatingsStats toEscapedModel() {
215         if (isEscapedModel()) {
216             return (RatingsStats)this;
217         }
218         else {
219             RatingsStats model = new RatingsStatsImpl();
220 
221             model.setNew(isNew());
222             model.setEscapedModel(true);
223 
224             model.setStatsId(getStatsId());
225             model.setClassNameId(getClassNameId());
226             model.setClassPK(getClassPK());
227             model.setTotalEntries(getTotalEntries());
228             model.setTotalScore(getTotalScore());
229             model.setAverageScore(getAverageScore());
230 
231             model = (RatingsStats)Proxy.newProxyInstance(RatingsStats.class.getClassLoader(),
232                     new Class[] { RatingsStats.class },
233                     new ReadOnlyBeanHandler(model));
234 
235             return model;
236         }
237     }
238 
239     public ExpandoBridge getExpandoBridge() {
240         if (_expandoBridge == null) {
241             _expandoBridge = new ExpandoBridgeImpl(RatingsStats.class.getName(),
242                     getPrimaryKey());
243         }
244 
245         return _expandoBridge;
246     }
247 
248     public Object clone() {
249         RatingsStatsImpl clone = new RatingsStatsImpl();
250 
251         clone.setStatsId(getStatsId());
252         clone.setClassNameId(getClassNameId());
253         clone.setClassPK(getClassPK());
254         clone.setTotalEntries(getTotalEntries());
255         clone.setTotalScore(getTotalScore());
256         clone.setAverageScore(getAverageScore());
257 
258         return clone;
259     }
260 
261     public int compareTo(RatingsStats ratingsStats) {
262         long pk = ratingsStats.getPrimaryKey();
263 
264         if (getPrimaryKey() < pk) {
265             return -1;
266         }
267         else if (getPrimaryKey() > pk) {
268             return 1;
269         }
270         else {
271             return 0;
272         }
273     }
274 
275     public boolean equals(Object obj) {
276         if (obj == null) {
277             return false;
278         }
279 
280         RatingsStats ratingsStats = null;
281 
282         try {
283             ratingsStats = (RatingsStats)obj;
284         }
285         catch (ClassCastException cce) {
286             return false;
287         }
288 
289         long pk = ratingsStats.getPrimaryKey();
290 
291         if (getPrimaryKey() == pk) {
292             return true;
293         }
294         else {
295             return false;
296         }
297     }
298 
299     public int hashCode() {
300         return (int)getPrimaryKey();
301     }
302 
303     public String toString() {
304         StringBuilder sb = new StringBuilder();
305 
306         sb.append("{statsId=");
307         sb.append(getStatsId());
308         sb.append(", classNameId=");
309         sb.append(getClassNameId());
310         sb.append(", classPK=");
311         sb.append(getClassPK());
312         sb.append(", totalEntries=");
313         sb.append(getTotalEntries());
314         sb.append(", totalScore=");
315         sb.append(getTotalScore());
316         sb.append(", averageScore=");
317         sb.append(getAverageScore());
318         sb.append("}");
319 
320         return sb.toString();
321     }
322 
323     public String toXmlString() {
324         StringBuilder sb = new StringBuilder();
325 
326         sb.append("<model><model-name>");
327         sb.append("com.liferay.portlet.ratings.model.RatingsStats");
328         sb.append("</model-name>");
329 
330         sb.append(
331             "<column><column-name>statsId</column-name><column-value><![CDATA[");
332         sb.append(getStatsId());
333         sb.append("]]></column-value></column>");
334         sb.append(
335             "<column><column-name>classNameId</column-name><column-value><![CDATA[");
336         sb.append(getClassNameId());
337         sb.append("]]></column-value></column>");
338         sb.append(
339             "<column><column-name>classPK</column-name><column-value><![CDATA[");
340         sb.append(getClassPK());
341         sb.append("]]></column-value></column>");
342         sb.append(
343             "<column><column-name>totalEntries</column-name><column-value><![CDATA[");
344         sb.append(getTotalEntries());
345         sb.append("]]></column-value></column>");
346         sb.append(
347             "<column><column-name>totalScore</column-name><column-value><![CDATA[");
348         sb.append(getTotalScore());
349         sb.append("]]></column-value></column>");
350         sb.append(
351             "<column><column-name>averageScore</column-name><column-value><![CDATA[");
352         sb.append(getAverageScore());
353         sb.append("]]></column-value></column>");
354 
355         sb.append("</model>");
356 
357         return sb.toString();
358     }
359 
360     private long _statsId;
361     private long _classNameId;
362     private long _originalClassNameId;
363     private boolean _setOriginalClassNameId;
364     private long _classPK;
365     private long _originalClassPK;
366     private boolean _setOriginalClassPK;
367     private int _totalEntries;
368     private double _totalScore;
369     private double _averageScore;
370     private transient ExpandoBridge _expandoBridge;
371 }