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