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 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.model.Resource
56   * @see com.liferay.portal.model.ResourceModel
57   * @see com.liferay.portal.model.impl.ResourceImpl
58   *
59   */
60  public class ResourceModelImpl extends BaseModelImpl<Resource> {
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(255) 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 ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
77                  "value.object.entity.cache.enabled.com.liferay.portal.model.Resource"),
78              true);
79      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
80                  "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
81              true);
82  
83      public static Resource toModel(ResourceSoap soapModel) {
84          Resource model = new ResourceImpl();
85  
86          model.setResourceId(soapModel.getResourceId());
87          model.setCodeId(soapModel.getCodeId());
88          model.setPrimKey(soapModel.getPrimKey());
89  
90          return model;
91      }
92  
93      public static List<Resource> toModels(ResourceSoap[] soapModels) {
94          List<Resource> models = new ArrayList<Resource>(soapModels.length);
95  
96          for (ResourceSoap soapModel : soapModels) {
97              models.add(toModel(soapModel));
98          }
99  
100         return models;
101     }
102 
103     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
104                 "lock.expiration.time.com.liferay.portal.model.Resource"));
105 
106     public ResourceModelImpl() {
107     }
108 
109     public long getPrimaryKey() {
110         return _resourceId;
111     }
112 
113     public void setPrimaryKey(long pk) {
114         setResourceId(pk);
115     }
116 
117     public Serializable getPrimaryKeyObj() {
118         return new Long(_resourceId);
119     }
120 
121     public long getResourceId() {
122         return _resourceId;
123     }
124 
125     public void setResourceId(long resourceId) {
126         _resourceId = resourceId;
127     }
128 
129     public long getCodeId() {
130         return _codeId;
131     }
132 
133     public void setCodeId(long codeId) {
134         _codeId = codeId;
135 
136         if (!_setOriginalCodeId) {
137             _setOriginalCodeId = true;
138 
139             _originalCodeId = codeId;
140         }
141     }
142 
143     public long getOriginalCodeId() {
144         return _originalCodeId;
145     }
146 
147     public String getPrimKey() {
148         return GetterUtil.getString(_primKey);
149     }
150 
151     public void setPrimKey(String primKey) {
152         _primKey = primKey;
153 
154         if (_originalPrimKey == null) {
155             _originalPrimKey = primKey;
156         }
157     }
158 
159     public String getOriginalPrimKey() {
160         return GetterUtil.getString(_originalPrimKey);
161     }
162 
163     public Resource toEscapedModel() {
164         if (isEscapedModel()) {
165             return (Resource)this;
166         }
167         else {
168             Resource model = new ResourceImpl();
169 
170             model.setNew(isNew());
171             model.setEscapedModel(true);
172 
173             model.setResourceId(getResourceId());
174             model.setCodeId(getCodeId());
175             model.setPrimKey(HtmlUtil.escape(getPrimKey()));
176 
177             model = (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
178                     new Class[] { Resource.class },
179                     new ReadOnlyBeanHandler(model));
180 
181             return model;
182         }
183     }
184 
185     public Object clone() {
186         ResourceImpl clone = new ResourceImpl();
187 
188         clone.setResourceId(getResourceId());
189         clone.setCodeId(getCodeId());
190         clone.setPrimKey(getPrimKey());
191 
192         return clone;
193     }
194 
195     public int compareTo(Resource resource) {
196         long pk = resource.getPrimaryKey();
197 
198         if (getPrimaryKey() < pk) {
199             return -1;
200         }
201         else if (getPrimaryKey() > pk) {
202             return 1;
203         }
204         else {
205             return 0;
206         }
207     }
208 
209     public boolean equals(Object obj) {
210         if (obj == null) {
211             return false;
212         }
213 
214         Resource resource = null;
215 
216         try {
217             resource = (Resource)obj;
218         }
219         catch (ClassCastException cce) {
220             return false;
221         }
222 
223         long pk = resource.getPrimaryKey();
224 
225         if (getPrimaryKey() == pk) {
226             return true;
227         }
228         else {
229             return false;
230         }
231     }
232 
233     public int hashCode() {
234         return (int)getPrimaryKey();
235     }
236 
237     public String toString() {
238         StringBuilder sb = new StringBuilder();
239 
240         sb.append("{resourceId=");
241         sb.append(getResourceId());
242         sb.append(", codeId=");
243         sb.append(getCodeId());
244         sb.append(", primKey=");
245         sb.append(getPrimKey());
246         sb.append("}");
247 
248         return sb.toString();
249     }
250 
251     public String toXmlString() {
252         StringBuilder sb = new StringBuilder();
253 
254         sb.append("<model><model-name>");
255         sb.append("com.liferay.portal.model.Resource");
256         sb.append("</model-name>");
257 
258         sb.append(
259             "<column><column-name>resourceId</column-name><column-value><![CDATA[");
260         sb.append(getResourceId());
261         sb.append("]]></column-value></column>");
262         sb.append(
263             "<column><column-name>codeId</column-name><column-value><![CDATA[");
264         sb.append(getCodeId());
265         sb.append("]]></column-value></column>");
266         sb.append(
267             "<column><column-name>primKey</column-name><column-value><![CDATA[");
268         sb.append(getPrimKey());
269         sb.append("]]></column-value></column>");
270 
271         sb.append("</model>");
272 
273         return sb.toString();
274     }
275 
276     private long _resourceId;
277     private long _codeId;
278     private long _originalCodeId;
279     private boolean _setOriginalCodeId;
280     private String _primKey;
281     private String _originalPrimKey;
282 }