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