1   /**
2    * Copyright (c) 2000-2009 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.polls.model.impl;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
27  import com.liferay.portal.kernel.util.GetterUtil;
28  import com.liferay.portal.model.impl.BaseModelImpl;
29  import com.liferay.portal.util.PortalUtil;
30  
31  import com.liferay.portlet.expando.model.ExpandoBridge;
32  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
33  import com.liferay.portlet.polls.model.PollsVote;
34  import com.liferay.portlet.polls.model.PollsVoteSoap;
35  
36  import java.io.Serializable;
37  
38  import java.lang.reflect.Proxy;
39  
40  import java.sql.Types;
41  
42  import java.util.ArrayList;
43  import java.util.Date;
44  import java.util.List;
45  
46  /**
47   * <a href="PollsVoteModelImpl.java.html"><b><i>View Source</i></b></a>
48   *
49   * <p>
50   * ServiceBuilder generated this class. Modifications in this class will be
51   * overwritten the next time is generated.
52   * </p>
53   *
54   * <p>
55   * This class is a model that represents the <code>PollsVote</code> table
56   * in the database.
57   * </p>
58   *
59   * @author Brian Wing Shun Chan
60   *
61   * @see com.liferay.portlet.polls.model.PollsVote
62   * @see com.liferay.portlet.polls.model.PollsVoteModel
63   * @see com.liferay.portlet.polls.model.impl.PollsVoteImpl
64   *
65   */
66  public class PollsVoteModelImpl extends BaseModelImpl<PollsVote> {
67      public static final String TABLE_NAME = "PollsVote";
68      public static final Object[][] TABLE_COLUMNS = {
69              { "voteId", new Integer(Types.BIGINT) },
70              
71  
72              { "userId", new Integer(Types.BIGINT) },
73              
74  
75              { "questionId", new Integer(Types.BIGINT) },
76              
77  
78              { "choiceId", new Integer(Types.BIGINT) },
79              
80  
81              { "voteDate", new Integer(Types.TIMESTAMP) }
82          };
83      public static final String TABLE_SQL_CREATE = "create table PollsVote (voteId LONG not null primary key,userId LONG,questionId LONG,choiceId LONG,voteDate DATE null)";
84      public static final String TABLE_SQL_DROP = "drop table PollsVote";
85      public static final String DATA_SOURCE = "liferayDataSource";
86      public static final String SESSION_FACTORY = "liferaySessionFactory";
87      public static final String TX_MANAGER = "liferayTransactionManager";
88      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
89                  "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsVote"),
90              true);
91      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
92                  "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsVote"),
93              true);
94  
95      public static PollsVote toModel(PollsVoteSoap soapModel) {
96          PollsVote model = new PollsVoteImpl();
97  
98          model.setVoteId(soapModel.getVoteId());
99          model.setUserId(soapModel.getUserId());
100         model.setQuestionId(soapModel.getQuestionId());
101         model.setChoiceId(soapModel.getChoiceId());
102         model.setVoteDate(soapModel.getVoteDate());
103 
104         return model;
105     }
106 
107     public static List<PollsVote> toModels(PollsVoteSoap[] soapModels) {
108         List<PollsVote> models = new ArrayList<PollsVote>(soapModels.length);
109 
110         for (PollsVoteSoap 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.polls.model.PollsVote"));
119 
120     public PollsVoteModelImpl() {
121     }
122 
123     public long getPrimaryKey() {
124         return _voteId;
125     }
126 
127     public void setPrimaryKey(long pk) {
128         setVoteId(pk);
129     }
130 
131     public Serializable getPrimaryKeyObj() {
132         return new Long(_voteId);
133     }
134 
135     public long getVoteId() {
136         return _voteId;
137     }
138 
139     public void setVoteId(long voteId) {
140         _voteId = voteId;
141     }
142 
143     public long getUserId() {
144         return _userId;
145     }
146 
147     public void setUserId(long userId) {
148         _userId = userId;
149 
150         if (!_setOriginalUserId) {
151             _setOriginalUserId = true;
152 
153             _originalUserId = userId;
154         }
155     }
156 
157     public String getUserUuid() throws SystemException {
158         return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
159     }
160 
161     public void setUserUuid(String userUuid) {
162         _userUuid = userUuid;
163     }
164 
165     public long getOriginalUserId() {
166         return _originalUserId;
167     }
168 
169     public long getQuestionId() {
170         return _questionId;
171     }
172 
173     public void setQuestionId(long questionId) {
174         _questionId = questionId;
175 
176         if (!_setOriginalQuestionId) {
177             _setOriginalQuestionId = true;
178 
179             _originalQuestionId = questionId;
180         }
181     }
182 
183     public long getOriginalQuestionId() {
184         return _originalQuestionId;
185     }
186 
187     public long getChoiceId() {
188         return _choiceId;
189     }
190 
191     public void setChoiceId(long choiceId) {
192         _choiceId = choiceId;
193     }
194 
195     public Date getVoteDate() {
196         return _voteDate;
197     }
198 
199     public void setVoteDate(Date voteDate) {
200         _voteDate = voteDate;
201     }
202 
203     public PollsVote toEscapedModel() {
204         if (isEscapedModel()) {
205             return (PollsVote)this;
206         }
207         else {
208             PollsVote model = new PollsVoteImpl();
209 
210             model.setNew(isNew());
211             model.setEscapedModel(true);
212 
213             model.setVoteId(getVoteId());
214             model.setUserId(getUserId());
215             model.setQuestionId(getQuestionId());
216             model.setChoiceId(getChoiceId());
217             model.setVoteDate(getVoteDate());
218 
219             model = (PollsVote)Proxy.newProxyInstance(PollsVote.class.getClassLoader(),
220                     new Class[] { PollsVote.class },
221                     new ReadOnlyBeanHandler(model));
222 
223             return model;
224         }
225     }
226 
227     public ExpandoBridge getExpandoBridge() {
228         if (_expandoBridge == null) {
229             _expandoBridge = new ExpandoBridgeImpl(PollsVote.class.getName(),
230                     getPrimaryKey());
231         }
232 
233         return _expandoBridge;
234     }
235 
236     public Object clone() {
237         PollsVoteImpl clone = new PollsVoteImpl();
238 
239         clone.setVoteId(getVoteId());
240         clone.setUserId(getUserId());
241         clone.setQuestionId(getQuestionId());
242         clone.setChoiceId(getChoiceId());
243         clone.setVoteDate(getVoteDate());
244 
245         return clone;
246     }
247 
248     public int compareTo(PollsVote pollsVote) {
249         long pk = pollsVote.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         PollsVote pollsVote = null;
268 
269         try {
270             pollsVote = (PollsVote)obj;
271         }
272         catch (ClassCastException cce) {
273             return false;
274         }
275 
276         long pk = pollsVote.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         StringBuilder sb = new StringBuilder();
292 
293         sb.append("{voteId=");
294         sb.append(getVoteId());
295         sb.append(", userId=");
296         sb.append(getUserId());
297         sb.append(", questionId=");
298         sb.append(getQuestionId());
299         sb.append(", choiceId=");
300         sb.append(getChoiceId());
301         sb.append(", voteDate=");
302         sb.append(getVoteDate());
303         sb.append("}");
304 
305         return sb.toString();
306     }
307 
308     public String toXmlString() {
309         StringBuilder sb = new StringBuilder();
310 
311         sb.append("<model><model-name>");
312         sb.append("com.liferay.portlet.polls.model.PollsVote");
313         sb.append("</model-name>");
314 
315         sb.append(
316             "<column><column-name>voteId</column-name><column-value><![CDATA[");
317         sb.append(getVoteId());
318         sb.append("]]></column-value></column>");
319         sb.append(
320             "<column><column-name>userId</column-name><column-value><![CDATA[");
321         sb.append(getUserId());
322         sb.append("]]></column-value></column>");
323         sb.append(
324             "<column><column-name>questionId</column-name><column-value><![CDATA[");
325         sb.append(getQuestionId());
326         sb.append("]]></column-value></column>");
327         sb.append(
328             "<column><column-name>choiceId</column-name><column-value><![CDATA[");
329         sb.append(getChoiceId());
330         sb.append("]]></column-value></column>");
331         sb.append(
332             "<column><column-name>voteDate</column-name><column-value><![CDATA[");
333         sb.append(getVoteDate());
334         sb.append("]]></column-value></column>");
335 
336         sb.append("</model>");
337 
338         return sb.toString();
339     }
340 
341     private long _voteId;
342     private long _userId;
343     private String _userUuid;
344     private long _originalUserId;
345     private boolean _setOriginalUserId;
346     private long _questionId;
347     private long _originalQuestionId;
348     private boolean _setOriginalQuestionId;
349     private long _choiceId;
350     private Date _voteDate;
351     private transient ExpandoBridge _expandoBridge;
352 }