001    /**
002     * Copyright (c) 2000-2012 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.Country;
025    import com.liferay.portal.model.CountryModel;
026    import com.liferay.portal.model.CountrySoap;
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.List;
038    
039    /**
040     * The base model implementation for the Country service. Represents a row in the "Country" database table, with each column mapped to a property of this class.
041     *
042     * <p>
043     * This implementation and its corresponding interface {@link com.liferay.portal.model.CountryModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link CountryImpl}.
044     * </p>
045     *
046     * @author Brian Wing Shun Chan
047     * @see CountryImpl
048     * @see com.liferay.portal.model.Country
049     * @see com.liferay.portal.model.CountryModel
050     * @generated
051     */
052    @JSON(strict = true)
053    public class CountryModelImpl extends BaseModelImpl<Country>
054            implements CountryModel {
055            /*
056             * NOTE FOR DEVELOPERS:
057             *
058             * Never modify or reference this class directly. All methods that expect a country model instance should use the {@link com.liferay.portal.model.Country} interface instead.
059             */
060            public static final String TABLE_NAME = "Country";
061            public static final Object[][] TABLE_COLUMNS = {
062                            { "countryId", Types.BIGINT },
063                            { "name", Types.VARCHAR },
064                            { "a2", Types.VARCHAR },
065                            { "a3", Types.VARCHAR },
066                            { "number_", Types.VARCHAR },
067                            { "idd_", Types.VARCHAR },
068                            { "zipRequired", Types.BOOLEAN },
069                            { "active_", Types.BOOLEAN }
070                    };
071            public static final String TABLE_SQL_CREATE = "create table Country (countryId LONG not null primary key,name VARCHAR(75) null,a2 VARCHAR(75) null,a3 VARCHAR(75) null,number_ VARCHAR(75) null,idd_ VARCHAR(75) null,zipRequired BOOLEAN,active_ BOOLEAN)";
072            public static final String TABLE_SQL_DROP = "drop table Country";
073            public static final String ORDER_BY_JPQL = " ORDER BY country.name ASC";
074            public static final String ORDER_BY_SQL = " ORDER BY Country.name ASC";
075            public static final String DATA_SOURCE = "liferayDataSource";
076            public static final String SESSION_FACTORY = "liferaySessionFactory";
077            public static final String TX_MANAGER = "liferayTransactionManager";
078            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Country"),
080                            true);
081            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Country"),
083                            true);
084            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
085                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.Country"),
086                            true);
087            public static long A2_COLUMN_BITMASK = 1L;
088            public static long A3_COLUMN_BITMASK = 2L;
089            public static long ACTIVE_COLUMN_BITMASK = 4L;
090            public static long NAME_COLUMN_BITMASK = 8L;
091    
092            /**
093             * Converts the soap model instance into a normal model instance.
094             *
095             * @param soapModel the soap model instance to convert
096             * @return the normal model instance
097             */
098            public static Country toModel(CountrySoap soapModel) {
099                    Country model = new CountryImpl();
100    
101                    model.setCountryId(soapModel.getCountryId());
102                    model.setName(soapModel.getName());
103                    model.setA2(soapModel.getA2());
104                    model.setA3(soapModel.getA3());
105                    model.setNumber(soapModel.getNumber());
106                    model.setIdd(soapModel.getIdd());
107                    model.setZipRequired(soapModel.getZipRequired());
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<Country> toModels(CountrySoap[] soapModels) {
120                    List<Country> models = new ArrayList<Country>(soapModels.length);
121    
122                    for (CountrySoap soapModel : soapModels) {
123                            models.add(toModel(soapModel));
124                    }
125    
126                    return models;
127            }
128    
129            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
130                                    "lock.expiration.time.com.liferay.portal.model.Country"));
131    
132            public CountryModelImpl() {
133            }
134    
135            public long getPrimaryKey() {
136                    return _countryId;
137            }
138    
139            public void setPrimaryKey(long primaryKey) {
140                    setCountryId(primaryKey);
141            }
142    
143            public Serializable getPrimaryKeyObj() {
144                    return new Long(_countryId);
145            }
146    
147            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
148                    setPrimaryKey(((Long)primaryKeyObj).longValue());
149            }
150    
151            public Class<?> getModelClass() {
152                    return Country.class;
153            }
154    
155            public String getModelClassName() {
156                    return Country.class.getName();
157            }
158    
159            @JSON
160            public long getCountryId() {
161                    return _countryId;
162            }
163    
164            public void setCountryId(long countryId) {
165                    _countryId = countryId;
166            }
167    
168            @JSON
169            public String getName() {
170                    if (_name == null) {
171                            return StringPool.BLANK;
172                    }
173                    else {
174                            return _name;
175                    }
176            }
177    
178            public void setName(String name) {
179                    _columnBitmask = -1L;
180    
181                    if (_originalName == null) {
182                            _originalName = _name;
183                    }
184    
185                    _name = name;
186            }
187    
188            public String getOriginalName() {
189                    return GetterUtil.getString(_originalName);
190            }
191    
192            @JSON
193            public String getA2() {
194                    if (_a2 == null) {
195                            return StringPool.BLANK;
196                    }
197                    else {
198                            return _a2;
199                    }
200            }
201    
202            public void setA2(String a2) {
203                    _columnBitmask |= A2_COLUMN_BITMASK;
204    
205                    if (_originalA2 == null) {
206                            _originalA2 = _a2;
207                    }
208    
209                    _a2 = a2;
210            }
211    
212            public String getOriginalA2() {
213                    return GetterUtil.getString(_originalA2);
214            }
215    
216            @JSON
217            public String getA3() {
218                    if (_a3 == null) {
219                            return StringPool.BLANK;
220                    }
221                    else {
222                            return _a3;
223                    }
224            }
225    
226            public void setA3(String a3) {
227                    _columnBitmask |= A3_COLUMN_BITMASK;
228    
229                    if (_originalA3 == null) {
230                            _originalA3 = _a3;
231                    }
232    
233                    _a3 = a3;
234            }
235    
236            public String getOriginalA3() {
237                    return GetterUtil.getString(_originalA3);
238            }
239    
240            @JSON
241            public String getNumber() {
242                    if (_number == null) {
243                            return StringPool.BLANK;
244                    }
245                    else {
246                            return _number;
247                    }
248            }
249    
250            public void setNumber(String number) {
251                    _number = number;
252            }
253    
254            @JSON
255            public String getIdd() {
256                    if (_idd == null) {
257                            return StringPool.BLANK;
258                    }
259                    else {
260                            return _idd;
261                    }
262            }
263    
264            public void setIdd(String idd) {
265                    _idd = idd;
266            }
267    
268            @JSON
269            public boolean getZipRequired() {
270                    return _zipRequired;
271            }
272    
273            public boolean isZipRequired() {
274                    return _zipRequired;
275            }
276    
277            public void setZipRequired(boolean zipRequired) {
278                    _zipRequired = zipRequired;
279            }
280    
281            @JSON
282            public boolean getActive() {
283                    return _active;
284            }
285    
286            public boolean isActive() {
287                    return _active;
288            }
289    
290            public void setActive(boolean active) {
291                    _columnBitmask |= ACTIVE_COLUMN_BITMASK;
292    
293                    if (!_setOriginalActive) {
294                            _setOriginalActive = true;
295    
296                            _originalActive = _active;
297                    }
298    
299                    _active = active;
300            }
301    
302            public boolean getOriginalActive() {
303                    return _originalActive;
304            }
305    
306            public long getColumnBitmask() {
307                    return _columnBitmask;
308            }
309    
310            @Override
311            public Country toEscapedModel() {
312                    if (_escapedModelProxy == null) {
313                            _escapedModelProxy = (Country)ProxyUtil.newProxyInstance(_classLoader,
314                                            _escapedModelProxyInterfaces,
315                                            new AutoEscapeBeanHandler(this));
316                    }
317    
318                    return _escapedModelProxy;
319            }
320    
321            @Override
322            public ExpandoBridge getExpandoBridge() {
323                    if (_expandoBridge == null) {
324                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
325                                            Country.class.getName(), getPrimaryKey());
326                    }
327    
328                    return _expandoBridge;
329            }
330    
331            @Override
332            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
333                    getExpandoBridge().setAttributes(serviceContext);
334            }
335    
336            @Override
337            public Object clone() {
338                    CountryImpl countryImpl = new CountryImpl();
339    
340                    countryImpl.setCountryId(getCountryId());
341                    countryImpl.setName(getName());
342                    countryImpl.setA2(getA2());
343                    countryImpl.setA3(getA3());
344                    countryImpl.setNumber(getNumber());
345                    countryImpl.setIdd(getIdd());
346                    countryImpl.setZipRequired(getZipRequired());
347                    countryImpl.setActive(getActive());
348    
349                    countryImpl.resetOriginalValues();
350    
351                    return countryImpl;
352            }
353    
354            public int compareTo(Country country) {
355                    int value = 0;
356    
357                    value = getName().compareTo(country.getName());
358    
359                    if (value != 0) {
360                            return value;
361                    }
362    
363                    return 0;
364            }
365    
366            @Override
367            public boolean equals(Object obj) {
368                    if (obj == null) {
369                            return false;
370                    }
371    
372                    Country country = null;
373    
374                    try {
375                            country = (Country)obj;
376                    }
377                    catch (ClassCastException cce) {
378                            return false;
379                    }
380    
381                    long primaryKey = country.getPrimaryKey();
382    
383                    if (getPrimaryKey() == primaryKey) {
384                            return true;
385                    }
386                    else {
387                            return false;
388                    }
389            }
390    
391            @Override
392            public int hashCode() {
393                    return (int)getPrimaryKey();
394            }
395    
396            @Override
397            public void resetOriginalValues() {
398                    CountryModelImpl countryModelImpl = this;
399    
400                    countryModelImpl._originalName = countryModelImpl._name;
401    
402                    countryModelImpl._originalA2 = countryModelImpl._a2;
403    
404                    countryModelImpl._originalA3 = countryModelImpl._a3;
405    
406                    countryModelImpl._originalActive = countryModelImpl._active;
407    
408                    countryModelImpl._setOriginalActive = false;
409    
410                    countryModelImpl._columnBitmask = 0;
411            }
412    
413            @Override
414            public CacheModel<Country> toCacheModel() {
415                    CountryCacheModel countryCacheModel = new CountryCacheModel();
416    
417                    countryCacheModel.countryId = getCountryId();
418    
419                    countryCacheModel.name = getName();
420    
421                    String name = countryCacheModel.name;
422    
423                    if ((name != null) && (name.length() == 0)) {
424                            countryCacheModel.name = null;
425                    }
426    
427                    countryCacheModel.a2 = getA2();
428    
429                    String a2 = countryCacheModel.a2;
430    
431                    if ((a2 != null) && (a2.length() == 0)) {
432                            countryCacheModel.a2 = null;
433                    }
434    
435                    countryCacheModel.a3 = getA3();
436    
437                    String a3 = countryCacheModel.a3;
438    
439                    if ((a3 != null) && (a3.length() == 0)) {
440                            countryCacheModel.a3 = null;
441                    }
442    
443                    countryCacheModel.number = getNumber();
444    
445                    String number = countryCacheModel.number;
446    
447                    if ((number != null) && (number.length() == 0)) {
448                            countryCacheModel.number = null;
449                    }
450    
451                    countryCacheModel.idd = getIdd();
452    
453                    String idd = countryCacheModel.idd;
454    
455                    if ((idd != null) && (idd.length() == 0)) {
456                            countryCacheModel.idd = null;
457                    }
458    
459                    countryCacheModel.zipRequired = getZipRequired();
460    
461                    countryCacheModel.active = getActive();
462    
463                    return countryCacheModel;
464            }
465    
466            @Override
467            public String toString() {
468                    StringBundler sb = new StringBundler(17);
469    
470                    sb.append("{countryId=");
471                    sb.append(getCountryId());
472                    sb.append(", name=");
473                    sb.append(getName());
474                    sb.append(", a2=");
475                    sb.append(getA2());
476                    sb.append(", a3=");
477                    sb.append(getA3());
478                    sb.append(", number=");
479                    sb.append(getNumber());
480                    sb.append(", idd=");
481                    sb.append(getIdd());
482                    sb.append(", zipRequired=");
483                    sb.append(getZipRequired());
484                    sb.append(", active=");
485                    sb.append(getActive());
486                    sb.append("}");
487    
488                    return sb.toString();
489            }
490    
491            public String toXmlString() {
492                    StringBundler sb = new StringBundler(28);
493    
494                    sb.append("<model><model-name>");
495                    sb.append("com.liferay.portal.model.Country");
496                    sb.append("</model-name>");
497    
498                    sb.append(
499                            "<column><column-name>countryId</column-name><column-value><![CDATA[");
500                    sb.append(getCountryId());
501                    sb.append("]]></column-value></column>");
502                    sb.append(
503                            "<column><column-name>name</column-name><column-value><![CDATA[");
504                    sb.append(getName());
505                    sb.append("]]></column-value></column>");
506                    sb.append(
507                            "<column><column-name>a2</column-name><column-value><![CDATA[");
508                    sb.append(getA2());
509                    sb.append("]]></column-value></column>");
510                    sb.append(
511                            "<column><column-name>a3</column-name><column-value><![CDATA[");
512                    sb.append(getA3());
513                    sb.append("]]></column-value></column>");
514                    sb.append(
515                            "<column><column-name>number</column-name><column-value><![CDATA[");
516                    sb.append(getNumber());
517                    sb.append("]]></column-value></column>");
518                    sb.append(
519                            "<column><column-name>idd</column-name><column-value><![CDATA[");
520                    sb.append(getIdd());
521                    sb.append("]]></column-value></column>");
522                    sb.append(
523                            "<column><column-name>zipRequired</column-name><column-value><![CDATA[");
524                    sb.append(getZipRequired());
525                    sb.append("]]></column-value></column>");
526                    sb.append(
527                            "<column><column-name>active</column-name><column-value><![CDATA[");
528                    sb.append(getActive());
529                    sb.append("]]></column-value></column>");
530    
531                    sb.append("</model>");
532    
533                    return sb.toString();
534            }
535    
536            private static ClassLoader _classLoader = Country.class.getClassLoader();
537            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
538                            Country.class
539                    };
540            private long _countryId;
541            private String _name;
542            private String _originalName;
543            private String _a2;
544            private String _originalA2;
545            private String _a3;
546            private String _originalA3;
547            private String _number;
548            private String _idd;
549            private boolean _zipRequired;
550            private boolean _active;
551            private boolean _originalActive;
552            private boolean _setOriginalActive;
553            private transient ExpandoBridge _expandoBridge;
554            private long _columnBitmask;
555            private Country _escapedModelProxy;
556    }