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