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.trash.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.DateUtil;
021    import com.liferay.portal.kernel.util.GetterUtil;
022    import com.liferay.portal.kernel.util.ProxyUtil;
023    import com.liferay.portal.kernel.util.StringBundler;
024    import com.liferay.portal.kernel.util.StringPool;
025    import com.liferay.portal.kernel.util.Validator;
026    import com.liferay.portal.model.CacheModel;
027    import com.liferay.portal.model.impl.BaseModelImpl;
028    import com.liferay.portal.service.ServiceContext;
029    import com.liferay.portal.util.PortalUtil;
030    
031    import com.liferay.portlet.expando.model.ExpandoBridge;
032    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
033    import com.liferay.portlet.trash.model.TrashEntry;
034    import com.liferay.portlet.trash.model.TrashEntryModel;
035    import com.liferay.portlet.trash.model.TrashEntrySoap;
036    
037    import java.io.Serializable;
038    
039    import java.sql.Types;
040    
041    import java.util.ArrayList;
042    import java.util.Date;
043    import java.util.HashMap;
044    import java.util.List;
045    import java.util.Map;
046    
047    /**
048     * The base model implementation for the TrashEntry service. Represents a row in the "TrashEntry" database table, with each column mapped to a property of this class.
049     *
050     * <p>
051     * This implementation and its corresponding interface {@link com.liferay.portlet.trash.model.TrashEntryModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link TrashEntryImpl}.
052     * </p>
053     *
054     * @author Brian Wing Shun Chan
055     * @see TrashEntryImpl
056     * @see com.liferay.portlet.trash.model.TrashEntry
057     * @see com.liferay.portlet.trash.model.TrashEntryModel
058     * @generated
059     */
060    @JSON(strict = true)
061    public class TrashEntryModelImpl extends BaseModelImpl<TrashEntry>
062            implements TrashEntryModel {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * Never modify or reference this class directly. All methods that expect a trash entry model instance should use the {@link com.liferay.portlet.trash.model.TrashEntry} interface instead.
067             */
068            public static final String TABLE_NAME = "TrashEntry";
069            public static final Object[][] TABLE_COLUMNS = {
070                            { "entryId", Types.BIGINT },
071                            { "groupId", Types.BIGINT },
072                            { "companyId", Types.BIGINT },
073                            { "userId", Types.BIGINT },
074                            { "userName", Types.VARCHAR },
075                            { "createDate", Types.TIMESTAMP },
076                            { "classNameId", Types.BIGINT },
077                            { "classPK", Types.BIGINT },
078                            { "typeSettings", Types.CLOB },
079                            { "status", Types.INTEGER }
080                    };
081            public static final String TABLE_SQL_CREATE = "create table TrashEntry (entryId LONG not null primary key,groupId LONG,companyId LONG,userId LONG,userName VARCHAR(75) null,createDate DATE null,classNameId LONG,classPK LONG,typeSettings TEXT null,status INTEGER)";
082            public static final String TABLE_SQL_DROP = "drop table TrashEntry";
083            public static final String ORDER_BY_JPQL = " ORDER BY trashEntry.createDate DESC";
084            public static final String ORDER_BY_SQL = " ORDER BY TrashEntry.createDate DESC";
085            public static final String DATA_SOURCE = "liferayDataSource";
086            public static final String SESSION_FACTORY = "liferaySessionFactory";
087            public static final String TX_MANAGER = "liferayTransactionManager";
088            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
089                                    "value.object.entity.cache.enabled.com.liferay.portlet.trash.model.TrashEntry"),
090                            true);
091            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
092                                    "value.object.finder.cache.enabled.com.liferay.portlet.trash.model.TrashEntry"),
093                            true);
094            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
095                                    "value.object.column.bitmask.enabled.com.liferay.portlet.trash.model.TrashEntry"),
096                            true);
097            public static long CLASSNAMEID_COLUMN_BITMASK = 1L;
098            public static long CLASSPK_COLUMN_BITMASK = 2L;
099            public static long COMPANYID_COLUMN_BITMASK = 4L;
100            public static long CREATEDATE_COLUMN_BITMASK = 8L;
101            public static long GROUPID_COLUMN_BITMASK = 16L;
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 TrashEntry toModel(TrashEntrySoap soapModel) {
110                    if (soapModel == null) {
111                            return null;
112                    }
113    
114                    TrashEntry model = new TrashEntryImpl();
115    
116                    model.setEntryId(soapModel.getEntryId());
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.setClassNameId(soapModel.getClassNameId());
123                    model.setClassPK(soapModel.getClassPK());
124                    model.setTypeSettings(soapModel.getTypeSettings());
125                    model.setStatus(soapModel.getStatus());
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<TrashEntry> toModels(TrashEntrySoap[] soapModels) {
137                    if (soapModels == null) {
138                            return null;
139                    }
140    
141                    List<TrashEntry> models = new ArrayList<TrashEntry>(soapModels.length);
142    
143                    for (TrashEntrySoap soapModel : soapModels) {
144                            models.add(toModel(soapModel));
145                    }
146    
147                    return models;
148            }
149    
150            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
151                                    "lock.expiration.time.com.liferay.portlet.trash.model.TrashEntry"));
152    
153            public TrashEntryModelImpl() {
154            }
155    
156            public long getPrimaryKey() {
157                    return _entryId;
158            }
159    
160            public void setPrimaryKey(long primaryKey) {
161                    setEntryId(primaryKey);
162            }
163    
164            public Serializable getPrimaryKeyObj() {
165                    return new Long(_entryId);
166            }
167    
168            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
169                    setPrimaryKey(((Long)primaryKeyObj).longValue());
170            }
171    
172            public Class<?> getModelClass() {
173                    return TrashEntry.class;
174            }
175    
176            public String getModelClassName() {
177                    return TrashEntry.class.getName();
178            }
179    
180            @Override
181            public Map<String, Object> getModelAttributes() {
182                    Map<String, Object> attributes = new HashMap<String, Object>();
183    
184                    attributes.put("entryId", getEntryId());
185                    attributes.put("groupId", getGroupId());
186                    attributes.put("companyId", getCompanyId());
187                    attributes.put("userId", getUserId());
188                    attributes.put("userName", getUserName());
189                    attributes.put("createDate", getCreateDate());
190                    attributes.put("classNameId", getClassNameId());
191                    attributes.put("classPK", getClassPK());
192                    attributes.put("typeSettings", getTypeSettings());
193                    attributes.put("status", getStatus());
194    
195                    return attributes;
196            }
197    
198            @Override
199            public void setModelAttributes(Map<String, Object> attributes) {
200                    Long entryId = (Long)attributes.get("entryId");
201    
202                    if (entryId != null) {
203                            setEntryId(entryId);
204                    }
205    
206                    Long groupId = (Long)attributes.get("groupId");
207    
208                    if (groupId != null) {
209                            setGroupId(groupId);
210                    }
211    
212                    Long companyId = (Long)attributes.get("companyId");
213    
214                    if (companyId != null) {
215                            setCompanyId(companyId);
216                    }
217    
218                    Long userId = (Long)attributes.get("userId");
219    
220                    if (userId != null) {
221                            setUserId(userId);
222                    }
223    
224                    String userName = (String)attributes.get("userName");
225    
226                    if (userName != null) {
227                            setUserName(userName);
228                    }
229    
230                    Date createDate = (Date)attributes.get("createDate");
231    
232                    if (createDate != null) {
233                            setCreateDate(createDate);
234                    }
235    
236                    Long classNameId = (Long)attributes.get("classNameId");
237    
238                    if (classNameId != null) {
239                            setClassNameId(classNameId);
240                    }
241    
242                    Long classPK = (Long)attributes.get("classPK");
243    
244                    if (classPK != null) {
245                            setClassPK(classPK);
246                    }
247    
248                    String typeSettings = (String)attributes.get("typeSettings");
249    
250                    if (typeSettings != null) {
251                            setTypeSettings(typeSettings);
252                    }
253    
254                    Integer status = (Integer)attributes.get("status");
255    
256                    if (status != null) {
257                            setStatus(status);
258                    }
259            }
260    
261            @JSON
262            public long getEntryId() {
263                    return _entryId;
264            }
265    
266            public void setEntryId(long entryId) {
267                    _entryId = entryId;
268            }
269    
270            @JSON
271            public long getGroupId() {
272                    return _groupId;
273            }
274    
275            public void setGroupId(long groupId) {
276                    _columnBitmask |= GROUPID_COLUMN_BITMASK;
277    
278                    if (!_setOriginalGroupId) {
279                            _setOriginalGroupId = true;
280    
281                            _originalGroupId = _groupId;
282                    }
283    
284                    _groupId = groupId;
285            }
286    
287            public long getOriginalGroupId() {
288                    return _originalGroupId;
289            }
290    
291            @JSON
292            public long getCompanyId() {
293                    return _companyId;
294            }
295    
296            public void setCompanyId(long companyId) {
297                    _columnBitmask |= COMPANYID_COLUMN_BITMASK;
298    
299                    if (!_setOriginalCompanyId) {
300                            _setOriginalCompanyId = true;
301    
302                            _originalCompanyId = _companyId;
303                    }
304    
305                    _companyId = companyId;
306            }
307    
308            public long getOriginalCompanyId() {
309                    return _originalCompanyId;
310            }
311    
312            @JSON
313            public long getUserId() {
314                    return _userId;
315            }
316    
317            public void setUserId(long userId) {
318                    _userId = userId;
319            }
320    
321            public String getUserUuid() throws SystemException {
322                    return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
323            }
324    
325            public void setUserUuid(String userUuid) {
326                    _userUuid = userUuid;
327            }
328    
329            @JSON
330            public String getUserName() {
331                    if (_userName == null) {
332                            return StringPool.BLANK;
333                    }
334                    else {
335                            return _userName;
336                    }
337            }
338    
339            public void setUserName(String userName) {
340                    _userName = userName;
341            }
342    
343            @JSON
344            public Date getCreateDate() {
345                    return _createDate;
346            }
347    
348            public void setCreateDate(Date createDate) {
349                    _columnBitmask = -1L;
350    
351                    if (_originalCreateDate == null) {
352                            _originalCreateDate = _createDate;
353                    }
354    
355                    _createDate = createDate;
356            }
357    
358            public Date getOriginalCreateDate() {
359                    return _originalCreateDate;
360            }
361    
362            public String getClassName() {
363                    if (getClassNameId() <= 0) {
364                            return StringPool.BLANK;
365                    }
366    
367                    return PortalUtil.getClassName(getClassNameId());
368            }
369    
370            public void setClassName(String className) {
371                    long classNameId = 0;
372    
373                    if (Validator.isNotNull(className)) {
374                            classNameId = PortalUtil.getClassNameId(className);
375                    }
376    
377                    setClassNameId(classNameId);
378            }
379    
380            @JSON
381            public long getClassNameId() {
382                    return _classNameId;
383            }
384    
385            public void setClassNameId(long classNameId) {
386                    _columnBitmask |= CLASSNAMEID_COLUMN_BITMASK;
387    
388                    if (!_setOriginalClassNameId) {
389                            _setOriginalClassNameId = true;
390    
391                            _originalClassNameId = _classNameId;
392                    }
393    
394                    _classNameId = classNameId;
395            }
396    
397            public long getOriginalClassNameId() {
398                    return _originalClassNameId;
399            }
400    
401            @JSON
402            public long getClassPK() {
403                    return _classPK;
404            }
405    
406            public void setClassPK(long classPK) {
407                    _columnBitmask |= CLASSPK_COLUMN_BITMASK;
408    
409                    if (!_setOriginalClassPK) {
410                            _setOriginalClassPK = true;
411    
412                            _originalClassPK = _classPK;
413                    }
414    
415                    _classPK = classPK;
416            }
417    
418            public long getOriginalClassPK() {
419                    return _originalClassPK;
420            }
421    
422            @JSON
423            public String getTypeSettings() {
424                    if (_typeSettings == null) {
425                            return StringPool.BLANK;
426                    }
427                    else {
428                            return _typeSettings;
429                    }
430            }
431    
432            public void setTypeSettings(String typeSettings) {
433                    _typeSettings = typeSettings;
434            }
435    
436            @JSON
437            public int getStatus() {
438                    return _status;
439            }
440    
441            public void setStatus(int status) {
442                    _status = status;
443            }
444    
445            public long getColumnBitmask() {
446                    return _columnBitmask;
447            }
448    
449            @Override
450            public ExpandoBridge getExpandoBridge() {
451                    return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
452                            TrashEntry.class.getName(), getPrimaryKey());
453            }
454    
455            @Override
456            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
457                    ExpandoBridge expandoBridge = getExpandoBridge();
458    
459                    expandoBridge.setAttributes(serviceContext);
460            }
461    
462            @Override
463            public TrashEntry toEscapedModel() {
464                    if (_escapedModel == null) {
465                            _escapedModel = (TrashEntry)ProxyUtil.newProxyInstance(_classLoader,
466                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
467                    }
468    
469                    return _escapedModel;
470            }
471    
472            @Override
473            public Object clone() {
474                    TrashEntryImpl trashEntryImpl = new TrashEntryImpl();
475    
476                    trashEntryImpl.setEntryId(getEntryId());
477                    trashEntryImpl.setGroupId(getGroupId());
478                    trashEntryImpl.setCompanyId(getCompanyId());
479                    trashEntryImpl.setUserId(getUserId());
480                    trashEntryImpl.setUserName(getUserName());
481                    trashEntryImpl.setCreateDate(getCreateDate());
482                    trashEntryImpl.setClassNameId(getClassNameId());
483                    trashEntryImpl.setClassPK(getClassPK());
484                    trashEntryImpl.setTypeSettings(getTypeSettings());
485                    trashEntryImpl.setStatus(getStatus());
486    
487                    trashEntryImpl.resetOriginalValues();
488    
489                    return trashEntryImpl;
490            }
491    
492            public int compareTo(TrashEntry trashEntry) {
493                    int value = 0;
494    
495                    value = DateUtil.compareTo(getCreateDate(), trashEntry.getCreateDate());
496    
497                    value = value * -1;
498    
499                    if (value != 0) {
500                            return value;
501                    }
502    
503                    return 0;
504            }
505    
506            @Override
507            public boolean equals(Object obj) {
508                    if (obj == null) {
509                            return false;
510                    }
511    
512                    TrashEntry trashEntry = null;
513    
514                    try {
515                            trashEntry = (TrashEntry)obj;
516                    }
517                    catch (ClassCastException cce) {
518                            return false;
519                    }
520    
521                    long primaryKey = trashEntry.getPrimaryKey();
522    
523                    if (getPrimaryKey() == primaryKey) {
524                            return true;
525                    }
526                    else {
527                            return false;
528                    }
529            }
530    
531            @Override
532            public int hashCode() {
533                    return (int)getPrimaryKey();
534            }
535    
536            @Override
537            public void resetOriginalValues() {
538                    TrashEntryModelImpl trashEntryModelImpl = this;
539    
540                    trashEntryModelImpl._originalGroupId = trashEntryModelImpl._groupId;
541    
542                    trashEntryModelImpl._setOriginalGroupId = false;
543    
544                    trashEntryModelImpl._originalCompanyId = trashEntryModelImpl._companyId;
545    
546                    trashEntryModelImpl._setOriginalCompanyId = false;
547    
548                    trashEntryModelImpl._originalCreateDate = trashEntryModelImpl._createDate;
549    
550                    trashEntryModelImpl._originalClassNameId = trashEntryModelImpl._classNameId;
551    
552                    trashEntryModelImpl._setOriginalClassNameId = false;
553    
554                    trashEntryModelImpl._originalClassPK = trashEntryModelImpl._classPK;
555    
556                    trashEntryModelImpl._setOriginalClassPK = false;
557    
558                    trashEntryModelImpl._columnBitmask = 0;
559            }
560    
561            @Override
562            public CacheModel<TrashEntry> toCacheModel() {
563                    TrashEntryCacheModel trashEntryCacheModel = new TrashEntryCacheModel();
564    
565                    trashEntryCacheModel.entryId = getEntryId();
566    
567                    trashEntryCacheModel.groupId = getGroupId();
568    
569                    trashEntryCacheModel.companyId = getCompanyId();
570    
571                    trashEntryCacheModel.userId = getUserId();
572    
573                    trashEntryCacheModel.userName = getUserName();
574    
575                    String userName = trashEntryCacheModel.userName;
576    
577                    if ((userName != null) && (userName.length() == 0)) {
578                            trashEntryCacheModel.userName = null;
579                    }
580    
581                    Date createDate = getCreateDate();
582    
583                    if (createDate != null) {
584                            trashEntryCacheModel.createDate = createDate.getTime();
585                    }
586                    else {
587                            trashEntryCacheModel.createDate = Long.MIN_VALUE;
588                    }
589    
590                    trashEntryCacheModel.classNameId = getClassNameId();
591    
592                    trashEntryCacheModel.classPK = getClassPK();
593    
594                    trashEntryCacheModel.typeSettings = getTypeSettings();
595    
596                    String typeSettings = trashEntryCacheModel.typeSettings;
597    
598                    if ((typeSettings != null) && (typeSettings.length() == 0)) {
599                            trashEntryCacheModel.typeSettings = null;
600                    }
601    
602                    trashEntryCacheModel.status = getStatus();
603    
604                    return trashEntryCacheModel;
605            }
606    
607            @Override
608            public String toString() {
609                    StringBundler sb = new StringBundler(21);
610    
611                    sb.append("{entryId=");
612                    sb.append(getEntryId());
613                    sb.append(", groupId=");
614                    sb.append(getGroupId());
615                    sb.append(", companyId=");
616                    sb.append(getCompanyId());
617                    sb.append(", userId=");
618                    sb.append(getUserId());
619                    sb.append(", userName=");
620                    sb.append(getUserName());
621                    sb.append(", createDate=");
622                    sb.append(getCreateDate());
623                    sb.append(", classNameId=");
624                    sb.append(getClassNameId());
625                    sb.append(", classPK=");
626                    sb.append(getClassPK());
627                    sb.append(", typeSettings=");
628                    sb.append(getTypeSettings());
629                    sb.append(", status=");
630                    sb.append(getStatus());
631                    sb.append("}");
632    
633                    return sb.toString();
634            }
635    
636            public String toXmlString() {
637                    StringBundler sb = new StringBundler(34);
638    
639                    sb.append("<model><model-name>");
640                    sb.append("com.liferay.portlet.trash.model.TrashEntry");
641                    sb.append("</model-name>");
642    
643                    sb.append(
644                            "<column><column-name>entryId</column-name><column-value><![CDATA[");
645                    sb.append(getEntryId());
646                    sb.append("]]></column-value></column>");
647                    sb.append(
648                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
649                    sb.append(getGroupId());
650                    sb.append("]]></column-value></column>");
651                    sb.append(
652                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
653                    sb.append(getCompanyId());
654                    sb.append("]]></column-value></column>");
655                    sb.append(
656                            "<column><column-name>userId</column-name><column-value><![CDATA[");
657                    sb.append(getUserId());
658                    sb.append("]]></column-value></column>");
659                    sb.append(
660                            "<column><column-name>userName</column-name><column-value><![CDATA[");
661                    sb.append(getUserName());
662                    sb.append("]]></column-value></column>");
663                    sb.append(
664                            "<column><column-name>createDate</column-name><column-value><![CDATA[");
665                    sb.append(getCreateDate());
666                    sb.append("]]></column-value></column>");
667                    sb.append(
668                            "<column><column-name>classNameId</column-name><column-value><![CDATA[");
669                    sb.append(getClassNameId());
670                    sb.append("]]></column-value></column>");
671                    sb.append(
672                            "<column><column-name>classPK</column-name><column-value><![CDATA[");
673                    sb.append(getClassPK());
674                    sb.append("]]></column-value></column>");
675                    sb.append(
676                            "<column><column-name>typeSettings</column-name><column-value><![CDATA[");
677                    sb.append(getTypeSettings());
678                    sb.append("]]></column-value></column>");
679                    sb.append(
680                            "<column><column-name>status</column-name><column-value><![CDATA[");
681                    sb.append(getStatus());
682                    sb.append("]]></column-value></column>");
683    
684                    sb.append("</model>");
685    
686                    return sb.toString();
687            }
688    
689            private static ClassLoader _classLoader = TrashEntry.class.getClassLoader();
690            private static Class<?>[] _escapedModelInterfaces = new Class[] {
691                            TrashEntry.class
692                    };
693            private long _entryId;
694            private long _groupId;
695            private long _originalGroupId;
696            private boolean _setOriginalGroupId;
697            private long _companyId;
698            private long _originalCompanyId;
699            private boolean _setOriginalCompanyId;
700            private long _userId;
701            private String _userUuid;
702            private String _userName;
703            private Date _createDate;
704            private Date _originalCreateDate;
705            private long _classNameId;
706            private long _originalClassNameId;
707            private boolean _setOriginalClassNameId;
708            private long _classPK;
709            private long _originalClassPK;
710            private boolean _setOriginalClassPK;
711            private String _typeSettings;
712            private int _status;
713            private long _columnBitmask;
714            private TrashEntry _escapedModel;
715    }