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