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