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