1   /**
2    * Copyright (c) 2000-2010 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   *
12   * 
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.HtmlUtil;
20  import com.liferay.portal.kernel.util.StringBundler;
21  import com.liferay.portal.model.Resource;
22  import com.liferay.portal.model.ResourceSoap;
23  
24  import java.io.Serializable;
25  
26  import java.lang.reflect.Proxy;
27  
28  import java.sql.Types;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * <a href="ResourceModelImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * <p>
37   * ServiceBuilder generated this class. Modifications in this class will be
38   * overwritten the next time is generated.
39   * </p>
40   *
41   * <p>
42   * This interface is a model that represents the Resource_ table in the
43   * database.
44   * </p>
45   *
46   * @author    Brian Wing Shun Chan
47   * @see       ResourceImpl
48   * @see       com.liferay.portal.model.Resource
49   * @see       com.liferay.portal.model.ResourceModel
50   * @generated
51   */
52  public class ResourceModelImpl extends BaseModelImpl<Resource> {
53      public static final String TABLE_NAME = "Resource_";
54      public static final Object[][] TABLE_COLUMNS = {
55              { "resourceId", new Integer(Types.BIGINT) },
56              { "codeId", new Integer(Types.BIGINT) },
57              { "primKey", new Integer(Types.VARCHAR) }
58          };
59      public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(255) null)";
60      public static final String TABLE_SQL_DROP = "drop table Resource_";
61      public static final String DATA_SOURCE = "liferayDataSource";
62      public static final String SESSION_FACTORY = "liferaySessionFactory";
63      public static final String TX_MANAGER = "liferayTransactionManager";
64      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
65                  "value.object.entity.cache.enabled.com.liferay.portal.model.Resource"),
66              true);
67      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
68                  "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
69              true);
70  
71      public static Resource toModel(ResourceSoap soapModel) {
72          Resource model = new ResourceImpl();
73  
74          model.setResourceId(soapModel.getResourceId());
75          model.setCodeId(soapModel.getCodeId());
76          model.setPrimKey(soapModel.getPrimKey());
77  
78          return model;
79      }
80  
81      public static List<Resource> toModels(ResourceSoap[] soapModels) {
82          List<Resource> models = new ArrayList<Resource>(soapModels.length);
83  
84          for (ResourceSoap soapModel : soapModels) {
85              models.add(toModel(soapModel));
86          }
87  
88          return models;
89      }
90  
91      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
92                  "lock.expiration.time.com.liferay.portal.model.Resource"));
93  
94      public ResourceModelImpl() {
95      }
96  
97      public long getPrimaryKey() {
98          return _resourceId;
99      }
100 
101     public void setPrimaryKey(long pk) {
102         setResourceId(pk);
103     }
104 
105     public Serializable getPrimaryKeyObj() {
106         return new Long(_resourceId);
107     }
108 
109     public long getResourceId() {
110         return _resourceId;
111     }
112 
113     public void setResourceId(long resourceId) {
114         _resourceId = resourceId;
115     }
116 
117     public long getCodeId() {
118         return _codeId;
119     }
120 
121     public void setCodeId(long codeId) {
122         _codeId = codeId;
123 
124         if (!_setOriginalCodeId) {
125             _setOriginalCodeId = true;
126 
127             _originalCodeId = codeId;
128         }
129     }
130 
131     public long getOriginalCodeId() {
132         return _originalCodeId;
133     }
134 
135     public String getPrimKey() {
136         return GetterUtil.getString(_primKey);
137     }
138 
139     public void setPrimKey(String primKey) {
140         _primKey = primKey;
141 
142         if (_originalPrimKey == null) {
143             _originalPrimKey = primKey;
144         }
145     }
146 
147     public String getOriginalPrimKey() {
148         return GetterUtil.getString(_originalPrimKey);
149     }
150 
151     public Resource toEscapedModel() {
152         if (isEscapedModel()) {
153             return (Resource)this;
154         }
155         else {
156             Resource model = new ResourceImpl();
157 
158             model.setNew(isNew());
159             model.setEscapedModel(true);
160 
161             model.setResourceId(getResourceId());
162             model.setCodeId(getCodeId());
163             model.setPrimKey(HtmlUtil.escape(getPrimKey()));
164 
165             model = (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
166                     new Class[] { Resource.class },
167                     new ReadOnlyBeanHandler(model));
168 
169             return model;
170         }
171     }
172 
173     public Object clone() {
174         ResourceImpl clone = new ResourceImpl();
175 
176         clone.setResourceId(getResourceId());
177         clone.setCodeId(getCodeId());
178         clone.setPrimKey(getPrimKey());
179 
180         return clone;
181     }
182 
183     public int compareTo(Resource resource) {
184         long pk = resource.getPrimaryKey();
185 
186         if (getPrimaryKey() < pk) {
187             return -1;
188         }
189         else if (getPrimaryKey() > pk) {
190             return 1;
191         }
192         else {
193             return 0;
194         }
195     }
196 
197     public boolean equals(Object obj) {
198         if (obj == null) {
199             return false;
200         }
201 
202         Resource resource = null;
203 
204         try {
205             resource = (Resource)obj;
206         }
207         catch (ClassCastException cce) {
208             return false;
209         }
210 
211         long pk = resource.getPrimaryKey();
212 
213         if (getPrimaryKey() == pk) {
214             return true;
215         }
216         else {
217             return false;
218         }
219     }
220 
221     public int hashCode() {
222         return (int)getPrimaryKey();
223     }
224 
225     public String toString() {
226         StringBundler sb = new StringBundler(7);
227 
228         sb.append("{resourceId=");
229         sb.append(getResourceId());
230         sb.append(", codeId=");
231         sb.append(getCodeId());
232         sb.append(", primKey=");
233         sb.append(getPrimKey());
234         sb.append("}");
235 
236         return sb.toString();
237     }
238 
239     public String toXmlString() {
240         StringBundler sb = new StringBundler(13);
241 
242         sb.append("<model><model-name>");
243         sb.append("com.liferay.portal.model.Resource");
244         sb.append("</model-name>");
245 
246         sb.append(
247             "<column><column-name>resourceId</column-name><column-value><![CDATA[");
248         sb.append(getResourceId());
249         sb.append("]]></column-value></column>");
250         sb.append(
251             "<column><column-name>codeId</column-name><column-value><![CDATA[");
252         sb.append(getCodeId());
253         sb.append("]]></column-value></column>");
254         sb.append(
255             "<column><column-name>primKey</column-name><column-value><![CDATA[");
256         sb.append(getPrimKey());
257         sb.append("]]></column-value></column>");
258 
259         sb.append("</model>");
260 
261         return sb.toString();
262     }
263 
264     private long _resourceId;
265     private long _codeId;
266     private long _originalCodeId;
267     private boolean _setOriginalCodeId;
268     private String _primKey;
269     private String _originalPrimKey;
270 }