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.messageboards.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.util.GetterUtil;
020    import com.liferay.portal.kernel.util.ProxyUtil;
021    import com.liferay.portal.kernel.util.StringBundler;
022    import com.liferay.portal.model.CacheModel;
023    import com.liferay.portal.model.impl.BaseModelImpl;
024    import com.liferay.portal.service.ServiceContext;
025    import com.liferay.portal.util.PortalUtil;
026    
027    import com.liferay.portlet.expando.model.ExpandoBridge;
028    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
029    import com.liferay.portlet.messageboards.model.MBStatsUser;
030    import com.liferay.portlet.messageboards.model.MBStatsUserModel;
031    
032    import java.io.Serializable;
033    
034    import java.sql.Types;
035    
036    import java.util.Date;
037    import java.util.HashMap;
038    import java.util.Map;
039    
040    /**
041     * The base model implementation for the MBStatsUser service. Represents a row in the "MBStatsUser" database table, with each column mapped to a property of this class.
042     *
043     * <p>
044     * This implementation and its corresponding interface {@link com.liferay.portlet.messageboards.model.MBStatsUserModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link MBStatsUserImpl}.
045     * </p>
046     *
047     * @author Brian Wing Shun Chan
048     * @see MBStatsUserImpl
049     * @see com.liferay.portlet.messageboards.model.MBStatsUser
050     * @see com.liferay.portlet.messageboards.model.MBStatsUserModel
051     * @generated
052     */
053    public class MBStatsUserModelImpl extends BaseModelImpl<MBStatsUser>
054            implements MBStatsUserModel {
055            /*
056             * NOTE FOR DEVELOPERS:
057             *
058             * Never modify or reference this class directly. All methods that expect a message boards stats user model instance should use the {@link com.liferay.portlet.messageboards.model.MBStatsUser} interface instead.
059             */
060            public static final String TABLE_NAME = "MBStatsUser";
061            public static final Object[][] TABLE_COLUMNS = {
062                            { "statsUserId", Types.BIGINT },
063                            { "groupId", Types.BIGINT },
064                            { "userId", Types.BIGINT },
065                            { "messageCount", Types.INTEGER },
066                            { "lastPostDate", Types.TIMESTAMP }
067                    };
068            public static final String TABLE_SQL_CREATE = "create table MBStatsUser (statsUserId LONG not null primary key,groupId LONG,userId LONG,messageCount INTEGER,lastPostDate DATE null)";
069            public static final String TABLE_SQL_DROP = "drop table MBStatsUser";
070            public static final String ORDER_BY_JPQL = " ORDER BY mbStatsUser.messageCount DESC";
071            public static final String ORDER_BY_SQL = " ORDER BY MBStatsUser.messageCount DESC";
072            public static final String DATA_SOURCE = "liferayDataSource";
073            public static final String SESSION_FACTORY = "liferaySessionFactory";
074            public static final String TX_MANAGER = "liferayTransactionManager";
075            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
076                                    "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBStatsUser"),
077                            true);
078            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079                                    "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBStatsUser"),
080                            true);
081            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.column.bitmask.enabled.com.liferay.portlet.messageboards.model.MBStatsUser"),
083                            true);
084            public static long GROUPID_COLUMN_BITMASK = 1L;
085            public static long MESSAGECOUNT_COLUMN_BITMASK = 2L;
086            public static long USERID_COLUMN_BITMASK = 4L;
087            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
088                                    "lock.expiration.time.com.liferay.portlet.messageboards.model.MBStatsUser"));
089    
090            public MBStatsUserModelImpl() {
091            }
092    
093            public long getPrimaryKey() {
094                    return _statsUserId;
095            }
096    
097            public void setPrimaryKey(long primaryKey) {
098                    setStatsUserId(primaryKey);
099            }
100    
101            public Serializable getPrimaryKeyObj() {
102                    return new Long(_statsUserId);
103            }
104    
105            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
106                    setPrimaryKey(((Long)primaryKeyObj).longValue());
107            }
108    
109            public Class<?> getModelClass() {
110                    return MBStatsUser.class;
111            }
112    
113            public String getModelClassName() {
114                    return MBStatsUser.class.getName();
115            }
116    
117            @Override
118            public Map<String, Object> getModelAttributes() {
119                    Map<String, Object> attributes = new HashMap<String, Object>();
120    
121                    attributes.put("statsUserId", getStatsUserId());
122                    attributes.put("groupId", getGroupId());
123                    attributes.put("userId", getUserId());
124                    attributes.put("messageCount", getMessageCount());
125                    attributes.put("lastPostDate", getLastPostDate());
126    
127                    return attributes;
128            }
129    
130            @Override
131            public void setModelAttributes(Map<String, Object> attributes) {
132                    Long statsUserId = (Long)attributes.get("statsUserId");
133    
134                    if (statsUserId != null) {
135                            setStatsUserId(statsUserId);
136                    }
137    
138                    Long groupId = (Long)attributes.get("groupId");
139    
140                    if (groupId != null) {
141                            setGroupId(groupId);
142                    }
143    
144                    Long userId = (Long)attributes.get("userId");
145    
146                    if (userId != null) {
147                            setUserId(userId);
148                    }
149    
150                    Integer messageCount = (Integer)attributes.get("messageCount");
151    
152                    if (messageCount != null) {
153                            setMessageCount(messageCount);
154                    }
155    
156                    Date lastPostDate = (Date)attributes.get("lastPostDate");
157    
158                    if (lastPostDate != null) {
159                            setLastPostDate(lastPostDate);
160                    }
161            }
162    
163            public long getStatsUserId() {
164                    return _statsUserId;
165            }
166    
167            public void setStatsUserId(long statsUserId) {
168                    _statsUserId = statsUserId;
169            }
170    
171            public String getStatsUserUuid() throws SystemException {
172                    return PortalUtil.getUserValue(getStatsUserId(), "uuid", _statsUserUuid);
173            }
174    
175            public void setStatsUserUuid(String statsUserUuid) {
176                    _statsUserUuid = statsUserUuid;
177            }
178    
179            public long getGroupId() {
180                    return _groupId;
181            }
182    
183            public void setGroupId(long groupId) {
184                    _columnBitmask |= GROUPID_COLUMN_BITMASK;
185    
186                    if (!_setOriginalGroupId) {
187                            _setOriginalGroupId = true;
188    
189                            _originalGroupId = _groupId;
190                    }
191    
192                    _groupId = groupId;
193            }
194    
195            public long getOriginalGroupId() {
196                    return _originalGroupId;
197            }
198    
199            public long getUserId() {
200                    return _userId;
201            }
202    
203            public void setUserId(long userId) {
204                    _columnBitmask |= USERID_COLUMN_BITMASK;
205    
206                    if (!_setOriginalUserId) {
207                            _setOriginalUserId = true;
208    
209                            _originalUserId = _userId;
210                    }
211    
212                    _userId = userId;
213            }
214    
215            public String getUserUuid() throws SystemException {
216                    return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
217            }
218    
219            public void setUserUuid(String userUuid) {
220                    _userUuid = userUuid;
221            }
222    
223            public long getOriginalUserId() {
224                    return _originalUserId;
225            }
226    
227            public int getMessageCount() {
228                    return _messageCount;
229            }
230    
231            public void setMessageCount(int messageCount) {
232                    _columnBitmask = -1L;
233    
234                    if (!_setOriginalMessageCount) {
235                            _setOriginalMessageCount = true;
236    
237                            _originalMessageCount = _messageCount;
238                    }
239    
240                    _messageCount = messageCount;
241            }
242    
243            public int getOriginalMessageCount() {
244                    return _originalMessageCount;
245            }
246    
247            public Date getLastPostDate() {
248                    return _lastPostDate;
249            }
250    
251            public void setLastPostDate(Date lastPostDate) {
252                    _lastPostDate = lastPostDate;
253            }
254    
255            public long getColumnBitmask() {
256                    return _columnBitmask;
257            }
258    
259            @Override
260            public ExpandoBridge getExpandoBridge() {
261                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
262                            MBStatsUser.class.getName(), getPrimaryKey());
263            }
264    
265            @Override
266            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
267                    ExpandoBridge expandoBridge = getExpandoBridge();
268    
269                    expandoBridge.setAttributes(serviceContext);
270            }
271    
272            @Override
273            public MBStatsUser toEscapedModel() {
274                    if (_escapedModel == null) {
275                            _escapedModel = (MBStatsUser)ProxyUtil.newProxyInstance(_classLoader,
276                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
277                    }
278    
279                    return _escapedModel;
280            }
281    
282            public MBStatsUser toUnescapedModel() {
283                    return (MBStatsUser)this;
284            }
285    
286            @Override
287            public Object clone() {
288                    MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
289    
290                    mbStatsUserImpl.setStatsUserId(getStatsUserId());
291                    mbStatsUserImpl.setGroupId(getGroupId());
292                    mbStatsUserImpl.setUserId(getUserId());
293                    mbStatsUserImpl.setMessageCount(getMessageCount());
294                    mbStatsUserImpl.setLastPostDate(getLastPostDate());
295    
296                    mbStatsUserImpl.resetOriginalValues();
297    
298                    return mbStatsUserImpl;
299            }
300    
301            public int compareTo(MBStatsUser mbStatsUser) {
302                    int value = 0;
303    
304                    if (getMessageCount() < mbStatsUser.getMessageCount()) {
305                            value = -1;
306                    }
307                    else if (getMessageCount() > mbStatsUser.getMessageCount()) {
308                            value = 1;
309                    }
310                    else {
311                            value = 0;
312                    }
313    
314                    value = value * -1;
315    
316                    if (value != 0) {
317                            return value;
318                    }
319    
320                    return 0;
321            }
322    
323            @Override
324            public boolean equals(Object obj) {
325                    if (this == obj) {
326                            return true;
327                    }
328    
329                    if (!(obj instanceof MBStatsUser)) {
330                            return false;
331                    }
332    
333                    MBStatsUser mbStatsUser = (MBStatsUser)obj;
334    
335                    long primaryKey = mbStatsUser.getPrimaryKey();
336    
337                    if (getPrimaryKey() == primaryKey) {
338                            return true;
339                    }
340                    else {
341                            return false;
342                    }
343            }
344    
345            @Override
346            public int hashCode() {
347                    return (int)getPrimaryKey();
348            }
349    
350            @Override
351            public void resetOriginalValues() {
352                    MBStatsUserModelImpl mbStatsUserModelImpl = this;
353    
354                    mbStatsUserModelImpl._originalGroupId = mbStatsUserModelImpl._groupId;
355    
356                    mbStatsUserModelImpl._setOriginalGroupId = false;
357    
358                    mbStatsUserModelImpl._originalUserId = mbStatsUserModelImpl._userId;
359    
360                    mbStatsUserModelImpl._setOriginalUserId = false;
361    
362                    mbStatsUserModelImpl._originalMessageCount = mbStatsUserModelImpl._messageCount;
363    
364                    mbStatsUserModelImpl._setOriginalMessageCount = false;
365    
366                    mbStatsUserModelImpl._columnBitmask = 0;
367            }
368    
369            @Override
370            public CacheModel<MBStatsUser> toCacheModel() {
371                    MBStatsUserCacheModel mbStatsUserCacheModel = new MBStatsUserCacheModel();
372    
373                    mbStatsUserCacheModel.statsUserId = getStatsUserId();
374    
375                    mbStatsUserCacheModel.groupId = getGroupId();
376    
377                    mbStatsUserCacheModel.userId = getUserId();
378    
379                    mbStatsUserCacheModel.messageCount = getMessageCount();
380    
381                    Date lastPostDate = getLastPostDate();
382    
383                    if (lastPostDate != null) {
384                            mbStatsUserCacheModel.lastPostDate = lastPostDate.getTime();
385                    }
386                    else {
387                            mbStatsUserCacheModel.lastPostDate = Long.MIN_VALUE;
388                    }
389    
390                    return mbStatsUserCacheModel;
391            }
392    
393            @Override
394            public String toString() {
395                    StringBundler sb = new StringBundler(11);
396    
397                    sb.append("{statsUserId=");
398                    sb.append(getStatsUserId());
399                    sb.append(", groupId=");
400                    sb.append(getGroupId());
401                    sb.append(", userId=");
402                    sb.append(getUserId());
403                    sb.append(", messageCount=");
404                    sb.append(getMessageCount());
405                    sb.append(", lastPostDate=");
406                    sb.append(getLastPostDate());
407                    sb.append("}");
408    
409                    return sb.toString();
410            }
411    
412            public String toXmlString() {
413                    StringBundler sb = new StringBundler(19);
414    
415                    sb.append("<model><model-name>");
416                    sb.append("com.liferay.portlet.messageboards.model.MBStatsUser");
417                    sb.append("</model-name>");
418    
419                    sb.append(
420                            "<column><column-name>statsUserId</column-name><column-value><![CDATA[");
421                    sb.append(getStatsUserId());
422                    sb.append("]]></column-value></column>");
423                    sb.append(
424                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
425                    sb.append(getGroupId());
426                    sb.append("]]></column-value></column>");
427                    sb.append(
428                            "<column><column-name>userId</column-name><column-value><![CDATA[");
429                    sb.append(getUserId());
430                    sb.append("]]></column-value></column>");
431                    sb.append(
432                            "<column><column-name>messageCount</column-name><column-value><![CDATA[");
433                    sb.append(getMessageCount());
434                    sb.append("]]></column-value></column>");
435                    sb.append(
436                            "<column><column-name>lastPostDate</column-name><column-value><![CDATA[");
437                    sb.append(getLastPostDate());
438                    sb.append("]]></column-value></column>");
439    
440                    sb.append("</model>");
441    
442                    return sb.toString();
443            }
444    
445            private static ClassLoader _classLoader = MBStatsUser.class.getClassLoader();
446            private static Class<?>[] _escapedModelInterfaces = new Class[] {
447                            MBStatsUser.class
448                    };
449            private long _statsUserId;
450            private String _statsUserUuid;
451            private long _groupId;
452            private long _originalGroupId;
453            private boolean _setOriginalGroupId;
454            private long _userId;
455            private String _userUuid;
456            private long _originalUserId;
457            private boolean _setOriginalUserId;
458            private int _messageCount;
459            private int _originalMessageCount;
460            private boolean _setOriginalMessageCount;
461            private Date _lastPostDate;
462            private long _columnBitmask;
463            private MBStatsUser _escapedModel;
464    }