1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.model.impl;
21  
22  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
23  import com.liferay.portal.kernel.util.GetterUtil;
24  import com.liferay.portal.kernel.util.HtmlUtil;
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.model.Role;
27  import com.liferay.portal.model.RoleSoap;
28  import com.liferay.portal.util.PortalUtil;
29  
30  import java.io.Serializable;
31  
32  import java.lang.reflect.Proxy;
33  
34  import java.sql.Types;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  /**
40   * <a href="RoleModelImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * <p>
43   * ServiceBuilder generated this class. Modifications in this class will be
44   * overwritten the next time is generated.
45   * </p>
46   *
47   * <p>
48   * This class is a model that represents the <code>Role</code> table
49   * in the database.
50   * </p>
51   *
52   * @author Brian Wing Shun Chan
53   *
54   * @see com.liferay.portal.model.Role
55   * @see com.liferay.portal.model.RoleModel
56   * @see com.liferay.portal.model.impl.RoleImpl
57   *
58   */
59  public class RoleModelImpl extends BaseModelImpl {
60      public static final String TABLE_NAME = "Role_";
61      public static final Object[][] TABLE_COLUMNS = {
62              { "roleId", new Integer(Types.BIGINT) },
63              
64  
65              { "companyId", new Integer(Types.BIGINT) },
66              
67  
68              { "classNameId", new Integer(Types.BIGINT) },
69              
70  
71              { "classPK", new Integer(Types.BIGINT) },
72              
73  
74              { "name", new Integer(Types.VARCHAR) },
75              
76  
77              { "description", new Integer(Types.VARCHAR) },
78              
79  
80              { "type_", new Integer(Types.INTEGER) }
81          };
82      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)";
83      public static final String TABLE_SQL_DROP = "drop table Role_";
84      public static final String DATA_SOURCE = "liferayDataSource";
85      public static final String SESSION_FACTORY = "liferaySessionFactory";
86      public static final String TX_MANAGER = "liferayTransactionManager";
87      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
88                  "value.object.finder.cache.enabled.com.liferay.portal.model.Role"),
89              true);
90  
91      public static Role toModel(RoleSoap soapModel) {
92          Role model = new RoleImpl();
93  
94          model.setRoleId(soapModel.getRoleId());
95          model.setCompanyId(soapModel.getCompanyId());
96          model.setClassNameId(soapModel.getClassNameId());
97          model.setClassPK(soapModel.getClassPK());
98          model.setName(soapModel.getName());
99          model.setDescription(soapModel.getDescription());
100         model.setType(soapModel.getType());
101 
102         return model;
103     }
104 
105     public static List<Role> toModels(RoleSoap[] soapModels) {
106         List<Role> models = new ArrayList<Role>(soapModels.length);
107 
108         for (RoleSoap soapModel : soapModels) {
109             models.add(toModel(soapModel));
110         }
111 
112         return models;
113     }
114 
115     public static final boolean CACHE_ENABLED_GROUPS_ROLES = com.liferay.portal.model.impl.GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
116     public static final boolean CACHE_ENABLED_ROLES_PERMISSIONS = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
117                 "value.object.finder.cache.enabled.Roles_Permissions"), true);
118     public static final boolean CACHE_ENABLED_USERS_ROLES = com.liferay.portal.model.impl.UserModelImpl.CACHE_ENABLED_USERS_ROLES;
119     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
120                 "lock.expiration.time.com.liferay.portal.model.Role"));
121 
122     public RoleModelImpl() {
123     }
124 
125     public long getPrimaryKey() {
126         return _roleId;
127     }
128 
129     public void setPrimaryKey(long pk) {
130         setRoleId(pk);
131     }
132 
133     public Serializable getPrimaryKeyObj() {
134         return new Long(_roleId);
135     }
136 
137     public long getRoleId() {
138         return _roleId;
139     }
140 
141     public void setRoleId(long roleId) {
142         if (roleId != _roleId) {
143             _roleId = roleId;
144         }
145     }
146 
147     public long getCompanyId() {
148         return _companyId;
149     }
150 
151     public void setCompanyId(long companyId) {
152         if (companyId != _companyId) {
153             _companyId = companyId;
154         }
155     }
156 
157     public String getClassName() {
158         if (getClassNameId() <= 0) {
159             return StringPool.BLANK;
160         }
161 
162         return PortalUtil.getClassName(getClassNameId());
163     }
164 
165     public long getClassNameId() {
166         return _classNameId;
167     }
168 
169     public void setClassNameId(long classNameId) {
170         if (classNameId != _classNameId) {
171             _classNameId = classNameId;
172         }
173     }
174 
175     public long getClassPK() {
176         return _classPK;
177     }
178 
179     public void setClassPK(long classPK) {
180         if (classPK != _classPK) {
181             _classPK = classPK;
182         }
183     }
184 
185     public String getName() {
186         return GetterUtil.getString(_name);
187     }
188 
189     public void setName(String name) {
190         if (((name == null) && (_name != null)) ||
191                 ((name != null) && (_name == null)) ||
192                 ((name != null) && (_name != null) && !name.equals(_name))) {
193             _name = name;
194         }
195     }
196 
197     public String getDescription() {
198         return GetterUtil.getString(_description);
199     }
200 
201     public void setDescription(String description) {
202         if (((description == null) && (_description != null)) ||
203                 ((description != null) && (_description == null)) ||
204                 ((description != null) && (_description != null) &&
205                 !description.equals(_description))) {
206             _description = description;
207         }
208     }
209 
210     public int getType() {
211         return _type;
212     }
213 
214     public void setType(int type) {
215         if (type != _type) {
216             _type = type;
217         }
218     }
219 
220     public Role toEscapedModel() {
221         if (isEscapedModel()) {
222             return (Role)this;
223         }
224         else {
225             Role model = new RoleImpl();
226 
227             model.setNew(isNew());
228             model.setEscapedModel(true);
229 
230             model.setRoleId(getRoleId());
231             model.setCompanyId(getCompanyId());
232             model.setClassNameId(getClassNameId());
233             model.setClassPK(getClassPK());
234             model.setName(HtmlUtil.escape(getName()));
235             model.setDescription(HtmlUtil.escape(getDescription()));
236             model.setType(getType());
237 
238             model = (Role)Proxy.newProxyInstance(Role.class.getClassLoader(),
239                     new Class[] { Role.class }, new ReadOnlyBeanHandler(model));
240 
241             return model;
242         }
243     }
244 
245     public Object clone() {
246         RoleImpl clone = new RoleImpl();
247 
248         clone.setRoleId(getRoleId());
249         clone.setCompanyId(getCompanyId());
250         clone.setClassNameId(getClassNameId());
251         clone.setClassPK(getClassPK());
252         clone.setName(getName());
253         clone.setDescription(getDescription());
254         clone.setType(getType());
255 
256         return clone;
257     }
258 
259     public int compareTo(Object obj) {
260         if (obj == null) {
261             return -1;
262         }
263 
264         RoleImpl role = (RoleImpl)obj;
265 
266         int value = 0;
267 
268         value = getName().compareTo(role.getName());
269 
270         if (value != 0) {
271             return value;
272         }
273 
274         return 0;
275     }
276 
277     public boolean equals(Object obj) {
278         if (obj == null) {
279             return false;
280         }
281 
282         RoleImpl role = null;
283 
284         try {
285             role = (RoleImpl)obj;
286         }
287         catch (ClassCastException cce) {
288             return false;
289         }
290 
291         long pk = role.getPrimaryKey();
292 
293         if (getPrimaryKey() == pk) {
294             return true;
295         }
296         else {
297             return false;
298         }
299     }
300 
301     public int hashCode() {
302         return (int)getPrimaryKey();
303     }
304 
305     private long _roleId;
306     private long _companyId;
307     private long _classNameId;
308     private long _classPK;
309     private String _name;
310     private String _description;
311     private int _type;
312 }