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