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.PortalUtil;
30  import com.liferay.portal.util.PropsUtil;
31  
32  import com.liferay.portlet.expando.model.ExpandoTable;
33  import com.liferay.portlet.expando.model.ExpandoTableSoap;
34  
35  import java.io.Serializable;
36  
37  import java.lang.reflect.Proxy;
38  
39  import java.sql.Types;
40  
41  import java.util.ArrayList;
42  import java.util.List;
43  
44  /**
45   * <a href="ExpandoTableModelImpl.java.html"><b><i>View Source</i></b></a>
46   *
47   * <p>
48   * ServiceBuilder generated this class. Modifications in this class will be
49   * overwritten the next time is generated.
50   * </p>
51   *
52   * <p>
53   * This class is a model that represents the <code>ExpandoTable</code> table
54   * in the database.
55   * </p>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   * @see com.liferay.portlet.expando.service.model.ExpandoTable
60   * @see com.liferay.portlet.expando.service.model.ExpandoTableModel
61   * @see com.liferay.portlet.expando.service.model.impl.ExpandoTableImpl
62   *
63   */
64  public class ExpandoTableModelImpl extends BaseModelImpl {
65      public static final String TABLE_NAME = "ExpandoTable";
66      public static final Object[][] TABLE_COLUMNS = {
67              { "tableId", new Integer(Types.BIGINT) },
68              
69  
70              { "classNameId", new Integer(Types.BIGINT) },
71              
72  
73              { "name", new Integer(Types.VARCHAR) }
74          };
75      public static final String TABLE_SQL_CREATE = "create table ExpandoTable (tableId LONG not null primary key,classNameId LONG,name VARCHAR(75) null)";
76      public static final String TABLE_SQL_DROP = "drop table ExpandoTable";
77      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(PropsUtil.get(
78                  "value.object.finder.cache.enabled.com.liferay.portlet.expando.model.ExpandoTable"),
79              true);
80  
81      public static ExpandoTable toModel(ExpandoTableSoap soapModel) {
82          ExpandoTable model = new ExpandoTableImpl();
83  
84          model.setTableId(soapModel.getTableId());
85          model.setClassNameId(soapModel.getClassNameId());
86          model.setName(soapModel.getName());
87  
88          return model;
89      }
90  
91      public static List<ExpandoTable> toModels(ExpandoTableSoap[] soapModels) {
92          List<ExpandoTable> models = new ArrayList<ExpandoTable>(soapModels.length);
93  
94          for (ExpandoTableSoap soapModel : soapModels) {
95              models.add(toModel(soapModel));
96          }
97  
98          return models;
99      }
100 
101     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(PropsUtil.get(
102                 "lock.expiration.time.com.liferay.portlet.expando.model.ExpandoTable"));
103 
104     public ExpandoTableModelImpl() {
105     }
106 
107     public long getPrimaryKey() {
108         return _tableId;
109     }
110 
111     public void setPrimaryKey(long pk) {
112         setTableId(pk);
113     }
114 
115     public Serializable getPrimaryKeyObj() {
116         return new Long(_tableId);
117     }
118 
119     public long getTableId() {
120         return _tableId;
121     }
122 
123     public void setTableId(long tableId) {
124         if (tableId != _tableId) {
125             _tableId = tableId;
126         }
127     }
128 
129     public String getClassName() {
130         return PortalUtil.getClassName(getClassNameId());
131     }
132 
133     public long getClassNameId() {
134         return _classNameId;
135     }
136 
137     public void setClassNameId(long classNameId) {
138         if (classNameId != _classNameId) {
139             _classNameId = classNameId;
140         }
141     }
142 
143     public String getName() {
144         return GetterUtil.getString(_name);
145     }
146 
147     public void setName(String name) {
148         if (((name == null) && (_name != null)) ||
149                 ((name != null) && (_name == null)) ||
150                 ((name != null) && (_name != null) && !name.equals(_name))) {
151             _name = name;
152         }
153     }
154 
155     public ExpandoTable toEscapedModel() {
156         if (isEscapedModel()) {
157             return (ExpandoTable)this;
158         }
159         else {
160             ExpandoTable model = new ExpandoTableImpl();
161 
162             model.setEscapedModel(true);
163 
164             model.setTableId(getTableId());
165             model.setClassNameId(getClassNameId());
166             model.setName(HtmlUtil.escape(getName()));
167 
168             model = (ExpandoTable)Proxy.newProxyInstance(ExpandoTable.class.getClassLoader(),
169                     new Class[] { ExpandoTable.class },
170                     new ReadOnlyBeanHandler(model));
171 
172             return model;
173         }
174     }
175 
176     public Object clone() {
177         ExpandoTableImpl clone = new ExpandoTableImpl();
178 
179         clone.setTableId(getTableId());
180         clone.setClassNameId(getClassNameId());
181         clone.setName(getName());
182 
183         return clone;
184     }
185 
186     public int compareTo(Object obj) {
187         if (obj == null) {
188             return -1;
189         }
190 
191         ExpandoTableImpl expandoTable = (ExpandoTableImpl)obj;
192 
193         long pk = expandoTable.getPrimaryKey();
194 
195         if (getPrimaryKey() < pk) {
196             return -1;
197         }
198         else if (getPrimaryKey() > pk) {
199             return 1;
200         }
201         else {
202             return 0;
203         }
204     }
205 
206     public boolean equals(Object obj) {
207         if (obj == null) {
208             return false;
209         }
210 
211         ExpandoTableImpl expandoTable = null;
212 
213         try {
214             expandoTable = (ExpandoTableImpl)obj;
215         }
216         catch (ClassCastException cce) {
217             return false;
218         }
219 
220         long pk = expandoTable.getPrimaryKey();
221 
222         if (getPrimaryKey() == pk) {
223             return true;
224         }
225         else {
226             return false;
227         }
228     }
229 
230     public int hashCode() {
231         return (int)getPrimaryKey();
232     }
233 
234     private long _tableId;
235     private long _classNameId;
236     private String _name;
237 }