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