001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
018    import com.liferay.portal.kernel.language.LanguageUtil;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.HtmlUtil;
021    import com.liferay.portal.kernel.util.LocaleUtil;
022    import com.liferay.portal.kernel.util.LocalizationUtil;
023    import com.liferay.portal.kernel.util.StringBundler;
024    import com.liferay.portal.kernel.util.StringPool;
025    import com.liferay.portal.kernel.util.Validator;
026    import com.liferay.portal.model.Role;
027    import com.liferay.portal.model.RoleModel;
028    import com.liferay.portal.model.RoleSoap;
029    import com.liferay.portal.service.ServiceContext;
030    import com.liferay.portal.util.PortalUtil;
031    
032    import com.liferay.portlet.expando.model.ExpandoBridge;
033    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
034    
035    import java.io.Serializable;
036    
037    import java.lang.reflect.Proxy;
038    
039    import java.sql.Types;
040    
041    import java.util.ArrayList;
042    import java.util.List;
043    import java.util.Locale;
044    import java.util.Map;
045    
046    /**
047     * <p>
048     * This interface is a model that represents the Role_ table in the
049     * database.
050     * </p>
051     *
052     * @author    Brian Wing Shun Chan
053     * @see       RoleImpl
054     * @see       com.liferay.portal.model.Role
055     * @see       com.liferay.portal.model.RoleModel
056     * @generated
057     */
058    public class RoleModelImpl extends BaseModelImpl<Role> implements RoleModel {
059            public static final String TABLE_NAME = "Role_";
060            public static final Object[][] TABLE_COLUMNS = {
061                            { "roleId", new Integer(Types.BIGINT) },
062                            { "companyId", new Integer(Types.BIGINT) },
063                            { "classNameId", new Integer(Types.BIGINT) },
064                            { "classPK", new Integer(Types.BIGINT) },
065                            { "name", new Integer(Types.VARCHAR) },
066                            { "title", new Integer(Types.VARCHAR) },
067                            { "description", new Integer(Types.VARCHAR) },
068                            { "type_", new Integer(Types.INTEGER) },
069                            { "subtype", new Integer(Types.VARCHAR) }
070                    };
071            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)";
072            public static final String TABLE_SQL_DROP = "drop table Role_";
073            public static final String ORDER_BY_JPQL = " ORDER BY role.name ASC";
074            public static final String ORDER_BY_SQL = " ORDER BY Role_.name ASC";
075            public static final String DATA_SOURCE = "liferayDataSource";
076            public static final String SESSION_FACTORY = "liferaySessionFactory";
077            public static final String TX_MANAGER = "liferayTransactionManager";
078            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Role"),
080                            true);
081            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Role"),
083                            true);
084    
085            public static Role toModel(RoleSoap soapModel) {
086                    Role model = new RoleImpl();
087    
088                    model.setRoleId(soapModel.getRoleId());
089                    model.setCompanyId(soapModel.getCompanyId());
090                    model.setClassNameId(soapModel.getClassNameId());
091                    model.setClassPK(soapModel.getClassPK());
092                    model.setName(soapModel.getName());
093                    model.setTitle(soapModel.getTitle());
094                    model.setDescription(soapModel.getDescription());
095                    model.setType(soapModel.getType());
096                    model.setSubtype(soapModel.getSubtype());
097    
098                    return model;
099            }
100    
101            public static List<Role> toModels(RoleSoap[] soapModels) {
102                    List<Role> models = new ArrayList<Role>(soapModels.length);
103    
104                    for (RoleSoap soapModel : soapModels) {
105                            models.add(toModel(soapModel));
106                    }
107    
108                    return models;
109            }
110    
111            public static final String MAPPING_TABLE_GROUPS_ROLES_NAME = com.liferay.portal.model.impl.GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME;
112            public static final boolean FINDER_CACHE_ENABLED_GROUPS_ROLES = com.liferay.portal.model.impl.GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES;
113            public static final String MAPPING_TABLE_ROLES_PERMISSIONS_NAME = "Roles_Permissions";
114            public static final Object[][] MAPPING_TABLE_ROLES_PERMISSIONS_COLUMNS = {
115                            { "roleId", new Integer(Types.BIGINT) },
116                            { "permissionId", new Integer(Types.BIGINT) }
117                    };
118            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))";
119            public static final boolean FINDER_CACHE_ENABLED_ROLES_PERMISSIONS = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
120                                    "value.object.finder.cache.enabled.Roles_Permissions"), true);
121            public static final String MAPPING_TABLE_USERS_ROLES_NAME = com.liferay.portal.model.impl.UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME;
122            public static final boolean FINDER_CACHE_ENABLED_USERS_ROLES = com.liferay.portal.model.impl.UserModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES;
123            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
124                                    "lock.expiration.time.com.liferay.portal.model.Role"));
125    
126            public RoleModelImpl() {
127            }
128    
129            public long getPrimaryKey() {
130                    return _roleId;
131            }
132    
133            public void setPrimaryKey(long pk) {
134                    setRoleId(pk);
135            }
136    
137            public Serializable getPrimaryKeyObj() {
138                    return new Long(_roleId);
139            }
140    
141            public long getRoleId() {
142                    return _roleId;
143            }
144    
145            public void setRoleId(long roleId) {
146                    _roleId = roleId;
147            }
148    
149            public long getCompanyId() {
150                    return _companyId;
151            }
152    
153            public void setCompanyId(long companyId) {
154                    _companyId = companyId;
155    
156                    if (!_setOriginalCompanyId) {
157                            _setOriginalCompanyId = true;
158    
159                            _originalCompanyId = companyId;
160                    }
161            }
162    
163            public long getOriginalCompanyId() {
164                    return _originalCompanyId;
165            }
166    
167            public String getClassName() {
168                    if (getClassNameId() <= 0) {
169                            return StringPool.BLANK;
170                    }
171    
172                    return PortalUtil.getClassName(getClassNameId());
173            }
174    
175            public long getClassNameId() {
176                    return _classNameId;
177            }
178    
179            public void setClassNameId(long classNameId) {
180                    _classNameId = classNameId;
181    
182                    if (!_setOriginalClassNameId) {
183                            _setOriginalClassNameId = true;
184    
185                            _originalClassNameId = classNameId;
186                    }
187            }
188    
189            public long getOriginalClassNameId() {
190                    return _originalClassNameId;
191            }
192    
193            public long getClassPK() {
194                    return _classPK;
195            }
196    
197            public void setClassPK(long classPK) {
198                    _classPK = classPK;
199    
200                    if (!_setOriginalClassPK) {
201                            _setOriginalClassPK = true;
202    
203                            _originalClassPK = classPK;
204                    }
205            }
206    
207            public long getOriginalClassPK() {
208                    return _originalClassPK;
209            }
210    
211            public String getName() {
212                    if (_name == null) {
213                            return StringPool.BLANK;
214                    }
215                    else {
216                            return _name;
217                    }
218            }
219    
220            public void setName(String name) {
221                    _name = name;
222    
223                    if (_originalName == null) {
224                            _originalName = name;
225                    }
226            }
227    
228            public String getOriginalName() {
229                    return GetterUtil.getString(_originalName);
230            }
231    
232            public String getTitle() {
233                    if (_title == null) {
234                            return StringPool.BLANK;
235                    }
236                    else {
237                            return _title;
238                    }
239            }
240    
241            public String getTitle(Locale locale) {
242                    String languageId = LocaleUtil.toLanguageId(locale);
243    
244                    return getTitle(languageId);
245            }
246    
247            public String getTitle(Locale locale, boolean useDefault) {
248                    String languageId = LocaleUtil.toLanguageId(locale);
249    
250                    return getTitle(languageId, useDefault);
251            }
252    
253            public String getTitle(String languageId) {
254                    String value = LocalizationUtil.getLocalization(getTitle(), languageId);
255    
256                    if (isEscapedModel()) {
257                            return HtmlUtil.escape(value);
258                    }
259                    else {
260                            return value;
261                    }
262            }
263    
264            public String getTitle(String languageId, boolean useDefault) {
265                    String value = LocalizationUtil.getLocalization(getTitle(), languageId,
266                                    useDefault);
267    
268                    if (isEscapedModel()) {
269                            return HtmlUtil.escape(value);
270                    }
271                    else {
272                            return value;
273                    }
274            }
275    
276            public Map<Locale, String> getTitleMap() {
277                    return LocalizationUtil.getLocalizationMap(getTitle());
278            }
279    
280            public void setTitle(String title) {
281                    _title = title;
282            }
283    
284            public void setTitle(Locale locale, String title) {
285                    String languageId = LocaleUtil.toLanguageId(locale);
286    
287                    if (Validator.isNotNull(title)) {
288                            setTitle(LocalizationUtil.updateLocalization(getTitle(), "Title",
289                                            title, languageId));
290                    }
291                    else {
292                            setTitle(LocalizationUtil.removeLocalization(getTitle(), "Title",
293                                            languageId));
294                    }
295            }
296    
297            public void setTitleMap(Map<Locale, String> titleMap) {
298                    if (titleMap == null) {
299                            return;
300                    }
301    
302                    Locale[] locales = LanguageUtil.getAvailableLocales();
303    
304                    for (Locale locale : locales) {
305                            String title = titleMap.get(locale);
306    
307                            setTitle(locale, title);
308                    }
309            }
310    
311            public String getDescription() {
312                    if (_description == null) {
313                            return StringPool.BLANK;
314                    }
315                    else {
316                            return _description;
317                    }
318            }
319    
320            public void setDescription(String description) {
321                    _description = description;
322            }
323    
324            public int getType() {
325                    return _type;
326            }
327    
328            public void setType(int type) {
329                    _type = type;
330            }
331    
332            public String getSubtype() {
333                    if (_subtype == null) {
334                            return StringPool.BLANK;
335                    }
336                    else {
337                            return _subtype;
338                    }
339            }
340    
341            public void setSubtype(String subtype) {
342                    _subtype = subtype;
343            }
344    
345            public Role toEscapedModel() {
346                    if (isEscapedModel()) {
347                            return (Role)this;
348                    }
349                    else {
350                            return (Role)Proxy.newProxyInstance(Role.class.getClassLoader(),
351                                    new Class[] { Role.class }, new AutoEscapeBeanHandler(this));
352                    }
353            }
354    
355            public ExpandoBridge getExpandoBridge() {
356                    if (_expandoBridge == null) {
357                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
358                                            Role.class.getName(), getPrimaryKey());
359                    }
360    
361                    return _expandoBridge;
362            }
363    
364            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
365                    getExpandoBridge().setAttributes(serviceContext);
366            }
367    
368            public Object clone() {
369                    RoleImpl clone = new RoleImpl();
370    
371                    clone.setRoleId(getRoleId());
372                    clone.setCompanyId(getCompanyId());
373                    clone.setClassNameId(getClassNameId());
374                    clone.setClassPK(getClassPK());
375                    clone.setName(getName());
376                    clone.setTitle(getTitle());
377                    clone.setDescription(getDescription());
378                    clone.setType(getType());
379                    clone.setSubtype(getSubtype());
380    
381                    return clone;
382            }
383    
384            public int compareTo(Role role) {
385                    int value = 0;
386    
387                    value = getName().compareTo(role.getName());
388    
389                    if (value != 0) {
390                            return value;
391                    }
392    
393                    return 0;
394            }
395    
396            public boolean equals(Object obj) {
397                    if (obj == null) {
398                            return false;
399                    }
400    
401                    Role role = null;
402    
403                    try {
404                            role = (Role)obj;
405                    }
406                    catch (ClassCastException cce) {
407                            return false;
408                    }
409    
410                    long pk = role.getPrimaryKey();
411    
412                    if (getPrimaryKey() == pk) {
413                            return true;
414                    }
415                    else {
416                            return false;
417                    }
418            }
419    
420            public int hashCode() {
421                    return (int)getPrimaryKey();
422            }
423    
424            public String toString() {
425                    StringBundler sb = new StringBundler(19);
426    
427                    sb.append("{roleId=");
428                    sb.append(getRoleId());
429                    sb.append(", companyId=");
430                    sb.append(getCompanyId());
431                    sb.append(", classNameId=");
432                    sb.append(getClassNameId());
433                    sb.append(", classPK=");
434                    sb.append(getClassPK());
435                    sb.append(", name=");
436                    sb.append(getName());
437                    sb.append(", title=");
438                    sb.append(getTitle());
439                    sb.append(", description=");
440                    sb.append(getDescription());
441                    sb.append(", type=");
442                    sb.append(getType());
443                    sb.append(", subtype=");
444                    sb.append(getSubtype());
445                    sb.append("}");
446    
447                    return sb.toString();
448            }
449    
450            public String toXmlString() {
451                    StringBundler sb = new StringBundler(31);
452    
453                    sb.append("<model><model-name>");
454                    sb.append("com.liferay.portal.model.Role");
455                    sb.append("</model-name>");
456    
457                    sb.append(
458                            "<column><column-name>roleId</column-name><column-value><![CDATA[");
459                    sb.append(getRoleId());
460                    sb.append("]]></column-value></column>");
461                    sb.append(
462                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
463                    sb.append(getCompanyId());
464                    sb.append("]]></column-value></column>");
465                    sb.append(
466                            "<column><column-name>classNameId</column-name><column-value><![CDATA[");
467                    sb.append(getClassNameId());
468                    sb.append("]]></column-value></column>");
469                    sb.append(
470                            "<column><column-name>classPK</column-name><column-value><![CDATA[");
471                    sb.append(getClassPK());
472                    sb.append("]]></column-value></column>");
473                    sb.append(
474                            "<column><column-name>name</column-name><column-value><![CDATA[");
475                    sb.append(getName());
476                    sb.append("]]></column-value></column>");
477                    sb.append(
478                            "<column><column-name>title</column-name><column-value><![CDATA[");
479                    sb.append(getTitle());
480                    sb.append("]]></column-value></column>");
481                    sb.append(
482                            "<column><column-name>description</column-name><column-value><![CDATA[");
483                    sb.append(getDescription());
484                    sb.append("]]></column-value></column>");
485                    sb.append(
486                            "<column><column-name>type</column-name><column-value><![CDATA[");
487                    sb.append(getType());
488                    sb.append("]]></column-value></column>");
489                    sb.append(
490                            "<column><column-name>subtype</column-name><column-value><![CDATA[");
491                    sb.append(getSubtype());
492                    sb.append("]]></column-value></column>");
493    
494                    sb.append("</model>");
495    
496                    return sb.toString();
497            }
498    
499            private long _roleId;
500            private long _companyId;
501            private long _originalCompanyId;
502            private boolean _setOriginalCompanyId;
503            private long _classNameId;
504            private long _originalClassNameId;
505            private boolean _setOriginalClassNameId;
506            private long _classPK;
507            private long _originalClassPK;
508            private boolean _setOriginalClassPK;
509            private String _name;
510            private String _originalName;
511            private String _title;
512            private String _description;
513            private int _type;
514            private String _subtype;
515            private transient ExpandoBridge _expandoBridge;
516    }