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