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.kernel.util.HtmlUtil;
28  import com.liferay.portal.model.impl.BaseModelImpl;
29  import com.liferay.portal.util.PropsUtil;
30  
31  import com.liferay.portlet.polls.model.PollsChoice;
32  import com.liferay.portlet.polls.model.PollsChoiceSoap;
33  
34  import java.io.Serializable;
35  
36  import java.lang.reflect.Proxy;
37  
38  import java.sql.Types;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  /**
44   * <a href="PollsChoiceModelImpl.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>PollsChoice</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portlet.polls.service.model.PollsChoice
59   * @see com.liferay.portlet.polls.service.model.PollsChoiceModel
60   * @see com.liferay.portlet.polls.service.model.impl.PollsChoiceImpl
61   *
62   */
63  public class PollsChoiceModelImpl extends BaseModelImpl {
64      public static final String TABLE_NAME = "PollsChoice";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "uuid_", new Integer(Types.VARCHAR) },
67              
68  
69              { "choiceId", new Integer(Types.BIGINT) },
70              
71  
72              { "questionId", new Integer(Types.BIGINT) },
73              
74  
75              { "name", new Integer(Types.VARCHAR) },
76              
77  
78              { "description", new Integer(Types.VARCHAR) }
79          };
80      public static final String TABLE_SQL_CREATE = "create table PollsChoice (uuid_ VARCHAR(75) null,choiceId LONG not null primary key,questionId LONG,name VARCHAR(75) null,description VARCHAR(1000) null)";
81      public static final String TABLE_SQL_DROP = "drop table PollsChoice";
82      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
83                  "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
84              true);
85  
86      public static PollsChoice toModel(PollsChoiceSoap soapModel) {
87          PollsChoice model = new PollsChoiceImpl();
88  
89          model.setUuid(soapModel.getUuid());
90          model.setChoiceId(soapModel.getChoiceId());
91          model.setQuestionId(soapModel.getQuestionId());
92          model.setName(soapModel.getName());
93          model.setDescription(soapModel.getDescription());
94  
95          return model;
96      }
97  
98      public static List<PollsChoice> toModels(PollsChoiceSoap[] soapModels) {
99          List<PollsChoice> models = new ArrayList<PollsChoice>(soapModels.length);
100 
101         for (PollsChoiceSoap 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.PollsChoice"));
110 
111     public PollsChoiceModelImpl() {
112     }
113 
114     public long getPrimaryKey() {
115         return _choiceId;
116     }
117 
118     public void setPrimaryKey(long pk) {
119         setChoiceId(pk);
120     }
121 
122     public Serializable getPrimaryKeyObj() {
123         return new Long(_choiceId);
124     }
125 
126     public String getUuid() {
127         return GetterUtil.getString(_uuid);
128     }
129 
130     public void setUuid(String uuid) {
131         if ((uuid != null) && (uuid != _uuid)) {
132             _uuid = uuid;
133         }
134     }
135 
136     public long getChoiceId() {
137         return _choiceId;
138     }
139 
140     public void setChoiceId(long choiceId) {
141         if (choiceId != _choiceId) {
142             _choiceId = choiceId;
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 String getName() {
157         return GetterUtil.getString(_name);
158     }
159 
160     public void setName(String name) {
161         if (((name == null) && (_name != null)) ||
162                 ((name != null) && (_name == null)) ||
163                 ((name != null) && (_name != null) && !name.equals(_name))) {
164             _name = name;
165         }
166     }
167 
168     public String getDescription() {
169         return GetterUtil.getString(_description);
170     }
171 
172     public void setDescription(String description) {
173         if (((description == null) && (_description != null)) ||
174                 ((description != null) && (_description == null)) ||
175                 ((description != null) && (_description != null) &&
176                 !description.equals(_description))) {
177             _description = description;
178         }
179     }
180 
181     public PollsChoice toEscapedModel() {
182         if (isEscapedModel()) {
183             return (PollsChoice)this;
184         }
185         else {
186             PollsChoice model = new PollsChoiceImpl();
187 
188             model.setEscapedModel(true);
189 
190             model.setUuid(HtmlUtil.escape(getUuid()));
191             model.setChoiceId(getChoiceId());
192             model.setQuestionId(getQuestionId());
193             model.setName(HtmlUtil.escape(getName()));
194             model.setDescription(HtmlUtil.escape(getDescription()));
195 
196             model = (PollsChoice)Proxy.newProxyInstance(PollsChoice.class.getClassLoader(),
197                     new Class[] { PollsChoice.class },
198                     new ReadOnlyBeanHandler(model));
199 
200             return model;
201         }
202     }
203 
204     public Object clone() {
205         PollsChoiceImpl clone = new PollsChoiceImpl();
206 
207         clone.setUuid(getUuid());
208         clone.setChoiceId(getChoiceId());
209         clone.setQuestionId(getQuestionId());
210         clone.setName(getName());
211         clone.setDescription(getDescription());
212 
213         return clone;
214     }
215 
216     public int compareTo(Object obj) {
217         if (obj == null) {
218             return -1;
219         }
220 
221         PollsChoiceImpl pollsChoice = (PollsChoiceImpl)obj;
222 
223         int value = 0;
224 
225         if (getQuestionId() < pollsChoice.getQuestionId()) {
226             value = -1;
227         }
228         else if (getQuestionId() > pollsChoice.getQuestionId()) {
229             value = 1;
230         }
231         else {
232             value = 0;
233         }
234 
235         if (value != 0) {
236             return value;
237         }
238 
239         value = getName().compareTo(pollsChoice.getName());
240 
241         if (value != 0) {
242             return value;
243         }
244 
245         return 0;
246     }
247 
248     public boolean equals(Object obj) {
249         if (obj == null) {
250             return false;
251         }
252 
253         PollsChoiceImpl pollsChoice = null;
254 
255         try {
256             pollsChoice = (PollsChoiceImpl)obj;
257         }
258         catch (ClassCastException cce) {
259             return false;
260         }
261 
262         long pk = pollsChoice.getPrimaryKey();
263 
264         if (getPrimaryKey() == pk) {
265             return true;
266         }
267         else {
268             return false;
269         }
270     }
271 
272     public int hashCode() {
273         return (int)getPrimaryKey();
274     }
275 
276     private String _uuid;
277     private long _choiceId;
278     private long _questionId;
279     private String _name;
280     private String _description;
281 }