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.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.service.model.Region
56   * @see com.liferay.portal.service.model.RegionModel
57   * @see com.liferay.portal.service.model.impl.RegionImpl
58   *
59   */
60  public class RegionModelImpl extends BaseModelImpl {
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 CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
83                  "value.object.finder.cache.enabled.com.liferay.portal.model.Region"),
84              true);
85  
86      public static Region toModel(RegionSoap soapModel) {
87          Region model = new RegionImpl();
88  
89          model.setRegionId(soapModel.getRegionId());
90          model.setCountryId(soapModel.getCountryId());
91          model.setRegionCode(soapModel.getRegionCode());
92          model.setName(soapModel.getName());
93          model.setActive(soapModel.getActive());
94  
95          return model;
96      }
97  
98      public static List<Region> toModels(RegionSoap[] soapModels) {
99          List<Region> models = new ArrayList<Region>(soapModels.length);
100 
101         for (RegionSoap soapModel : soapModels) {
102             models.add(toModel(soapModel));
103         }
104 
105         return models;
106     }
107 
108     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
109                 "lock.expiration.time.com.liferay.portal.model.Region"));
110 
111     public RegionModelImpl() {
112     }
113 
114     public long getPrimaryKey() {
115         return _regionId;
116     }
117 
118     public void setPrimaryKey(long pk) {
119         setRegionId(pk);
120     }
121 
122     public Serializable getPrimaryKeyObj() {
123         return new Long(_regionId);
124     }
125 
126     public long getRegionId() {
127         return _regionId;
128     }
129 
130     public void setRegionId(long regionId) {
131         if (regionId != _regionId) {
132             _regionId = regionId;
133         }
134     }
135 
136     public long getCountryId() {
137         return _countryId;
138     }
139 
140     public void setCountryId(long countryId) {
141         if (countryId != _countryId) {
142             _countryId = countryId;
143         }
144     }
145 
146     public String getRegionCode() {
147         return GetterUtil.getString(_regionCode);
148     }
149 
150     public void setRegionCode(String regionCode) {
151         if (((regionCode == null) && (_regionCode != null)) ||
152                 ((regionCode != null) && (_regionCode == null)) ||
153                 ((regionCode != null) && (_regionCode != null) &&
154                 !regionCode.equals(_regionCode))) {
155             _regionCode = regionCode;
156         }
157     }
158 
159     public String getName() {
160         return GetterUtil.getString(_name);
161     }
162 
163     public void setName(String name) {
164         if (((name == null) && (_name != null)) ||
165                 ((name != null) && (_name == null)) ||
166                 ((name != null) && (_name != null) && !name.equals(_name))) {
167             _name = name;
168         }
169     }
170 
171     public boolean getActive() {
172         return _active;
173     }
174 
175     public boolean isActive() {
176         return _active;
177     }
178 
179     public void setActive(boolean active) {
180         if (active != _active) {
181             _active = active;
182         }
183     }
184 
185     public Region toEscapedModel() {
186         if (isEscapedModel()) {
187             return (Region)this;
188         }
189         else {
190             Region model = new RegionImpl();
191 
192             model.setEscapedModel(true);
193 
194             model.setRegionId(getRegionId());
195             model.setCountryId(getCountryId());
196             model.setRegionCode(HtmlUtil.escape(getRegionCode()));
197             model.setName(HtmlUtil.escape(getName()));
198             model.setActive(getActive());
199 
200             model = (Region)Proxy.newProxyInstance(Region.class.getClassLoader(),
201                     new Class[] { Region.class }, new ReadOnlyBeanHandler(model));
202 
203             return model;
204         }
205     }
206 
207     public Object clone() {
208         RegionImpl clone = new RegionImpl();
209 
210         clone.setRegionId(getRegionId());
211         clone.setCountryId(getCountryId());
212         clone.setRegionCode(getRegionCode());
213         clone.setName(getName());
214         clone.setActive(getActive());
215 
216         return clone;
217     }
218 
219     public int compareTo(Object obj) {
220         if (obj == null) {
221             return -1;
222         }
223 
224         RegionImpl region = (RegionImpl)obj;
225 
226         int value = 0;
227 
228         value = getName().compareTo(region.getName());
229 
230         if (value != 0) {
231             return value;
232         }
233 
234         return 0;
235     }
236 
237     public boolean equals(Object obj) {
238         if (obj == null) {
239             return false;
240         }
241 
242         RegionImpl region = null;
243 
244         try {
245             region = (RegionImpl)obj;
246         }
247         catch (ClassCastException cce) {
248             return false;
249         }
250 
251         long pk = region.getPrimaryKey();
252 
253         if (getPrimaryKey() == pk) {
254             return true;
255         }
256         else {
257             return false;
258         }
259     }
260 
261     public int hashCode() {
262         return (int)getPrimaryKey();
263     }
264 
265     private long _regionId;
266     private long _countryId;
267     private String _regionCode;
268     private String _name;
269     private boolean _active;
270 }