1   /**
2    * Copyright (c) 2000-2007 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.util.GetterUtil;
26  import com.liferay.portal.model.impl.BaseModelImpl;
27  import com.liferay.portal.util.PropsUtil;
28  
29  import com.liferay.util.XSSUtil;
30  
31  import java.io.Serializable;
32  
33  import java.sql.Types;
34  
35  /**
36   * <a href="PollsChoiceModelImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * <p>
39   * ServiceBuilder generated this class. Modifications in this class will be overwritten
40   * the next time is generated.
41   * </p>
42   *
43   * <p>
44   * This class is a model that represents the <code>PollsChoice</code> table in the
45   * database.
46   * </p>
47   *
48   * @author Brian Wing Shun Chan
49   *
50   * @see com.liferay.portlet.polls.service.model.PollsChoice
51   * @see com.liferay.portlet.polls.service.model.PollsChoiceModel
52   * @see com.liferay.portlet.polls.service.model.impl.PollsChoiceImpl
53   *
54   */
55  public class PollsChoiceModelImpl extends BaseModelImpl {
56      public static String TABLE_NAME = "PollsChoice";
57      public static Object[][] TABLE_COLUMNS = {
58              { "choiceId", new Integer(Types.BIGINT) },
59              { "questionId", new Integer(Types.BIGINT) },
60              { "name", new Integer(Types.VARCHAR) },
61              { "description", new Integer(Types.VARCHAR) }
62          };
63      public static String TABLE_SQL_CREATE = "create table PollsChoice (choiceId LONG not null primary key,questionId LONG,name VARCHAR(75) null,description VARCHAR(1000) null)";
64      public static String TABLE_SQL_DROP = "drop table PollsChoice";
65      public static boolean XSS_ALLOW_BY_MODEL = GetterUtil.getBoolean(PropsUtil.get(
66                  "xss.allow.com.liferay.portlet.polls.model.PollsChoice"),
67              XSS_ALLOW);
68      public static boolean XSS_ALLOW_NAME = GetterUtil.getBoolean(PropsUtil.get(
69                  "xss.allow.com.liferay.portlet.polls.model.PollsChoice.name"),
70              XSS_ALLOW_BY_MODEL);
71      public static boolean XSS_ALLOW_DESCRIPTION = GetterUtil.getBoolean(PropsUtil.get(
72                  "xss.allow.com.liferay.portlet.polls.model.PollsChoice.description"),
73              XSS_ALLOW_BY_MODEL);
74      public static long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
75                  "lock.expiration.time.com.liferay.portlet.polls.model.PollsChoiceModel"));
76  
77      public PollsChoiceModelImpl() {
78      }
79  
80      public long getPrimaryKey() {
81          return _choiceId;
82      }
83  
84      public void setPrimaryKey(long pk) {
85          setChoiceId(pk);
86      }
87  
88      public Serializable getPrimaryKeyObj() {
89          return new Long(_choiceId);
90      }
91  
92      public long getChoiceId() {
93          return _choiceId;
94      }
95  
96      public void setChoiceId(long choiceId) {
97          if (choiceId != _choiceId) {
98              _choiceId = choiceId;
99          }
100     }
101 
102     public long getQuestionId() {
103         return _questionId;
104     }
105 
106     public void setQuestionId(long questionId) {
107         if (questionId != _questionId) {
108             _questionId = questionId;
109         }
110     }
111 
112     public String getName() {
113         return GetterUtil.getString(_name);
114     }
115 
116     public void setName(String name) {
117         if (((name == null) && (_name != null)) ||
118                 ((name != null) && (_name == null)) ||
119                 ((name != null) && (_name != null) && !name.equals(_name))) {
120             if (!XSS_ALLOW_NAME) {
121                 name = XSSUtil.strip(name);
122             }
123 
124             _name = name;
125         }
126     }
127 
128     public String getDescription() {
129         return GetterUtil.getString(_description);
130     }
131 
132     public void setDescription(String description) {
133         if (((description == null) && (_description != null)) ||
134                 ((description != null) && (_description == null)) ||
135                 ((description != null) && (_description != null) &&
136                 !description.equals(_description))) {
137             if (!XSS_ALLOW_DESCRIPTION) {
138                 description = XSSUtil.strip(description);
139             }
140 
141             _description = description;
142         }
143     }
144 
145     public Object clone() {
146         PollsChoiceImpl clone = new PollsChoiceImpl();
147         clone.setChoiceId(getChoiceId());
148         clone.setQuestionId(getQuestionId());
149         clone.setName(getName());
150         clone.setDescription(getDescription());
151 
152         return clone;
153     }
154 
155     public int compareTo(Object obj) {
156         if (obj == null) {
157             return -1;
158         }
159 
160         PollsChoiceImpl pollsChoice = (PollsChoiceImpl)obj;
161         int value = 0;
162 
163         if (getQuestionId() < pollsChoice.getQuestionId()) {
164             value = -1;
165         }
166         else if (getQuestionId() > pollsChoice.getQuestionId()) {
167             value = 1;
168         }
169         else {
170             value = 0;
171         }
172 
173         if (value != 0) {
174             return value;
175         }
176 
177         value = getName().compareTo(pollsChoice.getName());
178 
179         if (value != 0) {
180             return value;
181         }
182 
183         return 0;
184     }
185 
186     public boolean equals(Object obj) {
187         if (obj == null) {
188             return false;
189         }
190 
191         PollsChoiceImpl pollsChoice = null;
192 
193         try {
194             pollsChoice = (PollsChoiceImpl)obj;
195         }
196         catch (ClassCastException cce) {
197             return false;
198         }
199 
200         long pk = pollsChoice.getPrimaryKey();
201 
202         if (getPrimaryKey() == pk) {
203             return true;
204         }
205         else {
206             return false;
207         }
208     }
209 
210     public int hashCode() {
211         return (int)getPrimaryKey();
212     }
213 
214     private long _choiceId;
215     private long _questionId;
216     private String _name;
217     private String _description;
218 }