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.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<ExpandoTable> {
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 ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
81                  "value.object.entity.cache.enabled.com.liferay.portlet.expando.model.ExpandoTable"),
82              true);
83      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
84                  "value.object.finder.cache.enabled.com.liferay.portlet.expando.model.ExpandoTable"),
85              true);
86  
87      public static ExpandoTable toModel(ExpandoTableSoap soapModel) {
88          ExpandoTable model = new ExpandoTableImpl();
89  
90          model.setTableId(soapModel.getTableId());
91          model.setClassNameId(soapModel.getClassNameId());
92          model.setName(soapModel.getName());
93  
94          return model;
95      }
96  
97      public static List<ExpandoTable> toModels(ExpandoTableSoap[] soapModels) {
98          List<ExpandoTable> models = new ArrayList<ExpandoTable>(soapModels.length);
99  
100         for (ExpandoTableSoap soapModel : soapModels) {
101             models.add(toModel(soapModel));
102         }
103 
104         return models;
105     }
106 
107     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
108                 "lock.expiration.time.com.liferay.portlet.expando.model.ExpandoTable"));
109 
110     public ExpandoTableModelImpl() {
111     }
112 
113     public long getPrimaryKey() {
114         return _tableId;
115     }
116 
117     public void setPrimaryKey(long pk) {
118         setTableId(pk);
119     }
120 
121     public Serializable getPrimaryKeyObj() {
122         return new Long(_tableId);
123     }
124 
125     public long getTableId() {
126         return _tableId;
127     }
128 
129     public void setTableId(long tableId) {
130         _tableId = tableId;
131     }
132 
133     public String getClassName() {
134         if (getClassNameId() <= 0) {
135             return StringPool.BLANK;
136         }
137 
138         return PortalUtil.getClassName(getClassNameId());
139     }
140 
141     public long getClassNameId() {
142         return _classNameId;
143     }
144 
145     public void setClassNameId(long classNameId) {
146         _classNameId = classNameId;
147 
148         if (!_setOriginalClassNameId) {
149             _setOriginalClassNameId = true;
150 
151             _originalClassNameId = classNameId;
152         }
153     }
154 
155     public long getOriginalClassNameId() {
156         return _originalClassNameId;
157     }
158 
159     public String getName() {
160         return GetterUtil.getString(_name);
161     }
162 
163     public void setName(String name) {
164         _name = name;
165 
166         if (_originalName == null) {
167             _originalName = name;
168         }
169     }
170 
171     public String getOriginalName() {
172         return GetterUtil.getString(_originalName);
173     }
174 
175     public ExpandoTable toEscapedModel() {
176         if (isEscapedModel()) {
177             return (ExpandoTable)this;
178         }
179         else {
180             ExpandoTable model = new ExpandoTableImpl();
181 
182             model.setNew(isNew());
183             model.setEscapedModel(true);
184 
185             model.setTableId(getTableId());
186             model.setClassNameId(getClassNameId());
187             model.setName(HtmlUtil.escape(getName()));
188 
189             model = (ExpandoTable)Proxy.newProxyInstance(ExpandoTable.class.getClassLoader(),
190                     new Class[] { ExpandoTable.class },
191                     new ReadOnlyBeanHandler(model));
192 
193             return model;
194         }
195     }
196 
197     public Object clone() {
198         ExpandoTableImpl clone = new ExpandoTableImpl();
199 
200         clone.setTableId(getTableId());
201         clone.setClassNameId(getClassNameId());
202         clone.setName(getName());
203 
204         return clone;
205     }
206 
207     public int compareTo(ExpandoTable expandoTable) {
208         long pk = expandoTable.getPrimaryKey();
209 
210         if (getPrimaryKey() < pk) {
211             return -1;
212         }
213         else if (getPrimaryKey() > pk) {
214             return 1;
215         }
216         else {
217             return 0;
218         }
219     }
220 
221     public boolean equals(Object obj) {
222         if (obj == null) {
223             return false;
224         }
225 
226         ExpandoTable expandoTable = null;
227 
228         try {
229             expandoTable = (ExpandoTable)obj;
230         }
231         catch (ClassCastException cce) {
232             return false;
233         }
234 
235         long pk = expandoTable.getPrimaryKey();
236 
237         if (getPrimaryKey() == pk) {
238             return true;
239         }
240         else {
241             return false;
242         }
243     }
244 
245     public int hashCode() {
246         return (int)getPrimaryKey();
247     }
248 
249     public String toString() {
250         StringBuilder sb = new StringBuilder();
251 
252         sb.append("{tableId=");
253         sb.append(getTableId());
254         sb.append(", classNameId=");
255         sb.append(getClassNameId());
256         sb.append(", name=");
257         sb.append(getName());
258         sb.append("}");
259 
260         return sb.toString();
261     }
262 
263     public String toXmlString() {
264         StringBuilder sb = new StringBuilder();
265 
266         sb.append("<model><model-name>");
267         sb.append("com.liferay.portlet.expando.model.ExpandoTable");
268         sb.append("</model-name>");
269 
270         sb.append(
271             "<column><column-name>tableId</column-name><column-value><![CDATA[");
272         sb.append(getTableId());
273         sb.append("]]></column-value></column>");
274         sb.append(
275             "<column><column-name>classNameId</column-name><column-value><![CDATA[");
276         sb.append(getClassNameId());
277         sb.append("]]></column-value></column>");
278         sb.append(
279             "<column><column-name>name</column-name><column-value><![CDATA[");
280         sb.append(getName());
281         sb.append("]]></column-value></column>");
282 
283         sb.append("</model>");
284 
285         return sb.toString();
286     }
287 
288     private long _tableId;
289     private long _classNameId;
290     private long _originalClassNameId;
291     private boolean _setOriginalClassNameId;
292     private String _name;
293     private String _originalName;
294 }