1   /**
2    * Copyright (c) 2000-2008 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  import com.liferay.portal.util.PropsUtil;
30  
31  import com.liferay.portlet.expando.model.ExpandoColumn;
32  import com.liferay.portlet.expando.model.ExpandoColumnSoap;
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="ExpandoColumnModelImpl.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>ExpandoColumn</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portlet.expando.service.model.ExpandoColumn
59   * @see com.liferay.portlet.expando.service.model.ExpandoColumnModel
60   * @see com.liferay.portlet.expando.service.model.impl.ExpandoColumnImpl
61   *
62   */
63  public class ExpandoColumnModelImpl extends BaseModelImpl {
64      public static final String TABLE_NAME = "ExpandoColumn";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "columnId", new Integer(Types.BIGINT) },
67              
68  
69              { "tableId", new Integer(Types.BIGINT) },
70              
71  
72              { "name", new Integer(Types.VARCHAR) },
73              
74  
75              { "type_", new Integer(Types.INTEGER) }
76          };
77      public static final String TABLE_SQL_CREATE = "create table ExpandoColumn (columnId LONG not null primary key,tableId LONG,name VARCHAR(75) null,type_ INTEGER)";
78      public static final String TABLE_SQL_DROP = "drop table ExpandoColumn";
79      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
80                  "value.object.finder.cache.enabled.com.liferay.portlet.expando.model.ExpandoColumn"),
81              true);
82  
83      public static ExpandoColumn toModel(ExpandoColumnSoap soapModel) {
84          ExpandoColumn model = new ExpandoColumnImpl();
85  
86          model.setColumnId(soapModel.getColumnId());
87          model.setTableId(soapModel.getTableId());
88          model.setName(soapModel.getName());
89          model.setType(soapModel.getType());
90  
91          return model;
92      }
93  
94      public static List<ExpandoColumn> toModels(ExpandoColumnSoap[] soapModels) {
95          List<ExpandoColumn> models = new ArrayList<ExpandoColumn>(soapModels.length);
96  
97          for (ExpandoColumnSoap soapModel : soapModels) {
98              models.add(toModel(soapModel));
99          }
100 
101         return models;
102     }
103 
104     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
105                 "lock.expiration.time.com.liferay.portlet.expando.model.ExpandoColumn"));
106 
107     public ExpandoColumnModelImpl() {
108     }
109 
110     public long getPrimaryKey() {
111         return _columnId;
112     }
113 
114     public void setPrimaryKey(long pk) {
115         setColumnId(pk);
116     }
117 
118     public Serializable getPrimaryKeyObj() {
119         return new Long(_columnId);
120     }
121 
122     public long getColumnId() {
123         return _columnId;
124     }
125 
126     public void setColumnId(long columnId) {
127         if (columnId != _columnId) {
128             _columnId = columnId;
129         }
130     }
131 
132     public long getTableId() {
133         return _tableId;
134     }
135 
136     public void setTableId(long tableId) {
137         if (tableId != _tableId) {
138             _tableId = tableId;
139         }
140     }
141 
142     public String getName() {
143         return GetterUtil.getString(_name);
144     }
145 
146     public void setName(String name) {
147         if (((name == null) && (_name != null)) ||
148                 ((name != null) && (_name == null)) ||
149                 ((name != null) && (_name != null) && !name.equals(_name))) {
150             _name = name;
151         }
152     }
153 
154     public int getType() {
155         return _type;
156     }
157 
158     public void setType(int type) {
159         if (type != _type) {
160             _type = type;
161         }
162     }
163 
164     public ExpandoColumn toEscapedModel() {
165         if (isEscapedModel()) {
166             return (ExpandoColumn)this;
167         }
168         else {
169             ExpandoColumn model = new ExpandoColumnImpl();
170 
171             model.setEscapedModel(true);
172 
173             model.setColumnId(getColumnId());
174             model.setTableId(getTableId());
175             model.setName(HtmlUtil.escape(getName()));
176             model.setType(getType());
177 
178             model = (ExpandoColumn)Proxy.newProxyInstance(ExpandoColumn.class.getClassLoader(),
179                     new Class[] { ExpandoColumn.class },
180                     new ReadOnlyBeanHandler(model));
181 
182             return model;
183         }
184     }
185 
186     public Object clone() {
187         ExpandoColumnImpl clone = new ExpandoColumnImpl();
188 
189         clone.setColumnId(getColumnId());
190         clone.setTableId(getTableId());
191         clone.setName(getName());
192         clone.setType(getType());
193 
194         return clone;
195     }
196 
197     public int compareTo(Object obj) {
198         if (obj == null) {
199             return -1;
200         }
201 
202         ExpandoColumnImpl expandoColumn = (ExpandoColumnImpl)obj;
203 
204         long pk = expandoColumn.getPrimaryKey();
205 
206         if (getPrimaryKey() < pk) {
207             return -1;
208         }
209         else if (getPrimaryKey() > pk) {
210             return 1;
211         }
212         else {
213             return 0;
214         }
215     }
216 
217     public boolean equals(Object obj) {
218         if (obj == null) {
219             return false;
220         }
221 
222         ExpandoColumnImpl expandoColumn = null;
223 
224         try {
225             expandoColumn = (ExpandoColumnImpl)obj;
226         }
227         catch (ClassCastException cce) {
228             return false;
229         }
230 
231         long pk = expandoColumn.getPrimaryKey();
232 
233         if (getPrimaryKey() == pk) {
234             return true;
235         }
236         else {
237             return false;
238         }
239     }
240 
241     public int hashCode() {
242         return (int)getPrimaryKey();
243     }
244 
245     private long _columnId;
246     private long _tableId;
247     private String _name;
248     private int _type;
249 }