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  
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 {
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 CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
83                  "value.object.finder.cache.enabled.com.liferay.portal.model.Portlet"),
84              true);
85  
86      public static Portlet toModel(PortletSoap soapModel) {
87          Portlet model = new PortletImpl();
88  
89          model.setId(soapModel.getId());
90          model.setCompanyId(soapModel.getCompanyId());
91          model.setPortletId(soapModel.getPortletId());
92          model.setRoles(soapModel.getRoles());
93          model.setActive(soapModel.getActive());
94  
95          return model;
96      }
97  
98      public static List<Portlet> toModels(PortletSoap[] soapModels) {
99          List<Portlet> models = new ArrayList<Portlet>(soapModels.length);
100 
101         for (PortletSoap soapModel : soapModels) {
102             models.add(toModel(soapModel));
103         }
104 
105         return models;
106     }
107 
108     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
109                 "lock.expiration.time.com.liferay.portal.model.Portlet"));
110 
111     public PortletModelImpl() {
112     }
113 
114     public long getPrimaryKey() {
115         return _id;
116     }
117 
118     public void setPrimaryKey(long pk) {
119         setId(pk);
120     }
121 
122     public Serializable getPrimaryKeyObj() {
123         return new Long(_id);
124     }
125 
126     public long getId() {
127         return _id;
128     }
129 
130     public void setId(long id) {
131         if (id != _id) {
132             _id = id;
133         }
134     }
135 
136     public long getCompanyId() {
137         return _companyId;
138     }
139 
140     public void setCompanyId(long companyId) {
141         if (companyId != _companyId) {
142             _companyId = companyId;
143         }
144     }
145 
146     public String getPortletId() {
147         return GetterUtil.getString(_portletId);
148     }
149 
150     public void setPortletId(String portletId) {
151         if (((portletId == null) && (_portletId != null)) ||
152                 ((portletId != null) && (_portletId == null)) ||
153                 ((portletId != null) && (_portletId != null) &&
154                 !portletId.equals(_portletId))) {
155             _portletId = portletId;
156         }
157     }
158 
159     public String getRoles() {
160         return GetterUtil.getString(_roles);
161     }
162 
163     public void setRoles(String roles) {
164         if (((roles == null) && (_roles != null)) ||
165                 ((roles != null) && (_roles == null)) ||
166                 ((roles != null) && (_roles != null) && !roles.equals(_roles))) {
167             _roles = roles;
168         }
169     }
170 
171     public boolean getActive() {
172         return _active;
173     }
174 
175     public boolean isActive() {
176         return _active;
177     }
178 
179     public void setActive(boolean active) {
180         if (active != _active) {
181             _active = active;
182         }
183     }
184 
185     public Portlet toEscapedModel() {
186         if (isEscapedModel()) {
187             return (Portlet)this;
188         }
189         else {
190             Portlet model = new PortletImpl();
191 
192             model.setNew(isNew());
193             model.setEscapedModel(true);
194 
195             model.setId(getId());
196             model.setCompanyId(getCompanyId());
197             model.setPortletId(HtmlUtil.escape(getPortletId()));
198             model.setRoles(HtmlUtil.escape(getRoles()));
199             model.setActive(getActive());
200 
201             model = (Portlet)Proxy.newProxyInstance(Portlet.class.getClassLoader(),
202                     new Class[] { Portlet.class },
203                     new ReadOnlyBeanHandler(model));
204 
205             return model;
206         }
207     }
208 
209     public Object clone() {
210         PortletImpl clone = new PortletImpl();
211 
212         clone.setId(getId());
213         clone.setCompanyId(getCompanyId());
214         clone.setPortletId(getPortletId());
215         clone.setRoles(getRoles());
216         clone.setActive(getActive());
217 
218         return clone;
219     }
220 
221     public int compareTo(Object obj) {
222         if (obj == null) {
223             return -1;
224         }
225 
226         PortletImpl portlet = (PortletImpl)obj;
227 
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         PortletImpl portlet = null;
247 
248         try {
249             portlet = (PortletImpl)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     private long _id;
270     private long _companyId;
271     private String _portletId;
272     private String _roles;
273     private boolean _active;
274 }