1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.model.impl;
21  
22  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
23  import com.liferay.portal.kernel.util.GetterUtil;
24  import com.liferay.portal.kernel.util.HtmlUtil;
25  import com.liferay.portal.model.Resource;
26  import com.liferay.portal.model.ResourceSoap;
27  
28  import java.io.Serializable;
29  
30  import java.lang.reflect.Proxy;
31  
32  import java.sql.Types;
33  
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * <a href="ResourceModelImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * <p>
41   * ServiceBuilder generated this class. Modifications in this class will be
42   * overwritten the next time is generated.
43   * </p>
44   *
45   * <p>
46   * This class is a model that represents the <code>Resource</code> table
47   * in the database.
48   * </p>
49   *
50   * @author Brian Wing Shun Chan
51   *
52   * @see com.liferay.portal.model.Resource
53   * @see com.liferay.portal.model.ResourceModel
54   * @see com.liferay.portal.model.impl.ResourceImpl
55   *
56   */
57  public class ResourceModelImpl extends BaseModelImpl {
58      public static final String TABLE_NAME = "Resource_";
59      public static final Object[][] TABLE_COLUMNS = {
60              { "resourceId", new Integer(Types.BIGINT) },
61              
62  
63              { "codeId", new Integer(Types.BIGINT) },
64              
65  
66              { "primKey", new Integer(Types.VARCHAR) }
67          };
68      public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(300) null)";
69      public static final String TABLE_SQL_DROP = "drop table Resource_";
70      public static final String DATA_SOURCE = "liferayDataSource";
71      public static final String SESSION_FACTORY = "liferaySessionFactory";
72      public static final String TX_MANAGER = "liferayTransactionManager";
73      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
74                  "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
75              true);
76  
77      public static Resource toModel(ResourceSoap soapModel) {
78          Resource model = new ResourceImpl();
79  
80          model.setResourceId(soapModel.getResourceId());
81          model.setCodeId(soapModel.getCodeId());
82          model.setPrimKey(soapModel.getPrimKey());
83  
84          return model;
85      }
86  
87      public static List<Resource> toModels(ResourceSoap[] soapModels) {
88          List<Resource> models = new ArrayList<Resource>(soapModels.length);
89  
90          for (ResourceSoap soapModel : soapModels) {
91              models.add(toModel(soapModel));
92          }
93  
94          return models;
95      }
96  
97      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
98                  "lock.expiration.time.com.liferay.portal.model.Resource"));
99  
100     public ResourceModelImpl() {
101     }
102 
103     public long getPrimaryKey() {
104         return _resourceId;
105     }
106 
107     public void setPrimaryKey(long pk) {
108         setResourceId(pk);
109     }
110 
111     public Serializable getPrimaryKeyObj() {
112         return new Long(_resourceId);
113     }
114 
115     public long getResourceId() {
116         return _resourceId;
117     }
118 
119     public void setResourceId(long resourceId) {
120         if (resourceId != _resourceId) {
121             _resourceId = resourceId;
122         }
123     }
124 
125     public long getCodeId() {
126         return _codeId;
127     }
128 
129     public void setCodeId(long codeId) {
130         if (codeId != _codeId) {
131             _codeId = codeId;
132         }
133     }
134 
135     public String getPrimKey() {
136         return GetterUtil.getString(_primKey);
137     }
138 
139     public void setPrimKey(String primKey) {
140         if (((primKey == null) && (_primKey != null)) ||
141                 ((primKey != null) && (_primKey == null)) ||
142                 ((primKey != null) && (_primKey != null) &&
143                 !primKey.equals(_primKey))) {
144             _primKey = primKey;
145         }
146     }
147 
148     public Resource toEscapedModel() {
149         if (isEscapedModel()) {
150             return (Resource)this;
151         }
152         else {
153             Resource model = new ResourceImpl();
154 
155             model.setNew(isNew());
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 }