001    /**
002     * Copyright (c) 2000-2012 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 = -1L;
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                    _columnBitmask = -1L;
287    
288                    _name = name;
289            }
290    
291            @JSON
292            public String getDescription() {
293                    if (_description == null) {
294                            return StringPool.BLANK;
295                    }
296                    else {
297                            return _description;
298                    }
299            }
300    
301            public void setDescription(String description) {
302                    _description = description;
303            }
304    
305            public long getColumnBitmask() {
306                    return _columnBitmask;
307            }
308    
309            @Override
310            public ShoppingCategory toEscapedModel() {
311                    if (_escapedModelProxy == null) {
312                            _escapedModelProxy = (ShoppingCategory)ProxyUtil.newProxyInstance(_classLoader,
313                                            _escapedModelProxyInterfaces,
314                                            new AutoEscapeBeanHandler(this));
315                    }
316    
317                    return _escapedModelProxy;
318            }
319    
320            @Override
321            public ExpandoBridge getExpandoBridge() {
322                    if (_expandoBridge == null) {
323                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
324                                            ShoppingCategory.class.getName(), getPrimaryKey());
325                    }
326    
327                    return _expandoBridge;
328            }
329    
330            @Override
331            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
332                    getExpandoBridge().setAttributes(serviceContext);
333            }
334    
335            @Override
336            public Object clone() {
337                    ShoppingCategoryImpl shoppingCategoryImpl = new ShoppingCategoryImpl();
338    
339                    shoppingCategoryImpl.setCategoryId(getCategoryId());
340                    shoppingCategoryImpl.setGroupId(getGroupId());
341                    shoppingCategoryImpl.setCompanyId(getCompanyId());
342                    shoppingCategoryImpl.setUserId(getUserId());
343                    shoppingCategoryImpl.setUserName(getUserName());
344                    shoppingCategoryImpl.setCreateDate(getCreateDate());
345                    shoppingCategoryImpl.setModifiedDate(getModifiedDate());
346                    shoppingCategoryImpl.setParentCategoryId(getParentCategoryId());
347                    shoppingCategoryImpl.setName(getName());
348                    shoppingCategoryImpl.setDescription(getDescription());
349    
350                    shoppingCategoryImpl.resetOriginalValues();
351    
352                    return shoppingCategoryImpl;
353            }
354    
355            public int compareTo(ShoppingCategory shoppingCategory) {
356                    int value = 0;
357    
358                    if (getParentCategoryId() < shoppingCategory.getParentCategoryId()) {
359                            value = -1;
360                    }
361                    else if (getParentCategoryId() > shoppingCategory.getParentCategoryId()) {
362                            value = 1;
363                    }
364                    else {
365                            value = 0;
366                    }
367    
368                    if (value != 0) {
369                            return value;
370                    }
371    
372                    value = getName().toLowerCase()
373                                            .compareTo(shoppingCategory.getName().toLowerCase());
374    
375                    if (value != 0) {
376                            return value;
377                    }
378    
379                    return 0;
380            }
381    
382            @Override
383            public boolean equals(Object obj) {
384                    if (obj == null) {
385                            return false;
386                    }
387    
388                    ShoppingCategory shoppingCategory = null;
389    
390                    try {
391                            shoppingCategory = (ShoppingCategory)obj;
392                    }
393                    catch (ClassCastException cce) {
394                            return false;
395                    }
396    
397                    long primaryKey = shoppingCategory.getPrimaryKey();
398    
399                    if (getPrimaryKey() == primaryKey) {
400                            return true;
401                    }
402                    else {
403                            return false;
404                    }
405            }
406    
407            @Override
408            public int hashCode() {
409                    return (int)getPrimaryKey();
410            }
411    
412            @Override
413            public void resetOriginalValues() {
414                    ShoppingCategoryModelImpl shoppingCategoryModelImpl = this;
415    
416                    shoppingCategoryModelImpl._originalGroupId = shoppingCategoryModelImpl._groupId;
417    
418                    shoppingCategoryModelImpl._setOriginalGroupId = false;
419    
420                    shoppingCategoryModelImpl._originalParentCategoryId = shoppingCategoryModelImpl._parentCategoryId;
421    
422                    shoppingCategoryModelImpl._setOriginalParentCategoryId = false;
423    
424                    shoppingCategoryModelImpl._columnBitmask = 0;
425            }
426    
427            @Override
428            public CacheModel<ShoppingCategory> toCacheModel() {
429                    ShoppingCategoryCacheModel shoppingCategoryCacheModel = new ShoppingCategoryCacheModel();
430    
431                    shoppingCategoryCacheModel.categoryId = getCategoryId();
432    
433                    shoppingCategoryCacheModel.groupId = getGroupId();
434    
435                    shoppingCategoryCacheModel.companyId = getCompanyId();
436    
437                    shoppingCategoryCacheModel.userId = getUserId();
438    
439                    shoppingCategoryCacheModel.userName = getUserName();
440    
441                    String userName = shoppingCategoryCacheModel.userName;
442    
443                    if ((userName != null) && (userName.length() == 0)) {
444                            shoppingCategoryCacheModel.userName = null;
445                    }
446    
447                    Date createDate = getCreateDate();
448    
449                    if (createDate != null) {
450                            shoppingCategoryCacheModel.createDate = createDate.getTime();
451                    }
452                    else {
453                            shoppingCategoryCacheModel.createDate = Long.MIN_VALUE;
454                    }
455    
456                    Date modifiedDate = getModifiedDate();
457    
458                    if (modifiedDate != null) {
459                            shoppingCategoryCacheModel.modifiedDate = modifiedDate.getTime();
460                    }
461                    else {
462                            shoppingCategoryCacheModel.modifiedDate = Long.MIN_VALUE;
463                    }
464    
465                    shoppingCategoryCacheModel.parentCategoryId = getParentCategoryId();
466    
467                    shoppingCategoryCacheModel.name = getName();
468    
469                    String name = shoppingCategoryCacheModel.name;
470    
471                    if ((name != null) && (name.length() == 0)) {
472                            shoppingCategoryCacheModel.name = null;
473                    }
474    
475                    shoppingCategoryCacheModel.description = getDescription();
476    
477                    String description = shoppingCategoryCacheModel.description;
478    
479                    if ((description != null) && (description.length() == 0)) {
480                            shoppingCategoryCacheModel.description = null;
481                    }
482    
483                    return shoppingCategoryCacheModel;
484            }
485    
486            @Override
487            public String toString() {
488                    StringBundler sb = new StringBundler(21);
489    
490                    sb.append("{categoryId=");
491                    sb.append(getCategoryId());
492                    sb.append(", groupId=");
493                    sb.append(getGroupId());
494                    sb.append(", companyId=");
495                    sb.append(getCompanyId());
496                    sb.append(", userId=");
497                    sb.append(getUserId());
498                    sb.append(", userName=");
499                    sb.append(getUserName());
500                    sb.append(", createDate=");
501                    sb.append(getCreateDate());
502                    sb.append(", modifiedDate=");
503                    sb.append(getModifiedDate());
504                    sb.append(", parentCategoryId=");
505                    sb.append(getParentCategoryId());
506                    sb.append(", name=");
507                    sb.append(getName());
508                    sb.append(", description=");
509                    sb.append(getDescription());
510                    sb.append("}");
511    
512                    return sb.toString();
513            }
514    
515            public String toXmlString() {
516                    StringBundler sb = new StringBundler(34);
517    
518                    sb.append("<model><model-name>");
519                    sb.append("com.liferay.portlet.shopping.model.ShoppingCategory");
520                    sb.append("</model-name>");
521    
522                    sb.append(
523                            "<column><column-name>categoryId</column-name><column-value><![CDATA[");
524                    sb.append(getCategoryId());
525                    sb.append("]]></column-value></column>");
526                    sb.append(
527                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
528                    sb.append(getGroupId());
529                    sb.append("]]></column-value></column>");
530                    sb.append(
531                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
532                    sb.append(getCompanyId());
533                    sb.append("]]></column-value></column>");
534                    sb.append(
535                            "<column><column-name>userId</column-name><column-value><![CDATA[");
536                    sb.append(getUserId());
537                    sb.append("]]></column-value></column>");
538                    sb.append(
539                            "<column><column-name>userName</column-name><column-value><![CDATA[");
540                    sb.append(getUserName());
541                    sb.append("]]></column-value></column>");
542                    sb.append(
543                            "<column><column-name>createDate</column-name><column-value><![CDATA[");
544                    sb.append(getCreateDate());
545                    sb.append("]]></column-value></column>");
546                    sb.append(
547                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
548                    sb.append(getModifiedDate());
549                    sb.append("]]></column-value></column>");
550                    sb.append(
551                            "<column><column-name>parentCategoryId</column-name><column-value><![CDATA[");
552                    sb.append(getParentCategoryId());
553                    sb.append("]]></column-value></column>");
554                    sb.append(
555                            "<column><column-name>name</column-name><column-value><![CDATA[");
556                    sb.append(getName());
557                    sb.append("]]></column-value></column>");
558                    sb.append(
559                            "<column><column-name>description</column-name><column-value><![CDATA[");
560                    sb.append(getDescription());
561                    sb.append("]]></column-value></column>");
562    
563                    sb.append("</model>");
564    
565                    return sb.toString();
566            }
567    
568            private static ClassLoader _classLoader = ShoppingCategory.class.getClassLoader();
569            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
570                            ShoppingCategory.class
571                    };
572            private long _categoryId;
573            private long _groupId;
574            private long _originalGroupId;
575            private boolean _setOriginalGroupId;
576            private long _companyId;
577            private long _userId;
578            private String _userUuid;
579            private String _userName;
580            private Date _createDate;
581            private Date _modifiedDate;
582            private long _parentCategoryId;
583            private long _originalParentCategoryId;
584            private boolean _setOriginalParentCategoryId;
585            private String _name;
586            private String _description;
587            private transient ExpandoBridge _expandoBridge;
588            private long _columnBitmask;
589            private ShoppingCategory _escapedModelProxy;
590    }