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