1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.util.GetterUtil;
27  import com.liferay.portal.kernel.util.HtmlUtil;
28  import com.liferay.portal.model.Permission;
29  import com.liferay.portal.model.PermissionSoap;
30  import com.liferay.portal.util.PropsUtil;
31  
32  import java.io.Serializable;
33  
34  import java.lang.reflect.Proxy;
35  
36  import java.sql.Types;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  /**
42   * <a href="PermissionModelImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * <p>
45   * ServiceBuilder generated this class. Modifications in this class will be
46   * overwritten the next time is generated.
47   * </p>
48   *
49   * <p>
50   * This class is a model that represents the <code>Permission</code> table
51   * in the database.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   * @see com.liferay.portal.service.model.Permission
57   * @see com.liferay.portal.service.model.PermissionModel
58   * @see com.liferay.portal.service.model.impl.PermissionImpl
59   *
60   */
61  public class PermissionModelImpl extends BaseModelImpl {
62      public static final String TABLE_NAME = "Permission_";
63      public static final Object[][] TABLE_COLUMNS = {
64              { "permissionId", new Integer(Types.BIGINT) },
65              
66  
67              { "companyId", new Integer(Types.BIGINT) },
68              
69  
70              { "actionId", new Integer(Types.VARCHAR) },
71              
72  
73              { "resourceId", new Integer(Types.BIGINT) }
74          };
75      public static final String TABLE_SQL_CREATE = "create table Permission_ (permissionId LONG not null primary key,companyId LONG,actionId VARCHAR(75) null,resourceId LONG)";
76      public static final String TABLE_SQL_DROP = "drop table Permission_";
77      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
78                  "value.object.finder.cache.enabled.com.liferay.portal.model.Permission"),
79              true);
80  
81      public static Permission toModel(PermissionSoap soapModel) {
82          Permission model = new PermissionImpl();
83  
84          model.setPermissionId(soapModel.getPermissionId());
85          model.setCompanyId(soapModel.getCompanyId());
86          model.setActionId(soapModel.getActionId());
87          model.setResourceId(soapModel.getResourceId());
88  
89          return model;
90      }
91  
92      public static List<Permission> toModels(PermissionSoap[] soapModels) {
93          List<Permission> models = new ArrayList<Permission>(soapModels.length);
94  
95          for (PermissionSoap soapModel : soapModels) {
96              models.add(toModel(soapModel));
97          }
98  
99          return models;
100     }
101 
102     public static final boolean CACHE_ENABLED_GROUPS_PERMISSIONS = com.liferay.portal.model.impl.GroupModelImpl.CACHE_ENABLED_GROUPS_PERMISSIONS;
103     public static final boolean CACHE_ENABLED_ROLES_PERMISSIONS = com.liferay.portal.model.impl.RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS;
104     public static final boolean CACHE_ENABLED_USERS_PERMISSIONS = com.liferay.portal.model.impl.UserModelImpl.CACHE_ENABLED_USERS_PERMISSIONS;
105     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
106                 "lock.expiration.time.com.liferay.portal.model.Permission"));
107 
108     public PermissionModelImpl() {
109     }
110 
111     public long getPrimaryKey() {
112         return _permissionId;
113     }
114 
115     public void setPrimaryKey(long pk) {
116         setPermissionId(pk);
117     }
118 
119     public Serializable getPrimaryKeyObj() {
120         return new Long(_permissionId);
121     }
122 
123     public long getPermissionId() {
124         return _permissionId;
125     }
126 
127     public void setPermissionId(long permissionId) {
128         if (permissionId != _permissionId) {
129             _permissionId = permissionId;
130         }
131     }
132 
133     public long getCompanyId() {
134         return _companyId;
135     }
136 
137     public void setCompanyId(long companyId) {
138         if (companyId != _companyId) {
139             _companyId = companyId;
140         }
141     }
142 
143     public String getActionId() {
144         return GetterUtil.getString(_actionId);
145     }
146 
147     public void setActionId(String actionId) {
148         if (((actionId == null) && (_actionId != null)) ||
149                 ((actionId != null) && (_actionId == null)) ||
150                 ((actionId != null) && (_actionId != null) &&
151                 !actionId.equals(_actionId))) {
152             _actionId = actionId;
153         }
154     }
155 
156     public long getResourceId() {
157         return _resourceId;
158     }
159 
160     public void setResourceId(long resourceId) {
161         if (resourceId != _resourceId) {
162             _resourceId = resourceId;
163         }
164     }
165 
166     public Permission toEscapedModel() {
167         if (isEscapedModel()) {
168             return (Permission)this;
169         }
170         else {
171             Permission model = new PermissionImpl();
172 
173             model.setEscapedModel(true);
174 
175             model.setPermissionId(getPermissionId());
176             model.setCompanyId(getCompanyId());
177             model.setActionId(HtmlUtil.escape(getActionId()));
178             model.setResourceId(getResourceId());
179 
180             model = (Permission)Proxy.newProxyInstance(Permission.class.getClassLoader(),
181                     new Class[] { Permission.class },
182                     new ReadOnlyBeanHandler(model));
183 
184             return model;
185         }
186     }
187 
188     public Object clone() {
189         PermissionImpl clone = new PermissionImpl();
190 
191         clone.setPermissionId(getPermissionId());
192         clone.setCompanyId(getCompanyId());
193         clone.setActionId(getActionId());
194         clone.setResourceId(getResourceId());
195 
196         return clone;
197     }
198 
199     public int compareTo(Object obj) {
200         if (obj == null) {
201             return -1;
202         }
203 
204         PermissionImpl permission = (PermissionImpl)obj;
205 
206         long pk = permission.getPrimaryKey();
207 
208         if (getPrimaryKey() < pk) {
209             return -1;
210         }
211         else if (getPrimaryKey() > pk) {
212             return 1;
213         }
214         else {
215             return 0;
216         }
217     }
218 
219     public boolean equals(Object obj) {
220         if (obj == null) {
221             return false;
222         }
223 
224         PermissionImpl permission = null;
225 
226         try {
227             permission = (PermissionImpl)obj;
228         }
229         catch (ClassCastException cce) {
230             return false;
231         }
232 
233         long pk = permission.getPrimaryKey();
234 
235         if (getPrimaryKey() == pk) {
236             return true;
237         }
238         else {
239             return false;
240         }
241     }
242 
243     public int hashCode() {
244         return (int)getPrimaryKey();
245     }
246 
247     private long _permissionId;
248     private long _companyId;
249     private String _actionId;
250     private long _resourceId;
251 }