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