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