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