1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.StringBundler;
20  import com.liferay.portal.kernel.util.StringPool;
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         if (_primKey == null) {
141             return StringPool.BLANK;
142         }
143         else {
144             return _primKey;
145         }
146     }
147 
148     public void setPrimKey(String primKey) {
149         _primKey = primKey;
150 
151         if (_originalPrimKey == null) {
152             _originalPrimKey = primKey;
153         }
154     }
155 
156     public String getOriginalPrimKey() {
157         return GetterUtil.getString(_originalPrimKey);
158     }
159 
160     public Resource toEscapedModel() {
161         if (isEscapedModel()) {
162             return (Resource)this;
163         }
164         else {
165             return (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
166                 new Class[] { Resource.class }, new AutoEscapeBeanHandler(this));
167         }
168     }
169 
170     public ExpandoBridge getExpandoBridge() {
171         if (_expandoBridge == null) {
172             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(Resource.class.getName(),
173                     getPrimaryKey());
174         }
175 
176         return _expandoBridge;
177     }
178 
179     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
180         getExpandoBridge().setAttributes(serviceContext);
181     }
182 
183     public Object clone() {
184         ResourceImpl clone = new ResourceImpl();
185 
186         clone.setResourceId(getResourceId());
187         clone.setCodeId(getCodeId());
188         clone.setPrimKey(getPrimKey());
189 
190         return clone;
191     }
192 
193     public int compareTo(Resource resource) {
194         long pk = resource.getPrimaryKey();
195 
196         if (getPrimaryKey() < pk) {
197             return -1;
198         }
199         else if (getPrimaryKey() > pk) {
200             return 1;
201         }
202         else {
203             return 0;
204         }
205     }
206 
207     public boolean equals(Object obj) {
208         if (obj == null) {
209             return false;
210         }
211 
212         Resource resource = null;
213 
214         try {
215             resource = (Resource)obj;
216         }
217         catch (ClassCastException cce) {
218             return false;
219         }
220 
221         long pk = resource.getPrimaryKey();
222 
223         if (getPrimaryKey() == pk) {
224             return true;
225         }
226         else {
227             return false;
228         }
229     }
230 
231     public int hashCode() {
232         return (int)getPrimaryKey();
233     }
234 
235     public String toString() {
236         StringBundler sb = new StringBundler(7);
237 
238         sb.append("{resourceId=");
239         sb.append(getResourceId());
240         sb.append(", codeId=");
241         sb.append(getCodeId());
242         sb.append(", primKey=");
243         sb.append(getPrimKey());
244         sb.append("}");
245 
246         return sb.toString();
247     }
248 
249     public String toXmlString() {
250         StringBundler sb = new StringBundler(13);
251 
252         sb.append("<model><model-name>");
253         sb.append("com.liferay.portal.model.Resource");
254         sb.append("</model-name>");
255 
256         sb.append(
257             "<column><column-name>resourceId</column-name><column-value><![CDATA[");
258         sb.append(getResourceId());
259         sb.append("]]></column-value></column>");
260         sb.append(
261             "<column><column-name>codeId</column-name><column-value><![CDATA[");
262         sb.append(getCodeId());
263         sb.append("]]></column-value></column>");
264         sb.append(
265             "<column><column-name>primKey</column-name><column-value><![CDATA[");
266         sb.append(getPrimKey());
267         sb.append("]]></column-value></column>");
268 
269         sb.append("</model>");
270 
271         return sb.toString();
272     }
273 
274     private long _resourceId;
275     private long _codeId;
276     private long _originalCodeId;
277     private boolean _setOriginalCodeId;
278     private String _primKey;
279     private String _originalPrimKey;
280     private transient ExpandoBridge _expandoBridge;
281 }