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.Role;
29  import com.liferay.portal.model.RoleSoap;
30  import com.liferay.portal.util.PortalUtil;
31  
32  import java.io.Serializable;
33  
34  import java.lang.reflect.Proxy;
35  
36  import java.sql.Types;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  /**
42   * <a href="RoleModelImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * <p>
45   * ServiceBuilder generated this class. Modifications in this class will be
46   * overwritten the next time is generated.
47   * </p>
48   *
49   * <p>
50   * This class is a model that represents the <code>Role</code> table
51   * in the database.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   * @see com.liferay.portal.service.model.Role
57   * @see com.liferay.portal.service.model.RoleModel
58   * @see com.liferay.portal.service.model.impl.RoleImpl
59   *
60   */
61  public class RoleModelImpl extends BaseModelImpl {
62      public static final String TABLE_NAME = "Role_";
63      public static final Object[][] TABLE_COLUMNS = {
64              { "roleId", new Integer(Types.BIGINT) },
65              
66  
67              { "companyId", new Integer(Types.BIGINT) },
68              
69  
70              { "classNameId", new Integer(Types.BIGINT) },
71              
72  
73              { "classPK", new Integer(Types.BIGINT) },
74              
75  
76              { "name", new Integer(Types.VARCHAR) },
77              
78  
79              { "description", new Integer(Types.VARCHAR) },
80              
81  
82              { "type_", new Integer(Types.INTEGER) }
83          };
84      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,description STRING null,type_ INTEGER)";
85      public static final String TABLE_SQL_DROP = "drop table Role_";
86      public static final String DATA_SOURCE = "liferayDataSource";
87      public static final String SESSION_FACTORY = "liferaySessionFactory";
88      public static final String TX_MANAGER = "liferayTransactionManager";
89      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
90                  "value.object.finder.cache.enabled.com.liferay.portal.model.Role"),
91              true);
92  
93      public static Role toModel(RoleSoap soapModel) {
94          Role model = new RoleImpl();
95  
96          model.setRoleId(soapModel.getRoleId());
97          model.setCompanyId(soapModel.getCompanyId());
98          model.setClassNameId(soapModel.getClassNameId());
99          model.setClassPK(soapModel.getClassPK());
100         model.setName(soapModel.getName());
101         model.setDescription(soapModel.getDescription());
102         model.setType(soapModel.getType());
103 
104         return model;
105     }
106 
107     public static List<Role> toModels(RoleSoap[] soapModels) {
108         List<Role> models = new ArrayList<Role>(soapModels.length);
109 
110         for (RoleSoap soapModel : soapModels) {
111             models.add(toModel(soapModel));
112         }
113 
114         return models;
115     }
116 
117     public static final boolean CACHE_ENABLED_GROUPS_ROLES = com.liferay.portal.model.impl.GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
118     public static final boolean CACHE_ENABLED_ROLES_PERMISSIONS = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
119                 "value.object.finder.cache.enabled.Roles_Permissions"), true);
120     public static final boolean CACHE_ENABLED_USERS_ROLES = com.liferay.portal.model.impl.UserModelImpl.CACHE_ENABLED_USERS_ROLES;
121     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
122                 "lock.expiration.time.com.liferay.portal.model.Role"));
123 
124     public RoleModelImpl() {
125     }
126 
127     public long getPrimaryKey() {
128         return _roleId;
129     }
130 
131     public void setPrimaryKey(long pk) {
132         setRoleId(pk);
133     }
134 
135     public Serializable getPrimaryKeyObj() {
136         return new Long(_roleId);
137     }
138 
139     public long getRoleId() {
140         return _roleId;
141     }
142 
143     public void setRoleId(long roleId) {
144         if (roleId != _roleId) {
145             _roleId = roleId;
146         }
147     }
148 
149     public long getCompanyId() {
150         return _companyId;
151     }
152 
153     public void setCompanyId(long companyId) {
154         if (companyId != _companyId) {
155             _companyId = companyId;
156         }
157     }
158 
159     public String getClassName() {
160         return PortalUtil.getClassName(getClassNameId());
161     }
162 
163     public long getClassNameId() {
164         return _classNameId;
165     }
166 
167     public void setClassNameId(long classNameId) {
168         if (classNameId != _classNameId) {
169             _classNameId = classNameId;
170         }
171     }
172 
173     public long getClassPK() {
174         return _classPK;
175     }
176 
177     public void setClassPK(long classPK) {
178         if (classPK != _classPK) {
179             _classPK = classPK;
180         }
181     }
182 
183     public String getName() {
184         return GetterUtil.getString(_name);
185     }
186 
187     public void setName(String name) {
188         if (((name == null) && (_name != null)) ||
189                 ((name != null) && (_name == null)) ||
190                 ((name != null) && (_name != null) && !name.equals(_name))) {
191             _name = name;
192         }
193     }
194 
195     public String getDescription() {
196         return GetterUtil.getString(_description);
197     }
198 
199     public void setDescription(String description) {
200         if (((description == null) && (_description != null)) ||
201                 ((description != null) && (_description == null)) ||
202                 ((description != null) && (_description != null) &&
203                 !description.equals(_description))) {
204             _description = description;
205         }
206     }
207 
208     public int getType() {
209         return _type;
210     }
211 
212     public void setType(int type) {
213         if (type != _type) {
214             _type = type;
215         }
216     }
217 
218     public Role toEscapedModel() {
219         if (isEscapedModel()) {
220             return (Role)this;
221         }
222         else {
223             Role model = new RoleImpl();
224 
225             model.setEscapedModel(true);
226 
227             model.setRoleId(getRoleId());
228             model.setCompanyId(getCompanyId());
229             model.setClassNameId(getClassNameId());
230             model.setClassPK(getClassPK());
231             model.setName(HtmlUtil.escape(getName()));
232             model.setDescription(HtmlUtil.escape(getDescription()));
233             model.setType(getType());
234 
235             model = (Role)Proxy.newProxyInstance(Role.class.getClassLoader(),
236                     new Class[] { Role.class }, new ReadOnlyBeanHandler(model));
237 
238             return model;
239         }
240     }
241 
242     public Object clone() {
243         RoleImpl clone = new RoleImpl();
244 
245         clone.setRoleId(getRoleId());
246         clone.setCompanyId(getCompanyId());
247         clone.setClassNameId(getClassNameId());
248         clone.setClassPK(getClassPK());
249         clone.setName(getName());
250         clone.setDescription(getDescription());
251         clone.setType(getType());
252 
253         return clone;
254     }
255 
256     public int compareTo(Object obj) {
257         if (obj == null) {
258             return -1;
259         }
260 
261         RoleImpl role = (RoleImpl)obj;
262 
263         int value = 0;
264 
265         value = getName().compareTo(role.getName());
266 
267         if (value != 0) {
268             return value;
269         }
270 
271         return 0;
272     }
273 
274     public boolean equals(Object obj) {
275         if (obj == null) {
276             return false;
277         }
278 
279         RoleImpl role = null;
280 
281         try {
282             role = (RoleImpl)obj;
283         }
284         catch (ClassCastException cce) {
285             return false;
286         }
287 
288         long pk = role.getPrimaryKey();
289 
290         if (getPrimaryKey() == pk) {
291             return true;
292         }
293         else {
294             return false;
295         }
296     }
297 
298     public int hashCode() {
299         return (int)getPrimaryKey();
300     }
301 
302     private long _roleId;
303     private long _companyId;
304     private long _classNameId;
305     private long _classPK;
306     private String _name;
307     private String _description;
308     private int _type;
309 }