1   /**
2    * Copyright (c) 2000-2008 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.model.impl.BaseModelImpl;
28  import com.liferay.portal.util.PortalUtil;
29  import com.liferay.portal.util.PropsUtil;
30  
31  import com.liferay.portlet.ratings.model.RatingsStats;
32  import com.liferay.portlet.ratings.model.RatingsStatsSoap;
33  
34  import java.io.Serializable;
35  
36  import java.lang.reflect.Proxy;
37  
38  import java.sql.Types;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  /**
44   * <a href="RatingsStatsModelImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * <p>
47   * ServiceBuilder generated this class. Modifications in this class will be
48   * overwritten the next time is generated.
49   * </p>
50   *
51   * <p>
52   * This class is a model that represents the <code>RatingsStats</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portlet.ratings.service.model.RatingsStats
59   * @see com.liferay.portlet.ratings.service.model.RatingsStatsModel
60   * @see com.liferay.portlet.ratings.service.model.impl.RatingsStatsImpl
61   *
62   */
63  public class RatingsStatsModelImpl extends BaseModelImpl {
64      public static final String TABLE_NAME = "RatingsStats";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "statsId", new Integer(Types.BIGINT) },
67              
68  
69              { "classNameId", new Integer(Types.BIGINT) },
70              
71  
72              { "classPK", new Integer(Types.BIGINT) },
73              
74  
75              { "totalEntries", new Integer(Types.INTEGER) },
76              
77  
78              { "totalScore", new Integer(Types.DOUBLE) },
79              
80  
81              { "averageScore", new Integer(Types.DOUBLE) }
82          };
83      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)";
84      public static final String TABLE_SQL_DROP = "drop table RatingsStats";
85      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
86                  "value.object.finder.cache.enabled.com.liferay.portlet.ratings.model.RatingsStats"),
87              true);
88  
89      public static RatingsStats toModel(RatingsStatsSoap soapModel) {
90          RatingsStats model = new RatingsStatsImpl();
91  
92          model.setStatsId(soapModel.getStatsId());
93          model.setClassNameId(soapModel.getClassNameId());
94          model.setClassPK(soapModel.getClassPK());
95          model.setTotalEntries(soapModel.getTotalEntries());
96          model.setTotalScore(soapModel.getTotalScore());
97          model.setAverageScore(soapModel.getAverageScore());
98  
99          return model;
100     }
101 
102     public static List<RatingsStats> toModels(RatingsStatsSoap[] soapModels) {
103         List<RatingsStats> models = new ArrayList<RatingsStats>(soapModels.length);
104 
105         for (RatingsStatsSoap soapModel : soapModels) {
106             models.add(toModel(soapModel));
107         }
108 
109         return models;
110     }
111 
112     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
113                 "lock.expiration.time.com.liferay.portlet.ratings.model.RatingsStats"));
114 
115     public RatingsStatsModelImpl() {
116     }
117 
118     public long getPrimaryKey() {
119         return _statsId;
120     }
121 
122     public void setPrimaryKey(long pk) {
123         setStatsId(pk);
124     }
125 
126     public Serializable getPrimaryKeyObj() {
127         return new Long(_statsId);
128     }
129 
130     public long getStatsId() {
131         return _statsId;
132     }
133 
134     public void setStatsId(long statsId) {
135         if (statsId != _statsId) {
136             _statsId = statsId;
137         }
138     }
139 
140     public String getClassName() {
141         return PortalUtil.getClassName(getClassNameId());
142     }
143 
144     public long getClassNameId() {
145         return _classNameId;
146     }
147 
148     public void setClassNameId(long classNameId) {
149         if (classNameId != _classNameId) {
150             _classNameId = classNameId;
151         }
152     }
153 
154     public long getClassPK() {
155         return _classPK;
156     }
157 
158     public void setClassPK(long classPK) {
159         if (classPK != _classPK) {
160             _classPK = classPK;
161         }
162     }
163 
164     public int getTotalEntries() {
165         return _totalEntries;
166     }
167 
168     public void setTotalEntries(int totalEntries) {
169         if (totalEntries != _totalEntries) {
170             _totalEntries = totalEntries;
171         }
172     }
173 
174     public double getTotalScore() {
175         return _totalScore;
176     }
177 
178     public void setTotalScore(double totalScore) {
179         if (totalScore != _totalScore) {
180             _totalScore = totalScore;
181         }
182     }
183 
184     public double getAverageScore() {
185         return _averageScore;
186     }
187 
188     public void setAverageScore(double averageScore) {
189         if (averageScore != _averageScore) {
190             _averageScore = averageScore;
191         }
192     }
193 
194     public RatingsStats toEscapedModel() {
195         if (isEscapedModel()) {
196             return (RatingsStats)this;
197         }
198         else {
199             RatingsStats model = new RatingsStatsImpl();
200 
201             model.setEscapedModel(true);
202 
203             model.setStatsId(getStatsId());
204             model.setClassNameId(getClassNameId());
205             model.setClassPK(getClassPK());
206             model.setTotalEntries(getTotalEntries());
207             model.setTotalScore(getTotalScore());
208             model.setAverageScore(getAverageScore());
209 
210             model = (RatingsStats)Proxy.newProxyInstance(RatingsStats.class.getClassLoader(),
211                     new Class[] { RatingsStats.class },
212                     new ReadOnlyBeanHandler(model));
213 
214             return model;
215         }
216     }
217 
218     public Object clone() {
219         RatingsStatsImpl clone = new RatingsStatsImpl();
220 
221         clone.setStatsId(getStatsId());
222         clone.setClassNameId(getClassNameId());
223         clone.setClassPK(getClassPK());
224         clone.setTotalEntries(getTotalEntries());
225         clone.setTotalScore(getTotalScore());
226         clone.setAverageScore(getAverageScore());
227 
228         return clone;
229     }
230 
231     public int compareTo(Object obj) {
232         if (obj == null) {
233             return -1;
234         }
235 
236         RatingsStatsImpl ratingsStats = (RatingsStatsImpl)obj;
237 
238         long pk = ratingsStats.getPrimaryKey();
239 
240         if (getPrimaryKey() < pk) {
241             return -1;
242         }
243         else if (getPrimaryKey() > pk) {
244             return 1;
245         }
246         else {
247             return 0;
248         }
249     }
250 
251     public boolean equals(Object obj) {
252         if (obj == null) {
253             return false;
254         }
255 
256         RatingsStatsImpl ratingsStats = null;
257 
258         try {
259             ratingsStats = (RatingsStatsImpl)obj;
260         }
261         catch (ClassCastException cce) {
262             return false;
263         }
264 
265         long pk = ratingsStats.getPrimaryKey();
266 
267         if (getPrimaryKey() == pk) {
268             return true;
269         }
270         else {
271             return false;
272         }
273     }
274 
275     public int hashCode() {
276         return (int)getPrimaryKey();
277     }
278 
279     private long _statsId;
280     private long _classNameId;
281     private long _classPK;
282     private int _totalEntries;
283     private double _totalScore;
284     private double _averageScore;
285 }