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.kernel.util.StringBundler;
29  import com.liferay.portal.model.Resource;
30  import com.liferay.portal.model.ResourceSoap;
31  import com.liferay.portal.service.ServiceContext;
32  
33  import com.liferay.portlet.expando.model.ExpandoBridge;
34  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
35  
36  import java.io.Serializable;
37  
38  import java.lang.reflect.Proxy;
39  
40  import java.sql.Types;
41  
42  import java.util.ArrayList;
43  import java.util.List;
44  
45  /**
46   * <a href="ResourceModelImpl.java.html"><b><i>View Source</i></b></a>
47   *
48   * <p>
49   * ServiceBuilder generated this class. Modifications in this class will be
50   * overwritten the next time is generated.
51   * </p>
52   *
53   * <p>
54   * This interface is a model that represents the Resource_ table in the
55   * database.
56   * </p>
57   *
58   * @author    Brian Wing Shun Chan
59   * @see       ResourceImpl
60   * @see       com.liferay.portal.model.Resource
61   * @see       com.liferay.portal.model.ResourceModel
62   * @generated
63   */
64  public class ResourceModelImpl extends BaseModelImpl<Resource> {
65      public static final String TABLE_NAME = "Resource_";
66      public static final Object[][] TABLE_COLUMNS = {
67              { "resourceId", new Integer(Types.BIGINT) },
68              { "codeId", new Integer(Types.BIGINT) },
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 ExpandoBridge getExpandoBridge() {
186         if (_expandoBridge == null) {
187             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(Resource.class.getName(),
188                     getPrimaryKey());
189         }
190 
191         return _expandoBridge;
192     }
193 
194     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
195         getExpandoBridge().setAttributes(serviceContext);
196     }
197 
198     public Object clone() {
199         ResourceImpl clone = new ResourceImpl();
200 
201         clone.setResourceId(getResourceId());
202         clone.setCodeId(getCodeId());
203         clone.setPrimKey(getPrimKey());
204 
205         return clone;
206     }
207 
208     public int compareTo(Resource resource) {
209         long pk = resource.getPrimaryKey();
210 
211         if (getPrimaryKey() < pk) {
212             return -1;
213         }
214         else if (getPrimaryKey() > pk) {
215             return 1;
216         }
217         else {
218             return 0;
219         }
220     }
221 
222     public boolean equals(Object obj) {
223         if (obj == null) {
224             return false;
225         }
226 
227         Resource resource = null;
228 
229         try {
230             resource = (Resource)obj;
231         }
232         catch (ClassCastException cce) {
233             return false;
234         }
235 
236         long pk = resource.getPrimaryKey();
237 
238         if (getPrimaryKey() == pk) {
239             return true;
240         }
241         else {
242             return false;
243         }
244     }
245 
246     public int hashCode() {
247         return (int)getPrimaryKey();
248     }
249 
250     public String toString() {
251         StringBundler sb = new StringBundler(7);
252 
253         sb.append("{resourceId=");
254         sb.append(getResourceId());
255         sb.append(", codeId=");
256         sb.append(getCodeId());
257         sb.append(", primKey=");
258         sb.append(getPrimKey());
259         sb.append("}");
260 
261         return sb.toString();
262     }
263 
264     public String toXmlString() {
265         StringBundler sb = new StringBundler(13);
266 
267         sb.append("<model><model-name>");
268         sb.append("com.liferay.portal.model.Resource");
269         sb.append("</model-name>");
270 
271         sb.append(
272             "<column><column-name>resourceId</column-name><column-value><![CDATA[");
273         sb.append(getResourceId());
274         sb.append("]]></column-value></column>");
275         sb.append(
276             "<column><column-name>codeId</column-name><column-value><![CDATA[");
277         sb.append(getCodeId());
278         sb.append("]]></column-value></column>");
279         sb.append(
280             "<column><column-name>primKey</column-name><column-value><![CDATA[");
281         sb.append(getPrimKey());
282         sb.append("]]></column-value></column>");
283 
284         sb.append("</model>");
285 
286         return sb.toString();
287     }
288 
289     private long _resourceId;
290     private long _codeId;
291     private long _originalCodeId;
292     private boolean _setOriginalCodeId;
293     private String _primKey;
294     private String _originalPrimKey;
295     private transient ExpandoBridge _expandoBridge;
296 }