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.portlet.expando.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.impl.BaseModelImpl;
29  
30  import com.liferay.portlet.expando.model.ExpandoColumn;
31  import com.liferay.portlet.expando.model.ExpandoColumnSoap;
32  
33  import java.io.Serializable;
34  
35  import java.lang.reflect.Proxy;
36  
37  import java.sql.Types;
38  
39  import java.util.ArrayList;
40  import java.util.List;
41  
42  /**
43   * <a href="ExpandoColumnModelImpl.java.html"><b><i>View Source</i></b></a>
44   *
45   * <p>
46   * ServiceBuilder generated this class. Modifications in this class will be
47   * overwritten the next time is generated.
48   * </p>
49   *
50   * <p>
51   * This class is a model that represents the <code>ExpandoColumn</code> table
52   * in the database.
53   * </p>
54   *
55   * @author Brian Wing Shun Chan
56   *
57   * @see com.liferay.portlet.expando.model.ExpandoColumn
58   * @see com.liferay.portlet.expando.model.ExpandoColumnModel
59   * @see com.liferay.portlet.expando.model.impl.ExpandoColumnImpl
60   *
61   */
62  public class ExpandoColumnModelImpl extends BaseModelImpl<ExpandoColumn> {
63      public static final String TABLE_NAME = "ExpandoColumn";
64      public static final Object[][] TABLE_COLUMNS = {
65              { "columnId", new Integer(Types.BIGINT) },
66              
67  
68              { "tableId", new Integer(Types.BIGINT) },
69              
70  
71              { "name", new Integer(Types.VARCHAR) },
72              
73  
74              { "type_", new Integer(Types.INTEGER) }
75          };
76      public static final String TABLE_SQL_CREATE = "create table ExpandoColumn (columnId LONG not null primary key,tableId LONG,name VARCHAR(75) null,type_ INTEGER)";
77      public static final String TABLE_SQL_DROP = "drop table ExpandoColumn";
78      public static final String DATA_SOURCE = "liferayDataSource";
79      public static final String SESSION_FACTORY = "liferaySessionFactory";
80      public static final String TX_MANAGER = "liferayTransactionManager";
81      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
82                  "value.object.entity.cache.enabled.com.liferay.portlet.expando.model.ExpandoColumn"),
83              true);
84      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
85                  "value.object.finder.cache.enabled.com.liferay.portlet.expando.model.ExpandoColumn"),
86              true);
87  
88      public static ExpandoColumn toModel(ExpandoColumnSoap soapModel) {
89          ExpandoColumn model = new ExpandoColumnImpl();
90  
91          model.setColumnId(soapModel.getColumnId());
92          model.setTableId(soapModel.getTableId());
93          model.setName(soapModel.getName());
94          model.setType(soapModel.getType());
95  
96          return model;
97      }
98  
99      public static List<ExpandoColumn> toModels(ExpandoColumnSoap[] soapModels) {
100         List<ExpandoColumn> models = new ArrayList<ExpandoColumn>(soapModels.length);
101 
102         for (ExpandoColumnSoap soapModel : soapModels) {
103             models.add(toModel(soapModel));
104         }
105 
106         return models;
107     }
108 
109     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
110                 "lock.expiration.time.com.liferay.portlet.expando.model.ExpandoColumn"));
111 
112     public ExpandoColumnModelImpl() {
113     }
114 
115     public long getPrimaryKey() {
116         return _columnId;
117     }
118 
119     public void setPrimaryKey(long pk) {
120         setColumnId(pk);
121     }
122 
123     public Serializable getPrimaryKeyObj() {
124         return new Long(_columnId);
125     }
126 
127     public long getColumnId() {
128         return _columnId;
129     }
130 
131     public void setColumnId(long columnId) {
132         _columnId = columnId;
133     }
134 
135     public long getTableId() {
136         return _tableId;
137     }
138 
139     public void setTableId(long tableId) {
140         _tableId = tableId;
141 
142         if (!_setOriginalTableId) {
143             _setOriginalTableId = true;
144 
145             _originalTableId = tableId;
146         }
147     }
148 
149     public long getOriginalTableId() {
150         return _originalTableId;
151     }
152 
153     public String getName() {
154         return GetterUtil.getString(_name);
155     }
156 
157     public void setName(String name) {
158         _name = name;
159 
160         if (_originalName == null) {
161             _originalName = name;
162         }
163     }
164 
165     public String getOriginalName() {
166         return GetterUtil.getString(_originalName);
167     }
168 
169     public int getType() {
170         return _type;
171     }
172 
173     public void setType(int type) {
174         _type = type;
175     }
176 
177     public ExpandoColumn toEscapedModel() {
178         if (isEscapedModel()) {
179             return (ExpandoColumn)this;
180         }
181         else {
182             ExpandoColumn model = new ExpandoColumnImpl();
183 
184             model.setNew(isNew());
185             model.setEscapedModel(true);
186 
187             model.setColumnId(getColumnId());
188             model.setTableId(getTableId());
189             model.setName(HtmlUtil.escape(getName()));
190             model.setType(getType());
191 
192             model = (ExpandoColumn)Proxy.newProxyInstance(ExpandoColumn.class.getClassLoader(),
193                     new Class[] { ExpandoColumn.class },
194                     new ReadOnlyBeanHandler(model));
195 
196             return model;
197         }
198     }
199 
200     public Object clone() {
201         ExpandoColumnImpl clone = new ExpandoColumnImpl();
202 
203         clone.setColumnId(getColumnId());
204         clone.setTableId(getTableId());
205         clone.setName(getName());
206         clone.setType(getType());
207 
208         return clone;
209     }
210 
211     public int compareTo(ExpandoColumn expandoColumn) {
212         long pk = expandoColumn.getPrimaryKey();
213 
214         if (getPrimaryKey() < pk) {
215             return -1;
216         }
217         else if (getPrimaryKey() > pk) {
218             return 1;
219         }
220         else {
221             return 0;
222         }
223     }
224 
225     public boolean equals(Object obj) {
226         if (obj == null) {
227             return false;
228         }
229 
230         ExpandoColumn expandoColumn = null;
231 
232         try {
233             expandoColumn = (ExpandoColumn)obj;
234         }
235         catch (ClassCastException cce) {
236             return false;
237         }
238 
239         long pk = expandoColumn.getPrimaryKey();
240 
241         if (getPrimaryKey() == pk) {
242             return true;
243         }
244         else {
245             return false;
246         }
247     }
248 
249     public int hashCode() {
250         return (int)getPrimaryKey();
251     }
252 
253     public String toString() {
254         StringBuilder sb = new StringBuilder();
255 
256         sb.append("{columnId=");
257         sb.append(getColumnId());
258         sb.append(", tableId=");
259         sb.append(getTableId());
260         sb.append(", name=");
261         sb.append(getName());
262         sb.append(", type=");
263         sb.append(getType());
264         sb.append("}");
265 
266         return sb.toString();
267     }
268 
269     public String toXmlString() {
270         StringBuilder sb = new StringBuilder();
271 
272         sb.append("<model><model-name>");
273         sb.append("com.liferay.portlet.expando.model.ExpandoColumn");
274         sb.append("</model-name>");
275 
276         sb.append(
277             "<column><column-name>columnId</column-name><column-value><![CDATA[");
278         sb.append(getColumnId());
279         sb.append("]]></column-value></column>");
280         sb.append(
281             "<column><column-name>tableId</column-name><column-value><![CDATA[");
282         sb.append(getTableId());
283         sb.append("]]></column-value></column>");
284         sb.append(
285             "<column><column-name>name</column-name><column-value><![CDATA[");
286         sb.append(getName());
287         sb.append("]]></column-value></column>");
288         sb.append(
289             "<column><column-name>type</column-name><column-value><![CDATA[");
290         sb.append(getType());
291         sb.append("]]></column-value></column>");
292 
293         sb.append("</model>");
294 
295         return sb.toString();
296     }
297 
298     private long _columnId;
299     private long _tableId;
300     private long _originalTableId;
301     private boolean _setOriginalTableId;
302     private String _name;
303     private String _originalName;
304     private int _type;
305 }