1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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 interface is a model that represents the Resource_ table in the
50   * database.
51   * </p>
52   *
53   * @author    Brian Wing Shun Chan
54   * @see       ResourceImpl
55   * @see       com.liferay.portal.model.Resource
56   * @see       com.liferay.portal.model.ResourceModel
57   * @generated
58   */
59  public class ResourceModelImpl extends BaseModelImpl<Resource> {
60      public static final String TABLE_NAME = "Resource_";
61      public static final Object[][] TABLE_COLUMNS = {
62              { "resourceId", new Integer(Types.BIGINT) },
63              { "codeId", new Integer(Types.BIGINT) },
64              { "primKey", new Integer(Types.VARCHAR) }
65          };
66      public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(255) null)";
67      public static final String TABLE_SQL_DROP = "drop table Resource_";
68      public static final String DATA_SOURCE = "liferayDataSource";
69      public static final String SESSION_FACTORY = "liferaySessionFactory";
70      public static final String TX_MANAGER = "liferayTransactionManager";
71      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
72                  "value.object.entity.cache.enabled.com.liferay.portal.model.Resource"),
73              true);
74      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
75                  "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
76              true);
77  
78      public static Resource toModel(ResourceSoap soapModel) {
79          Resource model = new ResourceImpl();
80  
81          model.setResourceId(soapModel.getResourceId());
82          model.setCodeId(soapModel.getCodeId());
83          model.setPrimKey(soapModel.getPrimKey());
84  
85          return model;
86      }
87  
88      public static List<Resource> toModels(ResourceSoap[] soapModels) {
89          List<Resource> models = new ArrayList<Resource>(soapModels.length);
90  
91          for (ResourceSoap soapModel : soapModels) {
92              models.add(toModel(soapModel));
93          }
94  
95          return models;
96      }
97  
98      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
99                  "lock.expiration.time.com.liferay.portal.model.Resource"));
100 
101     public ResourceModelImpl() {
102     }
103 
104     public long getPrimaryKey() {
105         return _resourceId;
106     }
107 
108     public void setPrimaryKey(long pk) {
109         setResourceId(pk);
110     }
111 
112     public Serializable getPrimaryKeyObj() {
113         return new Long(_resourceId);
114     }
115 
116     public long getResourceId() {
117         return _resourceId;
118     }
119 
120     public void setResourceId(long resourceId) {
121         _resourceId = resourceId;
122     }
123 
124     public long getCodeId() {
125         return _codeId;
126     }
127 
128     public void setCodeId(long codeId) {
129         _codeId = codeId;
130 
131         if (!_setOriginalCodeId) {
132             _setOriginalCodeId = true;
133 
134             _originalCodeId = codeId;
135         }
136     }
137 
138     public long getOriginalCodeId() {
139         return _originalCodeId;
140     }
141 
142     public String getPrimKey() {
143         return GetterUtil.getString(_primKey);
144     }
145 
146     public void setPrimKey(String primKey) {
147         _primKey = primKey;
148 
149         if (_originalPrimKey == null) {
150             _originalPrimKey = primKey;
151         }
152     }
153 
154     public String getOriginalPrimKey() {
155         return GetterUtil.getString(_originalPrimKey);
156     }
157 
158     public Resource toEscapedModel() {
159         if (isEscapedModel()) {
160             return (Resource)this;
161         }
162         else {
163             Resource model = new ResourceImpl();
164 
165             model.setNew(isNew());
166             model.setEscapedModel(true);
167 
168             model.setResourceId(getResourceId());
169             model.setCodeId(getCodeId());
170             model.setPrimKey(HtmlUtil.escape(getPrimKey()));
171 
172             model = (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
173                     new Class[] { Resource.class },
174                     new ReadOnlyBeanHandler(model));
175 
176             return model;
177         }
178     }
179 
180     public Object clone() {
181         ResourceImpl clone = new ResourceImpl();
182 
183         clone.setResourceId(getResourceId());
184         clone.setCodeId(getCodeId());
185         clone.setPrimKey(getPrimKey());
186 
187         return clone;
188     }
189 
190     public int compareTo(Resource resource) {
191         long pk = resource.getPrimaryKey();
192 
193         if (getPrimaryKey() < pk) {
194             return -1;
195         }
196         else if (getPrimaryKey() > pk) {
197             return 1;
198         }
199         else {
200             return 0;
201         }
202     }
203 
204     public boolean equals(Object obj) {
205         if (obj == null) {
206             return false;
207         }
208 
209         Resource resource = null;
210 
211         try {
212             resource = (Resource)obj;
213         }
214         catch (ClassCastException cce) {
215             return false;
216         }
217 
218         long pk = resource.getPrimaryKey();
219 
220         if (getPrimaryKey() == pk) {
221             return true;
222         }
223         else {
224             return false;
225         }
226     }
227 
228     public int hashCode() {
229         return (int)getPrimaryKey();
230     }
231 
232     public String toString() {
233         StringBuilder sb = new StringBuilder();
234 
235         sb.append("{resourceId=");
236         sb.append(getResourceId());
237         sb.append(", codeId=");
238         sb.append(getCodeId());
239         sb.append(", primKey=");
240         sb.append(getPrimKey());
241         sb.append("}");
242 
243         return sb.toString();
244     }
245 
246     public String toXmlString() {
247         StringBuilder sb = new StringBuilder();
248 
249         sb.append("<model><model-name>");
250         sb.append("com.liferay.portal.model.Resource");
251         sb.append("</model-name>");
252 
253         sb.append(
254             "<column><column-name>resourceId</column-name><column-value><![CDATA[");
255         sb.append(getResourceId());
256         sb.append("]]></column-value></column>");
257         sb.append(
258             "<column><column-name>codeId</column-name><column-value><![CDATA[");
259         sb.append(getCodeId());
260         sb.append("]]></column-value></column>");
261         sb.append(
262             "<column><column-name>primKey</column-name><column-value><![CDATA[");
263         sb.append(getPrimKey());
264         sb.append("]]></column-value></column>");
265 
266         sb.append("</model>");
267 
268         return sb.toString();
269     }
270 
271     private long _resourceId;
272     private long _codeId;
273     private long _originalCodeId;
274     private boolean _setOriginalCodeId;
275     private String _primKey;
276     private String _originalPrimKey;
277 }