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