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