1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.service.ServiceContext;
30  
31  import com.liferay.portlet.expando.model.ExpandoBridge;
32  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
33  import com.liferay.portlet.polls.model.PollsChoice;
34  import com.liferay.portlet.polls.model.PollsChoiceSoap;
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.List;
44  
45  /**
46   * <a href="PollsChoiceModelImpl.java.html"><b><i>View Source</i></b></a>
47   *
48   * <p>
49   * ServiceBuilder generated this class. Modifications in this class will be
50   * overwritten the next time is generated.
51   * </p>
52   *
53   * <p>
54   * This interface is a model that represents the PollsChoice table in the
55   * database.
56   * </p>
57   *
58   * @author    Brian Wing Shun Chan
59   * @see       PollsChoiceImpl
60   * @see       com.liferay.portlet.polls.model.PollsChoice
61   * @see       com.liferay.portlet.polls.model.PollsChoiceModel
62   * @generated
63   */
64  public class PollsChoiceModelImpl extends BaseModelImpl<PollsChoice> {
65      public static final String TABLE_NAME = "PollsChoice";
66      public static final Object[][] TABLE_COLUMNS = {
67              { "uuid_", new Integer(Types.VARCHAR) },
68              { "choiceId", new Integer(Types.BIGINT) },
69              { "questionId", new Integer(Types.BIGINT) },
70              { "name", new Integer(Types.VARCHAR) },
71              { "description", new Integer(Types.VARCHAR) }
72          };
73      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)";
74      public static final String TABLE_SQL_DROP = "drop table PollsChoice";
75      public static final String DATA_SOURCE = "liferayDataSource";
76      public static final String SESSION_FACTORY = "liferaySessionFactory";
77      public static final String TX_MANAGER = "liferayTransactionManager";
78      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
79                  "value.object.entity.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
80              true);
81      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
82                  "value.object.finder.cache.enabled.com.liferay.portlet.polls.model.PollsChoice"),
83              true);
84  
85      public static PollsChoice toModel(PollsChoiceSoap soapModel) {
86          PollsChoice model = new PollsChoiceImpl();
87  
88          model.setUuid(soapModel.getUuid());
89          model.setChoiceId(soapModel.getChoiceId());
90          model.setQuestionId(soapModel.getQuestionId());
91          model.setName(soapModel.getName());
92          model.setDescription(soapModel.getDescription());
93  
94          return model;
95      }
96  
97      public static List<PollsChoice> toModels(PollsChoiceSoap[] soapModels) {
98          List<PollsChoice> models = new ArrayList<PollsChoice>(soapModels.length);
99  
100         for (PollsChoiceSoap soapModel : soapModels) {
101             models.add(toModel(soapModel));
102         }
103 
104         return models;
105     }
106 
107     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
108                 "lock.expiration.time.com.liferay.portlet.polls.model.PollsChoice"));
109 
110     public PollsChoiceModelImpl() {
111     }
112 
113     public long getPrimaryKey() {
114         return _choiceId;
115     }
116 
117     public void setPrimaryKey(long pk) {
118         setChoiceId(pk);
119     }
120 
121     public Serializable getPrimaryKeyObj() {
122         return new Long(_choiceId);
123     }
124 
125     public String getUuid() {
126         return GetterUtil.getString(_uuid);
127     }
128 
129     public void setUuid(String uuid) {
130         _uuid = uuid;
131     }
132 
133     public long getChoiceId() {
134         return _choiceId;
135     }
136 
137     public void setChoiceId(long choiceId) {
138         _choiceId = choiceId;
139     }
140 
141     public long getQuestionId() {
142         return _questionId;
143     }
144 
145     public void setQuestionId(long questionId) {
146         _questionId = questionId;
147 
148         if (!_setOriginalQuestionId) {
149             _setOriginalQuestionId = true;
150 
151             _originalQuestionId = questionId;
152         }
153     }
154 
155     public long getOriginalQuestionId() {
156         return _originalQuestionId;
157     }
158 
159     public String getName() {
160         return GetterUtil.getString(_name);
161     }
162 
163     public void setName(String name) {
164         _name = name;
165 
166         if (_originalName == null) {
167             _originalName = name;
168         }
169     }
170 
171     public String getOriginalName() {
172         return GetterUtil.getString(_originalName);
173     }
174 
175     public String getDescription() {
176         return GetterUtil.getString(_description);
177     }
178 
179     public void setDescription(String description) {
180         _description = description;
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 ExpandoBridge getExpandoBridge() {
208         if (_expandoBridge == null) {
209             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(PollsChoice.class.getName(),
210                     getPrimaryKey());
211         }
212 
213         return _expandoBridge;
214     }
215 
216     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
217         getExpandoBridge().setAttributes(serviceContext);
218     }
219 
220     public Object clone() {
221         PollsChoiceImpl clone = new PollsChoiceImpl();
222 
223         clone.setUuid(getUuid());
224         clone.setChoiceId(getChoiceId());
225         clone.setQuestionId(getQuestionId());
226         clone.setName(getName());
227         clone.setDescription(getDescription());
228 
229         return clone;
230     }
231 
232     public int compareTo(PollsChoice pollsChoice) {
233         int value = 0;
234 
235         if (getQuestionId() < pollsChoice.getQuestionId()) {
236             value = -1;
237         }
238         else if (getQuestionId() > pollsChoice.getQuestionId()) {
239             value = 1;
240         }
241         else {
242             value = 0;
243         }
244 
245         if (value != 0) {
246             return value;
247         }
248 
249         value = getName().compareTo(pollsChoice.getName());
250 
251         if (value != 0) {
252             return value;
253         }
254 
255         return 0;
256     }
257 
258     public boolean equals(Object obj) {
259         if (obj == null) {
260             return false;
261         }
262 
263         PollsChoice pollsChoice = null;
264 
265         try {
266             pollsChoice = (PollsChoice)obj;
267         }
268         catch (ClassCastException cce) {
269             return false;
270         }
271 
272         long pk = pollsChoice.getPrimaryKey();
273 
274         if (getPrimaryKey() == pk) {
275             return true;
276         }
277         else {
278             return false;
279         }
280     }
281 
282     public int hashCode() {
283         return (int)getPrimaryKey();
284     }
285 
286     public String toString() {
287         StringBuilder sb = new StringBuilder();
288 
289         sb.append("{uuid=");
290         sb.append(getUuid());
291         sb.append(", choiceId=");
292         sb.append(getChoiceId());
293         sb.append(", questionId=");
294         sb.append(getQuestionId());
295         sb.append(", name=");
296         sb.append(getName());
297         sb.append(", description=");
298         sb.append(getDescription());
299         sb.append("}");
300 
301         return sb.toString();
302     }
303 
304     public String toXmlString() {
305         StringBuilder sb = new StringBuilder();
306 
307         sb.append("<model><model-name>");
308         sb.append("com.liferay.portlet.polls.model.PollsChoice");
309         sb.append("</model-name>");
310 
311         sb.append(
312             "<column><column-name>uuid</column-name><column-value><![CDATA[");
313         sb.append(getUuid());
314         sb.append("]]></column-value></column>");
315         sb.append(
316             "<column><column-name>choiceId</column-name><column-value><![CDATA[");
317         sb.append(getChoiceId());
318         sb.append("]]></column-value></column>");
319         sb.append(
320             "<column><column-name>questionId</column-name><column-value><![CDATA[");
321         sb.append(getQuestionId());
322         sb.append("]]></column-value></column>");
323         sb.append(
324             "<column><column-name>name</column-name><column-value><![CDATA[");
325         sb.append(getName());
326         sb.append("]]></column-value></column>");
327         sb.append(
328             "<column><column-name>description</column-name><column-value><![CDATA[");
329         sb.append(getDescription());
330         sb.append("]]></column-value></column>");
331 
332         sb.append("</model>");
333 
334         return sb.toString();
335     }
336 
337     private String _uuid;
338     private long _choiceId;
339     private long _questionId;
340     private long _originalQuestionId;
341     private boolean _setOriginalQuestionId;
342     private String _name;
343     private String _originalName;
344     private String _description;
345     private transient ExpandoBridge _expandoBridge;
346 }