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.PortletPreferences;
29  import com.liferay.portal.model.PortletPreferencesSoap;
30  
31  import com.liferay.portlet.expando.model.ExpandoBridge;
32  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
33  
34  import java.io.Serializable;
35  
36  import java.lang.reflect.Proxy;
37  
38  import java.sql.Types;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  /**
44   * <a href="PortletPreferencesModelImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * <p>
47   * ServiceBuilder generated this class. Modifications in this class will be
48   * overwritten the next time is generated.
49   * </p>
50   *
51   * <p>
52   * This class is a model that represents the <code>PortletPreferences</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portal.model.PortletPreferences
59   * @see com.liferay.portal.model.PortletPreferencesModel
60   * @see com.liferay.portal.model.impl.PortletPreferencesImpl
61   *
62   */
63  public class PortletPreferencesModelImpl extends BaseModelImpl<PortletPreferences> {
64      public static final String TABLE_NAME = "PortletPreferences";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "portletPreferencesId", new Integer(Types.BIGINT) },
67              
68  
69              { "ownerId", new Integer(Types.BIGINT) },
70              
71  
72              { "ownerType", new Integer(Types.INTEGER) },
73              
74  
75              { "plid", new Integer(Types.BIGINT) },
76              
77  
78              { "portletId", new Integer(Types.VARCHAR) },
79              
80  
81              { "preferences", new Integer(Types.CLOB) }
82          };
83      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)";
84      public static final String TABLE_SQL_DROP = "drop table PortletPreferences";
85      public static final String DATA_SOURCE = "liferayDataSource";
86      public static final String SESSION_FACTORY = "liferaySessionFactory";
87      public static final String TX_MANAGER = "liferayTransactionManager";
88      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
89                  "value.object.entity.cache.enabled.com.liferay.portal.model.PortletPreferences"),
90              true);
91      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
92                  "value.object.finder.cache.enabled.com.liferay.portal.model.PortletPreferences"),
93              true);
94  
95      public static PortletPreferences toModel(PortletPreferencesSoap soapModel) {
96          PortletPreferences model = new PortletPreferencesImpl();
97  
98          model.setPortletPreferencesId(soapModel.getPortletPreferencesId());
99          model.setOwnerId(soapModel.getOwnerId());
100         model.setOwnerType(soapModel.getOwnerType());
101         model.setPlid(soapModel.getPlid());
102         model.setPortletId(soapModel.getPortletId());
103         model.setPreferences(soapModel.getPreferences());
104 
105         return model;
106     }
107 
108     public static List<PortletPreferences> toModels(
109         PortletPreferencesSoap[] soapModels) {
110         List<PortletPreferences> models = new ArrayList<PortletPreferences>(soapModels.length);
111 
112         for (PortletPreferencesSoap soapModel : soapModels) {
113             models.add(toModel(soapModel));
114         }
115 
116         return models;
117     }
118 
119     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
120                 "lock.expiration.time.com.liferay.portal.model.PortletPreferences"));
121 
122     public PortletPreferencesModelImpl() {
123     }
124 
125     public long getPrimaryKey() {
126         return _portletPreferencesId;
127     }
128 
129     public void setPrimaryKey(long pk) {
130         setPortletPreferencesId(pk);
131     }
132 
133     public Serializable getPrimaryKeyObj() {
134         return new Long(_portletPreferencesId);
135     }
136 
137     public long getPortletPreferencesId() {
138         return _portletPreferencesId;
139     }
140 
141     public void setPortletPreferencesId(long portletPreferencesId) {
142         _portletPreferencesId = portletPreferencesId;
143     }
144 
145     public long getOwnerId() {
146         return _ownerId;
147     }
148 
149     public void setOwnerId(long ownerId) {
150         _ownerId = ownerId;
151 
152         if (!_setOriginalOwnerId) {
153             _setOriginalOwnerId = true;
154 
155             _originalOwnerId = ownerId;
156         }
157     }
158 
159     public long getOriginalOwnerId() {
160         return _originalOwnerId;
161     }
162 
163     public int getOwnerType() {
164         return _ownerType;
165     }
166 
167     public void setOwnerType(int ownerType) {
168         _ownerType = ownerType;
169 
170         if (!_setOriginalOwnerType) {
171             _setOriginalOwnerType = true;
172 
173             _originalOwnerType = ownerType;
174         }
175     }
176 
177     public int getOriginalOwnerType() {
178         return _originalOwnerType;
179     }
180 
181     public long getPlid() {
182         return _plid;
183     }
184 
185     public void setPlid(long plid) {
186         _plid = plid;
187 
188         if (!_setOriginalPlid) {
189             _setOriginalPlid = true;
190 
191             _originalPlid = plid;
192         }
193     }
194 
195     public long getOriginalPlid() {
196         return _originalPlid;
197     }
198 
199     public String getPortletId() {
200         return GetterUtil.getString(_portletId);
201     }
202 
203     public void setPortletId(String portletId) {
204         _portletId = portletId;
205 
206         if (_originalPortletId == null) {
207             _originalPortletId = portletId;
208         }
209     }
210 
211     public String getOriginalPortletId() {
212         return GetterUtil.getString(_originalPortletId);
213     }
214 
215     public String getPreferences() {
216         return GetterUtil.getString(_preferences);
217     }
218 
219     public void setPreferences(String preferences) {
220         _preferences = preferences;
221     }
222 
223     public PortletPreferences toEscapedModel() {
224         if (isEscapedModel()) {
225             return (PortletPreferences)this;
226         }
227         else {
228             PortletPreferences model = new PortletPreferencesImpl();
229 
230             model.setNew(isNew());
231             model.setEscapedModel(true);
232 
233             model.setPortletPreferencesId(getPortletPreferencesId());
234             model.setOwnerId(getOwnerId());
235             model.setOwnerType(getOwnerType());
236             model.setPlid(getPlid());
237             model.setPortletId(HtmlUtil.escape(getPortletId()));
238             model.setPreferences(HtmlUtil.escape(getPreferences()));
239 
240             model = (PortletPreferences)Proxy.newProxyInstance(PortletPreferences.class.getClassLoader(),
241                     new Class[] { PortletPreferences.class },
242                     new ReadOnlyBeanHandler(model));
243 
244             return model;
245         }
246     }
247 
248     public ExpandoBridge getExpandoBridge() {
249         if (_expandoBridge == null) {
250             _expandoBridge = new ExpandoBridgeImpl(PortletPreferences.class.getName(),
251                     getPrimaryKey());
252         }
253 
254         return _expandoBridge;
255     }
256 
257     public Object clone() {
258         PortletPreferencesImpl clone = new PortletPreferencesImpl();
259 
260         clone.setPortletPreferencesId(getPortletPreferencesId());
261         clone.setOwnerId(getOwnerId());
262         clone.setOwnerType(getOwnerType());
263         clone.setPlid(getPlid());
264         clone.setPortletId(getPortletId());
265         clone.setPreferences(getPreferences());
266 
267         return clone;
268     }
269 
270     public int compareTo(PortletPreferences portletPreferences) {
271         long pk = portletPreferences.getPrimaryKey();
272 
273         if (getPrimaryKey() < pk) {
274             return -1;
275         }
276         else if (getPrimaryKey() > pk) {
277             return 1;
278         }
279         else {
280             return 0;
281         }
282     }
283 
284     public boolean equals(Object obj) {
285         if (obj == null) {
286             return false;
287         }
288 
289         PortletPreferences portletPreferences = null;
290 
291         try {
292             portletPreferences = (PortletPreferences)obj;
293         }
294         catch (ClassCastException cce) {
295             return false;
296         }
297 
298         long pk = portletPreferences.getPrimaryKey();
299 
300         if (getPrimaryKey() == pk) {
301             return true;
302         }
303         else {
304             return false;
305         }
306     }
307 
308     public int hashCode() {
309         return (int)getPrimaryKey();
310     }
311 
312     public String toString() {
313         StringBuilder sb = new StringBuilder();
314 
315         sb.append("{portletPreferencesId=");
316         sb.append(getPortletPreferencesId());
317         sb.append(", ownerId=");
318         sb.append(getOwnerId());
319         sb.append(", ownerType=");
320         sb.append(getOwnerType());
321         sb.append(", plid=");
322         sb.append(getPlid());
323         sb.append(", portletId=");
324         sb.append(getPortletId());
325         sb.append(", preferences=");
326         sb.append(getPreferences());
327         sb.append("}");
328 
329         return sb.toString();
330     }
331 
332     public String toXmlString() {
333         StringBuilder sb = new StringBuilder();
334 
335         sb.append("<model><model-name>");
336         sb.append("com.liferay.portal.model.PortletPreferences");
337         sb.append("</model-name>");
338 
339         sb.append(
340             "<column><column-name>portletPreferencesId</column-name><column-value><![CDATA[");
341         sb.append(getPortletPreferencesId());
342         sb.append("]]></column-value></column>");
343         sb.append(
344             "<column><column-name>ownerId</column-name><column-value><![CDATA[");
345         sb.append(getOwnerId());
346         sb.append("]]></column-value></column>");
347         sb.append(
348             "<column><column-name>ownerType</column-name><column-value><![CDATA[");
349         sb.append(getOwnerType());
350         sb.append("]]></column-value></column>");
351         sb.append(
352             "<column><column-name>plid</column-name><column-value><![CDATA[");
353         sb.append(getPlid());
354         sb.append("]]></column-value></column>");
355         sb.append(
356             "<column><column-name>portletId</column-name><column-value><![CDATA[");
357         sb.append(getPortletId());
358         sb.append("]]></column-value></column>");
359         sb.append(
360             "<column><column-name>preferences</column-name><column-value><![CDATA[");
361         sb.append(getPreferences());
362         sb.append("]]></column-value></column>");
363 
364         sb.append("</model>");
365 
366         return sb.toString();
367     }
368 
369     private long _portletPreferencesId;
370     private long _ownerId;
371     private long _originalOwnerId;
372     private boolean _setOriginalOwnerId;
373     private int _ownerType;
374     private int _originalOwnerType;
375     private boolean _setOriginalOwnerType;
376     private long _plid;
377     private long _originalPlid;
378     private boolean _setOriginalPlid;
379     private String _portletId;
380     private String _originalPortletId;
381     private String _preferences;
382     private transient ExpandoBridge _expandoBridge;
383 }