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