1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchRegionException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.annotation.BeanReference;
28 import com.liferay.portal.kernel.cache.CacheRegistry;
29 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32 import com.liferay.portal.kernel.dao.orm.FinderPath;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryPos;
35 import com.liferay.portal.kernel.dao.orm.QueryUtil;
36 import com.liferay.portal.kernel.dao.orm.Session;
37 import com.liferay.portal.kernel.log.Log;
38 import com.liferay.portal.kernel.log.LogFactoryUtil;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.OrderByComparator;
41 import com.liferay.portal.kernel.util.StringPool;
42 import com.liferay.portal.kernel.util.StringUtil;
43 import com.liferay.portal.model.ModelListener;
44 import com.liferay.portal.model.Region;
45 import com.liferay.portal.model.impl.RegionImpl;
46 import com.liferay.portal.model.impl.RegionModelImpl;
47 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.List;
52
53
59 public class RegionPersistenceImpl extends BasePersistenceImpl
60 implements RegionPersistence {
61 public static final String FINDER_CLASS_NAME_ENTITY = RegionImpl.class.getName();
62 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
63 ".List";
64 public static final FinderPath FINDER_PATH_FIND_BY_COUNTRYID = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
65 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
66 "findByCountryId", new String[] { Long.class.getName() });
67 public static final FinderPath FINDER_PATH_FIND_BY_OBC_COUNTRYID = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
68 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
69 "findByCountryId",
70 new String[] {
71 Long.class.getName(),
72
73 "java.lang.Integer", "java.lang.Integer",
74 "com.liferay.portal.kernel.util.OrderByComparator"
75 });
76 public static final FinderPath FINDER_PATH_COUNT_BY_COUNTRYID = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
77 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
78 "countByCountryId", new String[] { Long.class.getName() });
79 public static final FinderPath FINDER_PATH_FIND_BY_ACTIVE = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
80 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
81 "findByActive", new String[] { Boolean.class.getName() });
82 public static final FinderPath FINDER_PATH_FIND_BY_OBC_ACTIVE = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
83 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
84 "findByActive",
85 new String[] {
86 Boolean.class.getName(),
87
88 "java.lang.Integer", "java.lang.Integer",
89 "com.liferay.portal.kernel.util.OrderByComparator"
90 });
91 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
92 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93 "countByActive", new String[] { Boolean.class.getName() });
94 public static final FinderPath FINDER_PATH_FIND_BY_C_A = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
95 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96 "findByC_A",
97 new String[] { Long.class.getName(), Boolean.class.getName() });
98 public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_A = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
99 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100 "findByC_A",
101 new String[] {
102 Long.class.getName(), Boolean.class.getName(),
103
104 "java.lang.Integer", "java.lang.Integer",
105 "com.liferay.portal.kernel.util.OrderByComparator"
106 });
107 public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
108 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109 "countByC_A",
110 new String[] { Long.class.getName(), Boolean.class.getName() });
111 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
112 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113 "findAll", new String[0]);
114 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RegionModelImpl.ENTITY_CACHE_ENABLED,
115 RegionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116 "countAll", new String[0]);
117
118 public void cacheResult(Region region) {
119 EntityCacheUtil.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
120 RegionImpl.class, region.getPrimaryKey(), region);
121 }
122
123 public void cacheResult(List<Region> regions) {
124 for (Region region : regions) {
125 if (EntityCacheUtil.getResult(
126 RegionModelImpl.ENTITY_CACHE_ENABLED, RegionImpl.class,
127 region.getPrimaryKey(), this) == null) {
128 cacheResult(region);
129 }
130 }
131 }
132
133 public void clearCache() {
134 CacheRegistry.clear(RegionImpl.class.getName());
135 EntityCacheUtil.clearCache(RegionImpl.class.getName());
136 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
137 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
138 }
139
140 public Region create(long regionId) {
141 Region region = new RegionImpl();
142
143 region.setNew(true);
144 region.setPrimaryKey(regionId);
145
146 return region;
147 }
148
149 public Region remove(long regionId)
150 throws NoSuchRegionException, SystemException {
151 Session session = null;
152
153 try {
154 session = openSession();
155
156 Region region = (Region)session.get(RegionImpl.class,
157 new Long(regionId));
158
159 if (region == null) {
160 if (_log.isWarnEnabled()) {
161 _log.warn("No Region exists with the primary key " +
162 regionId);
163 }
164
165 throw new NoSuchRegionException(
166 "No Region exists with the primary key " + regionId);
167 }
168
169 return remove(region);
170 }
171 catch (NoSuchRegionException nsee) {
172 throw nsee;
173 }
174 catch (Exception e) {
175 throw processException(e);
176 }
177 finally {
178 closeSession(session);
179 }
180 }
181
182 public Region remove(Region region) throws SystemException {
183 for (ModelListener<Region> listener : listeners) {
184 listener.onBeforeRemove(region);
185 }
186
187 region = removeImpl(region);
188
189 for (ModelListener<Region> listener : listeners) {
190 listener.onAfterRemove(region);
191 }
192
193 return region;
194 }
195
196 protected Region removeImpl(Region region) throws SystemException {
197 Session session = null;
198
199 try {
200 session = openSession();
201
202 if (region.isCachedModel() || BatchSessionUtil.isEnabled()) {
203 Object staleObject = session.get(RegionImpl.class,
204 region.getPrimaryKeyObj());
205
206 if (staleObject != null) {
207 session.evict(staleObject);
208 }
209 }
210
211 session.delete(region);
212
213 session.flush();
214 }
215 catch (Exception e) {
216 throw processException(e);
217 }
218 finally {
219 closeSession(session);
220 }
221
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
223
224 EntityCacheUtil.removeResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
225 RegionImpl.class, region.getPrimaryKey());
226
227 return region;
228 }
229
230
233 public Region update(Region region) throws SystemException {
234 if (_log.isWarnEnabled()) {
235 _log.warn(
236 "Using the deprecated update(Region region) method. Use update(Region region, boolean merge) instead.");
237 }
238
239 return update(region, false);
240 }
241
242
255 public Region update(Region region, boolean merge)
256 throws SystemException {
257 boolean isNew = region.isNew();
258
259 for (ModelListener<Region> listener : listeners) {
260 if (isNew) {
261 listener.onBeforeCreate(region);
262 }
263 else {
264 listener.onBeforeUpdate(region);
265 }
266 }
267
268 region = updateImpl(region, merge);
269
270 for (ModelListener<Region> listener : listeners) {
271 if (isNew) {
272 listener.onAfterCreate(region);
273 }
274 else {
275 listener.onAfterUpdate(region);
276 }
277 }
278
279 return region;
280 }
281
282 public Region updateImpl(com.liferay.portal.model.Region region,
283 boolean merge) throws SystemException {
284 Session session = null;
285
286 try {
287 session = openSession();
288
289 BatchSessionUtil.update(session, region, merge);
290
291 region.setNew(false);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
301
302 EntityCacheUtil.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
303 RegionImpl.class, region.getPrimaryKey(), region);
304
305 return region;
306 }
307
308 public Region findByPrimaryKey(long regionId)
309 throws NoSuchRegionException, SystemException {
310 Region region = fetchByPrimaryKey(regionId);
311
312 if (region == null) {
313 if (_log.isWarnEnabled()) {
314 _log.warn("No Region exists with the primary key " + regionId);
315 }
316
317 throw new NoSuchRegionException(
318 "No Region exists with the primary key " + regionId);
319 }
320
321 return region;
322 }
323
324 public Region fetchByPrimaryKey(long regionId) throws SystemException {
325 Region region = (Region)EntityCacheUtil.getResult(RegionModelImpl.ENTITY_CACHE_ENABLED,
326 RegionImpl.class, regionId, this);
327
328 if (region == null) {
329 Session session = null;
330
331 try {
332 session = openSession();
333
334 region = (Region)session.get(RegionImpl.class,
335 new Long(regionId));
336 }
337 catch (Exception e) {
338 throw processException(e);
339 }
340 finally {
341 if (region != null) {
342 cacheResult(region);
343 }
344
345 closeSession(session);
346 }
347 }
348
349 return region;
350 }
351
352 public List<Region> findByCountryId(long countryId)
353 throws SystemException {
354 Object[] finderArgs = new Object[] { new Long(countryId) };
355
356 List<Region> list = (List<Region>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COUNTRYID,
357 finderArgs, this);
358
359 if (list == null) {
360 Session session = null;
361
362 try {
363 session = openSession();
364
365 StringBuilder query = new StringBuilder();
366
367 query.append("FROM com.liferay.portal.model.Region WHERE ");
368
369 query.append("countryId = ?");
370
371 query.append(" ");
372
373 query.append("ORDER BY ");
374
375 query.append("name ASC");
376
377 Query q = session.createQuery(query.toString());
378
379 QueryPos qPos = QueryPos.getInstance(q);
380
381 qPos.add(countryId);
382
383 list = q.list();
384 }
385 catch (Exception e) {
386 throw processException(e);
387 }
388 finally {
389 if (list == null) {
390 list = new ArrayList<Region>();
391 }
392
393 cacheResult(list);
394
395 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COUNTRYID,
396 finderArgs, list);
397
398 closeSession(session);
399 }
400 }
401
402 return list;
403 }
404
405 public List<Region> findByCountryId(long countryId, int start, int end)
406 throws SystemException {
407 return findByCountryId(countryId, start, end, null);
408 }
409
410 public List<Region> findByCountryId(long countryId, int start, int end,
411 OrderByComparator obc) throws SystemException {
412 Object[] finderArgs = new Object[] {
413 new Long(countryId),
414
415 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
416 };
417
418 List<Region> list = (List<Region>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COUNTRYID,
419 finderArgs, this);
420
421 if (list == null) {
422 Session session = null;
423
424 try {
425 session = openSession();
426
427 StringBuilder query = new StringBuilder();
428
429 query.append("FROM com.liferay.portal.model.Region WHERE ");
430
431 query.append("countryId = ?");
432
433 query.append(" ");
434
435 if (obc != null) {
436 query.append("ORDER BY ");
437 query.append(obc.getOrderBy());
438 }
439
440 else {
441 query.append("ORDER BY ");
442
443 query.append("name ASC");
444 }
445
446 Query q = session.createQuery(query.toString());
447
448 QueryPos qPos = QueryPos.getInstance(q);
449
450 qPos.add(countryId);
451
452 list = (List<Region>)QueryUtil.list(q, getDialect(), start, end);
453 }
454 catch (Exception e) {
455 throw processException(e);
456 }
457 finally {
458 if (list == null) {
459 list = new ArrayList<Region>();
460 }
461
462 cacheResult(list);
463
464 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COUNTRYID,
465 finderArgs, list);
466
467 closeSession(session);
468 }
469 }
470
471 return list;
472 }
473
474 public Region findByCountryId_First(long countryId, OrderByComparator obc)
475 throws NoSuchRegionException, SystemException {
476 List<Region> list = findByCountryId(countryId, 0, 1, obc);
477
478 if (list.isEmpty()) {
479 StringBuilder msg = new StringBuilder();
480
481 msg.append("No Region exists with the key {");
482
483 msg.append("countryId=" + countryId);
484
485 msg.append(StringPool.CLOSE_CURLY_BRACE);
486
487 throw new NoSuchRegionException(msg.toString());
488 }
489 else {
490 return list.get(0);
491 }
492 }
493
494 public Region findByCountryId_Last(long countryId, OrderByComparator obc)
495 throws NoSuchRegionException, SystemException {
496 int count = countByCountryId(countryId);
497
498 List<Region> list = findByCountryId(countryId, count - 1, count, obc);
499
500 if (list.isEmpty()) {
501 StringBuilder msg = new StringBuilder();
502
503 msg.append("No Region exists with the key {");
504
505 msg.append("countryId=" + countryId);
506
507 msg.append(StringPool.CLOSE_CURLY_BRACE);
508
509 throw new NoSuchRegionException(msg.toString());
510 }
511 else {
512 return list.get(0);
513 }
514 }
515
516 public Region[] findByCountryId_PrevAndNext(long regionId, long countryId,
517 OrderByComparator obc) throws NoSuchRegionException, SystemException {
518 Region region = findByPrimaryKey(regionId);
519
520 int count = countByCountryId(countryId);
521
522 Session session = null;
523
524 try {
525 session = openSession();
526
527 StringBuilder query = new StringBuilder();
528
529 query.append("FROM com.liferay.portal.model.Region WHERE ");
530
531 query.append("countryId = ?");
532
533 query.append(" ");
534
535 if (obc != null) {
536 query.append("ORDER BY ");
537 query.append(obc.getOrderBy());
538 }
539
540 else {
541 query.append("ORDER BY ");
542
543 query.append("name ASC");
544 }
545
546 Query q = session.createQuery(query.toString());
547
548 QueryPos qPos = QueryPos.getInstance(q);
549
550 qPos.add(countryId);
551
552 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, region);
553
554 Region[] array = new RegionImpl[3];
555
556 array[0] = (Region)objArray[0];
557 array[1] = (Region)objArray[1];
558 array[2] = (Region)objArray[2];
559
560 return array;
561 }
562 catch (Exception e) {
563 throw processException(e);
564 }
565 finally {
566 closeSession(session);
567 }
568 }
569
570 public List<Region> findByActive(boolean active) throws SystemException {
571 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
572
573 List<Region> list = (List<Region>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
574 finderArgs, this);
575
576 if (list == null) {
577 Session session = null;
578
579 try {
580 session = openSession();
581
582 StringBuilder query = new StringBuilder();
583
584 query.append("FROM com.liferay.portal.model.Region WHERE ");
585
586 query.append("active_ = ?");
587
588 query.append(" ");
589
590 query.append("ORDER BY ");
591
592 query.append("name ASC");
593
594 Query q = session.createQuery(query.toString());
595
596 QueryPos qPos = QueryPos.getInstance(q);
597
598 qPos.add(active);
599
600 list = q.list();
601 }
602 catch (Exception e) {
603 throw processException(e);
604 }
605 finally {
606 if (list == null) {
607 list = new ArrayList<Region>();
608 }
609
610 cacheResult(list);
611
612 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
613 finderArgs, list);
614
615 closeSession(session);
616 }
617 }
618
619 return list;
620 }
621
622 public List<Region> findByActive(boolean active, int start, int end)
623 throws SystemException {
624 return findByActive(active, start, end, null);
625 }
626
627 public List<Region> findByActive(boolean active, int start, int end,
628 OrderByComparator obc) throws SystemException {
629 Object[] finderArgs = new Object[] {
630 Boolean.valueOf(active),
631
632 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
633 };
634
635 List<Region> list = (List<Region>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
636 finderArgs, this);
637
638 if (list == null) {
639 Session session = null;
640
641 try {
642 session = openSession();
643
644 StringBuilder query = new StringBuilder();
645
646 query.append("FROM com.liferay.portal.model.Region WHERE ");
647
648 query.append("active_ = ?");
649
650 query.append(" ");
651
652 if (obc != null) {
653 query.append("ORDER BY ");
654 query.append(obc.getOrderBy());
655 }
656
657 else {
658 query.append("ORDER BY ");
659
660 query.append("name ASC");
661 }
662
663 Query q = session.createQuery(query.toString());
664
665 QueryPos qPos = QueryPos.getInstance(q);
666
667 qPos.add(active);
668
669 list = (List<Region>)QueryUtil.list(q, getDialect(), start, end);
670 }
671 catch (Exception e) {
672 throw processException(e);
673 }
674 finally {
675 if (list == null) {
676 list = new ArrayList<Region>();
677 }
678
679 cacheResult(list);
680
681 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
682 finderArgs, list);
683
684 closeSession(session);
685 }
686 }
687
688 return list;
689 }
690
691 public Region findByActive_First(boolean active, OrderByComparator obc)
692 throws NoSuchRegionException, SystemException {
693 List<Region> list = findByActive(active, 0, 1, obc);
694
695 if (list.isEmpty()) {
696 StringBuilder msg = new StringBuilder();
697
698 msg.append("No Region exists with the key {");
699
700 msg.append("active=" + active);
701
702 msg.append(StringPool.CLOSE_CURLY_BRACE);
703
704 throw new NoSuchRegionException(msg.toString());
705 }
706 else {
707 return list.get(0);
708 }
709 }
710
711 public Region findByActive_Last(boolean active, OrderByComparator obc)
712 throws NoSuchRegionException, SystemException {
713 int count = countByActive(active);
714
715 List<Region> list = findByActive(active, count - 1, count, obc);
716
717 if (list.isEmpty()) {
718 StringBuilder msg = new StringBuilder();
719
720 msg.append("No Region exists with the key {");
721
722 msg.append("active=" + active);
723
724 msg.append(StringPool.CLOSE_CURLY_BRACE);
725
726 throw new NoSuchRegionException(msg.toString());
727 }
728 else {
729 return list.get(0);
730 }
731 }
732
733 public Region[] findByActive_PrevAndNext(long regionId, boolean active,
734 OrderByComparator obc) throws NoSuchRegionException, SystemException {
735 Region region = findByPrimaryKey(regionId);
736
737 int count = countByActive(active);
738
739 Session session = null;
740
741 try {
742 session = openSession();
743
744 StringBuilder query = new StringBuilder();
745
746 query.append("FROM com.liferay.portal.model.Region WHERE ");
747
748 query.append("active_ = ?");
749
750 query.append(" ");
751
752 if (obc != null) {
753 query.append("ORDER BY ");
754 query.append(obc.getOrderBy());
755 }
756
757 else {
758 query.append("ORDER BY ");
759
760 query.append("name ASC");
761 }
762
763 Query q = session.createQuery(query.toString());
764
765 QueryPos qPos = QueryPos.getInstance(q);
766
767 qPos.add(active);
768
769 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, region);
770
771 Region[] array = new RegionImpl[3];
772
773 array[0] = (Region)objArray[0];
774 array[1] = (Region)objArray[1];
775 array[2] = (Region)objArray[2];
776
777 return array;
778 }
779 catch (Exception e) {
780 throw processException(e);
781 }
782 finally {
783 closeSession(session);
784 }
785 }
786
787 public List<Region> findByC_A(long countryId, boolean active)
788 throws SystemException {
789 Object[] finderArgs = new Object[] {
790 new Long(countryId), Boolean.valueOf(active)
791 };
792
793 List<Region> list = (List<Region>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_A,
794 finderArgs, this);
795
796 if (list == null) {
797 Session session = null;
798
799 try {
800 session = openSession();
801
802 StringBuilder query = new StringBuilder();
803
804 query.append("FROM com.liferay.portal.model.Region WHERE ");
805
806 query.append("countryId = ?");
807
808 query.append(" AND ");
809
810 query.append("active_ = ?");
811
812 query.append(" ");
813
814 query.append("ORDER BY ");
815
816 query.append("name ASC");
817
818 Query q = session.createQuery(query.toString());
819
820 QueryPos qPos = QueryPos.getInstance(q);
821
822 qPos.add(countryId);
823
824 qPos.add(active);
825
826 list = q.list();
827 }
828 catch (Exception e) {
829 throw processException(e);
830 }
831 finally {
832 if (list == null) {
833 list = new ArrayList<Region>();
834 }
835
836 cacheResult(list);
837
838 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_A, finderArgs,
839 list);
840
841 closeSession(session);
842 }
843 }
844
845 return list;
846 }
847
848 public List<Region> findByC_A(long countryId, boolean active, int start,
849 int end) throws SystemException {
850 return findByC_A(countryId, active, start, end, null);
851 }
852
853 public List<Region> findByC_A(long countryId, boolean active, int start,
854 int end, OrderByComparator obc) throws SystemException {
855 Object[] finderArgs = new Object[] {
856 new Long(countryId), Boolean.valueOf(active),
857
858 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
859 };
860
861 List<Region> list = (List<Region>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_A,
862 finderArgs, this);
863
864 if (list == null) {
865 Session session = null;
866
867 try {
868 session = openSession();
869
870 StringBuilder query = new StringBuilder();
871
872 query.append("FROM com.liferay.portal.model.Region WHERE ");
873
874 query.append("countryId = ?");
875
876 query.append(" AND ");
877
878 query.append("active_ = ?");
879
880 query.append(" ");
881
882 if (obc != null) {
883 query.append("ORDER BY ");
884 query.append(obc.getOrderBy());
885 }
886
887 else {
888 query.append("ORDER BY ");
889
890 query.append("name ASC");
891 }
892
893 Query q = session.createQuery(query.toString());
894
895 QueryPos qPos = QueryPos.getInstance(q);
896
897 qPos.add(countryId);
898
899 qPos.add(active);
900
901 list = (List<Region>)QueryUtil.list(q, getDialect(), start, end);
902 }
903 catch (Exception e) {
904 throw processException(e);
905 }
906 finally {
907 if (list == null) {
908 list = new ArrayList<Region>();
909 }
910
911 cacheResult(list);
912
913 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_A,
914 finderArgs, list);
915
916 closeSession(session);
917 }
918 }
919
920 return list;
921 }
922
923 public Region findByC_A_First(long countryId, boolean active,
924 OrderByComparator obc) throws NoSuchRegionException, SystemException {
925 List<Region> list = findByC_A(countryId, active, 0, 1, obc);
926
927 if (list.isEmpty()) {
928 StringBuilder msg = new StringBuilder();
929
930 msg.append("No Region exists with the key {");
931
932 msg.append("countryId=" + countryId);
933
934 msg.append(", ");
935 msg.append("active=" + active);
936
937 msg.append(StringPool.CLOSE_CURLY_BRACE);
938
939 throw new NoSuchRegionException(msg.toString());
940 }
941 else {
942 return list.get(0);
943 }
944 }
945
946 public Region findByC_A_Last(long countryId, boolean active,
947 OrderByComparator obc) throws NoSuchRegionException, SystemException {
948 int count = countByC_A(countryId, active);
949
950 List<Region> list = findByC_A(countryId, active, count - 1, count, obc);
951
952 if (list.isEmpty()) {
953 StringBuilder msg = new StringBuilder();
954
955 msg.append("No Region exists with the key {");
956
957 msg.append("countryId=" + countryId);
958
959 msg.append(", ");
960 msg.append("active=" + active);
961
962 msg.append(StringPool.CLOSE_CURLY_BRACE);
963
964 throw new NoSuchRegionException(msg.toString());
965 }
966 else {
967 return list.get(0);
968 }
969 }
970
971 public Region[] findByC_A_PrevAndNext(long regionId, long countryId,
972 boolean active, OrderByComparator obc)
973 throws NoSuchRegionException, SystemException {
974 Region region = findByPrimaryKey(regionId);
975
976 int count = countByC_A(countryId, active);
977
978 Session session = null;
979
980 try {
981 session = openSession();
982
983 StringBuilder query = new StringBuilder();
984
985 query.append("FROM com.liferay.portal.model.Region WHERE ");
986
987 query.append("countryId = ?");
988
989 query.append(" AND ");
990
991 query.append("active_ = ?");
992
993 query.append(" ");
994
995 if (obc != null) {
996 query.append("ORDER BY ");
997 query.append(obc.getOrderBy());
998 }
999
1000 else {
1001 query.append("ORDER BY ");
1002
1003 query.append("name ASC");
1004 }
1005
1006 Query q = session.createQuery(query.toString());
1007
1008 QueryPos qPos = QueryPos.getInstance(q);
1009
1010 qPos.add(countryId);
1011
1012 qPos.add(active);
1013
1014 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, region);
1015
1016 Region[] array = new RegionImpl[3];
1017
1018 array[0] = (Region)objArray[0];
1019 array[1] = (Region)objArray[1];
1020 array[2] = (Region)objArray[2];
1021
1022 return array;
1023 }
1024 catch (Exception e) {
1025 throw processException(e);
1026 }
1027 finally {
1028 closeSession(session);
1029 }
1030 }
1031
1032 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1033 throws SystemException {
1034 Session session = null;
1035
1036 try {
1037 session = openSession();
1038
1039 dynamicQuery.compile(session);
1040
1041 return dynamicQuery.list();
1042 }
1043 catch (Exception e) {
1044 throw processException(e);
1045 }
1046 finally {
1047 closeSession(session);
1048 }
1049 }
1050
1051 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1052 int start, int end) throws SystemException {
1053 Session session = null;
1054
1055 try {
1056 session = openSession();
1057
1058 dynamicQuery.setLimit(start, end);
1059
1060 dynamicQuery.compile(session);
1061
1062 return dynamicQuery.list();
1063 }
1064 catch (Exception e) {
1065 throw processException(e);
1066 }
1067 finally {
1068 closeSession(session);
1069 }
1070 }
1071
1072 public List<Region> findAll() throws SystemException {
1073 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1074 }
1075
1076 public List<Region> findAll(int start, int end) throws SystemException {
1077 return findAll(start, end, null);
1078 }
1079
1080 public List<Region> findAll(int start, int end, OrderByComparator obc)
1081 throws SystemException {
1082 Object[] finderArgs = new Object[] {
1083 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1084 };
1085
1086 List<Region> list = (List<Region>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1087 finderArgs, this);
1088
1089 if (list == null) {
1090 Session session = null;
1091
1092 try {
1093 session = openSession();
1094
1095 StringBuilder query = new StringBuilder();
1096
1097 query.append("FROM com.liferay.portal.model.Region ");
1098
1099 if (obc != null) {
1100 query.append("ORDER BY ");
1101 query.append(obc.getOrderBy());
1102 }
1103
1104 else {
1105 query.append("ORDER BY ");
1106
1107 query.append("name ASC");
1108 }
1109
1110 Query q = session.createQuery(query.toString());
1111
1112 if (obc == null) {
1113 list = (List<Region>)QueryUtil.list(q, getDialect(), start,
1114 end, false);
1115
1116 Collections.sort(list);
1117 }
1118 else {
1119 list = (List<Region>)QueryUtil.list(q, getDialect(), start,
1120 end);
1121 }
1122 }
1123 catch (Exception e) {
1124 throw processException(e);
1125 }
1126 finally {
1127 if (list == null) {
1128 list = new ArrayList<Region>();
1129 }
1130
1131 cacheResult(list);
1132
1133 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1134
1135 closeSession(session);
1136 }
1137 }
1138
1139 return list;
1140 }
1141
1142 public void removeByCountryId(long countryId) throws SystemException {
1143 for (Region region : findByCountryId(countryId)) {
1144 remove(region);
1145 }
1146 }
1147
1148 public void removeByActive(boolean active) throws SystemException {
1149 for (Region region : findByActive(active)) {
1150 remove(region);
1151 }
1152 }
1153
1154 public void removeByC_A(long countryId, boolean active)
1155 throws SystemException {
1156 for (Region region : findByC_A(countryId, active)) {
1157 remove(region);
1158 }
1159 }
1160
1161 public void removeAll() throws SystemException {
1162 for (Region region : findAll()) {
1163 remove(region);
1164 }
1165 }
1166
1167 public int countByCountryId(long countryId) throws SystemException {
1168 Object[] finderArgs = new Object[] { new Long(countryId) };
1169
1170 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COUNTRYID,
1171 finderArgs, this);
1172
1173 if (count == null) {
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
1179 StringBuilder query = new StringBuilder();
1180
1181 query.append("SELECT COUNT(*) ");
1182 query.append("FROM com.liferay.portal.model.Region WHERE ");
1183
1184 query.append("countryId = ?");
1185
1186 query.append(" ");
1187
1188 Query q = session.createQuery(query.toString());
1189
1190 QueryPos qPos = QueryPos.getInstance(q);
1191
1192 qPos.add(countryId);
1193
1194 count = (Long)q.uniqueResult();
1195 }
1196 catch (Exception e) {
1197 throw processException(e);
1198 }
1199 finally {
1200 if (count == null) {
1201 count = Long.valueOf(0);
1202 }
1203
1204 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COUNTRYID,
1205 finderArgs, count);
1206
1207 closeSession(session);
1208 }
1209 }
1210
1211 return count.intValue();
1212 }
1213
1214 public int countByActive(boolean active) throws SystemException {
1215 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1216
1217 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1218 finderArgs, this);
1219
1220 if (count == null) {
1221 Session session = null;
1222
1223 try {
1224 session = openSession();
1225
1226 StringBuilder query = new StringBuilder();
1227
1228 query.append("SELECT COUNT(*) ");
1229 query.append("FROM com.liferay.portal.model.Region WHERE ");
1230
1231 query.append("active_ = ?");
1232
1233 query.append(" ");
1234
1235 Query q = session.createQuery(query.toString());
1236
1237 QueryPos qPos = QueryPos.getInstance(q);
1238
1239 qPos.add(active);
1240
1241 count = (Long)q.uniqueResult();
1242 }
1243 catch (Exception e) {
1244 throw processException(e);
1245 }
1246 finally {
1247 if (count == null) {
1248 count = Long.valueOf(0);
1249 }
1250
1251 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1252 finderArgs, count);
1253
1254 closeSession(session);
1255 }
1256 }
1257
1258 return count.intValue();
1259 }
1260
1261 public int countByC_A(long countryId, boolean active)
1262 throws SystemException {
1263 Object[] finderArgs = new Object[] {
1264 new Long(countryId), Boolean.valueOf(active)
1265 };
1266
1267 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_A,
1268 finderArgs, this);
1269
1270 if (count == null) {
1271 Session session = null;
1272
1273 try {
1274 session = openSession();
1275
1276 StringBuilder query = new StringBuilder();
1277
1278 query.append("SELECT COUNT(*) ");
1279 query.append("FROM com.liferay.portal.model.Region WHERE ");
1280
1281 query.append("countryId = ?");
1282
1283 query.append(" AND ");
1284
1285 query.append("active_ = ?");
1286
1287 query.append(" ");
1288
1289 Query q = session.createQuery(query.toString());
1290
1291 QueryPos qPos = QueryPos.getInstance(q);
1292
1293 qPos.add(countryId);
1294
1295 qPos.add(active);
1296
1297 count = (Long)q.uniqueResult();
1298 }
1299 catch (Exception e) {
1300 throw processException(e);
1301 }
1302 finally {
1303 if (count == null) {
1304 count = Long.valueOf(0);
1305 }
1306
1307 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_A, finderArgs,
1308 count);
1309
1310 closeSession(session);
1311 }
1312 }
1313
1314 return count.intValue();
1315 }
1316
1317 public int countAll() throws SystemException {
1318 Object[] finderArgs = new Object[0];
1319
1320 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1321 finderArgs, this);
1322
1323 if (count == null) {
1324 Session session = null;
1325
1326 try {
1327 session = openSession();
1328
1329 Query q = session.createQuery(
1330 "SELECT COUNT(*) FROM com.liferay.portal.model.Region");
1331
1332 count = (Long)q.uniqueResult();
1333 }
1334 catch (Exception e) {
1335 throw processException(e);
1336 }
1337 finally {
1338 if (count == null) {
1339 count = Long.valueOf(0);
1340 }
1341
1342 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1343 count);
1344
1345 closeSession(session);
1346 }
1347 }
1348
1349 return count.intValue();
1350 }
1351
1352 public void afterPropertiesSet() {
1353 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1354 com.liferay.portal.util.PropsUtil.get(
1355 "value.object.listener.com.liferay.portal.model.Region")));
1356
1357 if (listenerClassNames.length > 0) {
1358 try {
1359 List<ModelListener<Region>> listenersList = new ArrayList<ModelListener<Region>>();
1360
1361 for (String listenerClassName : listenerClassNames) {
1362 listenersList.add((ModelListener<Region>)Class.forName(
1363 listenerClassName).newInstance());
1364 }
1365
1366 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1367 }
1368 catch (Exception e) {
1369 _log.error(e);
1370 }
1371 }
1372 }
1373
1374 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1375 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1376 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1377 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1378 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1379 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1380 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1381 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1382 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1383 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1384 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1385 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1386 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1387 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1388 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1389 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1390 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1391 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1392 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1393 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1394 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1395 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1396 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1397 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1398 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1399 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1400 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1401 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1402 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1403 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1404 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1405 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1406 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1407 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1408 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1409 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1410 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1411 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1412 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1413 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1414 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1415 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1416 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1417 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1418 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1419 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1420 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1421 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1422 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1423 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1424 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1425 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1426 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1427 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1428 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1429 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1430 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1431 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1432 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1433 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1434 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1435 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1436 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1437 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1438 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1439 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1440 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1441 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1442 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1443 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1444 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1445 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1446 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1447 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1448 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1449 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1450 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1451 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1452 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1453 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1454 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1455 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1456 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1457 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1458 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1459 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1460 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1461 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1462 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1463 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1464 private static Log _log = LogFactoryUtil.getLog(RegionPersistenceImpl.class);
1465}