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.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 {
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.setNew(isNew());
193             model.setEscapedModel(true);
194 
195             model.setRegionId(getRegionId());
196             model.setCountryId(getCountryId());
197             model.setRegionCode(HtmlUtil.escape(getRegionCode()));
198             model.setName(HtmlUtil.escape(getName()));
199             model.setActive(getActive());
200 
201             model = (Region)Proxy.newProxyInstance(Region.class.getClassLoader(),
202                     new Class[] { Region.class }, new ReadOnlyBeanHandler(model));
203 
204             return model;
205         }
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(Object obj) {
221         if (obj == null) {
222             return -1;
223         }
224 
225         RegionImpl region = (RegionImpl)obj;
226 
227         int value = 0;
228 
229         value = getName().compareTo(region.getName());
230 
231         if (value != 0) {
232             return value;
233         }
234 
235         return 0;
236     }
237 
238     public boolean equals(Object obj) {
239         if (obj == null) {
240             return false;
241         }
242 
243         RegionImpl region = null;
244 
245         try {
246             region = (RegionImpl)obj;
247         }
248         catch (ClassCastException cce) {
249             return false;
250         }
251 
252         long pk = region.getPrimaryKey();
253 
254         if (getPrimaryKey() == pk) {
255             return true;
256         }
257         else {
258             return false;
259         }
260     }
261 
262     public int hashCode() {
263         return (int)getPrimaryKey();
264     }
265 
266     private long _regionId;
267     private long _countryId;
268     private String _regionCode;
269     private String _name;
270     private boolean _active;
271 }