1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.HtmlUtil;
20  import com.liferay.portal.kernel.util.StringBundler;
21  import com.liferay.portal.model.Portlet;
22  import com.liferay.portal.model.PortletSoap;
23  import com.liferay.portal.service.ServiceContext;
24  
25  import com.liferay.portlet.expando.model.ExpandoBridge;
26  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
27  
28  import java.io.Serializable;
29  
30  import java.lang.reflect.Proxy;
31  
32  import java.sql.Types;
33  
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * <a href="PortletModelImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * <p>
41   * ServiceBuilder generated this class. Modifications in this class will be
42   * overwritten the next time is generated.
43   * </p>
44   *
45   * <p>
46   * This interface is a model that represents the Portlet table in the
47   * database.
48   * </p>
49   *
50   * @author    Brian Wing Shun Chan
51   * @see       PortletImpl
52   * @see       com.liferay.portal.model.Portlet
53   * @see       com.liferay.portal.model.PortletModel
54   * @generated
55   */
56  public class PortletModelImpl extends BaseModelImpl<Portlet> {
57      public static final String TABLE_NAME = "Portlet";
58      public static final Object[][] TABLE_COLUMNS = {
59              { "id_", new Integer(Types.BIGINT) },
60              { "companyId", new Integer(Types.BIGINT) },
61              { "portletId", new Integer(Types.VARCHAR) },
62              { "roles", new Integer(Types.VARCHAR) },
63              { "active_", new Integer(Types.BOOLEAN) }
64          };
65      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)";
66      public static final String TABLE_SQL_DROP = "drop table Portlet";
67      public static final String DATA_SOURCE = "liferayDataSource";
68      public static final String SESSION_FACTORY = "liferaySessionFactory";
69      public static final String TX_MANAGER = "liferayTransactionManager";
70      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
71                  "value.object.entity.cache.enabled.com.liferay.portal.model.Portlet"),
72              true);
73      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
74                  "value.object.finder.cache.enabled.com.liferay.portal.model.Portlet"),
75              true);
76  
77      public static Portlet toModel(PortletSoap soapModel) {
78          Portlet model = new PortletImpl();
79  
80          model.setId(soapModel.getId());
81          model.setCompanyId(soapModel.getCompanyId());
82          model.setPortletId(soapModel.getPortletId());
83          model.setRoles(soapModel.getRoles());
84          model.setActive(soapModel.getActive());
85  
86          return model;
87      }
88  
89      public static List<Portlet> toModels(PortletSoap[] soapModels) {
90          List<Portlet> models = new ArrayList<Portlet>(soapModels.length);
91  
92          for (PortletSoap soapModel : soapModels) {
93              models.add(toModel(soapModel));
94          }
95  
96          return models;
97      }
98  
99      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
100                 "lock.expiration.time.com.liferay.portal.model.Portlet"));
101 
102     public PortletModelImpl() {
103     }
104 
105     public long getPrimaryKey() {
106         return _id;
107     }
108 
109     public void setPrimaryKey(long pk) {
110         setId(pk);
111     }
112 
113     public Serializable getPrimaryKeyObj() {
114         return new Long(_id);
115     }
116 
117     public long getId() {
118         return _id;
119     }
120 
121     public void setId(long id) {
122         _id = id;
123     }
124 
125     public long getCompanyId() {
126         return _companyId;
127     }
128 
129     public void setCompanyId(long companyId) {
130         _companyId = companyId;
131 
132         if (!_setOriginalCompanyId) {
133             _setOriginalCompanyId = true;
134 
135             _originalCompanyId = companyId;
136         }
137     }
138 
139     public long getOriginalCompanyId() {
140         return _originalCompanyId;
141     }
142 
143     public String getPortletId() {
144         return GetterUtil.getString(_portletId);
145     }
146 
147     public void setPortletId(String portletId) {
148         _portletId = portletId;
149 
150         if (_originalPortletId == null) {
151             _originalPortletId = portletId;
152         }
153     }
154 
155     public String getOriginalPortletId() {
156         return GetterUtil.getString(_originalPortletId);
157     }
158 
159     public String getRoles() {
160         return GetterUtil.getString(_roles);
161     }
162 
163     public void setRoles(String roles) {
164         _roles = roles;
165     }
166 
167     public boolean getActive() {
168         return _active;
169     }
170 
171     public boolean isActive() {
172         return _active;
173     }
174 
175     public void setActive(boolean active) {
176         _active = active;
177     }
178 
179     public Portlet toEscapedModel() {
180         if (isEscapedModel()) {
181             return (Portlet)this;
182         }
183         else {
184             Portlet model = new PortletImpl();
185 
186             model.setNew(isNew());
187             model.setEscapedModel(true);
188 
189             model.setId(getId());
190             model.setCompanyId(getCompanyId());
191             model.setPortletId(HtmlUtil.escape(getPortletId()));
192             model.setRoles(HtmlUtil.escape(getRoles()));
193             model.setActive(getActive());
194 
195             model = (Portlet)Proxy.newProxyInstance(Portlet.class.getClassLoader(),
196                     new Class[] { Portlet.class },
197                     new ReadOnlyBeanHandler(model));
198 
199             return model;
200         }
201     }
202 
203     public ExpandoBridge getExpandoBridge() {
204         if (_expandoBridge == null) {
205             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
206                     Portlet.class.getName(), getPrimaryKey());
207         }
208 
209         return _expandoBridge;
210     }
211 
212     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
213         getExpandoBridge().setAttributes(serviceContext);
214     }
215 
216     public Object clone() {
217         PortletImpl clone = new PortletImpl();
218 
219         clone.setId(getId());
220         clone.setCompanyId(getCompanyId());
221         clone.setPortletId(getPortletId());
222         clone.setRoles(getRoles());
223         clone.setActive(getActive());
224 
225         return clone;
226     }
227 
228     public int compareTo(Portlet portlet) {
229         long pk = portlet.getPrimaryKey();
230 
231         if (getPrimaryKey() < pk) {
232             return -1;
233         }
234         else if (getPrimaryKey() > pk) {
235             return 1;
236         }
237         else {
238             return 0;
239         }
240     }
241 
242     public boolean equals(Object obj) {
243         if (obj == null) {
244             return false;
245         }
246 
247         Portlet portlet = null;
248 
249         try {
250             portlet = (Portlet)obj;
251         }
252         catch (ClassCastException cce) {
253             return false;
254         }
255 
256         long pk = portlet.getPrimaryKey();
257 
258         if (getPrimaryKey() == pk) {
259             return true;
260         }
261         else {
262             return false;
263         }
264     }
265 
266     public int hashCode() {
267         return (int)getPrimaryKey();
268     }
269 
270     public String toString() {
271         StringBundler sb = new StringBundler(11);
272 
273         sb.append("{id=");
274         sb.append(getId());
275         sb.append(", companyId=");
276         sb.append(getCompanyId());
277         sb.append(", portletId=");
278         sb.append(getPortletId());
279         sb.append(", roles=");
280         sb.append(getRoles());
281         sb.append(", active=");
282         sb.append(getActive());
283         sb.append("}");
284 
285         return sb.toString();
286     }
287 
288     public String toXmlString() {
289         StringBundler sb = new StringBundler(19);
290 
291         sb.append("<model><model-name>");
292         sb.append("com.liferay.portal.model.Portlet");
293         sb.append("</model-name>");
294 
295         sb.append(
296             "<column><column-name>id</column-name><column-value><![CDATA[");
297         sb.append(getId());
298         sb.append("]]></column-value></column>");
299         sb.append(
300             "<column><column-name>companyId</column-name><column-value><![CDATA[");
301         sb.append(getCompanyId());
302         sb.append("]]></column-value></column>");
303         sb.append(
304             "<column><column-name>portletId</column-name><column-value><![CDATA[");
305         sb.append(getPortletId());
306         sb.append("]]></column-value></column>");
307         sb.append(
308             "<column><column-name>roles</column-name><column-value><![CDATA[");
309         sb.append(getRoles());
310         sb.append("]]></column-value></column>");
311         sb.append(
312             "<column><column-name>active</column-name><column-value><![CDATA[");
313         sb.append(getActive());
314         sb.append("]]></column-value></column>");
315 
316         sb.append("</model>");
317 
318         return sb.toString();
319     }
320 
321     private long _id;
322     private long _companyId;
323     private long _originalCompanyId;
324     private boolean _setOriginalCompanyId;
325     private String _portletId;
326     private String _originalPortletId;
327     private String _roles;
328     private boolean _active;
329     private transient ExpandoBridge _expandoBridge;
330 }