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