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.service.persistence;
016    
017    import com.liferay.portal.NoSuchCountryException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.SetUtil;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.Country;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.model.impl.CountryImpl;
042    import com.liferay.portal.model.impl.CountryModelImpl;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the country service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see CountryPersistence
061     * @see CountryUtil
062     * @generated
063     */
064    public class CountryPersistenceImpl extends BasePersistenceImpl<Country>
065            implements CountryPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link CountryUtil} to access the country persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = CountryImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
077                            CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
080                            CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
083                            CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085            public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
086                            CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
087                            FINDER_CLASS_NAME_ENTITY, "fetchByName",
088                            new String[] { String.class.getName() },
089                            CountryModelImpl.NAME_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
091                            CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
093                            new String[] { String.class.getName() });
094    
095            /**
096             * Returns the country where name = &#63; or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
097             *
098             * @param name the name
099             * @return the matching country
100             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
101             * @throws SystemException if a system exception occurred
102             */
103            public Country findByName(String name)
104                    throws NoSuchCountryException, SystemException {
105                    Country country = fetchByName(name);
106    
107                    if (country == null) {
108                            StringBundler msg = new StringBundler(4);
109    
110                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111    
112                            msg.append("name=");
113                            msg.append(name);
114    
115                            msg.append(StringPool.CLOSE_CURLY_BRACE);
116    
117                            if (_log.isWarnEnabled()) {
118                                    _log.warn(msg.toString());
119                            }
120    
121                            throw new NoSuchCountryException(msg.toString());
122                    }
123    
124                    return country;
125            }
126    
127            /**
128             * Returns the country where name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
129             *
130             * @param name the name
131             * @return the matching country, or <code>null</code> if a matching country could not be found
132             * @throws SystemException if a system exception occurred
133             */
134            public Country fetchByName(String name) throws SystemException {
135                    return fetchByName(name, true);
136            }
137    
138            /**
139             * Returns the country where name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
140             *
141             * @param name the name
142             * @param retrieveFromCache whether to use the finder cache
143             * @return the matching country, or <code>null</code> if a matching country could not be found
144             * @throws SystemException if a system exception occurred
145             */
146            public Country fetchByName(String name, boolean retrieveFromCache)
147                    throws SystemException {
148                    Object[] finderArgs = new Object[] { name };
149    
150                    Object result = null;
151    
152                    if (retrieveFromCache) {
153                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
154                                            finderArgs, this);
155                    }
156    
157                    if (result instanceof Country) {
158                            Country country = (Country)result;
159    
160                            if (!Validator.equals(name, country.getName())) {
161                                    result = null;
162                            }
163                    }
164    
165                    if (result == null) {
166                            StringBundler query = new StringBundler(3);
167    
168                            query.append(_SQL_SELECT_COUNTRY_WHERE);
169    
170                            boolean bindName = false;
171    
172                            if (name == null) {
173                                    query.append(_FINDER_COLUMN_NAME_NAME_1);
174                            }
175                            else if (name.equals(StringPool.BLANK)) {
176                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
177                            }
178                            else {
179                                    bindName = true;
180    
181                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
182                            }
183    
184                            String sql = query.toString();
185    
186                            Session session = null;
187    
188                            try {
189                                    session = openSession();
190    
191                                    Query q = session.createQuery(sql);
192    
193                                    QueryPos qPos = QueryPos.getInstance(q);
194    
195                                    if (bindName) {
196                                            qPos.add(name);
197                                    }
198    
199                                    List<Country> list = q.list();
200    
201                                    if (list.isEmpty()) {
202                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
203                                                    finderArgs, list);
204                                    }
205                                    else {
206                                            Country country = list.get(0);
207    
208                                            result = country;
209    
210                                            cacheResult(country);
211    
212                                            if ((country.getName() == null) ||
213                                                            !country.getName().equals(name)) {
214                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
215                                                            finderArgs, country);
216                                            }
217                                    }
218                            }
219                            catch (Exception e) {
220                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
221                                            finderArgs);
222    
223                                    throw processException(e);
224                            }
225                            finally {
226                                    closeSession(session);
227                            }
228                    }
229    
230                    if (result instanceof List<?>) {
231                            return null;
232                    }
233                    else {
234                            return (Country)result;
235                    }
236            }
237    
238            /**
239             * Removes the country where name = &#63; from the database.
240             *
241             * @param name the name
242             * @return the country that was removed
243             * @throws SystemException if a system exception occurred
244             */
245            public Country removeByName(String name)
246                    throws NoSuchCountryException, SystemException {
247                    Country country = findByName(name);
248    
249                    return remove(country);
250            }
251    
252            /**
253             * Returns the number of countries where name = &#63;.
254             *
255             * @param name the name
256             * @return the number of matching countries
257             * @throws SystemException if a system exception occurred
258             */
259            public int countByName(String name) throws SystemException {
260                    FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
261    
262                    Object[] finderArgs = new Object[] { name };
263    
264                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
265                                    this);
266    
267                    if (count == null) {
268                            StringBundler query = new StringBundler(2);
269    
270                            query.append(_SQL_COUNT_COUNTRY_WHERE);
271    
272                            boolean bindName = false;
273    
274                            if (name == null) {
275                                    query.append(_FINDER_COLUMN_NAME_NAME_1);
276                            }
277                            else if (name.equals(StringPool.BLANK)) {
278                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
279                            }
280                            else {
281                                    bindName = true;
282    
283                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
284                            }
285    
286                            String sql = query.toString();
287    
288                            Session session = null;
289    
290                            try {
291                                    session = openSession();
292    
293                                    Query q = session.createQuery(sql);
294    
295                                    QueryPos qPos = QueryPos.getInstance(q);
296    
297                                    if (bindName) {
298                                            qPos.add(name);
299                                    }
300    
301                                    count = (Long)q.uniqueResult();
302    
303                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
304                            }
305                            catch (Exception e) {
306                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
307    
308                                    throw processException(e);
309                            }
310                            finally {
311                                    closeSession(session);
312                            }
313                    }
314    
315                    return count.intValue();
316            }
317    
318            private static final String _FINDER_COLUMN_NAME_NAME_1 = "country.name IS NULL";
319            private static final String _FINDER_COLUMN_NAME_NAME_2 = "country.name = ?";
320            private static final String _FINDER_COLUMN_NAME_NAME_3 = "(country.name IS NULL OR country.name = '')";
321            public static final FinderPath FINDER_PATH_FETCH_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
322                            CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
323                            FINDER_CLASS_NAME_ENTITY, "fetchByA2",
324                            new String[] { String.class.getName() },
325                            CountryModelImpl.A2_COLUMN_BITMASK);
326            public static final FinderPath FINDER_PATH_COUNT_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
327                            CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
328                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA2",
329                            new String[] { String.class.getName() });
330    
331            /**
332             * Returns the country where a2 = &#63; or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
333             *
334             * @param a2 the a2
335             * @return the matching country
336             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
337             * @throws SystemException if a system exception occurred
338             */
339            public Country findByA2(String a2)
340                    throws NoSuchCountryException, SystemException {
341                    Country country = fetchByA2(a2);
342    
343                    if (country == null) {
344                            StringBundler msg = new StringBundler(4);
345    
346                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
347    
348                            msg.append("a2=");
349                            msg.append(a2);
350    
351                            msg.append(StringPool.CLOSE_CURLY_BRACE);
352    
353                            if (_log.isWarnEnabled()) {
354                                    _log.warn(msg.toString());
355                            }
356    
357                            throw new NoSuchCountryException(msg.toString());
358                    }
359    
360                    return country;
361            }
362    
363            /**
364             * Returns the country where a2 = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
365             *
366             * @param a2 the a2
367             * @return the matching country, or <code>null</code> if a matching country could not be found
368             * @throws SystemException if a system exception occurred
369             */
370            public Country fetchByA2(String a2) throws SystemException {
371                    return fetchByA2(a2, true);
372            }
373    
374            /**
375             * Returns the country where a2 = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
376             *
377             * @param a2 the a2
378             * @param retrieveFromCache whether to use the finder cache
379             * @return the matching country, or <code>null</code> if a matching country could not be found
380             * @throws SystemException if a system exception occurred
381             */
382            public Country fetchByA2(String a2, boolean retrieveFromCache)
383                    throws SystemException {
384                    Object[] finderArgs = new Object[] { a2 };
385    
386                    Object result = null;
387    
388                    if (retrieveFromCache) {
389                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A2,
390                                            finderArgs, this);
391                    }
392    
393                    if (result instanceof Country) {
394                            Country country = (Country)result;
395    
396                            if (!Validator.equals(a2, country.getA2())) {
397                                    result = null;
398                            }
399                    }
400    
401                    if (result == null) {
402                            StringBundler query = new StringBundler(3);
403    
404                            query.append(_SQL_SELECT_COUNTRY_WHERE);
405    
406                            boolean bindA2 = false;
407    
408                            if (a2 == null) {
409                                    query.append(_FINDER_COLUMN_A2_A2_1);
410                            }
411                            else if (a2.equals(StringPool.BLANK)) {
412                                    query.append(_FINDER_COLUMN_A2_A2_3);
413                            }
414                            else {
415                                    bindA2 = true;
416    
417                                    query.append(_FINDER_COLUMN_A2_A2_2);
418                            }
419    
420                            String sql = query.toString();
421    
422                            Session session = null;
423    
424                            try {
425                                    session = openSession();
426    
427                                    Query q = session.createQuery(sql);
428    
429                                    QueryPos qPos = QueryPos.getInstance(q);
430    
431                                    if (bindA2) {
432                                            qPos.add(a2);
433                                    }
434    
435                                    List<Country> list = q.list();
436    
437                                    if (list.isEmpty()) {
438                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
439                                                    finderArgs, list);
440                                    }
441                                    else {
442                                            Country country = list.get(0);
443    
444                                            result = country;
445    
446                                            cacheResult(country);
447    
448                                            if ((country.getA2() == null) ||
449                                                            !country.getA2().equals(a2)) {
450                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
451                                                            finderArgs, country);
452                                            }
453                                    }
454                            }
455                            catch (Exception e) {
456                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, finderArgs);
457    
458                                    throw processException(e);
459                            }
460                            finally {
461                                    closeSession(session);
462                            }
463                    }
464    
465                    if (result instanceof List<?>) {
466                            return null;
467                    }
468                    else {
469                            return (Country)result;
470                    }
471            }
472    
473            /**
474             * Removes the country where a2 = &#63; from the database.
475             *
476             * @param a2 the a2
477             * @return the country that was removed
478             * @throws SystemException if a system exception occurred
479             */
480            public Country removeByA2(String a2)
481                    throws NoSuchCountryException, SystemException {
482                    Country country = findByA2(a2);
483    
484                    return remove(country);
485            }
486    
487            /**
488             * Returns the number of countries where a2 = &#63;.
489             *
490             * @param a2 the a2
491             * @return the number of matching countries
492             * @throws SystemException if a system exception occurred
493             */
494            public int countByA2(String a2) throws SystemException {
495                    FinderPath finderPath = FINDER_PATH_COUNT_BY_A2;
496    
497                    Object[] finderArgs = new Object[] { a2 };
498    
499                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
500                                    this);
501    
502                    if (count == null) {
503                            StringBundler query = new StringBundler(2);
504    
505                            query.append(_SQL_COUNT_COUNTRY_WHERE);
506    
507                            boolean bindA2 = false;
508    
509                            if (a2 == null) {
510                                    query.append(_FINDER_COLUMN_A2_A2_1);
511                            }
512                            else if (a2.equals(StringPool.BLANK)) {
513                                    query.append(_FINDER_COLUMN_A2_A2_3);
514                            }
515                            else {
516                                    bindA2 = true;
517    
518                                    query.append(_FINDER_COLUMN_A2_A2_2);
519                            }
520    
521                            String sql = query.toString();
522    
523                            Session session = null;
524    
525                            try {
526                                    session = openSession();
527    
528                                    Query q = session.createQuery(sql);
529    
530                                    QueryPos qPos = QueryPos.getInstance(q);
531    
532                                    if (bindA2) {
533                                            qPos.add(a2);
534                                    }
535    
536                                    count = (Long)q.uniqueResult();
537    
538                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
539                            }
540                            catch (Exception e) {
541                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
542    
543                                    throw processException(e);
544                            }
545                            finally {
546                                    closeSession(session);
547                            }
548                    }
549    
550                    return count.intValue();
551            }
552    
553            private static final String _FINDER_COLUMN_A2_A2_1 = "country.a2 IS NULL";
554            private static final String _FINDER_COLUMN_A2_A2_2 = "country.a2 = ?";
555            private static final String _FINDER_COLUMN_A2_A2_3 = "(country.a2 IS NULL OR country.a2 = '')";
556            public static final FinderPath FINDER_PATH_FETCH_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
557                            CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
558                            FINDER_CLASS_NAME_ENTITY, "fetchByA3",
559                            new String[] { String.class.getName() },
560                            CountryModelImpl.A3_COLUMN_BITMASK);
561            public static final FinderPath FINDER_PATH_COUNT_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
562                            CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
563                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA3",
564                            new String[] { String.class.getName() });
565    
566            /**
567             * Returns the country where a3 = &#63; or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
568             *
569             * @param a3 the a3
570             * @return the matching country
571             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
572             * @throws SystemException if a system exception occurred
573             */
574            public Country findByA3(String a3)
575                    throws NoSuchCountryException, SystemException {
576                    Country country = fetchByA3(a3);
577    
578                    if (country == null) {
579                            StringBundler msg = new StringBundler(4);
580    
581                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
582    
583                            msg.append("a3=");
584                            msg.append(a3);
585    
586                            msg.append(StringPool.CLOSE_CURLY_BRACE);
587    
588                            if (_log.isWarnEnabled()) {
589                                    _log.warn(msg.toString());
590                            }
591    
592                            throw new NoSuchCountryException(msg.toString());
593                    }
594    
595                    return country;
596            }
597    
598            /**
599             * Returns the country where a3 = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
600             *
601             * @param a3 the a3
602             * @return the matching country, or <code>null</code> if a matching country could not be found
603             * @throws SystemException if a system exception occurred
604             */
605            public Country fetchByA3(String a3) throws SystemException {
606                    return fetchByA3(a3, true);
607            }
608    
609            /**
610             * Returns the country where a3 = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
611             *
612             * @param a3 the a3
613             * @param retrieveFromCache whether to use the finder cache
614             * @return the matching country, or <code>null</code> if a matching country could not be found
615             * @throws SystemException if a system exception occurred
616             */
617            public Country fetchByA3(String a3, boolean retrieveFromCache)
618                    throws SystemException {
619                    Object[] finderArgs = new Object[] { a3 };
620    
621                    Object result = null;
622    
623                    if (retrieveFromCache) {
624                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
625                                            finderArgs, this);
626                    }
627    
628                    if (result instanceof Country) {
629                            Country country = (Country)result;
630    
631                            if (!Validator.equals(a3, country.getA3())) {
632                                    result = null;
633                            }
634                    }
635    
636                    if (result == null) {
637                            StringBundler query = new StringBundler(3);
638    
639                            query.append(_SQL_SELECT_COUNTRY_WHERE);
640    
641                            boolean bindA3 = false;
642    
643                            if (a3 == null) {
644                                    query.append(_FINDER_COLUMN_A3_A3_1);
645                            }
646                            else if (a3.equals(StringPool.BLANK)) {
647                                    query.append(_FINDER_COLUMN_A3_A3_3);
648                            }
649                            else {
650                                    bindA3 = true;
651    
652                                    query.append(_FINDER_COLUMN_A3_A3_2);
653                            }
654    
655                            String sql = query.toString();
656    
657                            Session session = null;
658    
659                            try {
660                                    session = openSession();
661    
662                                    Query q = session.createQuery(sql);
663    
664                                    QueryPos qPos = QueryPos.getInstance(q);
665    
666                                    if (bindA3) {
667                                            qPos.add(a3);
668                                    }
669    
670                                    List<Country> list = q.list();
671    
672                                    if (list.isEmpty()) {
673                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
674                                                    finderArgs, list);
675                                    }
676                                    else {
677                                            Country country = list.get(0);
678    
679                                            result = country;
680    
681                                            cacheResult(country);
682    
683                                            if ((country.getA3() == null) ||
684                                                            !country.getA3().equals(a3)) {
685                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
686                                                            finderArgs, country);
687                                            }
688                                    }
689                            }
690                            catch (Exception e) {
691                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, finderArgs);
692    
693                                    throw processException(e);
694                            }
695                            finally {
696                                    closeSession(session);
697                            }
698                    }
699    
700                    if (result instanceof List<?>) {
701                            return null;
702                    }
703                    else {
704                            return (Country)result;
705                    }
706            }
707    
708            /**
709             * Removes the country where a3 = &#63; from the database.
710             *
711             * @param a3 the a3
712             * @return the country that was removed
713             * @throws SystemException if a system exception occurred
714             */
715            public Country removeByA3(String a3)
716                    throws NoSuchCountryException, SystemException {
717                    Country country = findByA3(a3);
718    
719                    return remove(country);
720            }
721    
722            /**
723             * Returns the number of countries where a3 = &#63;.
724             *
725             * @param a3 the a3
726             * @return the number of matching countries
727             * @throws SystemException if a system exception occurred
728             */
729            public int countByA3(String a3) throws SystemException {
730                    FinderPath finderPath = FINDER_PATH_COUNT_BY_A3;
731    
732                    Object[] finderArgs = new Object[] { a3 };
733    
734                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
735                                    this);
736    
737                    if (count == null) {
738                            StringBundler query = new StringBundler(2);
739    
740                            query.append(_SQL_COUNT_COUNTRY_WHERE);
741    
742                            boolean bindA3 = false;
743    
744                            if (a3 == null) {
745                                    query.append(_FINDER_COLUMN_A3_A3_1);
746                            }
747                            else if (a3.equals(StringPool.BLANK)) {
748                                    query.append(_FINDER_COLUMN_A3_A3_3);
749                            }
750                            else {
751                                    bindA3 = true;
752    
753                                    query.append(_FINDER_COLUMN_A3_A3_2);
754                            }
755    
756                            String sql = query.toString();
757    
758                            Session session = null;
759    
760                            try {
761                                    session = openSession();
762    
763                                    Query q = session.createQuery(sql);
764    
765                                    QueryPos qPos = QueryPos.getInstance(q);
766    
767                                    if (bindA3) {
768                                            qPos.add(a3);
769                                    }
770    
771                                    count = (Long)q.uniqueResult();
772    
773                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
774                            }
775                            catch (Exception e) {
776                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
777    
778                                    throw processException(e);
779                            }
780                            finally {
781                                    closeSession(session);
782                            }
783                    }
784    
785                    return count.intValue();
786            }
787    
788            private static final String _FINDER_COLUMN_A3_A3_1 = "country.a3 IS NULL";
789            private static final String _FINDER_COLUMN_A3_A3_2 = "country.a3 = ?";
790            private static final String _FINDER_COLUMN_A3_A3_3 = "(country.a3 IS NULL OR country.a3 = '')";
791            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
792                            CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
793                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
794                            new String[] {
795                                    Boolean.class.getName(),
796                                    
797                            Integer.class.getName(), Integer.class.getName(),
798                                    OrderByComparator.class.getName()
799                            });
800            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
801                    new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
802                            CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
803                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
804                            new String[] { Boolean.class.getName() },
805                            CountryModelImpl.ACTIVE_COLUMN_BITMASK |
806                            CountryModelImpl.NAME_COLUMN_BITMASK);
807            public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
808                            CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
809                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
810                            new String[] { Boolean.class.getName() });
811    
812            /**
813             * Returns all the countries where active = &#63;.
814             *
815             * @param active the active
816             * @return the matching countries
817             * @throws SystemException if a system exception occurred
818             */
819            public List<Country> findByActive(boolean active) throws SystemException {
820                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
821            }
822    
823            /**
824             * Returns a range of all the countries where active = &#63;.
825             *
826             * <p>
827             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.CountryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
828             * </p>
829             *
830             * @param active the active
831             * @param start the lower bound of the range of countries
832             * @param end the upper bound of the range of countries (not inclusive)
833             * @return the range of matching countries
834             * @throws SystemException if a system exception occurred
835             */
836            public List<Country> findByActive(boolean active, int start, int end)
837                    throws SystemException {
838                    return findByActive(active, start, end, null);
839            }
840    
841            /**
842             * Returns an ordered range of all the countries where active = &#63;.
843             *
844             * <p>
845             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.CountryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
846             * </p>
847             *
848             * @param active the active
849             * @param start the lower bound of the range of countries
850             * @param end the upper bound of the range of countries (not inclusive)
851             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
852             * @return the ordered range of matching countries
853             * @throws SystemException if a system exception occurred
854             */
855            public List<Country> findByActive(boolean active, int start, int end,
856                    OrderByComparator orderByComparator) throws SystemException {
857                    boolean pagination = true;
858                    FinderPath finderPath = null;
859                    Object[] finderArgs = null;
860    
861                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
862                                    (orderByComparator == null)) {
863                            pagination = false;
864                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
865                            finderArgs = new Object[] { active };
866                    }
867                    else {
868                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
869                            finderArgs = new Object[] { active, start, end, orderByComparator };
870                    }
871    
872                    List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
873                                    finderArgs, this);
874    
875                    if ((list != null) && !list.isEmpty()) {
876                            for (Country country : list) {
877                                    if ((active != country.getActive())) {
878                                            list = null;
879    
880                                            break;
881                                    }
882                            }
883                    }
884    
885                    if (list == null) {
886                            StringBundler query = null;
887    
888                            if (orderByComparator != null) {
889                                    query = new StringBundler(3 +
890                                                    (orderByComparator.getOrderByFields().length * 3));
891                            }
892                            else {
893                                    query = new StringBundler(3);
894                            }
895    
896                            query.append(_SQL_SELECT_COUNTRY_WHERE);
897    
898                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
899    
900                            if (orderByComparator != null) {
901                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
902                                            orderByComparator);
903                            }
904                            else
905                             if (pagination) {
906                                    query.append(CountryModelImpl.ORDER_BY_JPQL);
907                            }
908    
909                            String sql = query.toString();
910    
911                            Session session = null;
912    
913                            try {
914                                    session = openSession();
915    
916                                    Query q = session.createQuery(sql);
917    
918                                    QueryPos qPos = QueryPos.getInstance(q);
919    
920                                    qPos.add(active);
921    
922                                    if (!pagination) {
923                                            list = (List<Country>)QueryUtil.list(q, getDialect(),
924                                                            start, end, false);
925    
926                                            Collections.sort(list);
927    
928                                            list = new UnmodifiableList<Country>(list);
929                                    }
930                                    else {
931                                            list = (List<Country>)QueryUtil.list(q, getDialect(),
932                                                            start, end);
933                                    }
934    
935                                    cacheResult(list);
936    
937                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
938                            }
939                            catch (Exception e) {
940                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
941    
942                                    throw processException(e);
943                            }
944                            finally {
945                                    closeSession(session);
946                            }
947                    }
948    
949                    return list;
950            }
951    
952            /**
953             * Returns the first country in the ordered set where active = &#63;.
954             *
955             * @param active the active
956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
957             * @return the first matching country
958             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
959             * @throws SystemException if a system exception occurred
960             */
961            public Country findByActive_First(boolean active,
962                    OrderByComparator orderByComparator)
963                    throws NoSuchCountryException, SystemException {
964                    Country country = fetchByActive_First(active, orderByComparator);
965    
966                    if (country != null) {
967                            return country;
968                    }
969    
970                    StringBundler msg = new StringBundler(4);
971    
972                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
973    
974                    msg.append("active=");
975                    msg.append(active);
976    
977                    msg.append(StringPool.CLOSE_CURLY_BRACE);
978    
979                    throw new NoSuchCountryException(msg.toString());
980            }
981    
982            /**
983             * Returns the first country in the ordered set where active = &#63;.
984             *
985             * @param active the active
986             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
987             * @return the first matching country, or <code>null</code> if a matching country could not be found
988             * @throws SystemException if a system exception occurred
989             */
990            public Country fetchByActive_First(boolean active,
991                    OrderByComparator orderByComparator) throws SystemException {
992                    List<Country> list = findByActive(active, 0, 1, orderByComparator);
993    
994                    if (!list.isEmpty()) {
995                            return list.get(0);
996                    }
997    
998                    return null;
999            }
1000    
1001            /**
1002             * Returns the last country in the ordered set where active = &#63;.
1003             *
1004             * @param active the active
1005             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1006             * @return the last matching country
1007             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
1008             * @throws SystemException if a system exception occurred
1009             */
1010            public Country findByActive_Last(boolean active,
1011                    OrderByComparator orderByComparator)
1012                    throws NoSuchCountryException, SystemException {
1013                    Country country = fetchByActive_Last(active, orderByComparator);
1014    
1015                    if (country != null) {
1016                            return country;
1017                    }
1018    
1019                    StringBundler msg = new StringBundler(4);
1020    
1021                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1022    
1023                    msg.append("active=");
1024                    msg.append(active);
1025    
1026                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1027    
1028                    throw new NoSuchCountryException(msg.toString());
1029            }
1030    
1031            /**
1032             * Returns the last country in the ordered set where active = &#63;.
1033             *
1034             * @param active the active
1035             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1036             * @return the last matching country, or <code>null</code> if a matching country could not be found
1037             * @throws SystemException if a system exception occurred
1038             */
1039            public Country fetchByActive_Last(boolean active,
1040                    OrderByComparator orderByComparator) throws SystemException {
1041                    int count = countByActive(active);
1042    
1043                    List<Country> list = findByActive(active, count - 1, count,
1044                                    orderByComparator);
1045    
1046                    if (!list.isEmpty()) {
1047                            return list.get(0);
1048                    }
1049    
1050                    return null;
1051            }
1052    
1053            /**
1054             * Returns the countries before and after the current country in the ordered set where active = &#63;.
1055             *
1056             * @param countryId the primary key of the current country
1057             * @param active the active
1058             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1059             * @return the previous, current, and next country
1060             * @throws com.liferay.portal.NoSuchCountryException if a country with the primary key could not be found
1061             * @throws SystemException if a system exception occurred
1062             */
1063            public Country[] findByActive_PrevAndNext(long countryId, boolean active,
1064                    OrderByComparator orderByComparator)
1065                    throws NoSuchCountryException, SystemException {
1066                    Country country = findByPrimaryKey(countryId);
1067    
1068                    Session session = null;
1069    
1070                    try {
1071                            session = openSession();
1072    
1073                            Country[] array = new CountryImpl[3];
1074    
1075                            array[0] = getByActive_PrevAndNext(session, country, active,
1076                                            orderByComparator, true);
1077    
1078                            array[1] = country;
1079    
1080                            array[2] = getByActive_PrevAndNext(session, country, active,
1081                                            orderByComparator, false);
1082    
1083                            return array;
1084                    }
1085                    catch (Exception e) {
1086                            throw processException(e);
1087                    }
1088                    finally {
1089                            closeSession(session);
1090                    }
1091            }
1092    
1093            protected Country getByActive_PrevAndNext(Session session, Country country,
1094                    boolean active, OrderByComparator orderByComparator, boolean previous) {
1095                    StringBundler query = null;
1096    
1097                    if (orderByComparator != null) {
1098                            query = new StringBundler(6 +
1099                                            (orderByComparator.getOrderByFields().length * 6));
1100                    }
1101                    else {
1102                            query = new StringBundler(3);
1103                    }
1104    
1105                    query.append(_SQL_SELECT_COUNTRY_WHERE);
1106    
1107                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1108    
1109                    if (orderByComparator != null) {
1110                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1111    
1112                            if (orderByConditionFields.length > 0) {
1113                                    query.append(WHERE_AND);
1114                            }
1115    
1116                            for (int i = 0; i < orderByConditionFields.length; i++) {
1117                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1118                                    query.append(orderByConditionFields[i]);
1119    
1120                                    if ((i + 1) < orderByConditionFields.length) {
1121                                            if (orderByComparator.isAscending() ^ previous) {
1122                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1123                                            }
1124                                            else {
1125                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1126                                            }
1127                                    }
1128                                    else {
1129                                            if (orderByComparator.isAscending() ^ previous) {
1130                                                    query.append(WHERE_GREATER_THAN);
1131                                            }
1132                                            else {
1133                                                    query.append(WHERE_LESSER_THAN);
1134                                            }
1135                                    }
1136                            }
1137    
1138                            query.append(ORDER_BY_CLAUSE);
1139    
1140                            String[] orderByFields = orderByComparator.getOrderByFields();
1141    
1142                            for (int i = 0; i < orderByFields.length; i++) {
1143                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1144                                    query.append(orderByFields[i]);
1145    
1146                                    if ((i + 1) < orderByFields.length) {
1147                                            if (orderByComparator.isAscending() ^ previous) {
1148                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1149                                            }
1150                                            else {
1151                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1152                                            }
1153                                    }
1154                                    else {
1155                                            if (orderByComparator.isAscending() ^ previous) {
1156                                                    query.append(ORDER_BY_ASC);
1157                                            }
1158                                            else {
1159                                                    query.append(ORDER_BY_DESC);
1160                                            }
1161                                    }
1162                            }
1163                    }
1164                    else {
1165                            query.append(CountryModelImpl.ORDER_BY_JPQL);
1166                    }
1167    
1168                    String sql = query.toString();
1169    
1170                    Query q = session.createQuery(sql);
1171    
1172                    q.setFirstResult(0);
1173                    q.setMaxResults(2);
1174    
1175                    QueryPos qPos = QueryPos.getInstance(q);
1176    
1177                    qPos.add(active);
1178    
1179                    if (orderByComparator != null) {
1180                            Object[] values = orderByComparator.getOrderByConditionValues(country);
1181    
1182                            for (Object value : values) {
1183                                    qPos.add(value);
1184                            }
1185                    }
1186    
1187                    List<Country> list = q.list();
1188    
1189                    if (list.size() == 2) {
1190                            return list.get(1);
1191                    }
1192                    else {
1193                            return null;
1194                    }
1195            }
1196    
1197            /**
1198             * Removes all the countries where active = &#63; from the database.
1199             *
1200             * @param active the active
1201             * @throws SystemException if a system exception occurred
1202             */
1203            public void removeByActive(boolean active) throws SystemException {
1204                    for (Country country : findByActive(active, QueryUtil.ALL_POS,
1205                                    QueryUtil.ALL_POS, null)) {
1206                            remove(country);
1207                    }
1208            }
1209    
1210            /**
1211             * Returns the number of countries where active = &#63;.
1212             *
1213             * @param active the active
1214             * @return the number of matching countries
1215             * @throws SystemException if a system exception occurred
1216             */
1217            public int countByActive(boolean active) throws SystemException {
1218                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1219    
1220                    Object[] finderArgs = new Object[] { active };
1221    
1222                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1223                                    this);
1224    
1225                    if (count == null) {
1226                            StringBundler query = new StringBundler(2);
1227    
1228                            query.append(_SQL_COUNT_COUNTRY_WHERE);
1229    
1230                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1231    
1232                            String sql = query.toString();
1233    
1234                            Session session = null;
1235    
1236                            try {
1237                                    session = openSession();
1238    
1239                                    Query q = session.createQuery(sql);
1240    
1241                                    QueryPos qPos = QueryPos.getInstance(q);
1242    
1243                                    qPos.add(active);
1244    
1245                                    count = (Long)q.uniqueResult();
1246    
1247                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1248                            }
1249                            catch (Exception e) {
1250                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1251    
1252                                    throw processException(e);
1253                            }
1254                            finally {
1255                                    closeSession(session);
1256                            }
1257                    }
1258    
1259                    return count.intValue();
1260            }
1261    
1262            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "country.active = ?";
1263    
1264            /**
1265             * Caches the country in the entity cache if it is enabled.
1266             *
1267             * @param country the country
1268             */
1269            public void cacheResult(Country country) {
1270                    EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1271                            CountryImpl.class, country.getPrimaryKey(), country);
1272    
1273                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
1274                            new Object[] { country.getName() }, country);
1275    
1276                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
1277                            new Object[] { country.getA2() }, country);
1278    
1279                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
1280                            new Object[] { country.getA3() }, country);
1281    
1282                    country.resetOriginalValues();
1283            }
1284    
1285            /**
1286             * Caches the countries in the entity cache if it is enabled.
1287             *
1288             * @param countries the countries
1289             */
1290            public void cacheResult(List<Country> countries) {
1291                    for (Country country : countries) {
1292                            if (EntityCacheUtil.getResult(
1293                                                    CountryModelImpl.ENTITY_CACHE_ENABLED,
1294                                                    CountryImpl.class, country.getPrimaryKey()) == null) {
1295                                    cacheResult(country);
1296                            }
1297                            else {
1298                                    country.resetOriginalValues();
1299                            }
1300                    }
1301            }
1302    
1303            /**
1304             * Clears the cache for all countries.
1305             *
1306             * <p>
1307             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1308             * </p>
1309             */
1310            @Override
1311            public void clearCache() {
1312                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1313                            CacheRegistryUtil.clear(CountryImpl.class.getName());
1314                    }
1315    
1316                    EntityCacheUtil.clearCache(CountryImpl.class.getName());
1317    
1318                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1319                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1320                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1321            }
1322    
1323            /**
1324             * Clears the cache for the country.
1325             *
1326             * <p>
1327             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1328             * </p>
1329             */
1330            @Override
1331            public void clearCache(Country country) {
1332                    EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1333                            CountryImpl.class, country.getPrimaryKey());
1334    
1335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1336                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1337    
1338                    clearUniqueFindersCache(country);
1339            }
1340    
1341            @Override
1342            public void clearCache(List<Country> countries) {
1343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1344                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1345    
1346                    for (Country country : countries) {
1347                            EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1348                                    CountryImpl.class, country.getPrimaryKey());
1349    
1350                            clearUniqueFindersCache(country);
1351                    }
1352            }
1353    
1354            protected void cacheUniqueFindersCache(Country country) {
1355                    if (country.isNew()) {
1356                            Object[] args = new Object[] { country.getName() };
1357    
1358                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1359                                    Long.valueOf(1));
1360                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args, country);
1361    
1362                            args = new Object[] { country.getA2() };
1363    
1364                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1365                                    Long.valueOf(1));
1366                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1367    
1368                            args = new Object[] { country.getA3() };
1369    
1370                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1371                                    Long.valueOf(1));
1372                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1373                    }
1374                    else {
1375                            CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1376    
1377                            if ((countryModelImpl.getColumnBitmask() &
1378                                            FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1379                                    Object[] args = new Object[] { country.getName() };
1380    
1381                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1382                                            Long.valueOf(1));
1383                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1384                                            country);
1385                            }
1386    
1387                            if ((countryModelImpl.getColumnBitmask() &
1388                                            FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1389                                    Object[] args = new Object[] { country.getA2() };
1390    
1391                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1392                                            Long.valueOf(1));
1393                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1394                            }
1395    
1396                            if ((countryModelImpl.getColumnBitmask() &
1397                                            FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1398                                    Object[] args = new Object[] { country.getA3() };
1399    
1400                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1401                                            Long.valueOf(1));
1402                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1403                            }
1404                    }
1405            }
1406    
1407            protected void clearUniqueFindersCache(Country country) {
1408                    CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1409    
1410                    Object[] args = new Object[] { country.getName() };
1411    
1412                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1413                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1414    
1415                    if ((countryModelImpl.getColumnBitmask() &
1416                                    FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1417                            args = new Object[] { countryModelImpl.getOriginalName() };
1418    
1419                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1420                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1421                    }
1422    
1423                    args = new Object[] { country.getA2() };
1424    
1425                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1426                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1427    
1428                    if ((countryModelImpl.getColumnBitmask() &
1429                                    FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1430                            args = new Object[] { countryModelImpl.getOriginalA2() };
1431    
1432                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1433                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1434                    }
1435    
1436                    args = new Object[] { country.getA3() };
1437    
1438                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1439                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1440    
1441                    if ((countryModelImpl.getColumnBitmask() &
1442                                    FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1443                            args = new Object[] { countryModelImpl.getOriginalA3() };
1444    
1445                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1446                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1447                    }
1448            }
1449    
1450            /**
1451             * Creates a new country with the primary key. Does not add the country to the database.
1452             *
1453             * @param countryId the primary key for the new country
1454             * @return the new country
1455             */
1456            public Country create(long countryId) {
1457                    Country country = new CountryImpl();
1458    
1459                    country.setNew(true);
1460                    country.setPrimaryKey(countryId);
1461    
1462                    return country;
1463            }
1464    
1465            /**
1466             * Removes the country with the primary key from the database. Also notifies the appropriate model listeners.
1467             *
1468             * @param countryId the primary key of the country
1469             * @return the country that was removed
1470             * @throws com.liferay.portal.NoSuchCountryException if a country with the primary key could not be found
1471             * @throws SystemException if a system exception occurred
1472             */
1473            public Country remove(long countryId)
1474                    throws NoSuchCountryException, SystemException {
1475                    return remove((Serializable)countryId);
1476            }
1477    
1478            /**
1479             * Removes the country with the primary key from the database. Also notifies the appropriate model listeners.
1480             *
1481             * @param primaryKey the primary key of the country
1482             * @return the country that was removed
1483             * @throws com.liferay.portal.NoSuchCountryException if a country with the primary key could not be found
1484             * @throws SystemException if a system exception occurred
1485             */
1486            @Override
1487            public Country remove(Serializable primaryKey)
1488                    throws NoSuchCountryException, SystemException {
1489                    Session session = null;
1490    
1491                    try {
1492                            session = openSession();
1493    
1494                            Country country = (Country)session.get(CountryImpl.class, primaryKey);
1495    
1496                            if (country == null) {
1497                                    if (_log.isWarnEnabled()) {
1498                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1499                                    }
1500    
1501                                    throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1502                                            primaryKey);
1503                            }
1504    
1505                            return remove(country);
1506                    }
1507                    catch (NoSuchCountryException nsee) {
1508                            throw nsee;
1509                    }
1510                    catch (Exception e) {
1511                            throw processException(e);
1512                    }
1513                    finally {
1514                            closeSession(session);
1515                    }
1516            }
1517    
1518            @Override
1519            protected Country removeImpl(Country country) throws SystemException {
1520                    country = toUnwrappedModel(country);
1521    
1522                    Session session = null;
1523    
1524                    try {
1525                            session = openSession();
1526    
1527                            if (!session.contains(country)) {
1528                                    country = (Country)session.get(CountryImpl.class,
1529                                                    country.getPrimaryKeyObj());
1530                            }
1531    
1532                            if (country != null) {
1533                                    session.delete(country);
1534                            }
1535                    }
1536                    catch (Exception e) {
1537                            throw processException(e);
1538                    }
1539                    finally {
1540                            closeSession(session);
1541                    }
1542    
1543                    if (country != null) {
1544                            clearCache(country);
1545                    }
1546    
1547                    return country;
1548            }
1549    
1550            @Override
1551            public Country updateImpl(com.liferay.portal.model.Country country)
1552                    throws SystemException {
1553                    country = toUnwrappedModel(country);
1554    
1555                    boolean isNew = country.isNew();
1556    
1557                    CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1558    
1559                    Session session = null;
1560    
1561                    try {
1562                            session = openSession();
1563    
1564                            if (country.isNew()) {
1565                                    session.save(country);
1566    
1567                                    country.setNew(false);
1568                            }
1569                            else {
1570                                    session.merge(country);
1571                            }
1572                    }
1573                    catch (Exception e) {
1574                            throw processException(e);
1575                    }
1576                    finally {
1577                            closeSession(session);
1578                    }
1579    
1580                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1581    
1582                    if (isNew || !CountryModelImpl.COLUMN_BITMASK_ENABLED) {
1583                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1584                    }
1585    
1586                    else {
1587                            if ((countryModelImpl.getColumnBitmask() &
1588                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
1589                                    Object[] args = new Object[] {
1590                                                    countryModelImpl.getOriginalActive()
1591                                            };
1592    
1593                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1594                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1595                                            args);
1596    
1597                                    args = new Object[] { countryModelImpl.getActive() };
1598    
1599                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1600                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1601                                            args);
1602                            }
1603                    }
1604    
1605                    EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1606                            CountryImpl.class, country.getPrimaryKey(), country);
1607    
1608                    clearUniqueFindersCache(country);
1609                    cacheUniqueFindersCache(country);
1610    
1611                    return country;
1612            }
1613    
1614            protected Country toUnwrappedModel(Country country) {
1615                    if (country instanceof CountryImpl) {
1616                            return country;
1617                    }
1618    
1619                    CountryImpl countryImpl = new CountryImpl();
1620    
1621                    countryImpl.setNew(country.isNew());
1622                    countryImpl.setPrimaryKey(country.getPrimaryKey());
1623    
1624                    countryImpl.setCountryId(country.getCountryId());
1625                    countryImpl.setName(country.getName());
1626                    countryImpl.setA2(country.getA2());
1627                    countryImpl.setA3(country.getA3());
1628                    countryImpl.setNumber(country.getNumber());
1629                    countryImpl.setIdd(country.getIdd());
1630                    countryImpl.setZipRequired(country.isZipRequired());
1631                    countryImpl.setActive(country.isActive());
1632    
1633                    return countryImpl;
1634            }
1635    
1636            /**
1637             * Returns the country with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1638             *
1639             * @param primaryKey the primary key of the country
1640             * @return the country
1641             * @throws com.liferay.portal.NoSuchCountryException if a country with the primary key could not be found
1642             * @throws SystemException if a system exception occurred
1643             */
1644            @Override
1645            public Country findByPrimaryKey(Serializable primaryKey)
1646                    throws NoSuchCountryException, SystemException {
1647                    Country country = fetchByPrimaryKey(primaryKey);
1648    
1649                    if (country == null) {
1650                            if (_log.isWarnEnabled()) {
1651                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1652                            }
1653    
1654                            throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1655                                    primaryKey);
1656                    }
1657    
1658                    return country;
1659            }
1660    
1661            /**
1662             * Returns the country with the primary key or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
1663             *
1664             * @param countryId the primary key of the country
1665             * @return the country
1666             * @throws com.liferay.portal.NoSuchCountryException if a country with the primary key could not be found
1667             * @throws SystemException if a system exception occurred
1668             */
1669            public Country findByPrimaryKey(long countryId)
1670                    throws NoSuchCountryException, SystemException {
1671                    return findByPrimaryKey((Serializable)countryId);
1672            }
1673    
1674            /**
1675             * Returns the country with the primary key or returns <code>null</code> if it could not be found.
1676             *
1677             * @param primaryKey the primary key of the country
1678             * @return the country, or <code>null</code> if a country with the primary key could not be found
1679             * @throws SystemException if a system exception occurred
1680             */
1681            @Override
1682            public Country fetchByPrimaryKey(Serializable primaryKey)
1683                    throws SystemException {
1684                    Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1685                                    CountryImpl.class, primaryKey);
1686    
1687                    if (country == _nullCountry) {
1688                            return null;
1689                    }
1690    
1691                    if (country == null) {
1692                            Session session = null;
1693    
1694                            try {
1695                                    session = openSession();
1696    
1697                                    country = (Country)session.get(CountryImpl.class, primaryKey);
1698    
1699                                    if (country != null) {
1700                                            cacheResult(country);
1701                                    }
1702                                    else {
1703                                            EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1704                                                    CountryImpl.class, primaryKey, _nullCountry);
1705                                    }
1706                            }
1707                            catch (Exception e) {
1708                                    EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1709                                            CountryImpl.class, primaryKey);
1710    
1711                                    throw processException(e);
1712                            }
1713                            finally {
1714                                    closeSession(session);
1715                            }
1716                    }
1717    
1718                    return country;
1719            }
1720    
1721            /**
1722             * Returns the country with the primary key or returns <code>null</code> if it could not be found.
1723             *
1724             * @param countryId the primary key of the country
1725             * @return the country, or <code>null</code> if a country with the primary key could not be found
1726             * @throws SystemException if a system exception occurred
1727             */
1728            public Country fetchByPrimaryKey(long countryId) throws SystemException {
1729                    return fetchByPrimaryKey((Serializable)countryId);
1730            }
1731    
1732            /**
1733             * Returns all the countries.
1734             *
1735             * @return the countries
1736             * @throws SystemException if a system exception occurred
1737             */
1738            public List<Country> findAll() throws SystemException {
1739                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1740            }
1741    
1742            /**
1743             * Returns a range of all the countries.
1744             *
1745             * <p>
1746             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.CountryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1747             * </p>
1748             *
1749             * @param start the lower bound of the range of countries
1750             * @param end the upper bound of the range of countries (not inclusive)
1751             * @return the range of countries
1752             * @throws SystemException if a system exception occurred
1753             */
1754            public List<Country> findAll(int start, int end) throws SystemException {
1755                    return findAll(start, end, null);
1756            }
1757    
1758            /**
1759             * Returns an ordered range of all the countries.
1760             *
1761             * <p>
1762             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.CountryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1763             * </p>
1764             *
1765             * @param start the lower bound of the range of countries
1766             * @param end the upper bound of the range of countries (not inclusive)
1767             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1768             * @return the ordered range of countries
1769             * @throws SystemException if a system exception occurred
1770             */
1771            public List<Country> findAll(int start, int end,
1772                    OrderByComparator orderByComparator) throws SystemException {
1773                    boolean pagination = true;
1774                    FinderPath finderPath = null;
1775                    Object[] finderArgs = null;
1776    
1777                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1778                                    (orderByComparator == null)) {
1779                            pagination = false;
1780                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1781                            finderArgs = FINDER_ARGS_EMPTY;
1782                    }
1783                    else {
1784                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1785                            finderArgs = new Object[] { start, end, orderByComparator };
1786                    }
1787    
1788                    List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
1789                                    finderArgs, this);
1790    
1791                    if (list == null) {
1792                            StringBundler query = null;
1793                            String sql = null;
1794    
1795                            if (orderByComparator != null) {
1796                                    query = new StringBundler(2 +
1797                                                    (orderByComparator.getOrderByFields().length * 3));
1798    
1799                                    query.append(_SQL_SELECT_COUNTRY);
1800    
1801                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1802                                            orderByComparator);
1803    
1804                                    sql = query.toString();
1805                            }
1806                            else {
1807                                    sql = _SQL_SELECT_COUNTRY;
1808    
1809                                    if (pagination) {
1810                                            sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
1811                                    }
1812                            }
1813    
1814                            Session session = null;
1815    
1816                            try {
1817                                    session = openSession();
1818    
1819                                    Query q = session.createQuery(sql);
1820    
1821                                    if (!pagination) {
1822                                            list = (List<Country>)QueryUtil.list(q, getDialect(),
1823                                                            start, end, false);
1824    
1825                                            Collections.sort(list);
1826    
1827                                            list = new UnmodifiableList<Country>(list);
1828                                    }
1829                                    else {
1830                                            list = (List<Country>)QueryUtil.list(q, getDialect(),
1831                                                            start, end);
1832                                    }
1833    
1834                                    cacheResult(list);
1835    
1836                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1837                            }
1838                            catch (Exception e) {
1839                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1840    
1841                                    throw processException(e);
1842                            }
1843                            finally {
1844                                    closeSession(session);
1845                            }
1846                    }
1847    
1848                    return list;
1849            }
1850    
1851            /**
1852             * Removes all the countries from the database.
1853             *
1854             * @throws SystemException if a system exception occurred
1855             */
1856            public void removeAll() throws SystemException {
1857                    for (Country country : findAll()) {
1858                            remove(country);
1859                    }
1860            }
1861    
1862            /**
1863             * Returns the number of countries.
1864             *
1865             * @return the number of countries
1866             * @throws SystemException if a system exception occurred
1867             */
1868            public int countAll() throws SystemException {
1869                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1870                                    FINDER_ARGS_EMPTY, this);
1871    
1872                    if (count == null) {
1873                            Session session = null;
1874    
1875                            try {
1876                                    session = openSession();
1877    
1878                                    Query q = session.createQuery(_SQL_COUNT_COUNTRY);
1879    
1880                                    count = (Long)q.uniqueResult();
1881    
1882                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1883                                            FINDER_ARGS_EMPTY, count);
1884                            }
1885                            catch (Exception e) {
1886                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1887                                            FINDER_ARGS_EMPTY);
1888    
1889                                    throw processException(e);
1890                            }
1891                            finally {
1892                                    closeSession(session);
1893                            }
1894                    }
1895    
1896                    return count.intValue();
1897            }
1898    
1899            @Override
1900            protected Set<String> getBadColumnNames() {
1901                    return _badColumnNames;
1902            }
1903    
1904            /**
1905             * Initializes the country persistence.
1906             */
1907            public void afterPropertiesSet() {
1908                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1909                                            com.liferay.portal.util.PropsUtil.get(
1910                                                    "value.object.listener.com.liferay.portal.model.Country")));
1911    
1912                    if (listenerClassNames.length > 0) {
1913                            try {
1914                                    List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1915    
1916                                    for (String listenerClassName : listenerClassNames) {
1917                                            listenersList.add((ModelListener<Country>)InstanceFactory.newInstance(
1918                                                            getClassLoader(), listenerClassName));
1919                                    }
1920    
1921                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1922                            }
1923                            catch (Exception e) {
1924                                    _log.error(e);
1925                            }
1926                    }
1927            }
1928    
1929            public void destroy() {
1930                    EntityCacheUtil.removeCache(CountryImpl.class.getName());
1931                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1932                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1933                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1934            }
1935    
1936            private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
1937            private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
1938            private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
1939            private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
1940            private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
1941            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
1942            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
1943            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1944            private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1945            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1946                                    "number", "idd", "active"
1947                            });
1948            private static Country _nullCountry = new CountryImpl() {
1949                            @Override
1950                            public Object clone() {
1951                                    return this;
1952                            }
1953    
1954                            @Override
1955                            public CacheModel<Country> toCacheModel() {
1956                                    return _nullCountryCacheModel;
1957                            }
1958                    };
1959    
1960            private static CacheModel<Country> _nullCountryCacheModel = new CacheModel<Country>() {
1961                            public Country toEntityModel() {
1962                                    return _nullCountry;
1963                            }
1964                    };
1965    }