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.announcements.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.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.announcements.model.AnnouncementsFlag;
030    import com.liferay.portlet.announcements.model.AnnouncementsFlagModel;
031    import com.liferay.portlet.announcements.model.AnnouncementsFlagSoap;
032    import com.liferay.portlet.expando.model.ExpandoBridge;
033    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
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.HashMap;
042    import java.util.List;
043    import java.util.Map;
044    
045    /**
046     * The base model implementation for the AnnouncementsFlag service. Represents a row in the "AnnouncementsFlag" database table, with each column mapped to a property of this class.
047     *
048     * <p>
049     * This implementation and its corresponding interface {@link com.liferay.portlet.announcements.model.AnnouncementsFlagModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AnnouncementsFlagImpl}.
050     * </p>
051     *
052     * @author Brian Wing Shun Chan
053     * @see AnnouncementsFlagImpl
054     * @see com.liferay.portlet.announcements.model.AnnouncementsFlag
055     * @see com.liferay.portlet.announcements.model.AnnouncementsFlagModel
056     * @generated
057     */
058    @JSON(strict = true)
059    public class AnnouncementsFlagModelImpl extends BaseModelImpl<AnnouncementsFlag>
060            implements AnnouncementsFlagModel {
061            /*
062             * NOTE FOR DEVELOPERS:
063             *
064             * Never modify or reference this class directly. All methods that expect a announcements flag model instance should use the {@link com.liferay.portlet.announcements.model.AnnouncementsFlag} interface instead.
065             */
066            public static final String TABLE_NAME = "AnnouncementsFlag";
067            public static final Object[][] TABLE_COLUMNS = {
068                            { "flagId", Types.BIGINT },
069                            { "userId", Types.BIGINT },
070                            { "createDate", Types.TIMESTAMP },
071                            { "entryId", Types.BIGINT },
072                            { "value", Types.INTEGER }
073                    };
074            public static final String TABLE_SQL_CREATE = "create table AnnouncementsFlag (flagId LONG not null primary key,userId LONG,createDate DATE null,entryId LONG,value INTEGER)";
075            public static final String TABLE_SQL_DROP = "drop table AnnouncementsFlag";
076            public static final String ORDER_BY_JPQL = " ORDER BY announcementsFlag.userId ASC, announcementsFlag.createDate ASC";
077            public static final String ORDER_BY_SQL = " ORDER BY AnnouncementsFlag.userId ASC, AnnouncementsFlag.createDate ASC";
078            public static final String DATA_SOURCE = "liferayDataSource";
079            public static final String SESSION_FACTORY = "liferaySessionFactory";
080            public static final String TX_MANAGER = "liferayTransactionManager";
081            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.entity.cache.enabled.com.liferay.portlet.announcements.model.AnnouncementsFlag"),
083                            true);
084            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
085                                    "value.object.finder.cache.enabled.com.liferay.portlet.announcements.model.AnnouncementsFlag"),
086                            true);
087            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
088                                    "value.object.column.bitmask.enabled.com.liferay.portlet.announcements.model.AnnouncementsFlag"),
089                            true);
090            public static long ENTRYID_COLUMN_BITMASK = 1L;
091            public static long USERID_COLUMN_BITMASK = 2L;
092            public static long VALUE_COLUMN_BITMASK = 4L;
093    
094            /**
095             * Converts the soap model instance into a normal model instance.
096             *
097             * @param soapModel the soap model instance to convert
098             * @return the normal model instance
099             */
100            public static AnnouncementsFlag toModel(AnnouncementsFlagSoap soapModel) {
101                    if (soapModel == null) {
102                            return null;
103                    }
104    
105                    AnnouncementsFlag model = new AnnouncementsFlagImpl();
106    
107                    model.setFlagId(soapModel.getFlagId());
108                    model.setUserId(soapModel.getUserId());
109                    model.setCreateDate(soapModel.getCreateDate());
110                    model.setEntryId(soapModel.getEntryId());
111                    model.setValue(soapModel.getValue());
112    
113                    return model;
114            }
115    
116            /**
117             * Converts the soap model instances into normal model instances.
118             *
119             * @param soapModels the soap model instances to convert
120             * @return the normal model instances
121             */
122            public static List<AnnouncementsFlag> toModels(
123                    AnnouncementsFlagSoap[] soapModels) {
124                    if (soapModels == null) {
125                            return null;
126                    }
127    
128                    List<AnnouncementsFlag> models = new ArrayList<AnnouncementsFlag>(soapModels.length);
129    
130                    for (AnnouncementsFlagSoap soapModel : soapModels) {
131                            models.add(toModel(soapModel));
132                    }
133    
134                    return models;
135            }
136    
137            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
138                                    "lock.expiration.time.com.liferay.portlet.announcements.model.AnnouncementsFlag"));
139    
140            public AnnouncementsFlagModelImpl() {
141            }
142    
143            public long getPrimaryKey() {
144                    return _flagId;
145            }
146    
147            public void setPrimaryKey(long primaryKey) {
148                    setFlagId(primaryKey);
149            }
150    
151            public Serializable getPrimaryKeyObj() {
152                    return new Long(_flagId);
153            }
154    
155            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
156                    setPrimaryKey(((Long)primaryKeyObj).longValue());
157            }
158    
159            public Class<?> getModelClass() {
160                    return AnnouncementsFlag.class;
161            }
162    
163            public String getModelClassName() {
164                    return AnnouncementsFlag.class.getName();
165            }
166    
167            @Override
168            public Map<String, Object> getModelAttributes() {
169                    Map<String, Object> attributes = new HashMap<String, Object>();
170    
171                    attributes.put("flagId", getFlagId());
172                    attributes.put("userId", getUserId());
173                    attributes.put("createDate", getCreateDate());
174                    attributes.put("entryId", getEntryId());
175                    attributes.put("value", getValue());
176    
177                    return attributes;
178            }
179    
180            @Override
181            public void setModelAttributes(Map<String, Object> attributes) {
182                    Long flagId = (Long)attributes.get("flagId");
183    
184                    if (flagId != null) {
185                            setFlagId(flagId);
186                    }
187    
188                    Long userId = (Long)attributes.get("userId");
189    
190                    if (userId != null) {
191                            setUserId(userId);
192                    }
193    
194                    Date createDate = (Date)attributes.get("createDate");
195    
196                    if (createDate != null) {
197                            setCreateDate(createDate);
198                    }
199    
200                    Long entryId = (Long)attributes.get("entryId");
201    
202                    if (entryId != null) {
203                            setEntryId(entryId);
204                    }
205    
206                    Integer value = (Integer)attributes.get("value");
207    
208                    if (value != null) {
209                            setValue(value);
210                    }
211            }
212    
213            @JSON
214            public long getFlagId() {
215                    return _flagId;
216            }
217    
218            public void setFlagId(long flagId) {
219                    _flagId = flagId;
220            }
221    
222            @JSON
223            public long getUserId() {
224                    return _userId;
225            }
226    
227            public void setUserId(long userId) {
228                    _columnBitmask = -1L;
229    
230                    if (!_setOriginalUserId) {
231                            _setOriginalUserId = true;
232    
233                            _originalUserId = _userId;
234                    }
235    
236                    _userId = userId;
237            }
238    
239            public String getUserUuid() throws SystemException {
240                    return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
241            }
242    
243            public void setUserUuid(String userUuid) {
244                    _userUuid = userUuid;
245            }
246    
247            public long getOriginalUserId() {
248                    return _originalUserId;
249            }
250    
251            @JSON
252            public Date getCreateDate() {
253                    return _createDate;
254            }
255    
256            public void setCreateDate(Date createDate) {
257                    _columnBitmask = -1L;
258    
259                    _createDate = createDate;
260            }
261    
262            @JSON
263            public long getEntryId() {
264                    return _entryId;
265            }
266    
267            public void setEntryId(long entryId) {
268                    _columnBitmask |= ENTRYID_COLUMN_BITMASK;
269    
270                    if (!_setOriginalEntryId) {
271                            _setOriginalEntryId = true;
272    
273                            _originalEntryId = _entryId;
274                    }
275    
276                    _entryId = entryId;
277            }
278    
279            public long getOriginalEntryId() {
280                    return _originalEntryId;
281            }
282    
283            @JSON
284            public int getValue() {
285                    return _value;
286            }
287    
288            public void setValue(int value) {
289                    _columnBitmask |= VALUE_COLUMN_BITMASK;
290    
291                    if (!_setOriginalValue) {
292                            _setOriginalValue = true;
293    
294                            _originalValue = _value;
295                    }
296    
297                    _value = value;
298            }
299    
300            public int getOriginalValue() {
301                    return _originalValue;
302            }
303    
304            public long getColumnBitmask() {
305                    return _columnBitmask;
306            }
307    
308            @Override
309            public ExpandoBridge getExpandoBridge() {
310                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
311                            AnnouncementsFlag.class.getName(), getPrimaryKey());
312            }
313    
314            @Override
315            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
316                    ExpandoBridge expandoBridge = getExpandoBridge();
317    
318                    expandoBridge.setAttributes(serviceContext);
319            }
320    
321            @Override
322            public AnnouncementsFlag toEscapedModel() {
323                    if (_escapedModel == null) {
324                            _escapedModel = (AnnouncementsFlag)ProxyUtil.newProxyInstance(_classLoader,
325                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
326                    }
327    
328                    return _escapedModel;
329            }
330    
331            public AnnouncementsFlag toUnescapedModel() {
332                    return (AnnouncementsFlag)this;
333            }
334    
335            @Override
336            public Object clone() {
337                    AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();
338    
339                    announcementsFlagImpl.setFlagId(getFlagId());
340                    announcementsFlagImpl.setUserId(getUserId());
341                    announcementsFlagImpl.setCreateDate(getCreateDate());
342                    announcementsFlagImpl.setEntryId(getEntryId());
343                    announcementsFlagImpl.setValue(getValue());
344    
345                    announcementsFlagImpl.resetOriginalValues();
346    
347                    return announcementsFlagImpl;
348            }
349    
350            public int compareTo(AnnouncementsFlag announcementsFlag) {
351                    int value = 0;
352    
353                    if (getUserId() < announcementsFlag.getUserId()) {
354                            value = -1;
355                    }
356                    else if (getUserId() > announcementsFlag.getUserId()) {
357                            value = 1;
358                    }
359                    else {
360                            value = 0;
361                    }
362    
363                    if (value != 0) {
364                            return value;
365                    }
366    
367                    value = DateUtil.compareTo(getCreateDate(),
368                                    announcementsFlag.getCreateDate());
369    
370                    if (value != 0) {
371                            return value;
372                    }
373    
374                    return 0;
375            }
376    
377            @Override
378            public boolean equals(Object obj) {
379                    if (this == obj) {
380                            return true;
381                    }
382    
383                    if (!(obj instanceof AnnouncementsFlag)) {
384                            return false;
385                    }
386    
387                    AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)obj;
388    
389                    long primaryKey = announcementsFlag.getPrimaryKey();
390    
391                    if (getPrimaryKey() == primaryKey) {
392                            return true;
393                    }
394                    else {
395                            return false;
396                    }
397            }
398    
399            @Override
400            public int hashCode() {
401                    return (int)getPrimaryKey();
402            }
403    
404            @Override
405            public void resetOriginalValues() {
406                    AnnouncementsFlagModelImpl announcementsFlagModelImpl = this;
407    
408                    announcementsFlagModelImpl._originalUserId = announcementsFlagModelImpl._userId;
409    
410                    announcementsFlagModelImpl._setOriginalUserId = false;
411    
412                    announcementsFlagModelImpl._originalEntryId = announcementsFlagModelImpl._entryId;
413    
414                    announcementsFlagModelImpl._setOriginalEntryId = false;
415    
416                    announcementsFlagModelImpl._originalValue = announcementsFlagModelImpl._value;
417    
418                    announcementsFlagModelImpl._setOriginalValue = false;
419    
420                    announcementsFlagModelImpl._columnBitmask = 0;
421            }
422    
423            @Override
424            public CacheModel<AnnouncementsFlag> toCacheModel() {
425                    AnnouncementsFlagCacheModel announcementsFlagCacheModel = new AnnouncementsFlagCacheModel();
426    
427                    announcementsFlagCacheModel.flagId = getFlagId();
428    
429                    announcementsFlagCacheModel.userId = getUserId();
430    
431                    Date createDate = getCreateDate();
432    
433                    if (createDate != null) {
434                            announcementsFlagCacheModel.createDate = createDate.getTime();
435                    }
436                    else {
437                            announcementsFlagCacheModel.createDate = Long.MIN_VALUE;
438                    }
439    
440                    announcementsFlagCacheModel.entryId = getEntryId();
441    
442                    announcementsFlagCacheModel.value = getValue();
443    
444                    return announcementsFlagCacheModel;
445            }
446    
447            @Override
448            public String toString() {
449                    StringBundler sb = new StringBundler(11);
450    
451                    sb.append("{flagId=");
452                    sb.append(getFlagId());
453                    sb.append(", userId=");
454                    sb.append(getUserId());
455                    sb.append(", createDate=");
456                    sb.append(getCreateDate());
457                    sb.append(", entryId=");
458                    sb.append(getEntryId());
459                    sb.append(", value=");
460                    sb.append(getValue());
461                    sb.append("}");
462    
463                    return sb.toString();
464            }
465    
466            public String toXmlString() {
467                    StringBundler sb = new StringBundler(19);
468    
469                    sb.append("<model><model-name>");
470                    sb.append("com.liferay.portlet.announcements.model.AnnouncementsFlag");
471                    sb.append("</model-name>");
472    
473                    sb.append(
474                            "<column><column-name>flagId</column-name><column-value><![CDATA[");
475                    sb.append(getFlagId());
476                    sb.append("]]></column-value></column>");
477                    sb.append(
478                            "<column><column-name>userId</column-name><column-value><![CDATA[");
479                    sb.append(getUserId());
480                    sb.append("]]></column-value></column>");
481                    sb.append(
482                            "<column><column-name>createDate</column-name><column-value><![CDATA[");
483                    sb.append(getCreateDate());
484                    sb.append("]]></column-value></column>");
485                    sb.append(
486                            "<column><column-name>entryId</column-name><column-value><![CDATA[");
487                    sb.append(getEntryId());
488                    sb.append("]]></column-value></column>");
489                    sb.append(
490                            "<column><column-name>value</column-name><column-value><![CDATA[");
491                    sb.append(getValue());
492                    sb.append("]]></column-value></column>");
493    
494                    sb.append("</model>");
495    
496                    return sb.toString();
497            }
498    
499            private static ClassLoader _classLoader = AnnouncementsFlag.class.getClassLoader();
500            private static Class<?>[] _escapedModelInterfaces = new Class[] {
501                            AnnouncementsFlag.class
502                    };
503            private long _flagId;
504            private long _userId;
505            private String _userUuid;
506            private long _originalUserId;
507            private boolean _setOriginalUserId;
508            private Date _createDate;
509            private long _entryId;
510            private long _originalEntryId;
511            private boolean _setOriginalEntryId;
512            private int _value;
513            private int _originalValue;
514            private boolean _setOriginalValue;
515            private long _columnBitmask;
516            private AnnouncementsFlag _escapedModel;
517    }