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.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.model.Region;
29  import com.liferay.portal.model.RegionSoap;
30  
31  import com.liferay.portlet.expando.model.ExpandoBridge;
32  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
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="RegionModelImpl.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>Region</code> table
53   * in the database.
54   * </p>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   * @see com.liferay.portal.model.Region
59   * @see com.liferay.portal.model.RegionModel
60   * @see com.liferay.portal.model.impl.RegionImpl
61   *
62   */
63  public class RegionModelImpl extends BaseModelImpl<Region> {
64      public static final String TABLE_NAME = "Region";
65      public static final Object[][] TABLE_COLUMNS = {
66              { "regionId", new Integer(Types.BIGINT) },
67              
68  
69              { "countryId", new Integer(Types.BIGINT) },
70              
71  
72              { "regionCode", new Integer(Types.VARCHAR) },
73              
74  
75              { "name", new Integer(Types.VARCHAR) },
76              
77  
78              { "active_", new Integer(Types.BOOLEAN) }
79          };
80      public static final String TABLE_SQL_CREATE = "create table Region (regionId LONG not null primary key,countryId LONG,regionCode VARCHAR(75) null,name VARCHAR(75) null,active_ BOOLEAN)";
81      public static final String TABLE_SQL_DROP = "drop table Region";
82      public static final String DATA_SOURCE = "liferayDataSource";
83      public static final String SESSION_FACTORY = "liferaySessionFactory";
84      public static final String TX_MANAGER = "liferayTransactionManager";
85      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
86                  "value.object.entity.cache.enabled.com.liferay.portal.model.Region"),
87              true);
88      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
89                  "value.object.finder.cache.enabled.com.liferay.portal.model.Region"),
90              true);
91  
92      public static Region toModel(RegionSoap soapModel) {
93          Region model = new RegionImpl();
94  
95          model.setRegionId(soapModel.getRegionId());
96          model.setCountryId(soapModel.getCountryId());
97          model.setRegionCode(soapModel.getRegionCode());
98          model.setName(soapModel.getName());
99          model.setActive(soapModel.getActive());
100 
101         return model;
102     }
103 
104     public static List<Region> toModels(RegionSoap[] soapModels) {
105         List<Region> models = new ArrayList<Region>(soapModels.length);
106 
107         for (RegionSoap soapModel : soapModels) {
108             models.add(toModel(soapModel));
109         }
110 
111         return models;
112     }
113 
114     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
115                 "lock.expiration.time.com.liferay.portal.model.Region"));
116 
117     public RegionModelImpl() {
118     }
119 
120     public long getPrimaryKey() {
121         return _regionId;
122     }
123 
124     public void setPrimaryKey(long pk) {
125         setRegionId(pk);
126     }
127 
128     public Serializable getPrimaryKeyObj() {
129         return new Long(_regionId);
130     }
131 
132     public long getRegionId() {
133         return _regionId;
134     }
135 
136     public void setRegionId(long regionId) {
137         _regionId = regionId;
138     }
139 
140     public long getCountryId() {
141         return _countryId;
142     }
143 
144     public void setCountryId(long countryId) {
145         _countryId = countryId;
146     }
147 
148     public String getRegionCode() {
149         return GetterUtil.getString(_regionCode);
150     }
151 
152     public void setRegionCode(String regionCode) {
153         _regionCode = regionCode;
154     }
155 
156     public String getName() {
157         return GetterUtil.getString(_name);
158     }
159 
160     public void setName(String name) {
161         _name = name;
162     }
163 
164     public boolean getActive() {
165         return _active;
166     }
167 
168     public boolean isActive() {
169         return _active;
170     }
171 
172     public void setActive(boolean active) {
173         _active = active;
174     }
175 
176     public Region toEscapedModel() {
177         if (isEscapedModel()) {
178             return (Region)this;
179         }
180         else {
181             Region model = new RegionImpl();
182 
183             model.setNew(isNew());
184             model.setEscapedModel(true);
185 
186             model.setRegionId(getRegionId());
187             model.setCountryId(getCountryId());
188             model.setRegionCode(HtmlUtil.escape(getRegionCode()));
189             model.setName(HtmlUtil.escape(getName()));
190             model.setActive(getActive());
191 
192             model = (Region)Proxy.newProxyInstance(Region.class.getClassLoader(),
193                     new Class[] { Region.class }, new ReadOnlyBeanHandler(model));
194 
195             return model;
196         }
197     }
198 
199     public ExpandoBridge getExpandoBridge() {
200         if (_expandoBridge == null) {
201             _expandoBridge = new ExpandoBridgeImpl(Region.class.getName(),
202                     getPrimaryKey());
203         }
204 
205         return _expandoBridge;
206     }
207 
208     public Object clone() {
209         RegionImpl clone = new RegionImpl();
210 
211         clone.setRegionId(getRegionId());
212         clone.setCountryId(getCountryId());
213         clone.setRegionCode(getRegionCode());
214         clone.setName(getName());
215         clone.setActive(getActive());
216 
217         return clone;
218     }
219 
220     public int compareTo(Region region) {
221         int value = 0;
222 
223         value = getName().compareTo(region.getName());
224 
225         if (value != 0) {
226             return value;
227         }
228 
229         return 0;
230     }
231 
232     public boolean equals(Object obj) {
233         if (obj == null) {
234             return false;
235         }
236 
237         Region region = null;
238 
239         try {
240             region = (Region)obj;
241         }
242         catch (ClassCastException cce) {
243             return false;
244         }
245 
246         long pk = region.getPrimaryKey();
247 
248         if (getPrimaryKey() == pk) {
249             return true;
250         }
251         else {
252             return false;
253         }
254     }
255 
256     public int hashCode() {
257         return (int)getPrimaryKey();
258     }
259 
260     public String toString() {
261         StringBuilder sb = new StringBuilder();
262 
263         sb.append("{regionId=");
264         sb.append(getRegionId());
265         sb.append(", countryId=");
266         sb.append(getCountryId());
267         sb.append(", regionCode=");
268         sb.append(getRegionCode());
269         sb.append(", name=");
270         sb.append(getName());
271         sb.append(", active=");
272         sb.append(getActive());
273         sb.append("}");
274 
275         return sb.toString();
276     }
277 
278     public String toXmlString() {
279         StringBuilder sb = new StringBuilder();
280 
281         sb.append("<model><model-name>");
282         sb.append("com.liferay.portal.model.Region");
283         sb.append("</model-name>");
284 
285         sb.append(
286             "<column><column-name>regionId</column-name><column-value><![CDATA[");
287         sb.append(getRegionId());
288         sb.append("]]></column-value></column>");
289         sb.append(
290             "<column><column-name>countryId</column-name><column-value><![CDATA[");
291         sb.append(getCountryId());
292         sb.append("]]></column-value></column>");
293         sb.append(
294             "<column><column-name>regionCode</column-name><column-value><![CDATA[");
295         sb.append(getRegionCode());
296         sb.append("]]></column-value></column>");
297         sb.append(
298             "<column><column-name>name</column-name><column-value><![CDATA[");
299         sb.append(getName());
300         sb.append("]]></column-value></column>");
301         sb.append(
302             "<column><column-name>active</column-name><column-value><![CDATA[");
303         sb.append(getActive());
304         sb.append("]]></column-value></column>");
305 
306         sb.append("</model>");
307 
308         return sb.toString();
309     }
310 
311     private long _regionId;
312     private long _countryId;
313     private String _regionCode;
314     private String _name;
315     private boolean _active;
316     private transient ExpandoBridge _expandoBridge;
317 }