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.dao.DynamicQuery;
28 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
29 import com.liferay.portal.kernel.util.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.model.Region;
33 import com.liferay.portal.model.impl.RegionImpl;
34 import com.liferay.portal.service.persistence.BasePersistence;
35 import com.liferay.portal.spring.hibernate.FinderCache;
36 import com.liferay.portal.spring.hibernate.HibernateUtil;
37
38 import com.liferay.util.dao.hibernate.QueryUtil;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43 import org.hibernate.Query;
44 import org.hibernate.Session;
45
46 import java.util.Collections;
47 import java.util.Iterator;
48 import java.util.List;
49
50
56 public class RegionPersistenceImpl extends BasePersistence
57 implements RegionPersistence {
58 public Region create(long regionId) {
59 Region region = new RegionImpl();
60 region.setNew(true);
61 region.setPrimaryKey(regionId);
62
63 return region;
64 }
65
66 public Region remove(long regionId)
67 throws NoSuchRegionException, SystemException {
68 Session session = null;
69
70 try {
71 session = openSession();
72
73 Region region = (Region)session.get(RegionImpl.class,
74 new Long(regionId));
75
76 if (region == null) {
77 if (_log.isWarnEnabled()) {
78 _log.warn("No Region exists with the primary key " +
79 regionId);
80 }
81
82 throw new NoSuchRegionException(
83 "No Region exists with the primary key " + regionId);
84 }
85
86 return remove(region);
87 }
88 catch (NoSuchRegionException nsee) {
89 throw nsee;
90 }
91 catch (Exception e) {
92 throw HibernateUtil.processException(e);
93 }
94 finally {
95 closeSession(session);
96 }
97 }
98
99 public Region remove(Region region) throws SystemException {
100 Session session = null;
101
102 try {
103 session = openSession();
104 session.delete(region);
105 session.flush();
106
107 return region;
108 }
109 catch (Exception e) {
110 throw HibernateUtil.processException(e);
111 }
112 finally {
113 closeSession(session);
114 FinderCache.clearCache(Region.class.getName());
115 }
116 }
117
118 public Region update(com.liferay.portal.model.Region region)
119 throws SystemException {
120 return update(region, false);
121 }
122
123 public Region update(com.liferay.portal.model.Region region, boolean merge)
124 throws SystemException {
125 Session session = null;
126
127 try {
128 session = openSession();
129
130 if (merge) {
131 session.merge(region);
132 }
133 else {
134 if (region.isNew()) {
135 session.save(region);
136 }
137 }
138
139 session.flush();
140 region.setNew(false);
141
142 return region;
143 }
144 catch (Exception e) {
145 throw HibernateUtil.processException(e);
146 }
147 finally {
148 closeSession(session);
149 FinderCache.clearCache(Region.class.getName());
150 }
151 }
152
153 public Region findByPrimaryKey(long regionId)
154 throws NoSuchRegionException, SystemException {
155 Region region = fetchByPrimaryKey(regionId);
156
157 if (region == null) {
158 if (_log.isWarnEnabled()) {
159 _log.warn("No Region exists with the primary key " + regionId);
160 }
161
162 throw new NoSuchRegionException(
163 "No Region exists with the primary key " + regionId);
164 }
165
166 return region;
167 }
168
169 public Region fetchByPrimaryKey(long regionId) throws SystemException {
170 Session session = null;
171
172 try {
173 session = openSession();
174
175 return (Region)session.get(RegionImpl.class, new Long(regionId));
176 }
177 catch (Exception e) {
178 throw HibernateUtil.processException(e);
179 }
180 finally {
181 closeSession(session);
182 }
183 }
184
185 public List findByCountryId(long countryId) throws SystemException {
186 String finderClassName = Region.class.getName();
187 String finderMethodName = "findByCountryId";
188 String[] finderParams = new String[] { Long.class.getName() };
189 Object[] finderArgs = new Object[] { new Long(countryId) };
190 Object result = FinderCache.getResult(finderClassName,
191 finderMethodName, finderParams, finderArgs, getSessionFactory());
192
193 if (result == null) {
194 Session session = null;
195
196 try {
197 session = openSession();
198
199 StringMaker query = new StringMaker();
200 query.append("FROM com.liferay.portal.model.Region WHERE ");
201 query.append("countryId = ?");
202 query.append(" ");
203 query.append("ORDER BY ");
204 query.append("name ASC");
205
206 Query q = session.createQuery(query.toString());
207 int queryPos = 0;
208 q.setLong(queryPos++, countryId);
209
210 List list = q.list();
211 FinderCache.putResult(finderClassName, finderMethodName,
212 finderParams, finderArgs, list);
213
214 return list;
215 }
216 catch (Exception e) {
217 throw HibernateUtil.processException(e);
218 }
219 finally {
220 closeSession(session);
221 }
222 }
223 else {
224 return (List)result;
225 }
226 }
227
228 public List findByCountryId(long countryId, int begin, int end)
229 throws SystemException {
230 return findByCountryId(countryId, begin, end, null);
231 }
232
233 public List findByCountryId(long countryId, int begin, int end,
234 OrderByComparator obc) throws SystemException {
235 String finderClassName = Region.class.getName();
236 String finderMethodName = "findByCountryId";
237 String[] finderParams = new String[] {
238 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
239 "com.liferay.portal.kernel.util.OrderByComparator"
240 };
241 Object[] finderArgs = new Object[] {
242 new Long(countryId), String.valueOf(begin), String.valueOf(end),
243 String.valueOf(obc)
244 };
245 Object result = FinderCache.getResult(finderClassName,
246 finderMethodName, finderParams, finderArgs, getSessionFactory());
247
248 if (result == null) {
249 Session session = null;
250
251 try {
252 session = openSession();
253
254 StringMaker query = new StringMaker();
255 query.append("FROM com.liferay.portal.model.Region WHERE ");
256 query.append("countryId = ?");
257 query.append(" ");
258
259 if (obc != null) {
260 query.append("ORDER BY ");
261 query.append(obc.getOrderBy());
262 }
263 else {
264 query.append("ORDER BY ");
265 query.append("name ASC");
266 }
267
268 Query q = session.createQuery(query.toString());
269 int queryPos = 0;
270 q.setLong(queryPos++, countryId);
271
272 List list = QueryUtil.list(q, getDialect(), begin, end);
273 FinderCache.putResult(finderClassName, finderMethodName,
274 finderParams, finderArgs, list);
275
276 return list;
277 }
278 catch (Exception e) {
279 throw HibernateUtil.processException(e);
280 }
281 finally {
282 closeSession(session);
283 }
284 }
285 else {
286 return (List)result;
287 }
288 }
289
290 public Region findByCountryId_First(long countryId, OrderByComparator obc)
291 throws NoSuchRegionException, SystemException {
292 List list = findByCountryId(countryId, 0, 1, obc);
293
294 if (list.size() == 0) {
295 StringMaker msg = new StringMaker();
296 msg.append("No Region exists with the key ");
297 msg.append(StringPool.OPEN_CURLY_BRACE);
298 msg.append("countryId=");
299 msg.append(countryId);
300 msg.append(StringPool.CLOSE_CURLY_BRACE);
301 throw new NoSuchRegionException(msg.toString());
302 }
303 else {
304 return (Region)list.get(0);
305 }
306 }
307
308 public Region findByCountryId_Last(long countryId, OrderByComparator obc)
309 throws NoSuchRegionException, SystemException {
310 int count = countByCountryId(countryId);
311 List list = findByCountryId(countryId, count - 1, count, obc);
312
313 if (list.size() == 0) {
314 StringMaker msg = new StringMaker();
315 msg.append("No Region exists with the key ");
316 msg.append(StringPool.OPEN_CURLY_BRACE);
317 msg.append("countryId=");
318 msg.append(countryId);
319 msg.append(StringPool.CLOSE_CURLY_BRACE);
320 throw new NoSuchRegionException(msg.toString());
321 }
322 else {
323 return (Region)list.get(0);
324 }
325 }
326
327 public Region[] findByCountryId_PrevAndNext(long regionId, long countryId,
328 OrderByComparator obc) throws NoSuchRegionException, SystemException {
329 Region region = findByPrimaryKey(regionId);
330 int count = countByCountryId(countryId);
331 Session session = null;
332
333 try {
334 session = openSession();
335
336 StringMaker query = new StringMaker();
337 query.append("FROM com.liferay.portal.model.Region WHERE ");
338 query.append("countryId = ?");
339 query.append(" ");
340
341 if (obc != null) {
342 query.append("ORDER BY ");
343 query.append(obc.getOrderBy());
344 }
345 else {
346 query.append("ORDER BY ");
347 query.append("name ASC");
348 }
349
350 Query q = session.createQuery(query.toString());
351 int queryPos = 0;
352 q.setLong(queryPos++, countryId);
353
354 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, region);
355 Region[] array = new RegionImpl[3];
356 array[0] = (Region)objArray[0];
357 array[1] = (Region)objArray[1];
358 array[2] = (Region)objArray[2];
359
360 return array;
361 }
362 catch (Exception e) {
363 throw HibernateUtil.processException(e);
364 }
365 finally {
366 closeSession(session);
367 }
368 }
369
370 public List findByActive(boolean active) throws SystemException {
371 String finderClassName = Region.class.getName();
372 String finderMethodName = "findByActive";
373 String[] finderParams = new String[] { Boolean.class.getName() };
374 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
375 Object result = FinderCache.getResult(finderClassName,
376 finderMethodName, finderParams, finderArgs, getSessionFactory());
377
378 if (result == null) {
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 StringMaker query = new StringMaker();
385 query.append("FROM com.liferay.portal.model.Region WHERE ");
386 query.append("active_ = ?");
387 query.append(" ");
388 query.append("ORDER BY ");
389 query.append("name ASC");
390
391 Query q = session.createQuery(query.toString());
392 int queryPos = 0;
393 q.setBoolean(queryPos++, active);
394
395 List list = q.list();
396 FinderCache.putResult(finderClassName, finderMethodName,
397 finderParams, finderArgs, list);
398
399 return list;
400 }
401 catch (Exception e) {
402 throw HibernateUtil.processException(e);
403 }
404 finally {
405 closeSession(session);
406 }
407 }
408 else {
409 return (List)result;
410 }
411 }
412
413 public List findByActive(boolean active, int begin, int end)
414 throws SystemException {
415 return findByActive(active, begin, end, null);
416 }
417
418 public List findByActive(boolean active, int begin, int end,
419 OrderByComparator obc) throws SystemException {
420 String finderClassName = Region.class.getName();
421 String finderMethodName = "findByActive";
422 String[] finderParams = new String[] {
423 Boolean.class.getName(), "java.lang.Integer",
424 "java.lang.Integer",
425 "com.liferay.portal.kernel.util.OrderByComparator"
426 };
427 Object[] finderArgs = new Object[] {
428 Boolean.valueOf(active), String.valueOf(begin),
429 String.valueOf(end), String.valueOf(obc)
430 };
431 Object result = FinderCache.getResult(finderClassName,
432 finderMethodName, finderParams, finderArgs, getSessionFactory());
433
434 if (result == null) {
435 Session session = null;
436
437 try {
438 session = openSession();
439
440 StringMaker query = new StringMaker();
441 query.append("FROM com.liferay.portal.model.Region WHERE ");
442 query.append("active_ = ?");
443 query.append(" ");
444
445 if (obc != null) {
446 query.append("ORDER BY ");
447 query.append(obc.getOrderBy());
448 }
449 else {
450 query.append("ORDER BY ");
451 query.append("name ASC");
452 }
453
454 Query q = session.createQuery(query.toString());
455 int queryPos = 0;
456 q.setBoolean(queryPos++, active);
457
458 List list = QueryUtil.list(q, getDialect(), begin, end);
459 FinderCache.putResult(finderClassName, finderMethodName,
460 finderParams, finderArgs, list);
461
462 return list;
463 }
464 catch (Exception e) {
465 throw HibernateUtil.processException(e);
466 }
467 finally {
468 closeSession(session);
469 }
470 }
471 else {
472 return (List)result;
473 }
474 }
475
476 public Region findByActive_First(boolean active, OrderByComparator obc)
477 throws NoSuchRegionException, SystemException {
478 List list = findByActive(active, 0, 1, obc);
479
480 if (list.size() == 0) {
481 StringMaker msg = new StringMaker();
482 msg.append("No Region exists with the key ");
483 msg.append(StringPool.OPEN_CURLY_BRACE);
484 msg.append("active=");
485 msg.append(active);
486 msg.append(StringPool.CLOSE_CURLY_BRACE);
487 throw new NoSuchRegionException(msg.toString());
488 }
489 else {
490 return (Region)list.get(0);
491 }
492 }
493
494 public Region findByActive_Last(boolean active, OrderByComparator obc)
495 throws NoSuchRegionException, SystemException {
496 int count = countByActive(active);
497 List list = findByActive(active, count - 1, count, obc);
498
499 if (list.size() == 0) {
500 StringMaker msg = new StringMaker();
501 msg.append("No Region exists with the key ");
502 msg.append(StringPool.OPEN_CURLY_BRACE);
503 msg.append("active=");
504 msg.append(active);
505 msg.append(StringPool.CLOSE_CURLY_BRACE);
506 throw new NoSuchRegionException(msg.toString());
507 }
508 else {
509 return (Region)list.get(0);
510 }
511 }
512
513 public Region[] findByActive_PrevAndNext(long regionId, boolean active,
514 OrderByComparator obc) throws NoSuchRegionException, SystemException {
515 Region region = findByPrimaryKey(regionId);
516 int count = countByActive(active);
517 Session session = null;
518
519 try {
520 session = openSession();
521
522 StringMaker query = new StringMaker();
523 query.append("FROM com.liferay.portal.model.Region WHERE ");
524 query.append("active_ = ?");
525 query.append(" ");
526
527 if (obc != null) {
528 query.append("ORDER BY ");
529 query.append(obc.getOrderBy());
530 }
531 else {
532 query.append("ORDER BY ");
533 query.append("name ASC");
534 }
535
536 Query q = session.createQuery(query.toString());
537 int queryPos = 0;
538 q.setBoolean(queryPos++, active);
539
540 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, region);
541 Region[] array = new RegionImpl[3];
542 array[0] = (Region)objArray[0];
543 array[1] = (Region)objArray[1];
544 array[2] = (Region)objArray[2];
545
546 return array;
547 }
548 catch (Exception e) {
549 throw HibernateUtil.processException(e);
550 }
551 finally {
552 closeSession(session);
553 }
554 }
555
556 public List findByC_A(long countryId, boolean active)
557 throws SystemException {
558 String finderClassName = Region.class.getName();
559 String finderMethodName = "findByC_A";
560 String[] finderParams = new String[] {
561 Long.class.getName(), Boolean.class.getName()
562 };
563 Object[] finderArgs = new Object[] {
564 new Long(countryId), Boolean.valueOf(active)
565 };
566 Object result = FinderCache.getResult(finderClassName,
567 finderMethodName, finderParams, finderArgs, getSessionFactory());
568
569 if (result == null) {
570 Session session = null;
571
572 try {
573 session = openSession();
574
575 StringMaker query = new StringMaker();
576 query.append("FROM com.liferay.portal.model.Region WHERE ");
577 query.append("countryId = ?");
578 query.append(" AND ");
579 query.append("active_ = ?");
580 query.append(" ");
581 query.append("ORDER BY ");
582 query.append("name ASC");
583
584 Query q = session.createQuery(query.toString());
585 int queryPos = 0;
586 q.setLong(queryPos++, countryId);
587 q.setBoolean(queryPos++, active);
588
589 List list = q.list();
590 FinderCache.putResult(finderClassName, finderMethodName,
591 finderParams, finderArgs, list);
592
593 return list;
594 }
595 catch (Exception e) {
596 throw HibernateUtil.processException(e);
597 }
598 finally {
599 closeSession(session);
600 }
601 }
602 else {
603 return (List)result;
604 }
605 }
606
607 public List findByC_A(long countryId, boolean active, int begin, int end)
608 throws SystemException {
609 return findByC_A(countryId, active, begin, end, null);
610 }
611
612 public List findByC_A(long countryId, boolean active, int begin, int end,
613 OrderByComparator obc) throws SystemException {
614 String finderClassName = Region.class.getName();
615 String finderMethodName = "findByC_A";
616 String[] finderParams = new String[] {
617 Long.class.getName(), Boolean.class.getName(),
618 "java.lang.Integer", "java.lang.Integer",
619 "com.liferay.portal.kernel.util.OrderByComparator"
620 };
621 Object[] finderArgs = new Object[] {
622 new Long(countryId), Boolean.valueOf(active),
623 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
624 };
625 Object result = FinderCache.getResult(finderClassName,
626 finderMethodName, finderParams, finderArgs, getSessionFactory());
627
628 if (result == null) {
629 Session session = null;
630
631 try {
632 session = openSession();
633
634 StringMaker query = new StringMaker();
635 query.append("FROM com.liferay.portal.model.Region WHERE ");
636 query.append("countryId = ?");
637 query.append(" AND ");
638 query.append("active_ = ?");
639 query.append(" ");
640
641 if (obc != null) {
642 query.append("ORDER BY ");
643 query.append(obc.getOrderBy());
644 }
645 else {
646 query.append("ORDER BY ");
647 query.append("name ASC");
648 }
649
650 Query q = session.createQuery(query.toString());
651 int queryPos = 0;
652 q.setLong(queryPos++, countryId);
653 q.setBoolean(queryPos++, active);
654
655 List list = QueryUtil.list(q, getDialect(), begin, end);
656 FinderCache.putResult(finderClassName, finderMethodName,
657 finderParams, finderArgs, list);
658
659 return list;
660 }
661 catch (Exception e) {
662 throw HibernateUtil.processException(e);
663 }
664 finally {
665 closeSession(session);
666 }
667 }
668 else {
669 return (List)result;
670 }
671 }
672
673 public Region findByC_A_First(long countryId, boolean active,
674 OrderByComparator obc) throws NoSuchRegionException, SystemException {
675 List list = findByC_A(countryId, active, 0, 1, obc);
676
677 if (list.size() == 0) {
678 StringMaker msg = new StringMaker();
679 msg.append("No Region exists with the key ");
680 msg.append(StringPool.OPEN_CURLY_BRACE);
681 msg.append("countryId=");
682 msg.append(countryId);
683 msg.append(", ");
684 msg.append("active=");
685 msg.append(active);
686 msg.append(StringPool.CLOSE_CURLY_BRACE);
687 throw new NoSuchRegionException(msg.toString());
688 }
689 else {
690 return (Region)list.get(0);
691 }
692 }
693
694 public Region findByC_A_Last(long countryId, boolean active,
695 OrderByComparator obc) throws NoSuchRegionException, SystemException {
696 int count = countByC_A(countryId, active);
697 List list = findByC_A(countryId, active, count - 1, count, obc);
698
699 if (list.size() == 0) {
700 StringMaker msg = new StringMaker();
701 msg.append("No Region exists with the key ");
702 msg.append(StringPool.OPEN_CURLY_BRACE);
703 msg.append("countryId=");
704 msg.append(countryId);
705 msg.append(", ");
706 msg.append("active=");
707 msg.append(active);
708 msg.append(StringPool.CLOSE_CURLY_BRACE);
709 throw new NoSuchRegionException(msg.toString());
710 }
711 else {
712 return (Region)list.get(0);
713 }
714 }
715
716 public Region[] findByC_A_PrevAndNext(long regionId, long countryId,
717 boolean active, OrderByComparator obc)
718 throws NoSuchRegionException, SystemException {
719 Region region = findByPrimaryKey(regionId);
720 int count = countByC_A(countryId, active);
721 Session session = null;
722
723 try {
724 session = openSession();
725
726 StringMaker query = new StringMaker();
727 query.append("FROM com.liferay.portal.model.Region WHERE ");
728 query.append("countryId = ?");
729 query.append(" AND ");
730 query.append("active_ = ?");
731 query.append(" ");
732
733 if (obc != null) {
734 query.append("ORDER BY ");
735 query.append(obc.getOrderBy());
736 }
737 else {
738 query.append("ORDER BY ");
739 query.append("name ASC");
740 }
741
742 Query q = session.createQuery(query.toString());
743 int queryPos = 0;
744 q.setLong(queryPos++, countryId);
745 q.setBoolean(queryPos++, active);
746
747 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, region);
748 Region[] array = new RegionImpl[3];
749 array[0] = (Region)objArray[0];
750 array[1] = (Region)objArray[1];
751 array[2] = (Region)objArray[2];
752
753 return array;
754 }
755 catch (Exception e) {
756 throw HibernateUtil.processException(e);
757 }
758 finally {
759 closeSession(session);
760 }
761 }
762
763 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
764 throws SystemException {
765 Session session = null;
766
767 try {
768 session = openSession();
769
770 DynamicQuery query = queryInitializer.initialize(session);
771
772 return query.list();
773 }
774 catch (Exception e) {
775 throw HibernateUtil.processException(e);
776 }
777 finally {
778 closeSession(session);
779 }
780 }
781
782 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
783 int begin, int end) throws SystemException {
784 Session session = null;
785
786 try {
787 session = openSession();
788
789 DynamicQuery query = queryInitializer.initialize(session);
790 query.setLimit(begin, end);
791
792 return query.list();
793 }
794 catch (Exception e) {
795 throw HibernateUtil.processException(e);
796 }
797 finally {
798 closeSession(session);
799 }
800 }
801
802 public List findAll() throws SystemException {
803 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
804 }
805
806 public List findAll(int begin, int end) throws SystemException {
807 return findAll(begin, end, null);
808 }
809
810 public List findAll(int begin, int end, OrderByComparator obc)
811 throws SystemException {
812 String finderClassName = Region.class.getName();
813 String finderMethodName = "findAll";
814 String[] finderParams = new String[] {
815 "java.lang.Integer", "java.lang.Integer",
816 "com.liferay.portal.kernel.util.OrderByComparator"
817 };
818 Object[] finderArgs = new Object[] {
819 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
820 };
821 Object result = FinderCache.getResult(finderClassName,
822 finderMethodName, finderParams, finderArgs, getSessionFactory());
823
824 if (result == null) {
825 Session session = null;
826
827 try {
828 session = openSession();
829
830 StringMaker query = new StringMaker();
831 query.append("FROM com.liferay.portal.model.Region ");
832
833 if (obc != null) {
834 query.append("ORDER BY ");
835 query.append(obc.getOrderBy());
836 }
837 else {
838 query.append("ORDER BY ");
839 query.append("name ASC");
840 }
841
842 Query q = session.createQuery(query.toString());
843 List list = QueryUtil.list(q, getDialect(), begin, end);
844
845 if (obc == null) {
846 Collections.sort(list);
847 }
848
849 FinderCache.putResult(finderClassName, finderMethodName,
850 finderParams, finderArgs, list);
851
852 return list;
853 }
854 catch (Exception e) {
855 throw HibernateUtil.processException(e);
856 }
857 finally {
858 closeSession(session);
859 }
860 }
861 else {
862 return (List)result;
863 }
864 }
865
866 public void removeByCountryId(long countryId) throws SystemException {
867 Iterator itr = findByCountryId(countryId).iterator();
868
869 while (itr.hasNext()) {
870 Region region = (Region)itr.next();
871 remove(region);
872 }
873 }
874
875 public void removeByActive(boolean active) throws SystemException {
876 Iterator itr = findByActive(active).iterator();
877
878 while (itr.hasNext()) {
879 Region region = (Region)itr.next();
880 remove(region);
881 }
882 }
883
884 public void removeByC_A(long countryId, boolean active)
885 throws SystemException {
886 Iterator itr = findByC_A(countryId, active).iterator();
887
888 while (itr.hasNext()) {
889 Region region = (Region)itr.next();
890 remove(region);
891 }
892 }
893
894 public void removeAll() throws SystemException {
895 Iterator itr = findAll().iterator();
896
897 while (itr.hasNext()) {
898 remove((Region)itr.next());
899 }
900 }
901
902 public int countByCountryId(long countryId) throws SystemException {
903 String finderClassName = Region.class.getName();
904 String finderMethodName = "countByCountryId";
905 String[] finderParams = new String[] { Long.class.getName() };
906 Object[] finderArgs = new Object[] { new Long(countryId) };
907 Object result = FinderCache.getResult(finderClassName,
908 finderMethodName, finderParams, finderArgs, getSessionFactory());
909
910 if (result == null) {
911 Session session = null;
912
913 try {
914 session = openSession();
915
916 StringMaker query = new StringMaker();
917 query.append("SELECT COUNT(*) ");
918 query.append("FROM com.liferay.portal.model.Region WHERE ");
919 query.append("countryId = ?");
920 query.append(" ");
921
922 Query q = session.createQuery(query.toString());
923 int queryPos = 0;
924 q.setLong(queryPos++, countryId);
925
926 Long count = null;
927 Iterator itr = q.list().iterator();
928
929 if (itr.hasNext()) {
930 count = (Long)itr.next();
931 }
932
933 if (count == null) {
934 count = new Long(0);
935 }
936
937 FinderCache.putResult(finderClassName, finderMethodName,
938 finderParams, finderArgs, count);
939
940 return count.intValue();
941 }
942 catch (Exception e) {
943 throw HibernateUtil.processException(e);
944 }
945 finally {
946 closeSession(session);
947 }
948 }
949 else {
950 return ((Long)result).intValue();
951 }
952 }
953
954 public int countByActive(boolean active) throws SystemException {
955 String finderClassName = Region.class.getName();
956 String finderMethodName = "countByActive";
957 String[] finderParams = new String[] { Boolean.class.getName() };
958 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
959 Object result = FinderCache.getResult(finderClassName,
960 finderMethodName, finderParams, finderArgs, getSessionFactory());
961
962 if (result == null) {
963 Session session = null;
964
965 try {
966 session = openSession();
967
968 StringMaker query = new StringMaker();
969 query.append("SELECT COUNT(*) ");
970 query.append("FROM com.liferay.portal.model.Region WHERE ");
971 query.append("active_ = ?");
972 query.append(" ");
973
974 Query q = session.createQuery(query.toString());
975 int queryPos = 0;
976 q.setBoolean(queryPos++, active);
977
978 Long count = null;
979 Iterator itr = q.list().iterator();
980
981 if (itr.hasNext()) {
982 count = (Long)itr.next();
983 }
984
985 if (count == null) {
986 count = new Long(0);
987 }
988
989 FinderCache.putResult(finderClassName, finderMethodName,
990 finderParams, finderArgs, count);
991
992 return count.intValue();
993 }
994 catch (Exception e) {
995 throw HibernateUtil.processException(e);
996 }
997 finally {
998 closeSession(session);
999 }
1000 }
1001 else {
1002 return ((Long)result).intValue();
1003 }
1004 }
1005
1006 public int countByC_A(long countryId, boolean active)
1007 throws SystemException {
1008 String finderClassName = Region.class.getName();
1009 String finderMethodName = "countByC_A";
1010 String[] finderParams = new String[] {
1011 Long.class.getName(), Boolean.class.getName()
1012 };
1013 Object[] finderArgs = new Object[] {
1014 new Long(countryId), Boolean.valueOf(active)
1015 };
1016 Object result = FinderCache.getResult(finderClassName,
1017 finderMethodName, finderParams, finderArgs, getSessionFactory());
1018
1019 if (result == null) {
1020 Session session = null;
1021
1022 try {
1023 session = openSession();
1024
1025 StringMaker query = new StringMaker();
1026 query.append("SELECT COUNT(*) ");
1027 query.append("FROM com.liferay.portal.model.Region WHERE ");
1028 query.append("countryId = ?");
1029 query.append(" AND ");
1030 query.append("active_ = ?");
1031 query.append(" ");
1032
1033 Query q = session.createQuery(query.toString());
1034 int queryPos = 0;
1035 q.setLong(queryPos++, countryId);
1036 q.setBoolean(queryPos++, active);
1037
1038 Long count = null;
1039 Iterator itr = q.list().iterator();
1040
1041 if (itr.hasNext()) {
1042 count = (Long)itr.next();
1043 }
1044
1045 if (count == null) {
1046 count = new Long(0);
1047 }
1048
1049 FinderCache.putResult(finderClassName, finderMethodName,
1050 finderParams, finderArgs, count);
1051
1052 return count.intValue();
1053 }
1054 catch (Exception e) {
1055 throw HibernateUtil.processException(e);
1056 }
1057 finally {
1058 closeSession(session);
1059 }
1060 }
1061 else {
1062 return ((Long)result).intValue();
1063 }
1064 }
1065
1066 public int countAll() throws SystemException {
1067 String finderClassName = Region.class.getName();
1068 String finderMethodName = "countAll";
1069 String[] finderParams = new String[] { };
1070 Object[] finderArgs = new Object[] { };
1071 Object result = FinderCache.getResult(finderClassName,
1072 finderMethodName, finderParams, finderArgs, getSessionFactory());
1073
1074 if (result == null) {
1075 Session session = null;
1076
1077 try {
1078 session = openSession();
1079
1080 StringMaker query = new StringMaker();
1081 query.append("SELECT COUNT(*) ");
1082 query.append("FROM com.liferay.portal.model.Region");
1083
1084 Query q = session.createQuery(query.toString());
1085 Long count = null;
1086 Iterator itr = q.list().iterator();
1087
1088 if (itr.hasNext()) {
1089 count = (Long)itr.next();
1090 }
1091
1092 if (count == null) {
1093 count = new Long(0);
1094 }
1095
1096 FinderCache.putResult(finderClassName, finderMethodName,
1097 finderParams, finderArgs, count);
1098
1099 return count.intValue();
1100 }
1101 catch (Exception e) {
1102 throw HibernateUtil.processException(e);
1103 }
1104 finally {
1105 closeSession(session);
1106 }
1107 }
1108 else {
1109 return ((Long)result).intValue();
1110 }
1111 }
1112
1113 protected void initDao() {
1114 }
1115
1116 private static Log _log = LogFactory.getLog(RegionPersistenceImpl.class);
1117}