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 {
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 CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
100                 "value.object.finder.cache.enabled.com.liferay.portal.model.Role"),
101             true);
102 
103     public static Role toModel(RoleSoap soapModel) {
104         Role model = new RoleImpl();
105 
106         model.setRoleId(soapModel.getRoleId());
107         model.setCompanyId(soapModel.getCompanyId());
108         model.setClassNameId(soapModel.getClassNameId());
109         model.setClassPK(soapModel.getClassPK());
110         model.setName(soapModel.getName());
111         model.setTitle(soapModel.getTitle());
112         model.setDescription(soapModel.getDescription());
113         model.setType(soapModel.getType());
114         model.setSubtype(soapModel.getSubtype());
115 
116         return model;
117     }
118 
119     public static List<Role> toModels(RoleSoap[] soapModels) {
120         List<Role> models = new ArrayList<Role>(soapModels.length);
121 
122         for (RoleSoap soapModel : soapModels) {
123             models.add(toModel(soapModel));
124         }
125 
126         return models;
127     }
128 
129     public static final boolean CACHE_ENABLED_GROUPS_ROLES = com.liferay.portal.model.impl.GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
130     public static final boolean CACHE_ENABLED_ROLES_PERMISSIONS = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
131                 "value.object.finder.cache.enabled.Roles_Permissions"), true);
132     public static final boolean CACHE_ENABLED_USERS_ROLES = com.liferay.portal.model.impl.UserModelImpl.CACHE_ENABLED_USERS_ROLES;
133     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
134                 "lock.expiration.time.com.liferay.portal.model.Role"));
135 
136     public RoleModelImpl() {
137     }
138 
139     public long getPrimaryKey() {
140         return _roleId;
141     }
142 
143     public void setPrimaryKey(long pk) {
144         setRoleId(pk);
145     }
146 
147     public Serializable getPrimaryKeyObj() {
148         return new Long(_roleId);
149     }
150 
151     public long getRoleId() {
152         return _roleId;
153     }
154 
155     public void setRoleId(long roleId) {
156         if (roleId != _roleId) {
157             _roleId = roleId;
158         }
159     }
160 
161     public long getCompanyId() {
162         return _companyId;
163     }
164 
165     public void setCompanyId(long companyId) {
166         if (companyId != _companyId) {
167             _companyId = companyId;
168         }
169     }
170 
171     public String getClassName() {
172         if (getClassNameId() <= 0) {
173             return StringPool.BLANK;
174         }
175 
176         return PortalUtil.getClassName(getClassNameId());
177     }
178 
179     public long getClassNameId() {
180         return _classNameId;
181     }
182 
183     public void setClassNameId(long classNameId) {
184         if (classNameId != _classNameId) {
185             _classNameId = classNameId;
186         }
187     }
188 
189     public long getClassPK() {
190         return _classPK;
191     }
192 
193     public void setClassPK(long classPK) {
194         if (classPK != _classPK) {
195             _classPK = classPK;
196         }
197     }
198 
199     public String getName() {
200         return GetterUtil.getString(_name);
201     }
202 
203     public void setName(String name) {
204         if (((name == null) && (_name != null)) ||
205                 ((name != null) && (_name == null)) ||
206                 ((name != null) && (_name != null) && !name.equals(_name))) {
207             _name = name;
208         }
209     }
210 
211     public String getTitle() {
212         return GetterUtil.getString(_title);
213     }
214 
215     public void setTitle(String title) {
216         if (((title == null) && (_title != null)) ||
217                 ((title != null) && (_title == null)) ||
218                 ((title != null) && (_title != null) && !title.equals(_title))) {
219             _title = title;
220         }
221     }
222 
223     public String getDescription() {
224         return GetterUtil.getString(_description);
225     }
226 
227     public void setDescription(String description) {
228         if (((description == null) && (_description != null)) ||
229                 ((description != null) && (_description == null)) ||
230                 ((description != null) && (_description != null) &&
231                 !description.equals(_description))) {
232             _description = description;
233         }
234     }
235 
236     public int getType() {
237         return _type;
238     }
239 
240     public void setType(int type) {
241         if (type != _type) {
242             _type = type;
243         }
244     }
245 
246     public String getSubtype() {
247         return GetterUtil.getString(_subtype);
248     }
249 
250     public void setSubtype(String subtype) {
251         if (((subtype == null) && (_subtype != null)) ||
252                 ((subtype != null) && (_subtype == null)) ||
253                 ((subtype != null) && (_subtype != null) &&
254                 !subtype.equals(_subtype))) {
255             _subtype = subtype;
256         }
257     }
258 
259     public Role toEscapedModel() {
260         if (isEscapedModel()) {
261             return (Role)this;
262         }
263         else {
264             Role model = new RoleImpl();
265 
266             model.setNew(isNew());
267             model.setEscapedModel(true);
268 
269             model.setRoleId(getRoleId());
270             model.setCompanyId(getCompanyId());
271             model.setClassNameId(getClassNameId());
272             model.setClassPK(getClassPK());
273             model.setName(HtmlUtil.escape(getName()));
274             model.setTitle(HtmlUtil.escape(getTitle()));
275             model.setDescription(HtmlUtil.escape(getDescription()));
276             model.setType(getType());
277             model.setSubtype(HtmlUtil.escape(getSubtype()));
278 
279             model = (Role)Proxy.newProxyInstance(Role.class.getClassLoader(),
280                     new Class[] { Role.class }, new ReadOnlyBeanHandler(model));
281 
282             return model;
283         }
284     }
285 
286     public ExpandoBridge getExpandoBridge() {
287         if (_expandoBridge == null) {
288             _expandoBridge = new ExpandoBridgeImpl(Role.class.getName(),
289                     getPrimaryKey());
290         }
291 
292         return _expandoBridge;
293     }
294 
295     public Object clone() {
296         RoleImpl clone = new RoleImpl();
297 
298         clone.setRoleId(getRoleId());
299         clone.setCompanyId(getCompanyId());
300         clone.setClassNameId(getClassNameId());
301         clone.setClassPK(getClassPK());
302         clone.setName(getName());
303         clone.setTitle(getTitle());
304         clone.setDescription(getDescription());
305         clone.setType(getType());
306         clone.setSubtype(getSubtype());
307 
308         return clone;
309     }
310 
311     public int compareTo(Object obj) {
312         if (obj == null) {
313             return -1;
314         }
315 
316         RoleImpl role = (RoleImpl)obj;
317 
318         int value = 0;
319 
320         value = getName().compareTo(role.getName());
321 
322         if (value != 0) {
323             return value;
324         }
325 
326         return 0;
327     }
328 
329     public boolean equals(Object obj) {
330         if (obj == null) {
331             return false;
332         }
333 
334         RoleImpl role = null;
335 
336         try {
337             role = (RoleImpl)obj;
338         }
339         catch (ClassCastException cce) {
340             return false;
341         }
342 
343         long pk = role.getPrimaryKey();
344 
345         if (getPrimaryKey() == pk) {
346             return true;
347         }
348         else {
349             return false;
350         }
351     }
352 
353     public int hashCode() {
354         return (int)getPrimaryKey();
355     }
356 
357     private long _roleId;
358     private long _companyId;
359     private long _classNameId;
360     private long _classPK;
361     private String _name;
362     private String _title;
363     private String _description;
364     private int _type;
365     private String _subtype;
366     private transient ExpandoBridge _expandoBridge;
367 }