1   /**
2    * Copyright (c) 2000-2008 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  import com.liferay.portal.util.PropsUtil;
31  
32  import java.io.Serializable;
33  
34  import java.lang.reflect.Proxy;
35  
36  import java.sql.Types;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  /**
42   * <a href="PortletModelImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * <p>
45   * ServiceBuilder generated this class. Modifications in this class will be
46   * overwritten the next time is generated.
47   * </p>
48   *
49   * <p>
50   * This class is a model that represents the <code>Portlet</code> table
51   * in the database.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   * @see com.liferay.portal.service.model.Portlet
57   * @see com.liferay.portal.service.model.PortletModel
58   * @see com.liferay.portal.service.model.impl.PortletImpl
59   *
60   */
61  public class PortletModelImpl extends BaseModelImpl {
62      public static final String TABLE_NAME = "Portlet";
63      public static final Object[][] TABLE_COLUMNS = {
64              { "id_", new Integer(Types.BIGINT) },
65              
66  
67              { "companyId", new Integer(Types.BIGINT) },
68              
69  
70              { "portletId", new Integer(Types.VARCHAR) },
71              
72  
73              { "roles", new Integer(Types.VARCHAR) },
74              
75  
76              { "active_", new Integer(Types.BOOLEAN) }
77          };
78      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)";
79      public static final String TABLE_SQL_DROP = "drop table Portlet";
80      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
81                  "value.object.finder.cache.enabled.com.liferay.portal.model.Portlet"),
82              true);
83  
84      public static Portlet toModel(PortletSoap soapModel) {
85          Portlet model = new PortletImpl();
86  
87          model.setId(soapModel.getId());
88          model.setCompanyId(soapModel.getCompanyId());
89          model.setPortletId(soapModel.getPortletId());
90          model.setRoles(soapModel.getRoles());
91          model.setActive(soapModel.getActive());
92  
93          return model;
94      }
95  
96      public static List<Portlet> toModels(PortletSoap[] soapModels) {
97          List<Portlet> models = new ArrayList<Portlet>(soapModels.length);
98  
99          for (PortletSoap soapModel : soapModels) {
100             models.add(toModel(soapModel));
101         }
102 
103         return models;
104     }
105 
106     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
107                 "lock.expiration.time.com.liferay.portal.model.Portlet"));
108 
109     public PortletModelImpl() {
110     }
111 
112     public long getPrimaryKey() {
113         return _id;
114     }
115 
116     public void setPrimaryKey(long pk) {
117         setId(pk);
118     }
119 
120     public Serializable getPrimaryKeyObj() {
121         return new Long(_id);
122     }
123 
124     public long getId() {
125         return _id;
126     }
127 
128     public void setId(long id) {
129         if (id != _id) {
130             _id = id;
131         }
132     }
133 
134     public long getCompanyId() {
135         return _companyId;
136     }
137 
138     public void setCompanyId(long companyId) {
139         if (companyId != _companyId) {
140             _companyId = companyId;
141         }
142     }
143 
144     public String getPortletId() {
145         return GetterUtil.getString(_portletId);
146     }
147 
148     public void setPortletId(String portletId) {
149         if (((portletId == null) && (_portletId != null)) ||
150                 ((portletId != null) && (_portletId == null)) ||
151                 ((portletId != null) && (_portletId != null) &&
152                 !portletId.equals(_portletId))) {
153             _portletId = portletId;
154         }
155     }
156 
157     public String getRoles() {
158         return GetterUtil.getString(_roles);
159     }
160 
161     public void setRoles(String roles) {
162         if (((roles == null) && (_roles != null)) ||
163                 ((roles != null) && (_roles == null)) ||
164                 ((roles != null) && (_roles != null) && !roles.equals(_roles))) {
165             _roles = roles;
166         }
167     }
168 
169     public boolean getActive() {
170         return _active;
171     }
172 
173     public boolean isActive() {
174         return _active;
175     }
176 
177     public void setActive(boolean active) {
178         if (active != _active) {
179             _active = active;
180         }
181     }
182 
183     public Portlet toEscapedModel() {
184         if (isEscapedModel()) {
185             return (Portlet)this;
186         }
187         else {
188             Portlet model = new PortletImpl();
189 
190             model.setEscapedModel(true);
191 
192             model.setId(getId());
193             model.setCompanyId(getCompanyId());
194             model.setPortletId(HtmlUtil.escape(getPortletId()));
195             model.setRoles(HtmlUtil.escape(getRoles()));
196             model.setActive(getActive());
197 
198             model = (Portlet)Proxy.newProxyInstance(Portlet.class.getClassLoader(),
199                     new Class[] { Portlet.class },
200                     new ReadOnlyBeanHandler(model));
201 
202             return model;
203         }
204     }
205 
206     public Object clone() {
207         PortletImpl clone = new PortletImpl();
208 
209         clone.setId(getId());
210         clone.setCompanyId(getCompanyId());
211         clone.setPortletId(getPortletId());
212         clone.setRoles(getRoles());
213         clone.setActive(getActive());
214 
215         return clone;
216     }
217 
218     public int compareTo(Object obj) {
219         if (obj == null) {
220             return -1;
221         }
222 
223         PortletImpl portlet = (PortletImpl)obj;
224 
225         long pk = portlet.getPrimaryKey();
226 
227         if (getPrimaryKey() < pk) {
228             return -1;
229         }
230         else if (getPrimaryKey() > pk) {
231             return 1;
232         }
233         else {
234             return 0;
235         }
236     }
237 
238     public boolean equals(Object obj) {
239         if (obj == null) {
240             return false;
241         }
242 
243         PortletImpl portlet = null;
244 
245         try {
246             portlet = (PortletImpl)obj;
247         }
248         catch (ClassCastException cce) {
249             return false;
250         }
251 
252         long pk = portlet.getPrimaryKey();
253 
254         if (getPrimaryKey() == pk) {
255             return true;
256         }
257         else {
258             return false;
259         }
260     }
261 
262     public int hashCode() {
263         return (int)getPrimaryKey();
264     }
265 
266     private long _id;
267     private long _companyId;
268     private String _portletId;
269     private String _roles;
270     private boolean _active;
271 }