001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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                    _columnBitmask = -1L;
207    
208                    _name = name;
209            }
210    
211            @JSON
212            public boolean getActive() {
213                    return _active;
214            }
215    
216            public boolean isActive() {
217                    return _active;
218            }
219    
220            public void setActive(boolean active) {
221                    _columnBitmask |= ACTIVE_COLUMN_BITMASK;
222    
223                    if (!_setOriginalActive) {
224                            _setOriginalActive = true;
225    
226                            _originalActive = _active;
227                    }
228    
229                    _active = active;
230            }
231    
232            public boolean getOriginalActive() {
233                    return _originalActive;
234            }
235    
236            public long getColumnBitmask() {
237                    return _columnBitmask;
238            }
239    
240            @Override
241            public Region toEscapedModel() {
242                    if (_escapedModelProxy == null) {
243                            _escapedModelProxy = (Region)ProxyUtil.newProxyInstance(_classLoader,
244                                            _escapedModelProxyInterfaces,
245                                            new AutoEscapeBeanHandler(this));
246                    }
247    
248                    return _escapedModelProxy;
249            }
250    
251            @Override
252            public ExpandoBridge getExpandoBridge() {
253                    if (_expandoBridge == null) {
254                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
255                                            Region.class.getName(), getPrimaryKey());
256                    }
257    
258                    return _expandoBridge;
259            }
260    
261            @Override
262            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
263                    getExpandoBridge().setAttributes(serviceContext);
264            }
265    
266            @Override
267            public Object clone() {
268                    RegionImpl regionImpl = new RegionImpl();
269    
270                    regionImpl.setRegionId(getRegionId());
271                    regionImpl.setCountryId(getCountryId());
272                    regionImpl.setRegionCode(getRegionCode());
273                    regionImpl.setName(getName());
274                    regionImpl.setActive(getActive());
275    
276                    regionImpl.resetOriginalValues();
277    
278                    return regionImpl;
279            }
280    
281            public int compareTo(Region region) {
282                    int value = 0;
283    
284                    value = getName().compareTo(region.getName());
285    
286                    if (value != 0) {
287                            return value;
288                    }
289    
290                    return 0;
291            }
292    
293            @Override
294            public boolean equals(Object obj) {
295                    if (obj == null) {
296                            return false;
297                    }
298    
299                    Region region = null;
300    
301                    try {
302                            region = (Region)obj;
303                    }
304                    catch (ClassCastException cce) {
305                            return false;
306                    }
307    
308                    long primaryKey = region.getPrimaryKey();
309    
310                    if (getPrimaryKey() == primaryKey) {
311                            return true;
312                    }
313                    else {
314                            return false;
315                    }
316            }
317    
318            @Override
319            public int hashCode() {
320                    return (int)getPrimaryKey();
321            }
322    
323            @Override
324            public void resetOriginalValues() {
325                    RegionModelImpl regionModelImpl = this;
326    
327                    regionModelImpl._originalCountryId = regionModelImpl._countryId;
328    
329                    regionModelImpl._setOriginalCountryId = false;
330    
331                    regionModelImpl._originalActive = regionModelImpl._active;
332    
333                    regionModelImpl._setOriginalActive = false;
334    
335                    regionModelImpl._columnBitmask = 0;
336            }
337    
338            @Override
339            public CacheModel<Region> toCacheModel() {
340                    RegionCacheModel regionCacheModel = new RegionCacheModel();
341    
342                    regionCacheModel.regionId = getRegionId();
343    
344                    regionCacheModel.countryId = getCountryId();
345    
346                    regionCacheModel.regionCode = getRegionCode();
347    
348                    String regionCode = regionCacheModel.regionCode;
349    
350                    if ((regionCode != null) && (regionCode.length() == 0)) {
351                            regionCacheModel.regionCode = null;
352                    }
353    
354                    regionCacheModel.name = getName();
355    
356                    String name = regionCacheModel.name;
357    
358                    if ((name != null) && (name.length() == 0)) {
359                            regionCacheModel.name = null;
360                    }
361    
362                    regionCacheModel.active = getActive();
363    
364                    return regionCacheModel;
365            }
366    
367            @Override
368            public String toString() {
369                    StringBundler sb = new StringBundler(11);
370    
371                    sb.append("{regionId=");
372                    sb.append(getRegionId());
373                    sb.append(", countryId=");
374                    sb.append(getCountryId());
375                    sb.append(", regionCode=");
376                    sb.append(getRegionCode());
377                    sb.append(", name=");
378                    sb.append(getName());
379                    sb.append(", active=");
380                    sb.append(getActive());
381                    sb.append("}");
382    
383                    return sb.toString();
384            }
385    
386            public String toXmlString() {
387                    StringBundler sb = new StringBundler(19);
388    
389                    sb.append("<model><model-name>");
390                    sb.append("com.liferay.portal.model.Region");
391                    sb.append("</model-name>");
392    
393                    sb.append(
394                            "<column><column-name>regionId</column-name><column-value><![CDATA[");
395                    sb.append(getRegionId());
396                    sb.append("]]></column-value></column>");
397                    sb.append(
398                            "<column><column-name>countryId</column-name><column-value><![CDATA[");
399                    sb.append(getCountryId());
400                    sb.append("]]></column-value></column>");
401                    sb.append(
402                            "<column><column-name>regionCode</column-name><column-value><![CDATA[");
403                    sb.append(getRegionCode());
404                    sb.append("]]></column-value></column>");
405                    sb.append(
406                            "<column><column-name>name</column-name><column-value><![CDATA[");
407                    sb.append(getName());
408                    sb.append("]]></column-value></column>");
409                    sb.append(
410                            "<column><column-name>active</column-name><column-value><![CDATA[");
411                    sb.append(getActive());
412                    sb.append("]]></column-value></column>");
413    
414                    sb.append("</model>");
415    
416                    return sb.toString();
417            }
418    
419            private static ClassLoader _classLoader = Region.class.getClassLoader();
420            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
421                            Region.class
422                    };
423            private long _regionId;
424            private long _countryId;
425            private long _originalCountryId;
426            private boolean _setOriginalCountryId;
427            private String _regionCode;
428            private String _name;
429            private boolean _active;
430            private boolean _originalActive;
431            private boolean _setOriginalActive;
432            private transient ExpandoBridge _expandoBridge;
433            private long _columnBitmask;
434            private Region _escapedModelProxy;
435    }