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.Resource;
29  import com.liferay.portal.model.ResourceSoap;
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="ResourceModelImpl.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>Resource</code> table
51   * in the database.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   * @see com.liferay.portal.service.model.Resource
57   * @see com.liferay.portal.service.model.ResourceModel
58   * @see com.liferay.portal.service.model.impl.ResourceImpl
59   *
60   */
61  public class ResourceModelImpl extends BaseModelImpl {
62      public static final String TABLE_NAME = "Resource_";
63      public static final Object[][] TABLE_COLUMNS = {
64              { "resourceId", new Integer(Types.BIGINT) },
65              
66  
67              { "codeId", new Integer(Types.BIGINT) },
68              
69  
70              { "primKey", new Integer(Types.VARCHAR) }
71          };
72      public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(300) null)";
73      public static final String TABLE_SQL_DROP = "drop table Resource_";
74      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
75                  "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
76              true);
77  
78      public static Resource toModel(ResourceSoap soapModel) {
79          Resource model = new ResourceImpl();
80  
81          model.setResourceId(soapModel.getResourceId());
82          model.setCodeId(soapModel.getCodeId());
83          model.setPrimKey(soapModel.getPrimKey());
84  
85          return model;
86      }
87  
88      public static List<Resource> toModels(ResourceSoap[] soapModels) {
89          List<Resource> models = new ArrayList<Resource>(soapModels.length);
90  
91          for (ResourceSoap soapModel : soapModels) {
92              models.add(toModel(soapModel));
93          }
94  
95          return models;
96      }
97  
98      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
99                  "lock.expiration.time.com.liferay.portal.model.Resource"));
100 
101     public ResourceModelImpl() {
102     }
103 
104     public long getPrimaryKey() {
105         return _resourceId;
106     }
107 
108     public void setPrimaryKey(long pk) {
109         setResourceId(pk);
110     }
111 
112     public Serializable getPrimaryKeyObj() {
113         return new Long(_resourceId);
114     }
115 
116     public long getResourceId() {
117         return _resourceId;
118     }
119 
120     public void setResourceId(long resourceId) {
121         if (resourceId != _resourceId) {
122             _resourceId = resourceId;
123         }
124     }
125 
126     public long getCodeId() {
127         return _codeId;
128     }
129 
130     public void setCodeId(long codeId) {
131         if (codeId != _codeId) {
132             _codeId = codeId;
133         }
134     }
135 
136     public String getPrimKey() {
137         return GetterUtil.getString(_primKey);
138     }
139 
140     public void setPrimKey(String primKey) {
141         if (((primKey == null) && (_primKey != null)) ||
142                 ((primKey != null) && (_primKey == null)) ||
143                 ((primKey != null) && (_primKey != null) &&
144                 !primKey.equals(_primKey))) {
145             _primKey = primKey;
146         }
147     }
148 
149     public Resource toEscapedModel() {
150         if (isEscapedModel()) {
151             return (Resource)this;
152         }
153         else {
154             Resource model = new ResourceImpl();
155 
156             model.setEscapedModel(true);
157 
158             model.setResourceId(getResourceId());
159             model.setCodeId(getCodeId());
160             model.setPrimKey(HtmlUtil.escape(getPrimKey()));
161 
162             model = (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
163                     new Class[] { Resource.class },
164                     new ReadOnlyBeanHandler(model));
165 
166             return model;
167         }
168     }
169 
170     public Object clone() {
171         ResourceImpl clone = new ResourceImpl();
172 
173         clone.setResourceId(getResourceId());
174         clone.setCodeId(getCodeId());
175         clone.setPrimKey(getPrimKey());
176 
177         return clone;
178     }
179 
180     public int compareTo(Object obj) {
181         if (obj == null) {
182             return -1;
183         }
184 
185         ResourceImpl resource = (ResourceImpl)obj;
186 
187         long pk = resource.getPrimaryKey();
188 
189         if (getPrimaryKey() < pk) {
190             return -1;
191         }
192         else if (getPrimaryKey() > pk) {
193             return 1;
194         }
195         else {
196             return 0;
197         }
198     }
199 
200     public boolean equals(Object obj) {
201         if (obj == null) {
202             return false;
203         }
204 
205         ResourceImpl resource = null;
206 
207         try {
208             resource = (ResourceImpl)obj;
209         }
210         catch (ClassCastException cce) {
211             return false;
212         }
213 
214         long pk = resource.getPrimaryKey();
215 
216         if (getPrimaryKey() == pk) {
217             return true;
218         }
219         else {
220             return false;
221         }
222     }
223 
224     public int hashCode() {
225         return (int)getPrimaryKey();
226     }
227 
228     private long _resourceId;
229     private long _codeId;
230     private String _primKey;
231 }