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.kernel.util.StringPool;
29  import com.liferay.portal.model.impl.BaseModelImpl;
30  import com.liferay.portal.util.PortalUtil;
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.model.ExpandoTable
60   * @see com.liferay.portlet.expando.model.ExpandoTableModel
61   * @see com.liferay.portlet.expando.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 String DATA_SOURCE = "liferayDataSource";
78      public static final String SESSION_FACTORY = "liferaySessionFactory";
79      public static final String TX_MANAGER = "liferayTransactionManager";
80      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
81                  "value.object.finder.cache.enabled.com.liferay.portlet.expando.model.ExpandoTable"),
82              true);
83  
84      public static ExpandoTable toModel(ExpandoTableSoap soapModel) {
85          ExpandoTable model = new ExpandoTableImpl();
86  
87          model.setTableId(soapModel.getTableId());
88          model.setClassNameId(soapModel.getClassNameId());
89          model.setName(soapModel.getName());
90  
91          return model;
92      }
93  
94      public static List<ExpandoTable> toModels(ExpandoTableSoap[] soapModels) {
95          List<ExpandoTable> models = new ArrayList<ExpandoTable>(soapModels.length);
96  
97          for (ExpandoTableSoap soapModel : soapModels) {
98              models.add(toModel(soapModel));
99          }
100 
101         return models;
102     }
103 
104     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
105                 "lock.expiration.time.com.liferay.portlet.expando.model.ExpandoTable"));
106 
107     public ExpandoTableModelImpl() {
108     }
109 
110     public long getPrimaryKey() {
111         return _tableId;
112     }
113 
114     public void setPrimaryKey(long pk) {
115         setTableId(pk);
116     }
117 
118     public Serializable getPrimaryKeyObj() {
119         return new Long(_tableId);
120     }
121 
122     public long getTableId() {
123         return _tableId;
124     }
125 
126     public void setTableId(long tableId) {
127         if (tableId != _tableId) {
128             _tableId = tableId;
129         }
130     }
131 
132     public String getClassName() {
133         if (getClassNameId() <= 0) {
134             return StringPool.BLANK;
135         }
136 
137         return PortalUtil.getClassName(getClassNameId());
138     }
139 
140     public long getClassNameId() {
141         return _classNameId;
142     }
143 
144     public void setClassNameId(long classNameId) {
145         if (classNameId != _classNameId) {
146             _classNameId = classNameId;
147         }
148     }
149 
150     public String getName() {
151         return GetterUtil.getString(_name);
152     }
153 
154     public void setName(String name) {
155         if (((name == null) && (_name != null)) ||
156                 ((name != null) && (_name == null)) ||
157                 ((name != null) && (_name != null) && !name.equals(_name))) {
158             _name = name;
159         }
160     }
161 
162     public ExpandoTable toEscapedModel() {
163         if (isEscapedModel()) {
164             return (ExpandoTable)this;
165         }
166         else {
167             ExpandoTable model = new ExpandoTableImpl();
168 
169             model.setNew(isNew());
170             model.setEscapedModel(true);
171 
172             model.setTableId(getTableId());
173             model.setClassNameId(getClassNameId());
174             model.setName(HtmlUtil.escape(getName()));
175 
176             model = (ExpandoTable)Proxy.newProxyInstance(ExpandoTable.class.getClassLoader(),
177                     new Class[] { ExpandoTable.class },
178                     new ReadOnlyBeanHandler(model));
179 
180             return model;
181         }
182     }
183 
184     public Object clone() {
185         ExpandoTableImpl clone = new ExpandoTableImpl();
186 
187         clone.setTableId(getTableId());
188         clone.setClassNameId(getClassNameId());
189         clone.setName(getName());
190 
191         return clone;
192     }
193 
194     public int compareTo(Object obj) {
195         if (obj == null) {
196             return -1;
197         }
198 
199         ExpandoTableImpl expandoTable = (ExpandoTableImpl)obj;
200 
201         long pk = expandoTable.getPrimaryKey();
202 
203         if (getPrimaryKey() < pk) {
204             return -1;
205         }
206         else if (getPrimaryKey() > pk) {
207             return 1;
208         }
209         else {
210             return 0;
211         }
212     }
213 
214     public boolean equals(Object obj) {
215         if (obj == null) {
216             return false;
217         }
218 
219         ExpandoTableImpl expandoTable = null;
220 
221         try {
222             expandoTable = (ExpandoTableImpl)obj;
223         }
224         catch (ClassCastException cce) {
225             return false;
226         }
227 
228         long pk = expandoTable.getPrimaryKey();
229 
230         if (getPrimaryKey() == pk) {
231             return true;
232         }
233         else {
234             return false;
235         }
236     }
237 
238     public int hashCode() {
239         return (int)getPrimaryKey();
240     }
241 
242     private long _tableId;
243     private long _classNameId;
244     private String _name;
245 }