001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.StringBundler;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.portal.model.impl.BaseModelImpl;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portal.util.PortalUtil;
025    
026    import com.liferay.portlet.expando.model.ExpandoBridge;
027    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
028    import com.liferay.portlet.shopping.model.ShoppingCategory;
029    import com.liferay.portlet.shopping.model.ShoppingCategoryModel;
030    import com.liferay.portlet.shopping.model.ShoppingCategorySoap;
031    
032    import java.io.Serializable;
033    
034    import java.lang.reflect.Proxy;
035    
036    import java.sql.Types;
037    
038    import java.util.ArrayList;
039    import java.util.Date;
040    import java.util.List;
041    
042    /**
043     * The base model implementation for the ShoppingCategory service. Represents a row in the "ShoppingCategory" database table, with each column mapped to a property of this class.
044     *
045     * <p>
046     * This implementation and its corresponding interface {@link com.liferay.portlet.shopping.model.ShoppingCategoryModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ShoppingCategoryImpl}.
047     * </p>
048     *
049     * <p>
050     * Never modify or reference this class directly. All methods that expect a shopping category model instance should use the {@link com.liferay.portlet.shopping.model.ShoppingCategory} interface instead.
051     * </p>
052     *
053     * @author Brian Wing Shun Chan
054     * @see ShoppingCategoryImpl
055     * @see com.liferay.portlet.shopping.model.ShoppingCategory
056     * @see com.liferay.portlet.shopping.model.ShoppingCategoryModel
057     * @generated
058     */
059    public class ShoppingCategoryModelImpl extends BaseModelImpl<ShoppingCategory>
060            implements ShoppingCategoryModel {
061            public static final String TABLE_NAME = "ShoppingCategory";
062            public static final Object[][] TABLE_COLUMNS = {
063                            { "categoryId", new Integer(Types.BIGINT) },
064                            { "groupId", new Integer(Types.BIGINT) },
065                            { "companyId", new Integer(Types.BIGINT) },
066                            { "userId", new Integer(Types.BIGINT) },
067                            { "userName", new Integer(Types.VARCHAR) },
068                            { "createDate", new Integer(Types.TIMESTAMP) },
069                            { "modifiedDate", new Integer(Types.TIMESTAMP) },
070                            { "parentCategoryId", new Integer(Types.BIGINT) },
071                            { "name", new Integer(Types.VARCHAR) },
072                            { "description", new Integer(Types.VARCHAR) }
073                    };
074            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)";
075            public static final String TABLE_SQL_DROP = "drop table ShoppingCategory";
076            public static final String ORDER_BY_JPQL = " ORDER BY shoppingCategory.parentCategoryId ASC, shoppingCategory.name ASC";
077            public static final String ORDER_BY_SQL = " ORDER BY ShoppingCategory.parentCategoryId ASC, ShoppingCategory.name ASC";
078            public static final String DATA_SOURCE = "liferayDataSource";
079            public static final String SESSION_FACTORY = "liferaySessionFactory";
080            public static final String TX_MANAGER = "liferayTransactionManager";
081            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.entity.cache.enabled.com.liferay.portlet.shopping.model.ShoppingCategory"),
083                            true);
084            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
085                                    "value.object.finder.cache.enabled.com.liferay.portlet.shopping.model.ShoppingCategory"),
086                            true);
087    
088            /**
089             * Converts the soap model instance into a normal model instance.
090             *
091             * @param soapModel the soap model instance to convert
092             * @return the normal model instance
093             */
094            public static ShoppingCategory toModel(ShoppingCategorySoap soapModel) {
095                    ShoppingCategory model = new ShoppingCategoryImpl();
096    
097                    model.setCategoryId(soapModel.getCategoryId());
098                    model.setGroupId(soapModel.getGroupId());
099                    model.setCompanyId(soapModel.getCompanyId());
100                    model.setUserId(soapModel.getUserId());
101                    model.setUserName(soapModel.getUserName());
102                    model.setCreateDate(soapModel.getCreateDate());
103                    model.setModifiedDate(soapModel.getModifiedDate());
104                    model.setParentCategoryId(soapModel.getParentCategoryId());
105                    model.setName(soapModel.getName());
106                    model.setDescription(soapModel.getDescription());
107    
108                    return model;
109            }
110    
111            /**
112             * Converts the soap model instances into normal model instances.
113             *
114             * @param soapModels the soap model instances to convert
115             * @return the normal model instances
116             */
117            public static List<ShoppingCategory> toModels(
118                    ShoppingCategorySoap[] soapModels) {
119                    List<ShoppingCategory> models = new ArrayList<ShoppingCategory>(soapModels.length);
120    
121                    for (ShoppingCategorySoap soapModel : soapModels) {
122                            models.add(toModel(soapModel));
123                    }
124    
125                    return models;
126            }
127    
128            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
129                                    "lock.expiration.time.com.liferay.portlet.shopping.model.ShoppingCategory"));
130    
131            public ShoppingCategoryModelImpl() {
132            }
133    
134            public long getPrimaryKey() {
135                    return _categoryId;
136            }
137    
138            public void setPrimaryKey(long pk) {
139                    setCategoryId(pk);
140            }
141    
142            public Serializable getPrimaryKeyObj() {
143                    return new Long(_categoryId);
144            }
145    
146            public long getCategoryId() {
147                    return _categoryId;
148            }
149    
150            public void setCategoryId(long categoryId) {
151                    _categoryId = categoryId;
152            }
153    
154            public long getGroupId() {
155                    return _groupId;
156            }
157    
158            public void setGroupId(long groupId) {
159                    _groupId = groupId;
160            }
161    
162            public long getCompanyId() {
163                    return _companyId;
164            }
165    
166            public void setCompanyId(long companyId) {
167                    _companyId = companyId;
168            }
169    
170            public long getUserId() {
171                    return _userId;
172            }
173    
174            public void setUserId(long userId) {
175                    _userId = userId;
176            }
177    
178            public String getUserUuid() throws SystemException {
179                    return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
180            }
181    
182            public void setUserUuid(String userUuid) {
183                    _userUuid = userUuid;
184            }
185    
186            public String getUserName() {
187                    if (_userName == null) {
188                            return StringPool.BLANK;
189                    }
190                    else {
191                            return _userName;
192                    }
193            }
194    
195            public void setUserName(String userName) {
196                    _userName = userName;
197            }
198    
199            public Date getCreateDate() {
200                    return _createDate;
201            }
202    
203            public void setCreateDate(Date createDate) {
204                    _createDate = createDate;
205            }
206    
207            public Date getModifiedDate() {
208                    return _modifiedDate;
209            }
210    
211            public void setModifiedDate(Date modifiedDate) {
212                    _modifiedDate = modifiedDate;
213            }
214    
215            public long getParentCategoryId() {
216                    return _parentCategoryId;
217            }
218    
219            public void setParentCategoryId(long parentCategoryId) {
220                    _parentCategoryId = parentCategoryId;
221            }
222    
223            public String getName() {
224                    if (_name == null) {
225                            return StringPool.BLANK;
226                    }
227                    else {
228                            return _name;
229                    }
230            }
231    
232            public void setName(String name) {
233                    _name = name;
234            }
235    
236            public String getDescription() {
237                    if (_description == null) {
238                            return StringPool.BLANK;
239                    }
240                    else {
241                            return _description;
242                    }
243            }
244    
245            public void setDescription(String description) {
246                    _description = description;
247            }
248    
249            public ShoppingCategory toEscapedModel() {
250                    if (isEscapedModel()) {
251                            return (ShoppingCategory)this;
252                    }
253                    else {
254                            return (ShoppingCategory)Proxy.newProxyInstance(ShoppingCategory.class.getClassLoader(),
255                                    new Class[] { ShoppingCategory.class },
256                                    new AutoEscapeBeanHandler(this));
257                    }
258            }
259    
260            public ExpandoBridge getExpandoBridge() {
261                    if (_expandoBridge == null) {
262                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
263                                            ShoppingCategory.class.getName(), getPrimaryKey());
264                    }
265    
266                    return _expandoBridge;
267            }
268    
269            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
270                    getExpandoBridge().setAttributes(serviceContext);
271            }
272    
273            public Object clone() {
274                    ShoppingCategoryImpl shoppingCategoryImpl = new ShoppingCategoryImpl();
275    
276                    shoppingCategoryImpl.setCategoryId(getCategoryId());
277    
278                    shoppingCategoryImpl.setGroupId(getGroupId());
279    
280                    shoppingCategoryImpl.setCompanyId(getCompanyId());
281    
282                    shoppingCategoryImpl.setUserId(getUserId());
283    
284                    shoppingCategoryImpl.setUserName(getUserName());
285    
286                    shoppingCategoryImpl.setCreateDate(getCreateDate());
287    
288                    shoppingCategoryImpl.setModifiedDate(getModifiedDate());
289    
290                    shoppingCategoryImpl.setParentCategoryId(getParentCategoryId());
291    
292                    shoppingCategoryImpl.setName(getName());
293    
294                    shoppingCategoryImpl.setDescription(getDescription());
295    
296                    return shoppingCategoryImpl;
297            }
298    
299            public int compareTo(ShoppingCategory shoppingCategory) {
300                    int value = 0;
301    
302                    if (getParentCategoryId() < shoppingCategory.getParentCategoryId()) {
303                            value = -1;
304                    }
305                    else if (getParentCategoryId() > shoppingCategory.getParentCategoryId()) {
306                            value = 1;
307                    }
308                    else {
309                            value = 0;
310                    }
311    
312                    if (value != 0) {
313                            return value;
314                    }
315    
316                    value = getName().toLowerCase()
317                                            .compareTo(shoppingCategory.getName().toLowerCase());
318    
319                    if (value != 0) {
320                            return value;
321                    }
322    
323                    return 0;
324            }
325    
326            public boolean equals(Object obj) {
327                    if (obj == null) {
328                            return false;
329                    }
330    
331                    ShoppingCategory shoppingCategory = null;
332    
333                    try {
334                            shoppingCategory = (ShoppingCategory)obj;
335                    }
336                    catch (ClassCastException cce) {
337                            return false;
338                    }
339    
340                    long pk = shoppingCategory.getPrimaryKey();
341    
342                    if (getPrimaryKey() == pk) {
343                            return true;
344                    }
345                    else {
346                            return false;
347                    }
348            }
349    
350            public int hashCode() {
351                    return (int)getPrimaryKey();
352            }
353    
354            public String toString() {
355                    StringBundler sb = new StringBundler(21);
356    
357                    sb.append("{categoryId=");
358                    sb.append(getCategoryId());
359                    sb.append(", groupId=");
360                    sb.append(getGroupId());
361                    sb.append(", companyId=");
362                    sb.append(getCompanyId());
363                    sb.append(", userId=");
364                    sb.append(getUserId());
365                    sb.append(", userName=");
366                    sb.append(getUserName());
367                    sb.append(", createDate=");
368                    sb.append(getCreateDate());
369                    sb.append(", modifiedDate=");
370                    sb.append(getModifiedDate());
371                    sb.append(", parentCategoryId=");
372                    sb.append(getParentCategoryId());
373                    sb.append(", name=");
374                    sb.append(getName());
375                    sb.append(", description=");
376                    sb.append(getDescription());
377                    sb.append("}");
378    
379                    return sb.toString();
380            }
381    
382            public String toXmlString() {
383                    StringBundler sb = new StringBundler(34);
384    
385                    sb.append("<model><model-name>");
386                    sb.append("com.liferay.portlet.shopping.model.ShoppingCategory");
387                    sb.append("</model-name>");
388    
389                    sb.append(
390                            "<column><column-name>categoryId</column-name><column-value><![CDATA[");
391                    sb.append(getCategoryId());
392                    sb.append("]]></column-value></column>");
393                    sb.append(
394                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
395                    sb.append(getGroupId());
396                    sb.append("]]></column-value></column>");
397                    sb.append(
398                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
399                    sb.append(getCompanyId());
400                    sb.append("]]></column-value></column>");
401                    sb.append(
402                            "<column><column-name>userId</column-name><column-value><![CDATA[");
403                    sb.append(getUserId());
404                    sb.append("]]></column-value></column>");
405                    sb.append(
406                            "<column><column-name>userName</column-name><column-value><![CDATA[");
407                    sb.append(getUserName());
408                    sb.append("]]></column-value></column>");
409                    sb.append(
410                            "<column><column-name>createDate</column-name><column-value><![CDATA[");
411                    sb.append(getCreateDate());
412                    sb.append("]]></column-value></column>");
413                    sb.append(
414                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
415                    sb.append(getModifiedDate());
416                    sb.append("]]></column-value></column>");
417                    sb.append(
418                            "<column><column-name>parentCategoryId</column-name><column-value><![CDATA[");
419                    sb.append(getParentCategoryId());
420                    sb.append("]]></column-value></column>");
421                    sb.append(
422                            "<column><column-name>name</column-name><column-value><![CDATA[");
423                    sb.append(getName());
424                    sb.append("]]></column-value></column>");
425                    sb.append(
426                            "<column><column-name>description</column-name><column-value><![CDATA[");
427                    sb.append(getDescription());
428                    sb.append("]]></column-value></column>");
429    
430                    sb.append("</model>");
431    
432                    return sb.toString();
433            }
434    
435            private long _categoryId;
436            private long _groupId;
437            private long _companyId;
438            private long _userId;
439            private String _userUuid;
440            private String _userName;
441            private Date _createDate;
442            private Date _modifiedDate;
443            private long _parentCategoryId;
444            private String _name;
445            private String _description;
446            private transient ExpandoBridge _expandoBridge;
447    }