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            public long getPrimaryKey() {
146                    return _countryId;
147            }
148    
149            public void setPrimaryKey(long primaryKey) {
150                    setCountryId(primaryKey);
151            }
152    
153            public Serializable getPrimaryKeyObj() {
154                    return new Long(_countryId);
155            }
156    
157            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
158                    setPrimaryKey(((Long)primaryKeyObj).longValue());
159            }
160    
161            public Class<?> getModelClass() {
162                    return Country.class;
163            }
164    
165            public String getModelClassName() {
166                    return Country.class.getName();
167            }
168    
169            @Override
170            public Map<String, Object> getModelAttributes() {
171                    Map<String, Object> attributes = new HashMap<String, Object>();
172    
173                    attributes.put("countryId", getCountryId());
174                    attributes.put("name", getName());
175                    attributes.put("a2", getA2());
176                    attributes.put("a3", getA3());
177                    attributes.put("number", getNumber());
178                    attributes.put("idd", getIdd());
179                    attributes.put("zipRequired", getZipRequired());
180                    attributes.put("active", getActive());
181    
182                    return attributes;
183            }
184    
185            @Override
186            public void setModelAttributes(Map<String, Object> attributes) {
187                    Long countryId = (Long)attributes.get("countryId");
188    
189                    if (countryId != null) {
190                            setCountryId(countryId);
191                    }
192    
193                    String name = (String)attributes.get("name");
194    
195                    if (name != null) {
196                            setName(name);
197                    }
198    
199                    String a2 = (String)attributes.get("a2");
200    
201                    if (a2 != null) {
202                            setA2(a2);
203                    }
204    
205                    String a3 = (String)attributes.get("a3");
206    
207                    if (a3 != null) {
208                            setA3(a3);
209                    }
210    
211                    String number = (String)attributes.get("number");
212    
213                    if (number != null) {
214                            setNumber(number);
215                    }
216    
217                    String idd = (String)attributes.get("idd");
218    
219                    if (idd != null) {
220                            setIdd(idd);
221                    }
222    
223                    Boolean zipRequired = (Boolean)attributes.get("zipRequired");
224    
225                    if (zipRequired != null) {
226                            setZipRequired(zipRequired);
227                    }
228    
229                    Boolean active = (Boolean)attributes.get("active");
230    
231                    if (active != null) {
232                            setActive(active);
233                    }
234            }
235    
236            @JSON
237            public long getCountryId() {
238                    return _countryId;
239            }
240    
241            public void setCountryId(long countryId) {
242                    _countryId = countryId;
243            }
244    
245            @JSON
246            public String getName() {
247                    if (_name == null) {
248                            return StringPool.BLANK;
249                    }
250                    else {
251                            return _name;
252                    }
253            }
254    
255            public void setName(String name) {
256                    _columnBitmask = -1L;
257    
258                    if (_originalName == null) {
259                            _originalName = _name;
260                    }
261    
262                    _name = name;
263            }
264    
265            public String getOriginalName() {
266                    return GetterUtil.getString(_originalName);
267            }
268    
269            @JSON
270            public String getA2() {
271                    if (_a2 == null) {
272                            return StringPool.BLANK;
273                    }
274                    else {
275                            return _a2;
276                    }
277            }
278    
279            public void setA2(String a2) {
280                    _columnBitmask |= A2_COLUMN_BITMASK;
281    
282                    if (_originalA2 == null) {
283                            _originalA2 = _a2;
284                    }
285    
286                    _a2 = a2;
287            }
288    
289            public String getOriginalA2() {
290                    return GetterUtil.getString(_originalA2);
291            }
292    
293            @JSON
294            public String getA3() {
295                    if (_a3 == null) {
296                            return StringPool.BLANK;
297                    }
298                    else {
299                            return _a3;
300                    }
301            }
302    
303            public void setA3(String a3) {
304                    _columnBitmask |= A3_COLUMN_BITMASK;
305    
306                    if (_originalA3 == null) {
307                            _originalA3 = _a3;
308                    }
309    
310                    _a3 = a3;
311            }
312    
313            public String getOriginalA3() {
314                    return GetterUtil.getString(_originalA3);
315            }
316    
317            @JSON
318            public String getNumber() {
319                    if (_number == null) {
320                            return StringPool.BLANK;
321                    }
322                    else {
323                            return _number;
324                    }
325            }
326    
327            public void setNumber(String number) {
328                    _number = number;
329            }
330    
331            @JSON
332            public String getIdd() {
333                    if (_idd == null) {
334                            return StringPool.BLANK;
335                    }
336                    else {
337                            return _idd;
338                    }
339            }
340    
341            public void setIdd(String idd) {
342                    _idd = idd;
343            }
344    
345            @JSON
346            public boolean getZipRequired() {
347                    return _zipRequired;
348            }
349    
350            public boolean isZipRequired() {
351                    return _zipRequired;
352            }
353    
354            public void setZipRequired(boolean zipRequired) {
355                    _zipRequired = zipRequired;
356            }
357    
358            @JSON
359            public boolean getActive() {
360                    return _active;
361            }
362    
363            public boolean isActive() {
364                    return _active;
365            }
366    
367            public void setActive(boolean active) {
368                    _columnBitmask |= ACTIVE_COLUMN_BITMASK;
369    
370                    if (!_setOriginalActive) {
371                            _setOriginalActive = true;
372    
373                            _originalActive = _active;
374                    }
375    
376                    _active = active;
377            }
378    
379            public boolean getOriginalActive() {
380                    return _originalActive;
381            }
382    
383            public long getColumnBitmask() {
384                    return _columnBitmask;
385            }
386    
387            @Override
388            public ExpandoBridge getExpandoBridge() {
389                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
390                            Country.class.getName(), getPrimaryKey());
391            }
392    
393            @Override
394            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
395                    ExpandoBridge expandoBridge = getExpandoBridge();
396    
397                    expandoBridge.setAttributes(serviceContext);
398            }
399    
400            @Override
401            public Country toEscapedModel() {
402                    if (_escapedModel == null) {
403                            _escapedModel = (Country)ProxyUtil.newProxyInstance(_classLoader,
404                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
405                    }
406    
407                    return _escapedModel;
408            }
409    
410            public Country toUnescapedModel() {
411                    return (Country)this;
412            }
413    
414            @Override
415            public Object clone() {
416                    CountryImpl countryImpl = new CountryImpl();
417    
418                    countryImpl.setCountryId(getCountryId());
419                    countryImpl.setName(getName());
420                    countryImpl.setA2(getA2());
421                    countryImpl.setA3(getA3());
422                    countryImpl.setNumber(getNumber());
423                    countryImpl.setIdd(getIdd());
424                    countryImpl.setZipRequired(getZipRequired());
425                    countryImpl.setActive(getActive());
426    
427                    countryImpl.resetOriginalValues();
428    
429                    return countryImpl;
430            }
431    
432            public int compareTo(Country country) {
433                    int value = 0;
434    
435                    value = getName().compareTo(country.getName());
436    
437                    if (value != 0) {
438                            return value;
439                    }
440    
441                    return 0;
442            }
443    
444            @Override
445            public boolean equals(Object obj) {
446                    if (this == obj) {
447                            return true;
448                    }
449    
450                    if (!(obj instanceof Country)) {
451                            return false;
452                    }
453    
454                    Country country = (Country)obj;
455    
456                    long primaryKey = country.getPrimaryKey();
457    
458                    if (getPrimaryKey() == primaryKey) {
459                            return true;
460                    }
461                    else {
462                            return false;
463                    }
464            }
465    
466            @Override
467            public int hashCode() {
468                    return (int)getPrimaryKey();
469            }
470    
471            @Override
472            public void resetOriginalValues() {
473                    CountryModelImpl countryModelImpl = this;
474    
475                    countryModelImpl._originalName = countryModelImpl._name;
476    
477                    countryModelImpl._originalA2 = countryModelImpl._a2;
478    
479                    countryModelImpl._originalA3 = countryModelImpl._a3;
480    
481                    countryModelImpl._originalActive = countryModelImpl._active;
482    
483                    countryModelImpl._setOriginalActive = false;
484    
485                    countryModelImpl._columnBitmask = 0;
486            }
487    
488            @Override
489            public CacheModel<Country> toCacheModel() {
490                    CountryCacheModel countryCacheModel = new CountryCacheModel();
491    
492                    countryCacheModel.countryId = getCountryId();
493    
494                    countryCacheModel.name = getName();
495    
496                    String name = countryCacheModel.name;
497    
498                    if ((name != null) && (name.length() == 0)) {
499                            countryCacheModel.name = null;
500                    }
501    
502                    countryCacheModel.a2 = getA2();
503    
504                    String a2 = countryCacheModel.a2;
505    
506                    if ((a2 != null) && (a2.length() == 0)) {
507                            countryCacheModel.a2 = null;
508                    }
509    
510                    countryCacheModel.a3 = getA3();
511    
512                    String a3 = countryCacheModel.a3;
513    
514                    if ((a3 != null) && (a3.length() == 0)) {
515                            countryCacheModel.a3 = null;
516                    }
517    
518                    countryCacheModel.number = getNumber();
519    
520                    String number = countryCacheModel.number;
521    
522                    if ((number != null) && (number.length() == 0)) {
523                            countryCacheModel.number = null;
524                    }
525    
526                    countryCacheModel.idd = getIdd();
527    
528                    String idd = countryCacheModel.idd;
529    
530                    if ((idd != null) && (idd.length() == 0)) {
531                            countryCacheModel.idd = null;
532                    }
533    
534                    countryCacheModel.zipRequired = getZipRequired();
535    
536                    countryCacheModel.active = getActive();
537    
538                    return countryCacheModel;
539            }
540    
541            @Override
542            public String toString() {
543                    StringBundler sb = new StringBundler(17);
544    
545                    sb.append("{countryId=");
546                    sb.append(getCountryId());
547                    sb.append(", name=");
548                    sb.append(getName());
549                    sb.append(", a2=");
550                    sb.append(getA2());
551                    sb.append(", a3=");
552                    sb.append(getA3());
553                    sb.append(", number=");
554                    sb.append(getNumber());
555                    sb.append(", idd=");
556                    sb.append(getIdd());
557                    sb.append(", zipRequired=");
558                    sb.append(getZipRequired());
559                    sb.append(", active=");
560                    sb.append(getActive());
561                    sb.append("}");
562    
563                    return sb.toString();
564            }
565    
566            public String toXmlString() {
567                    StringBundler sb = new StringBundler(28);
568    
569                    sb.append("<model><model-name>");
570                    sb.append("com.liferay.portal.model.Country");
571                    sb.append("</model-name>");
572    
573                    sb.append(
574                            "<column><column-name>countryId</column-name><column-value><![CDATA[");
575                    sb.append(getCountryId());
576                    sb.append("]]></column-value></column>");
577                    sb.append(
578                            "<column><column-name>name</column-name><column-value><![CDATA[");
579                    sb.append(getName());
580                    sb.append("]]></column-value></column>");
581                    sb.append(
582                            "<column><column-name>a2</column-name><column-value><![CDATA[");
583                    sb.append(getA2());
584                    sb.append("]]></column-value></column>");
585                    sb.append(
586                            "<column><column-name>a3</column-name><column-value><![CDATA[");
587                    sb.append(getA3());
588                    sb.append("]]></column-value></column>");
589                    sb.append(
590                            "<column><column-name>number</column-name><column-value><![CDATA[");
591                    sb.append(getNumber());
592                    sb.append("]]></column-value></column>");
593                    sb.append(
594                            "<column><column-name>idd</column-name><column-value><![CDATA[");
595                    sb.append(getIdd());
596                    sb.append("]]></column-value></column>");
597                    sb.append(
598                            "<column><column-name>zipRequired</column-name><column-value><![CDATA[");
599                    sb.append(getZipRequired());
600                    sb.append("]]></column-value></column>");
601                    sb.append(
602                            "<column><column-name>active</column-name><column-value><![CDATA[");
603                    sb.append(getActive());
604                    sb.append("]]></column-value></column>");
605    
606                    sb.append("</model>");
607    
608                    return sb.toString();
609            }
610    
611            private static ClassLoader _classLoader = Country.class.getClassLoader();
612            private static Class<?>[] _escapedModelInterfaces = new Class[] {
613                            Country.class
614                    };
615            private long _countryId;
616            private String _name;
617            private String _originalName;
618            private String _a2;
619            private String _originalA2;
620            private String _a3;
621            private String _originalA3;
622            private String _number;
623            private String _idd;
624            private boolean _zipRequired;
625            private boolean _active;
626            private boolean _originalActive;
627            private boolean _setOriginalActive;
628            private long _columnBitmask;
629            private Country _escapedModel;
630    }