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