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