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