001    /**
002     * Copyright (c) 2000-2010 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                            if (country.isCachedModel() || BatchSessionUtil.isEnabled()) {
254                                    Object staleObject = session.get(CountryImpl.class,
255                                                    country.getPrimaryKeyObj());
256    
257                                    if (staleObject != null) {
258                                            session.evict(staleObject);
259                                    }
260                            }
261    
262                            session.delete(country);
263    
264                            session.flush();
265                    }
266                    catch (Exception e) {
267                            throw processException(e);
268                    }
269                    finally {
270                            closeSession(session);
271                    }
272    
273                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
274    
275                    CountryModelImpl countryModelImpl = (CountryModelImpl)country;
276    
277                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
278                            new Object[] { countryModelImpl.getOriginalName() });
279    
280                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2,
281                            new Object[] { countryModelImpl.getOriginalA2() });
282    
283                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3,
284                            new Object[] { countryModelImpl.getOriginalA3() });
285    
286                    EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
287                            CountryImpl.class, country.getPrimaryKey());
288    
289                    return country;
290            }
291    
292            public Country updateImpl(com.liferay.portal.model.Country country,
293                    boolean merge) throws SystemException {
294                    country = toUnwrappedModel(country);
295    
296                    boolean isNew = country.isNew();
297    
298                    CountryModelImpl countryModelImpl = (CountryModelImpl)country;
299    
300                    Session session = null;
301    
302                    try {
303                            session = openSession();
304    
305                            BatchSessionUtil.update(session, country, merge);
306    
307                            country.setNew(false);
308                    }
309                    catch (Exception e) {
310                            throw processException(e);
311                    }
312                    finally {
313                            closeSession(session);
314                    }
315    
316                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
317    
318                    EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
319                            CountryImpl.class, country.getPrimaryKey(), country);
320    
321                    if (!isNew &&
322                                    (!Validator.equals(country.getName(),
323                                            countryModelImpl.getOriginalName()))) {
324                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
325                                    new Object[] { countryModelImpl.getOriginalName() });
326                    }
327    
328                    if (isNew ||
329                                    (!Validator.equals(country.getName(),
330                                            countryModelImpl.getOriginalName()))) {
331                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
332                                    new Object[] { country.getName() }, country);
333                    }
334    
335                    if (!isNew &&
336                                    (!Validator.equals(country.getA2(),
337                                            countryModelImpl.getOriginalA2()))) {
338                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2,
339                                    new Object[] { countryModelImpl.getOriginalA2() });
340                    }
341    
342                    if (isNew ||
343                                    (!Validator.equals(country.getA2(),
344                                            countryModelImpl.getOriginalA2()))) {
345                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
346                                    new Object[] { country.getA2() }, country);
347                    }
348    
349                    if (!isNew &&
350                                    (!Validator.equals(country.getA3(),
351                                            countryModelImpl.getOriginalA3()))) {
352                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3,
353                                    new Object[] { countryModelImpl.getOriginalA3() });
354                    }
355    
356                    if (isNew ||
357                                    (!Validator.equals(country.getA3(),
358                                            countryModelImpl.getOriginalA3()))) {
359                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
360                                    new Object[] { country.getA3() }, country);
361                    }
362    
363                    return country;
364            }
365    
366            protected Country toUnwrappedModel(Country country) {
367                    if (country instanceof CountryImpl) {
368                            return country;
369                    }
370    
371                    CountryImpl countryImpl = new CountryImpl();
372    
373                    countryImpl.setNew(country.isNew());
374                    countryImpl.setPrimaryKey(country.getPrimaryKey());
375    
376                    countryImpl.setCountryId(country.getCountryId());
377                    countryImpl.setName(country.getName());
378                    countryImpl.setA2(country.getA2());
379                    countryImpl.setA3(country.getA3());
380                    countryImpl.setNumber(country.getNumber());
381                    countryImpl.setIdd(country.getIdd());
382                    countryImpl.setActive(country.isActive());
383    
384                    return countryImpl;
385            }
386    
387            /**
388             * Finds the country with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
389             *
390             * @param primaryKey the primary key of the country to find
391             * @return the country
392             * @throws com.liferay.portal.NoSuchModelException if a country with the primary key could not be found
393             * @throws SystemException if a system exception occurred
394             */
395            public Country findByPrimaryKey(Serializable primaryKey)
396                    throws NoSuchModelException, SystemException {
397                    return findByPrimaryKey(((Long)primaryKey).longValue());
398            }
399    
400            /**
401             * Finds the country with the primary key or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
402             *
403             * @param countryId the primary key of the country to find
404             * @return the country
405             * @throws com.liferay.portal.NoSuchCountryException if a country with the primary key could not be found
406             * @throws SystemException if a system exception occurred
407             */
408            public Country findByPrimaryKey(long countryId)
409                    throws NoSuchCountryException, SystemException {
410                    Country country = fetchByPrimaryKey(countryId);
411    
412                    if (country == null) {
413                            if (_log.isWarnEnabled()) {
414                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + countryId);
415                            }
416    
417                            throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
418                                    countryId);
419                    }
420    
421                    return country;
422            }
423    
424            /**
425             * Finds the country with the primary key or returns <code>null</code> if it could not be found.
426             *
427             * @param primaryKey the primary key of the country to find
428             * @return the country, or <code>null</code> if a country with the primary key could not be found
429             * @throws SystemException if a system exception occurred
430             */
431            public Country fetchByPrimaryKey(Serializable primaryKey)
432                    throws SystemException {
433                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
434            }
435    
436            /**
437             * Finds the country with the primary key or returns <code>null</code> if it could not be found.
438             *
439             * @param countryId the primary key of the country to find
440             * @return the country, or <code>null</code> if a country with the primary key could not be found
441             * @throws SystemException if a system exception occurred
442             */
443            public Country fetchByPrimaryKey(long countryId) throws SystemException {
444                    Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
445                                    CountryImpl.class, countryId, this);
446    
447                    if (country == null) {
448                            Session session = null;
449    
450                            try {
451                                    session = openSession();
452    
453                                    country = (Country)session.get(CountryImpl.class,
454                                                    new Long(countryId));
455                            }
456                            catch (Exception e) {
457                                    throw processException(e);
458                            }
459                            finally {
460                                    if (country != null) {
461                                            cacheResult(country);
462                                    }
463    
464                                    closeSession(session);
465                            }
466                    }
467    
468                    return country;
469            }
470    
471            /**
472             * Finds the country where name = &#63; or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
473             *
474             * @param name the name to search with
475             * @return the matching country
476             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
477             * @throws SystemException if a system exception occurred
478             */
479            public Country findByName(String name)
480                    throws NoSuchCountryException, SystemException {
481                    Country country = fetchByName(name);
482    
483                    if (country == null) {
484                            StringBundler msg = new StringBundler(4);
485    
486                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
487    
488                            msg.append("name=");
489                            msg.append(name);
490    
491                            msg.append(StringPool.CLOSE_CURLY_BRACE);
492    
493                            if (_log.isWarnEnabled()) {
494                                    _log.warn(msg.toString());
495                            }
496    
497                            throw new NoSuchCountryException(msg.toString());
498                    }
499    
500                    return country;
501            }
502    
503            /**
504             * Finds the country where name = &#63; or returns <code>null</code> if it could not be found. Uses 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) throws SystemException {
511                    return fetchByName(name, true);
512            }
513    
514            /**
515             * Finds the country where name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
516             *
517             * @param name the name to search with
518             * @return the matching country, or <code>null</code> if a matching country could not be found
519             * @throws SystemException if a system exception occurred
520             */
521            public Country fetchByName(String name, boolean retrieveFromCache)
522                    throws SystemException {
523                    Object[] finderArgs = new Object[] { name };
524    
525                    Object result = null;
526    
527                    if (retrieveFromCache) {
528                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
529                                            finderArgs, this);
530                    }
531    
532                    if (result == null) {
533                            Session session = null;
534    
535                            try {
536                                    session = openSession();
537    
538                                    StringBundler query = new StringBundler(3);
539    
540                                    query.append(_SQL_SELECT_COUNTRY_WHERE);
541    
542                                    if (name == null) {
543                                            query.append(_FINDER_COLUMN_NAME_NAME_1);
544                                    }
545                                    else {
546                                            if (name.equals(StringPool.BLANK)) {
547                                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
548                                            }
549                                            else {
550                                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
551                                            }
552                                    }
553    
554                                    query.append(CountryModelImpl.ORDER_BY_JPQL);
555    
556                                    String sql = query.toString();
557    
558                                    Query q = session.createQuery(sql);
559    
560                                    QueryPos qPos = QueryPos.getInstance(q);
561    
562                                    if (name != null) {
563                                            qPos.add(name);
564                                    }
565    
566                                    List<Country> list = q.list();
567    
568                                    result = list;
569    
570                                    Country country = null;
571    
572                                    if (list.isEmpty()) {
573                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
574                                                    finderArgs, list);
575                                    }
576                                    else {
577                                            country = list.get(0);
578    
579                                            cacheResult(country);
580    
581                                            if ((country.getName() == null) ||
582                                                            !country.getName().equals(name)) {
583                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
584                                                            finderArgs, country);
585                                            }
586                                    }
587    
588                                    return country;
589                            }
590                            catch (Exception e) {
591                                    throw processException(e);
592                            }
593                            finally {
594                                    if (result == null) {
595                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
596                                                    finderArgs, new ArrayList<Country>());
597                                    }
598    
599                                    closeSession(session);
600                            }
601                    }
602                    else {
603                            if (result instanceof List<?>) {
604                                    return null;
605                            }
606                            else {
607                                    return (Country)result;
608                            }
609                    }
610            }
611    
612            /**
613             * Finds the country where a2 = &#63; or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
614             *
615             * @param a2 the a2 to search with
616             * @return the matching country
617             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
618             * @throws SystemException if a system exception occurred
619             */
620            public Country findByA2(String a2)
621                    throws NoSuchCountryException, SystemException {
622                    Country country = fetchByA2(a2);
623    
624                    if (country == null) {
625                            StringBundler msg = new StringBundler(4);
626    
627                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
628    
629                            msg.append("a2=");
630                            msg.append(a2);
631    
632                            msg.append(StringPool.CLOSE_CURLY_BRACE);
633    
634                            if (_log.isWarnEnabled()) {
635                                    _log.warn(msg.toString());
636                            }
637    
638                            throw new NoSuchCountryException(msg.toString());
639                    }
640    
641                    return country;
642            }
643    
644            /**
645             * Finds the country where a2 = &#63; or returns <code>null</code> if it could not be found. Uses 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) throws SystemException {
652                    return fetchByA2(a2, true);
653            }
654    
655            /**
656             * Finds the country where a2 = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
657             *
658             * @param a2 the a2 to search with
659             * @return the matching country, or <code>null</code> if a matching country could not be found
660             * @throws SystemException if a system exception occurred
661             */
662            public Country fetchByA2(String a2, boolean retrieveFromCache)
663                    throws SystemException {
664                    Object[] finderArgs = new Object[] { a2 };
665    
666                    Object result = null;
667    
668                    if (retrieveFromCache) {
669                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A2,
670                                            finderArgs, this);
671                    }
672    
673                    if (result == null) {
674                            Session session = null;
675    
676                            try {
677                                    session = openSession();
678    
679                                    StringBundler query = new StringBundler(3);
680    
681                                    query.append(_SQL_SELECT_COUNTRY_WHERE);
682    
683                                    if (a2 == null) {
684                                            query.append(_FINDER_COLUMN_A2_A2_1);
685                                    }
686                                    else {
687                                            if (a2.equals(StringPool.BLANK)) {
688                                                    query.append(_FINDER_COLUMN_A2_A2_3);
689                                            }
690                                            else {
691                                                    query.append(_FINDER_COLUMN_A2_A2_2);
692                                            }
693                                    }
694    
695                                    query.append(CountryModelImpl.ORDER_BY_JPQL);
696    
697                                    String sql = query.toString();
698    
699                                    Query q = session.createQuery(sql);
700    
701                                    QueryPos qPos = QueryPos.getInstance(q);
702    
703                                    if (a2 != null) {
704                                            qPos.add(a2);
705                                    }
706    
707                                    List<Country> list = q.list();
708    
709                                    result = list;
710    
711                                    Country country = null;
712    
713                                    if (list.isEmpty()) {
714                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
715                                                    finderArgs, list);
716                                    }
717                                    else {
718                                            country = list.get(0);
719    
720                                            cacheResult(country);
721    
722                                            if ((country.getA2() == null) ||
723                                                            !country.getA2().equals(a2)) {
724                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
725                                                            finderArgs, country);
726                                            }
727                                    }
728    
729                                    return country;
730                            }
731                            catch (Exception e) {
732                                    throw processException(e);
733                            }
734                            finally {
735                                    if (result == null) {
736                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
737                                                    finderArgs, new ArrayList<Country>());
738                                    }
739    
740                                    closeSession(session);
741                            }
742                    }
743                    else {
744                            if (result instanceof List<?>) {
745                                    return null;
746                            }
747                            else {
748                                    return (Country)result;
749                            }
750                    }
751            }
752    
753            /**
754             * Finds the country where a3 = &#63; or throws a {@link com.liferay.portal.NoSuchCountryException} if it could not be found.
755             *
756             * @param a3 the a3 to search with
757             * @return the matching country
758             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
759             * @throws SystemException if a system exception occurred
760             */
761            public Country findByA3(String a3)
762                    throws NoSuchCountryException, SystemException {
763                    Country country = fetchByA3(a3);
764    
765                    if (country == null) {
766                            StringBundler msg = new StringBundler(4);
767    
768                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
769    
770                            msg.append("a3=");
771                            msg.append(a3);
772    
773                            msg.append(StringPool.CLOSE_CURLY_BRACE);
774    
775                            if (_log.isWarnEnabled()) {
776                                    _log.warn(msg.toString());
777                            }
778    
779                            throw new NoSuchCountryException(msg.toString());
780                    }
781    
782                    return country;
783            }
784    
785            /**
786             * Finds the country where a3 = &#63; or returns <code>null</code> if it could not be found. Uses 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) throws SystemException {
793                    return fetchByA3(a3, true);
794            }
795    
796            /**
797             * Finds the country where a3 = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
798             *
799             * @param a3 the a3 to search with
800             * @return the matching country, or <code>null</code> if a matching country could not be found
801             * @throws SystemException if a system exception occurred
802             */
803            public Country fetchByA3(String a3, boolean retrieveFromCache)
804                    throws SystemException {
805                    Object[] finderArgs = new Object[] { a3 };
806    
807                    Object result = null;
808    
809                    if (retrieveFromCache) {
810                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
811                                            finderArgs, this);
812                    }
813    
814                    if (result == null) {
815                            Session session = null;
816    
817                            try {
818                                    session = openSession();
819    
820                                    StringBundler query = new StringBundler(3);
821    
822                                    query.append(_SQL_SELECT_COUNTRY_WHERE);
823    
824                                    if (a3 == null) {
825                                            query.append(_FINDER_COLUMN_A3_A3_1);
826                                    }
827                                    else {
828                                            if (a3.equals(StringPool.BLANK)) {
829                                                    query.append(_FINDER_COLUMN_A3_A3_3);
830                                            }
831                                            else {
832                                                    query.append(_FINDER_COLUMN_A3_A3_2);
833                                            }
834                                    }
835    
836                                    query.append(CountryModelImpl.ORDER_BY_JPQL);
837    
838                                    String sql = query.toString();
839    
840                                    Query q = session.createQuery(sql);
841    
842                                    QueryPos qPos = QueryPos.getInstance(q);
843    
844                                    if (a3 != null) {
845                                            qPos.add(a3);
846                                    }
847    
848                                    List<Country> list = q.list();
849    
850                                    result = list;
851    
852                                    Country country = null;
853    
854                                    if (list.isEmpty()) {
855                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
856                                                    finderArgs, list);
857                                    }
858                                    else {
859                                            country = list.get(0);
860    
861                                            cacheResult(country);
862    
863                                            if ((country.getA3() == null) ||
864                                                            !country.getA3().equals(a3)) {
865                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
866                                                            finderArgs, country);
867                                            }
868                                    }
869    
870                                    return country;
871                            }
872                            catch (Exception e) {
873                                    throw processException(e);
874                            }
875                            finally {
876                                    if (result == null) {
877                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
878                                                    finderArgs, new ArrayList<Country>());
879                                    }
880    
881                                    closeSession(session);
882                            }
883                    }
884                    else {
885                            if (result instanceof List<?>) {
886                                    return null;
887                            }
888                            else {
889                                    return (Country)result;
890                            }
891                    }
892            }
893    
894            /**
895             * Finds all the countries where active = &#63;.
896             *
897             * @param active the active to search with
898             * @return the matching countries
899             * @throws SystemException if a system exception occurred
900             */
901            public List<Country> findByActive(boolean active) throws SystemException {
902                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
903            }
904    
905            /**
906             * Finds a range of all the countries where active = &#63;.
907             *
908             * <p>
909             * 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.
910             * </p>
911             *
912             * @param active the active to search with
913             * @param start the lower bound of the range of countries to return
914             * @param end the upper bound of the range of countries to return (not inclusive)
915             * @return the range of matching countries
916             * @throws SystemException if a system exception occurred
917             */
918            public List<Country> findByActive(boolean active, int start, int end)
919                    throws SystemException {
920                    return findByActive(active, start, end, null);
921            }
922    
923            /**
924             * Finds an ordered range of all the countries where active = &#63;.
925             *
926             * <p>
927             * 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.
928             * </p>
929             *
930             * @param active the active to search with
931             * @param start the lower bound of the range of countries to return
932             * @param end the upper bound of the range of countries to return (not inclusive)
933             * @param orderByComparator the comparator to order the results by
934             * @return the ordered range of matching countries
935             * @throws SystemException if a system exception occurred
936             */
937            public List<Country> findByActive(boolean active, int start, int end,
938                    OrderByComparator orderByComparator) throws SystemException {
939                    Object[] finderArgs = new Object[] {
940                                    active,
941                                    
942                                    String.valueOf(start), String.valueOf(end),
943                                    String.valueOf(orderByComparator)
944                            };
945    
946                    List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
947                                    finderArgs, this);
948    
949                    if (list == null) {
950                            Session session = null;
951    
952                            try {
953                                    session = openSession();
954    
955                                    StringBundler query = null;
956    
957                                    if (orderByComparator != null) {
958                                            query = new StringBundler(3 +
959                                                            (orderByComparator.getOrderByFields().length * 3));
960                                    }
961                                    else {
962                                            query = new StringBundler(3);
963                                    }
964    
965                                    query.append(_SQL_SELECT_COUNTRY_WHERE);
966    
967                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
968    
969                                    if (orderByComparator != null) {
970                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
971                                                    orderByComparator);
972                                    }
973    
974                                    else {
975                                            query.append(CountryModelImpl.ORDER_BY_JPQL);
976                                    }
977    
978                                    String sql = query.toString();
979    
980                                    Query q = session.createQuery(sql);
981    
982                                    QueryPos qPos = QueryPos.getInstance(q);
983    
984                                    qPos.add(active);
985    
986                                    list = (List<Country>)QueryUtil.list(q, getDialect(), start, end);
987                            }
988                            catch (Exception e) {
989                                    throw processException(e);
990                            }
991                            finally {
992                                    if (list == null) {
993                                            list = new ArrayList<Country>();
994                                    }
995    
996                                    cacheResult(list);
997    
998                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
999                                            finderArgs, list);
1000    
1001                                    closeSession(session);
1002                            }
1003                    }
1004    
1005                    return list;
1006            }
1007    
1008            /**
1009             * Finds the first country in the ordered set where active = &#63;.
1010             *
1011             * <p>
1012             * 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.
1013             * </p>
1014             *
1015             * @param active the active to search with
1016             * @param orderByComparator the comparator to order the set by
1017             * @return the first matching country
1018             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
1019             * @throws SystemException if a system exception occurred
1020             */
1021            public Country findByActive_First(boolean active,
1022                    OrderByComparator orderByComparator)
1023                    throws NoSuchCountryException, SystemException {
1024                    List<Country> list = findByActive(active, 0, 1, orderByComparator);
1025    
1026                    if (list.isEmpty()) {
1027                            StringBundler msg = new StringBundler(4);
1028    
1029                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1030    
1031                            msg.append("active=");
1032                            msg.append(active);
1033    
1034                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1035    
1036                            throw new NoSuchCountryException(msg.toString());
1037                    }
1038                    else {
1039                            return list.get(0);
1040                    }
1041            }
1042    
1043            /**
1044             * Finds the last country in the ordered set where active = &#63;.
1045             *
1046             * <p>
1047             * 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.
1048             * </p>
1049             *
1050             * @param active the active to search with
1051             * @param orderByComparator the comparator to order the set by
1052             * @return the last matching country
1053             * @throws com.liferay.portal.NoSuchCountryException if a matching country could not be found
1054             * @throws SystemException if a system exception occurred
1055             */
1056            public Country findByActive_Last(boolean active,
1057                    OrderByComparator orderByComparator)
1058                    throws NoSuchCountryException, SystemException {
1059                    int count = countByActive(active);
1060    
1061                    List<Country> list = findByActive(active, count - 1, count,
1062                                    orderByComparator);
1063    
1064                    if (list.isEmpty()) {
1065                            StringBundler msg = new StringBundler(4);
1066    
1067                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1068    
1069                            msg.append("active=");
1070                            msg.append(active);
1071    
1072                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1073    
1074                            throw new NoSuchCountryException(msg.toString());
1075                    }
1076                    else {
1077                            return list.get(0);
1078                    }
1079            }
1080    
1081            /**
1082             * Finds the countries before and after the current country in the ordered set where active = &#63;.
1083             *
1084             * <p>
1085             * 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.
1086             * </p>
1087             *
1088             * @param countryId the primary key of the current country
1089             * @param active the active to search with
1090             * @param orderByComparator the comparator to order the set by
1091             * @return the previous, current, and next country
1092             * @throws com.liferay.portal.NoSuchCountryException if a country with the primary key could not be found
1093             * @throws SystemException if a system exception occurred
1094             */
1095            public Country[] findByActive_PrevAndNext(long countryId, boolean active,
1096                    OrderByComparator orderByComparator)
1097                    throws NoSuchCountryException, SystemException {
1098                    Country country = findByPrimaryKey(countryId);
1099    
1100                    Session session = null;
1101    
1102                    try {
1103                            session = openSession();
1104    
1105                            Country[] array = new CountryImpl[3];
1106    
1107                            array[0] = getByActive_PrevAndNext(session, country, active,
1108                                            orderByComparator, true);
1109    
1110                            array[1] = country;
1111    
1112                            array[2] = getByActive_PrevAndNext(session, country, active,
1113                                            orderByComparator, false);
1114    
1115                            return array;
1116                    }
1117                    catch (Exception e) {
1118                            throw processException(e);
1119                    }
1120                    finally {
1121                            closeSession(session);
1122                    }
1123            }
1124    
1125            protected Country getByActive_PrevAndNext(Session session, Country country,
1126                    boolean active, OrderByComparator orderByComparator, boolean previous) {
1127                    StringBundler query = null;
1128    
1129                    if (orderByComparator != null) {
1130                            query = new StringBundler(6 +
1131                                            (orderByComparator.getOrderByFields().length * 6));
1132                    }
1133                    else {
1134                            query = new StringBundler(3);
1135                    }
1136    
1137                    query.append(_SQL_SELECT_COUNTRY_WHERE);
1138    
1139                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1140    
1141                    if (orderByComparator != null) {
1142                            String[] orderByFields = orderByComparator.getOrderByFields();
1143    
1144                            if (orderByFields.length > 0) {
1145                                    query.append(WHERE_AND);
1146                            }
1147    
1148                            for (int i = 0; i < orderByFields.length; i++) {
1149                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1150                                    query.append(orderByFields[i]);
1151    
1152                                    if ((i + 1) < orderByFields.length) {
1153                                            if (orderByComparator.isAscending() ^ previous) {
1154                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1155                                            }
1156                                            else {
1157                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1158                                            }
1159                                    }
1160                                    else {
1161                                            if (orderByComparator.isAscending() ^ previous) {
1162                                                    query.append(WHERE_GREATER_THAN);
1163                                            }
1164                                            else {
1165                                                    query.append(WHERE_LESSER_THAN);
1166                                            }
1167                                    }
1168                            }
1169    
1170                            query.append(ORDER_BY_CLAUSE);
1171    
1172                            for (int i = 0; i < orderByFields.length; i++) {
1173                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1174                                    query.append(orderByFields[i]);
1175    
1176                                    if ((i + 1) < orderByFields.length) {
1177                                            if (orderByComparator.isAscending() ^ previous) {
1178                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1179                                            }
1180                                            else {
1181                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1182                                            }
1183                                    }
1184                                    else {
1185                                            if (orderByComparator.isAscending() ^ previous) {
1186                                                    query.append(ORDER_BY_ASC);
1187                                            }
1188                                            else {
1189                                                    query.append(ORDER_BY_DESC);
1190                                            }
1191                                    }
1192                            }
1193                    }
1194    
1195                    else {
1196                            query.append(CountryModelImpl.ORDER_BY_JPQL);
1197                    }
1198    
1199                    String sql = query.toString();
1200    
1201                    Query q = session.createQuery(sql);
1202    
1203                    q.setFirstResult(0);
1204                    q.setMaxResults(2);
1205    
1206                    QueryPos qPos = QueryPos.getInstance(q);
1207    
1208                    qPos.add(active);
1209    
1210                    if (orderByComparator != null) {
1211                            Object[] values = orderByComparator.getOrderByValues(country);
1212    
1213                            for (Object value : values) {
1214                                    qPos.add(value);
1215                            }
1216                    }
1217    
1218                    List<Country> list = q.list();
1219    
1220                    if (list.size() == 2) {
1221                            return list.get(1);
1222                    }
1223                    else {
1224                            return null;
1225                    }
1226            }
1227    
1228            /**
1229             * Finds all the countries.
1230             *
1231             * @return the countries
1232             * @throws SystemException if a system exception occurred
1233             */
1234            public List<Country> findAll() throws SystemException {
1235                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1236            }
1237    
1238            /**
1239             * Finds a range of all the countries.
1240             *
1241             * <p>
1242             * 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.
1243             * </p>
1244             *
1245             * @param start the lower bound of the range of countries to return
1246             * @param end the upper bound of the range of countries to return (not inclusive)
1247             * @return the range of countries
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public List<Country> findAll(int start, int end) throws SystemException {
1251                    return findAll(start, end, null);
1252            }
1253    
1254            /**
1255             * Finds an ordered range of all the countries.
1256             *
1257             * <p>
1258             * 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.
1259             * </p>
1260             *
1261             * @param start the lower bound of the range of countries to return
1262             * @param end the upper bound of the range of countries to return (not inclusive)
1263             * @param orderByComparator the comparator to order the results by
1264             * @return the ordered range of countries
1265             * @throws SystemException if a system exception occurred
1266             */
1267            public List<Country> findAll(int start, int end,
1268                    OrderByComparator orderByComparator) throws SystemException {
1269                    Object[] finderArgs = new Object[] {
1270                                    String.valueOf(start), String.valueOf(end),
1271                                    String.valueOf(orderByComparator)
1272                            };
1273    
1274                    List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1275                                    finderArgs, this);
1276    
1277                    if (list == null) {
1278                            Session session = null;
1279    
1280                            try {
1281                                    session = openSession();
1282    
1283                                    StringBundler query = null;
1284                                    String sql = null;
1285    
1286                                    if (orderByComparator != null) {
1287                                            query = new StringBundler(2 +
1288                                                            (orderByComparator.getOrderByFields().length * 3));
1289    
1290                                            query.append(_SQL_SELECT_COUNTRY);
1291    
1292                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1293                                                    orderByComparator);
1294    
1295                                            sql = query.toString();
1296                                    }
1297                                    else {
1298                                            sql = _SQL_SELECT_COUNTRY.concat(CountryModelImpl.ORDER_BY_JPQL);
1299                                    }
1300    
1301                                    Query q = session.createQuery(sql);
1302    
1303                                    if (orderByComparator == null) {
1304                                            list = (List<Country>)QueryUtil.list(q, getDialect(),
1305                                                            start, end, false);
1306    
1307                                            Collections.sort(list);
1308                                    }
1309                                    else {
1310                                            list = (List<Country>)QueryUtil.list(q, getDialect(),
1311                                                            start, end);
1312                                    }
1313                            }
1314                            catch (Exception e) {
1315                                    throw processException(e);
1316                            }
1317                            finally {
1318                                    if (list == null) {
1319                                            list = new ArrayList<Country>();
1320                                    }
1321    
1322                                    cacheResult(list);
1323    
1324                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1325    
1326                                    closeSession(session);
1327                            }
1328                    }
1329    
1330                    return list;
1331            }
1332    
1333            /**
1334             * Removes the country where name = &#63; from the database.
1335             *
1336             * @param name the name to search with
1337             * @throws SystemException if a system exception occurred
1338             */
1339            public void removeByName(String name)
1340                    throws NoSuchCountryException, SystemException {
1341                    Country country = findByName(name);
1342    
1343                    remove(country);
1344            }
1345    
1346            /**
1347             * Removes the country where a2 = &#63; from the database.
1348             *
1349             * @param a2 the a2 to search with
1350             * @throws SystemException if a system exception occurred
1351             */
1352            public void removeByA2(String a2)
1353                    throws NoSuchCountryException, SystemException {
1354                    Country country = findByA2(a2);
1355    
1356                    remove(country);
1357            }
1358    
1359            /**
1360             * Removes the country where a3 = &#63; from the database.
1361             *
1362             * @param a3 the a3 to search with
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public void removeByA3(String a3)
1366                    throws NoSuchCountryException, SystemException {
1367                    Country country = findByA3(a3);
1368    
1369                    remove(country);
1370            }
1371    
1372            /**
1373             * Removes all the countries where active = &#63; from the database.
1374             *
1375             * @param active the active to search with
1376             * @throws SystemException if a system exception occurred
1377             */
1378            public void removeByActive(boolean active) throws SystemException {
1379                    for (Country country : findByActive(active)) {
1380                            remove(country);
1381                    }
1382            }
1383    
1384            /**
1385             * Removes all the countries from the database.
1386             *
1387             * @throws SystemException if a system exception occurred
1388             */
1389            public void removeAll() throws SystemException {
1390                    for (Country country : findAll()) {
1391                            remove(country);
1392                    }
1393            }
1394    
1395            /**
1396             * Counts all the countries where name = &#63;.
1397             *
1398             * @param name the name to search with
1399             * @return the number of matching countries
1400             * @throws SystemException if a system exception occurred
1401             */
1402            public int countByName(String name) throws SystemException {
1403                    Object[] finderArgs = new Object[] { name };
1404    
1405                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1406                                    finderArgs, this);
1407    
1408                    if (count == null) {
1409                            Session session = null;
1410    
1411                            try {
1412                                    session = openSession();
1413    
1414                                    StringBundler query = new StringBundler(2);
1415    
1416                                    query.append(_SQL_COUNT_COUNTRY_WHERE);
1417    
1418                                    if (name == null) {
1419                                            query.append(_FINDER_COLUMN_NAME_NAME_1);
1420                                    }
1421                                    else {
1422                                            if (name.equals(StringPool.BLANK)) {
1423                                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
1424                                            }
1425                                            else {
1426                                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
1427                                            }
1428                                    }
1429    
1430                                    String sql = query.toString();
1431    
1432                                    Query q = session.createQuery(sql);
1433    
1434                                    QueryPos qPos = QueryPos.getInstance(q);
1435    
1436                                    if (name != null) {
1437                                            qPos.add(name);
1438                                    }
1439    
1440                                    count = (Long)q.uniqueResult();
1441                            }
1442                            catch (Exception e) {
1443                                    throw processException(e);
1444                            }
1445                            finally {
1446                                    if (count == null) {
1447                                            count = Long.valueOf(0);
1448                                    }
1449    
1450                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1451                                            finderArgs, count);
1452    
1453                                    closeSession(session);
1454                            }
1455                    }
1456    
1457                    return count.intValue();
1458            }
1459    
1460            /**
1461             * Counts all the countries where a2 = &#63;.
1462             *
1463             * @param a2 the a2 to search with
1464             * @return the number of matching countries
1465             * @throws SystemException if a system exception occurred
1466             */
1467            public int countByA2(String a2) throws SystemException {
1468                    Object[] finderArgs = new Object[] { a2 };
1469    
1470                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A2,
1471                                    finderArgs, this);
1472    
1473                    if (count == null) {
1474                            Session session = null;
1475    
1476                            try {
1477                                    session = openSession();
1478    
1479                                    StringBundler query = new StringBundler(2);
1480    
1481                                    query.append(_SQL_COUNT_COUNTRY_WHERE);
1482    
1483                                    if (a2 == null) {
1484                                            query.append(_FINDER_COLUMN_A2_A2_1);
1485                                    }
1486                                    else {
1487                                            if (a2.equals(StringPool.BLANK)) {
1488                                                    query.append(_FINDER_COLUMN_A2_A2_3);
1489                                            }
1490                                            else {
1491                                                    query.append(_FINDER_COLUMN_A2_A2_2);
1492                                            }
1493                                    }
1494    
1495                                    String sql = query.toString();
1496    
1497                                    Query q = session.createQuery(sql);
1498    
1499                                    QueryPos qPos = QueryPos.getInstance(q);
1500    
1501                                    if (a2 != null) {
1502                                            qPos.add(a2);
1503                                    }
1504    
1505                                    count = (Long)q.uniqueResult();
1506                            }
1507                            catch (Exception e) {
1508                                    throw processException(e);
1509                            }
1510                            finally {
1511                                    if (count == null) {
1512                                            count = Long.valueOf(0);
1513                                    }
1514    
1515                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, finderArgs,
1516                                            count);
1517    
1518                                    closeSession(session);
1519                            }
1520                    }
1521    
1522                    return count.intValue();
1523            }
1524    
1525            /**
1526             * Counts all the countries where a3 = &#63;.
1527             *
1528             * @param a3 the a3 to search with
1529             * @return the number of matching countries
1530             * @throws SystemException if a system exception occurred
1531             */
1532            public int countByA3(String a3) throws SystemException {
1533                    Object[] finderArgs = new Object[] { a3 };
1534    
1535                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A3,
1536                                    finderArgs, this);
1537    
1538                    if (count == null) {
1539                            Session session = null;
1540    
1541                            try {
1542                                    session = openSession();
1543    
1544                                    StringBundler query = new StringBundler(2);
1545    
1546                                    query.append(_SQL_COUNT_COUNTRY_WHERE);
1547    
1548                                    if (a3 == null) {
1549                                            query.append(_FINDER_COLUMN_A3_A3_1);
1550                                    }
1551                                    else {
1552                                            if (a3.equals(StringPool.BLANK)) {
1553                                                    query.append(_FINDER_COLUMN_A3_A3_3);
1554                                            }
1555                                            else {
1556                                                    query.append(_FINDER_COLUMN_A3_A3_2);
1557                                            }
1558                                    }
1559    
1560                                    String sql = query.toString();
1561    
1562                                    Query q = session.createQuery(sql);
1563    
1564                                    QueryPos qPos = QueryPos.getInstance(q);
1565    
1566                                    if (a3 != null) {
1567                                            qPos.add(a3);
1568                                    }
1569    
1570                                    count = (Long)q.uniqueResult();
1571                            }
1572                            catch (Exception e) {
1573                                    throw processException(e);
1574                            }
1575                            finally {
1576                                    if (count == null) {
1577                                            count = Long.valueOf(0);
1578                                    }
1579    
1580                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, finderArgs,
1581                                            count);
1582    
1583                                    closeSession(session);
1584                            }
1585                    }
1586    
1587                    return count.intValue();
1588            }
1589    
1590            /**
1591             * Counts all the countries where active = &#63;.
1592             *
1593             * @param active the active to search with
1594             * @return the number of matching countries
1595             * @throws SystemException if a system exception occurred
1596             */
1597            public int countByActive(boolean active) throws SystemException {
1598                    Object[] finderArgs = new Object[] { active };
1599    
1600                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1601                                    finderArgs, this);
1602    
1603                    if (count == null) {
1604                            Session session = null;
1605    
1606                            try {
1607                                    session = openSession();
1608    
1609                                    StringBundler query = new StringBundler(2);
1610    
1611                                    query.append(_SQL_COUNT_COUNTRY_WHERE);
1612    
1613                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1614    
1615                                    String sql = query.toString();
1616    
1617                                    Query q = session.createQuery(sql);
1618    
1619                                    QueryPos qPos = QueryPos.getInstance(q);
1620    
1621                                    qPos.add(active);
1622    
1623                                    count = (Long)q.uniqueResult();
1624                            }
1625                            catch (Exception e) {
1626                                    throw processException(e);
1627                            }
1628                            finally {
1629                                    if (count == null) {
1630                                            count = Long.valueOf(0);
1631                                    }
1632    
1633                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1634                                            finderArgs, count);
1635    
1636                                    closeSession(session);
1637                            }
1638                    }
1639    
1640                    return count.intValue();
1641            }
1642    
1643            /**
1644             * Counts all the countries.
1645             *
1646             * @return the number of countries
1647             * @throws SystemException if a system exception occurred
1648             */
1649            public int countAll() throws SystemException {
1650                    Object[] finderArgs = new Object[0];
1651    
1652                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1653                                    finderArgs, this);
1654    
1655                    if (count == null) {
1656                            Session session = null;
1657    
1658                            try {
1659                                    session = openSession();
1660    
1661                                    Query q = session.createQuery(_SQL_COUNT_COUNTRY);
1662    
1663                                    count = (Long)q.uniqueResult();
1664                            }
1665                            catch (Exception e) {
1666                                    throw processException(e);
1667                            }
1668                            finally {
1669                                    if (count == null) {
1670                                            count = Long.valueOf(0);
1671                                    }
1672    
1673                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1674                                            count);
1675    
1676                                    closeSession(session);
1677                            }
1678                    }
1679    
1680                    return count.intValue();
1681            }
1682    
1683            /**
1684             * Initializes the country persistence.
1685             */
1686            public void afterPropertiesSet() {
1687                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1688                                            com.liferay.portal.util.PropsUtil.get(
1689                                                    "value.object.listener.com.liferay.portal.model.Country")));
1690    
1691                    if (listenerClassNames.length > 0) {
1692                            try {
1693                                    List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1694    
1695                                    for (String listenerClassName : listenerClassNames) {
1696                                            listenersList.add((ModelListener<Country>)InstanceFactory.newInstance(
1697                                                            listenerClassName));
1698                                    }
1699    
1700                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1701                            }
1702                            catch (Exception e) {
1703                                    _log.error(e);
1704                            }
1705                    }
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    }