1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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 com.liferay.portlet.expando.model.ExpandoBridge;
32  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
33  
34  import java.io.Serializable;
35  
36  import java.lang.reflect.Proxy;
37  
38  import java.sql.Types;
39  
40  import java.util.ArrayList;
41  import java.util.List;
42  
43  /**
44   * <a href="ResourceModelImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * <p>
47   * ServiceBuilder generated this class. Modifications in this class will be
48   * overwritten the next time is generated.
49   * </p>
50   *
51   * <p>
52   * This class is a model that represents the <code>Resource</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portal.model.Resource
59   * @see com.liferay.portal.model.ResourceModel
60   * @see com.liferay.portal.model.impl.ResourceImpl
61   *
62   */
63  public class ResourceModelImpl extends BaseModelImpl {
64      public static final String TABLE_NAME = "Resource_";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "resourceId", new Integer(Types.BIGINT) },
67              
68  
69              { "codeId", new Integer(Types.BIGINT) },
70              
71  
72              { "primKey", new Integer(Types.VARCHAR) }
73          };
74      public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(300) null)";
75      public static final String TABLE_SQL_DROP = "drop table Resource_";
76      public static final String DATA_SOURCE = "liferayDataSource";
77      public static final String SESSION_FACTORY = "liferaySessionFactory";
78      public static final String TX_MANAGER = "liferayTransactionManager";
79      public static final boolean 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         if (resourceId != _resourceId) {
127             _resourceId = resourceId;
128         }
129     }
130 
131     public long getCodeId() {
132         return _codeId;
133     }
134 
135     public void setCodeId(long codeId) {
136         if (codeId != _codeId) {
137             _codeId = codeId;
138         }
139     }
140 
141     public String getPrimKey() {
142         return GetterUtil.getString(_primKey);
143     }
144 
145     public void setPrimKey(String primKey) {
146         if (((primKey == null) && (_primKey != null)) ||
147                 ((primKey != null) && (_primKey == null)) ||
148                 ((primKey != null) && (_primKey != null) &&
149                 !primKey.equals(_primKey))) {
150             _primKey = primKey;
151         }
152     }
153 
154     public Resource toEscapedModel() {
155         if (isEscapedModel()) {
156             return (Resource)this;
157         }
158         else {
159             Resource model = new ResourceImpl();
160 
161             model.setNew(isNew());
162             model.setEscapedModel(true);
163 
164             model.setResourceId(getResourceId());
165             model.setCodeId(getCodeId());
166             model.setPrimKey(HtmlUtil.escape(getPrimKey()));
167 
168             model = (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
169                     new Class[] { Resource.class },
170                     new ReadOnlyBeanHandler(model));
171 
172             return model;
173         }
174     }
175 
176     public ExpandoBridge getExpandoBridge() {
177         if (_expandoBridge == null) {
178             _expandoBridge = new ExpandoBridgeImpl(Resource.class.getName(),
179                     getPrimaryKey());
180         }
181 
182         return _expandoBridge;
183     }
184 
185     public Object clone() {
186         ResourceImpl clone = new ResourceImpl();
187 
188         clone.setResourceId(getResourceId());
189         clone.setCodeId(getCodeId());
190         clone.setPrimKey(getPrimKey());
191 
192         return clone;
193     }
194 
195     public int compareTo(Object obj) {
196         if (obj == null) {
197             return -1;
198         }
199 
200         ResourceImpl resource = (ResourceImpl)obj;
201 
202         long pk = resource.getPrimaryKey();
203 
204         if (getPrimaryKey() < pk) {
205             return -1;
206         }
207         else if (getPrimaryKey() > pk) {
208             return 1;
209         }
210         else {
211             return 0;
212         }
213     }
214 
215     public boolean equals(Object obj) {
216         if (obj == null) {
217             return false;
218         }
219 
220         ResourceImpl resource = null;
221 
222         try {
223             resource = (ResourceImpl)obj;
224         }
225         catch (ClassCastException cce) {
226             return false;
227         }
228 
229         long pk = resource.getPrimaryKey();
230 
231         if (getPrimaryKey() == pk) {
232             return true;
233         }
234         else {
235             return false;
236         }
237     }
238 
239     public int hashCode() {
240         return (int)getPrimaryKey();
241     }
242 
243     private long _resourceId;
244     private long _codeId;
245     private String _primKey;
246     private transient ExpandoBridge _expandoBridge;
247 }