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