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