1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.ratings.model.impl;
16  
17  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.StringBundler;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.model.impl.BaseModelImpl;
22  import com.liferay.portal.service.ServiceContext;
23  import com.liferay.portal.util.PortalUtil;
24  
25  import com.liferay.portlet.expando.model.ExpandoBridge;
26  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
27  import com.liferay.portlet.ratings.model.RatingsStats;
28  import com.liferay.portlet.ratings.model.RatingsStatsSoap;
29  
30  import java.io.Serializable;
31  
32  import java.lang.reflect.Proxy;
33  
34  import java.sql.Types;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  /**
40   * <a href="RatingsStatsModelImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * <p>
43   * ServiceBuilder generated this class. Modifications in this class will be
44   * overwritten the next time is generated.
45   * </p>
46   *
47   * <p>
48   * This interface is a model that represents the RatingsStats table in the
49   * database.
50   * </p>
51   *
52   * @author    Brian Wing Shun Chan
53   * @see       RatingsStatsImpl
54   * @see       com.liferay.portlet.ratings.model.RatingsStats
55   * @see       com.liferay.portlet.ratings.model.RatingsStatsModel
56   * @generated
57   */
58  public class RatingsStatsModelImpl extends BaseModelImpl<RatingsStats> {
59      public static final String TABLE_NAME = "RatingsStats";
60      public static final Object[][] TABLE_COLUMNS = {
61              { "statsId", new Integer(Types.BIGINT) },
62              { "classNameId", new Integer(Types.BIGINT) },
63              { "classPK", new Integer(Types.BIGINT) },
64              { "totalEntries", new Integer(Types.INTEGER) },
65              { "totalScore", new Integer(Types.DOUBLE) },
66              { "averageScore", new Integer(Types.DOUBLE) }
67          };
68      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)";
69      public static final String TABLE_SQL_DROP = "drop table RatingsStats";
70      public static final String DATA_SOURCE = "liferayDataSource";
71      public static final String SESSION_FACTORY = "liferaySessionFactory";
72      public static final String TX_MANAGER = "liferayTransactionManager";
73      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
74                  "value.object.entity.cache.enabled.com.liferay.portlet.ratings.model.RatingsStats"),
75              true);
76      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
77                  "value.object.finder.cache.enabled.com.liferay.portlet.ratings.model.RatingsStats"),
78              true);
79  
80      public static RatingsStats toModel(RatingsStatsSoap soapModel) {
81          RatingsStats model = new RatingsStatsImpl();
82  
83          model.setStatsId(soapModel.getStatsId());
84          model.setClassNameId(soapModel.getClassNameId());
85          model.setClassPK(soapModel.getClassPK());
86          model.setTotalEntries(soapModel.getTotalEntries());
87          model.setTotalScore(soapModel.getTotalScore());
88          model.setAverageScore(soapModel.getAverageScore());
89  
90          return model;
91      }
92  
93      public static List<RatingsStats> toModels(RatingsStatsSoap[] soapModels) {
94          List<RatingsStats> models = new ArrayList<RatingsStats>(soapModels.length);
95  
96          for (RatingsStatsSoap soapModel : soapModels) {
97              models.add(toModel(soapModel));
98          }
99  
100         return models;
101     }
102 
103     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
104                 "lock.expiration.time.com.liferay.portlet.ratings.model.RatingsStats"));
105 
106     public RatingsStatsModelImpl() {
107     }
108 
109     public long getPrimaryKey() {
110         return _statsId;
111     }
112 
113     public void setPrimaryKey(long pk) {
114         setStatsId(pk);
115     }
116 
117     public Serializable getPrimaryKeyObj() {
118         return new Long(_statsId);
119     }
120 
121     public long getStatsId() {
122         return _statsId;
123     }
124 
125     public void setStatsId(long statsId) {
126         _statsId = statsId;
127     }
128 
129     public String getClassName() {
130         if (getClassNameId() <= 0) {
131             return StringPool.BLANK;
132         }
133 
134         return PortalUtil.getClassName(getClassNameId());
135     }
136 
137     public long getClassNameId() {
138         return _classNameId;
139     }
140 
141     public void setClassNameId(long classNameId) {
142         _classNameId = classNameId;
143 
144         if (!_setOriginalClassNameId) {
145             _setOriginalClassNameId = true;
146 
147             _originalClassNameId = classNameId;
148         }
149     }
150 
151     public long getOriginalClassNameId() {
152         return _originalClassNameId;
153     }
154 
155     public long getClassPK() {
156         return _classPK;
157     }
158 
159     public void setClassPK(long classPK) {
160         _classPK = classPK;
161 
162         if (!_setOriginalClassPK) {
163             _setOriginalClassPK = true;
164 
165             _originalClassPK = classPK;
166         }
167     }
168 
169     public long getOriginalClassPK() {
170         return _originalClassPK;
171     }
172 
173     public int getTotalEntries() {
174         return _totalEntries;
175     }
176 
177     public void setTotalEntries(int totalEntries) {
178         _totalEntries = totalEntries;
179     }
180 
181     public double getTotalScore() {
182         return _totalScore;
183     }
184 
185     public void setTotalScore(double totalScore) {
186         _totalScore = totalScore;
187     }
188 
189     public double getAverageScore() {
190         return _averageScore;
191     }
192 
193     public void setAverageScore(double averageScore) {
194         _averageScore = averageScore;
195     }
196 
197     public RatingsStats toEscapedModel() {
198         if (isEscapedModel()) {
199             return (RatingsStats)this;
200         }
201         else {
202             RatingsStats model = new RatingsStatsImpl();
203 
204             model.setNew(isNew());
205             model.setEscapedModel(true);
206 
207             model.setStatsId(getStatsId());
208             model.setClassNameId(getClassNameId());
209             model.setClassPK(getClassPK());
210             model.setTotalEntries(getTotalEntries());
211             model.setTotalScore(getTotalScore());
212             model.setAverageScore(getAverageScore());
213 
214             model = (RatingsStats)Proxy.newProxyInstance(RatingsStats.class.getClassLoader(),
215                     new Class[] { RatingsStats.class },
216                     new ReadOnlyBeanHandler(model));
217 
218             return model;
219         }
220     }
221 
222     public ExpandoBridge getExpandoBridge() {
223         if (_expandoBridge == null) {
224             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
225                     RatingsStats.class.getName(), getPrimaryKey());
226         }
227 
228         return _expandoBridge;
229     }
230 
231     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
232         getExpandoBridge().setAttributes(serviceContext);
233     }
234 
235     public Object clone() {
236         RatingsStatsImpl clone = new RatingsStatsImpl();
237 
238         clone.setStatsId(getStatsId());
239         clone.setClassNameId(getClassNameId());
240         clone.setClassPK(getClassPK());
241         clone.setTotalEntries(getTotalEntries());
242         clone.setTotalScore(getTotalScore());
243         clone.setAverageScore(getAverageScore());
244 
245         return clone;
246     }
247 
248     public int compareTo(RatingsStats ratingsStats) {
249         long pk = ratingsStats.getPrimaryKey();
250 
251         if (getPrimaryKey() < pk) {
252             return -1;
253         }
254         else if (getPrimaryKey() > pk) {
255             return 1;
256         }
257         else {
258             return 0;
259         }
260     }
261 
262     public boolean equals(Object obj) {
263         if (obj == null) {
264             return false;
265         }
266 
267         RatingsStats ratingsStats = null;
268 
269         try {
270             ratingsStats = (RatingsStats)obj;
271         }
272         catch (ClassCastException cce) {
273             return false;
274         }
275 
276         long pk = ratingsStats.getPrimaryKey();
277 
278         if (getPrimaryKey() == pk) {
279             return true;
280         }
281         else {
282             return false;
283         }
284     }
285 
286     public int hashCode() {
287         return (int)getPrimaryKey();
288     }
289 
290     public String toString() {
291         StringBundler sb = new StringBundler(13);
292 
293         sb.append("{statsId=");
294         sb.append(getStatsId());
295         sb.append(", classNameId=");
296         sb.append(getClassNameId());
297         sb.append(", classPK=");
298         sb.append(getClassPK());
299         sb.append(", totalEntries=");
300         sb.append(getTotalEntries());
301         sb.append(", totalScore=");
302         sb.append(getTotalScore());
303         sb.append(", averageScore=");
304         sb.append(getAverageScore());
305         sb.append("}");
306 
307         return sb.toString();
308     }
309 
310     public String toXmlString() {
311         StringBundler sb = new StringBundler(22);
312 
313         sb.append("<model><model-name>");
314         sb.append("com.liferay.portlet.ratings.model.RatingsStats");
315         sb.append("</model-name>");
316 
317         sb.append(
318             "<column><column-name>statsId</column-name><column-value><![CDATA[");
319         sb.append(getStatsId());
320         sb.append("]]></column-value></column>");
321         sb.append(
322             "<column><column-name>classNameId</column-name><column-value><![CDATA[");
323         sb.append(getClassNameId());
324         sb.append("]]></column-value></column>");
325         sb.append(
326             "<column><column-name>classPK</column-name><column-value><![CDATA[");
327         sb.append(getClassPK());
328         sb.append("]]></column-value></column>");
329         sb.append(
330             "<column><column-name>totalEntries</column-name><column-value><![CDATA[");
331         sb.append(getTotalEntries());
332         sb.append("]]></column-value></column>");
333         sb.append(
334             "<column><column-name>totalScore</column-name><column-value><![CDATA[");
335         sb.append(getTotalScore());
336         sb.append("]]></column-value></column>");
337         sb.append(
338             "<column><column-name>averageScore</column-name><column-value><![CDATA[");
339         sb.append(getAverageScore());
340         sb.append("]]></column-value></column>");
341 
342         sb.append("</model>");
343 
344         return sb.toString();
345     }
346 
347     private long _statsId;
348     private long _classNameId;
349     private long _originalClassNameId;
350     private boolean _setOriginalClassNameId;
351     private long _classPK;
352     private long _originalClassPK;
353     private boolean _setOriginalClassPK;
354     private int _totalEntries;
355     private double _totalScore;
356     private double _averageScore;
357     private transient ExpandoBridge _expandoBridge;
358 }