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