1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
18  import com.liferay.portal.kernel.language.LanguageUtil;
19  import com.liferay.portal.kernel.util.GetterUtil;
20  import com.liferay.portal.kernel.util.HtmlUtil;
21  import com.liferay.portal.kernel.util.LocaleUtil;
22  import com.liferay.portal.kernel.util.StringBundler;
23  import com.liferay.portal.kernel.util.StringPool;
24  import com.liferay.portal.kernel.util.Validator;
25  import com.liferay.portal.model.Role;
26  import com.liferay.portal.model.RoleSoap;
27  import com.liferay.portal.service.ServiceContext;
28  import com.liferay.portal.util.PortalUtil;
29  
30  import com.liferay.portlet.expando.model.ExpandoBridge;
31  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
32  
33  import com.liferay.util.LocalizationUtil;
34  
35  import java.io.Serializable;
36  
37  import java.lang.reflect.Proxy;
38  
39  import java.sql.Types;
40  
41  import java.util.ArrayList;
42  import java.util.List;
43  import java.util.Locale;
44  import java.util.Map;
45  
46  /**
47   * <a href="RoleModelImpl.java.html"><b><i>View Source</i></b></a>
48   *
49   * <p>
50   * ServiceBuilder generated this class. Modifications in this class will be
51   * overwritten the next time is generated.
52   * </p>
53   *
54   * <p>
55   * This interface is a model that represents the Role_ table in the
56   * database.
57   * </p>
58   *
59   * @author    Brian Wing Shun Chan
60   * @see       RoleImpl
61   * @see       com.liferay.portal.model.Role
62   * @see       com.liferay.portal.model.RoleModel
63   * @generated
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              { "companyId", new Integer(Types.BIGINT) },
70              { "classNameId", new Integer(Types.BIGINT) },
71              { "classPK", new Integer(Types.BIGINT) },
72              { "name", new Integer(Types.VARCHAR) },
73              { "title", new Integer(Types.VARCHAR) },
74              { "description", new Integer(Types.VARCHAR) },
75              { "type_", new Integer(Types.INTEGER) },
76              { "subtype", new Integer(Types.VARCHAR) }
77          };
78      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)";
79      public static final String TABLE_SQL_DROP = "drop table Role_";
80      public static final String ORDER_BY_JPQL = " ORDER BY role.name ASC";
81      public static final String ORDER_BY_SQL = " ORDER BY Role_.name ASC";
82      public static final String DATA_SOURCE = "liferayDataSource";
83      public static final String SESSION_FACTORY = "liferaySessionFactory";
84      public static final String TX_MANAGER = "liferayTransactionManager";
85      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
86                  "value.object.entity.cache.enabled.com.liferay.portal.model.Role"),
87              true);
88      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
89                  "value.object.finder.cache.enabled.com.liferay.portal.model.Role"),
90              true);
91  
92      public static Role toModel(RoleSoap soapModel) {
93          Role model = new RoleImpl();
94  
95          model.setRoleId(soapModel.getRoleId());
96          model.setCompanyId(soapModel.getCompanyId());
97          model.setClassNameId(soapModel.getClassNameId());
98          model.setClassPK(soapModel.getClassPK());
99          model.setName(soapModel.getName());
100         model.setTitle(soapModel.getTitle());
101         model.setDescription(soapModel.getDescription());
102         model.setType(soapModel.getType());
103         model.setSubtype(soapModel.getSubtype());
104 
105         return model;
106     }
107 
108     public static List<Role> toModels(RoleSoap[] soapModels) {
109         List<Role> models = new ArrayList<Role>(soapModels.length);
110 
111         for (RoleSoap soapModel : soapModels) {
112             models.add(toModel(soapModel));
113         }
114 
115         return models;
116     }
117 
118     public static final String MAPPING_TABLE_GROUPS_ROLES_NAME = com.liferay.portal.model.impl.GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME;
119     public static final boolean FINDER_CACHE_ENABLED_GROUPS_ROLES = com.liferay.portal.model.impl.GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES;
120     public static final String MAPPING_TABLE_ROLES_PERMISSIONS_NAME = "Roles_Permissions";
121     public static final Object[][] MAPPING_TABLE_ROLES_PERMISSIONS_COLUMNS = {
122             { "roleId", new Integer(Types.BIGINT) },
123             { "permissionId", new Integer(Types.BIGINT) }
124         };
125     public static final String MAPPING_TABLE_ROLES_PERMISSIONS_SQL_CREATE = "create table Roles_Permissions (roleId LONG not null,permissionId LONG not null,primary key (roleId, permissionId))";
126     public static final boolean FINDER_CACHE_ENABLED_ROLES_PERMISSIONS = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
127                 "value.object.finder.cache.enabled.Roles_Permissions"), true);
128     public static final String MAPPING_TABLE_USERS_ROLES_NAME = com.liferay.portal.model.impl.UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME;
129     public static final boolean FINDER_CACHE_ENABLED_USERS_ROLES = com.liferay.portal.model.impl.UserModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES;
130     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
131                 "lock.expiration.time.com.liferay.portal.model.Role"));
132 
133     public RoleModelImpl() {
134     }
135 
136     public long getPrimaryKey() {
137         return _roleId;
138     }
139 
140     public void setPrimaryKey(long pk) {
141         setRoleId(pk);
142     }
143 
144     public Serializable getPrimaryKeyObj() {
145         return new Long(_roleId);
146     }
147 
148     public long getRoleId() {
149         return _roleId;
150     }
151 
152     public void setRoleId(long roleId) {
153         _roleId = roleId;
154     }
155 
156     public long getCompanyId() {
157         return _companyId;
158     }
159 
160     public void setCompanyId(long companyId) {
161         _companyId = companyId;
162 
163         if (!_setOriginalCompanyId) {
164             _setOriginalCompanyId = true;
165 
166             _originalCompanyId = companyId;
167         }
168     }
169 
170     public long getOriginalCompanyId() {
171         return _originalCompanyId;
172     }
173 
174     public String getClassName() {
175         if (getClassNameId() <= 0) {
176             return StringPool.BLANK;
177         }
178 
179         return PortalUtil.getClassName(getClassNameId());
180     }
181 
182     public long getClassNameId() {
183         return _classNameId;
184     }
185 
186     public void setClassNameId(long classNameId) {
187         _classNameId = classNameId;
188 
189         if (!_setOriginalClassNameId) {
190             _setOriginalClassNameId = true;
191 
192             _originalClassNameId = classNameId;
193         }
194     }
195 
196     public long getOriginalClassNameId() {
197         return _originalClassNameId;
198     }
199 
200     public long getClassPK() {
201         return _classPK;
202     }
203 
204     public void setClassPK(long classPK) {
205         _classPK = classPK;
206 
207         if (!_setOriginalClassPK) {
208             _setOriginalClassPK = true;
209 
210             _originalClassPK = classPK;
211         }
212     }
213 
214     public long getOriginalClassPK() {
215         return _originalClassPK;
216     }
217 
218     public String getName() {
219         return GetterUtil.getString(_name);
220     }
221 
222     public void setName(String name) {
223         _name = name;
224 
225         if (_originalName == null) {
226             _originalName = name;
227         }
228     }
229 
230     public String getOriginalName() {
231         return GetterUtil.getString(_originalName);
232     }
233 
234     public String getTitle() {
235         return GetterUtil.getString(_title);
236     }
237 
238     public String getTitle(Locale locale) {
239         String languageId = LocaleUtil.toLanguageId(locale);
240 
241         return getTitle(languageId);
242     }
243 
244     public String getTitle(Locale locale, boolean useDefault) {
245         String languageId = LocaleUtil.toLanguageId(locale);
246 
247         return getTitle(languageId, useDefault);
248     }
249 
250     public String getTitle(String languageId) {
251         String value = LocalizationUtil.getLocalization(getTitle(), languageId);
252 
253         if (isEscapedModel()) {
254             return HtmlUtil.escape(value);
255         }
256         else {
257             return value;
258         }
259     }
260 
261     public String getTitle(String languageId, boolean useDefault) {
262         String value = LocalizationUtil.getLocalization(getTitle(), languageId,
263                 useDefault);
264 
265         if (isEscapedModel()) {
266             return HtmlUtil.escape(value);
267         }
268         else {
269             return value;
270         }
271     }
272 
273     public Map<Locale, String> getTitleMap() {
274         return LocalizationUtil.getLocalizationMap(getTitle());
275     }
276 
277     public void setTitle(String title) {
278         _title = title;
279     }
280 
281     public void setTitle(Locale locale, String title) {
282         String languageId = LocaleUtil.toLanguageId(locale);
283 
284         if (Validator.isNotNull(title)) {
285             setTitle(LocalizationUtil.updateLocalization(getTitle(), "Title",
286                     title, languageId));
287         }
288         else {
289             setTitle(LocalizationUtil.removeLocalization(getTitle(), "Title",
290                     languageId));
291         }
292     }
293 
294     public void setTitleMap(Map<Locale, String> titleMap) {
295         if (titleMap == null) {
296             return;
297         }
298 
299         Locale[] locales = LanguageUtil.getAvailableLocales();
300 
301         for (Locale locale : locales) {
302             String title = titleMap.get(locale);
303 
304             setTitle(locale, title);
305         }
306     }
307 
308     public String getDescription() {
309         return GetterUtil.getString(_description);
310     }
311 
312     public void setDescription(String description) {
313         _description = description;
314     }
315 
316     public int getType() {
317         return _type;
318     }
319 
320     public void setType(int type) {
321         _type = type;
322     }
323 
324     public String getSubtype() {
325         return GetterUtil.getString(_subtype);
326     }
327 
328     public void setSubtype(String subtype) {
329         _subtype = subtype;
330     }
331 
332     public Role toEscapedModel() {
333         if (isEscapedModel()) {
334             return (Role)this;
335         }
336         else {
337             Role model = new RoleImpl();
338 
339             model.setNew(isNew());
340             model.setEscapedModel(true);
341 
342             model.setRoleId(getRoleId());
343             model.setCompanyId(getCompanyId());
344             model.setClassNameId(getClassNameId());
345             model.setClassPK(getClassPK());
346             model.setName(HtmlUtil.escape(getName()));
347             model.setTitle(getTitle());
348             model.setDescription(HtmlUtil.escape(getDescription()));
349             model.setType(getType());
350             model.setSubtype(HtmlUtil.escape(getSubtype()));
351 
352             model = (Role)Proxy.newProxyInstance(Role.class.getClassLoader(),
353                     new Class[] { Role.class }, new ReadOnlyBeanHandler(model));
354 
355             return model;
356         }
357     }
358 
359     public ExpandoBridge getExpandoBridge() {
360         if (_expandoBridge == null) {
361             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
362                     Role.class.getName(), getPrimaryKey());
363         }
364 
365         return _expandoBridge;
366     }
367 
368     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
369         getExpandoBridge().setAttributes(serviceContext);
370     }
371 
372     public Object clone() {
373         RoleImpl clone = new RoleImpl();
374 
375         clone.setRoleId(getRoleId());
376         clone.setCompanyId(getCompanyId());
377         clone.setClassNameId(getClassNameId());
378         clone.setClassPK(getClassPK());
379         clone.setName(getName());
380         clone.setTitle(getTitle());
381         clone.setDescription(getDescription());
382         clone.setType(getType());
383         clone.setSubtype(getSubtype());
384 
385         return clone;
386     }
387 
388     public int compareTo(Role role) {
389         int value = 0;
390 
391         value = getName().compareTo(role.getName());
392 
393         if (value != 0) {
394             return value;
395         }
396 
397         return 0;
398     }
399 
400     public boolean equals(Object obj) {
401         if (obj == null) {
402             return false;
403         }
404 
405         Role role = null;
406 
407         try {
408             role = (Role)obj;
409         }
410         catch (ClassCastException cce) {
411             return false;
412         }
413 
414         long pk = role.getPrimaryKey();
415 
416         if (getPrimaryKey() == pk) {
417             return true;
418         }
419         else {
420             return false;
421         }
422     }
423 
424     public int hashCode() {
425         return (int)getPrimaryKey();
426     }
427 
428     public String toString() {
429         StringBundler sb = new StringBundler(19);
430 
431         sb.append("{roleId=");
432         sb.append(getRoleId());
433         sb.append(", companyId=");
434         sb.append(getCompanyId());
435         sb.append(", classNameId=");
436         sb.append(getClassNameId());
437         sb.append(", classPK=");
438         sb.append(getClassPK());
439         sb.append(", name=");
440         sb.append(getName());
441         sb.append(", title=");
442         sb.append(getTitle());
443         sb.append(", description=");
444         sb.append(getDescription());
445         sb.append(", type=");
446         sb.append(getType());
447         sb.append(", subtype=");
448         sb.append(getSubtype());
449         sb.append("}");
450 
451         return sb.toString();
452     }
453 
454     public String toXmlString() {
455         StringBundler sb = new StringBundler(31);
456 
457         sb.append("<model><model-name>");
458         sb.append("com.liferay.portal.model.Role");
459         sb.append("</model-name>");
460 
461         sb.append(
462             "<column><column-name>roleId</column-name><column-value><![CDATA[");
463         sb.append(getRoleId());
464         sb.append("]]></column-value></column>");
465         sb.append(
466             "<column><column-name>companyId</column-name><column-value><![CDATA[");
467         sb.append(getCompanyId());
468         sb.append("]]></column-value></column>");
469         sb.append(
470             "<column><column-name>classNameId</column-name><column-value><![CDATA[");
471         sb.append(getClassNameId());
472         sb.append("]]></column-value></column>");
473         sb.append(
474             "<column><column-name>classPK</column-name><column-value><![CDATA[");
475         sb.append(getClassPK());
476         sb.append("]]></column-value></column>");
477         sb.append(
478             "<column><column-name>name</column-name><column-value><![CDATA[");
479         sb.append(getName());
480         sb.append("]]></column-value></column>");
481         sb.append(
482             "<column><column-name>title</column-name><column-value><![CDATA[");
483         sb.append(getTitle());
484         sb.append("]]></column-value></column>");
485         sb.append(
486             "<column><column-name>description</column-name><column-value><![CDATA[");
487         sb.append(getDescription());
488         sb.append("]]></column-value></column>");
489         sb.append(
490             "<column><column-name>type</column-name><column-value><![CDATA[");
491         sb.append(getType());
492         sb.append("]]></column-value></column>");
493         sb.append(
494             "<column><column-name>subtype</column-name><column-value><![CDATA[");
495         sb.append(getSubtype());
496         sb.append("]]></column-value></column>");
497 
498         sb.append("</model>");
499 
500         return sb.toString();
501     }
502 
503     private long _roleId;
504     private long _companyId;
505     private long _originalCompanyId;
506     private boolean _setOriginalCompanyId;
507     private long _classNameId;
508     private long _originalClassNameId;
509     private boolean _setOriginalClassNameId;
510     private long _classPK;
511     private long _originalClassPK;
512     private boolean _setOriginalClassPK;
513     private String _name;
514     private String _originalName;
515     private String _title;
516     private String _description;
517     private int _type;
518     private String _subtype;
519     private transient ExpandoBridge _expandoBridge;
520 }