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.json.JSON;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.kernel.util.ProxyUtil;
022    import com.liferay.portal.kernel.util.StringBundler;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portal.model.CacheModel;
025    import com.liferay.portal.model.impl.BaseModelImpl;
026    import com.liferay.portal.service.ServiceContext;
027    import com.liferay.portal.util.PortalUtil;
028    
029    import com.liferay.portlet.expando.model.ExpandoBridge;
030    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
031    import com.liferay.portlet.shopping.model.ShoppingCategory;
032    import com.liferay.portlet.shopping.model.ShoppingCategoryModel;
033    import com.liferay.portlet.shopping.model.ShoppingCategorySoap;
034    
035    import java.io.Serializable;
036    
037    import java.sql.Types;
038    
039    import java.util.ArrayList;
040    import java.util.Date;
041    import java.util.List;
042    
043    /**
044     * 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.
045     *
046     * <p>
047     * 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}.
048     * </p>
049     *
050     * @author Brian Wing Shun Chan
051     * @see ShoppingCategoryImpl
052     * @see com.liferay.portlet.shopping.model.ShoppingCategory
053     * @see com.liferay.portlet.shopping.model.ShoppingCategoryModel
054     * @generated
055     */
056    @JSON(strict = true)
057    public class ShoppingCategoryModelImpl extends BaseModelImpl<ShoppingCategory>
058            implements ShoppingCategoryModel {
059            /*
060             * NOTE FOR DEVELOPERS:
061             *
062             * 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.
063             */
064            public static final String TABLE_NAME = "ShoppingCategory";
065            public static final Object[][] TABLE_COLUMNS = {
066                            { "categoryId", Types.BIGINT },
067                            { "groupId", Types.BIGINT },
068                            { "companyId", Types.BIGINT },
069                            { "userId", Types.BIGINT },
070                            { "userName", Types.VARCHAR },
071                            { "createDate", Types.TIMESTAMP },
072                            { "modifiedDate", Types.TIMESTAMP },
073                            { "parentCategoryId", Types.BIGINT },
074                            { "name", Types.VARCHAR },
075                            { "description", Types.VARCHAR }
076                    };
077            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)";
078            public static final String TABLE_SQL_DROP = "drop table ShoppingCategory";
079            public static final String ORDER_BY_JPQL = " ORDER BY shoppingCategory.parentCategoryId ASC, shoppingCategory.name ASC";
080            public static final String ORDER_BY_SQL = " ORDER BY ShoppingCategory.parentCategoryId ASC, ShoppingCategory.name ASC";
081            public static final String DATA_SOURCE = "liferayDataSource";
082            public static final String SESSION_FACTORY = "liferaySessionFactory";
083            public static final String TX_MANAGER = "liferayTransactionManager";
084            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
085                                    "value.object.entity.cache.enabled.com.liferay.portlet.shopping.model.ShoppingCategory"),
086                            true);
087            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
088                                    "value.object.finder.cache.enabled.com.liferay.portlet.shopping.model.ShoppingCategory"),
089                            true);
090            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
091                                    "value.object.column.bitmask.enabled.com.liferay.portlet.shopping.model.ShoppingCategory"),
092                            true);
093            public static long GROUPID_COLUMN_BITMASK = 1L;
094            public static long PARENTCATEGORYID_COLUMN_BITMASK = 2L;
095    
096            /**
097             * Converts the soap model instance into a normal model instance.
098             *
099             * @param soapModel the soap model instance to convert
100             * @return the normal model instance
101             */
102            public static ShoppingCategory toModel(ShoppingCategorySoap soapModel) {
103                    ShoppingCategory model = new ShoppingCategoryImpl();
104    
105                    model.setCategoryId(soapModel.getCategoryId());
106                    model.setGroupId(soapModel.getGroupId());
107                    model.setCompanyId(soapModel.getCompanyId());
108                    model.setUserId(soapModel.getUserId());
109                    model.setUserName(soapModel.getUserName());
110                    model.setCreateDate(soapModel.getCreateDate());
111                    model.setModifiedDate(soapModel.getModifiedDate());
112                    model.setParentCategoryId(soapModel.getParentCategoryId());
113                    model.setName(soapModel.getName());
114                    model.setDescription(soapModel.getDescription());
115    
116                    return model;
117            }
118    
119            /**
120             * Converts the soap model instances into normal model instances.
121             *
122             * @param soapModels the soap model instances to convert
123             * @return the normal model instances
124             */
125            public static List<ShoppingCategory> toModels(
126                    ShoppingCategorySoap[] soapModels) {
127                    List<ShoppingCategory> models = new ArrayList<ShoppingCategory>(soapModels.length);
128    
129                    for (ShoppingCategorySoap soapModel : soapModels) {
130                            models.add(toModel(soapModel));
131                    }
132    
133                    return models;
134            }
135    
136            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
137                                    "lock.expiration.time.com.liferay.portlet.shopping.model.ShoppingCategory"));
138    
139            public ShoppingCategoryModelImpl() {
140            }
141    
142            public long getPrimaryKey() {
143                    return _categoryId;
144            }
145    
146            public void setPrimaryKey(long primaryKey) {
147                    setCategoryId(primaryKey);
148            }
149    
150            public Serializable getPrimaryKeyObj() {
151                    return new Long(_categoryId);
152            }
153    
154            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
155                    setPrimaryKey(((Long)primaryKeyObj).longValue());
156            }
157    
158            public Class<?> getModelClass() {
159                    return ShoppingCategory.class;
160            }
161    
162            public String getModelClassName() {
163                    return ShoppingCategory.class.getName();
164            }
165    
166            @JSON
167            public long getCategoryId() {
168                    return _categoryId;
169            }
170    
171            public void setCategoryId(long categoryId) {
172                    _categoryId = categoryId;
173            }
174    
175            @JSON
176            public long getGroupId() {
177                    return _groupId;
178            }
179    
180            public void setGroupId(long groupId) {
181                    _columnBitmask |= GROUPID_COLUMN_BITMASK;
182    
183                    if (!_setOriginalGroupId) {
184                            _setOriginalGroupId = true;
185    
186                            _originalGroupId = _groupId;
187                    }
188    
189                    _groupId = groupId;
190            }
191    
192            public long getOriginalGroupId() {
193                    return _originalGroupId;
194            }
195    
196            @JSON
197            public long getCompanyId() {
198                    return _companyId;
199            }
200    
201            public void setCompanyId(long companyId) {
202                    _companyId = companyId;
203            }
204    
205            @JSON
206            public long getUserId() {
207                    return _userId;
208            }
209    
210            public void setUserId(long userId) {
211                    _userId = userId;
212            }
213    
214            public String getUserUuid() throws SystemException {
215                    return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
216            }
217    
218            public void setUserUuid(String userUuid) {
219                    _userUuid = userUuid;
220            }
221    
222            @JSON
223            public String getUserName() {
224                    if (_userName == null) {
225                            return StringPool.BLANK;
226                    }
227                    else {
228                            return _userName;
229                    }
230            }
231    
232            public void setUserName(String userName) {
233                    _userName = userName;
234            }
235    
236            @JSON
237            public Date getCreateDate() {
238                    return _createDate;
239            }
240    
241            public void setCreateDate(Date createDate) {
242                    _createDate = createDate;
243            }
244    
245            @JSON
246            public Date getModifiedDate() {
247                    return _modifiedDate;
248            }
249    
250            public void setModifiedDate(Date modifiedDate) {
251                    _modifiedDate = modifiedDate;
252            }
253    
254            @JSON
255            public long getParentCategoryId() {
256                    return _parentCategoryId;
257            }
258    
259            public void setParentCategoryId(long parentCategoryId) {
260                    _columnBitmask |= PARENTCATEGORYID_COLUMN_BITMASK;
261    
262                    if (!_setOriginalParentCategoryId) {
263                            _setOriginalParentCategoryId = true;
264    
265                            _originalParentCategoryId = _parentCategoryId;
266                    }
267    
268                    _parentCategoryId = parentCategoryId;
269            }
270    
271            public long getOriginalParentCategoryId() {
272                    return _originalParentCategoryId;
273            }
274    
275            @JSON
276            public String getName() {
277                    if (_name == null) {
278                            return StringPool.BLANK;
279                    }
280                    else {
281                            return _name;
282                    }
283            }
284    
285            public void setName(String name) {
286                    _name = name;
287            }
288    
289            @JSON
290            public String getDescription() {
291                    if (_description == null) {
292                            return StringPool.BLANK;
293                    }
294                    else {
295                            return _description;
296                    }
297            }
298    
299            public void setDescription(String description) {
300                    _description = description;
301            }
302    
303            public long getColumnBitmask() {
304                    return _columnBitmask;
305            }
306    
307            @Override
308            public ShoppingCategory toEscapedModel() {
309                    if (_escapedModelProxy == null) {
310                            _escapedModelProxy = (ShoppingCategory)ProxyUtil.newProxyInstance(_classLoader,
311                                            _escapedModelProxyInterfaces,
312                                            new AutoEscapeBeanHandler(this));
313                    }
314    
315                    return _escapedModelProxy;
316            }
317    
318            @Override
319            public ExpandoBridge getExpandoBridge() {
320                    if (_expandoBridge == null) {
321                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
322                                            ShoppingCategory.class.getName(), getPrimaryKey());
323                    }
324    
325                    return _expandoBridge;
326            }
327    
328            @Override
329            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
330                    getExpandoBridge().setAttributes(serviceContext);
331            }
332    
333            @Override
334            public Object clone() {
335                    ShoppingCategoryImpl shoppingCategoryImpl = new ShoppingCategoryImpl();
336    
337                    shoppingCategoryImpl.setCategoryId(getCategoryId());
338                    shoppingCategoryImpl.setGroupId(getGroupId());
339                    shoppingCategoryImpl.setCompanyId(getCompanyId());
340                    shoppingCategoryImpl.setUserId(getUserId());
341                    shoppingCategoryImpl.setUserName(getUserName());
342                    shoppingCategoryImpl.setCreateDate(getCreateDate());
343                    shoppingCategoryImpl.setModifiedDate(getModifiedDate());
344                    shoppingCategoryImpl.setParentCategoryId(getParentCategoryId());
345                    shoppingCategoryImpl.setName(getName());
346                    shoppingCategoryImpl.setDescription(getDescription());
347    
348                    shoppingCategoryImpl.resetOriginalValues();
349    
350                    return shoppingCategoryImpl;
351            }
352    
353            public int compareTo(ShoppingCategory shoppingCategory) {
354                    int value = 0;
355    
356                    if (getParentCategoryId() < shoppingCategory.getParentCategoryId()) {
357                            value = -1;
358                    }
359                    else if (getParentCategoryId() > shoppingCategory.getParentCategoryId()) {
360                            value = 1;
361                    }
362                    else {
363                            value = 0;
364                    }
365    
366                    if (value != 0) {
367                            return value;
368                    }
369    
370                    value = getName().toLowerCase()
371                                            .compareTo(shoppingCategory.getName().toLowerCase());
372    
373                    if (value != 0) {
374                            return value;
375                    }
376    
377                    return 0;
378            }
379    
380            @Override
381            public boolean equals(Object obj) {
382                    if (obj == null) {
383                            return false;
384                    }
385    
386                    ShoppingCategory shoppingCategory = null;
387    
388                    try {
389                            shoppingCategory = (ShoppingCategory)obj;
390                    }
391                    catch (ClassCastException cce) {
392                            return false;
393                    }
394    
395                    long primaryKey = shoppingCategory.getPrimaryKey();
396    
397                    if (getPrimaryKey() == primaryKey) {
398                            return true;
399                    }
400                    else {
401                            return false;
402                    }
403            }
404    
405            @Override
406            public int hashCode() {
407                    return (int)getPrimaryKey();
408            }
409    
410            @Override
411            public void resetOriginalValues() {
412                    ShoppingCategoryModelImpl shoppingCategoryModelImpl = this;
413    
414                    shoppingCategoryModelImpl._originalGroupId = shoppingCategoryModelImpl._groupId;
415    
416                    shoppingCategoryModelImpl._setOriginalGroupId = false;
417    
418                    shoppingCategoryModelImpl._originalParentCategoryId = shoppingCategoryModelImpl._parentCategoryId;
419    
420                    shoppingCategoryModelImpl._setOriginalParentCategoryId = false;
421    
422                    shoppingCategoryModelImpl._columnBitmask = 0;
423            }
424    
425            @Override
426            public CacheModel<ShoppingCategory> toCacheModel() {
427                    ShoppingCategoryCacheModel shoppingCategoryCacheModel = new ShoppingCategoryCacheModel();
428    
429                    shoppingCategoryCacheModel.categoryId = getCategoryId();
430    
431                    shoppingCategoryCacheModel.groupId = getGroupId();
432    
433                    shoppingCategoryCacheModel.companyId = getCompanyId();
434    
435                    shoppingCategoryCacheModel.userId = getUserId();
436    
437                    shoppingCategoryCacheModel.userName = getUserName();
438    
439                    String userName = shoppingCategoryCacheModel.userName;
440    
441                    if ((userName != null) && (userName.length() == 0)) {
442                            shoppingCategoryCacheModel.userName = null;
443                    }
444    
445                    Date createDate = getCreateDate();
446    
447                    if (createDate != null) {
448                            shoppingCategoryCacheModel.createDate = createDate.getTime();
449                    }
450                    else {
451                            shoppingCategoryCacheModel.createDate = Long.MIN_VALUE;
452                    }
453    
454                    Date modifiedDate = getModifiedDate();
455    
456                    if (modifiedDate != null) {
457                            shoppingCategoryCacheModel.modifiedDate = modifiedDate.getTime();
458                    }
459                    else {
460                            shoppingCategoryCacheModel.modifiedDate = Long.MIN_VALUE;
461                    }
462    
463                    shoppingCategoryCacheModel.parentCategoryId = getParentCategoryId();
464    
465                    shoppingCategoryCacheModel.name = getName();
466    
467                    String name = shoppingCategoryCacheModel.name;
468    
469                    if ((name != null) && (name.length() == 0)) {
470                            shoppingCategoryCacheModel.name = null;
471                    }
472    
473                    shoppingCategoryCacheModel.description = getDescription();
474    
475                    String description = shoppingCategoryCacheModel.description;
476    
477                    if ((description != null) && (description.length() == 0)) {
478                            shoppingCategoryCacheModel.description = null;
479                    }
480    
481                    return shoppingCategoryCacheModel;
482            }
483    
484            @Override
485            public String toString() {
486                    StringBundler sb = new StringBundler(21);
487    
488                    sb.append("{categoryId=");
489                    sb.append(getCategoryId());
490                    sb.append(", groupId=");
491                    sb.append(getGroupId());
492                    sb.append(", companyId=");
493                    sb.append(getCompanyId());
494                    sb.append(", userId=");
495                    sb.append(getUserId());
496                    sb.append(", userName=");
497                    sb.append(getUserName());
498                    sb.append(", createDate=");
499                    sb.append(getCreateDate());
500                    sb.append(", modifiedDate=");
501                    sb.append(getModifiedDate());
502                    sb.append(", parentCategoryId=");
503                    sb.append(getParentCategoryId());
504                    sb.append(", name=");
505                    sb.append(getName());
506                    sb.append(", description=");
507                    sb.append(getDescription());
508                    sb.append("}");
509    
510                    return sb.toString();
511            }
512    
513            public String toXmlString() {
514                    StringBundler sb = new StringBundler(34);
515    
516                    sb.append("<model><model-name>");
517                    sb.append("com.liferay.portlet.shopping.model.ShoppingCategory");
518                    sb.append("</model-name>");
519    
520                    sb.append(
521                            "<column><column-name>categoryId</column-name><column-value><![CDATA[");
522                    sb.append(getCategoryId());
523                    sb.append("]]></column-value></column>");
524                    sb.append(
525                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
526                    sb.append(getGroupId());
527                    sb.append("]]></column-value></column>");
528                    sb.append(
529                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
530                    sb.append(getCompanyId());
531                    sb.append("]]></column-value></column>");
532                    sb.append(
533                            "<column><column-name>userId</column-name><column-value><![CDATA[");
534                    sb.append(getUserId());
535                    sb.append("]]></column-value></column>");
536                    sb.append(
537                            "<column><column-name>userName</column-name><column-value><![CDATA[");
538                    sb.append(getUserName());
539                    sb.append("]]></column-value></column>");
540                    sb.append(
541                            "<column><column-name>createDate</column-name><column-value><![CDATA[");
542                    sb.append(getCreateDate());
543                    sb.append("]]></column-value></column>");
544                    sb.append(
545                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
546                    sb.append(getModifiedDate());
547                    sb.append("]]></column-value></column>");
548                    sb.append(
549                            "<column><column-name>parentCategoryId</column-name><column-value><![CDATA[");
550                    sb.append(getParentCategoryId());
551                    sb.append("]]></column-value></column>");
552                    sb.append(
553                            "<column><column-name>name</column-name><column-value><![CDATA[");
554                    sb.append(getName());
555                    sb.append("]]></column-value></column>");
556                    sb.append(
557                            "<column><column-name>description</column-name><column-value><![CDATA[");
558                    sb.append(getDescription());
559                    sb.append("]]></column-value></column>");
560    
561                    sb.append("</model>");
562    
563                    return sb.toString();
564            }
565    
566            private static ClassLoader _classLoader = ShoppingCategory.class.getClassLoader();
567            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
568                            ShoppingCategory.class
569                    };
570            private long _categoryId;
571            private long _groupId;
572            private long _originalGroupId;
573            private boolean _setOriginalGroupId;
574            private long _companyId;
575            private long _userId;
576            private String _userUuid;
577            private String _userName;
578            private Date _createDate;
579            private Date _modifiedDate;
580            private long _parentCategoryId;
581            private long _originalParentCategoryId;
582            private boolean _setOriginalParentCategoryId;
583            private String _name;
584            private String _description;
585            private transient ExpandoBridge _expandoBridge;
586            private long _columnBitmask;
587            private ShoppingCategory _escapedModelProxy;
588    }