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