1
19
20 package com.liferay.portal.service.persistence;
21
22 import com.liferay.portal.NoSuchCountryException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
25 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
26 import com.liferay.portal.kernel.dao.orm.Query;
27 import com.liferay.portal.kernel.dao.orm.QueryPos;
28 import com.liferay.portal.kernel.dao.orm.QueryUtil;
29 import com.liferay.portal.kernel.dao.orm.Session;
30 import com.liferay.portal.kernel.log.Log;
31 import com.liferay.portal.kernel.log.LogFactoryUtil;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.OrderByComparator;
34 import com.liferay.portal.kernel.util.StringPool;
35 import com.liferay.portal.kernel.util.StringUtil;
36 import com.liferay.portal.model.Country;
37 import com.liferay.portal.model.ModelListener;
38 import com.liferay.portal.model.impl.CountryImpl;
39 import com.liferay.portal.model.impl.CountryModelImpl;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.Iterator;
45 import java.util.List;
46
47
53 public class CountryPersistenceImpl extends BasePersistenceImpl
54 implements CountryPersistence {
55 public Country create(long countryId) {
56 Country country = new CountryImpl();
57
58 country.setNew(true);
59 country.setPrimaryKey(countryId);
60
61 return country;
62 }
63
64 public Country remove(long countryId)
65 throws NoSuchCountryException, SystemException {
66 Session session = null;
67
68 try {
69 session = openSession();
70
71 Country country = (Country)session.get(CountryImpl.class,
72 new Long(countryId));
73
74 if (country == null) {
75 if (_log.isWarnEnabled()) {
76 _log.warn("No Country exists with the primary key " +
77 countryId);
78 }
79
80 throw new NoSuchCountryException(
81 "No Country exists with the primary key " + countryId);
82 }
83
84 return remove(country);
85 }
86 catch (NoSuchCountryException nsee) {
87 throw nsee;
88 }
89 catch (Exception e) {
90 throw processException(e);
91 }
92 finally {
93 closeSession(session);
94 }
95 }
96
97 public Country remove(Country country) throws SystemException {
98 for (ModelListener listener : listeners) {
99 listener.onBeforeRemove(country);
100 }
101
102 country = removeImpl(country);
103
104 for (ModelListener listener : listeners) {
105 listener.onAfterRemove(country);
106 }
107
108 return country;
109 }
110
111 protected Country removeImpl(Country country) throws SystemException {
112 Session session = null;
113
114 try {
115 session = openSession();
116
117 if (BatchSessionUtil.isEnabled()) {
118 Object staleObject = session.get(CountryImpl.class,
119 country.getPrimaryKeyObj());
120
121 if (staleObject != null) {
122 session.evict(staleObject);
123 }
124 }
125
126 session.delete(country);
127
128 session.flush();
129
130 return country;
131 }
132 catch (Exception e) {
133 throw processException(e);
134 }
135 finally {
136 closeSession(session);
137
138 FinderCacheUtil.clearCache(Country.class.getName());
139 }
140 }
141
142
145 public Country update(Country country) throws SystemException {
146 if (_log.isWarnEnabled()) {
147 _log.warn(
148 "Using the deprecated update(Country country) method. Use update(Country country, boolean merge) instead.");
149 }
150
151 return update(country, false);
152 }
153
154
167 public Country update(Country country, boolean merge)
168 throws SystemException {
169 boolean isNew = country.isNew();
170
171 for (ModelListener listener : listeners) {
172 if (isNew) {
173 listener.onBeforeCreate(country);
174 }
175 else {
176 listener.onBeforeUpdate(country);
177 }
178 }
179
180 country = updateImpl(country, merge);
181
182 for (ModelListener listener : listeners) {
183 if (isNew) {
184 listener.onAfterCreate(country);
185 }
186 else {
187 listener.onAfterUpdate(country);
188 }
189 }
190
191 return country;
192 }
193
194 public Country updateImpl(com.liferay.portal.model.Country country,
195 boolean merge) throws SystemException {
196 Session session = null;
197
198 try {
199 session = openSession();
200
201 BatchSessionUtil.update(session, country, merge);
202
203 country.setNew(false);
204
205 return country;
206 }
207 catch (Exception e) {
208 throw processException(e);
209 }
210 finally {
211 closeSession(session);
212
213 FinderCacheUtil.clearCache(Country.class.getName());
214 }
215 }
216
217 public Country findByPrimaryKey(long countryId)
218 throws NoSuchCountryException, SystemException {
219 Country country = fetchByPrimaryKey(countryId);
220
221 if (country == null) {
222 if (_log.isWarnEnabled()) {
223 _log.warn("No Country exists with the primary key " +
224 countryId);
225 }
226
227 throw new NoSuchCountryException(
228 "No Country exists with the primary key " + countryId);
229 }
230
231 return country;
232 }
233
234 public Country fetchByPrimaryKey(long countryId) throws SystemException {
235 Session session = null;
236
237 try {
238 session = openSession();
239
240 return (Country)session.get(CountryImpl.class, new Long(countryId));
241 }
242 catch (Exception e) {
243 throw processException(e);
244 }
245 finally {
246 closeSession(session);
247 }
248 }
249
250 public Country findByName(String name)
251 throws NoSuchCountryException, SystemException {
252 Country country = fetchByName(name);
253
254 if (country == null) {
255 StringBuilder msg = new StringBuilder();
256
257 msg.append("No Country exists with the key {");
258
259 msg.append("name=" + name);
260
261 msg.append(StringPool.CLOSE_CURLY_BRACE);
262
263 if (_log.isWarnEnabled()) {
264 _log.warn(msg.toString());
265 }
266
267 throw new NoSuchCountryException(msg.toString());
268 }
269
270 return country;
271 }
272
273 public Country fetchByName(String name) throws SystemException {
274 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
275 String finderClassName = Country.class.getName();
276 String finderMethodName = "fetchByName";
277 String[] finderParams = new String[] { String.class.getName() };
278 Object[] finderArgs = new Object[] { name };
279
280 Object result = null;
281
282 if (finderClassNameCacheEnabled) {
283 result = FinderCacheUtil.getResult(finderClassName,
284 finderMethodName, finderParams, finderArgs, this);
285 }
286
287 if (result == null) {
288 Session session = null;
289
290 try {
291 session = openSession();
292
293 StringBuilder query = new StringBuilder();
294
295 query.append("FROM com.liferay.portal.model.Country WHERE ");
296
297 if (name == null) {
298 query.append("name IS NULL");
299 }
300 else {
301 query.append("name = ?");
302 }
303
304 query.append(" ");
305
306 query.append("ORDER BY ");
307
308 query.append("name ASC");
309
310 Query q = session.createQuery(query.toString());
311
312 QueryPos qPos = QueryPos.getInstance(q);
313
314 if (name != null) {
315 qPos.add(name);
316 }
317
318 List<Country> list = q.list();
319
320 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
321 finderClassName, finderMethodName, finderParams,
322 finderArgs, list);
323
324 if (list.size() == 0) {
325 return null;
326 }
327 else {
328 return list.get(0);
329 }
330 }
331 catch (Exception e) {
332 throw processException(e);
333 }
334 finally {
335 closeSession(session);
336 }
337 }
338 else {
339 List<Country> list = (List<Country>)result;
340
341 if (list.size() == 0) {
342 return null;
343 }
344 else {
345 return list.get(0);
346 }
347 }
348 }
349
350 public Country findByA2(String a2)
351 throws NoSuchCountryException, SystemException {
352 Country country = fetchByA2(a2);
353
354 if (country == null) {
355 StringBuilder msg = new StringBuilder();
356
357 msg.append("No Country exists with the key {");
358
359 msg.append("a2=" + a2);
360
361 msg.append(StringPool.CLOSE_CURLY_BRACE);
362
363 if (_log.isWarnEnabled()) {
364 _log.warn(msg.toString());
365 }
366
367 throw new NoSuchCountryException(msg.toString());
368 }
369
370 return country;
371 }
372
373 public Country fetchByA2(String a2) throws SystemException {
374 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
375 String finderClassName = Country.class.getName();
376 String finderMethodName = "fetchByA2";
377 String[] finderParams = new String[] { String.class.getName() };
378 Object[] finderArgs = new Object[] { a2 };
379
380 Object result = null;
381
382 if (finderClassNameCacheEnabled) {
383 result = FinderCacheUtil.getResult(finderClassName,
384 finderMethodName, finderParams, finderArgs, this);
385 }
386
387 if (result == null) {
388 Session session = null;
389
390 try {
391 session = openSession();
392
393 StringBuilder query = new StringBuilder();
394
395 query.append("FROM com.liferay.portal.model.Country WHERE ");
396
397 if (a2 == null) {
398 query.append("a2 IS NULL");
399 }
400 else {
401 query.append("a2 = ?");
402 }
403
404 query.append(" ");
405
406 query.append("ORDER BY ");
407
408 query.append("name ASC");
409
410 Query q = session.createQuery(query.toString());
411
412 QueryPos qPos = QueryPos.getInstance(q);
413
414 if (a2 != null) {
415 qPos.add(a2);
416 }
417
418 List<Country> list = q.list();
419
420 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
421 finderClassName, finderMethodName, finderParams,
422 finderArgs, list);
423
424 if (list.size() == 0) {
425 return null;
426 }
427 else {
428 return list.get(0);
429 }
430 }
431 catch (Exception e) {
432 throw processException(e);
433 }
434 finally {
435 closeSession(session);
436 }
437 }
438 else {
439 List<Country> list = (List<Country>)result;
440
441 if (list.size() == 0) {
442 return null;
443 }
444 else {
445 return list.get(0);
446 }
447 }
448 }
449
450 public Country findByA3(String a3)
451 throws NoSuchCountryException, SystemException {
452 Country country = fetchByA3(a3);
453
454 if (country == null) {
455 StringBuilder msg = new StringBuilder();
456
457 msg.append("No Country exists with the key {");
458
459 msg.append("a3=" + a3);
460
461 msg.append(StringPool.CLOSE_CURLY_BRACE);
462
463 if (_log.isWarnEnabled()) {
464 _log.warn(msg.toString());
465 }
466
467 throw new NoSuchCountryException(msg.toString());
468 }
469
470 return country;
471 }
472
473 public Country fetchByA3(String a3) throws SystemException {
474 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
475 String finderClassName = Country.class.getName();
476 String finderMethodName = "fetchByA3";
477 String[] finderParams = new String[] { String.class.getName() };
478 Object[] finderArgs = new Object[] { a3 };
479
480 Object result = null;
481
482 if (finderClassNameCacheEnabled) {
483 result = FinderCacheUtil.getResult(finderClassName,
484 finderMethodName, finderParams, finderArgs, this);
485 }
486
487 if (result == null) {
488 Session session = null;
489
490 try {
491 session = openSession();
492
493 StringBuilder query = new StringBuilder();
494
495 query.append("FROM com.liferay.portal.model.Country WHERE ");
496
497 if (a3 == null) {
498 query.append("a3 IS NULL");
499 }
500 else {
501 query.append("a3 = ?");
502 }
503
504 query.append(" ");
505
506 query.append("ORDER BY ");
507
508 query.append("name ASC");
509
510 Query q = session.createQuery(query.toString());
511
512 QueryPos qPos = QueryPos.getInstance(q);
513
514 if (a3 != null) {
515 qPos.add(a3);
516 }
517
518 List<Country> list = q.list();
519
520 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
521 finderClassName, finderMethodName, finderParams,
522 finderArgs, list);
523
524 if (list.size() == 0) {
525 return null;
526 }
527 else {
528 return list.get(0);
529 }
530 }
531 catch (Exception e) {
532 throw processException(e);
533 }
534 finally {
535 closeSession(session);
536 }
537 }
538 else {
539 List<Country> list = (List<Country>)result;
540
541 if (list.size() == 0) {
542 return null;
543 }
544 else {
545 return list.get(0);
546 }
547 }
548 }
549
550 public List<Country> findByActive(boolean active) throws SystemException {
551 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
552 String finderClassName = Country.class.getName();
553 String finderMethodName = "findByActive";
554 String[] finderParams = new String[] { Boolean.class.getName() };
555 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
556
557 Object result = null;
558
559 if (finderClassNameCacheEnabled) {
560 result = FinderCacheUtil.getResult(finderClassName,
561 finderMethodName, finderParams, finderArgs, this);
562 }
563
564 if (result == null) {
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 StringBuilder query = new StringBuilder();
571
572 query.append("FROM com.liferay.portal.model.Country WHERE ");
573
574 query.append("active_ = ?");
575
576 query.append(" ");
577
578 query.append("ORDER BY ");
579
580 query.append("name ASC");
581
582 Query q = session.createQuery(query.toString());
583
584 QueryPos qPos = QueryPos.getInstance(q);
585
586 qPos.add(active);
587
588 List<Country> list = q.list();
589
590 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
591 finderClassName, finderMethodName, finderParams,
592 finderArgs, list);
593
594 return list;
595 }
596 catch (Exception e) {
597 throw processException(e);
598 }
599 finally {
600 closeSession(session);
601 }
602 }
603 else {
604 return (List<Country>)result;
605 }
606 }
607
608 public List<Country> findByActive(boolean active, int start, int end)
609 throws SystemException {
610 return findByActive(active, start, end, null);
611 }
612
613 public List<Country> findByActive(boolean active, int start, int end,
614 OrderByComparator obc) throws SystemException {
615 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
616 String finderClassName = Country.class.getName();
617 String finderMethodName = "findByActive";
618 String[] finderParams = new String[] {
619 Boolean.class.getName(),
620
621 "java.lang.Integer", "java.lang.Integer",
622 "com.liferay.portal.kernel.util.OrderByComparator"
623 };
624 Object[] finderArgs = new Object[] {
625 Boolean.valueOf(active),
626
627 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
628 };
629
630 Object result = null;
631
632 if (finderClassNameCacheEnabled) {
633 result = FinderCacheUtil.getResult(finderClassName,
634 finderMethodName, finderParams, finderArgs, this);
635 }
636
637 if (result == null) {
638 Session session = null;
639
640 try {
641 session = openSession();
642
643 StringBuilder query = new StringBuilder();
644
645 query.append("FROM com.liferay.portal.model.Country WHERE ");
646
647 query.append("active_ = ?");
648
649 query.append(" ");
650
651 if (obc != null) {
652 query.append("ORDER BY ");
653 query.append(obc.getOrderBy());
654 }
655
656 else {
657 query.append("ORDER BY ");
658
659 query.append("name ASC");
660 }
661
662 Query q = session.createQuery(query.toString());
663
664 QueryPos qPos = QueryPos.getInstance(q);
665
666 qPos.add(active);
667
668 List<Country> list = (List<Country>)QueryUtil.list(q,
669 getDialect(), start, end);
670
671 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
672 finderClassName, finderMethodName, finderParams,
673 finderArgs, list);
674
675 return list;
676 }
677 catch (Exception e) {
678 throw processException(e);
679 }
680 finally {
681 closeSession(session);
682 }
683 }
684 else {
685 return (List<Country>)result;
686 }
687 }
688
689 public Country findByActive_First(boolean active, OrderByComparator obc)
690 throws NoSuchCountryException, SystemException {
691 List<Country> list = findByActive(active, 0, 1, obc);
692
693 if (list.size() == 0) {
694 StringBuilder msg = new StringBuilder();
695
696 msg.append("No Country exists with the key {");
697
698 msg.append("active=" + active);
699
700 msg.append(StringPool.CLOSE_CURLY_BRACE);
701
702 throw new NoSuchCountryException(msg.toString());
703 }
704 else {
705 return list.get(0);
706 }
707 }
708
709 public Country findByActive_Last(boolean active, OrderByComparator obc)
710 throws NoSuchCountryException, SystemException {
711 int count = countByActive(active);
712
713 List<Country> list = findByActive(active, count - 1, count, obc);
714
715 if (list.size() == 0) {
716 StringBuilder msg = new StringBuilder();
717
718 msg.append("No Country exists with the key {");
719
720 msg.append("active=" + active);
721
722 msg.append(StringPool.CLOSE_CURLY_BRACE);
723
724 throw new NoSuchCountryException(msg.toString());
725 }
726 else {
727 return list.get(0);
728 }
729 }
730
731 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
732 OrderByComparator obc) throws NoSuchCountryException, SystemException {
733 Country country = findByPrimaryKey(countryId);
734
735 int count = countByActive(active);
736
737 Session session = null;
738
739 try {
740 session = openSession();
741
742 StringBuilder query = new StringBuilder();
743
744 query.append("FROM com.liferay.portal.model.Country WHERE ");
745
746 query.append("active_ = ?");
747
748 query.append(" ");
749
750 if (obc != null) {
751 query.append("ORDER BY ");
752 query.append(obc.getOrderBy());
753 }
754
755 else {
756 query.append("ORDER BY ");
757
758 query.append("name ASC");
759 }
760
761 Query q = session.createQuery(query.toString());
762
763 QueryPos qPos = QueryPos.getInstance(q);
764
765 qPos.add(active);
766
767 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, country);
768
769 Country[] array = new CountryImpl[3];
770
771 array[0] = (Country)objArray[0];
772 array[1] = (Country)objArray[1];
773 array[2] = (Country)objArray[2];
774
775 return array;
776 }
777 catch (Exception e) {
778 throw processException(e);
779 }
780 finally {
781 closeSession(session);
782 }
783 }
784
785 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
786 throws SystemException {
787 Session session = null;
788
789 try {
790 session = openSession();
791
792 dynamicQuery.compile(session);
793
794 return dynamicQuery.list();
795 }
796 catch (Exception e) {
797 throw processException(e);
798 }
799 finally {
800 closeSession(session);
801 }
802 }
803
804 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
805 int start, int end) throws SystemException {
806 Session session = null;
807
808 try {
809 session = openSession();
810
811 dynamicQuery.setLimit(start, end);
812
813 dynamicQuery.compile(session);
814
815 return dynamicQuery.list();
816 }
817 catch (Exception e) {
818 throw processException(e);
819 }
820 finally {
821 closeSession(session);
822 }
823 }
824
825 public List<Country> findAll() throws SystemException {
826 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
827 }
828
829 public List<Country> findAll(int start, int end) throws SystemException {
830 return findAll(start, end, null);
831 }
832
833 public List<Country> findAll(int start, int end, OrderByComparator obc)
834 throws SystemException {
835 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
836 String finderClassName = Country.class.getName();
837 String finderMethodName = "findAll";
838 String[] finderParams = new String[] {
839 "java.lang.Integer", "java.lang.Integer",
840 "com.liferay.portal.kernel.util.OrderByComparator"
841 };
842 Object[] finderArgs = new Object[] {
843 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
844 };
845
846 Object result = null;
847
848 if (finderClassNameCacheEnabled) {
849 result = FinderCacheUtil.getResult(finderClassName,
850 finderMethodName, finderParams, finderArgs, this);
851 }
852
853 if (result == null) {
854 Session session = null;
855
856 try {
857 session = openSession();
858
859 StringBuilder query = new StringBuilder();
860
861 query.append("FROM com.liferay.portal.model.Country ");
862
863 if (obc != null) {
864 query.append("ORDER BY ");
865 query.append(obc.getOrderBy());
866 }
867
868 else {
869 query.append("ORDER BY ");
870
871 query.append("name ASC");
872 }
873
874 Query q = session.createQuery(query.toString());
875
876 List<Country> list = null;
877
878 if (obc == null) {
879 list = (List<Country>)QueryUtil.list(q, getDialect(),
880 start, end, false);
881
882 Collections.sort(list);
883 }
884 else {
885 list = (List<Country>)QueryUtil.list(q, getDialect(),
886 start, end);
887 }
888
889 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
890 finderClassName, finderMethodName, finderParams,
891 finderArgs, list);
892
893 return list;
894 }
895 catch (Exception e) {
896 throw processException(e);
897 }
898 finally {
899 closeSession(session);
900 }
901 }
902 else {
903 return (List<Country>)result;
904 }
905 }
906
907 public void removeByName(String name)
908 throws NoSuchCountryException, SystemException {
909 Country country = findByName(name);
910
911 remove(country);
912 }
913
914 public void removeByA2(String a2)
915 throws NoSuchCountryException, SystemException {
916 Country country = findByA2(a2);
917
918 remove(country);
919 }
920
921 public void removeByA3(String a3)
922 throws NoSuchCountryException, SystemException {
923 Country country = findByA3(a3);
924
925 remove(country);
926 }
927
928 public void removeByActive(boolean active) throws SystemException {
929 for (Country country : findByActive(active)) {
930 remove(country);
931 }
932 }
933
934 public void removeAll() throws SystemException {
935 for (Country country : findAll()) {
936 remove(country);
937 }
938 }
939
940 public int countByName(String name) throws SystemException {
941 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
942 String finderClassName = Country.class.getName();
943 String finderMethodName = "countByName";
944 String[] finderParams = new String[] { String.class.getName() };
945 Object[] finderArgs = new Object[] { name };
946
947 Object result = null;
948
949 if (finderClassNameCacheEnabled) {
950 result = FinderCacheUtil.getResult(finderClassName,
951 finderMethodName, finderParams, finderArgs, this);
952 }
953
954 if (result == null) {
955 Session session = null;
956
957 try {
958 session = openSession();
959
960 StringBuilder query = new StringBuilder();
961
962 query.append("SELECT COUNT(*) ");
963 query.append("FROM com.liferay.portal.model.Country WHERE ");
964
965 if (name == null) {
966 query.append("name IS NULL");
967 }
968 else {
969 query.append("name = ?");
970 }
971
972 query.append(" ");
973
974 Query q = session.createQuery(query.toString());
975
976 QueryPos qPos = QueryPos.getInstance(q);
977
978 if (name != null) {
979 qPos.add(name);
980 }
981
982 Long count = null;
983
984 Iterator<Long> itr = q.list().iterator();
985
986 if (itr.hasNext()) {
987 count = itr.next();
988 }
989
990 if (count == null) {
991 count = new Long(0);
992 }
993
994 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
995 finderClassName, finderMethodName, finderParams,
996 finderArgs, count);
997
998 return count.intValue();
999 }
1000 catch (Exception e) {
1001 throw processException(e);
1002 }
1003 finally {
1004 closeSession(session);
1005 }
1006 }
1007 else {
1008 return ((Long)result).intValue();
1009 }
1010 }
1011
1012 public int countByA2(String a2) throws SystemException {
1013 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
1014 String finderClassName = Country.class.getName();
1015 String finderMethodName = "countByA2";
1016 String[] finderParams = new String[] { String.class.getName() };
1017 Object[] finderArgs = new Object[] { a2 };
1018
1019 Object result = null;
1020
1021 if (finderClassNameCacheEnabled) {
1022 result = FinderCacheUtil.getResult(finderClassName,
1023 finderMethodName, finderParams, finderArgs, this);
1024 }
1025
1026 if (result == null) {
1027 Session session = null;
1028
1029 try {
1030 session = openSession();
1031
1032 StringBuilder query = new StringBuilder();
1033
1034 query.append("SELECT COUNT(*) ");
1035 query.append("FROM com.liferay.portal.model.Country WHERE ");
1036
1037 if (a2 == null) {
1038 query.append("a2 IS NULL");
1039 }
1040 else {
1041 query.append("a2 = ?");
1042 }
1043
1044 query.append(" ");
1045
1046 Query q = session.createQuery(query.toString());
1047
1048 QueryPos qPos = QueryPos.getInstance(q);
1049
1050 if (a2 != null) {
1051 qPos.add(a2);
1052 }
1053
1054 Long count = null;
1055
1056 Iterator<Long> itr = q.list().iterator();
1057
1058 if (itr.hasNext()) {
1059 count = itr.next();
1060 }
1061
1062 if (count == null) {
1063 count = new Long(0);
1064 }
1065
1066 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1067 finderClassName, finderMethodName, finderParams,
1068 finderArgs, count);
1069
1070 return count.intValue();
1071 }
1072 catch (Exception e) {
1073 throw processException(e);
1074 }
1075 finally {
1076 closeSession(session);
1077 }
1078 }
1079 else {
1080 return ((Long)result).intValue();
1081 }
1082 }
1083
1084 public int countByA3(String a3) throws SystemException {
1085 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
1086 String finderClassName = Country.class.getName();
1087 String finderMethodName = "countByA3";
1088 String[] finderParams = new String[] { String.class.getName() };
1089 Object[] finderArgs = new Object[] { a3 };
1090
1091 Object result = null;
1092
1093 if (finderClassNameCacheEnabled) {
1094 result = FinderCacheUtil.getResult(finderClassName,
1095 finderMethodName, finderParams, finderArgs, this);
1096 }
1097
1098 if (result == null) {
1099 Session session = null;
1100
1101 try {
1102 session = openSession();
1103
1104 StringBuilder query = new StringBuilder();
1105
1106 query.append("SELECT COUNT(*) ");
1107 query.append("FROM com.liferay.portal.model.Country WHERE ");
1108
1109 if (a3 == null) {
1110 query.append("a3 IS NULL");
1111 }
1112 else {
1113 query.append("a3 = ?");
1114 }
1115
1116 query.append(" ");
1117
1118 Query q = session.createQuery(query.toString());
1119
1120 QueryPos qPos = QueryPos.getInstance(q);
1121
1122 if (a3 != null) {
1123 qPos.add(a3);
1124 }
1125
1126 Long count = null;
1127
1128 Iterator<Long> itr = q.list().iterator();
1129
1130 if (itr.hasNext()) {
1131 count = itr.next();
1132 }
1133
1134 if (count == null) {
1135 count = new Long(0);
1136 }
1137
1138 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1139 finderClassName, finderMethodName, finderParams,
1140 finderArgs, count);
1141
1142 return count.intValue();
1143 }
1144 catch (Exception e) {
1145 throw processException(e);
1146 }
1147 finally {
1148 closeSession(session);
1149 }
1150 }
1151 else {
1152 return ((Long)result).intValue();
1153 }
1154 }
1155
1156 public int countByActive(boolean active) throws SystemException {
1157 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
1158 String finderClassName = Country.class.getName();
1159 String finderMethodName = "countByActive";
1160 String[] finderParams = new String[] { Boolean.class.getName() };
1161 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1162
1163 Object result = null;
1164
1165 if (finderClassNameCacheEnabled) {
1166 result = FinderCacheUtil.getResult(finderClassName,
1167 finderMethodName, finderParams, finderArgs, this);
1168 }
1169
1170 if (result == null) {
1171 Session session = null;
1172
1173 try {
1174 session = openSession();
1175
1176 StringBuilder query = new StringBuilder();
1177
1178 query.append("SELECT COUNT(*) ");
1179 query.append("FROM com.liferay.portal.model.Country WHERE ");
1180
1181 query.append("active_ = ?");
1182
1183 query.append(" ");
1184
1185 Query q = session.createQuery(query.toString());
1186
1187 QueryPos qPos = QueryPos.getInstance(q);
1188
1189 qPos.add(active);
1190
1191 Long count = null;
1192
1193 Iterator<Long> itr = q.list().iterator();
1194
1195 if (itr.hasNext()) {
1196 count = itr.next();
1197 }
1198
1199 if (count == null) {
1200 count = new Long(0);
1201 }
1202
1203 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1204 finderClassName, finderMethodName, finderParams,
1205 finderArgs, count);
1206
1207 return count.intValue();
1208 }
1209 catch (Exception e) {
1210 throw processException(e);
1211 }
1212 finally {
1213 closeSession(session);
1214 }
1215 }
1216 else {
1217 return ((Long)result).intValue();
1218 }
1219 }
1220
1221 public int countAll() throws SystemException {
1222 boolean finderClassNameCacheEnabled = CountryModelImpl.CACHE_ENABLED;
1223 String finderClassName = Country.class.getName();
1224 String finderMethodName = "countAll";
1225 String[] finderParams = new String[] { };
1226 Object[] finderArgs = new Object[] { };
1227
1228 Object result = null;
1229
1230 if (finderClassNameCacheEnabled) {
1231 result = FinderCacheUtil.getResult(finderClassName,
1232 finderMethodName, finderParams, finderArgs, this);
1233 }
1234
1235 if (result == null) {
1236 Session session = null;
1237
1238 try {
1239 session = openSession();
1240
1241 Query q = session.createQuery(
1242 "SELECT COUNT(*) FROM com.liferay.portal.model.Country");
1243
1244 Long count = null;
1245
1246 Iterator<Long> itr = q.list().iterator();
1247
1248 if (itr.hasNext()) {
1249 count = itr.next();
1250 }
1251
1252 if (count == null) {
1253 count = new Long(0);
1254 }
1255
1256 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1257 finderClassName, finderMethodName, finderParams,
1258 finderArgs, count);
1259
1260 return count.intValue();
1261 }
1262 catch (Exception e) {
1263 throw processException(e);
1264 }
1265 finally {
1266 closeSession(session);
1267 }
1268 }
1269 else {
1270 return ((Long)result).intValue();
1271 }
1272 }
1273
1274 public void afterPropertiesSet() {
1275 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1276 com.liferay.portal.util.PropsUtil.get(
1277 "value.object.listener.com.liferay.portal.model.Country")));
1278
1279 if (listenerClassNames.length > 0) {
1280 try {
1281 List<ModelListener> listenersList = new ArrayList<ModelListener>();
1282
1283 for (String listenerClassName : listenerClassNames) {
1284 listenersList.add((ModelListener)Class.forName(
1285 listenerClassName).newInstance());
1286 }
1287
1288 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1289 }
1290 catch (Exception e) {
1291 _log.error(e);
1292 }
1293 }
1294 }
1295
1296 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1297}