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