1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.polls.model.impl;
21  
22  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
23  import com.liferay.portal.kernel.util.GetterUtil;
24  import com.liferay.portal.kernel.util.HtmlUtil;
25  import com.liferay.portal.model.impl.BaseModelImpl;
26  
27  import com.liferay.portlet.polls.model.PollsChoice;
28  import com.liferay.portlet.polls.model.PollsChoiceSoap;
29  
30  import java.io.Serializable;
31  
32  import java.lang.reflect.Proxy;
33  
34  import java.sql.Types;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  /**
40   * <a href="PollsChoiceModelImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * <p>
43   * ServiceBuilder generated this class. Modifications in this class will be
44   * overwritten the next time is generated.
45   * </p>
46   *
47   * <p>
48   * This class is a model that represents the <code>PollsChoice</code> table
49   * in the database.
50   * </p>
51   *
52   * @author Brian Wing Shun Chan
53   *
54   * @see com.liferay.portlet.polls.model.PollsChoice
55   * @see com.liferay.portlet.polls.model.PollsChoiceModel
56   * @see com.liferay.portlet.polls.model.impl.PollsChoiceImpl
57   *
58   */
59  public class PollsChoiceModelImpl extends BaseModelImpl {
60      public static final String TABLE_NAME = "PollsChoice";
61      public static final Object[][] TABLE_COLUMNS = {
62              { "uuid_", new Integer(Types.VARCHAR) },
63              
64  
65              { "choiceId", new Integer(Types.BIGINT) },
66              
67  
68              { "questionId", new Integer(Types.BIGINT) },
69              
70  
71              { "name", new Integer(Types.VARCHAR) },
72              
73  
74              { "description", new Integer(Types.VARCHAR) }
75          };
76      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)";
77      public static final String TABLE_SQL_DROP = "drop table PollsChoice";
78      public static final String DATA_SOURCE = "liferayDataSource";
79      public static final String SESSION_FACTORY = "liferaySessionFactory";
80      public static final String TX_MANAGER = "liferayTransactionManager";
81      public static final boolean 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         if ((uuid != null) && (uuid != _uuid)) {
131             _uuid = uuid;
132         }
133     }
134 
135     public long getChoiceId() {
136         return _choiceId;
137     }
138 
139     public void setChoiceId(long choiceId) {
140         if (choiceId != _choiceId) {
141             _choiceId = choiceId;
142         }
143     }
144 
145     public long getQuestionId() {
146         return _questionId;
147     }
148 
149     public void setQuestionId(long questionId) {
150         if (questionId != _questionId) {
151             _questionId = questionId;
152         }
153     }
154 
155     public String getName() {
156         return GetterUtil.getString(_name);
157     }
158 
159     public void setName(String name) {
160         if (((name == null) && (_name != null)) ||
161                 ((name != null) && (_name == null)) ||
162                 ((name != null) && (_name != null) && !name.equals(_name))) {
163             _name = name;
164         }
165     }
166 
167     public String getDescription() {
168         return GetterUtil.getString(_description);
169     }
170 
171     public void setDescription(String description) {
172         if (((description == null) && (_description != null)) ||
173                 ((description != null) && (_description == null)) ||
174                 ((description != null) && (_description != null) &&
175                 !description.equals(_description))) {
176             _description = description;
177         }
178     }
179 
180     public PollsChoice toEscapedModel() {
181         if (isEscapedModel()) {
182             return (PollsChoice)this;
183         }
184         else {
185             PollsChoice model = new PollsChoiceImpl();
186 
187             model.setNew(isNew());
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 }