001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchCountryException;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.Country;
038 import com.liferay.portal.model.MVCCModel;
039 import com.liferay.portal.model.impl.CountryImpl;
040 import com.liferay.portal.model.impl.CountryModelImpl;
041 import com.liferay.portal.service.persistence.CountryPersistence;
042
043 import java.io.Serializable;
044
045 import java.util.Collections;
046 import java.util.HashMap;
047 import java.util.HashSet;
048 import java.util.Iterator;
049 import java.util.List;
050 import java.util.Map;
051 import java.util.Set;
052
053
065 @ProviderType
066 public class CountryPersistenceImpl extends BasePersistenceImpl<Country>
067 implements CountryPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = CountryImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
079 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
082 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
085 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
088 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
089 FINDER_CLASS_NAME_ENTITY, "fetchByName",
090 new String[] { String.class.getName() },
091 CountryModelImpl.NAME_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
093 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
095 new String[] { String.class.getName() });
096
097
104 @Override
105 public Country findByName(String name) throws NoSuchCountryException {
106 Country country = fetchByName(name);
107
108 if (country == null) {
109 StringBundler msg = new StringBundler(4);
110
111 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
112
113 msg.append("name=");
114 msg.append(name);
115
116 msg.append(StringPool.CLOSE_CURLY_BRACE);
117
118 if (_log.isWarnEnabled()) {
119 _log.warn(msg.toString());
120 }
121
122 throw new NoSuchCountryException(msg.toString());
123 }
124
125 return country;
126 }
127
128
134 @Override
135 public Country fetchByName(String name) {
136 return fetchByName(name, true);
137 }
138
139
146 @Override
147 public Country fetchByName(String name, boolean retrieveFromCache) {
148 Object[] finderArgs = new Object[] { name };
149
150 Object result = null;
151
152 if (retrieveFromCache) {
153 result = finderCache.getResult(FINDER_PATH_FETCH_BY_NAME,
154 finderArgs, this);
155 }
156
157 if (result instanceof Country) {
158 Country country = (Country)result;
159
160 if (!Validator.equals(name, country.getName())) {
161 result = null;
162 }
163 }
164
165 if (result == null) {
166 StringBundler query = new StringBundler(3);
167
168 query.append(_SQL_SELECT_COUNTRY_WHERE);
169
170 boolean bindName = false;
171
172 if (name == null) {
173 query.append(_FINDER_COLUMN_NAME_NAME_1);
174 }
175 else if (name.equals(StringPool.BLANK)) {
176 query.append(_FINDER_COLUMN_NAME_NAME_3);
177 }
178 else {
179 bindName = true;
180
181 query.append(_FINDER_COLUMN_NAME_NAME_2);
182 }
183
184 String sql = query.toString();
185
186 Session session = null;
187
188 try {
189 session = openSession();
190
191 Query q = session.createQuery(sql);
192
193 QueryPos qPos = QueryPos.getInstance(q);
194
195 if (bindName) {
196 qPos.add(name);
197 }
198
199 List<Country> list = q.list();
200
201 if (list.isEmpty()) {
202 finderCache.putResult(FINDER_PATH_FETCH_BY_NAME,
203 finderArgs, list);
204 }
205 else {
206 Country country = list.get(0);
207
208 result = country;
209
210 cacheResult(country);
211
212 if ((country.getName() == null) ||
213 !country.getName().equals(name)) {
214 finderCache.putResult(FINDER_PATH_FETCH_BY_NAME,
215 finderArgs, country);
216 }
217 }
218 }
219 catch (Exception e) {
220 finderCache.removeResult(FINDER_PATH_FETCH_BY_NAME, finderArgs);
221
222 throw processException(e);
223 }
224 finally {
225 closeSession(session);
226 }
227 }
228
229 if (result instanceof List<?>) {
230 return null;
231 }
232 else {
233 return (Country)result;
234 }
235 }
236
237
243 @Override
244 public Country removeByName(String name) throws NoSuchCountryException {
245 Country country = findByName(name);
246
247 return remove(country);
248 }
249
250
256 @Override
257 public int countByName(String name) {
258 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
259
260 Object[] finderArgs = new Object[] { name };
261
262 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
263
264 if (count == null) {
265 StringBundler query = new StringBundler(2);
266
267 query.append(_SQL_COUNT_COUNTRY_WHERE);
268
269 boolean bindName = false;
270
271 if (name == null) {
272 query.append(_FINDER_COLUMN_NAME_NAME_1);
273 }
274 else if (name.equals(StringPool.BLANK)) {
275 query.append(_FINDER_COLUMN_NAME_NAME_3);
276 }
277 else {
278 bindName = true;
279
280 query.append(_FINDER_COLUMN_NAME_NAME_2);
281 }
282
283 String sql = query.toString();
284
285 Session session = null;
286
287 try {
288 session = openSession();
289
290 Query q = session.createQuery(sql);
291
292 QueryPos qPos = QueryPos.getInstance(q);
293
294 if (bindName) {
295 qPos.add(name);
296 }
297
298 count = (Long)q.uniqueResult();
299
300 finderCache.putResult(finderPath, finderArgs, count);
301 }
302 catch (Exception e) {
303 finderCache.removeResult(finderPath, finderArgs);
304
305 throw processException(e);
306 }
307 finally {
308 closeSession(session);
309 }
310 }
311
312 return count.intValue();
313 }
314
315 private static final String _FINDER_COLUMN_NAME_NAME_1 = "country.name IS NULL";
316 private static final String _FINDER_COLUMN_NAME_NAME_2 = "country.name = ?";
317 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(country.name IS NULL OR country.name = '')";
318 public static final FinderPath FINDER_PATH_FETCH_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
319 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
320 FINDER_CLASS_NAME_ENTITY, "fetchByA2",
321 new String[] { String.class.getName() },
322 CountryModelImpl.A2_COLUMN_BITMASK);
323 public static final FinderPath FINDER_PATH_COUNT_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
324 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
325 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA2",
326 new String[] { String.class.getName() });
327
328
335 @Override
336 public Country findByA2(String a2) throws NoSuchCountryException {
337 Country country = fetchByA2(a2);
338
339 if (country == null) {
340 StringBundler msg = new StringBundler(4);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("a2=");
345 msg.append(a2);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 if (_log.isWarnEnabled()) {
350 _log.warn(msg.toString());
351 }
352
353 throw new NoSuchCountryException(msg.toString());
354 }
355
356 return country;
357 }
358
359
365 @Override
366 public Country fetchByA2(String a2) {
367 return fetchByA2(a2, true);
368 }
369
370
377 @Override
378 public Country fetchByA2(String a2, boolean retrieveFromCache) {
379 Object[] finderArgs = new Object[] { a2 };
380
381 Object result = null;
382
383 if (retrieveFromCache) {
384 result = finderCache.getResult(FINDER_PATH_FETCH_BY_A2, finderArgs,
385 this);
386 }
387
388 if (result instanceof Country) {
389 Country country = (Country)result;
390
391 if (!Validator.equals(a2, country.getA2())) {
392 result = null;
393 }
394 }
395
396 if (result == null) {
397 StringBundler query = new StringBundler(3);
398
399 query.append(_SQL_SELECT_COUNTRY_WHERE);
400
401 boolean bindA2 = false;
402
403 if (a2 == null) {
404 query.append(_FINDER_COLUMN_A2_A2_1);
405 }
406 else if (a2.equals(StringPool.BLANK)) {
407 query.append(_FINDER_COLUMN_A2_A2_3);
408 }
409 else {
410 bindA2 = true;
411
412 query.append(_FINDER_COLUMN_A2_A2_2);
413 }
414
415 String sql = query.toString();
416
417 Session session = null;
418
419 try {
420 session = openSession();
421
422 Query q = session.createQuery(sql);
423
424 QueryPos qPos = QueryPos.getInstance(q);
425
426 if (bindA2) {
427 qPos.add(a2);
428 }
429
430 List<Country> list = q.list();
431
432 if (list.isEmpty()) {
433 finderCache.putResult(FINDER_PATH_FETCH_BY_A2, finderArgs,
434 list);
435 }
436 else {
437 Country country = list.get(0);
438
439 result = country;
440
441 cacheResult(country);
442
443 if ((country.getA2() == null) ||
444 !country.getA2().equals(a2)) {
445 finderCache.putResult(FINDER_PATH_FETCH_BY_A2,
446 finderArgs, country);
447 }
448 }
449 }
450 catch (Exception e) {
451 finderCache.removeResult(FINDER_PATH_FETCH_BY_A2, finderArgs);
452
453 throw processException(e);
454 }
455 finally {
456 closeSession(session);
457 }
458 }
459
460 if (result instanceof List<?>) {
461 return null;
462 }
463 else {
464 return (Country)result;
465 }
466 }
467
468
474 @Override
475 public Country removeByA2(String a2) throws NoSuchCountryException {
476 Country country = findByA2(a2);
477
478 return remove(country);
479 }
480
481
487 @Override
488 public int countByA2(String a2) {
489 FinderPath finderPath = FINDER_PATH_COUNT_BY_A2;
490
491 Object[] finderArgs = new Object[] { a2 };
492
493 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
494
495 if (count == null) {
496 StringBundler query = new StringBundler(2);
497
498 query.append(_SQL_COUNT_COUNTRY_WHERE);
499
500 boolean bindA2 = false;
501
502 if (a2 == null) {
503 query.append(_FINDER_COLUMN_A2_A2_1);
504 }
505 else if (a2.equals(StringPool.BLANK)) {
506 query.append(_FINDER_COLUMN_A2_A2_3);
507 }
508 else {
509 bindA2 = true;
510
511 query.append(_FINDER_COLUMN_A2_A2_2);
512 }
513
514 String sql = query.toString();
515
516 Session session = null;
517
518 try {
519 session = openSession();
520
521 Query q = session.createQuery(sql);
522
523 QueryPos qPos = QueryPos.getInstance(q);
524
525 if (bindA2) {
526 qPos.add(a2);
527 }
528
529 count = (Long)q.uniqueResult();
530
531 finderCache.putResult(finderPath, finderArgs, count);
532 }
533 catch (Exception e) {
534 finderCache.removeResult(finderPath, finderArgs);
535
536 throw processException(e);
537 }
538 finally {
539 closeSession(session);
540 }
541 }
542
543 return count.intValue();
544 }
545
546 private static final String _FINDER_COLUMN_A2_A2_1 = "country.a2 IS NULL";
547 private static final String _FINDER_COLUMN_A2_A2_2 = "country.a2 = ?";
548 private static final String _FINDER_COLUMN_A2_A2_3 = "(country.a2 IS NULL OR country.a2 = '')";
549 public static final FinderPath FINDER_PATH_FETCH_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
550 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
551 FINDER_CLASS_NAME_ENTITY, "fetchByA3",
552 new String[] { String.class.getName() },
553 CountryModelImpl.A3_COLUMN_BITMASK);
554 public static final FinderPath FINDER_PATH_COUNT_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
555 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
556 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA3",
557 new String[] { String.class.getName() });
558
559
566 @Override
567 public Country findByA3(String a3) throws NoSuchCountryException {
568 Country country = fetchByA3(a3);
569
570 if (country == null) {
571 StringBundler msg = new StringBundler(4);
572
573 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
574
575 msg.append("a3=");
576 msg.append(a3);
577
578 msg.append(StringPool.CLOSE_CURLY_BRACE);
579
580 if (_log.isWarnEnabled()) {
581 _log.warn(msg.toString());
582 }
583
584 throw new NoSuchCountryException(msg.toString());
585 }
586
587 return country;
588 }
589
590
596 @Override
597 public Country fetchByA3(String a3) {
598 return fetchByA3(a3, true);
599 }
600
601
608 @Override
609 public Country fetchByA3(String a3, boolean retrieveFromCache) {
610 Object[] finderArgs = new Object[] { a3 };
611
612 Object result = null;
613
614 if (retrieveFromCache) {
615 result = finderCache.getResult(FINDER_PATH_FETCH_BY_A3, finderArgs,
616 this);
617 }
618
619 if (result instanceof Country) {
620 Country country = (Country)result;
621
622 if (!Validator.equals(a3, country.getA3())) {
623 result = null;
624 }
625 }
626
627 if (result == null) {
628 StringBundler query = new StringBundler(3);
629
630 query.append(_SQL_SELECT_COUNTRY_WHERE);
631
632 boolean bindA3 = false;
633
634 if (a3 == null) {
635 query.append(_FINDER_COLUMN_A3_A3_1);
636 }
637 else if (a3.equals(StringPool.BLANK)) {
638 query.append(_FINDER_COLUMN_A3_A3_3);
639 }
640 else {
641 bindA3 = true;
642
643 query.append(_FINDER_COLUMN_A3_A3_2);
644 }
645
646 String sql = query.toString();
647
648 Session session = null;
649
650 try {
651 session = openSession();
652
653 Query q = session.createQuery(sql);
654
655 QueryPos qPos = QueryPos.getInstance(q);
656
657 if (bindA3) {
658 qPos.add(a3);
659 }
660
661 List<Country> list = q.list();
662
663 if (list.isEmpty()) {
664 finderCache.putResult(FINDER_PATH_FETCH_BY_A3, finderArgs,
665 list);
666 }
667 else {
668 Country country = list.get(0);
669
670 result = country;
671
672 cacheResult(country);
673
674 if ((country.getA3() == null) ||
675 !country.getA3().equals(a3)) {
676 finderCache.putResult(FINDER_PATH_FETCH_BY_A3,
677 finderArgs, country);
678 }
679 }
680 }
681 catch (Exception e) {
682 finderCache.removeResult(FINDER_PATH_FETCH_BY_A3, finderArgs);
683
684 throw processException(e);
685 }
686 finally {
687 closeSession(session);
688 }
689 }
690
691 if (result instanceof List<?>) {
692 return null;
693 }
694 else {
695 return (Country)result;
696 }
697 }
698
699
705 @Override
706 public Country removeByA3(String a3) throws NoSuchCountryException {
707 Country country = findByA3(a3);
708
709 return remove(country);
710 }
711
712
718 @Override
719 public int countByA3(String a3) {
720 FinderPath finderPath = FINDER_PATH_COUNT_BY_A3;
721
722 Object[] finderArgs = new Object[] { a3 };
723
724 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
725
726 if (count == null) {
727 StringBundler query = new StringBundler(2);
728
729 query.append(_SQL_COUNT_COUNTRY_WHERE);
730
731 boolean bindA3 = false;
732
733 if (a3 == null) {
734 query.append(_FINDER_COLUMN_A3_A3_1);
735 }
736 else if (a3.equals(StringPool.BLANK)) {
737 query.append(_FINDER_COLUMN_A3_A3_3);
738 }
739 else {
740 bindA3 = true;
741
742 query.append(_FINDER_COLUMN_A3_A3_2);
743 }
744
745 String sql = query.toString();
746
747 Session session = null;
748
749 try {
750 session = openSession();
751
752 Query q = session.createQuery(sql);
753
754 QueryPos qPos = QueryPos.getInstance(q);
755
756 if (bindA3) {
757 qPos.add(a3);
758 }
759
760 count = (Long)q.uniqueResult();
761
762 finderCache.putResult(finderPath, finderArgs, count);
763 }
764 catch (Exception e) {
765 finderCache.removeResult(finderPath, finderArgs);
766
767 throw processException(e);
768 }
769 finally {
770 closeSession(session);
771 }
772 }
773
774 return count.intValue();
775 }
776
777 private static final String _FINDER_COLUMN_A3_A3_1 = "country.a3 IS NULL";
778 private static final String _FINDER_COLUMN_A3_A3_2 = "country.a3 = ?";
779 private static final String _FINDER_COLUMN_A3_A3_3 = "(country.a3 IS NULL OR country.a3 = '')";
780 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
781 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
782 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
783 new String[] {
784 Boolean.class.getName(),
785
786 Integer.class.getName(), Integer.class.getName(),
787 OrderByComparator.class.getName()
788 });
789 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
790 new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
791 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
792 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
793 new String[] { Boolean.class.getName() },
794 CountryModelImpl.ACTIVE_COLUMN_BITMASK |
795 CountryModelImpl.NAME_COLUMN_BITMASK);
796 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
797 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
798 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
799 new String[] { Boolean.class.getName() });
800
801
807 @Override
808 public List<Country> findByActive(boolean active) {
809 return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
810 }
811
812
824 @Override
825 public List<Country> findByActive(boolean active, int start, int end) {
826 return findByActive(active, start, end, null);
827 }
828
829
842 @Override
843 public List<Country> findByActive(boolean active, int start, int end,
844 OrderByComparator<Country> orderByComparator) {
845 return findByActive(active, start, end, orderByComparator, true);
846 }
847
848
862 @Override
863 public List<Country> findByActive(boolean active, int start, int end,
864 OrderByComparator<Country> orderByComparator, boolean retrieveFromCache) {
865 boolean pagination = true;
866 FinderPath finderPath = null;
867 Object[] finderArgs = null;
868
869 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
870 (orderByComparator == null)) {
871 pagination = false;
872 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
873 finderArgs = new Object[] { active };
874 }
875 else {
876 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
877 finderArgs = new Object[] { active, start, end, orderByComparator };
878 }
879
880 List<Country> list = null;
881
882 if (retrieveFromCache) {
883 list = (List<Country>)finderCache.getResult(finderPath, finderArgs,
884 this);
885
886 if ((list != null) && !list.isEmpty()) {
887 for (Country country : list) {
888 if ((active != country.getActive())) {
889 list = null;
890
891 break;
892 }
893 }
894 }
895 }
896
897 if (list == null) {
898 StringBundler query = null;
899
900 if (orderByComparator != null) {
901 query = new StringBundler(3 +
902 (orderByComparator.getOrderByFields().length * 2));
903 }
904 else {
905 query = new StringBundler(3);
906 }
907
908 query.append(_SQL_SELECT_COUNTRY_WHERE);
909
910 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
911
912 if (orderByComparator != null) {
913 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
914 orderByComparator);
915 }
916 else
917 if (pagination) {
918 query.append(CountryModelImpl.ORDER_BY_JPQL);
919 }
920
921 String sql = query.toString();
922
923 Session session = null;
924
925 try {
926 session = openSession();
927
928 Query q = session.createQuery(sql);
929
930 QueryPos qPos = QueryPos.getInstance(q);
931
932 qPos.add(active);
933
934 if (!pagination) {
935 list = (List<Country>)QueryUtil.list(q, getDialect(),
936 start, end, false);
937
938 Collections.sort(list);
939
940 list = Collections.unmodifiableList(list);
941 }
942 else {
943 list = (List<Country>)QueryUtil.list(q, getDialect(),
944 start, end);
945 }
946
947 cacheResult(list);
948
949 finderCache.putResult(finderPath, finderArgs, list);
950 }
951 catch (Exception e) {
952 finderCache.removeResult(finderPath, finderArgs);
953
954 throw processException(e);
955 }
956 finally {
957 closeSession(session);
958 }
959 }
960
961 return list;
962 }
963
964
972 @Override
973 public Country findByActive_First(boolean active,
974 OrderByComparator<Country> orderByComparator)
975 throws NoSuchCountryException {
976 Country country = fetchByActive_First(active, orderByComparator);
977
978 if (country != null) {
979 return country;
980 }
981
982 StringBundler msg = new StringBundler(4);
983
984 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
985
986 msg.append("active=");
987 msg.append(active);
988
989 msg.append(StringPool.CLOSE_CURLY_BRACE);
990
991 throw new NoSuchCountryException(msg.toString());
992 }
993
994
1001 @Override
1002 public Country fetchByActive_First(boolean active,
1003 OrderByComparator<Country> orderByComparator) {
1004 List<Country> list = findByActive(active, 0, 1, orderByComparator);
1005
1006 if (!list.isEmpty()) {
1007 return list.get(0);
1008 }
1009
1010 return null;
1011 }
1012
1013
1021 @Override
1022 public Country findByActive_Last(boolean active,
1023 OrderByComparator<Country> orderByComparator)
1024 throws NoSuchCountryException {
1025 Country country = fetchByActive_Last(active, orderByComparator);
1026
1027 if (country != null) {
1028 return country;
1029 }
1030
1031 StringBundler msg = new StringBundler(4);
1032
1033 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1034
1035 msg.append("active=");
1036 msg.append(active);
1037
1038 msg.append(StringPool.CLOSE_CURLY_BRACE);
1039
1040 throw new NoSuchCountryException(msg.toString());
1041 }
1042
1043
1050 @Override
1051 public Country fetchByActive_Last(boolean active,
1052 OrderByComparator<Country> orderByComparator) {
1053 int count = countByActive(active);
1054
1055 if (count == 0) {
1056 return null;
1057 }
1058
1059 List<Country> list = findByActive(active, count - 1, count,
1060 orderByComparator);
1061
1062 if (!list.isEmpty()) {
1063 return list.get(0);
1064 }
1065
1066 return null;
1067 }
1068
1069
1078 @Override
1079 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
1080 OrderByComparator<Country> orderByComparator)
1081 throws NoSuchCountryException {
1082 Country country = findByPrimaryKey(countryId);
1083
1084 Session session = null;
1085
1086 try {
1087 session = openSession();
1088
1089 Country[] array = new CountryImpl[3];
1090
1091 array[0] = getByActive_PrevAndNext(session, country, active,
1092 orderByComparator, true);
1093
1094 array[1] = country;
1095
1096 array[2] = getByActive_PrevAndNext(session, country, active,
1097 orderByComparator, false);
1098
1099 return array;
1100 }
1101 catch (Exception e) {
1102 throw processException(e);
1103 }
1104 finally {
1105 closeSession(session);
1106 }
1107 }
1108
1109 protected Country getByActive_PrevAndNext(Session session, Country country,
1110 boolean active, OrderByComparator<Country> orderByComparator,
1111 boolean previous) {
1112 StringBundler query = null;
1113
1114 if (orderByComparator != null) {
1115 query = new StringBundler(4 +
1116 (orderByComparator.getOrderByConditionFields().length * 3) +
1117 (orderByComparator.getOrderByFields().length * 3));
1118 }
1119 else {
1120 query = new StringBundler(3);
1121 }
1122
1123 query.append(_SQL_SELECT_COUNTRY_WHERE);
1124
1125 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1126
1127 if (orderByComparator != null) {
1128 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1129
1130 if (orderByConditionFields.length > 0) {
1131 query.append(WHERE_AND);
1132 }
1133
1134 for (int i = 0; i < orderByConditionFields.length; i++) {
1135 query.append(_ORDER_BY_ENTITY_ALIAS);
1136 query.append(orderByConditionFields[i]);
1137
1138 if ((i + 1) < orderByConditionFields.length) {
1139 if (orderByComparator.isAscending() ^ previous) {
1140 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1141 }
1142 else {
1143 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1144 }
1145 }
1146 else {
1147 if (orderByComparator.isAscending() ^ previous) {
1148 query.append(WHERE_GREATER_THAN);
1149 }
1150 else {
1151 query.append(WHERE_LESSER_THAN);
1152 }
1153 }
1154 }
1155
1156 query.append(ORDER_BY_CLAUSE);
1157
1158 String[] orderByFields = orderByComparator.getOrderByFields();
1159
1160 for (int i = 0; i < orderByFields.length; i++) {
1161 query.append(_ORDER_BY_ENTITY_ALIAS);
1162 query.append(orderByFields[i]);
1163
1164 if ((i + 1) < orderByFields.length) {
1165 if (orderByComparator.isAscending() ^ previous) {
1166 query.append(ORDER_BY_ASC_HAS_NEXT);
1167 }
1168 else {
1169 query.append(ORDER_BY_DESC_HAS_NEXT);
1170 }
1171 }
1172 else {
1173 if (orderByComparator.isAscending() ^ previous) {
1174 query.append(ORDER_BY_ASC);
1175 }
1176 else {
1177 query.append(ORDER_BY_DESC);
1178 }
1179 }
1180 }
1181 }
1182 else {
1183 query.append(CountryModelImpl.ORDER_BY_JPQL);
1184 }
1185
1186 String sql = query.toString();
1187
1188 Query q = session.createQuery(sql);
1189
1190 q.setFirstResult(0);
1191 q.setMaxResults(2);
1192
1193 QueryPos qPos = QueryPos.getInstance(q);
1194
1195 qPos.add(active);
1196
1197 if (orderByComparator != null) {
1198 Object[] values = orderByComparator.getOrderByConditionValues(country);
1199
1200 for (Object value : values) {
1201 qPos.add(value);
1202 }
1203 }
1204
1205 List<Country> list = q.list();
1206
1207 if (list.size() == 2) {
1208 return list.get(1);
1209 }
1210 else {
1211 return null;
1212 }
1213 }
1214
1215
1220 @Override
1221 public void removeByActive(boolean active) {
1222 for (Country country : findByActive(active, QueryUtil.ALL_POS,
1223 QueryUtil.ALL_POS, null)) {
1224 remove(country);
1225 }
1226 }
1227
1228
1234 @Override
1235 public int countByActive(boolean active) {
1236 FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1237
1238 Object[] finderArgs = new Object[] { active };
1239
1240 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1241
1242 if (count == null) {
1243 StringBundler query = new StringBundler(2);
1244
1245 query.append(_SQL_COUNT_COUNTRY_WHERE);
1246
1247 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1248
1249 String sql = query.toString();
1250
1251 Session session = null;
1252
1253 try {
1254 session = openSession();
1255
1256 Query q = session.createQuery(sql);
1257
1258 QueryPos qPos = QueryPos.getInstance(q);
1259
1260 qPos.add(active);
1261
1262 count = (Long)q.uniqueResult();
1263
1264 finderCache.putResult(finderPath, finderArgs, count);
1265 }
1266 catch (Exception e) {
1267 finderCache.removeResult(finderPath, finderArgs);
1268
1269 throw processException(e);
1270 }
1271 finally {
1272 closeSession(session);
1273 }
1274 }
1275
1276 return count.intValue();
1277 }
1278
1279 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "country.active = ?";
1280
1281 public CountryPersistenceImpl() {
1282 setModelClass(Country.class);
1283 }
1284
1285
1290 @Override
1291 public void cacheResult(Country country) {
1292 entityCache.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1293 CountryImpl.class, country.getPrimaryKey(), country);
1294
1295 finderCache.putResult(FINDER_PATH_FETCH_BY_NAME,
1296 new Object[] { country.getName() }, country);
1297
1298 finderCache.putResult(FINDER_PATH_FETCH_BY_A2,
1299 new Object[] { country.getA2() }, country);
1300
1301 finderCache.putResult(FINDER_PATH_FETCH_BY_A3,
1302 new Object[] { country.getA3() }, country);
1303
1304 country.resetOriginalValues();
1305 }
1306
1307
1312 @Override
1313 public void cacheResult(List<Country> countries) {
1314 for (Country country : countries) {
1315 if (entityCache.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1316 CountryImpl.class, country.getPrimaryKey()) == null) {
1317 cacheResult(country);
1318 }
1319 else {
1320 country.resetOriginalValues();
1321 }
1322 }
1323 }
1324
1325
1332 @Override
1333 public void clearCache() {
1334 entityCache.clearCache(CountryImpl.class);
1335
1336 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1337 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1338 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1339 }
1340
1341
1348 @Override
1349 public void clearCache(Country country) {
1350 entityCache.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1351 CountryImpl.class, country.getPrimaryKey());
1352
1353 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1354 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1355
1356 clearUniqueFindersCache((CountryModelImpl)country);
1357 }
1358
1359 @Override
1360 public void clearCache(List<Country> countries) {
1361 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1362 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1363
1364 for (Country country : countries) {
1365 entityCache.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1366 CountryImpl.class, country.getPrimaryKey());
1367
1368 clearUniqueFindersCache((CountryModelImpl)country);
1369 }
1370 }
1371
1372 protected void cacheUniqueFindersCache(CountryModelImpl countryModelImpl,
1373 boolean isNew) {
1374 if (isNew) {
1375 Object[] args = new Object[] { countryModelImpl.getName() };
1376
1377 finderCache.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1378 Long.valueOf(1));
1379 finderCache.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1380 countryModelImpl);
1381
1382 args = new Object[] { countryModelImpl.getA2() };
1383
1384 finderCache.putResult(FINDER_PATH_COUNT_BY_A2, args, Long.valueOf(1));
1385 finderCache.putResult(FINDER_PATH_FETCH_BY_A2, args,
1386 countryModelImpl);
1387
1388 args = new Object[] { countryModelImpl.getA3() };
1389
1390 finderCache.putResult(FINDER_PATH_COUNT_BY_A3, args, Long.valueOf(1));
1391 finderCache.putResult(FINDER_PATH_FETCH_BY_A3, args,
1392 countryModelImpl);
1393 }
1394 else {
1395 if ((countryModelImpl.getColumnBitmask() &
1396 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1397 Object[] args = new Object[] { countryModelImpl.getName() };
1398
1399 finderCache.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1400 Long.valueOf(1));
1401 finderCache.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1402 countryModelImpl);
1403 }
1404
1405 if ((countryModelImpl.getColumnBitmask() &
1406 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1407 Object[] args = new Object[] { countryModelImpl.getA2() };
1408
1409 finderCache.putResult(FINDER_PATH_COUNT_BY_A2, args,
1410 Long.valueOf(1));
1411 finderCache.putResult(FINDER_PATH_FETCH_BY_A2, args,
1412 countryModelImpl);
1413 }
1414
1415 if ((countryModelImpl.getColumnBitmask() &
1416 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1417 Object[] args = new Object[] { countryModelImpl.getA3() };
1418
1419 finderCache.putResult(FINDER_PATH_COUNT_BY_A3, args,
1420 Long.valueOf(1));
1421 finderCache.putResult(FINDER_PATH_FETCH_BY_A3, args,
1422 countryModelImpl);
1423 }
1424 }
1425 }
1426
1427 protected void clearUniqueFindersCache(CountryModelImpl countryModelImpl) {
1428 Object[] args = new Object[] { countryModelImpl.getName() };
1429
1430 finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1431 finderCache.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1432
1433 if ((countryModelImpl.getColumnBitmask() &
1434 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1435 args = new Object[] { countryModelImpl.getOriginalName() };
1436
1437 finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1438 finderCache.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1439 }
1440
1441 args = new Object[] { countryModelImpl.getA2() };
1442
1443 finderCache.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1444 finderCache.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1445
1446 if ((countryModelImpl.getColumnBitmask() &
1447 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1448 args = new Object[] { countryModelImpl.getOriginalA2() };
1449
1450 finderCache.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1451 finderCache.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1452 }
1453
1454 args = new Object[] { countryModelImpl.getA3() };
1455
1456 finderCache.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1457 finderCache.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1458
1459 if ((countryModelImpl.getColumnBitmask() &
1460 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1461 args = new Object[] { countryModelImpl.getOriginalA3() };
1462
1463 finderCache.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1464 finderCache.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1465 }
1466 }
1467
1468
1474 @Override
1475 public Country create(long countryId) {
1476 Country country = new CountryImpl();
1477
1478 country.setNew(true);
1479 country.setPrimaryKey(countryId);
1480
1481 return country;
1482 }
1483
1484
1491 @Override
1492 public Country remove(long countryId) throws NoSuchCountryException {
1493 return remove((Serializable)countryId);
1494 }
1495
1496
1503 @Override
1504 public Country remove(Serializable primaryKey)
1505 throws NoSuchCountryException {
1506 Session session = null;
1507
1508 try {
1509 session = openSession();
1510
1511 Country country = (Country)session.get(CountryImpl.class, primaryKey);
1512
1513 if (country == null) {
1514 if (_log.isWarnEnabled()) {
1515 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1516 }
1517
1518 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1519 primaryKey);
1520 }
1521
1522 return remove(country);
1523 }
1524 catch (NoSuchCountryException nsee) {
1525 throw nsee;
1526 }
1527 catch (Exception e) {
1528 throw processException(e);
1529 }
1530 finally {
1531 closeSession(session);
1532 }
1533 }
1534
1535 @Override
1536 protected Country removeImpl(Country country) {
1537 country = toUnwrappedModel(country);
1538
1539 Session session = null;
1540
1541 try {
1542 session = openSession();
1543
1544 if (!session.contains(country)) {
1545 country = (Country)session.get(CountryImpl.class,
1546 country.getPrimaryKeyObj());
1547 }
1548
1549 if (country != null) {
1550 session.delete(country);
1551 }
1552 }
1553 catch (Exception e) {
1554 throw processException(e);
1555 }
1556 finally {
1557 closeSession(session);
1558 }
1559
1560 if (country != null) {
1561 clearCache(country);
1562 }
1563
1564 return country;
1565 }
1566
1567 @Override
1568 public Country updateImpl(Country country) {
1569 country = toUnwrappedModel(country);
1570
1571 boolean isNew = country.isNew();
1572
1573 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1574
1575 Session session = null;
1576
1577 try {
1578 session = openSession();
1579
1580 if (country.isNew()) {
1581 session.save(country);
1582
1583 country.setNew(false);
1584 }
1585 else {
1586 country = (Country)session.merge(country);
1587 }
1588 }
1589 catch (Exception e) {
1590 throw processException(e);
1591 }
1592 finally {
1593 closeSession(session);
1594 }
1595
1596 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1597
1598 if (isNew || !CountryModelImpl.COLUMN_BITMASK_ENABLED) {
1599 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1600 }
1601
1602 else {
1603 if ((countryModelImpl.getColumnBitmask() &
1604 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
1605 Object[] args = new Object[] {
1606 countryModelImpl.getOriginalActive()
1607 };
1608
1609 finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1610 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1611 args);
1612
1613 args = new Object[] { countryModelImpl.getActive() };
1614
1615 finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1616 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1617 args);
1618 }
1619 }
1620
1621 entityCache.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1622 CountryImpl.class, country.getPrimaryKey(), country, false);
1623
1624 clearUniqueFindersCache(countryModelImpl);
1625 cacheUniqueFindersCache(countryModelImpl, isNew);
1626
1627 country.resetOriginalValues();
1628
1629 return country;
1630 }
1631
1632 protected Country toUnwrappedModel(Country country) {
1633 if (country instanceof CountryImpl) {
1634 return country;
1635 }
1636
1637 CountryImpl countryImpl = new CountryImpl();
1638
1639 countryImpl.setNew(country.isNew());
1640 countryImpl.setPrimaryKey(country.getPrimaryKey());
1641
1642 countryImpl.setMvccVersion(country.getMvccVersion());
1643 countryImpl.setCountryId(country.getCountryId());
1644 countryImpl.setName(country.getName());
1645 countryImpl.setA2(country.getA2());
1646 countryImpl.setA3(country.getA3());
1647 countryImpl.setNumber(country.getNumber());
1648 countryImpl.setIdd(country.getIdd());
1649 countryImpl.setZipRequired(country.isZipRequired());
1650 countryImpl.setActive(country.isActive());
1651
1652 return countryImpl;
1653 }
1654
1655
1662 @Override
1663 public Country findByPrimaryKey(Serializable primaryKey)
1664 throws NoSuchCountryException {
1665 Country country = fetchByPrimaryKey(primaryKey);
1666
1667 if (country == null) {
1668 if (_log.isWarnEnabled()) {
1669 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1670 }
1671
1672 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1673 primaryKey);
1674 }
1675
1676 return country;
1677 }
1678
1679
1686 @Override
1687 public Country findByPrimaryKey(long countryId)
1688 throws NoSuchCountryException {
1689 return findByPrimaryKey((Serializable)countryId);
1690 }
1691
1692
1698 @Override
1699 public Country fetchByPrimaryKey(Serializable primaryKey) {
1700 Country country = (Country)entityCache.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1701 CountryImpl.class, primaryKey);
1702
1703 if (country == _nullCountry) {
1704 return null;
1705 }
1706
1707 if (country == null) {
1708 Session session = null;
1709
1710 try {
1711 session = openSession();
1712
1713 country = (Country)session.get(CountryImpl.class, primaryKey);
1714
1715 if (country != null) {
1716 cacheResult(country);
1717 }
1718 else {
1719 entityCache.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1720 CountryImpl.class, primaryKey, _nullCountry);
1721 }
1722 }
1723 catch (Exception e) {
1724 entityCache.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1725 CountryImpl.class, primaryKey);
1726
1727 throw processException(e);
1728 }
1729 finally {
1730 closeSession(session);
1731 }
1732 }
1733
1734 return country;
1735 }
1736
1737
1743 @Override
1744 public Country fetchByPrimaryKey(long countryId) {
1745 return fetchByPrimaryKey((Serializable)countryId);
1746 }
1747
1748 @Override
1749 public Map<Serializable, Country> fetchByPrimaryKeys(
1750 Set<Serializable> primaryKeys) {
1751 if (primaryKeys.isEmpty()) {
1752 return Collections.emptyMap();
1753 }
1754
1755 Map<Serializable, Country> map = new HashMap<Serializable, Country>();
1756
1757 if (primaryKeys.size() == 1) {
1758 Iterator<Serializable> iterator = primaryKeys.iterator();
1759
1760 Serializable primaryKey = iterator.next();
1761
1762 Country country = fetchByPrimaryKey(primaryKey);
1763
1764 if (country != null) {
1765 map.put(primaryKey, country);
1766 }
1767
1768 return map;
1769 }
1770
1771 Set<Serializable> uncachedPrimaryKeys = null;
1772
1773 for (Serializable primaryKey : primaryKeys) {
1774 Country country = (Country)entityCache.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1775 CountryImpl.class, primaryKey);
1776
1777 if (country == null) {
1778 if (uncachedPrimaryKeys == null) {
1779 uncachedPrimaryKeys = new HashSet<Serializable>();
1780 }
1781
1782 uncachedPrimaryKeys.add(primaryKey);
1783 }
1784 else {
1785 map.put(primaryKey, country);
1786 }
1787 }
1788
1789 if (uncachedPrimaryKeys == null) {
1790 return map;
1791 }
1792
1793 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1794 1);
1795
1796 query.append(_SQL_SELECT_COUNTRY_WHERE_PKS_IN);
1797
1798 for (Serializable primaryKey : uncachedPrimaryKeys) {
1799 query.append(String.valueOf(primaryKey));
1800
1801 query.append(StringPool.COMMA);
1802 }
1803
1804 query.setIndex(query.index() - 1);
1805
1806 query.append(StringPool.CLOSE_PARENTHESIS);
1807
1808 String sql = query.toString();
1809
1810 Session session = null;
1811
1812 try {
1813 session = openSession();
1814
1815 Query q = session.createQuery(sql);
1816
1817 for (Country country : (List<Country>)q.list()) {
1818 map.put(country.getPrimaryKeyObj(), country);
1819
1820 cacheResult(country);
1821
1822 uncachedPrimaryKeys.remove(country.getPrimaryKeyObj());
1823 }
1824
1825 for (Serializable primaryKey : uncachedPrimaryKeys) {
1826 entityCache.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1827 CountryImpl.class, primaryKey, _nullCountry);
1828 }
1829 }
1830 catch (Exception e) {
1831 throw processException(e);
1832 }
1833 finally {
1834 closeSession(session);
1835 }
1836
1837 return map;
1838 }
1839
1840
1845 @Override
1846 public List<Country> findAll() {
1847 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1848 }
1849
1850
1861 @Override
1862 public List<Country> findAll(int start, int end) {
1863 return findAll(start, end, null);
1864 }
1865
1866
1878 @Override
1879 public List<Country> findAll(int start, int end,
1880 OrderByComparator<Country> orderByComparator) {
1881 return findAll(start, end, orderByComparator, true);
1882 }
1883
1884
1897 @Override
1898 public List<Country> findAll(int start, int end,
1899 OrderByComparator<Country> orderByComparator, boolean retrieveFromCache) {
1900 boolean pagination = true;
1901 FinderPath finderPath = null;
1902 Object[] finderArgs = null;
1903
1904 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1905 (orderByComparator == null)) {
1906 pagination = false;
1907 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1908 finderArgs = FINDER_ARGS_EMPTY;
1909 }
1910 else {
1911 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1912 finderArgs = new Object[] { start, end, orderByComparator };
1913 }
1914
1915 List<Country> list = null;
1916
1917 if (retrieveFromCache) {
1918 list = (List<Country>)finderCache.getResult(finderPath, finderArgs,
1919 this);
1920 }
1921
1922 if (list == null) {
1923 StringBundler query = null;
1924 String sql = null;
1925
1926 if (orderByComparator != null) {
1927 query = new StringBundler(2 +
1928 (orderByComparator.getOrderByFields().length * 2));
1929
1930 query.append(_SQL_SELECT_COUNTRY);
1931
1932 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1933 orderByComparator);
1934
1935 sql = query.toString();
1936 }
1937 else {
1938 sql = _SQL_SELECT_COUNTRY;
1939
1940 if (pagination) {
1941 sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
1942 }
1943 }
1944
1945 Session session = null;
1946
1947 try {
1948 session = openSession();
1949
1950 Query q = session.createQuery(sql);
1951
1952 if (!pagination) {
1953 list = (List<Country>)QueryUtil.list(q, getDialect(),
1954 start, end, false);
1955
1956 Collections.sort(list);
1957
1958 list = Collections.unmodifiableList(list);
1959 }
1960 else {
1961 list = (List<Country>)QueryUtil.list(q, getDialect(),
1962 start, end);
1963 }
1964
1965 cacheResult(list);
1966
1967 finderCache.putResult(finderPath, finderArgs, list);
1968 }
1969 catch (Exception e) {
1970 finderCache.removeResult(finderPath, finderArgs);
1971
1972 throw processException(e);
1973 }
1974 finally {
1975 closeSession(session);
1976 }
1977 }
1978
1979 return list;
1980 }
1981
1982
1986 @Override
1987 public void removeAll() {
1988 for (Country country : findAll()) {
1989 remove(country);
1990 }
1991 }
1992
1993
1998 @Override
1999 public int countAll() {
2000 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2001 FINDER_ARGS_EMPTY, this);
2002
2003 if (count == null) {
2004 Session session = null;
2005
2006 try {
2007 session = openSession();
2008
2009 Query q = session.createQuery(_SQL_COUNT_COUNTRY);
2010
2011 count = (Long)q.uniqueResult();
2012
2013 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2014 count);
2015 }
2016 catch (Exception e) {
2017 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2018 FINDER_ARGS_EMPTY);
2019
2020 throw processException(e);
2021 }
2022 finally {
2023 closeSession(session);
2024 }
2025 }
2026
2027 return count.intValue();
2028 }
2029
2030 @Override
2031 public Set<String> getBadColumnNames() {
2032 return _badColumnNames;
2033 }
2034
2035 @Override
2036 protected Map<String, Integer> getTableColumnsMap() {
2037 return CountryModelImpl.TABLE_COLUMNS_MAP;
2038 }
2039
2040
2043 public void afterPropertiesSet() {
2044 }
2045
2046 public void destroy() {
2047 entityCache.removeCache(CountryImpl.class.getName());
2048 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2049 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2050 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2051 }
2052
2053 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2054 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2055 private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
2056 private static final String _SQL_SELECT_COUNTRY_WHERE_PKS_IN = "SELECT country FROM Country country WHERE countryId IN (";
2057 private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
2058 private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
2059 private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
2060 private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
2061 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
2062 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
2063 private static final Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
2064 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2065 "number", "idd", "active"
2066 });
2067 private static final Country _nullCountry = new CountryImpl() {
2068 @Override
2069 public Object clone() {
2070 return this;
2071 }
2072
2073 @Override
2074 public CacheModel<Country> toCacheModel() {
2075 return _nullCountryCacheModel;
2076 }
2077 };
2078
2079 private static final CacheModel<Country> _nullCountryCacheModel = new NullCacheModel();
2080
2081 private static class NullCacheModel implements CacheModel<Country>,
2082 MVCCModel {
2083 @Override
2084 public long getMvccVersion() {
2085 return -1;
2086 }
2087
2088 @Override
2089 public void setMvccVersion(long mvccVersion) {
2090 }
2091
2092 @Override
2093 public Country toEntityModel() {
2094 return _nullCountry;
2095 }
2096 }
2097 }