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