001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchCountryException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.Country;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.impl.CountryImpl;
041 import com.liferay.portal.model.impl.CountryModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class CountryPersistenceImpl extends BasePersistenceImpl<Country>
063 implements CountryPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = CountryImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
075 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
078 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
081 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
084 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
085 FINDER_CLASS_NAME_ENTITY, "fetchByName",
086 new String[] { String.class.getName() },
087 CountryModelImpl.NAME_COLUMN_BITMASK);
088 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
089 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
091 new String[] { String.class.getName() });
092
093
101 public Country findByName(String name)
102 throws NoSuchCountryException, SystemException {
103 Country country = fetchByName(name);
104
105 if (country == null) {
106 StringBundler msg = new StringBundler(4);
107
108 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
109
110 msg.append("name=");
111 msg.append(name);
112
113 msg.append(StringPool.CLOSE_CURLY_BRACE);
114
115 if (_log.isWarnEnabled()) {
116 _log.warn(msg.toString());
117 }
118
119 throw new NoSuchCountryException(msg.toString());
120 }
121
122 return country;
123 }
124
125
132 public Country fetchByName(String name) throws SystemException {
133 return fetchByName(name, true);
134 }
135
136
144 public Country fetchByName(String name, boolean retrieveFromCache)
145 throws SystemException {
146 Object[] finderArgs = new Object[] { name };
147
148 Object result = null;
149
150 if (retrieveFromCache) {
151 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
152 finderArgs, this);
153 }
154
155 if (result instanceof Country) {
156 Country country = (Country)result;
157
158 if (!Validator.equals(name, country.getName())) {
159 result = null;
160 }
161 }
162
163 if (result == null) {
164 StringBundler query = new StringBundler(3);
165
166 query.append(_SQL_SELECT_COUNTRY_WHERE);
167
168 boolean bindName = false;
169
170 if (name == null) {
171 query.append(_FINDER_COLUMN_NAME_NAME_1);
172 }
173 else if (name.equals(StringPool.BLANK)) {
174 query.append(_FINDER_COLUMN_NAME_NAME_3);
175 }
176 else {
177 bindName = true;
178
179 query.append(_FINDER_COLUMN_NAME_NAME_2);
180 }
181
182 String sql = query.toString();
183
184 Session session = null;
185
186 try {
187 session = openSession();
188
189 Query q = session.createQuery(sql);
190
191 QueryPos qPos = QueryPos.getInstance(q);
192
193 if (bindName) {
194 qPos.add(name);
195 }
196
197 List<Country> list = q.list();
198
199 if (list.isEmpty()) {
200 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
201 finderArgs, list);
202 }
203 else {
204 Country country = list.get(0);
205
206 result = country;
207
208 cacheResult(country);
209
210 if ((country.getName() == null) ||
211 !country.getName().equals(name)) {
212 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
213 finderArgs, country);
214 }
215 }
216 }
217 catch (Exception e) {
218 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
219 finderArgs);
220
221 throw processException(e);
222 }
223 finally {
224 closeSession(session);
225 }
226 }
227
228 if (result instanceof List<?>) {
229 return null;
230 }
231 else {
232 return (Country)result;
233 }
234 }
235
236
243 public Country removeByName(String name)
244 throws NoSuchCountryException, SystemException {
245 Country country = findByName(name);
246
247 return remove(country);
248 }
249
250
257 public int countByName(String name) throws SystemException {
258 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
259
260 Object[] finderArgs = new Object[] { name };
261
262 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
263 this);
264
265 if (count == null) {
266 StringBundler query = new StringBundler(2);
267
268 query.append(_SQL_COUNT_COUNTRY_WHERE);
269
270 boolean bindName = false;
271
272 if (name == null) {
273 query.append(_FINDER_COLUMN_NAME_NAME_1);
274 }
275 else if (name.equals(StringPool.BLANK)) {
276 query.append(_FINDER_COLUMN_NAME_NAME_3);
277 }
278 else {
279 bindName = true;
280
281 query.append(_FINDER_COLUMN_NAME_NAME_2);
282 }
283
284 String sql = query.toString();
285
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 Query q = session.createQuery(sql);
292
293 QueryPos qPos = QueryPos.getInstance(q);
294
295 if (bindName) {
296 qPos.add(name);
297 }
298
299 count = (Long)q.uniqueResult();
300
301 FinderCacheUtil.putResult(finderPath, finderArgs, count);
302 }
303 catch (Exception e) {
304 FinderCacheUtil.removeResult(finderPath, finderArgs);
305
306 throw processException(e);
307 }
308 finally {
309 closeSession(session);
310 }
311 }
312
313 return count.intValue();
314 }
315
316 private static final String _FINDER_COLUMN_NAME_NAME_1 = "country.name IS NULL";
317 private static final String _FINDER_COLUMN_NAME_NAME_2 = "country.name = ?";
318 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(country.name IS NULL OR country.name = '')";
319 public static final FinderPath FINDER_PATH_FETCH_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
320 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
321 FINDER_CLASS_NAME_ENTITY, "fetchByA2",
322 new String[] { String.class.getName() },
323 CountryModelImpl.A2_COLUMN_BITMASK);
324 public static final FinderPath FINDER_PATH_COUNT_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
325 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
326 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA2",
327 new String[] { String.class.getName() });
328
329
337 public Country findByA2(String a2)
338 throws NoSuchCountryException, SystemException {
339 Country country = fetchByA2(a2);
340
341 if (country == null) {
342 StringBundler msg = new StringBundler(4);
343
344 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
345
346 msg.append("a2=");
347 msg.append(a2);
348
349 msg.append(StringPool.CLOSE_CURLY_BRACE);
350
351 if (_log.isWarnEnabled()) {
352 _log.warn(msg.toString());
353 }
354
355 throw new NoSuchCountryException(msg.toString());
356 }
357
358 return country;
359 }
360
361
368 public Country fetchByA2(String a2) throws SystemException {
369 return fetchByA2(a2, true);
370 }
371
372
380 public Country fetchByA2(String a2, boolean retrieveFromCache)
381 throws SystemException {
382 Object[] finderArgs = new Object[] { a2 };
383
384 Object result = null;
385
386 if (retrieveFromCache) {
387 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A2,
388 finderArgs, this);
389 }
390
391 if (result instanceof Country) {
392 Country country = (Country)result;
393
394 if (!Validator.equals(a2, country.getA2())) {
395 result = null;
396 }
397 }
398
399 if (result == null) {
400 StringBundler query = new StringBundler(3);
401
402 query.append(_SQL_SELECT_COUNTRY_WHERE);
403
404 boolean bindA2 = false;
405
406 if (a2 == null) {
407 query.append(_FINDER_COLUMN_A2_A2_1);
408 }
409 else if (a2.equals(StringPool.BLANK)) {
410 query.append(_FINDER_COLUMN_A2_A2_3);
411 }
412 else {
413 bindA2 = true;
414
415 query.append(_FINDER_COLUMN_A2_A2_2);
416 }
417
418 String sql = query.toString();
419
420 Session session = null;
421
422 try {
423 session = openSession();
424
425 Query q = session.createQuery(sql);
426
427 QueryPos qPos = QueryPos.getInstance(q);
428
429 if (bindA2) {
430 qPos.add(a2);
431 }
432
433 List<Country> list = q.list();
434
435 if (list.isEmpty()) {
436 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
437 finderArgs, list);
438 }
439 else {
440 Country country = list.get(0);
441
442 result = country;
443
444 cacheResult(country);
445
446 if ((country.getA2() == null) ||
447 !country.getA2().equals(a2)) {
448 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
449 finderArgs, country);
450 }
451 }
452 }
453 catch (Exception e) {
454 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, finderArgs);
455
456 throw processException(e);
457 }
458 finally {
459 closeSession(session);
460 }
461 }
462
463 if (result instanceof List<?>) {
464 return null;
465 }
466 else {
467 return (Country)result;
468 }
469 }
470
471
478 public Country removeByA2(String a2)
479 throws NoSuchCountryException, SystemException {
480 Country country = findByA2(a2);
481
482 return remove(country);
483 }
484
485
492 public int countByA2(String a2) throws SystemException {
493 FinderPath finderPath = FINDER_PATH_COUNT_BY_A2;
494
495 Object[] finderArgs = new Object[] { a2 };
496
497 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
498 this);
499
500 if (count == null) {
501 StringBundler query = new StringBundler(2);
502
503 query.append(_SQL_COUNT_COUNTRY_WHERE);
504
505 boolean bindA2 = false;
506
507 if (a2 == null) {
508 query.append(_FINDER_COLUMN_A2_A2_1);
509 }
510 else if (a2.equals(StringPool.BLANK)) {
511 query.append(_FINDER_COLUMN_A2_A2_3);
512 }
513 else {
514 bindA2 = true;
515
516 query.append(_FINDER_COLUMN_A2_A2_2);
517 }
518
519 String sql = query.toString();
520
521 Session session = null;
522
523 try {
524 session = openSession();
525
526 Query q = session.createQuery(sql);
527
528 QueryPos qPos = QueryPos.getInstance(q);
529
530 if (bindA2) {
531 qPos.add(a2);
532 }
533
534 count = (Long)q.uniqueResult();
535
536 FinderCacheUtil.putResult(finderPath, finderArgs, count);
537 }
538 catch (Exception e) {
539 FinderCacheUtil.removeResult(finderPath, finderArgs);
540
541 throw processException(e);
542 }
543 finally {
544 closeSession(session);
545 }
546 }
547
548 return count.intValue();
549 }
550
551 private static final String _FINDER_COLUMN_A2_A2_1 = "country.a2 IS NULL";
552 private static final String _FINDER_COLUMN_A2_A2_2 = "country.a2 = ?";
553 private static final String _FINDER_COLUMN_A2_A2_3 = "(country.a2 IS NULL OR country.a2 = '')";
554 public static final FinderPath FINDER_PATH_FETCH_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
555 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
556 FINDER_CLASS_NAME_ENTITY, "fetchByA3",
557 new String[] { String.class.getName() },
558 CountryModelImpl.A3_COLUMN_BITMASK);
559 public static final FinderPath FINDER_PATH_COUNT_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
560 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
561 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA3",
562 new String[] { String.class.getName() });
563
564
572 public Country findByA3(String a3)
573 throws NoSuchCountryException, SystemException {
574 Country country = fetchByA3(a3);
575
576 if (country == null) {
577 StringBundler msg = new StringBundler(4);
578
579 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
580
581 msg.append("a3=");
582 msg.append(a3);
583
584 msg.append(StringPool.CLOSE_CURLY_BRACE);
585
586 if (_log.isWarnEnabled()) {
587 _log.warn(msg.toString());
588 }
589
590 throw new NoSuchCountryException(msg.toString());
591 }
592
593 return country;
594 }
595
596
603 public Country fetchByA3(String a3) throws SystemException {
604 return fetchByA3(a3, true);
605 }
606
607
615 public Country fetchByA3(String a3, boolean retrieveFromCache)
616 throws SystemException {
617 Object[] finderArgs = new Object[] { a3 };
618
619 Object result = null;
620
621 if (retrieveFromCache) {
622 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
623 finderArgs, this);
624 }
625
626 if (result instanceof Country) {
627 Country country = (Country)result;
628
629 if (!Validator.equals(a3, country.getA3())) {
630 result = null;
631 }
632 }
633
634 if (result == null) {
635 StringBundler query = new StringBundler(3);
636
637 query.append(_SQL_SELECT_COUNTRY_WHERE);
638
639 boolean bindA3 = false;
640
641 if (a3 == null) {
642 query.append(_FINDER_COLUMN_A3_A3_1);
643 }
644 else if (a3.equals(StringPool.BLANK)) {
645 query.append(_FINDER_COLUMN_A3_A3_3);
646 }
647 else {
648 bindA3 = true;
649
650 query.append(_FINDER_COLUMN_A3_A3_2);
651 }
652
653 String sql = query.toString();
654
655 Session session = null;
656
657 try {
658 session = openSession();
659
660 Query q = session.createQuery(sql);
661
662 QueryPos qPos = QueryPos.getInstance(q);
663
664 if (bindA3) {
665 qPos.add(a3);
666 }
667
668 List<Country> list = q.list();
669
670 if (list.isEmpty()) {
671 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
672 finderArgs, list);
673 }
674 else {
675 Country country = list.get(0);
676
677 result = country;
678
679 cacheResult(country);
680
681 if ((country.getA3() == null) ||
682 !country.getA3().equals(a3)) {
683 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
684 finderArgs, country);
685 }
686 }
687 }
688 catch (Exception e) {
689 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, finderArgs);
690
691 throw processException(e);
692 }
693 finally {
694 closeSession(session);
695 }
696 }
697
698 if (result instanceof List<?>) {
699 return null;
700 }
701 else {
702 return (Country)result;
703 }
704 }
705
706
713 public Country removeByA3(String a3)
714 throws NoSuchCountryException, SystemException {
715 Country country = findByA3(a3);
716
717 return remove(country);
718 }
719
720
727 public int countByA3(String a3) throws SystemException {
728 FinderPath finderPath = FINDER_PATH_COUNT_BY_A3;
729
730 Object[] finderArgs = new Object[] { a3 };
731
732 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
733 this);
734
735 if (count == null) {
736 StringBundler query = new StringBundler(2);
737
738 query.append(_SQL_COUNT_COUNTRY_WHERE);
739
740 boolean bindA3 = false;
741
742 if (a3 == null) {
743 query.append(_FINDER_COLUMN_A3_A3_1);
744 }
745 else if (a3.equals(StringPool.BLANK)) {
746 query.append(_FINDER_COLUMN_A3_A3_3);
747 }
748 else {
749 bindA3 = true;
750
751 query.append(_FINDER_COLUMN_A3_A3_2);
752 }
753
754 String sql = query.toString();
755
756 Session session = null;
757
758 try {
759 session = openSession();
760
761 Query q = session.createQuery(sql);
762
763 QueryPos qPos = QueryPos.getInstance(q);
764
765 if (bindA3) {
766 qPos.add(a3);
767 }
768
769 count = (Long)q.uniqueResult();
770
771 FinderCacheUtil.putResult(finderPath, finderArgs, count);
772 }
773 catch (Exception e) {
774 FinderCacheUtil.removeResult(finderPath, finderArgs);
775
776 throw processException(e);
777 }
778 finally {
779 closeSession(session);
780 }
781 }
782
783 return count.intValue();
784 }
785
786 private static final String _FINDER_COLUMN_A3_A3_1 = "country.a3 IS NULL";
787 private static final String _FINDER_COLUMN_A3_A3_2 = "country.a3 = ?";
788 private static final String _FINDER_COLUMN_A3_A3_3 = "(country.a3 IS NULL OR country.a3 = '')";
789 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
790 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
791 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
792 new String[] {
793 Boolean.class.getName(),
794
795 Integer.class.getName(), Integer.class.getName(),
796 OrderByComparator.class.getName()
797 });
798 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
799 new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
800 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
801 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
802 new String[] { Boolean.class.getName() },
803 CountryModelImpl.ACTIVE_COLUMN_BITMASK |
804 CountryModelImpl.NAME_COLUMN_BITMASK);
805 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
806 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
807 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
808 new String[] { Boolean.class.getName() });
809
810
817 public List<Country> findByActive(boolean active) throws SystemException {
818 return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
819 }
820
821
834 public List<Country> findByActive(boolean active, int start, int end)
835 throws SystemException {
836 return findByActive(active, start, end, null);
837 }
838
839
853 public List<Country> findByActive(boolean active, int start, int end,
854 OrderByComparator orderByComparator) throws SystemException {
855 boolean pagination = true;
856 FinderPath finderPath = null;
857 Object[] finderArgs = null;
858
859 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
860 (orderByComparator == null)) {
861 pagination = false;
862 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
863 finderArgs = new Object[] { active };
864 }
865 else {
866 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
867 finderArgs = new Object[] { active, start, end, orderByComparator };
868 }
869
870 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
871 finderArgs, this);
872
873 if ((list != null) && !list.isEmpty()) {
874 for (Country country : list) {
875 if ((active != country.getActive())) {
876 list = null;
877
878 break;
879 }
880 }
881 }
882
883 if (list == null) {
884 StringBundler query = null;
885
886 if (orderByComparator != null) {
887 query = new StringBundler(3 +
888 (orderByComparator.getOrderByFields().length * 3));
889 }
890 else {
891 query = new StringBundler(3);
892 }
893
894 query.append(_SQL_SELECT_COUNTRY_WHERE);
895
896 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
897
898 if (orderByComparator != null) {
899 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
900 orderByComparator);
901 }
902 else
903 if (pagination) {
904 query.append(CountryModelImpl.ORDER_BY_JPQL);
905 }
906
907 String sql = query.toString();
908
909 Session session = null;
910
911 try {
912 session = openSession();
913
914 Query q = session.createQuery(sql);
915
916 QueryPos qPos = QueryPos.getInstance(q);
917
918 qPos.add(active);
919
920 if (!pagination) {
921 list = (List<Country>)QueryUtil.list(q, getDialect(),
922 start, end, false);
923
924 Collections.sort(list);
925
926 list = new UnmodifiableList<Country>(list);
927 }
928 else {
929 list = (List<Country>)QueryUtil.list(q, getDialect(),
930 start, end);
931 }
932
933 cacheResult(list);
934
935 FinderCacheUtil.putResult(finderPath, finderArgs, list);
936 }
937 catch (Exception e) {
938 FinderCacheUtil.removeResult(finderPath, finderArgs);
939
940 throw processException(e);
941 }
942 finally {
943 closeSession(session);
944 }
945 }
946
947 return list;
948 }
949
950
959 public Country findByActive_First(boolean active,
960 OrderByComparator orderByComparator)
961 throws NoSuchCountryException, SystemException {
962 Country country = fetchByActive_First(active, orderByComparator);
963
964 if (country != null) {
965 return country;
966 }
967
968 StringBundler msg = new StringBundler(4);
969
970 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
971
972 msg.append("active=");
973 msg.append(active);
974
975 msg.append(StringPool.CLOSE_CURLY_BRACE);
976
977 throw new NoSuchCountryException(msg.toString());
978 }
979
980
988 public Country fetchByActive_First(boolean active,
989 OrderByComparator orderByComparator) throws SystemException {
990 List<Country> list = findByActive(active, 0, 1, orderByComparator);
991
992 if (!list.isEmpty()) {
993 return list.get(0);
994 }
995
996 return null;
997 }
998
999
1008 public Country findByActive_Last(boolean active,
1009 OrderByComparator orderByComparator)
1010 throws NoSuchCountryException, SystemException {
1011 Country country = fetchByActive_Last(active, orderByComparator);
1012
1013 if (country != null) {
1014 return country;
1015 }
1016
1017 StringBundler msg = new StringBundler(4);
1018
1019 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1020
1021 msg.append("active=");
1022 msg.append(active);
1023
1024 msg.append(StringPool.CLOSE_CURLY_BRACE);
1025
1026 throw new NoSuchCountryException(msg.toString());
1027 }
1028
1029
1037 public Country fetchByActive_Last(boolean active,
1038 OrderByComparator orderByComparator) throws SystemException {
1039 int count = countByActive(active);
1040
1041 List<Country> list = findByActive(active, count - 1, count,
1042 orderByComparator);
1043
1044 if (!list.isEmpty()) {
1045 return list.get(0);
1046 }
1047
1048 return null;
1049 }
1050
1051
1061 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
1062 OrderByComparator orderByComparator)
1063 throws NoSuchCountryException, SystemException {
1064 Country country = findByPrimaryKey(countryId);
1065
1066 Session session = null;
1067
1068 try {
1069 session = openSession();
1070
1071 Country[] array = new CountryImpl[3];
1072
1073 array[0] = getByActive_PrevAndNext(session, country, active,
1074 orderByComparator, true);
1075
1076 array[1] = country;
1077
1078 array[2] = getByActive_PrevAndNext(session, country, active,
1079 orderByComparator, false);
1080
1081 return array;
1082 }
1083 catch (Exception e) {
1084 throw processException(e);
1085 }
1086 finally {
1087 closeSession(session);
1088 }
1089 }
1090
1091 protected Country getByActive_PrevAndNext(Session session, Country country,
1092 boolean active, OrderByComparator orderByComparator, boolean previous) {
1093 StringBundler query = null;
1094
1095 if (orderByComparator != null) {
1096 query = new StringBundler(6 +
1097 (orderByComparator.getOrderByFields().length * 6));
1098 }
1099 else {
1100 query = new StringBundler(3);
1101 }
1102
1103 query.append(_SQL_SELECT_COUNTRY_WHERE);
1104
1105 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1106
1107 if (orderByComparator != null) {
1108 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1109
1110 if (orderByConditionFields.length > 0) {
1111 query.append(WHERE_AND);
1112 }
1113
1114 for (int i = 0; i < orderByConditionFields.length; i++) {
1115 query.append(_ORDER_BY_ENTITY_ALIAS);
1116 query.append(orderByConditionFields[i]);
1117
1118 if ((i + 1) < orderByConditionFields.length) {
1119 if (orderByComparator.isAscending() ^ previous) {
1120 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1121 }
1122 else {
1123 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1124 }
1125 }
1126 else {
1127 if (orderByComparator.isAscending() ^ previous) {
1128 query.append(WHERE_GREATER_THAN);
1129 }
1130 else {
1131 query.append(WHERE_LESSER_THAN);
1132 }
1133 }
1134 }
1135
1136 query.append(ORDER_BY_CLAUSE);
1137
1138 String[] orderByFields = orderByComparator.getOrderByFields();
1139
1140 for (int i = 0; i < orderByFields.length; i++) {
1141 query.append(_ORDER_BY_ENTITY_ALIAS);
1142 query.append(orderByFields[i]);
1143
1144 if ((i + 1) < orderByFields.length) {
1145 if (orderByComparator.isAscending() ^ previous) {
1146 query.append(ORDER_BY_ASC_HAS_NEXT);
1147 }
1148 else {
1149 query.append(ORDER_BY_DESC_HAS_NEXT);
1150 }
1151 }
1152 else {
1153 if (orderByComparator.isAscending() ^ previous) {
1154 query.append(ORDER_BY_ASC);
1155 }
1156 else {
1157 query.append(ORDER_BY_DESC);
1158 }
1159 }
1160 }
1161 }
1162 else {
1163 query.append(CountryModelImpl.ORDER_BY_JPQL);
1164 }
1165
1166 String sql = query.toString();
1167
1168 Query q = session.createQuery(sql);
1169
1170 q.setFirstResult(0);
1171 q.setMaxResults(2);
1172
1173 QueryPos qPos = QueryPos.getInstance(q);
1174
1175 qPos.add(active);
1176
1177 if (orderByComparator != null) {
1178 Object[] values = orderByComparator.getOrderByConditionValues(country);
1179
1180 for (Object value : values) {
1181 qPos.add(value);
1182 }
1183 }
1184
1185 List<Country> list = q.list();
1186
1187 if (list.size() == 2) {
1188 return list.get(1);
1189 }
1190 else {
1191 return null;
1192 }
1193 }
1194
1195
1201 public void removeByActive(boolean active) throws SystemException {
1202 for (Country country : findByActive(active, QueryUtil.ALL_POS,
1203 QueryUtil.ALL_POS, null)) {
1204 remove(country);
1205 }
1206 }
1207
1208
1215 public int countByActive(boolean active) throws SystemException {
1216 FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1217
1218 Object[] finderArgs = new Object[] { active };
1219
1220 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1221 this);
1222
1223 if (count == null) {
1224 StringBundler query = new StringBundler(2);
1225
1226 query.append(_SQL_COUNT_COUNTRY_WHERE);
1227
1228 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1229
1230 String sql = query.toString();
1231
1232 Session session = null;
1233
1234 try {
1235 session = openSession();
1236
1237 Query q = session.createQuery(sql);
1238
1239 QueryPos qPos = QueryPos.getInstance(q);
1240
1241 qPos.add(active);
1242
1243 count = (Long)q.uniqueResult();
1244
1245 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1246 }
1247 catch (Exception e) {
1248 FinderCacheUtil.removeResult(finderPath, finderArgs);
1249
1250 throw processException(e);
1251 }
1252 finally {
1253 closeSession(session);
1254 }
1255 }
1256
1257 return count.intValue();
1258 }
1259
1260 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "country.active = ?";
1261
1262
1267 public void cacheResult(Country country) {
1268 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1269 CountryImpl.class, country.getPrimaryKey(), country);
1270
1271 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
1272 new Object[] { country.getName() }, country);
1273
1274 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
1275 new Object[] { country.getA2() }, country);
1276
1277 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
1278 new Object[] { country.getA3() }, country);
1279
1280 country.resetOriginalValues();
1281 }
1282
1283
1288 public void cacheResult(List<Country> countries) {
1289 for (Country country : countries) {
1290 if (EntityCacheUtil.getResult(
1291 CountryModelImpl.ENTITY_CACHE_ENABLED,
1292 CountryImpl.class, country.getPrimaryKey()) == null) {
1293 cacheResult(country);
1294 }
1295 else {
1296 country.resetOriginalValues();
1297 }
1298 }
1299 }
1300
1301
1308 @Override
1309 public void clearCache() {
1310 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1311 CacheRegistryUtil.clear(CountryImpl.class.getName());
1312 }
1313
1314 EntityCacheUtil.clearCache(CountryImpl.class.getName());
1315
1316 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1317 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1318 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1319 }
1320
1321
1328 @Override
1329 public void clearCache(Country country) {
1330 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1331 CountryImpl.class, country.getPrimaryKey());
1332
1333 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1335
1336 clearUniqueFindersCache(country);
1337 }
1338
1339 @Override
1340 public void clearCache(List<Country> countries) {
1341 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1342 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1343
1344 for (Country country : countries) {
1345 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1346 CountryImpl.class, country.getPrimaryKey());
1347
1348 clearUniqueFindersCache(country);
1349 }
1350 }
1351
1352 protected void cacheUniqueFindersCache(Country country) {
1353 if (country.isNew()) {
1354 Object[] args = new Object[] { country.getName() };
1355
1356 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1357 Long.valueOf(1));
1358 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args, country);
1359
1360 args = new Object[] { country.getA2() };
1361
1362 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1363 Long.valueOf(1));
1364 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1365
1366 args = new Object[] { country.getA3() };
1367
1368 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1369 Long.valueOf(1));
1370 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1371 }
1372 else {
1373 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1374
1375 if ((countryModelImpl.getColumnBitmask() &
1376 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1377 Object[] args = new Object[] { country.getName() };
1378
1379 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1380 Long.valueOf(1));
1381 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1382 country);
1383 }
1384
1385 if ((countryModelImpl.getColumnBitmask() &
1386 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1387 Object[] args = new Object[] { country.getA2() };
1388
1389 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1390 Long.valueOf(1));
1391 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1392 }
1393
1394 if ((countryModelImpl.getColumnBitmask() &
1395 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1396 Object[] args = new Object[] { country.getA3() };
1397
1398 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1399 Long.valueOf(1));
1400 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1401 }
1402 }
1403 }
1404
1405 protected void clearUniqueFindersCache(Country country) {
1406 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1407
1408 Object[] args = new Object[] { country.getName() };
1409
1410 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1411 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1412
1413 if ((countryModelImpl.getColumnBitmask() &
1414 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1415 args = new Object[] { countryModelImpl.getOriginalName() };
1416
1417 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1418 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1419 }
1420
1421 args = new Object[] { country.getA2() };
1422
1423 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1424 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1425
1426 if ((countryModelImpl.getColumnBitmask() &
1427 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1428 args = new Object[] { countryModelImpl.getOriginalA2() };
1429
1430 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1431 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1432 }
1433
1434 args = new Object[] { country.getA3() };
1435
1436 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1437 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1438
1439 if ((countryModelImpl.getColumnBitmask() &
1440 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1441 args = new Object[] { countryModelImpl.getOriginalA3() };
1442
1443 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1444 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1445 }
1446 }
1447
1448
1454 public Country create(long countryId) {
1455 Country country = new CountryImpl();
1456
1457 country.setNew(true);
1458 country.setPrimaryKey(countryId);
1459
1460 return country;
1461 }
1462
1463
1471 public Country remove(long countryId)
1472 throws NoSuchCountryException, SystemException {
1473 return remove((Serializable)countryId);
1474 }
1475
1476
1484 @Override
1485 public Country remove(Serializable primaryKey)
1486 throws NoSuchCountryException, SystemException {
1487 Session session = null;
1488
1489 try {
1490 session = openSession();
1491
1492 Country country = (Country)session.get(CountryImpl.class, primaryKey);
1493
1494 if (country == null) {
1495 if (_log.isWarnEnabled()) {
1496 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1497 }
1498
1499 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1500 primaryKey);
1501 }
1502
1503 return remove(country);
1504 }
1505 catch (NoSuchCountryException nsee) {
1506 throw nsee;
1507 }
1508 catch (Exception e) {
1509 throw processException(e);
1510 }
1511 finally {
1512 closeSession(session);
1513 }
1514 }
1515
1516 @Override
1517 protected Country removeImpl(Country country) throws SystemException {
1518 country = toUnwrappedModel(country);
1519
1520 Session session = null;
1521
1522 try {
1523 session = openSession();
1524
1525 if (!session.contains(country)) {
1526 country = (Country)session.get(CountryImpl.class,
1527 country.getPrimaryKeyObj());
1528 }
1529
1530 if (country != null) {
1531 session.delete(country);
1532 }
1533 }
1534 catch (Exception e) {
1535 throw processException(e);
1536 }
1537 finally {
1538 closeSession(session);
1539 }
1540
1541 if (country != null) {
1542 clearCache(country);
1543 }
1544
1545 return country;
1546 }
1547
1548 @Override
1549 public Country updateImpl(com.liferay.portal.model.Country country)
1550 throws SystemException {
1551 country = toUnwrappedModel(country);
1552
1553 boolean isNew = country.isNew();
1554
1555 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1556
1557 Session session = null;
1558
1559 try {
1560 session = openSession();
1561
1562 if (country.isNew()) {
1563 session.save(country);
1564
1565 country.setNew(false);
1566 }
1567 else {
1568 session.merge(country);
1569 }
1570 }
1571 catch (Exception e) {
1572 throw processException(e);
1573 }
1574 finally {
1575 closeSession(session);
1576 }
1577
1578 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1579
1580 if (isNew || !CountryModelImpl.COLUMN_BITMASK_ENABLED) {
1581 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1582 }
1583
1584 else {
1585 if ((countryModelImpl.getColumnBitmask() &
1586 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
1587 Object[] args = new Object[] {
1588 countryModelImpl.getOriginalActive()
1589 };
1590
1591 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1592 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1593 args);
1594
1595 args = new Object[] { countryModelImpl.getActive() };
1596
1597 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1598 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1599 args);
1600 }
1601 }
1602
1603 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1604 CountryImpl.class, country.getPrimaryKey(), country);
1605
1606 clearUniqueFindersCache(country);
1607 cacheUniqueFindersCache(country);
1608
1609 return country;
1610 }
1611
1612 protected Country toUnwrappedModel(Country country) {
1613 if (country instanceof CountryImpl) {
1614 return country;
1615 }
1616
1617 CountryImpl countryImpl = new CountryImpl();
1618
1619 countryImpl.setNew(country.isNew());
1620 countryImpl.setPrimaryKey(country.getPrimaryKey());
1621
1622 countryImpl.setCountryId(country.getCountryId());
1623 countryImpl.setName(country.getName());
1624 countryImpl.setA2(country.getA2());
1625 countryImpl.setA3(country.getA3());
1626 countryImpl.setNumber(country.getNumber());
1627 countryImpl.setIdd(country.getIdd());
1628 countryImpl.setZipRequired(country.isZipRequired());
1629 countryImpl.setActive(country.isActive());
1630
1631 return countryImpl;
1632 }
1633
1634
1642 @Override
1643 public Country findByPrimaryKey(Serializable primaryKey)
1644 throws NoSuchCountryException, SystemException {
1645 Country country = fetchByPrimaryKey(primaryKey);
1646
1647 if (country == null) {
1648 if (_log.isWarnEnabled()) {
1649 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1650 }
1651
1652 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1653 primaryKey);
1654 }
1655
1656 return country;
1657 }
1658
1659
1667 public Country findByPrimaryKey(long countryId)
1668 throws NoSuchCountryException, SystemException {
1669 return findByPrimaryKey((Serializable)countryId);
1670 }
1671
1672
1679 @Override
1680 public Country fetchByPrimaryKey(Serializable primaryKey)
1681 throws SystemException {
1682 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1683 CountryImpl.class, primaryKey);
1684
1685 if (country == _nullCountry) {
1686 return null;
1687 }
1688
1689 if (country == null) {
1690 Session session = null;
1691
1692 try {
1693 session = openSession();
1694
1695 country = (Country)session.get(CountryImpl.class, primaryKey);
1696
1697 if (country != null) {
1698 cacheResult(country);
1699 }
1700 else {
1701 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1702 CountryImpl.class, primaryKey, _nullCountry);
1703 }
1704 }
1705 catch (Exception e) {
1706 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1707 CountryImpl.class, primaryKey);
1708
1709 throw processException(e);
1710 }
1711 finally {
1712 closeSession(session);
1713 }
1714 }
1715
1716 return country;
1717 }
1718
1719
1726 public Country fetchByPrimaryKey(long countryId) throws SystemException {
1727 return fetchByPrimaryKey((Serializable)countryId);
1728 }
1729
1730
1736 public List<Country> findAll() throws SystemException {
1737 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1738 }
1739
1740
1752 public List<Country> findAll(int start, int end) throws SystemException {
1753 return findAll(start, end, null);
1754 }
1755
1756
1769 public List<Country> findAll(int start, int end,
1770 OrderByComparator orderByComparator) throws SystemException {
1771 boolean pagination = true;
1772 FinderPath finderPath = null;
1773 Object[] finderArgs = null;
1774
1775 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1776 (orderByComparator == null)) {
1777 pagination = false;
1778 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1779 finderArgs = FINDER_ARGS_EMPTY;
1780 }
1781 else {
1782 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1783 finderArgs = new Object[] { start, end, orderByComparator };
1784 }
1785
1786 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
1787 finderArgs, this);
1788
1789 if (list == null) {
1790 StringBundler query = null;
1791 String sql = null;
1792
1793 if (orderByComparator != null) {
1794 query = new StringBundler(2 +
1795 (orderByComparator.getOrderByFields().length * 3));
1796
1797 query.append(_SQL_SELECT_COUNTRY);
1798
1799 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1800 orderByComparator);
1801
1802 sql = query.toString();
1803 }
1804 else {
1805 sql = _SQL_SELECT_COUNTRY;
1806
1807 if (pagination) {
1808 sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
1809 }
1810 }
1811
1812 Session session = null;
1813
1814 try {
1815 session = openSession();
1816
1817 Query q = session.createQuery(sql);
1818
1819 if (!pagination) {
1820 list = (List<Country>)QueryUtil.list(q, getDialect(),
1821 start, end, false);
1822
1823 Collections.sort(list);
1824
1825 list = new UnmodifiableList<Country>(list);
1826 }
1827 else {
1828 list = (List<Country>)QueryUtil.list(q, getDialect(),
1829 start, end);
1830 }
1831
1832 cacheResult(list);
1833
1834 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1835 }
1836 catch (Exception e) {
1837 FinderCacheUtil.removeResult(finderPath, finderArgs);
1838
1839 throw processException(e);
1840 }
1841 finally {
1842 closeSession(session);
1843 }
1844 }
1845
1846 return list;
1847 }
1848
1849
1854 public void removeAll() throws SystemException {
1855 for (Country country : findAll()) {
1856 remove(country);
1857 }
1858 }
1859
1860
1866 public int countAll() throws SystemException {
1867 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1868 FINDER_ARGS_EMPTY, this);
1869
1870 if (count == null) {
1871 Session session = null;
1872
1873 try {
1874 session = openSession();
1875
1876 Query q = session.createQuery(_SQL_COUNT_COUNTRY);
1877
1878 count = (Long)q.uniqueResult();
1879
1880 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1881 FINDER_ARGS_EMPTY, count);
1882 }
1883 catch (Exception e) {
1884 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1885 FINDER_ARGS_EMPTY);
1886
1887 throw processException(e);
1888 }
1889 finally {
1890 closeSession(session);
1891 }
1892 }
1893
1894 return count.intValue();
1895 }
1896
1897
1900 public void afterPropertiesSet() {
1901 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1902 com.liferay.portal.util.PropsUtil.get(
1903 "value.object.listener.com.liferay.portal.model.Country")));
1904
1905 if (listenerClassNames.length > 0) {
1906 try {
1907 List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1908
1909 for (String listenerClassName : listenerClassNames) {
1910 listenersList.add((ModelListener<Country>)InstanceFactory.newInstance(
1911 listenerClassName));
1912 }
1913
1914 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1915 }
1916 catch (Exception e) {
1917 _log.error(e);
1918 }
1919 }
1920 }
1921
1922 public void destroy() {
1923 EntityCacheUtil.removeCache(CountryImpl.class.getName());
1924 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1925 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1926 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1927 }
1928
1929 private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
1930 private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
1931 private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
1932 private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
1933 private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
1934 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
1935 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
1936 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1937 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1938 private static Country _nullCountry = new CountryImpl() {
1939 @Override
1940 public Object clone() {
1941 return this;
1942 }
1943
1944 @Override
1945 public CacheModel<Country> toCacheModel() {
1946 return _nullCountryCacheModel;
1947 }
1948 };
1949
1950 private static CacheModel<Country> _nullCountryCacheModel = new CacheModel<Country>() {
1951 public Country toEntityModel() {
1952 return _nullCountry;
1953 }
1954 };
1955 }