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