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.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 ORDER_BY_JPQL = " ORDER BY portletPreferences.portletPreferencesId ASC";
074            public static final String ORDER_BY_SQL = " ORDER BY PortletPreferences.portletPreferencesId ASC";
075            public static final String DATA_SOURCE = "liferayDataSource";
076            public static final String SESSION_FACTORY = "liferaySessionFactory";
077            public static final String TX_MANAGER = "liferayTransactionManager";
078            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079                                    "value.object.entity.cache.enabled.com.liferay.portal.model.PortletPreferences"),
080                            true);
081            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.finder.cache.enabled.com.liferay.portal.model.PortletPreferences"),
083                            true);
084            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
085                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.PortletPreferences"),
086                            true);
087            public static long OWNERID_COLUMN_BITMASK = 1L;
088            public static long OWNERTYPE_COLUMN_BITMASK = 2L;
089            public static long PLID_COLUMN_BITMASK = 4L;
090            public static long PORTLETID_COLUMN_BITMASK = 8L;
091            public static long PORTLETPREFERENCESID_COLUMN_BITMASK = 16L;
092    
093            /**
094             * Converts the soap model instance into a normal model instance.
095             *
096             * @param soapModel the soap model instance to convert
097             * @return the normal model instance
098             */
099            public static PortletPreferences toModel(PortletPreferencesSoap soapModel) {
100                    if (soapModel == null) {
101                            return null;
102                    }
103    
104                    PortletPreferences model = new PortletPreferencesImpl();
105    
106                    model.setPortletPreferencesId(soapModel.getPortletPreferencesId());
107                    model.setOwnerId(soapModel.getOwnerId());
108                    model.setOwnerType(soapModel.getOwnerType());
109                    model.setPlid(soapModel.getPlid());
110                    model.setPortletId(soapModel.getPortletId());
111                    model.setPreferences(soapModel.getPreferences());
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<PortletPreferences> toModels(
123                    PortletPreferencesSoap[] soapModels) {
124                    if (soapModels == null) {
125                            return null;
126                    }
127    
128                    List<PortletPreferences> models = new ArrayList<PortletPreferences>(soapModels.length);
129    
130                    for (PortletPreferencesSoap 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.portal.model.PortletPreferences"));
139    
140            public PortletPreferencesModelImpl() {
141            }
142    
143            public long getPrimaryKey() {
144                    return _portletPreferencesId;
145            }
146    
147            public void setPrimaryKey(long primaryKey) {
148                    setPortletPreferencesId(primaryKey);
149            }
150    
151            public Serializable getPrimaryKeyObj() {
152                    return _portletPreferencesId;
153            }
154    
155            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
156                    setPrimaryKey(((Long)primaryKeyObj).longValue());
157            }
158    
159            public Class<?> getModelClass() {
160                    return PortletPreferences.class;
161            }
162    
163            public String getModelClassName() {
164                    return PortletPreferences.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("portletPreferencesId", getPortletPreferencesId());
172                    attributes.put("ownerId", getOwnerId());
173                    attributes.put("ownerType", getOwnerType());
174                    attributes.put("plid", getPlid());
175                    attributes.put("portletId", getPortletId());
176                    attributes.put("preferences", getPreferences());
177    
178                    return attributes;
179            }
180    
181            @Override
182            public void setModelAttributes(Map<String, Object> attributes) {
183                    Long portletPreferencesId = (Long)attributes.get("portletPreferencesId");
184    
185                    if (portletPreferencesId != null) {
186                            setPortletPreferencesId(portletPreferencesId);
187                    }
188    
189                    Long ownerId = (Long)attributes.get("ownerId");
190    
191                    if (ownerId != null) {
192                            setOwnerId(ownerId);
193                    }
194    
195                    Integer ownerType = (Integer)attributes.get("ownerType");
196    
197                    if (ownerType != null) {
198                            setOwnerType(ownerType);
199                    }
200    
201                    Long plid = (Long)attributes.get("plid");
202    
203                    if (plid != null) {
204                            setPlid(plid);
205                    }
206    
207                    String portletId = (String)attributes.get("portletId");
208    
209                    if (portletId != null) {
210                            setPortletId(portletId);
211                    }
212    
213                    String preferences = (String)attributes.get("preferences");
214    
215                    if (preferences != null) {
216                            setPreferences(preferences);
217                    }
218            }
219    
220            @JSON
221            public long getPortletPreferencesId() {
222                    return _portletPreferencesId;
223            }
224    
225            public void setPortletPreferencesId(long portletPreferencesId) {
226                    _portletPreferencesId = portletPreferencesId;
227            }
228    
229            @JSON
230            public long getOwnerId() {
231                    return _ownerId;
232            }
233    
234            public void setOwnerId(long ownerId) {
235                    _columnBitmask |= OWNERID_COLUMN_BITMASK;
236    
237                    if (!_setOriginalOwnerId) {
238                            _setOriginalOwnerId = true;
239    
240                            _originalOwnerId = _ownerId;
241                    }
242    
243                    _ownerId = ownerId;
244            }
245    
246            public long getOriginalOwnerId() {
247                    return _originalOwnerId;
248            }
249    
250            @JSON
251            public int getOwnerType() {
252                    return _ownerType;
253            }
254    
255            public void setOwnerType(int ownerType) {
256                    _columnBitmask |= OWNERTYPE_COLUMN_BITMASK;
257    
258                    if (!_setOriginalOwnerType) {
259                            _setOriginalOwnerType = true;
260    
261                            _originalOwnerType = _ownerType;
262                    }
263    
264                    _ownerType = ownerType;
265            }
266    
267            public int getOriginalOwnerType() {
268                    return _originalOwnerType;
269            }
270    
271            @JSON
272            public long getPlid() {
273                    return _plid;
274            }
275    
276            public void setPlid(long plid) {
277                    _columnBitmask |= PLID_COLUMN_BITMASK;
278    
279                    if (!_setOriginalPlid) {
280                            _setOriginalPlid = true;
281    
282                            _originalPlid = _plid;
283                    }
284    
285                    _plid = plid;
286            }
287    
288            public long getOriginalPlid() {
289                    return _originalPlid;
290            }
291    
292            @JSON
293            public String getPortletId() {
294                    if (_portletId == null) {
295                            return StringPool.BLANK;
296                    }
297                    else {
298                            return _portletId;
299                    }
300            }
301    
302            public void setPortletId(String portletId) {
303                    _columnBitmask |= PORTLETID_COLUMN_BITMASK;
304    
305                    if (_originalPortletId == null) {
306                            _originalPortletId = _portletId;
307                    }
308    
309                    _portletId = portletId;
310            }
311    
312            public String getOriginalPortletId() {
313                    return GetterUtil.getString(_originalPortletId);
314            }
315    
316            @JSON
317            public String getPreferences() {
318                    if (_preferences == null) {
319                            return StringPool.BLANK;
320                    }
321                    else {
322                            return _preferences;
323                    }
324            }
325    
326            public void setPreferences(String preferences) {
327                    _preferences = preferences;
328            }
329    
330            public long getColumnBitmask() {
331                    return _columnBitmask;
332            }
333    
334            @Override
335            public ExpandoBridge getExpandoBridge() {
336                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
337                            PortletPreferences.class.getName(), getPrimaryKey());
338            }
339    
340            @Override
341            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
342                    ExpandoBridge expandoBridge = getExpandoBridge();
343    
344                    expandoBridge.setAttributes(serviceContext);
345            }
346    
347            @Override
348            public PortletPreferences toEscapedModel() {
349                    if (_escapedModel == null) {
350                            _escapedModel = (PortletPreferences)ProxyUtil.newProxyInstance(_classLoader,
351                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
352                    }
353    
354                    return _escapedModel;
355            }
356    
357            @Override
358            public Object clone() {
359                    PortletPreferencesImpl portletPreferencesImpl = new PortletPreferencesImpl();
360    
361                    portletPreferencesImpl.setPortletPreferencesId(getPortletPreferencesId());
362                    portletPreferencesImpl.setOwnerId(getOwnerId());
363                    portletPreferencesImpl.setOwnerType(getOwnerType());
364                    portletPreferencesImpl.setPlid(getPlid());
365                    portletPreferencesImpl.setPortletId(getPortletId());
366                    portletPreferencesImpl.setPreferences(getPreferences());
367    
368                    portletPreferencesImpl.resetOriginalValues();
369    
370                    return portletPreferencesImpl;
371            }
372    
373            public int compareTo(PortletPreferences portletPreferences) {
374                    long primaryKey = portletPreferences.getPrimaryKey();
375    
376                    if (getPrimaryKey() < primaryKey) {
377                            return -1;
378                    }
379                    else if (getPrimaryKey() > primaryKey) {
380                            return 1;
381                    }
382                    else {
383                            return 0;
384                    }
385            }
386    
387            @Override
388            public boolean equals(Object obj) {
389                    if (obj == null) {
390                            return false;
391                    }
392    
393                    PortletPreferences portletPreferences = null;
394    
395                    try {
396                            portletPreferences = (PortletPreferences)obj;
397                    }
398                    catch (ClassCastException cce) {
399                            return false;
400                    }
401    
402                    long primaryKey = portletPreferences.getPrimaryKey();
403    
404                    if (getPrimaryKey() == primaryKey) {
405                            return true;
406                    }
407                    else {
408                            return false;
409                    }
410            }
411    
412            @Override
413            public int hashCode() {
414                    return (int)getPrimaryKey();
415            }
416    
417            @Override
418            public void resetOriginalValues() {
419                    PortletPreferencesModelImpl portletPreferencesModelImpl = this;
420    
421                    portletPreferencesModelImpl._originalOwnerId = portletPreferencesModelImpl._ownerId;
422    
423                    portletPreferencesModelImpl._setOriginalOwnerId = false;
424    
425                    portletPreferencesModelImpl._originalOwnerType = portletPreferencesModelImpl._ownerType;
426    
427                    portletPreferencesModelImpl._setOriginalOwnerType = false;
428    
429                    portletPreferencesModelImpl._originalPlid = portletPreferencesModelImpl._plid;
430    
431                    portletPreferencesModelImpl._setOriginalPlid = false;
432    
433                    portletPreferencesModelImpl._originalPortletId = portletPreferencesModelImpl._portletId;
434    
435                    portletPreferencesModelImpl._columnBitmask = 0;
436            }
437    
438            @Override
439            public CacheModel<PortletPreferences> toCacheModel() {
440                    PortletPreferencesCacheModel portletPreferencesCacheModel = new PortletPreferencesCacheModel();
441    
442                    portletPreferencesCacheModel.portletPreferencesId = getPortletPreferencesId();
443    
444                    portletPreferencesCacheModel.ownerId = getOwnerId();
445    
446                    portletPreferencesCacheModel.ownerType = getOwnerType();
447    
448                    portletPreferencesCacheModel.plid = getPlid();
449    
450                    portletPreferencesCacheModel.portletId = getPortletId();
451    
452                    String portletId = portletPreferencesCacheModel.portletId;
453    
454                    if ((portletId != null) && (portletId.length() == 0)) {
455                            portletPreferencesCacheModel.portletId = null;
456                    }
457    
458                    portletPreferencesCacheModel.preferences = getPreferences();
459    
460                    String preferences = portletPreferencesCacheModel.preferences;
461    
462                    if ((preferences != null) && (preferences.length() == 0)) {
463                            portletPreferencesCacheModel.preferences = null;
464                    }
465    
466                    return portletPreferencesCacheModel;
467            }
468    
469            @Override
470            public String toString() {
471                    StringBundler sb = new StringBundler(13);
472    
473                    sb.append("{portletPreferencesId=");
474                    sb.append(getPortletPreferencesId());
475                    sb.append(", ownerId=");
476                    sb.append(getOwnerId());
477                    sb.append(", ownerType=");
478                    sb.append(getOwnerType());
479                    sb.append(", plid=");
480                    sb.append(getPlid());
481                    sb.append(", portletId=");
482                    sb.append(getPortletId());
483                    sb.append(", preferences=");
484                    sb.append(getPreferences());
485                    sb.append("}");
486    
487                    return sb.toString();
488            }
489    
490            public String toXmlString() {
491                    StringBundler sb = new StringBundler(22);
492    
493                    sb.append("<model><model-name>");
494                    sb.append("com.liferay.portal.model.PortletPreferences");
495                    sb.append("</model-name>");
496    
497                    sb.append(
498                            "<column><column-name>portletPreferencesId</column-name><column-value><![CDATA[");
499                    sb.append(getPortletPreferencesId());
500                    sb.append("]]></column-value></column>");
501                    sb.append(
502                            "<column><column-name>ownerId</column-name><column-value><![CDATA[");
503                    sb.append(getOwnerId());
504                    sb.append("]]></column-value></column>");
505                    sb.append(
506                            "<column><column-name>ownerType</column-name><column-value><![CDATA[");
507                    sb.append(getOwnerType());
508                    sb.append("]]></column-value></column>");
509                    sb.append(
510                            "<column><column-name>plid</column-name><column-value><![CDATA[");
511                    sb.append(getPlid());
512                    sb.append("]]></column-value></column>");
513                    sb.append(
514                            "<column><column-name>portletId</column-name><column-value><![CDATA[");
515                    sb.append(getPortletId());
516                    sb.append("]]></column-value></column>");
517                    sb.append(
518                            "<column><column-name>preferences</column-name><column-value><![CDATA[");
519                    sb.append(getPreferences());
520                    sb.append("]]></column-value></column>");
521    
522                    sb.append("</model>");
523    
524                    return sb.toString();
525            }
526    
527            private static ClassLoader _classLoader = PortletPreferences.class.getClassLoader();
528            private static Class<?>[] _escapedModelInterfaces = new Class[] {
529                            PortletPreferences.class
530                    };
531            private long _portletPreferencesId;
532            private long _ownerId;
533            private long _originalOwnerId;
534            private boolean _setOriginalOwnerId;
535            private int _ownerType;
536            private int _originalOwnerType;
537            private boolean _setOriginalOwnerType;
538            private long _plid;
539            private long _originalPlid;
540            private boolean _setOriginalPlid;
541            private String _portletId;
542            private String _originalPortletId;
543            private String _preferences;
544            private long _columnBitmask;
545            private PortletPreferences _escapedModel;
546    }