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