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