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.PortletPreferences;
29  import com.liferay.portal.model.PortletPreferencesSoap;
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="PortletPreferencesModelImpl.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>PortletPreferences</code> table
50   * in the database.
51   * </p>
52   *
53   * @author Brian Wing Shun Chan
54   *
55   * @see com.liferay.portal.model.PortletPreferences
56   * @see com.liferay.portal.model.PortletPreferencesModel
57   * @see com.liferay.portal.model.impl.PortletPreferencesImpl
58   *
59   */
60  public class PortletPreferencesModelImpl extends BaseModelImpl {
61      public static final String TABLE_NAME = "PortletPreferences";
62      public static final Object[][] TABLE_COLUMNS = {
63              { "portletPreferencesId", new Integer(Types.BIGINT) },
64              
65  
66              { "ownerId", new Integer(Types.BIGINT) },
67              
68  
69              { "ownerType", new Integer(Types.INTEGER) },
70              
71  
72              { "plid", new Integer(Types.BIGINT) },
73              
74  
75              { "portletId", new Integer(Types.VARCHAR) },
76              
77  
78              { "preferences", new Integer(Types.CLOB) }
79          };
80      public static final String TABLE_SQL_CREATE = "create table PortletPreferences (portletPreferencesId LONG not null primary key,ownerId LONG,ownerType INTEGER,plid LONG,portletId VARCHAR(200) null,preferences TEXT null)";
81      public static final String TABLE_SQL_DROP = "drop table PortletPreferences";
82      public static final String DATA_SOURCE = "liferayDataSource";
83      public static final String SESSION_FACTORY = "liferaySessionFactory";
84      public static final String TX_MANAGER = "liferayTransactionManager";
85      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
86                  "value.object.finder.cache.enabled.com.liferay.portal.model.PortletPreferences"),
87              true);
88  
89      public static PortletPreferences toModel(PortletPreferencesSoap soapModel) {
90          PortletPreferences model = new PortletPreferencesImpl();
91  
92          model.setPortletPreferencesId(soapModel.getPortletPreferencesId());
93          model.setOwnerId(soapModel.getOwnerId());
94          model.setOwnerType(soapModel.getOwnerType());
95          model.setPlid(soapModel.getPlid());
96          model.setPortletId(soapModel.getPortletId());
97          model.setPreferences(soapModel.getPreferences());
98  
99          return model;
100     }
101 
102     public static List<PortletPreferences> toModels(
103         PortletPreferencesSoap[] soapModels) {
104         List<PortletPreferences> models = new ArrayList<PortletPreferences>(soapModels.length);
105 
106         for (PortletPreferencesSoap soapModel : soapModels) {
107             models.add(toModel(soapModel));
108         }
109 
110         return models;
111     }
112 
113     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
114                 "lock.expiration.time.com.liferay.portal.model.PortletPreferences"));
115 
116     public PortletPreferencesModelImpl() {
117     }
118 
119     public long getPrimaryKey() {
120         return _portletPreferencesId;
121     }
122 
123     public void setPrimaryKey(long pk) {
124         setPortletPreferencesId(pk);
125     }
126 
127     public Serializable getPrimaryKeyObj() {
128         return new Long(_portletPreferencesId);
129     }
130 
131     public long getPortletPreferencesId() {
132         return _portletPreferencesId;
133     }
134 
135     public void setPortletPreferencesId(long portletPreferencesId) {
136         if (portletPreferencesId != _portletPreferencesId) {
137             _portletPreferencesId = portletPreferencesId;
138         }
139     }
140 
141     public long getOwnerId() {
142         return _ownerId;
143     }
144 
145     public void setOwnerId(long ownerId) {
146         if (ownerId != _ownerId) {
147             _ownerId = ownerId;
148         }
149     }
150 
151     public int getOwnerType() {
152         return _ownerType;
153     }
154 
155     public void setOwnerType(int ownerType) {
156         if (ownerType != _ownerType) {
157             _ownerType = ownerType;
158         }
159     }
160 
161     public long getPlid() {
162         return _plid;
163     }
164 
165     public void setPlid(long plid) {
166         if (plid != _plid) {
167             _plid = plid;
168         }
169     }
170 
171     public String getPortletId() {
172         return GetterUtil.getString(_portletId);
173     }
174 
175     public void setPortletId(String portletId) {
176         if (((portletId == null) && (_portletId != null)) ||
177                 ((portletId != null) && (_portletId == null)) ||
178                 ((portletId != null) && (_portletId != null) &&
179                 !portletId.equals(_portletId))) {
180             _portletId = portletId;
181         }
182     }
183 
184     public String getPreferences() {
185         return GetterUtil.getString(_preferences);
186     }
187 
188     public void setPreferences(String preferences) {
189         if (((preferences == null) && (_preferences != null)) ||
190                 ((preferences != null) && (_preferences == null)) ||
191                 ((preferences != null) && (_preferences != null) &&
192                 !preferences.equals(_preferences))) {
193             _preferences = preferences;
194         }
195     }
196 
197     public PortletPreferences toEscapedModel() {
198         if (isEscapedModel()) {
199             return (PortletPreferences)this;
200         }
201         else {
202             PortletPreferences model = new PortletPreferencesImpl();
203 
204             model.setNew(isNew());
205             model.setEscapedModel(true);
206 
207             model.setPortletPreferencesId(getPortletPreferencesId());
208             model.setOwnerId(getOwnerId());
209             model.setOwnerType(getOwnerType());
210             model.setPlid(getPlid());
211             model.setPortletId(HtmlUtil.escape(getPortletId()));
212             model.setPreferences(HtmlUtil.escape(getPreferences()));
213 
214             model = (PortletPreferences)Proxy.newProxyInstance(PortletPreferences.class.getClassLoader(),
215                     new Class[] { PortletPreferences.class },
216                     new ReadOnlyBeanHandler(model));
217 
218             return model;
219         }
220     }
221 
222     public Object clone() {
223         PortletPreferencesImpl clone = new PortletPreferencesImpl();
224 
225         clone.setPortletPreferencesId(getPortletPreferencesId());
226         clone.setOwnerId(getOwnerId());
227         clone.setOwnerType(getOwnerType());
228         clone.setPlid(getPlid());
229         clone.setPortletId(getPortletId());
230         clone.setPreferences(getPreferences());
231 
232         return clone;
233     }
234 
235     public int compareTo(Object obj) {
236         if (obj == null) {
237             return -1;
238         }
239 
240         PortletPreferencesImpl portletPreferences = (PortletPreferencesImpl)obj;
241 
242         long pk = portletPreferences.getPrimaryKey();
243 
244         if (getPrimaryKey() < pk) {
245             return -1;
246         }
247         else if (getPrimaryKey() > pk) {
248             return 1;
249         }
250         else {
251             return 0;
252         }
253     }
254 
255     public boolean equals(Object obj) {
256         if (obj == null) {
257             return false;
258         }
259 
260         PortletPreferencesImpl portletPreferences = null;
261 
262         try {
263             portletPreferences = (PortletPreferencesImpl)obj;
264         }
265         catch (ClassCastException cce) {
266             return false;
267         }
268 
269         long pk = portletPreferences.getPrimaryKey();
270 
271         if (getPrimaryKey() == pk) {
272             return true;
273         }
274         else {
275             return false;
276         }
277     }
278 
279     public int hashCode() {
280         return (int)getPrimaryKey();
281     }
282 
283     private long _portletPreferencesId;
284     private long _ownerId;
285     private int _ownerType;
286     private long _plid;
287     private String _portletId;
288     private String _preferences;
289 }