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