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.shopping.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.shopping.model.ShoppingCategory;
28  import com.liferay.portlet.shopping.model.ShoppingCategorySoap;
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.Date;
38  import java.util.List;
39  
40  /**
41   * <a href="ShoppingCategoryModelImpl.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>ShoppingCategory</code> table
50   * in the database.
51   * </p>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   * @see com.liferay.portlet.shopping.model.ShoppingCategory
56   * @see com.liferay.portlet.shopping.model.ShoppingCategoryModel
57   * @see com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl
58   *
59   */
60  public class ShoppingCategoryModelImpl extends BaseModelImpl {
61      public static final String TABLE_NAME = "ShoppingCategory";
62      public static final Object[][] TABLE_COLUMNS = {
63              { "categoryId", new Integer(Types.BIGINT) },
64              
65  
66              { "groupId", new Integer(Types.BIGINT) },
67              
68  
69              { "companyId", new Integer(Types.BIGINT) },
70              
71  
72              { "userId", new Integer(Types.BIGINT) },
73              
74  
75              { "userName", new Integer(Types.VARCHAR) },
76              
77  
78              { "createDate", new Integer(Types.TIMESTAMP) },
79              
80  
81              { "modifiedDate", new Integer(Types.TIMESTAMP) },
82              
83  
84              { "parentCategoryId", new Integer(Types.BIGINT) },
85              
86  
87              { "name", new Integer(Types.VARCHAR) },
88              
89  
90              { "description", new Integer(Types.VARCHAR) }
91          };
92      public static final String TABLE_SQL_CREATE = "create table ShoppingCategory (categoryId LONG not null primary key,groupId LONG,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,modifiedDate DATE null,parentCategoryId LONG,name VARCHAR(75) null,description STRING null)";
93      public static final String TABLE_SQL_DROP = "drop table ShoppingCategory";
94      public static final String DATA_SOURCE = "liferayDataSource";
95      public static final String SESSION_FACTORY = "liferaySessionFactory";
96      public static final String TX_MANAGER = "liferayTransactionManager";
97      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
98                  "value.object.finder.cache.enabled.com.liferay.portlet.shopping.model.ShoppingCategory"),
99              true);
100 
101     public static ShoppingCategory toModel(ShoppingCategorySoap soapModel) {
102         ShoppingCategory model = new ShoppingCategoryImpl();
103 
104         model.setCategoryId(soapModel.getCategoryId());
105         model.setGroupId(soapModel.getGroupId());
106         model.setCompanyId(soapModel.getCompanyId());
107         model.setUserId(soapModel.getUserId());
108         model.setUserName(soapModel.getUserName());
109         model.setCreateDate(soapModel.getCreateDate());
110         model.setModifiedDate(soapModel.getModifiedDate());
111         model.setParentCategoryId(soapModel.getParentCategoryId());
112         model.setName(soapModel.getName());
113         model.setDescription(soapModel.getDescription());
114 
115         return model;
116     }
117 
118     public static List<ShoppingCategory> toModels(
119         ShoppingCategorySoap[] soapModels) {
120         List<ShoppingCategory> models = new ArrayList<ShoppingCategory>(soapModels.length);
121 
122         for (ShoppingCategorySoap soapModel : soapModels) {
123             models.add(toModel(soapModel));
124         }
125 
126         return models;
127     }
128 
129     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
130                 "lock.expiration.time.com.liferay.portlet.shopping.model.ShoppingCategory"));
131 
132     public ShoppingCategoryModelImpl() {
133     }
134 
135     public long getPrimaryKey() {
136         return _categoryId;
137     }
138 
139     public void setPrimaryKey(long pk) {
140         setCategoryId(pk);
141     }
142 
143     public Serializable getPrimaryKeyObj() {
144         return new Long(_categoryId);
145     }
146 
147     public long getCategoryId() {
148         return _categoryId;
149     }
150 
151     public void setCategoryId(long categoryId) {
152         if (categoryId != _categoryId) {
153             _categoryId = categoryId;
154         }
155     }
156 
157     public long getGroupId() {
158         return _groupId;
159     }
160 
161     public void setGroupId(long groupId) {
162         if (groupId != _groupId) {
163             _groupId = groupId;
164         }
165     }
166 
167     public long getCompanyId() {
168         return _companyId;
169     }
170 
171     public void setCompanyId(long companyId) {
172         if (companyId != _companyId) {
173             _companyId = companyId;
174         }
175     }
176 
177     public long getUserId() {
178         return _userId;
179     }
180 
181     public void setUserId(long userId) {
182         if (userId != _userId) {
183             _userId = userId;
184         }
185     }
186 
187     public String getUserName() {
188         return GetterUtil.getString(_userName);
189     }
190 
191     public void setUserName(String userName) {
192         if (((userName == null) && (_userName != null)) ||
193                 ((userName != null) && (_userName == null)) ||
194                 ((userName != null) && (_userName != null) &&
195                 !userName.equals(_userName))) {
196             _userName = userName;
197         }
198     }
199 
200     public Date getCreateDate() {
201         return _createDate;
202     }
203 
204     public void setCreateDate(Date createDate) {
205         if (((createDate == null) && (_createDate != null)) ||
206                 ((createDate != null) && (_createDate == null)) ||
207                 ((createDate != null) && (_createDate != null) &&
208                 !createDate.equals(_createDate))) {
209             _createDate = createDate;
210         }
211     }
212 
213     public Date getModifiedDate() {
214         return _modifiedDate;
215     }
216 
217     public void setModifiedDate(Date modifiedDate) {
218         if (((modifiedDate == null) && (_modifiedDate != null)) ||
219                 ((modifiedDate != null) && (_modifiedDate == null)) ||
220                 ((modifiedDate != null) && (_modifiedDate != null) &&
221                 !modifiedDate.equals(_modifiedDate))) {
222             _modifiedDate = modifiedDate;
223         }
224     }
225 
226     public long getParentCategoryId() {
227         return _parentCategoryId;
228     }
229 
230     public void setParentCategoryId(long parentCategoryId) {
231         if (parentCategoryId != _parentCategoryId) {
232             _parentCategoryId = parentCategoryId;
233         }
234     }
235 
236     public String getName() {
237         return GetterUtil.getString(_name);
238     }
239 
240     public void setName(String name) {
241         if (((name == null) && (_name != null)) ||
242                 ((name != null) && (_name == null)) ||
243                 ((name != null) && (_name != null) && !name.equals(_name))) {
244             _name = name;
245         }
246     }
247 
248     public String getDescription() {
249         return GetterUtil.getString(_description);
250     }
251 
252     public void setDescription(String description) {
253         if (((description == null) && (_description != null)) ||
254                 ((description != null) && (_description == null)) ||
255                 ((description != null) && (_description != null) &&
256                 !description.equals(_description))) {
257             _description = description;
258         }
259     }
260 
261     public ShoppingCategory toEscapedModel() {
262         if (isEscapedModel()) {
263             return (ShoppingCategory)this;
264         }
265         else {
266             ShoppingCategory model = new ShoppingCategoryImpl();
267 
268             model.setNew(isNew());
269             model.setEscapedModel(true);
270 
271             model.setCategoryId(getCategoryId());
272             model.setGroupId(getGroupId());
273             model.setCompanyId(getCompanyId());
274             model.setUserId(getUserId());
275             model.setUserName(HtmlUtil.escape(getUserName()));
276             model.setCreateDate(getCreateDate());
277             model.setModifiedDate(getModifiedDate());
278             model.setParentCategoryId(getParentCategoryId());
279             model.setName(HtmlUtil.escape(getName()));
280             model.setDescription(HtmlUtil.escape(getDescription()));
281 
282             model = (ShoppingCategory)Proxy.newProxyInstance(ShoppingCategory.class.getClassLoader(),
283                     new Class[] { ShoppingCategory.class },
284                     new ReadOnlyBeanHandler(model));
285 
286             return model;
287         }
288     }
289 
290     public Object clone() {
291         ShoppingCategoryImpl clone = new ShoppingCategoryImpl();
292 
293         clone.setCategoryId(getCategoryId());
294         clone.setGroupId(getGroupId());
295         clone.setCompanyId(getCompanyId());
296         clone.setUserId(getUserId());
297         clone.setUserName(getUserName());
298         clone.setCreateDate(getCreateDate());
299         clone.setModifiedDate(getModifiedDate());
300         clone.setParentCategoryId(getParentCategoryId());
301         clone.setName(getName());
302         clone.setDescription(getDescription());
303 
304         return clone;
305     }
306 
307     public int compareTo(Object obj) {
308         if (obj == null) {
309             return -1;
310         }
311 
312         ShoppingCategoryImpl shoppingCategory = (ShoppingCategoryImpl)obj;
313 
314         int value = 0;
315 
316         if (getParentCategoryId() < shoppingCategory.getParentCategoryId()) {
317             value = -1;
318         }
319         else if (getParentCategoryId() > shoppingCategory.getParentCategoryId()) {
320             value = 1;
321         }
322         else {
323             value = 0;
324         }
325 
326         if (value != 0) {
327             return value;
328         }
329 
330         value = getName().toLowerCase()
331                     .compareTo(shoppingCategory.getName().toLowerCase());
332 
333         if (value != 0) {
334             return value;
335         }
336 
337         return 0;
338     }
339 
340     public boolean equals(Object obj) {
341         if (obj == null) {
342             return false;
343         }
344 
345         ShoppingCategoryImpl shoppingCategory = null;
346 
347         try {
348             shoppingCategory = (ShoppingCategoryImpl)obj;
349         }
350         catch (ClassCastException cce) {
351             return false;
352         }
353 
354         long pk = shoppingCategory.getPrimaryKey();
355 
356         if (getPrimaryKey() == pk) {
357             return true;
358         }
359         else {
360             return false;
361         }
362     }
363 
364     public int hashCode() {
365         return (int)getPrimaryKey();
366     }
367 
368     private long _categoryId;
369     private long _groupId;
370     private long _companyId;
371     private long _userId;
372     private String _userName;
373     private Date _createDate;
374     private Date _modifiedDate;
375     private long _parentCategoryId;
376     private String _name;
377     private String _description;
378 }