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