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.util.GetterUtil;
019    import com.liferay.portal.kernel.util.ProxyUtil;
020    import com.liferay.portal.kernel.util.StringBundler;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.portal.kernel.util.Validator;
023    import com.liferay.portal.model.CacheModel;
024    import com.liferay.portal.model.impl.BaseModelImpl;
025    import com.liferay.portal.service.ServiceContext;
026    import com.liferay.portal.util.PortalUtil;
027    
028    import com.liferay.portlet.expando.model.ExpandoBridge;
029    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
030    import com.liferay.portlet.messageboards.model.MBDiscussion;
031    import com.liferay.portlet.messageboards.model.MBDiscussionModel;
032    
033    import java.io.Serializable;
034    
035    import java.sql.Types;
036    
037    import java.util.HashMap;
038    import java.util.Map;
039    
040    /**
041     * The base model implementation for the MBDiscussion service. Represents a row in the "MBDiscussion" 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.MBDiscussionModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link MBDiscussionImpl}.
045     * </p>
046     *
047     * @author Brian Wing Shun Chan
048     * @see MBDiscussionImpl
049     * @see com.liferay.portlet.messageboards.model.MBDiscussion
050     * @see com.liferay.portlet.messageboards.model.MBDiscussionModel
051     * @generated
052     */
053    public class MBDiscussionModelImpl extends BaseModelImpl<MBDiscussion>
054            implements MBDiscussionModel {
055            /*
056             * NOTE FOR DEVELOPERS:
057             *
058             * Never modify or reference this class directly. All methods that expect a message boards discussion model instance should use the {@link com.liferay.portlet.messageboards.model.MBDiscussion} interface instead.
059             */
060            public static final String TABLE_NAME = "MBDiscussion";
061            public static final Object[][] TABLE_COLUMNS = {
062                            { "discussionId", Types.BIGINT },
063                            { "classNameId", Types.BIGINT },
064                            { "classPK", Types.BIGINT },
065                            { "threadId", Types.BIGINT }
066                    };
067            public static final String TABLE_SQL_CREATE = "create table MBDiscussion (discussionId LONG not null primary key,classNameId LONG,classPK LONG,threadId LONG)";
068            public static final String TABLE_SQL_DROP = "drop table MBDiscussion";
069            public static final String DATA_SOURCE = "liferayDataSource";
070            public static final String SESSION_FACTORY = "liferaySessionFactory";
071            public static final String TX_MANAGER = "liferayTransactionManager";
072            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
073                                    "value.object.entity.cache.enabled.com.liferay.portlet.messageboards.model.MBDiscussion"),
074                            true);
075            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
076                                    "value.object.finder.cache.enabled.com.liferay.portlet.messageboards.model.MBDiscussion"),
077                            true);
078            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079                                    "value.object.column.bitmask.enabled.com.liferay.portlet.messageboards.model.MBDiscussion"),
080                            true);
081            public static long CLASSNAMEID_COLUMN_BITMASK = 1L;
082            public static long CLASSPK_COLUMN_BITMASK = 2L;
083            public static long THREADID_COLUMN_BITMASK = 4L;
084            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
085                                    "lock.expiration.time.com.liferay.portlet.messageboards.model.MBDiscussion"));
086    
087            public MBDiscussionModelImpl() {
088            }
089    
090            public long getPrimaryKey() {
091                    return _discussionId;
092            }
093    
094            public void setPrimaryKey(long primaryKey) {
095                    setDiscussionId(primaryKey);
096            }
097    
098            public Serializable getPrimaryKeyObj() {
099                    return new Long(_discussionId);
100            }
101    
102            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
103                    setPrimaryKey(((Long)primaryKeyObj).longValue());
104            }
105    
106            public Class<?> getModelClass() {
107                    return MBDiscussion.class;
108            }
109    
110            public String getModelClassName() {
111                    return MBDiscussion.class.getName();
112            }
113    
114            @Override
115            public Map<String, Object> getModelAttributes() {
116                    Map<String, Object> attributes = new HashMap<String, Object>();
117    
118                    attributes.put("discussionId", getDiscussionId());
119                    attributes.put("classNameId", getClassNameId());
120                    attributes.put("classPK", getClassPK());
121                    attributes.put("threadId", getThreadId());
122    
123                    return attributes;
124            }
125    
126            @Override
127            public void setModelAttributes(Map<String, Object> attributes) {
128                    Long discussionId = (Long)attributes.get("discussionId");
129    
130                    if (discussionId != null) {
131                            setDiscussionId(discussionId);
132                    }
133    
134                    Long classNameId = (Long)attributes.get("classNameId");
135    
136                    if (classNameId != null) {
137                            setClassNameId(classNameId);
138                    }
139    
140                    Long classPK = (Long)attributes.get("classPK");
141    
142                    if (classPK != null) {
143                            setClassPK(classPK);
144                    }
145    
146                    Long threadId = (Long)attributes.get("threadId");
147    
148                    if (threadId != null) {
149                            setThreadId(threadId);
150                    }
151            }
152    
153            public long getDiscussionId() {
154                    return _discussionId;
155            }
156    
157            public void setDiscussionId(long discussionId) {
158                    _discussionId = discussionId;
159            }
160    
161            public String getClassName() {
162                    if (getClassNameId() <= 0) {
163                            return StringPool.BLANK;
164                    }
165    
166                    return PortalUtil.getClassName(getClassNameId());
167            }
168    
169            public void setClassName(String className) {
170                    long classNameId = 0;
171    
172                    if (Validator.isNotNull(className)) {
173                            classNameId = PortalUtil.getClassNameId(className);
174                    }
175    
176                    setClassNameId(classNameId);
177            }
178    
179            public long getClassNameId() {
180                    return _classNameId;
181            }
182    
183            public void setClassNameId(long classNameId) {
184                    _columnBitmask |= CLASSNAMEID_COLUMN_BITMASK;
185    
186                    if (!_setOriginalClassNameId) {
187                            _setOriginalClassNameId = true;
188    
189                            _originalClassNameId = _classNameId;
190                    }
191    
192                    _classNameId = classNameId;
193            }
194    
195            public long getOriginalClassNameId() {
196                    return _originalClassNameId;
197            }
198    
199            public long getClassPK() {
200                    return _classPK;
201            }
202    
203            public void setClassPK(long classPK) {
204                    _columnBitmask |= CLASSPK_COLUMN_BITMASK;
205    
206                    if (!_setOriginalClassPK) {
207                            _setOriginalClassPK = true;
208    
209                            _originalClassPK = _classPK;
210                    }
211    
212                    _classPK = classPK;
213            }
214    
215            public long getOriginalClassPK() {
216                    return _originalClassPK;
217            }
218    
219            public long getThreadId() {
220                    return _threadId;
221            }
222    
223            public void setThreadId(long threadId) {
224                    _columnBitmask |= THREADID_COLUMN_BITMASK;
225    
226                    if (!_setOriginalThreadId) {
227                            _setOriginalThreadId = true;
228    
229                            _originalThreadId = _threadId;
230                    }
231    
232                    _threadId = threadId;
233            }
234    
235            public long getOriginalThreadId() {
236                    return _originalThreadId;
237            }
238    
239            public long getColumnBitmask() {
240                    return _columnBitmask;
241            }
242    
243            @Override
244            public ExpandoBridge getExpandoBridge() {
245                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
246                            MBDiscussion.class.getName(), getPrimaryKey());
247            }
248    
249            @Override
250            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
251                    ExpandoBridge expandoBridge = getExpandoBridge();
252    
253                    expandoBridge.setAttributes(serviceContext);
254            }
255    
256            @Override
257            public MBDiscussion toEscapedModel() {
258                    if (_escapedModel == null) {
259                            _escapedModel = (MBDiscussion)ProxyUtil.newProxyInstance(_classLoader,
260                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
261                    }
262    
263                    return _escapedModel;
264            }
265    
266            public MBDiscussion toUnescapedModel() {
267                    return (MBDiscussion)this;
268            }
269    
270            @Override
271            public Object clone() {
272                    MBDiscussionImpl mbDiscussionImpl = new MBDiscussionImpl();
273    
274                    mbDiscussionImpl.setDiscussionId(getDiscussionId());
275                    mbDiscussionImpl.setClassNameId(getClassNameId());
276                    mbDiscussionImpl.setClassPK(getClassPK());
277                    mbDiscussionImpl.setThreadId(getThreadId());
278    
279                    mbDiscussionImpl.resetOriginalValues();
280    
281                    return mbDiscussionImpl;
282            }
283    
284            public int compareTo(MBDiscussion mbDiscussion) {
285                    long primaryKey = mbDiscussion.getPrimaryKey();
286    
287                    if (getPrimaryKey() < primaryKey) {
288                            return -1;
289                    }
290                    else if (getPrimaryKey() > primaryKey) {
291                            return 1;
292                    }
293                    else {
294                            return 0;
295                    }
296            }
297    
298            @Override
299            public boolean equals(Object obj) {
300                    if (this == obj) {
301                            return true;
302                    }
303    
304                    if (!(obj instanceof MBDiscussion)) {
305                            return false;
306                    }
307    
308                    MBDiscussion mbDiscussion = (MBDiscussion)obj;
309    
310                    long primaryKey = mbDiscussion.getPrimaryKey();
311    
312                    if (getPrimaryKey() == primaryKey) {
313                            return true;
314                    }
315                    else {
316                            return false;
317                    }
318            }
319    
320            @Override
321            public int hashCode() {
322                    return (int)getPrimaryKey();
323            }
324    
325            @Override
326            public void resetOriginalValues() {
327                    MBDiscussionModelImpl mbDiscussionModelImpl = this;
328    
329                    mbDiscussionModelImpl._originalClassNameId = mbDiscussionModelImpl._classNameId;
330    
331                    mbDiscussionModelImpl._setOriginalClassNameId = false;
332    
333                    mbDiscussionModelImpl._originalClassPK = mbDiscussionModelImpl._classPK;
334    
335                    mbDiscussionModelImpl._setOriginalClassPK = false;
336    
337                    mbDiscussionModelImpl._originalThreadId = mbDiscussionModelImpl._threadId;
338    
339                    mbDiscussionModelImpl._setOriginalThreadId = false;
340    
341                    mbDiscussionModelImpl._columnBitmask = 0;
342            }
343    
344            @Override
345            public CacheModel<MBDiscussion> toCacheModel() {
346                    MBDiscussionCacheModel mbDiscussionCacheModel = new MBDiscussionCacheModel();
347    
348                    mbDiscussionCacheModel.discussionId = getDiscussionId();
349    
350                    mbDiscussionCacheModel.classNameId = getClassNameId();
351    
352                    mbDiscussionCacheModel.classPK = getClassPK();
353    
354                    mbDiscussionCacheModel.threadId = getThreadId();
355    
356                    return mbDiscussionCacheModel;
357            }
358    
359            @Override
360            public String toString() {
361                    StringBundler sb = new StringBundler(9);
362    
363                    sb.append("{discussionId=");
364                    sb.append(getDiscussionId());
365                    sb.append(", classNameId=");
366                    sb.append(getClassNameId());
367                    sb.append(", classPK=");
368                    sb.append(getClassPK());
369                    sb.append(", threadId=");
370                    sb.append(getThreadId());
371                    sb.append("}");
372    
373                    return sb.toString();
374            }
375    
376            public String toXmlString() {
377                    StringBundler sb = new StringBundler(16);
378    
379                    sb.append("<model><model-name>");
380                    sb.append("com.liferay.portlet.messageboards.model.MBDiscussion");
381                    sb.append("</model-name>");
382    
383                    sb.append(
384                            "<column><column-name>discussionId</column-name><column-value><![CDATA[");
385                    sb.append(getDiscussionId());
386                    sb.append("]]></column-value></column>");
387                    sb.append(
388                            "<column><column-name>classNameId</column-name><column-value><![CDATA[");
389                    sb.append(getClassNameId());
390                    sb.append("]]></column-value></column>");
391                    sb.append(
392                            "<column><column-name>classPK</column-name><column-value><![CDATA[");
393                    sb.append(getClassPK());
394                    sb.append("]]></column-value></column>");
395                    sb.append(
396                            "<column><column-name>threadId</column-name><column-value><![CDATA[");
397                    sb.append(getThreadId());
398                    sb.append("]]></column-value></column>");
399    
400                    sb.append("</model>");
401    
402                    return sb.toString();
403            }
404    
405            private static ClassLoader _classLoader = MBDiscussion.class.getClassLoader();
406            private static Class<?>[] _escapedModelInterfaces = new Class[] {
407                            MBDiscussion.class
408                    };
409            private long _discussionId;
410            private long _classNameId;
411            private long _originalClassNameId;
412            private boolean _setOriginalClassNameId;
413            private long _classPK;
414            private long _originalClassPK;
415            private boolean _setOriginalClassPK;
416            private long _threadId;
417            private long _originalThreadId;
418            private boolean _setOriginalThreadId;
419            private long _columnBitmask;
420            private MBDiscussion _escapedModel;
421    }