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.model.Resource;
28  import com.liferay.portal.util.PropsUtil;
29  
30  import com.liferay.util.Html;
31  
32  import java.io.Serializable;
33  
34  import java.lang.reflect.Proxy;
35  
36  import java.sql.Types;
37  
38  /**
39   * <a href="ResourceModelImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * <p>
42   * ServiceBuilder generated this class. Modifications in this class will be
43   * overwritten the next time is generated.
44   * </p>
45   *
46   * <p>
47   * This class is a model that represents the <code>Resource</code> table
48   * in the database.
49   * </p>
50   *
51   * @author Brian Wing Shun Chan
52   *
53   * @see com.liferay.portal.service.model.Resource
54   * @see com.liferay.portal.service.model.ResourceModel
55   * @see com.liferay.portal.service.model.impl.ResourceImpl
56   *
57   */
58  public class ResourceModelImpl extends BaseModelImpl {
59      public static final String TABLE_NAME = "Resource_";
60      public static final Object[][] TABLE_COLUMNS = {
61              { "resourceId", new Integer(Types.BIGINT) },
62              
63  
64              { "codeId", new Integer(Types.BIGINT) },
65              
66  
67              { "primKey", new Integer(Types.VARCHAR) }
68          };
69      public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(300) null)";
70      public static final String TABLE_SQL_DROP = "drop table Resource_";
71      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
72                  "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
73              true);
74      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
75                  "lock.expiration.time.com.liferay.portal.model.Resource"));
76  
77      public ResourceModelImpl() {
78      }
79  
80      public long getPrimaryKey() {
81          return _resourceId;
82      }
83  
84      public void setPrimaryKey(long pk) {
85          setResourceId(pk);
86      }
87  
88      public Serializable getPrimaryKeyObj() {
89          return new Long(_resourceId);
90      }
91  
92      public long getResourceId() {
93          return _resourceId;
94      }
95  
96      public void setResourceId(long resourceId) {
97          if (resourceId != _resourceId) {
98              _resourceId = resourceId;
99          }
100     }
101 
102     public long getCodeId() {
103         return _codeId;
104     }
105 
106     public void setCodeId(long codeId) {
107         if (codeId != _codeId) {
108             _codeId = codeId;
109         }
110     }
111 
112     public String getPrimKey() {
113         return GetterUtil.getString(_primKey);
114     }
115 
116     public void setPrimKey(String primKey) {
117         if (((primKey == null) && (_primKey != null)) ||
118                 ((primKey != null) && (_primKey == null)) ||
119                 ((primKey != null) && (_primKey != null) &&
120                 !primKey.equals(_primKey))) {
121             _primKey = primKey;
122         }
123     }
124 
125     public Resource toEscapedModel() {
126         if (isEscapedModel()) {
127             return (Resource)this;
128         }
129         else {
130             Resource model = new ResourceImpl();
131 
132             model.setEscapedModel(true);
133 
134             model.setResourceId(getResourceId());
135             model.setCodeId(getCodeId());
136             model.setPrimKey(Html.escape(getPrimKey()));
137 
138             model = (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
139                     new Class[] { Resource.class },
140                     new ReadOnlyBeanHandler(model));
141 
142             return model;
143         }
144     }
145 
146     public Object clone() {
147         ResourceImpl clone = new ResourceImpl();
148 
149         clone.setResourceId(getResourceId());
150         clone.setCodeId(getCodeId());
151         clone.setPrimKey(getPrimKey());
152 
153         return clone;
154     }
155 
156     public int compareTo(Object obj) {
157         if (obj == null) {
158             return -1;
159         }
160 
161         ResourceImpl resource = (ResourceImpl)obj;
162 
163         long pk = resource.getPrimaryKey();
164 
165         if (getPrimaryKey() < pk) {
166             return -1;
167         }
168         else if (getPrimaryKey() > pk) {
169             return 1;
170         }
171         else {
172             return 0;
173         }
174     }
175 
176     public boolean equals(Object obj) {
177         if (obj == null) {
178             return false;
179         }
180 
181         ResourceImpl resource = null;
182 
183         try {
184             resource = (ResourceImpl)obj;
185         }
186         catch (ClassCastException cce) {
187             return false;
188         }
189 
190         long pk = resource.getPrimaryKey();
191 
192         if (getPrimaryKey() == pk) {
193             return true;
194         }
195         else {
196             return false;
197         }
198     }
199 
200     public int hashCode() {
201         return (int)getPrimaryKey();
202     }
203 
204     private long _resourceId;
205     private long _codeId;
206     private String _primKey;
207 }