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.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            public long getPrimaryKey() {
139                    return _id;
140            }
141    
142            public void setPrimaryKey(long primaryKey) {
143                    setId(primaryKey);
144            }
145    
146            public Serializable getPrimaryKeyObj() {
147                    return _id;
148            }
149    
150            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
151                    setPrimaryKey(((Long)primaryKeyObj).longValue());
152            }
153    
154            public Class<?> getModelClass() {
155                    return Portlet.class;
156            }
157    
158            public String getModelClassName() {
159                    return Portlet.class.getName();
160            }
161    
162            @Override
163            public Map<String, Object> getModelAttributes() {
164                    Map<String, Object> attributes = new HashMap<String, Object>();
165    
166                    attributes.put("id", getId());
167                    attributes.put("companyId", getCompanyId());
168                    attributes.put("portletId", getPortletId());
169                    attributes.put("roles", getRoles());
170                    attributes.put("active", getActive());
171    
172                    return attributes;
173            }
174    
175            @Override
176            public void setModelAttributes(Map<String, Object> attributes) {
177                    Long id = (Long)attributes.get("id");
178    
179                    if (id != null) {
180                            setId(id);
181                    }
182    
183                    Long companyId = (Long)attributes.get("companyId");
184    
185                    if (companyId != null) {
186                            setCompanyId(companyId);
187                    }
188    
189                    String portletId = (String)attributes.get("portletId");
190    
191                    if (portletId != null) {
192                            setPortletId(portletId);
193                    }
194    
195                    String roles = (String)attributes.get("roles");
196    
197                    if (roles != null) {
198                            setRoles(roles);
199                    }
200    
201                    Boolean active = (Boolean)attributes.get("active");
202    
203                    if (active != null) {
204                            setActive(active);
205                    }
206            }
207    
208            @JSON
209            public long getId() {
210                    return _id;
211            }
212    
213            public void setId(long id) {
214                    _id = id;
215            }
216    
217            @JSON
218            public long getCompanyId() {
219                    return _companyId;
220            }
221    
222            public void setCompanyId(long companyId) {
223                    _columnBitmask |= COMPANYID_COLUMN_BITMASK;
224    
225                    if (!_setOriginalCompanyId) {
226                            _setOriginalCompanyId = true;
227    
228                            _originalCompanyId = _companyId;
229                    }
230    
231                    _companyId = companyId;
232            }
233    
234            public long getOriginalCompanyId() {
235                    return _originalCompanyId;
236            }
237    
238            @JSON
239            public String getPortletId() {
240                    if (_portletId == null) {
241                            return StringPool.BLANK;
242                    }
243                    else {
244                            return _portletId;
245                    }
246            }
247    
248            public void setPortletId(String portletId) {
249                    _columnBitmask |= PORTLETID_COLUMN_BITMASK;
250    
251                    if (_originalPortletId == null) {
252                            _originalPortletId = _portletId;
253                    }
254    
255                    _portletId = portletId;
256            }
257    
258            public String getOriginalPortletId() {
259                    return GetterUtil.getString(_originalPortletId);
260            }
261    
262            @JSON
263            public String getRoles() {
264                    if (_roles == null) {
265                            return StringPool.BLANK;
266                    }
267                    else {
268                            return _roles;
269                    }
270            }
271    
272            public void setRoles(String roles) {
273                    _roles = roles;
274            }
275    
276            @JSON
277            public boolean getActive() {
278                    return _active;
279            }
280    
281            public boolean isActive() {
282                    return _active;
283            }
284    
285            public void setActive(boolean active) {
286                    _active = active;
287            }
288    
289            public long getColumnBitmask() {
290                    return _columnBitmask;
291            }
292    
293            @Override
294            public ExpandoBridge getExpandoBridge() {
295                    return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
296                            Portlet.class.getName(), getPrimaryKey());
297            }
298    
299            @Override
300            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
301                    ExpandoBridge expandoBridge = getExpandoBridge();
302    
303                    expandoBridge.setAttributes(serviceContext);
304            }
305    
306            @Override
307            public Portlet toEscapedModel() {
308                    if (_escapedModel == null) {
309                            _escapedModel = (Portlet)ProxyUtil.newProxyInstance(_classLoader,
310                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
311                    }
312    
313                    return _escapedModel;
314            }
315    
316            @Override
317            public Object clone() {
318                    PortletImpl portletImpl = new PortletImpl();
319    
320                    portletImpl.setId(getId());
321                    portletImpl.setCompanyId(getCompanyId());
322                    portletImpl.setPortletId(getPortletId());
323                    portletImpl.setRoles(getRoles());
324                    portletImpl.setActive(getActive());
325    
326                    portletImpl.resetOriginalValues();
327    
328                    return portletImpl;
329            }
330    
331            public int compareTo(Portlet portlet) {
332                    long primaryKey = portlet.getPrimaryKey();
333    
334                    if (getPrimaryKey() < primaryKey) {
335                            return -1;
336                    }
337                    else if (getPrimaryKey() > primaryKey) {
338                            return 1;
339                    }
340                    else {
341                            return 0;
342                    }
343            }
344    
345            @Override
346            public boolean equals(Object obj) {
347                    if (obj == null) {
348                            return false;
349                    }
350    
351                    Portlet portlet = null;
352    
353                    try {
354                            portlet = (Portlet)obj;
355                    }
356                    catch (ClassCastException cce) {
357                            return false;
358                    }
359    
360                    long primaryKey = portlet.getPrimaryKey();
361    
362                    if (getPrimaryKey() == primaryKey) {
363                            return true;
364                    }
365                    else {
366                            return false;
367                    }
368            }
369    
370            @Override
371            public int hashCode() {
372                    return (int)getPrimaryKey();
373            }
374    
375            @Override
376            public void resetOriginalValues() {
377                    PortletModelImpl portletModelImpl = this;
378    
379                    portletModelImpl._originalCompanyId = portletModelImpl._companyId;
380    
381                    portletModelImpl._setOriginalCompanyId = false;
382    
383                    portletModelImpl._originalPortletId = portletModelImpl._portletId;
384    
385                    portletModelImpl._columnBitmask = 0;
386            }
387    
388            @Override
389            public CacheModel<Portlet> toCacheModel() {
390                    PortletCacheModel portletCacheModel = new PortletCacheModel();
391    
392                    portletCacheModel.id = getId();
393    
394                    portletCacheModel.companyId = getCompanyId();
395    
396                    portletCacheModel.portletId = getPortletId();
397    
398                    String portletId = portletCacheModel.portletId;
399    
400                    if ((portletId != null) && (portletId.length() == 0)) {
401                            portletCacheModel.portletId = null;
402                    }
403    
404                    portletCacheModel.roles = getRoles();
405    
406                    String roles = portletCacheModel.roles;
407    
408                    if ((roles != null) && (roles.length() == 0)) {
409                            portletCacheModel.roles = null;
410                    }
411    
412                    portletCacheModel.active = getActive();
413    
414                    return portletCacheModel;
415            }
416    
417            @Override
418            public String toString() {
419                    StringBundler sb = new StringBundler(11);
420    
421                    sb.append("{id=");
422                    sb.append(getId());
423                    sb.append(", companyId=");
424                    sb.append(getCompanyId());
425                    sb.append(", portletId=");
426                    sb.append(getPortletId());
427                    sb.append(", roles=");
428                    sb.append(getRoles());
429                    sb.append(", active=");
430                    sb.append(getActive());
431                    sb.append("}");
432    
433                    return sb.toString();
434            }
435    
436            public String toXmlString() {
437                    StringBundler sb = new StringBundler(19);
438    
439                    sb.append("<model><model-name>");
440                    sb.append("com.liferay.portal.model.Portlet");
441                    sb.append("</model-name>");
442    
443                    sb.append(
444                            "<column><column-name>id</column-name><column-value><![CDATA[");
445                    sb.append(getId());
446                    sb.append("]]></column-value></column>");
447                    sb.append(
448                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
449                    sb.append(getCompanyId());
450                    sb.append("]]></column-value></column>");
451                    sb.append(
452                            "<column><column-name>portletId</column-name><column-value><![CDATA[");
453                    sb.append(getPortletId());
454                    sb.append("]]></column-value></column>");
455                    sb.append(
456                            "<column><column-name>roles</column-name><column-value><![CDATA[");
457                    sb.append(getRoles());
458                    sb.append("]]></column-value></column>");
459                    sb.append(
460                            "<column><column-name>active</column-name><column-value><![CDATA[");
461                    sb.append(getActive());
462                    sb.append("]]></column-value></column>");
463    
464                    sb.append("</model>");
465    
466                    return sb.toString();
467            }
468    
469            private static ClassLoader _classLoader = Portlet.class.getClassLoader();
470            private static Class<?>[] _escapedModelInterfaces = new Class[] {
471                            Portlet.class
472                    };
473            private long _id;
474            private long _companyId;
475            private long _originalCompanyId;
476            private boolean _setOriginalCompanyId;
477            private String _portletId;
478            private String _originalPortletId;
479            private String _roles;
480            private boolean _active;
481            private long _columnBitmask;
482            private Portlet _escapedModel;
483    }