001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
018    import com.liferay.portal.kernel.json.JSON;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.ProxyUtil;
021    import com.liferay.portal.kernel.util.StringBundler;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.model.CacheModel;
024    import com.liferay.portal.model.Region;
025    import com.liferay.portal.model.RegionModel;
026    import com.liferay.portal.model.RegionSoap;
027    import com.liferay.portal.service.ServiceContext;
028    
029    import com.liferay.portlet.expando.model.ExpandoBridge;
030    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
031    
032    import java.io.Serializable;
033    
034    import java.sql.Types;
035    
036    import java.util.ArrayList;
037    import java.util.List;
038    
039    /**
040     * The base model implementation for the Region service. Represents a row in the "Region" database table, with each column mapped to a property of this class.
041     *
042     * <p>
043     * This implementation and its corresponding interface {@link com.liferay.portal.model.RegionModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link RegionImpl}.
044     * </p>
045     *
046     * @author Brian Wing Shun Chan
047     * @see RegionImpl
048     * @see com.liferay.portal.model.Region
049     * @see com.liferay.portal.model.RegionModel
050     * @generated
051     */
052    @JSON(strict = true)
053    public class RegionModelImpl extends BaseModelImpl<Region>
054            implements RegionModel {
055            /*
056             * NOTE FOR DEVELOPERS:
057             *
058             * Never modify or reference this class directly. All methods that expect a region model instance should use the {@link com.liferay.portal.model.Region} interface instead.
059             */
060            public static final String TABLE_NAME = "Region";
061            public static final Object[][] TABLE_COLUMNS = {
062                            { "regionId", Types.BIGINT },
063                            { "countryId", Types.BIGINT },
064                            { "regionCode", Types.VARCHAR },
065                            { "name", Types.VARCHAR },
066                            { "active_", Types.BOOLEAN }
067                    };
068            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)";
069            public static final String TABLE_SQL_DROP = "drop table Region";
070            public static final String ORDER_BY_JPQL = " ORDER BY region.name ASC";
071            public static final String ORDER_BY_SQL = " ORDER BY Region.name ASC";
072            public static final String DATA_SOURCE = "liferayDataSource";
073            public static final String SESSION_FACTORY = "liferaySessionFactory";
074            public static final String TX_MANAGER = "liferayTransactionManager";
075            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
076                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Region"),
077                            true);
078            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Region"),
080                            true);
081            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.Region"),
083                            true);
084            public static long ACTIVE_COLUMN_BITMASK = 1L;
085            public static long COUNTRYID_COLUMN_BITMASK = 2L;
086    
087            /**
088             * Converts the soap model instance into a normal model instance.
089             *
090             * @param soapModel the soap model instance to convert
091             * @return the normal model instance
092             */
093            public static Region toModel(RegionSoap soapModel) {
094                    Region model = new RegionImpl();
095    
096                    model.setRegionId(soapModel.getRegionId());
097                    model.setCountryId(soapModel.getCountryId());
098                    model.setRegionCode(soapModel.getRegionCode());
099                    model.setName(soapModel.getName());
100                    model.setActive(soapModel.getActive());
101    
102                    return model;
103            }
104    
105            /**
106             * Converts the soap model instances into normal model instances.
107             *
108             * @param soapModels the soap model instances to convert
109             * @return the normal model instances
110             */
111            public static List<Region> toModels(RegionSoap[] soapModels) {
112                    List<Region> models = new ArrayList<Region>(soapModels.length);
113    
114                    for (RegionSoap soapModel : soapModels) {
115                            models.add(toModel(soapModel));
116                    }
117    
118                    return models;
119            }
120    
121            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
122                                    "lock.expiration.time.com.liferay.portal.model.Region"));
123    
124            public RegionModelImpl() {
125            }
126    
127            public long getPrimaryKey() {
128                    return _regionId;
129            }
130    
131            public void setPrimaryKey(long primaryKey) {
132                    setRegionId(primaryKey);
133            }
134    
135            public Serializable getPrimaryKeyObj() {
136                    return new Long(_regionId);
137            }
138    
139            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
140                    setPrimaryKey(((Long)primaryKeyObj).longValue());
141            }
142    
143            public Class<?> getModelClass() {
144                    return Region.class;
145            }
146    
147            public String getModelClassName() {
148                    return Region.class.getName();
149            }
150    
151            @JSON
152            public long getRegionId() {
153                    return _regionId;
154            }
155    
156            public void setRegionId(long regionId) {
157                    _regionId = regionId;
158            }
159    
160            @JSON
161            public long getCountryId() {
162                    return _countryId;
163            }
164    
165            public void setCountryId(long countryId) {
166                    _columnBitmask |= COUNTRYID_COLUMN_BITMASK;
167    
168                    if (!_setOriginalCountryId) {
169                            _setOriginalCountryId = true;
170    
171                            _originalCountryId = _countryId;
172                    }
173    
174                    _countryId = countryId;
175            }
176    
177            public long getOriginalCountryId() {
178                    return _originalCountryId;
179            }
180    
181            @JSON
182            public String getRegionCode() {
183                    if (_regionCode == null) {
184                            return StringPool.BLANK;
185                    }
186                    else {
187                            return _regionCode;
188                    }
189            }
190    
191            public void setRegionCode(String regionCode) {
192                    _regionCode = regionCode;
193            }
194    
195            @JSON
196            public String getName() {
197                    if (_name == null) {
198                            return StringPool.BLANK;
199                    }
200                    else {
201                            return _name;
202                    }
203            }
204    
205            public void setName(String name) {
206                    _name = name;
207            }
208    
209            @JSON
210            public boolean getActive() {
211                    return _active;
212            }
213    
214            public boolean isActive() {
215                    return _active;
216            }
217    
218            public void setActive(boolean active) {
219                    _columnBitmask |= ACTIVE_COLUMN_BITMASK;
220    
221                    if (!_setOriginalActive) {
222                            _setOriginalActive = true;
223    
224                            _originalActive = _active;
225                    }
226    
227                    _active = active;
228            }
229    
230            public boolean getOriginalActive() {
231                    return _originalActive;
232            }
233    
234            public long getColumnBitmask() {
235                    return _columnBitmask;
236            }
237    
238            @Override
239            public Region toEscapedModel() {
240                    if (_escapedModelProxy == null) {
241                            _escapedModelProxy = (Region)ProxyUtil.newProxyInstance(_classLoader,
242                                            _escapedModelProxyInterfaces,
243                                            new AutoEscapeBeanHandler(this));
244                    }
245    
246                    return _escapedModelProxy;
247            }
248    
249            @Override
250            public ExpandoBridge getExpandoBridge() {
251                    if (_expandoBridge == null) {
252                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
253                                            Region.class.getName(), getPrimaryKey());
254                    }
255    
256                    return _expandoBridge;
257            }
258    
259            @Override
260            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
261                    getExpandoBridge().setAttributes(serviceContext);
262            }
263    
264            @Override
265            public Object clone() {
266                    RegionImpl regionImpl = new RegionImpl();
267    
268                    regionImpl.setRegionId(getRegionId());
269                    regionImpl.setCountryId(getCountryId());
270                    regionImpl.setRegionCode(getRegionCode());
271                    regionImpl.setName(getName());
272                    regionImpl.setActive(getActive());
273    
274                    regionImpl.resetOriginalValues();
275    
276                    return regionImpl;
277            }
278    
279            public int compareTo(Region region) {
280                    int value = 0;
281    
282                    value = getName().compareTo(region.getName());
283    
284                    if (value != 0) {
285                            return value;
286                    }
287    
288                    return 0;
289            }
290    
291            @Override
292            public boolean equals(Object obj) {
293                    if (obj == null) {
294                            return false;
295                    }
296    
297                    Region region = null;
298    
299                    try {
300                            region = (Region)obj;
301                    }
302                    catch (ClassCastException cce) {
303                            return false;
304                    }
305    
306                    long primaryKey = region.getPrimaryKey();
307    
308                    if (getPrimaryKey() == primaryKey) {
309                            return true;
310                    }
311                    else {
312                            return false;
313                    }
314            }
315    
316            @Override
317            public int hashCode() {
318                    return (int)getPrimaryKey();
319            }
320    
321            @Override
322            public void resetOriginalValues() {
323                    RegionModelImpl regionModelImpl = this;
324    
325                    regionModelImpl._originalCountryId = regionModelImpl._countryId;
326    
327                    regionModelImpl._setOriginalCountryId = false;
328    
329                    regionModelImpl._originalActive = regionModelImpl._active;
330    
331                    regionModelImpl._setOriginalActive = false;
332    
333                    regionModelImpl._columnBitmask = 0;
334            }
335    
336            @Override
337            public CacheModel<Region> toCacheModel() {
338                    RegionCacheModel regionCacheModel = new RegionCacheModel();
339    
340                    regionCacheModel.regionId = getRegionId();
341    
342                    regionCacheModel.countryId = getCountryId();
343    
344                    regionCacheModel.regionCode = getRegionCode();
345    
346                    String regionCode = regionCacheModel.regionCode;
347    
348                    if ((regionCode != null) && (regionCode.length() == 0)) {
349                            regionCacheModel.regionCode = null;
350                    }
351    
352                    regionCacheModel.name = getName();
353    
354                    String name = regionCacheModel.name;
355    
356                    if ((name != null) && (name.length() == 0)) {
357                            regionCacheModel.name = null;
358                    }
359    
360                    regionCacheModel.active = getActive();
361    
362                    return regionCacheModel;
363            }
364    
365            @Override
366            public String toString() {
367                    StringBundler sb = new StringBundler(11);
368    
369                    sb.append("{regionId=");
370                    sb.append(getRegionId());
371                    sb.append(", countryId=");
372                    sb.append(getCountryId());
373                    sb.append(", regionCode=");
374                    sb.append(getRegionCode());
375                    sb.append(", name=");
376                    sb.append(getName());
377                    sb.append(", active=");
378                    sb.append(getActive());
379                    sb.append("}");
380    
381                    return sb.toString();
382            }
383    
384            public String toXmlString() {
385                    StringBundler sb = new StringBundler(19);
386    
387                    sb.append("<model><model-name>");
388                    sb.append("com.liferay.portal.model.Region");
389                    sb.append("</model-name>");
390    
391                    sb.append(
392                            "<column><column-name>regionId</column-name><column-value><![CDATA[");
393                    sb.append(getRegionId());
394                    sb.append("]]></column-value></column>");
395                    sb.append(
396                            "<column><column-name>countryId</column-name><column-value><![CDATA[");
397                    sb.append(getCountryId());
398                    sb.append("]]></column-value></column>");
399                    sb.append(
400                            "<column><column-name>regionCode</column-name><column-value><![CDATA[");
401                    sb.append(getRegionCode());
402                    sb.append("]]></column-value></column>");
403                    sb.append(
404                            "<column><column-name>name</column-name><column-value><![CDATA[");
405                    sb.append(getName());
406                    sb.append("]]></column-value></column>");
407                    sb.append(
408                            "<column><column-name>active</column-name><column-value><![CDATA[");
409                    sb.append(getActive());
410                    sb.append("]]></column-value></column>");
411    
412                    sb.append("</model>");
413    
414                    return sb.toString();
415            }
416    
417            private static ClassLoader _classLoader = Region.class.getClassLoader();
418            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
419                            Region.class
420                    };
421            private long _regionId;
422            private long _countryId;
423            private long _originalCountryId;
424            private boolean _setOriginalCountryId;
425            private String _regionCode;
426            private String _name;
427            private boolean _active;
428            private boolean _originalActive;
429            private boolean _setOriginalActive;
430            private transient ExpandoBridge _expandoBridge;
431            private long _columnBitmask;
432            private Region _escapedModelProxy;
433    }