1   /**
2    * Copyright (c) 2000-2008 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.kernel.bean.ReadOnlyBeanHandler;
26  import com.liferay.portal.kernel.util.GetterUtil;
27  import com.liferay.portal.model.impl.BaseModelImpl;
28  import com.liferay.portal.util.PropsUtil;
29  
30  import com.liferay.portlet.polls.model.PollsVote;
31  import com.liferay.portlet.polls.model.PollsVoteSoap;
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.Date;
41  import java.util.List;
42  
43  /**
44   * <a href="PollsVoteModelImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * <p>
47   * ServiceBuilder generated this class. Modifications in this class will be
48   * overwritten the next time is generated.
49   * </p>
50   *
51   * <p>
52   * This class is a model that represents the <code>PollsVote</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portlet.polls.service.model.PollsVote
59   * @see com.liferay.portlet.polls.service.model.PollsVoteModel
60   * @see com.liferay.portlet.polls.service.model.impl.PollsVoteImpl
61   *
62   */
63  public class PollsVoteModelImpl extends BaseModelImpl {
64      public static final String TABLE_NAME = "PollsVote";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "voteId", new Integer(Types.BIGINT) },
67              
68  
69              { "userId", new Integer(Types.BIGINT) },
70              
71  
72              { "questionId", new Integer(Types.BIGINT) },
73              
74  
75              { "choiceId", new Integer(Types.BIGINT) },
76              
77  
78              { "voteDate", new Integer(Types.TIMESTAMP) }
79          };
80      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)";
81      public static final String TABLE_SQL_DROP = "drop table PollsVote";
82      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
83                  "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsVote"),
84              true);
85  
86      public static PollsVote toModel(PollsVoteSoap soapModel) {
87          PollsVote model = new PollsVoteImpl();
88  
89          model.setVoteId(soapModel.getVoteId());
90          model.setUserId(soapModel.getUserId());
91          model.setQuestionId(soapModel.getQuestionId());
92          model.setChoiceId(soapModel.getChoiceId());
93          model.setVoteDate(soapModel.getVoteDate());
94  
95          return model;
96      }
97  
98      public static List<PollsVote> toModels(PollsVoteSoap[] soapModels) {
99          List<PollsVote> models = new ArrayList<PollsVote>(soapModels.length);
100 
101         for (PollsVoteSoap soapModel : soapModels) {
102             models.add(toModel(soapModel));
103         }
104 
105         return models;
106     }
107 
108     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
109                 "lock.expiration.time.com.liferay.portlet.polls.model.PollsVote"));
110 
111     public PollsVoteModelImpl() {
112     }
113 
114     public long getPrimaryKey() {
115         return _voteId;
116     }
117 
118     public void setPrimaryKey(long pk) {
119         setVoteId(pk);
120     }
121 
122     public Serializable getPrimaryKeyObj() {
123         return new Long(_voteId);
124     }
125 
126     public long getVoteId() {
127         return _voteId;
128     }
129 
130     public void setVoteId(long voteId) {
131         if (voteId != _voteId) {
132             _voteId = voteId;
133         }
134     }
135 
136     public long getUserId() {
137         return _userId;
138     }
139 
140     public void setUserId(long userId) {
141         if (userId != _userId) {
142             _userId = userId;
143         }
144     }
145 
146     public long getQuestionId() {
147         return _questionId;
148     }
149 
150     public void setQuestionId(long questionId) {
151         if (questionId != _questionId) {
152             _questionId = questionId;
153         }
154     }
155 
156     public long getChoiceId() {
157         return _choiceId;
158     }
159 
160     public void setChoiceId(long choiceId) {
161         if (choiceId != _choiceId) {
162             _choiceId = choiceId;
163         }
164     }
165 
166     public Date getVoteDate() {
167         return _voteDate;
168     }
169 
170     public void setVoteDate(Date voteDate) {
171         if (((voteDate == null) && (_voteDate != null)) ||
172                 ((voteDate != null) && (_voteDate == null)) ||
173                 ((voteDate != null) && (_voteDate != null) &&
174                 !voteDate.equals(_voteDate))) {
175             _voteDate = voteDate;
176         }
177     }
178 
179     public PollsVote toEscapedModel() {
180         if (isEscapedModel()) {
181             return (PollsVote)this;
182         }
183         else {
184             PollsVote model = new PollsVoteImpl();
185 
186             model.setEscapedModel(true);
187 
188             model.setVoteId(getVoteId());
189             model.setUserId(getUserId());
190             model.setQuestionId(getQuestionId());
191             model.setChoiceId(getChoiceId());
192             model.setVoteDate(getVoteDate());
193 
194             model = (PollsVote)Proxy.newProxyInstance(PollsVote.class.getClassLoader(),
195                     new Class[] { PollsVote.class },
196                     new ReadOnlyBeanHandler(model));
197 
198             return model;
199         }
200     }
201 
202     public Object clone() {
203         PollsVoteImpl clone = new PollsVoteImpl();
204 
205         clone.setVoteId(getVoteId());
206         clone.setUserId(getUserId());
207         clone.setQuestionId(getQuestionId());
208         clone.setChoiceId(getChoiceId());
209         clone.setVoteDate(getVoteDate());
210 
211         return clone;
212     }
213 
214     public int compareTo(Object obj) {
215         if (obj == null) {
216             return -1;
217         }
218 
219         PollsVoteImpl pollsVote = (PollsVoteImpl)obj;
220 
221         long pk = pollsVote.getPrimaryKey();
222 
223         if (getPrimaryKey() < pk) {
224             return -1;
225         }
226         else if (getPrimaryKey() > pk) {
227             return 1;
228         }
229         else {
230             return 0;
231         }
232     }
233 
234     public boolean equals(Object obj) {
235         if (obj == null) {
236             return false;
237         }
238 
239         PollsVoteImpl pollsVote = null;
240 
241         try {
242             pollsVote = (PollsVoteImpl)obj;
243         }
244         catch (ClassCastException cce) {
245             return false;
246         }
247 
248         long pk = pollsVote.getPrimaryKey();
249 
250         if (getPrimaryKey() == pk) {
251             return true;
252         }
253         else {
254             return false;
255         }
256     }
257 
258     public int hashCode() {
259         return (int)getPrimaryKey();
260     }
261 
262     private long _voteId;
263     private long _userId;
264     private long _questionId;
265     private long _choiceId;
266     private Date _voteDate;
267 }