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