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