1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.expando.model.impl;
21  
22  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
23  import com.liferay.portal.kernel.util.GetterUtil;
24  import com.liferay.portal.kernel.util.HtmlUtil;
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.model.impl.BaseModelImpl;
27  import com.liferay.portal.util.PortalUtil;
28  
29  import com.liferay.portlet.expando.model.ExpandoTable;
30  import com.liferay.portlet.expando.model.ExpandoTableSoap;
31  
32  import java.io.Serializable;
33  
34  import java.lang.reflect.Proxy;
35  
36  import java.sql.Types;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  /**
42   * <a href="ExpandoTableModelImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * <p>
45   * ServiceBuilder generated this class. Modifications in this class will be
46   * overwritten the next time is generated.
47   * </p>
48   *
49   * <p>
50   * This class is a model that represents the <code>ExpandoTable</code> table
51   * in the database.
52   * </p>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   * @see com.liferay.portlet.expando.model.ExpandoTable
57   * @see com.liferay.portlet.expando.model.ExpandoTableModel
58   * @see com.liferay.portlet.expando.model.impl.ExpandoTableImpl
59   *
60   */
61  public class ExpandoTableModelImpl extends BaseModelImpl {
62      public static final String TABLE_NAME = "ExpandoTable";
63      public static final Object[][] TABLE_COLUMNS = {
64              { "tableId", new Integer(Types.BIGINT) },
65              
66  
67              { "classNameId", new Integer(Types.BIGINT) },
68              
69  
70              { "name", new Integer(Types.VARCHAR) }
71          };
72      public static final String TABLE_SQL_CREATE = "create table ExpandoTable (tableId LONG not null primary key,classNameId LONG,name VARCHAR(75) null)";
73      public static final String TABLE_SQL_DROP = "drop table ExpandoTable";
74      public static final String DATA_SOURCE = "liferayDataSource";
75      public static final String SESSION_FACTORY = "liferaySessionFactory";
76      public static final String TX_MANAGER = "liferayTransactionManager";
77      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.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(com.liferay.portal.util.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         if (getClassNameId() <= 0) {
131             return StringPool.BLANK;
132         }
133 
134         return PortalUtil.getClassName(getClassNameId());
135     }
136 
137     public long getClassNameId() {
138         return _classNameId;
139     }
140 
141     public void setClassNameId(long classNameId) {
142         if (classNameId != _classNameId) {
143             _classNameId = classNameId;
144         }
145     }
146 
147     public String getName() {
148         return GetterUtil.getString(_name);
149     }
150 
151     public void setName(String name) {
152         if (((name == null) && (_name != null)) ||
153                 ((name != null) && (_name == null)) ||
154                 ((name != null) && (_name != null) && !name.equals(_name))) {
155             _name = name;
156         }
157     }
158 
159     public ExpandoTable toEscapedModel() {
160         if (isEscapedModel()) {
161             return (ExpandoTable)this;
162         }
163         else {
164             ExpandoTable model = new ExpandoTableImpl();
165 
166             model.setNew(isNew());
167             model.setEscapedModel(true);
168 
169             model.setTableId(getTableId());
170             model.setClassNameId(getClassNameId());
171             model.setName(HtmlUtil.escape(getName()));
172 
173             model = (ExpandoTable)Proxy.newProxyInstance(ExpandoTable.class.getClassLoader(),
174                     new Class[] { ExpandoTable.class },
175                     new ReadOnlyBeanHandler(model));
176 
177             return model;
178         }
179     }
180 
181     public Object clone() {
182         ExpandoTableImpl clone = new ExpandoTableImpl();
183 
184         clone.setTableId(getTableId());
185         clone.setClassNameId(getClassNameId());
186         clone.setName(getName());
187 
188         return clone;
189     }
190 
191     public int compareTo(Object obj) {
192         if (obj == null) {
193             return -1;
194         }
195 
196         ExpandoTableImpl expandoTable = (ExpandoTableImpl)obj;
197 
198         long pk = expandoTable.getPrimaryKey();
199 
200         if (getPrimaryKey() < pk) {
201             return -1;
202         }
203         else if (getPrimaryKey() > pk) {
204             return 1;
205         }
206         else {
207             return 0;
208         }
209     }
210 
211     public boolean equals(Object obj) {
212         if (obj == null) {
213             return false;
214         }
215 
216         ExpandoTableImpl expandoTable = null;
217 
218         try {
219             expandoTable = (ExpandoTableImpl)obj;
220         }
221         catch (ClassCastException cce) {
222             return false;
223         }
224 
225         long pk = expandoTable.getPrimaryKey();
226 
227         if (getPrimaryKey() == pk) {
228             return true;
229         }
230         else {
231             return false;
232         }
233     }
234 
235     public int hashCode() {
236         return (int)getPrimaryKey();
237     }
238 
239     private long _tableId;
240     private long _classNameId;
241     private String _name;
242 }