1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.model.impl;
24  
25  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
26  import com.liferay.portal.kernel.util.GetterUtil;
27  import com.liferay.portal.kernel.util.HtmlUtil;
28  import com.liferay.portal.model.Portlet;
29  import com.liferay.portal.model.PortletSoap;
30  
31  import java.io.Serializable;
32  
33  import java.lang.reflect.Proxy;
34  
35  import java.sql.Types;
36  
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  /**
41   * <a href="PortletModelImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * <p>
44   * ServiceBuilder generated this class. Modifications in this class will be
45   * overwritten the next time is generated.
46   * </p>
47   *
48   * <p>
49   * This class is a model that represents the <code>Portlet</code> table
50   * in the database.
51   * </p>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   * @see com.liferay.portal.model.Portlet
56   * @see com.liferay.portal.model.PortletModel
57   * @see com.liferay.portal.model.impl.PortletImpl
58   *
59   */
60  public class PortletModelImpl extends BaseModelImpl<Portlet> {
61      public static final String TABLE_NAME = "Portlet";
62      public static final Object[][] TABLE_COLUMNS = {
63              { "id_", new Integer(Types.BIGINT) },
64              
65  
66              { "companyId", new Integer(Types.BIGINT) },
67              
68  
69              { "portletId", new Integer(Types.VARCHAR) },
70              
71  
72              { "roles", new Integer(Types.VARCHAR) },
73              
74  
75              { "active_", new Integer(Types.BOOLEAN) }
76          };
77      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)";
78      public static final String TABLE_SQL_DROP = "drop table Portlet";
79      public static final String DATA_SOURCE = "liferayDataSource";
80      public static final String SESSION_FACTORY = "liferaySessionFactory";
81      public static final String TX_MANAGER = "liferayTransactionManager";
82      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
83                  "value.object.entity.cache.enabled.com.liferay.portal.model.Portlet"),
84              true);
85      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
86                  "value.object.finder.cache.enabled.com.liferay.portal.model.Portlet"),
87              true);
88  
89      public static Portlet toModel(PortletSoap soapModel) {
90          Portlet model = new PortletImpl();
91  
92          model.setId(soapModel.getId());
93          model.setCompanyId(soapModel.getCompanyId());
94          model.setPortletId(soapModel.getPortletId());
95          model.setRoles(soapModel.getRoles());
96          model.setActive(soapModel.getActive());
97  
98          return model;
99      }
100 
101     public static List<Portlet> toModels(PortletSoap[] soapModels) {
102         List<Portlet> models = new ArrayList<Portlet>(soapModels.length);
103 
104         for (PortletSoap soapModel : soapModels) {
105             models.add(toModel(soapModel));
106         }
107 
108         return models;
109     }
110 
111     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
112                 "lock.expiration.time.com.liferay.portal.model.Portlet"));
113 
114     public PortletModelImpl() {
115     }
116 
117     public long getPrimaryKey() {
118         return _id;
119     }
120 
121     public void setPrimaryKey(long pk) {
122         setId(pk);
123     }
124 
125     public Serializable getPrimaryKeyObj() {
126         return new Long(_id);
127     }
128 
129     public long getId() {
130         return _id;
131     }
132 
133     public void setId(long id) {
134         _id = id;
135     }
136 
137     public long getCompanyId() {
138         return _companyId;
139     }
140 
141     public void setCompanyId(long companyId) {
142         _companyId = companyId;
143 
144         if (!_setOriginalCompanyId) {
145             _setOriginalCompanyId = true;
146 
147             _originalCompanyId = companyId;
148         }
149     }
150 
151     public long getOriginalCompanyId() {
152         return _originalCompanyId;
153     }
154 
155     public String getPortletId() {
156         return GetterUtil.getString(_portletId);
157     }
158 
159     public void setPortletId(String portletId) {
160         _portletId = portletId;
161 
162         if (_originalPortletId == null) {
163             _originalPortletId = portletId;
164         }
165     }
166 
167     public String getOriginalPortletId() {
168         return GetterUtil.getString(_originalPortletId);
169     }
170 
171     public String getRoles() {
172         return GetterUtil.getString(_roles);
173     }
174 
175     public void setRoles(String roles) {
176         _roles = roles;
177     }
178 
179     public boolean getActive() {
180         return _active;
181     }
182 
183     public boolean isActive() {
184         return _active;
185     }
186 
187     public void setActive(boolean active) {
188         _active = active;
189     }
190 
191     public Portlet toEscapedModel() {
192         if (isEscapedModel()) {
193             return (Portlet)this;
194         }
195         else {
196             Portlet model = new PortletImpl();
197 
198             model.setNew(isNew());
199             model.setEscapedModel(true);
200 
201             model.setId(getId());
202             model.setCompanyId(getCompanyId());
203             model.setPortletId(HtmlUtil.escape(getPortletId()));
204             model.setRoles(HtmlUtil.escape(getRoles()));
205             model.setActive(getActive());
206 
207             model = (Portlet)Proxy.newProxyInstance(Portlet.class.getClassLoader(),
208                     new Class[] { Portlet.class },
209                     new ReadOnlyBeanHandler(model));
210 
211             return model;
212         }
213     }
214 
215     public Object clone() {
216         PortletImpl clone = new PortletImpl();
217 
218         clone.setId(getId());
219         clone.setCompanyId(getCompanyId());
220         clone.setPortletId(getPortletId());
221         clone.setRoles(getRoles());
222         clone.setActive(getActive());
223 
224         return clone;
225     }
226 
227     public int compareTo(Portlet portlet) {
228         long pk = portlet.getPrimaryKey();
229 
230         if (getPrimaryKey() < pk) {
231             return -1;
232         }
233         else if (getPrimaryKey() > pk) {
234             return 1;
235         }
236         else {
237             return 0;
238         }
239     }
240 
241     public boolean equals(Object obj) {
242         if (obj == null) {
243             return false;
244         }
245 
246         Portlet portlet = null;
247 
248         try {
249             portlet = (Portlet)obj;
250         }
251         catch (ClassCastException cce) {
252             return false;
253         }
254 
255         long pk = portlet.getPrimaryKey();
256 
257         if (getPrimaryKey() == pk) {
258             return true;
259         }
260         else {
261             return false;
262         }
263     }
264 
265     public int hashCode() {
266         return (int)getPrimaryKey();
267     }
268 
269     public String toString() {
270         StringBuilder sb = new StringBuilder();
271 
272         sb.append("{id=");
273         sb.append(getId());
274         sb.append(", companyId=");
275         sb.append(getCompanyId());
276         sb.append(", portletId=");
277         sb.append(getPortletId());
278         sb.append(", roles=");
279         sb.append(getRoles());
280         sb.append(", active=");
281         sb.append(getActive());
282         sb.append("}");
283 
284         return sb.toString();
285     }
286 
287     public String toXmlString() {
288         StringBuilder sb = new StringBuilder();
289 
290         sb.append("<model><model-name>");
291         sb.append("com.liferay.portal.model.Portlet");
292         sb.append("</model-name>");
293 
294         sb.append(
295             "<column><column-name>id</column-name><column-value><![CDATA[");
296         sb.append(getId());
297         sb.append("]]></column-value></column>");
298         sb.append(
299             "<column><column-name>companyId</column-name><column-value><![CDATA[");
300         sb.append(getCompanyId());
301         sb.append("]]></column-value></column>");
302         sb.append(
303             "<column><column-name>portletId</column-name><column-value><![CDATA[");
304         sb.append(getPortletId());
305         sb.append("]]></column-value></column>");
306         sb.append(
307             "<column><column-name>roles</column-name><column-value><![CDATA[");
308         sb.append(getRoles());
309         sb.append("]]></column-value></column>");
310         sb.append(
311             "<column><column-name>active</column-name><column-value><![CDATA[");
312         sb.append(getActive());
313         sb.append("]]></column-value></column>");
314 
315         sb.append("</model>");
316 
317         return sb.toString();
318     }
319 
320     private long _id;
321     private long _companyId;
322     private long _originalCompanyId;
323     private boolean _setOriginalCompanyId;
324     private String _portletId;
325     private String _originalPortletId;
326     private String _roles;
327     private boolean _active;
328 }