001    /**
002     * Copyright (c) 2000-2013 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.HashMap;
038    import java.util.List;
039    import java.util.Map;
040    
041    /**
042     * 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.
043     *
044     * <p>
045     * 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}.
046     * </p>
047     *
048     * @author Brian Wing Shun Chan
049     * @see RegionImpl
050     * @see com.liferay.portal.model.Region
051     * @see com.liferay.portal.model.RegionModel
052     * @generated
053     */
054    @JSON(strict = true)
055    public class RegionModelImpl extends BaseModelImpl<Region>
056            implements RegionModel {
057            /*
058             * NOTE FOR DEVELOPERS:
059             *
060             * 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.
061             */
062            public static final String TABLE_NAME = "Region";
063            public static final Object[][] TABLE_COLUMNS = {
064                            { "regionId", Types.BIGINT },
065                            { "countryId", Types.BIGINT },
066                            { "regionCode", Types.VARCHAR },
067                            { "name", Types.VARCHAR },
068                            { "active_", Types.BOOLEAN }
069                    };
070            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)";
071            public static final String TABLE_SQL_DROP = "drop table Region";
072            public static final String ORDER_BY_JPQL = " ORDER BY region.name ASC";
073            public static final String ORDER_BY_SQL = " ORDER BY Region.name ASC";
074            public static final String DATA_SOURCE = "liferayDataSource";
075            public static final String SESSION_FACTORY = "liferaySessionFactory";
076            public static final String TX_MANAGER = "liferayTransactionManager";
077            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
078                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Region"),
079                            true);
080            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
081                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Region"),
082                            true);
083            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
084                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.Region"),
085                            true);
086            public static long ACTIVE_COLUMN_BITMASK = 1L;
087            public static long COUNTRYID_COLUMN_BITMASK = 2L;
088            public static long REGIONCODE_COLUMN_BITMASK = 4L;
089    
090            /**
091             * Converts the soap model instance into a normal model instance.
092             *
093             * @param soapModel the soap model instance to convert
094             * @return the normal model instance
095             */
096            public static Region toModel(RegionSoap soapModel) {
097                    if (soapModel == null) {
098                            return null;
099                    }
100    
101                    Region model = new RegionImpl();
102    
103                    model.setRegionId(soapModel.getRegionId());
104                    model.setCountryId(soapModel.getCountryId());
105                    model.setRegionCode(soapModel.getRegionCode());
106                    model.setName(soapModel.getName());
107                    model.setActive(soapModel.getActive());
108    
109                    return model;
110            }
111    
112            /**
113             * Converts the soap model instances into normal model instances.
114             *
115             * @param soapModels the soap model instances to convert
116             * @return the normal model instances
117             */
118            public static List<Region> toModels(RegionSoap[] soapModels) {
119                    if (soapModels == null) {
120                            return null;
121                    }
122    
123                    List<Region> models = new ArrayList<Region>(soapModels.length);
124    
125                    for (RegionSoap soapModel : soapModels) {
126                            models.add(toModel(soapModel));
127                    }
128    
129                    return models;
130            }
131    
132            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
133                                    "lock.expiration.time.com.liferay.portal.model.Region"));
134    
135            public RegionModelImpl() {
136            }
137    
138            public long getPrimaryKey() {
139                    return _regionId;
140            }
141    
142            public void setPrimaryKey(long primaryKey) {
143                    setRegionId(primaryKey);
144            }
145    
146            public Serializable getPrimaryKeyObj() {
147                    return new Long(_regionId);
148            }
149    
150            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
151                    setPrimaryKey(((Long)primaryKeyObj).longValue());
152            }
153    
154            public Class<?> getModelClass() {
155                    return Region.class;
156            }
157    
158            public String getModelClassName() {
159                    return Region.class.getName();
160            }
161    
162            @Override
163            public Map<String, Object> getModelAttributes() {
164                    Map<String, Object> attributes = new HashMap<String, Object>();
165    
166                    attributes.put("regionId", getRegionId());
167                    attributes.put("countryId", getCountryId());
168                    attributes.put("regionCode", getRegionCode());
169                    attributes.put("name", getName());
170                    attributes.put("active", getActive());
171    
172                    return attributes;
173            }
174    
175            @Override
176            public void setModelAttributes(Map<String, Object> attributes) {
177                    Long regionId = (Long)attributes.get("regionId");
178    
179                    if (regionId != null) {
180                            setRegionId(regionId);
181                    }
182    
183                    Long countryId = (Long)attributes.get("countryId");
184    
185                    if (countryId != null) {
186                            setCountryId(countryId);
187                    }
188    
189                    String regionCode = (String)attributes.get("regionCode");
190    
191                    if (regionCode != null) {
192                            setRegionCode(regionCode);
193                    }
194    
195                    String name = (String)attributes.get("name");
196    
197                    if (name != null) {
198                            setName(name);
199                    }
200    
201                    Boolean active = (Boolean)attributes.get("active");
202    
203                    if (active != null) {
204                            setActive(active);
205                    }
206            }
207    
208            @JSON
209            public long getRegionId() {
210                    return _regionId;
211            }
212    
213            public void setRegionId(long regionId) {
214                    _regionId = regionId;
215            }
216    
217            @JSON
218            public long getCountryId() {
219                    return _countryId;
220            }
221    
222            public void setCountryId(long countryId) {
223                    _columnBitmask |= COUNTRYID_COLUMN_BITMASK;
224    
225                    if (!_setOriginalCountryId) {
226                            _setOriginalCountryId = true;
227    
228                            _originalCountryId = _countryId;
229                    }
230    
231                    _countryId = countryId;
232            }
233    
234            public long getOriginalCountryId() {
235                    return _originalCountryId;
236            }
237    
238            @JSON
239            public String getRegionCode() {
240                    if (_regionCode == null) {
241                            return StringPool.BLANK;
242                    }
243                    else {
244                            return _regionCode;
245                    }
246            }
247    
248            public void setRegionCode(String regionCode) {
249                    _columnBitmask |= REGIONCODE_COLUMN_BITMASK;
250    
251                    if (_originalRegionCode == null) {
252                            _originalRegionCode = _regionCode;
253                    }
254    
255                    _regionCode = regionCode;
256            }
257    
258            public String getOriginalRegionCode() {
259                    return GetterUtil.getString(_originalRegionCode);
260            }
261    
262            @JSON
263            public String getName() {
264                    if (_name == null) {
265                            return StringPool.BLANK;
266                    }
267                    else {
268                            return _name;
269                    }
270            }
271    
272            public void setName(String name) {
273                    _columnBitmask = -1L;
274    
275                    _name = name;
276            }
277    
278            @JSON
279            public boolean getActive() {
280                    return _active;
281            }
282    
283            public boolean isActive() {
284                    return _active;
285            }
286    
287            public void setActive(boolean active) {
288                    _columnBitmask |= ACTIVE_COLUMN_BITMASK;
289    
290                    if (!_setOriginalActive) {
291                            _setOriginalActive = true;
292    
293                            _originalActive = _active;
294                    }
295    
296                    _active = active;
297            }
298    
299            public boolean getOriginalActive() {
300                    return _originalActive;
301            }
302    
303            public long getColumnBitmask() {
304                    return _columnBitmask;
305            }
306    
307            @Override
308            public ExpandoBridge getExpandoBridge() {
309                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
310                            Region.class.getName(), getPrimaryKey());
311            }
312    
313            @Override
314            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
315                    ExpandoBridge expandoBridge = getExpandoBridge();
316    
317                    expandoBridge.setAttributes(serviceContext);
318            }
319    
320            @Override
321            public Region toEscapedModel() {
322                    if (_escapedModel == null) {
323                            _escapedModel = (Region)ProxyUtil.newProxyInstance(_classLoader,
324                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
325                    }
326    
327                    return _escapedModel;
328            }
329    
330            public Region toUnescapedModel() {
331                    return (Region)this;
332            }
333    
334            @Override
335            public Object clone() {
336                    RegionImpl regionImpl = new RegionImpl();
337    
338                    regionImpl.setRegionId(getRegionId());
339                    regionImpl.setCountryId(getCountryId());
340                    regionImpl.setRegionCode(getRegionCode());
341                    regionImpl.setName(getName());
342                    regionImpl.setActive(getActive());
343    
344                    regionImpl.resetOriginalValues();
345    
346                    return regionImpl;
347            }
348    
349            public int compareTo(Region region) {
350                    int value = 0;
351    
352                    value = getName().compareTo(region.getName());
353    
354                    if (value != 0) {
355                            return value;
356                    }
357    
358                    return 0;
359            }
360    
361            @Override
362            public boolean equals(Object obj) {
363                    if (this == obj) {
364                            return true;
365                    }
366    
367                    if (!(obj instanceof Region)) {
368                            return false;
369                    }
370    
371                    Region region = (Region)obj;
372    
373                    long primaryKey = region.getPrimaryKey();
374    
375                    if (getPrimaryKey() == primaryKey) {
376                            return true;
377                    }
378                    else {
379                            return false;
380                    }
381            }
382    
383            @Override
384            public int hashCode() {
385                    return (int)getPrimaryKey();
386            }
387    
388            @Override
389            public void resetOriginalValues() {
390                    RegionModelImpl regionModelImpl = this;
391    
392                    regionModelImpl._originalCountryId = regionModelImpl._countryId;
393    
394                    regionModelImpl._setOriginalCountryId = false;
395    
396                    regionModelImpl._originalRegionCode = regionModelImpl._regionCode;
397    
398                    regionModelImpl._originalActive = regionModelImpl._active;
399    
400                    regionModelImpl._setOriginalActive = false;
401    
402                    regionModelImpl._columnBitmask = 0;
403            }
404    
405            @Override
406            public CacheModel<Region> toCacheModel() {
407                    RegionCacheModel regionCacheModel = new RegionCacheModel();
408    
409                    regionCacheModel.regionId = getRegionId();
410    
411                    regionCacheModel.countryId = getCountryId();
412    
413                    regionCacheModel.regionCode = getRegionCode();
414    
415                    String regionCode = regionCacheModel.regionCode;
416    
417                    if ((regionCode != null) && (regionCode.length() == 0)) {
418                            regionCacheModel.regionCode = null;
419                    }
420    
421                    regionCacheModel.name = getName();
422    
423                    String name = regionCacheModel.name;
424    
425                    if ((name != null) && (name.length() == 0)) {
426                            regionCacheModel.name = null;
427                    }
428    
429                    regionCacheModel.active = getActive();
430    
431                    return regionCacheModel;
432            }
433    
434            @Override
435            public String toString() {
436                    StringBundler sb = new StringBundler(11);
437    
438                    sb.append("{regionId=");
439                    sb.append(getRegionId());
440                    sb.append(", countryId=");
441                    sb.append(getCountryId());
442                    sb.append(", regionCode=");
443                    sb.append(getRegionCode());
444                    sb.append(", name=");
445                    sb.append(getName());
446                    sb.append(", active=");
447                    sb.append(getActive());
448                    sb.append("}");
449    
450                    return sb.toString();
451            }
452    
453            public String toXmlString() {
454                    StringBundler sb = new StringBundler(19);
455    
456                    sb.append("<model><model-name>");
457                    sb.append("com.liferay.portal.model.Region");
458                    sb.append("</model-name>");
459    
460                    sb.append(
461                            "<column><column-name>regionId</column-name><column-value><![CDATA[");
462                    sb.append(getRegionId());
463                    sb.append("]]></column-value></column>");
464                    sb.append(
465                            "<column><column-name>countryId</column-name><column-value><![CDATA[");
466                    sb.append(getCountryId());
467                    sb.append("]]></column-value></column>");
468                    sb.append(
469                            "<column><column-name>regionCode</column-name><column-value><![CDATA[");
470                    sb.append(getRegionCode());
471                    sb.append("]]></column-value></column>");
472                    sb.append(
473                            "<column><column-name>name</column-name><column-value><![CDATA[");
474                    sb.append(getName());
475                    sb.append("]]></column-value></column>");
476                    sb.append(
477                            "<column><column-name>active</column-name><column-value><![CDATA[");
478                    sb.append(getActive());
479                    sb.append("]]></column-value></column>");
480    
481                    sb.append("</model>");
482    
483                    return sb.toString();
484            }
485    
486            private static ClassLoader _classLoader = Region.class.getClassLoader();
487            private static Class<?>[] _escapedModelInterfaces = new Class[] { Region.class };
488            private long _regionId;
489            private long _countryId;
490            private long _originalCountryId;
491            private boolean _setOriginalCountryId;
492            private String _regionCode;
493            private String _originalRegionCode;
494            private String _name;
495            private boolean _active;
496            private boolean _originalActive;
497            private boolean _setOriginalActive;
498            private long _columnBitmask;
499            private Region _escapedModel;
500    }