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