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