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