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