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.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.HashMap;
038    import java.util.List;
039    import java.util.Map;
040    
041    /**
042     * 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.
043     *
044     * <p>
045     * 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}.
046     * </p>
047     *
048     * @author Brian Wing Shun Chan
049     * @see CountryImpl
050     * @see com.liferay.portal.model.Country
051     * @see com.liferay.portal.model.CountryModel
052     * @generated
053     */
054    @JSON(strict = true)
055    public class CountryModelImpl extends BaseModelImpl<Country>
056            implements CountryModel {
057            /*
058             * NOTE FOR DEVELOPERS:
059             *
060             * 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.
061             */
062            public static final String TABLE_NAME = "Country";
063            public static final Object[][] TABLE_COLUMNS = {
064                            { "countryId", Types.BIGINT },
065                            { "name", Types.VARCHAR },
066                            { "a2", Types.VARCHAR },
067                            { "a3", Types.VARCHAR },
068                            { "number_", Types.VARCHAR },
069                            { "idd_", Types.VARCHAR },
070                            { "zipRequired", Types.BOOLEAN },
071                            { "active_", Types.BOOLEAN }
072                    };
073            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)";
074            public static final String TABLE_SQL_DROP = "drop table Country";
075            public static final String ORDER_BY_JPQL = " ORDER BY country.name ASC";
076            public static final String ORDER_BY_SQL = " ORDER BY Country.name ASC";
077            public static final String DATA_SOURCE = "liferayDataSource";
078            public static final String SESSION_FACTORY = "liferaySessionFactory";
079            public static final String TX_MANAGER = "liferayTransactionManager";
080            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
081                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Country"),
082                            true);
083            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
084                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Country"),
085                            true);
086            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
087                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.Country"),
088                            true);
089            public static long A2_COLUMN_BITMASK = 1L;
090            public static long A3_COLUMN_BITMASK = 2L;
091            public static long ACTIVE_COLUMN_BITMASK = 4L;
092            public static long NAME_COLUMN_BITMASK = 8L;
093    
094            /**
095             * Converts the soap model instance into a normal model instance.
096             *
097             * @param soapModel the soap model instance to convert
098             * @return the normal model instance
099             */
100            public static Country toModel(CountrySoap soapModel) {
101                    if (soapModel == null) {
102                            return null;
103                    }
104    
105                    Country model = new CountryImpl();
106    
107                    model.setCountryId(soapModel.getCountryId());
108                    model.setName(soapModel.getName());
109                    model.setA2(soapModel.getA2());
110                    model.setA3(soapModel.getA3());
111                    model.setNumber(soapModel.getNumber());
112                    model.setIdd(soapModel.getIdd());
113                    model.setZipRequired(soapModel.getZipRequired());
114                    model.setActive(soapModel.getActive());
115    
116                    return model;
117            }
118    
119            /**
120             * Converts the soap model instances into normal model instances.
121             *
122             * @param soapModels the soap model instances to convert
123             * @return the normal model instances
124             */
125            public static List<Country> toModels(CountrySoap[] soapModels) {
126                    if (soapModels == null) {
127                            return null;
128                    }
129    
130                    List<Country> models = new ArrayList<Country>(soapModels.length);
131    
132                    for (CountrySoap soapModel : soapModels) {
133                            models.add(toModel(soapModel));
134                    }
135    
136                    return models;
137            }
138    
139            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
140                                    "lock.expiration.time.com.liferay.portal.model.Country"));
141    
142            public CountryModelImpl() {
143            }
144    
145            @Override
146            public long getPrimaryKey() {
147                    return _countryId;
148            }
149    
150            @Override
151            public void setPrimaryKey(long primaryKey) {
152                    setCountryId(primaryKey);
153            }
154    
155            @Override
156            public Serializable getPrimaryKeyObj() {
157                    return _countryId;
158            }
159    
160            @Override
161            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
162                    setPrimaryKey(((Long)primaryKeyObj).longValue());
163            }
164    
165            @Override
166            public Class<?> getModelClass() {
167                    return Country.class;
168            }
169    
170            @Override
171            public String getModelClassName() {
172                    return Country.class.getName();
173            }
174    
175            @Override
176            public Map<String, Object> getModelAttributes() {
177                    Map<String, Object> attributes = new HashMap<String, Object>();
178    
179                    attributes.put("countryId", getCountryId());
180                    attributes.put("name", getName());
181                    attributes.put("a2", getA2());
182                    attributes.put("a3", getA3());
183                    attributes.put("number", getNumber());
184                    attributes.put("idd", getIdd());
185                    attributes.put("zipRequired", getZipRequired());
186                    attributes.put("active", getActive());
187    
188                    return attributes;
189            }
190    
191            @Override
192            public void setModelAttributes(Map<String, Object> attributes) {
193                    Long countryId = (Long)attributes.get("countryId");
194    
195                    if (countryId != null) {
196                            setCountryId(countryId);
197                    }
198    
199                    String name = (String)attributes.get("name");
200    
201                    if (name != null) {
202                            setName(name);
203                    }
204    
205                    String a2 = (String)attributes.get("a2");
206    
207                    if (a2 != null) {
208                            setA2(a2);
209                    }
210    
211                    String a3 = (String)attributes.get("a3");
212    
213                    if (a3 != null) {
214                            setA3(a3);
215                    }
216    
217                    String number = (String)attributes.get("number");
218    
219                    if (number != null) {
220                            setNumber(number);
221                    }
222    
223                    String idd = (String)attributes.get("idd");
224    
225                    if (idd != null) {
226                            setIdd(idd);
227                    }
228    
229                    Boolean zipRequired = (Boolean)attributes.get("zipRequired");
230    
231                    if (zipRequired != null) {
232                            setZipRequired(zipRequired);
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 getCountryId() {
245                    return _countryId;
246            }
247    
248            @Override
249            public void setCountryId(long countryId) {
250                    _countryId = countryId;
251            }
252    
253            @JSON
254            @Override
255            public String getName() {
256                    if (_name == null) {
257                            return StringPool.BLANK;
258                    }
259                    else {
260                            return _name;
261                    }
262            }
263    
264            @Override
265            public void setName(String name) {
266                    _columnBitmask = -1L;
267    
268                    if (_originalName == null) {
269                            _originalName = _name;
270                    }
271    
272                    _name = name;
273            }
274    
275            public String getOriginalName() {
276                    return GetterUtil.getString(_originalName);
277            }
278    
279            @JSON
280            @Override
281            public String getA2() {
282                    if (_a2 == null) {
283                            return StringPool.BLANK;
284                    }
285                    else {
286                            return _a2;
287                    }
288            }
289    
290            @Override
291            public void setA2(String a2) {
292                    _columnBitmask |= A2_COLUMN_BITMASK;
293    
294                    if (_originalA2 == null) {
295                            _originalA2 = _a2;
296                    }
297    
298                    _a2 = a2;
299            }
300    
301            public String getOriginalA2() {
302                    return GetterUtil.getString(_originalA2);
303            }
304    
305            @JSON
306            @Override
307            public String getA3() {
308                    if (_a3 == null) {
309                            return StringPool.BLANK;
310                    }
311                    else {
312                            return _a3;
313                    }
314            }
315    
316            @Override
317            public void setA3(String a3) {
318                    _columnBitmask |= A3_COLUMN_BITMASK;
319    
320                    if (_originalA3 == null) {
321                            _originalA3 = _a3;
322                    }
323    
324                    _a3 = a3;
325            }
326    
327            public String getOriginalA3() {
328                    return GetterUtil.getString(_originalA3);
329            }
330    
331            @JSON
332            @Override
333            public String getNumber() {
334                    if (_number == null) {
335                            return StringPool.BLANK;
336                    }
337                    else {
338                            return _number;
339                    }
340            }
341    
342            @Override
343            public void setNumber(String number) {
344                    _number = number;
345            }
346    
347            @JSON
348            @Override
349            public String getIdd() {
350                    if (_idd == null) {
351                            return StringPool.BLANK;
352                    }
353                    else {
354                            return _idd;
355                    }
356            }
357    
358            @Override
359            public void setIdd(String idd) {
360                    _idd = idd;
361            }
362    
363            @JSON
364            @Override
365            public boolean getZipRequired() {
366                    return _zipRequired;
367            }
368    
369            @Override
370            public boolean isZipRequired() {
371                    return _zipRequired;
372            }
373    
374            @Override
375            public void setZipRequired(boolean zipRequired) {
376                    _zipRequired = zipRequired;
377            }
378    
379            @JSON
380            @Override
381            public boolean getActive() {
382                    return _active;
383            }
384    
385            @Override
386            public boolean isActive() {
387                    return _active;
388            }
389    
390            @Override
391            public void setActive(boolean active) {
392                    _columnBitmask |= ACTIVE_COLUMN_BITMASK;
393    
394                    if (!_setOriginalActive) {
395                            _setOriginalActive = true;
396    
397                            _originalActive = _active;
398                    }
399    
400                    _active = active;
401            }
402    
403            public boolean getOriginalActive() {
404                    return _originalActive;
405            }
406    
407            public long getColumnBitmask() {
408                    return _columnBitmask;
409            }
410    
411            @Override
412            public ExpandoBridge getExpandoBridge() {
413                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
414                            Country.class.getName(), getPrimaryKey());
415            }
416    
417            @Override
418            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
419                    ExpandoBridge expandoBridge = getExpandoBridge();
420    
421                    expandoBridge.setAttributes(serviceContext);
422            }
423    
424            @Override
425            public Country toEscapedModel() {
426                    if (_escapedModel == null) {
427                            _escapedModel = (Country)ProxyUtil.newProxyInstance(_classLoader,
428                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
429                    }
430    
431                    return _escapedModel;
432            }
433    
434            @Override
435            public Object clone() {
436                    CountryImpl countryImpl = new CountryImpl();
437    
438                    countryImpl.setCountryId(getCountryId());
439                    countryImpl.setName(getName());
440                    countryImpl.setA2(getA2());
441                    countryImpl.setA3(getA3());
442                    countryImpl.setNumber(getNumber());
443                    countryImpl.setIdd(getIdd());
444                    countryImpl.setZipRequired(getZipRequired());
445                    countryImpl.setActive(getActive());
446    
447                    countryImpl.resetOriginalValues();
448    
449                    return countryImpl;
450            }
451    
452            @Override
453            public int compareTo(Country country) {
454                    int value = 0;
455    
456                    value = getName().compareTo(country.getName());
457    
458                    if (value != 0) {
459                            return value;
460                    }
461    
462                    return 0;
463            }
464    
465            @Override
466            public boolean equals(Object obj) {
467                    if (this == obj) {
468                            return true;
469                    }
470    
471                    if (!(obj instanceof Country)) {
472                            return false;
473                    }
474    
475                    Country country = (Country)obj;
476    
477                    long primaryKey = country.getPrimaryKey();
478    
479                    if (getPrimaryKey() == primaryKey) {
480                            return true;
481                    }
482                    else {
483                            return false;
484                    }
485            }
486    
487            @Override
488            public int hashCode() {
489                    return (int)getPrimaryKey();
490            }
491    
492            @Override
493            public void resetOriginalValues() {
494                    CountryModelImpl countryModelImpl = this;
495    
496                    countryModelImpl._originalName = countryModelImpl._name;
497    
498                    countryModelImpl._originalA2 = countryModelImpl._a2;
499    
500                    countryModelImpl._originalA3 = countryModelImpl._a3;
501    
502                    countryModelImpl._originalActive = countryModelImpl._active;
503    
504                    countryModelImpl._setOriginalActive = false;
505    
506                    countryModelImpl._columnBitmask = 0;
507            }
508    
509            @Override
510            public CacheModel<Country> toCacheModel() {
511                    CountryCacheModel countryCacheModel = new CountryCacheModel();
512    
513                    countryCacheModel.countryId = getCountryId();
514    
515                    countryCacheModel.name = getName();
516    
517                    String name = countryCacheModel.name;
518    
519                    if ((name != null) && (name.length() == 0)) {
520                            countryCacheModel.name = null;
521                    }
522    
523                    countryCacheModel.a2 = getA2();
524    
525                    String a2 = countryCacheModel.a2;
526    
527                    if ((a2 != null) && (a2.length() == 0)) {
528                            countryCacheModel.a2 = null;
529                    }
530    
531                    countryCacheModel.a3 = getA3();
532    
533                    String a3 = countryCacheModel.a3;
534    
535                    if ((a3 != null) && (a3.length() == 0)) {
536                            countryCacheModel.a3 = null;
537                    }
538    
539                    countryCacheModel.number = getNumber();
540    
541                    String number = countryCacheModel.number;
542    
543                    if ((number != null) && (number.length() == 0)) {
544                            countryCacheModel.number = null;
545                    }
546    
547                    countryCacheModel.idd = getIdd();
548    
549                    String idd = countryCacheModel.idd;
550    
551                    if ((idd != null) && (idd.length() == 0)) {
552                            countryCacheModel.idd = null;
553                    }
554    
555                    countryCacheModel.zipRequired = getZipRequired();
556    
557                    countryCacheModel.active = getActive();
558    
559                    return countryCacheModel;
560            }
561    
562            @Override
563            public String toString() {
564                    StringBundler sb = new StringBundler(17);
565    
566                    sb.append("{countryId=");
567                    sb.append(getCountryId());
568                    sb.append(", name=");
569                    sb.append(getName());
570                    sb.append(", a2=");
571                    sb.append(getA2());
572                    sb.append(", a3=");
573                    sb.append(getA3());
574                    sb.append(", number=");
575                    sb.append(getNumber());
576                    sb.append(", idd=");
577                    sb.append(getIdd());
578                    sb.append(", zipRequired=");
579                    sb.append(getZipRequired());
580                    sb.append(", active=");
581                    sb.append(getActive());
582                    sb.append("}");
583    
584                    return sb.toString();
585            }
586    
587            @Override
588            public String toXmlString() {
589                    StringBundler sb = new StringBundler(28);
590    
591                    sb.append("<model><model-name>");
592                    sb.append("com.liferay.portal.model.Country");
593                    sb.append("</model-name>");
594    
595                    sb.append(
596                            "<column><column-name>countryId</column-name><column-value><![CDATA[");
597                    sb.append(getCountryId());
598                    sb.append("]]></column-value></column>");
599                    sb.append(
600                            "<column><column-name>name</column-name><column-value><![CDATA[");
601                    sb.append(getName());
602                    sb.append("]]></column-value></column>");
603                    sb.append(
604                            "<column><column-name>a2</column-name><column-value><![CDATA[");
605                    sb.append(getA2());
606                    sb.append("]]></column-value></column>");
607                    sb.append(
608                            "<column><column-name>a3</column-name><column-value><![CDATA[");
609                    sb.append(getA3());
610                    sb.append("]]></column-value></column>");
611                    sb.append(
612                            "<column><column-name>number</column-name><column-value><![CDATA[");
613                    sb.append(getNumber());
614                    sb.append("]]></column-value></column>");
615                    sb.append(
616                            "<column><column-name>idd</column-name><column-value><![CDATA[");
617                    sb.append(getIdd());
618                    sb.append("]]></column-value></column>");
619                    sb.append(
620                            "<column><column-name>zipRequired</column-name><column-value><![CDATA[");
621                    sb.append(getZipRequired());
622                    sb.append("]]></column-value></column>");
623                    sb.append(
624                            "<column><column-name>active</column-name><column-value><![CDATA[");
625                    sb.append(getActive());
626                    sb.append("]]></column-value></column>");
627    
628                    sb.append("</model>");
629    
630                    return sb.toString();
631            }
632    
633            private static ClassLoader _classLoader = Country.class.getClassLoader();
634            private static Class<?>[] _escapedModelInterfaces = new Class[] {
635                            Country.class
636                    };
637            private long _countryId;
638            private String _name;
639            private String _originalName;
640            private String _a2;
641            private String _originalA2;
642            private String _a3;
643            private String _originalA3;
644            private String _number;
645            private String _idd;
646            private boolean _zipRequired;
647            private boolean _active;
648            private boolean _originalActive;
649            private boolean _setOriginalActive;
650            private long _columnBitmask;
651            private Country _escapedModel;
652    }