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