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