1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.ratings.model.impl;
21  
22  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
23  import com.liferay.portal.kernel.util.GetterUtil;
24  import com.liferay.portal.kernel.util.StringPool;
25  import com.liferay.portal.model.impl.BaseModelImpl;
26  import com.liferay.portal.util.PortalUtil;
27  
28  import com.liferay.portlet.ratings.model.RatingsStats;
29  import com.liferay.portlet.ratings.model.RatingsStatsSoap;
30  
31  import java.io.Serializable;
32  
33  import java.lang.reflect.Proxy;
34  
35  import java.sql.Types;
36  
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  /**
41   * <a href="RatingsStatsModelImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * <p>
44   * ServiceBuilder generated this class. Modifications in this class will be
45   * overwritten the next time is generated.
46   * </p>
47   *
48   * <p>
49   * This class is a model that represents the <code>RatingsStats</code> table
50   * in the database.
51   * </p>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   * @see com.liferay.portlet.ratings.model.RatingsStats
56   * @see com.liferay.portlet.ratings.model.RatingsStatsModel
57   * @see com.liferay.portlet.ratings.model.impl.RatingsStatsImpl
58   *
59   */
60  public class RatingsStatsModelImpl extends BaseModelImpl {
61      public static final String TABLE_NAME = "RatingsStats";
62      public static final Object[][] TABLE_COLUMNS = {
63              { "statsId", new Integer(Types.BIGINT) },
64              
65  
66              { "classNameId", new Integer(Types.BIGINT) },
67              
68  
69              { "classPK", new Integer(Types.BIGINT) },
70              
71  
72              { "totalEntries", new Integer(Types.INTEGER) },
73              
74  
75              { "totalScore", new Integer(Types.DOUBLE) },
76              
77  
78              { "averageScore", new Integer(Types.DOUBLE) }
79          };
80      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)";
81      public static final String TABLE_SQL_DROP = "drop table RatingsStats";
82      public static final String DATA_SOURCE = "liferayDataSource";
83      public static final String SESSION_FACTORY = "liferaySessionFactory";
84      public static final String TX_MANAGER = "liferayTransactionManager";
85      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.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(com.liferay.portal.util.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         if (getClassNameId() <= 0) {
142             return StringPool.BLANK;
143         }
144 
145         return PortalUtil.getClassName(getClassNameId());
146     }
147 
148     public long getClassNameId() {
149         return _classNameId;
150     }
151 
152     public void setClassNameId(long classNameId) {
153         if (classNameId != _classNameId) {
154             _classNameId = classNameId;
155         }
156     }
157 
158     public long getClassPK() {
159         return _classPK;
160     }
161 
162     public void setClassPK(long classPK) {
163         if (classPK != _classPK) {
164             _classPK = classPK;
165         }
166     }
167 
168     public int getTotalEntries() {
169         return _totalEntries;
170     }
171 
172     public void setTotalEntries(int totalEntries) {
173         if (totalEntries != _totalEntries) {
174             _totalEntries = totalEntries;
175         }
176     }
177 
178     public double getTotalScore() {
179         return _totalScore;
180     }
181 
182     public void setTotalScore(double totalScore) {
183         if (totalScore != _totalScore) {
184             _totalScore = totalScore;
185         }
186     }
187 
188     public double getAverageScore() {
189         return _averageScore;
190     }
191 
192     public void setAverageScore(double averageScore) {
193         if (averageScore != _averageScore) {
194             _averageScore = averageScore;
195         }
196     }
197 
198     public RatingsStats toEscapedModel() {
199         if (isEscapedModel()) {
200             return (RatingsStats)this;
201         }
202         else {
203             RatingsStats model = new RatingsStatsImpl();
204 
205             model.setNew(isNew());
206             model.setEscapedModel(true);
207 
208             model.setStatsId(getStatsId());
209             model.setClassNameId(getClassNameId());
210             model.setClassPK(getClassPK());
211             model.setTotalEntries(getTotalEntries());
212             model.setTotalScore(getTotalScore());
213             model.setAverageScore(getAverageScore());
214 
215             model = (RatingsStats)Proxy.newProxyInstance(RatingsStats.class.getClassLoader(),
216                     new Class[] { RatingsStats.class },
217                     new ReadOnlyBeanHandler(model));
218 
219             return model;
220         }
221     }
222 
223     public Object clone() {
224         RatingsStatsImpl clone = new RatingsStatsImpl();
225 
226         clone.setStatsId(getStatsId());
227         clone.setClassNameId(getClassNameId());
228         clone.setClassPK(getClassPK());
229         clone.setTotalEntries(getTotalEntries());
230         clone.setTotalScore(getTotalScore());
231         clone.setAverageScore(getAverageScore());
232 
233         return clone;
234     }
235 
236     public int compareTo(Object obj) {
237         if (obj == null) {
238             return -1;
239         }
240 
241         RatingsStatsImpl ratingsStats = (RatingsStatsImpl)obj;
242 
243         long pk = ratingsStats.getPrimaryKey();
244 
245         if (getPrimaryKey() < pk) {
246             return -1;
247         }
248         else if (getPrimaryKey() > pk) {
249             return 1;
250         }
251         else {
252             return 0;
253         }
254     }
255 
256     public boolean equals(Object obj) {
257         if (obj == null) {
258             return false;
259         }
260 
261         RatingsStatsImpl ratingsStats = null;
262 
263         try {
264             ratingsStats = (RatingsStatsImpl)obj;
265         }
266         catch (ClassCastException cce) {
267             return false;
268         }
269 
270         long pk = ratingsStats.getPrimaryKey();
271 
272         if (getPrimaryKey() == pk) {
273             return true;
274         }
275         else {
276             return false;
277         }
278     }
279 
280     public int hashCode() {
281         return (int)getPrimaryKey();
282     }
283 
284     private long _statsId;
285     private long _classNameId;
286     private long _classPK;
287     private int _totalEntries;
288     private double _totalScore;
289     private double _averageScore;
290 }