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