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