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  import com.liferay.portal.service.ServiceContext;
31  
32  import com.liferay.portlet.expando.model.ExpandoBridge;
33  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
34  
35  import java.io.Serializable;
36  
37  import java.lang.reflect.Proxy;
38  
39  import java.sql.Types;
40  
41  import java.util.ArrayList;
42  import java.util.List;
43  
44  /**
45   * <a href="ResourceModelImpl.java.html"><b><i>View Source</i></b></a>
46   *
47   * <p>
48   * ServiceBuilder generated this class. Modifications in this class will be
49   * overwritten the next time is generated.
50   * </p>
51   *
52   * <p>
53   * This interface is a model that represents the Resource_ table in the
54   * database.
55   * </p>
56   *
57   * @author    Brian Wing Shun Chan
58   * @see       ResourceImpl
59   * @see       com.liferay.portal.model.Resource
60   * @see       com.liferay.portal.model.ResourceModel
61   * @generated
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              { "codeId", new Integer(Types.BIGINT) },
68              { "primKey", new Integer(Types.VARCHAR) }
69          };
70      public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(255) null)";
71      public static final String TABLE_SQL_DROP = "drop table Resource_";
72      public static final String DATA_SOURCE = "liferayDataSource";
73      public static final String SESSION_FACTORY = "liferaySessionFactory";
74      public static final String TX_MANAGER = "liferayTransactionManager";
75      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
76                  "value.object.entity.cache.enabled.com.liferay.portal.model.Resource"),
77              true);
78      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
79                  "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
80              true);
81  
82      public static Resource toModel(ResourceSoap soapModel) {
83          Resource model = new ResourceImpl();
84  
85          model.setResourceId(soapModel.getResourceId());
86          model.setCodeId(soapModel.getCodeId());
87          model.setPrimKey(soapModel.getPrimKey());
88  
89          return model;
90      }
91  
92      public static List<Resource> toModels(ResourceSoap[] soapModels) {
93          List<Resource> models = new ArrayList<Resource>(soapModels.length);
94  
95          for (ResourceSoap soapModel : soapModels) {
96              models.add(toModel(soapModel));
97          }
98  
99          return models;
100     }
101 
102     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
103                 "lock.expiration.time.com.liferay.portal.model.Resource"));
104 
105     public ResourceModelImpl() {
106     }
107 
108     public long getPrimaryKey() {
109         return _resourceId;
110     }
111 
112     public void setPrimaryKey(long pk) {
113         setResourceId(pk);
114     }
115 
116     public Serializable getPrimaryKeyObj() {
117         return new Long(_resourceId);
118     }
119 
120     public long getResourceId() {
121         return _resourceId;
122     }
123 
124     public void setResourceId(long resourceId) {
125         _resourceId = resourceId;
126     }
127 
128     public long getCodeId() {
129         return _codeId;
130     }
131 
132     public void setCodeId(long codeId) {
133         _codeId = codeId;
134 
135         if (!_setOriginalCodeId) {
136             _setOriginalCodeId = true;
137 
138             _originalCodeId = codeId;
139         }
140     }
141 
142     public long getOriginalCodeId() {
143         return _originalCodeId;
144     }
145 
146     public String getPrimKey() {
147         return GetterUtil.getString(_primKey);
148     }
149 
150     public void setPrimKey(String primKey) {
151         _primKey = primKey;
152 
153         if (_originalPrimKey == null) {
154             _originalPrimKey = primKey;
155         }
156     }
157 
158     public String getOriginalPrimKey() {
159         return GetterUtil.getString(_originalPrimKey);
160     }
161 
162     public Resource toEscapedModel() {
163         if (isEscapedModel()) {
164             return (Resource)this;
165         }
166         else {
167             Resource model = new ResourceImpl();
168 
169             model.setNew(isNew());
170             model.setEscapedModel(true);
171 
172             model.setResourceId(getResourceId());
173             model.setCodeId(getCodeId());
174             model.setPrimKey(HtmlUtil.escape(getPrimKey()));
175 
176             model = (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
177                     new Class[] { Resource.class },
178                     new ReadOnlyBeanHandler(model));
179 
180             return model;
181         }
182     }
183 
184     public ExpandoBridge getExpandoBridge() {
185         if (_expandoBridge == null) {
186             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(Resource.class.getName(),
187                     getPrimaryKey());
188         }
189 
190         return _expandoBridge;
191     }
192 
193     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
194         getExpandoBridge().setAttributes(serviceContext);
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 }