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