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.kernel.util.StringPool;
29  import com.liferay.portal.model.Role;
30  import com.liferay.portal.model.RoleSoap;
31  import com.liferay.portal.util.PortalUtil;
32  
33  import com.liferay.portlet.expando.model.ExpandoBridge;
34  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
35  
36  import java.io.Serializable;
37  
38  import java.lang.reflect.Proxy;
39  
40  import java.sql.Types;
41  
42  import java.util.ArrayList;
43  import java.util.List;
44  
45  /**
46   * <a href="RoleModelImpl.java.html"><b><i>View Source</i></b></a>
47   *
48   * <p>
49   * ServiceBuilder generated this class. Modifications in this class will be
50   * overwritten the next time is generated.
51   * </p>
52   *
53   * <p>
54   * This class is a model that represents the <code>Role</code> table
55   * in the database.
56   * </p>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   * @see com.liferay.portal.model.Role
61   * @see com.liferay.portal.model.RoleModel
62   * @see com.liferay.portal.model.impl.RoleImpl
63   *
64   */
65  public class RoleModelImpl extends BaseModelImpl<Role> {
66      public static final String TABLE_NAME = "Role_";
67      public static final Object[][] TABLE_COLUMNS = {
68              { "roleId", new Integer(Types.BIGINT) },
69              
70  
71              { "companyId", new Integer(Types.BIGINT) },
72              
73  
74              { "classNameId", new Integer(Types.BIGINT) },
75              
76  
77              { "classPK", new Integer(Types.BIGINT) },
78              
79  
80              { "name", new Integer(Types.VARCHAR) },
81              
82  
83              { "title", new Integer(Types.VARCHAR) },
84              
85  
86              { "description", new Integer(Types.VARCHAR) },
87              
88  
89              { "type_", new Integer(Types.INTEGER) },
90              
91  
92              { "subtype", new Integer(Types.VARCHAR) }
93          };
94      public static final String TABLE_SQL_CREATE = "create table Role_ (roleId LONG not null primary key,companyId LONG,classNameId LONG,classPK LONG,name VARCHAR(75) null,title STRING null,description STRING null,type_ INTEGER,subtype VARCHAR(75) null)";
95      public static final String TABLE_SQL_DROP = "drop table Role_";
96      public static final String DATA_SOURCE = "liferayDataSource";
97      public static final String SESSION_FACTORY = "liferaySessionFactory";
98      public static final String TX_MANAGER = "liferayTransactionManager";
99      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
100                 "value.object.entity.cache.enabled.com.liferay.portal.model.Role"),
101             true);
102     public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
103                 "value.object.finder.cache.enabled.com.liferay.portal.model.Role"),
104             true);
105 
106     public static Role toModel(RoleSoap soapModel) {
107         Role model = new RoleImpl();
108 
109         model.setRoleId(soapModel.getRoleId());
110         model.setCompanyId(soapModel.getCompanyId());
111         model.setClassNameId(soapModel.getClassNameId());
112         model.setClassPK(soapModel.getClassPK());
113         model.setName(soapModel.getName());
114         model.setTitle(soapModel.getTitle());
115         model.setDescription(soapModel.getDescription());
116         model.setType(soapModel.getType());
117         model.setSubtype(soapModel.getSubtype());
118 
119         return model;
120     }
121 
122     public static List<Role> toModels(RoleSoap[] soapModels) {
123         List<Role> models = new ArrayList<Role>(soapModels.length);
124 
125         for (RoleSoap soapModel : soapModels) {
126             models.add(toModel(soapModel));
127         }
128 
129         return models;
130     }
131 
132     public static final boolean FINDER_CACHE_ENABLED_GROUPS_ROLES = com.liferay.portal.model.impl.GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES;
133     public static final boolean FINDER_CACHE_ENABLED_ROLES_PERMISSIONS = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
134                 "value.object.finder.cache.enabled.Roles_Permissions"), true);
135     public static final boolean FINDER_CACHE_ENABLED_USERS_ROLES = com.liferay.portal.model.impl.UserModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES;
136     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
137                 "lock.expiration.time.com.liferay.portal.model.Role"));
138 
139     public RoleModelImpl() {
140     }
141 
142     public long getPrimaryKey() {
143         return _roleId;
144     }
145 
146     public void setPrimaryKey(long pk) {
147         setRoleId(pk);
148     }
149 
150     public Serializable getPrimaryKeyObj() {
151         return new Long(_roleId);
152     }
153 
154     public long getRoleId() {
155         return _roleId;
156     }
157 
158     public void setRoleId(long roleId) {
159         _roleId = roleId;
160     }
161 
162     public long getCompanyId() {
163         return _companyId;
164     }
165 
166     public void setCompanyId(long companyId) {
167         _companyId = companyId;
168 
169         if (!_setOriginalCompanyId) {
170             _setOriginalCompanyId = true;
171 
172             _originalCompanyId = companyId;
173         }
174     }
175 
176     public long getOriginalCompanyId() {
177         return _originalCompanyId;
178     }
179 
180     public String getClassName() {
181         if (getClassNameId() <= 0) {
182             return StringPool.BLANK;
183         }
184 
185         return PortalUtil.getClassName(getClassNameId());
186     }
187 
188     public long getClassNameId() {
189         return _classNameId;
190     }
191 
192     public void setClassNameId(long classNameId) {
193         _classNameId = classNameId;
194 
195         if (!_setOriginalClassNameId) {
196             _setOriginalClassNameId = true;
197 
198             _originalClassNameId = classNameId;
199         }
200     }
201 
202     public long getOriginalClassNameId() {
203         return _originalClassNameId;
204     }
205 
206     public long getClassPK() {
207         return _classPK;
208     }
209 
210     public void setClassPK(long classPK) {
211         _classPK = classPK;
212 
213         if (!_setOriginalClassPK) {
214             _setOriginalClassPK = true;
215 
216             _originalClassPK = classPK;
217         }
218     }
219 
220     public long getOriginalClassPK() {
221         return _originalClassPK;
222     }
223 
224     public String getName() {
225         return GetterUtil.getString(_name);
226     }
227 
228     public void setName(String name) {
229         _name = name;
230 
231         if (_originalName == null) {
232             _originalName = name;
233         }
234     }
235 
236     public String getOriginalName() {
237         return GetterUtil.getString(_originalName);
238     }
239 
240     public String getTitle() {
241         return GetterUtil.getString(_title);
242     }
243 
244     public void setTitle(String title) {
245         _title = title;
246     }
247 
248     public String getDescription() {
249         return GetterUtil.getString(_description);
250     }
251 
252     public void setDescription(String description) {
253         _description = description;
254     }
255 
256     public int getType() {
257         return _type;
258     }
259 
260     public void setType(int type) {
261         _type = type;
262     }
263 
264     public String getSubtype() {
265         return GetterUtil.getString(_subtype);
266     }
267 
268     public void setSubtype(String subtype) {
269         _subtype = subtype;
270     }
271 
272     public Role toEscapedModel() {
273         if (isEscapedModel()) {
274             return (Role)this;
275         }
276         else {
277             Role model = new RoleImpl();
278 
279             model.setNew(isNew());
280             model.setEscapedModel(true);
281 
282             model.setRoleId(getRoleId());
283             model.setCompanyId(getCompanyId());
284             model.setClassNameId(getClassNameId());
285             model.setClassPK(getClassPK());
286             model.setName(HtmlUtil.escape(getName()));
287             model.setTitle(HtmlUtil.escape(getTitle()));
288             model.setDescription(HtmlUtil.escape(getDescription()));
289             model.setType(getType());
290             model.setSubtype(HtmlUtil.escape(getSubtype()));
291 
292             model = (Role)Proxy.newProxyInstance(Role.class.getClassLoader(),
293                     new Class[] { Role.class }, new ReadOnlyBeanHandler(model));
294 
295             return model;
296         }
297     }
298 
299     public ExpandoBridge getExpandoBridge() {
300         if (_expandoBridge == null) {
301             _expandoBridge = new ExpandoBridgeImpl(Role.class.getName(),
302                     getPrimaryKey());
303         }
304 
305         return _expandoBridge;
306     }
307 
308     public Object clone() {
309         RoleImpl clone = new RoleImpl();
310 
311         clone.setRoleId(getRoleId());
312         clone.setCompanyId(getCompanyId());
313         clone.setClassNameId(getClassNameId());
314         clone.setClassPK(getClassPK());
315         clone.setName(getName());
316         clone.setTitle(getTitle());
317         clone.setDescription(getDescription());
318         clone.setType(getType());
319         clone.setSubtype(getSubtype());
320 
321         return clone;
322     }
323 
324     public int compareTo(Role role) {
325         int value = 0;
326 
327         value = getName().compareTo(role.getName());
328 
329         if (value != 0) {
330             return value;
331         }
332 
333         return 0;
334     }
335 
336     public boolean equals(Object obj) {
337         if (obj == null) {
338             return false;
339         }
340 
341         Role role = null;
342 
343         try {
344             role = (Role)obj;
345         }
346         catch (ClassCastException cce) {
347             return false;
348         }
349 
350         long pk = role.getPrimaryKey();
351 
352         if (getPrimaryKey() == pk) {
353             return true;
354         }
355         else {
356             return false;
357         }
358     }
359 
360     public int hashCode() {
361         return (int)getPrimaryKey();
362     }
363 
364     public String toString() {
365         StringBuilder sb = new StringBuilder();
366 
367         sb.append("{roleId=");
368         sb.append(getRoleId());
369         sb.append(", companyId=");
370         sb.append(getCompanyId());
371         sb.append(", classNameId=");
372         sb.append(getClassNameId());
373         sb.append(", classPK=");
374         sb.append(getClassPK());
375         sb.append(", name=");
376         sb.append(getName());
377         sb.append(", title=");
378         sb.append(getTitle());
379         sb.append(", description=");
380         sb.append(getDescription());
381         sb.append(", type=");
382         sb.append(getType());
383         sb.append(", subtype=");
384         sb.append(getSubtype());
385         sb.append("}");
386 
387         return sb.toString();
388     }
389 
390     public String toXmlString() {
391         StringBuilder sb = new StringBuilder();
392 
393         sb.append("<model><model-name>");
394         sb.append("com.liferay.portal.model.Role");
395         sb.append("</model-name>");
396 
397         sb.append(
398             "<column><column-name>roleId</column-name><column-value><![CDATA[");
399         sb.append(getRoleId());
400         sb.append("]]></column-value></column>");
401         sb.append(
402             "<column><column-name>companyId</column-name><column-value><![CDATA[");
403         sb.append(getCompanyId());
404         sb.append("]]></column-value></column>");
405         sb.append(
406             "<column><column-name>classNameId</column-name><column-value><![CDATA[");
407         sb.append(getClassNameId());
408         sb.append("]]></column-value></column>");
409         sb.append(
410             "<column><column-name>classPK</column-name><column-value><![CDATA[");
411         sb.append(getClassPK());
412         sb.append("]]></column-value></column>");
413         sb.append(
414             "<column><column-name>name</column-name><column-value><![CDATA[");
415         sb.append(getName());
416         sb.append("]]></column-value></column>");
417         sb.append(
418             "<column><column-name>title</column-name><column-value><![CDATA[");
419         sb.append(getTitle());
420         sb.append("]]></column-value></column>");
421         sb.append(
422             "<column><column-name>description</column-name><column-value><![CDATA[");
423         sb.append(getDescription());
424         sb.append("]]></column-value></column>");
425         sb.append(
426             "<column><column-name>type</column-name><column-value><![CDATA[");
427         sb.append(getType());
428         sb.append("]]></column-value></column>");
429         sb.append(
430             "<column><column-name>subtype</column-name><column-value><![CDATA[");
431         sb.append(getSubtype());
432         sb.append("]]></column-value></column>");
433 
434         sb.append("</model>");
435 
436         return sb.toString();
437     }
438 
439     private long _roleId;
440     private long _companyId;
441     private long _originalCompanyId;
442     private boolean _setOriginalCompanyId;
443     private long _classNameId;
444     private long _originalClassNameId;
445     private boolean _setOriginalClassNameId;
446     private long _classPK;
447     private long _originalClassPK;
448     private boolean _setOriginalClassPK;
449     private String _name;
450     private String _originalName;
451     private String _title;
452     private String _description;
453     private int _type;
454     private String _subtype;
455     private transient ExpandoBridge _expandoBridge;
456 }