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 {
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 CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
89                  "value.object.finder.cache.enabled.com.liferay.portal.model.PortletPreferences"),
90              true);
91  
92      public static PortletPreferences toModel(PortletPreferencesSoap soapModel) {
93          PortletPreferences model = new PortletPreferencesImpl();
94  
95          model.setPortletPreferencesId(soapModel.getPortletPreferencesId());
96          model.setOwnerId(soapModel.getOwnerId());
97          model.setOwnerType(soapModel.getOwnerType());
98          model.setPlid(soapModel.getPlid());
99          model.setPortletId(soapModel.getPortletId());
100         model.setPreferences(soapModel.getPreferences());
101 
102         return model;
103     }
104 
105     public static List<PortletPreferences> toModels(
106         PortletPreferencesSoap[] soapModels) {
107         List<PortletPreferences> models = new ArrayList<PortletPreferences>(soapModels.length);
108 
109         for (PortletPreferencesSoap soapModel : soapModels) {
110             models.add(toModel(soapModel));
111         }
112 
113         return models;
114     }
115 
116     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
117                 "lock.expiration.time.com.liferay.portal.model.PortletPreferences"));
118 
119     public PortletPreferencesModelImpl() {
120     }
121 
122     public long getPrimaryKey() {
123         return _portletPreferencesId;
124     }
125 
126     public void setPrimaryKey(long pk) {
127         setPortletPreferencesId(pk);
128     }
129 
130     public Serializable getPrimaryKeyObj() {
131         return new Long(_portletPreferencesId);
132     }
133 
134     public long getPortletPreferencesId() {
135         return _portletPreferencesId;
136     }
137 
138     public void setPortletPreferencesId(long portletPreferencesId) {
139         if (portletPreferencesId != _portletPreferencesId) {
140             _portletPreferencesId = portletPreferencesId;
141         }
142     }
143 
144     public long getOwnerId() {
145         return _ownerId;
146     }
147 
148     public void setOwnerId(long ownerId) {
149         if (ownerId != _ownerId) {
150             _ownerId = ownerId;
151         }
152     }
153 
154     public int getOwnerType() {
155         return _ownerType;
156     }
157 
158     public void setOwnerType(int ownerType) {
159         if (ownerType != _ownerType) {
160             _ownerType = ownerType;
161         }
162     }
163 
164     public long getPlid() {
165         return _plid;
166     }
167 
168     public void setPlid(long plid) {
169         if (plid != _plid) {
170             _plid = plid;
171         }
172     }
173 
174     public String getPortletId() {
175         return GetterUtil.getString(_portletId);
176     }
177 
178     public void setPortletId(String portletId) {
179         if (((portletId == null) && (_portletId != null)) ||
180                 ((portletId != null) && (_portletId == null)) ||
181                 ((portletId != null) && (_portletId != null) &&
182                 !portletId.equals(_portletId))) {
183             _portletId = portletId;
184         }
185     }
186 
187     public String getPreferences() {
188         return GetterUtil.getString(_preferences);
189     }
190 
191     public void setPreferences(String preferences) {
192         if (((preferences == null) && (_preferences != null)) ||
193                 ((preferences != null) && (_preferences == null)) ||
194                 ((preferences != null) && (_preferences != null) &&
195                 !preferences.equals(_preferences))) {
196             _preferences = preferences;
197         }
198     }
199 
200     public PortletPreferences toEscapedModel() {
201         if (isEscapedModel()) {
202             return (PortletPreferences)this;
203         }
204         else {
205             PortletPreferences model = new PortletPreferencesImpl();
206 
207             model.setNew(isNew());
208             model.setEscapedModel(true);
209 
210             model.setPortletPreferencesId(getPortletPreferencesId());
211             model.setOwnerId(getOwnerId());
212             model.setOwnerType(getOwnerType());
213             model.setPlid(getPlid());
214             model.setPortletId(HtmlUtil.escape(getPortletId()));
215             model.setPreferences(HtmlUtil.escape(getPreferences()));
216 
217             model = (PortletPreferences)Proxy.newProxyInstance(PortletPreferences.class.getClassLoader(),
218                     new Class[] { PortletPreferences.class },
219                     new ReadOnlyBeanHandler(model));
220 
221             return model;
222         }
223     }
224 
225     public ExpandoBridge getExpandoBridge() {
226         if (_expandoBridge == null) {
227             _expandoBridge = new ExpandoBridgeImpl(PortletPreferences.class.getName(),
228                     getPrimaryKey());
229         }
230 
231         return _expandoBridge;
232     }
233 
234     public Object clone() {
235         PortletPreferencesImpl clone = new PortletPreferencesImpl();
236 
237         clone.setPortletPreferencesId(getPortletPreferencesId());
238         clone.setOwnerId(getOwnerId());
239         clone.setOwnerType(getOwnerType());
240         clone.setPlid(getPlid());
241         clone.setPortletId(getPortletId());
242         clone.setPreferences(getPreferences());
243 
244         return clone;
245     }
246 
247     public int compareTo(Object obj) {
248         if (obj == null) {
249             return -1;
250         }
251 
252         PortletPreferencesImpl portletPreferences = (PortletPreferencesImpl)obj;
253 
254         long pk = portletPreferences.getPrimaryKey();
255 
256         if (getPrimaryKey() < pk) {
257             return -1;
258         }
259         else if (getPrimaryKey() > pk) {
260             return 1;
261         }
262         else {
263             return 0;
264         }
265     }
266 
267     public boolean equals(Object obj) {
268         if (obj == null) {
269             return false;
270         }
271 
272         PortletPreferencesImpl portletPreferences = null;
273 
274         try {
275             portletPreferences = (PortletPreferencesImpl)obj;
276         }
277         catch (ClassCastException cce) {
278             return false;
279         }
280 
281         long pk = portletPreferences.getPrimaryKey();
282 
283         if (getPrimaryKey() == pk) {
284             return true;
285         }
286         else {
287             return false;
288         }
289     }
290 
291     public int hashCode() {
292         return (int)getPrimaryKey();
293     }
294 
295     private long _portletPreferencesId;
296     private long _ownerId;
297     private int _ownerType;
298     private long _plid;
299     private String _portletId;
300     private String _preferences;
301     private transient ExpandoBridge _expandoBridge;
302 }