1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.model.impl;
21  
22  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
23  import com.liferay.portal.kernel.util.GetterUtil;
24  import com.liferay.portal.kernel.util.HtmlUtil;
25  import com.liferay.portal.model.Region;
26  import com.liferay.portal.model.RegionSoap;
27  
28  import java.io.Serializable;
29  
30  import java.lang.reflect.Proxy;
31  
32  import java.sql.Types;
33  
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * <a href="RegionModelImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * <p>
41   * ServiceBuilder generated this class. Modifications in this class will be
42   * overwritten the next time is generated.
43   * </p>
44   *
45   * <p>
46   * This class is a model that represents the <code>Region</code> table
47   * in the database.
48   * </p>
49   *
50   * @author Brian Wing Shun Chan
51   *
52   * @see com.liferay.portal.model.Region
53   * @see com.liferay.portal.model.RegionModel
54   * @see com.liferay.portal.model.impl.RegionImpl
55   *
56   */
57  public class RegionModelImpl extends BaseModelImpl {
58      public static final String TABLE_NAME = "Region";
59      public static final Object[][] TABLE_COLUMNS = {
60              { "regionId", new Integer(Types.BIGINT) },
61              
62  
63              { "countryId", new Integer(Types.BIGINT) },
64              
65  
66              { "regionCode", new Integer(Types.VARCHAR) },
67              
68  
69              { "name", new Integer(Types.VARCHAR) },
70              
71  
72              { "active_", new Integer(Types.BOOLEAN) }
73          };
74      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)";
75      public static final String TABLE_SQL_DROP = "drop table Region";
76      public static final String DATA_SOURCE = "liferayDataSource";
77      public static final String SESSION_FACTORY = "liferaySessionFactory";
78      public static final String TX_MANAGER = "liferayTransactionManager";
79      public static final boolean CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
80                  "value.object.finder.cache.enabled.com.liferay.portal.model.Region"),
81              true);
82  
83      public static Region toModel(RegionSoap soapModel) {
84          Region model = new RegionImpl();
85  
86          model.setRegionId(soapModel.getRegionId());
87          model.setCountryId(soapModel.getCountryId());
88          model.setRegionCode(soapModel.getRegionCode());
89          model.setName(soapModel.getName());
90          model.setActive(soapModel.getActive());
91  
92          return model;
93      }
94  
95      public static List<Region> toModels(RegionSoap[] soapModels) {
96          List<Region> models = new ArrayList<Region>(soapModels.length);
97  
98          for (RegionSoap soapModel : soapModels) {
99              models.add(toModel(soapModel));
100         }
101 
102         return models;
103     }
104 
105     public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
106                 "lock.expiration.time.com.liferay.portal.model.Region"));
107 
108     public RegionModelImpl() {
109     }
110 
111     public long getPrimaryKey() {
112         return _regionId;
113     }
114 
115     public void setPrimaryKey(long pk) {
116         setRegionId(pk);
117     }
118 
119     public Serializable getPrimaryKeyObj() {
120         return new Long(_regionId);
121     }
122 
123     public long getRegionId() {
124         return _regionId;
125     }
126 
127     public void setRegionId(long regionId) {
128         if (regionId != _regionId) {
129             _regionId = regionId;
130         }
131     }
132 
133     public long getCountryId() {
134         return _countryId;
135     }
136 
137     public void setCountryId(long countryId) {
138         if (countryId != _countryId) {
139             _countryId = countryId;
140         }
141     }
142 
143     public String getRegionCode() {
144         return GetterUtil.getString(_regionCode);
145     }
146 
147     public void setRegionCode(String regionCode) {
148         if (((regionCode == null) && (_regionCode != null)) ||
149                 ((regionCode != null) && (_regionCode == null)) ||
150                 ((regionCode != null) && (_regionCode != null) &&
151                 !regionCode.equals(_regionCode))) {
152             _regionCode = regionCode;
153         }
154     }
155 
156     public String getName() {
157         return GetterUtil.getString(_name);
158     }
159 
160     public void setName(String name) {
161         if (((name == null) && (_name != null)) ||
162                 ((name != null) && (_name == null)) ||
163                 ((name != null) && (_name != null) && !name.equals(_name))) {
164             _name = name;
165         }
166     }
167 
168     public boolean getActive() {
169         return _active;
170     }
171 
172     public boolean isActive() {
173         return _active;
174     }
175 
176     public void setActive(boolean active) {
177         if (active != _active) {
178             _active = active;
179         }
180     }
181 
182     public Region toEscapedModel() {
183         if (isEscapedModel()) {
184             return (Region)this;
185         }
186         else {
187             Region model = new RegionImpl();
188 
189             model.setNew(isNew());
190             model.setEscapedModel(true);
191 
192             model.setRegionId(getRegionId());
193             model.setCountryId(getCountryId());
194             model.setRegionCode(HtmlUtil.escape(getRegionCode()));
195             model.setName(HtmlUtil.escape(getName()));
196             model.setActive(getActive());
197 
198             model = (Region)Proxy.newProxyInstance(Region.class.getClassLoader(),
199                     new Class[] { Region.class }, new ReadOnlyBeanHandler(model));
200 
201             return model;
202         }
203     }
204 
205     public Object clone() {
206         RegionImpl clone = new RegionImpl();
207 
208         clone.setRegionId(getRegionId());
209         clone.setCountryId(getCountryId());
210         clone.setRegionCode(getRegionCode());
211         clone.setName(getName());
212         clone.setActive(getActive());
213 
214         return clone;
215     }
216 
217     public int compareTo(Object obj) {
218         if (obj == null) {
219             return -1;
220         }
221 
222         RegionImpl region = (RegionImpl)obj;
223 
224         int value = 0;
225 
226         value = getName().compareTo(region.getName());
227 
228         if (value != 0) {
229             return value;
230         }
231 
232         return 0;
233     }
234 
235     public boolean equals(Object obj) {
236         if (obj == null) {
237             return false;
238         }
239 
240         RegionImpl region = null;
241 
242         try {
243             region = (RegionImpl)obj;
244         }
245         catch (ClassCastException cce) {
246             return false;
247         }
248 
249         long pk = region.getPrimaryKey();
250 
251         if (getPrimaryKey() == pk) {
252             return true;
253         }
254         else {
255             return false;
256         }
257     }
258 
259     public int hashCode() {
260         return (int)getPrimaryKey();
261     }
262 
263     private long _regionId;
264     private long _countryId;
265     private String _regionCode;
266     private String _name;
267     private boolean _active;
268 }