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