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            public long getPrimaryKey() {
140                    return _regionId;
141            }
142    
143            public void setPrimaryKey(long primaryKey) {
144                    setRegionId(primaryKey);
145            }
146    
147            public Serializable getPrimaryKeyObj() {
148                    return _regionId;
149            }
150    
151            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
152                    setPrimaryKey(((Long)primaryKeyObj).longValue());
153            }
154    
155            public Class<?> getModelClass() {
156                    return Region.class;
157            }
158    
159            public String getModelClassName() {
160                    return Region.class.getName();
161            }
162    
163            @Override
164            public Map<String, Object> getModelAttributes() {
165                    Map<String, Object> attributes = new HashMap<String, Object>();
166    
167                    attributes.put("regionId", getRegionId());
168                    attributes.put("countryId", getCountryId());
169                    attributes.put("regionCode", getRegionCode());
170                    attributes.put("name", getName());
171                    attributes.put("active", getActive());
172    
173                    return attributes;
174            }
175    
176            @Override
177            public void setModelAttributes(Map<String, Object> attributes) {
178                    Long regionId = (Long)attributes.get("regionId");
179    
180                    if (regionId != null) {
181                            setRegionId(regionId);
182                    }
183    
184                    Long countryId = (Long)attributes.get("countryId");
185    
186                    if (countryId != null) {
187                            setCountryId(countryId);
188                    }
189    
190                    String regionCode = (String)attributes.get("regionCode");
191    
192                    if (regionCode != null) {
193                            setRegionCode(regionCode);
194                    }
195    
196                    String name = (String)attributes.get("name");
197    
198                    if (name != null) {
199                            setName(name);
200                    }
201    
202                    Boolean active = (Boolean)attributes.get("active");
203    
204                    if (active != null) {
205                            setActive(active);
206                    }
207            }
208    
209            @JSON
210            public long getRegionId() {
211                    return _regionId;
212            }
213    
214            public void setRegionId(long regionId) {
215                    _regionId = regionId;
216            }
217    
218            @JSON
219            public long getCountryId() {
220                    return _countryId;
221            }
222    
223            public void setCountryId(long countryId) {
224                    _columnBitmask |= COUNTRYID_COLUMN_BITMASK;
225    
226                    if (!_setOriginalCountryId) {
227                            _setOriginalCountryId = true;
228    
229                            _originalCountryId = _countryId;
230                    }
231    
232                    _countryId = countryId;
233            }
234    
235            public long getOriginalCountryId() {
236                    return _originalCountryId;
237            }
238    
239            @JSON
240            public String getRegionCode() {
241                    if (_regionCode == null) {
242                            return StringPool.BLANK;
243                    }
244                    else {
245                            return _regionCode;
246                    }
247            }
248    
249            public void setRegionCode(String regionCode) {
250                    _columnBitmask |= REGIONCODE_COLUMN_BITMASK;
251    
252                    if (_originalRegionCode == null) {
253                            _originalRegionCode = _regionCode;
254                    }
255    
256                    _regionCode = regionCode;
257            }
258    
259            public String getOriginalRegionCode() {
260                    return GetterUtil.getString(_originalRegionCode);
261            }
262    
263            @JSON
264            public String getName() {
265                    if (_name == null) {
266                            return StringPool.BLANK;
267                    }
268                    else {
269                            return _name;
270                    }
271            }
272    
273            public void setName(String name) {
274                    _columnBitmask = -1L;
275    
276                    _name = name;
277            }
278    
279            @JSON
280            public boolean getActive() {
281                    return _active;
282            }
283    
284            public boolean isActive() {
285                    return _active;
286            }
287    
288            public void setActive(boolean active) {
289                    _columnBitmask |= ACTIVE_COLUMN_BITMASK;
290    
291                    if (!_setOriginalActive) {
292                            _setOriginalActive = true;
293    
294                            _originalActive = _active;
295                    }
296    
297                    _active = active;
298            }
299    
300            public boolean getOriginalActive() {
301                    return _originalActive;
302            }
303    
304            public long getColumnBitmask() {
305                    return _columnBitmask;
306            }
307    
308            @Override
309            public ExpandoBridge getExpandoBridge() {
310                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
311                            Region.class.getName(), getPrimaryKey());
312            }
313    
314            @Override
315            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
316                    ExpandoBridge expandoBridge = getExpandoBridge();
317    
318                    expandoBridge.setAttributes(serviceContext);
319            }
320    
321            @Override
322            public Region toEscapedModel() {
323                    if (_escapedModel == null) {
324                            _escapedModel = (Region)ProxyUtil.newProxyInstance(_classLoader,
325                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
326                    }
327    
328                    return _escapedModel;
329            }
330    
331            @Override
332            public Object clone() {
333                    RegionImpl regionImpl = new RegionImpl();
334    
335                    regionImpl.setRegionId(getRegionId());
336                    regionImpl.setCountryId(getCountryId());
337                    regionImpl.setRegionCode(getRegionCode());
338                    regionImpl.setName(getName());
339                    regionImpl.setActive(getActive());
340    
341                    regionImpl.resetOriginalValues();
342    
343                    return regionImpl;
344            }
345    
346            public int compareTo(Region region) {
347                    int value = 0;
348    
349                    value = getName().compareTo(region.getName());
350    
351                    if (value != 0) {
352                            return value;
353                    }
354    
355                    return 0;
356            }
357    
358            @Override
359            public boolean equals(Object obj) {
360                    if (obj == null) {
361                            return false;
362                    }
363    
364                    Region region = null;
365    
366                    try {
367                            region = (Region)obj;
368                    }
369                    catch (ClassCastException cce) {
370                            return false;
371                    }
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    }