001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchCountryException;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
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.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.Country;
037 import com.liferay.portal.model.MVCCModel;
038 import com.liferay.portal.model.impl.CountryImpl;
039 import com.liferay.portal.model.impl.CountryModelImpl;
040 import com.liferay.portal.service.persistence.CountryPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class CountryPersistenceImpl extends BasePersistenceImpl<Country>
066 implements CountryPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = CountryImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
078 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
081 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
084 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
087 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
088 FINDER_CLASS_NAME_ENTITY, "fetchByName",
089 new String[] { String.class.getName() },
090 CountryModelImpl.NAME_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
092 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
094 new String[] { String.class.getName() });
095
096
103 @Override
104 public Country findByName(String name) throws NoSuchCountryException {
105 Country country = fetchByName(name);
106
107 if (country == null) {
108 StringBundler msg = new StringBundler(4);
109
110 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111
112 msg.append("name=");
113 msg.append(name);
114
115 msg.append(StringPool.CLOSE_CURLY_BRACE);
116
117 if (_log.isWarnEnabled()) {
118 _log.warn(msg.toString());
119 }
120
121 throw new NoSuchCountryException(msg.toString());
122 }
123
124 return country;
125 }
126
127
133 @Override
134 public Country fetchByName(String name) {
135 return fetchByName(name, true);
136 }
137
138
145 @Override
146 public Country fetchByName(String name, boolean retrieveFromCache) {
147 Object[] finderArgs = new Object[] { name };
148
149 Object result = null;
150
151 if (retrieveFromCache) {
152 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
153 finderArgs, this);
154 }
155
156 if (result instanceof Country) {
157 Country country = (Country)result;
158
159 if (!Validator.equals(name, country.getName())) {
160 result = null;
161 }
162 }
163
164 if (result == null) {
165 StringBundler query = new StringBundler(3);
166
167 query.append(_SQL_SELECT_COUNTRY_WHERE);
168
169 boolean bindName = false;
170
171 if (name == null) {
172 query.append(_FINDER_COLUMN_NAME_NAME_1);
173 }
174 else if (name.equals(StringPool.BLANK)) {
175 query.append(_FINDER_COLUMN_NAME_NAME_3);
176 }
177 else {
178 bindName = true;
179
180 query.append(_FINDER_COLUMN_NAME_NAME_2);
181 }
182
183 String sql = query.toString();
184
185 Session session = null;
186
187 try {
188 session = openSession();
189
190 Query q = session.createQuery(sql);
191
192 QueryPos qPos = QueryPos.getInstance(q);
193
194 if (bindName) {
195 qPos.add(name);
196 }
197
198 List<Country> list = q.list();
199
200 if (list.isEmpty()) {
201 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
202 finderArgs, list);
203 }
204 else {
205 Country country = list.get(0);
206
207 result = country;
208
209 cacheResult(country);
210
211 if ((country.getName() == null) ||
212 !country.getName().equals(name)) {
213 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
214 finderArgs, country);
215 }
216 }
217 }
218 catch (Exception e) {
219 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
220 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)FinderCacheUtil.getResult(finderPath, finderArgs,
263 this);
264
265 if (count == null) {
266 StringBundler query = new StringBundler(2);
267
268 query.append(_SQL_COUNT_COUNTRY_WHERE);
269
270 boolean bindName = false;
271
272 if (name == null) {
273 query.append(_FINDER_COLUMN_NAME_NAME_1);
274 }
275 else if (name.equals(StringPool.BLANK)) {
276 query.append(_FINDER_COLUMN_NAME_NAME_3);
277 }
278 else {
279 bindName = true;
280
281 query.append(_FINDER_COLUMN_NAME_NAME_2);
282 }
283
284 String sql = query.toString();
285
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 Query q = session.createQuery(sql);
292
293 QueryPos qPos = QueryPos.getInstance(q);
294
295 if (bindName) {
296 qPos.add(name);
297 }
298
299 count = (Long)q.uniqueResult();
300
301 FinderCacheUtil.putResult(finderPath, finderArgs, count);
302 }
303 catch (Exception e) {
304 FinderCacheUtil.removeResult(finderPath, finderArgs);
305
306 throw processException(e);
307 }
308 finally {
309 closeSession(session);
310 }
311 }
312
313 return count.intValue();
314 }
315
316 private static final String _FINDER_COLUMN_NAME_NAME_1 = "country.name IS NULL";
317 private static final String _FINDER_COLUMN_NAME_NAME_2 = "country.name = ?";
318 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(country.name IS NULL OR country.name = '')";
319 public static final FinderPath FINDER_PATH_FETCH_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
320 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
321 FINDER_CLASS_NAME_ENTITY, "fetchByA2",
322 new String[] { String.class.getName() },
323 CountryModelImpl.A2_COLUMN_BITMASK);
324 public static final FinderPath FINDER_PATH_COUNT_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
325 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
326 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA2",
327 new String[] { String.class.getName() });
328
329
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 = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A2,
386 finderArgs, 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 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
435 finderArgs, 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 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
447 finderArgs, country);
448 }
449 }
450 }
451 catch (Exception e) {
452 FinderCacheUtil.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)FinderCacheUtil.getResult(finderPath, finderArgs,
495 this);
496
497 if (count == null) {
498 StringBundler query = new StringBundler(2);
499
500 query.append(_SQL_COUNT_COUNTRY_WHERE);
501
502 boolean bindA2 = false;
503
504 if (a2 == null) {
505 query.append(_FINDER_COLUMN_A2_A2_1);
506 }
507 else if (a2.equals(StringPool.BLANK)) {
508 query.append(_FINDER_COLUMN_A2_A2_3);
509 }
510 else {
511 bindA2 = true;
512
513 query.append(_FINDER_COLUMN_A2_A2_2);
514 }
515
516 String sql = query.toString();
517
518 Session session = null;
519
520 try {
521 session = openSession();
522
523 Query q = session.createQuery(sql);
524
525 QueryPos qPos = QueryPos.getInstance(q);
526
527 if (bindA2) {
528 qPos.add(a2);
529 }
530
531 count = (Long)q.uniqueResult();
532
533 FinderCacheUtil.putResult(finderPath, finderArgs, count);
534 }
535 catch (Exception e) {
536 FinderCacheUtil.removeResult(finderPath, finderArgs);
537
538 throw processException(e);
539 }
540 finally {
541 closeSession(session);
542 }
543 }
544
545 return count.intValue();
546 }
547
548 private static final String _FINDER_COLUMN_A2_A2_1 = "country.a2 IS NULL";
549 private static final String _FINDER_COLUMN_A2_A2_2 = "country.a2 = ?";
550 private static final String _FINDER_COLUMN_A2_A2_3 = "(country.a2 IS NULL OR country.a2 = '')";
551 public static final FinderPath FINDER_PATH_FETCH_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
552 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
553 FINDER_CLASS_NAME_ENTITY, "fetchByA3",
554 new String[] { String.class.getName() },
555 CountryModelImpl.A3_COLUMN_BITMASK);
556 public static final FinderPath FINDER_PATH_COUNT_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
557 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
558 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA3",
559 new String[] { String.class.getName() });
560
561
568 @Override
569 public Country findByA3(String a3) throws NoSuchCountryException {
570 Country country = fetchByA3(a3);
571
572 if (country == null) {
573 StringBundler msg = new StringBundler(4);
574
575 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
576
577 msg.append("a3=");
578 msg.append(a3);
579
580 msg.append(StringPool.CLOSE_CURLY_BRACE);
581
582 if (_log.isWarnEnabled()) {
583 _log.warn(msg.toString());
584 }
585
586 throw new NoSuchCountryException(msg.toString());
587 }
588
589 return country;
590 }
591
592
598 @Override
599 public Country fetchByA3(String a3) {
600 return fetchByA3(a3, true);
601 }
602
603
610 @Override
611 public Country fetchByA3(String a3, boolean retrieveFromCache) {
612 Object[] finderArgs = new Object[] { a3 };
613
614 Object result = null;
615
616 if (retrieveFromCache) {
617 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
618 finderArgs, this);
619 }
620
621 if (result instanceof Country) {
622 Country country = (Country)result;
623
624 if (!Validator.equals(a3, country.getA3())) {
625 result = null;
626 }
627 }
628
629 if (result == null) {
630 StringBundler query = new StringBundler(3);
631
632 query.append(_SQL_SELECT_COUNTRY_WHERE);
633
634 boolean bindA3 = false;
635
636 if (a3 == null) {
637 query.append(_FINDER_COLUMN_A3_A3_1);
638 }
639 else if (a3.equals(StringPool.BLANK)) {
640 query.append(_FINDER_COLUMN_A3_A3_3);
641 }
642 else {
643 bindA3 = true;
644
645 query.append(_FINDER_COLUMN_A3_A3_2);
646 }
647
648 String sql = query.toString();
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 Query q = session.createQuery(sql);
656
657 QueryPos qPos = QueryPos.getInstance(q);
658
659 if (bindA3) {
660 qPos.add(a3);
661 }
662
663 List<Country> list = q.list();
664
665 if (list.isEmpty()) {
666 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
667 finderArgs, list);
668 }
669 else {
670 Country country = list.get(0);
671
672 result = country;
673
674 cacheResult(country);
675
676 if ((country.getA3() == null) ||
677 !country.getA3().equals(a3)) {
678 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
679 finderArgs, country);
680 }
681 }
682 }
683 catch (Exception e) {
684 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, finderArgs);
685
686 throw processException(e);
687 }
688 finally {
689 closeSession(session);
690 }
691 }
692
693 if (result instanceof List<?>) {
694 return null;
695 }
696 else {
697 return (Country)result;
698 }
699 }
700
701
707 @Override
708 public Country removeByA3(String a3) throws NoSuchCountryException {
709 Country country = findByA3(a3);
710
711 return remove(country);
712 }
713
714
720 @Override
721 public int countByA3(String a3) {
722 FinderPath finderPath = FINDER_PATH_COUNT_BY_A3;
723
724 Object[] finderArgs = new Object[] { a3 };
725
726 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
727 this);
728
729 if (count == null) {
730 StringBundler query = new StringBundler(2);
731
732 query.append(_SQL_COUNT_COUNTRY_WHERE);
733
734 boolean bindA3 = false;
735
736 if (a3 == null) {
737 query.append(_FINDER_COLUMN_A3_A3_1);
738 }
739 else if (a3.equals(StringPool.BLANK)) {
740 query.append(_FINDER_COLUMN_A3_A3_3);
741 }
742 else {
743 bindA3 = true;
744
745 query.append(_FINDER_COLUMN_A3_A3_2);
746 }
747
748 String sql = query.toString();
749
750 Session session = null;
751
752 try {
753 session = openSession();
754
755 Query q = session.createQuery(sql);
756
757 QueryPos qPos = QueryPos.getInstance(q);
758
759 if (bindA3) {
760 qPos.add(a3);
761 }
762
763 count = (Long)q.uniqueResult();
764
765 FinderCacheUtil.putResult(finderPath, finderArgs, count);
766 }
767 catch (Exception e) {
768 FinderCacheUtil.removeResult(finderPath, finderArgs);
769
770 throw processException(e);
771 }
772 finally {
773 closeSession(session);
774 }
775 }
776
777 return count.intValue();
778 }
779
780 private static final String _FINDER_COLUMN_A3_A3_1 = "country.a3 IS NULL";
781 private static final String _FINDER_COLUMN_A3_A3_2 = "country.a3 = ?";
782 private static final String _FINDER_COLUMN_A3_A3_3 = "(country.a3 IS NULL OR country.a3 = '')";
783 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
784 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
785 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
786 new String[] {
787 Boolean.class.getName(),
788
789 Integer.class.getName(), Integer.class.getName(),
790 OrderByComparator.class.getName()
791 });
792 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
793 new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
794 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
795 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
796 new String[] { Boolean.class.getName() },
797 CountryModelImpl.ACTIVE_COLUMN_BITMASK |
798 CountryModelImpl.NAME_COLUMN_BITMASK);
799 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
800 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
801 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
802 new String[] { Boolean.class.getName() });
803
804
810 @Override
811 public List<Country> findByActive(boolean active) {
812 return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
813 }
814
815
827 @Override
828 public List<Country> findByActive(boolean active, int start, int end) {
829 return findByActive(active, start, end, null);
830 }
831
832
845 @Override
846 public List<Country> findByActive(boolean active, int start, int end,
847 OrderByComparator<Country> orderByComparator) {
848 boolean pagination = true;
849 FinderPath finderPath = null;
850 Object[] finderArgs = null;
851
852 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
853 (orderByComparator == null)) {
854 pagination = false;
855 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
856 finderArgs = new Object[] { active };
857 }
858 else {
859 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
860 finderArgs = new Object[] { active, start, end, orderByComparator };
861 }
862
863 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
864 finderArgs, this);
865
866 if ((list != null) && !list.isEmpty()) {
867 for (Country country : list) {
868 if ((active != country.getActive())) {
869 list = null;
870
871 break;
872 }
873 }
874 }
875
876 if (list == null) {
877 StringBundler query = null;
878
879 if (orderByComparator != null) {
880 query = new StringBundler(3 +
881 (orderByComparator.getOrderByFields().length * 3));
882 }
883 else {
884 query = new StringBundler(3);
885 }
886
887 query.append(_SQL_SELECT_COUNTRY_WHERE);
888
889 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
890
891 if (orderByComparator != null) {
892 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
893 orderByComparator);
894 }
895 else
896 if (pagination) {
897 query.append(CountryModelImpl.ORDER_BY_JPQL);
898 }
899
900 String sql = query.toString();
901
902 Session session = null;
903
904 try {
905 session = openSession();
906
907 Query q = session.createQuery(sql);
908
909 QueryPos qPos = QueryPos.getInstance(q);
910
911 qPos.add(active);
912
913 if (!pagination) {
914 list = (List<Country>)QueryUtil.list(q, getDialect(),
915 start, end, false);
916
917 Collections.sort(list);
918
919 list = Collections.unmodifiableList(list);
920 }
921 else {
922 list = (List<Country>)QueryUtil.list(q, getDialect(),
923 start, end);
924 }
925
926 cacheResult(list);
927
928 FinderCacheUtil.putResult(finderPath, finderArgs, list);
929 }
930 catch (Exception e) {
931 FinderCacheUtil.removeResult(finderPath, finderArgs);
932
933 throw processException(e);
934 }
935 finally {
936 closeSession(session);
937 }
938 }
939
940 return list;
941 }
942
943
951 @Override
952 public Country findByActive_First(boolean active,
953 OrderByComparator<Country> orderByComparator)
954 throws NoSuchCountryException {
955 Country country = fetchByActive_First(active, orderByComparator);
956
957 if (country != null) {
958 return country;
959 }
960
961 StringBundler msg = new StringBundler(4);
962
963 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
964
965 msg.append("active=");
966 msg.append(active);
967
968 msg.append(StringPool.CLOSE_CURLY_BRACE);
969
970 throw new NoSuchCountryException(msg.toString());
971 }
972
973
980 @Override
981 public Country fetchByActive_First(boolean active,
982 OrderByComparator<Country> orderByComparator) {
983 List<Country> list = findByActive(active, 0, 1, orderByComparator);
984
985 if (!list.isEmpty()) {
986 return list.get(0);
987 }
988
989 return null;
990 }
991
992
1000 @Override
1001 public Country findByActive_Last(boolean active,
1002 OrderByComparator<Country> orderByComparator)
1003 throws NoSuchCountryException {
1004 Country country = fetchByActive_Last(active, orderByComparator);
1005
1006 if (country != null) {
1007 return country;
1008 }
1009
1010 StringBundler msg = new StringBundler(4);
1011
1012 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1013
1014 msg.append("active=");
1015 msg.append(active);
1016
1017 msg.append(StringPool.CLOSE_CURLY_BRACE);
1018
1019 throw new NoSuchCountryException(msg.toString());
1020 }
1021
1022
1029 @Override
1030 public Country fetchByActive_Last(boolean active,
1031 OrderByComparator<Country> orderByComparator) {
1032 int count = countByActive(active);
1033
1034 if (count == 0) {
1035 return null;
1036 }
1037
1038 List<Country> list = findByActive(active, count - 1, count,
1039 orderByComparator);
1040
1041 if (!list.isEmpty()) {
1042 return list.get(0);
1043 }
1044
1045 return null;
1046 }
1047
1048
1057 @Override
1058 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
1059 OrderByComparator<Country> orderByComparator)
1060 throws NoSuchCountryException {
1061 Country country = findByPrimaryKey(countryId);
1062
1063 Session session = null;
1064
1065 try {
1066 session = openSession();
1067
1068 Country[] array = new CountryImpl[3];
1069
1070 array[0] = getByActive_PrevAndNext(session, country, active,
1071 orderByComparator, true);
1072
1073 array[1] = country;
1074
1075 array[2] = getByActive_PrevAndNext(session, country, active,
1076 orderByComparator, false);
1077
1078 return array;
1079 }
1080 catch (Exception e) {
1081 throw processException(e);
1082 }
1083 finally {
1084 closeSession(session);
1085 }
1086 }
1087
1088 protected Country getByActive_PrevAndNext(Session session, Country country,
1089 boolean active, OrderByComparator<Country> orderByComparator,
1090 boolean previous) {
1091 StringBundler query = null;
1092
1093 if (orderByComparator != null) {
1094 query = new StringBundler(6 +
1095 (orderByComparator.getOrderByFields().length * 6));
1096 }
1097 else {
1098 query = new StringBundler(3);
1099 }
1100
1101 query.append(_SQL_SELECT_COUNTRY_WHERE);
1102
1103 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1104
1105 if (orderByComparator != null) {
1106 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1107
1108 if (orderByConditionFields.length > 0) {
1109 query.append(WHERE_AND);
1110 }
1111
1112 for (int i = 0; i < orderByConditionFields.length; i++) {
1113 query.append(_ORDER_BY_ENTITY_ALIAS);
1114 query.append(orderByConditionFields[i]);
1115
1116 if ((i + 1) < orderByConditionFields.length) {
1117 if (orderByComparator.isAscending() ^ previous) {
1118 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1119 }
1120 else {
1121 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1122 }
1123 }
1124 else {
1125 if (orderByComparator.isAscending() ^ previous) {
1126 query.append(WHERE_GREATER_THAN);
1127 }
1128 else {
1129 query.append(WHERE_LESSER_THAN);
1130 }
1131 }
1132 }
1133
1134 query.append(ORDER_BY_CLAUSE);
1135
1136 String[] orderByFields = orderByComparator.getOrderByFields();
1137
1138 for (int i = 0; i < orderByFields.length; i++) {
1139 query.append(_ORDER_BY_ENTITY_ALIAS);
1140 query.append(orderByFields[i]);
1141
1142 if ((i + 1) < orderByFields.length) {
1143 if (orderByComparator.isAscending() ^ previous) {
1144 query.append(ORDER_BY_ASC_HAS_NEXT);
1145 }
1146 else {
1147 query.append(ORDER_BY_DESC_HAS_NEXT);
1148 }
1149 }
1150 else {
1151 if (orderByComparator.isAscending() ^ previous) {
1152 query.append(ORDER_BY_ASC);
1153 }
1154 else {
1155 query.append(ORDER_BY_DESC);
1156 }
1157 }
1158 }
1159 }
1160 else {
1161 query.append(CountryModelImpl.ORDER_BY_JPQL);
1162 }
1163
1164 String sql = query.toString();
1165
1166 Query q = session.createQuery(sql);
1167
1168 q.setFirstResult(0);
1169 q.setMaxResults(2);
1170
1171 QueryPos qPos = QueryPos.getInstance(q);
1172
1173 qPos.add(active);
1174
1175 if (orderByComparator != null) {
1176 Object[] values = orderByComparator.getOrderByConditionValues(country);
1177
1178 for (Object value : values) {
1179 qPos.add(value);
1180 }
1181 }
1182
1183 List<Country> list = q.list();
1184
1185 if (list.size() == 2) {
1186 return list.get(1);
1187 }
1188 else {
1189 return null;
1190 }
1191 }
1192
1193
1198 @Override
1199 public void removeByActive(boolean active) {
1200 for (Country country : findByActive(active, QueryUtil.ALL_POS,
1201 QueryUtil.ALL_POS, null)) {
1202 remove(country);
1203 }
1204 }
1205
1206
1212 @Override
1213 public int countByActive(boolean active) {
1214 FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1215
1216 Object[] finderArgs = new Object[] { active };
1217
1218 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1219 this);
1220
1221 if (count == null) {
1222 StringBundler query = new StringBundler(2);
1223
1224 query.append(_SQL_COUNT_COUNTRY_WHERE);
1225
1226 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1227
1228 String sql = query.toString();
1229
1230 Session session = null;
1231
1232 try {
1233 session = openSession();
1234
1235 Query q = session.createQuery(sql);
1236
1237 QueryPos qPos = QueryPos.getInstance(q);
1238
1239 qPos.add(active);
1240
1241 count = (Long)q.uniqueResult();
1242
1243 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1244 }
1245 catch (Exception e) {
1246 FinderCacheUtil.removeResult(finderPath, finderArgs);
1247
1248 throw processException(e);
1249 }
1250 finally {
1251 closeSession(session);
1252 }
1253 }
1254
1255 return count.intValue();
1256 }
1257
1258 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "country.active = ?";
1259
1260 public CountryPersistenceImpl() {
1261 setModelClass(Country.class);
1262 }
1263
1264
1269 @Override
1270 public void cacheResult(Country country) {
1271 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1272 CountryImpl.class, country.getPrimaryKey(), country);
1273
1274 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
1275 new Object[] { country.getName() }, country);
1276
1277 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
1278 new Object[] { country.getA2() }, country);
1279
1280 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
1281 new Object[] { country.getA3() }, country);
1282
1283 country.resetOriginalValues();
1284 }
1285
1286
1291 @Override
1292 public void cacheResult(List<Country> countries) {
1293 for (Country country : countries) {
1294 if (EntityCacheUtil.getResult(
1295 CountryModelImpl.ENTITY_CACHE_ENABLED,
1296 CountryImpl.class, country.getPrimaryKey()) == null) {
1297 cacheResult(country);
1298 }
1299 else {
1300 country.resetOriginalValues();
1301 }
1302 }
1303 }
1304
1305
1312 @Override
1313 public void clearCache() {
1314 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1315 CacheRegistryUtil.clear(CountryImpl.class.getName());
1316 }
1317
1318 EntityCacheUtil.clearCache(CountryImpl.class);
1319
1320 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1321 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1323 }
1324
1325
1332 @Override
1333 public void clearCache(Country country) {
1334 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1335 CountryImpl.class, country.getPrimaryKey());
1336
1337 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1338 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1339
1340 clearUniqueFindersCache(country);
1341 }
1342
1343 @Override
1344 public void clearCache(List<Country> countries) {
1345 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1346 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1347
1348 for (Country country : countries) {
1349 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1350 CountryImpl.class, country.getPrimaryKey());
1351
1352 clearUniqueFindersCache(country);
1353 }
1354 }
1355
1356 protected void cacheUniqueFindersCache(Country country) {
1357 if (country.isNew()) {
1358 Object[] args = new Object[] { country.getName() };
1359
1360 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1361 Long.valueOf(1));
1362 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args, country);
1363
1364 args = new Object[] { country.getA2() };
1365
1366 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1367 Long.valueOf(1));
1368 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1369
1370 args = new Object[] { country.getA3() };
1371
1372 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1373 Long.valueOf(1));
1374 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1375 }
1376 else {
1377 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1378
1379 if ((countryModelImpl.getColumnBitmask() &
1380 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1381 Object[] args = new Object[] { country.getName() };
1382
1383 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1384 Long.valueOf(1));
1385 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1386 country);
1387 }
1388
1389 if ((countryModelImpl.getColumnBitmask() &
1390 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1391 Object[] args = new Object[] { country.getA2() };
1392
1393 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1394 Long.valueOf(1));
1395 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1396 }
1397
1398 if ((countryModelImpl.getColumnBitmask() &
1399 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1400 Object[] args = new Object[] { country.getA3() };
1401
1402 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1403 Long.valueOf(1));
1404 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1405 }
1406 }
1407 }
1408
1409 protected void clearUniqueFindersCache(Country country) {
1410 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1411
1412 Object[] args = new Object[] { country.getName() };
1413
1414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1415 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1416
1417 if ((countryModelImpl.getColumnBitmask() &
1418 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1419 args = new Object[] { countryModelImpl.getOriginalName() };
1420
1421 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1422 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1423 }
1424
1425 args = new Object[] { country.getA2() };
1426
1427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1428 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1429
1430 if ((countryModelImpl.getColumnBitmask() &
1431 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1432 args = new Object[] { countryModelImpl.getOriginalA2() };
1433
1434 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1435 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1436 }
1437
1438 args = new Object[] { country.getA3() };
1439
1440 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1441 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1442
1443 if ((countryModelImpl.getColumnBitmask() &
1444 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1445 args = new Object[] { countryModelImpl.getOriginalA3() };
1446
1447 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1448 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1449 }
1450 }
1451
1452
1458 @Override
1459 public Country create(long countryId) {
1460 Country country = new CountryImpl();
1461
1462 country.setNew(true);
1463 country.setPrimaryKey(countryId);
1464
1465 return country;
1466 }
1467
1468
1475 @Override
1476 public Country remove(long countryId) throws NoSuchCountryException {
1477 return remove((Serializable)countryId);
1478 }
1479
1480
1487 @Override
1488 public Country remove(Serializable primaryKey)
1489 throws NoSuchCountryException {
1490 Session session = null;
1491
1492 try {
1493 session = openSession();
1494
1495 Country country = (Country)session.get(CountryImpl.class, primaryKey);
1496
1497 if (country == null) {
1498 if (_log.isWarnEnabled()) {
1499 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1500 }
1501
1502 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1503 primaryKey);
1504 }
1505
1506 return remove(country);
1507 }
1508 catch (NoSuchCountryException nsee) {
1509 throw nsee;
1510 }
1511 catch (Exception e) {
1512 throw processException(e);
1513 }
1514 finally {
1515 closeSession(session);
1516 }
1517 }
1518
1519 @Override
1520 protected Country removeImpl(Country country) {
1521 country = toUnwrappedModel(country);
1522
1523 Session session = null;
1524
1525 try {
1526 session = openSession();
1527
1528 if (!session.contains(country)) {
1529 country = (Country)session.get(CountryImpl.class,
1530 country.getPrimaryKeyObj());
1531 }
1532
1533 if (country != null) {
1534 session.delete(country);
1535 }
1536 }
1537 catch (Exception e) {
1538 throw processException(e);
1539 }
1540 finally {
1541 closeSession(session);
1542 }
1543
1544 if (country != null) {
1545 clearCache(country);
1546 }
1547
1548 return country;
1549 }
1550
1551 @Override
1552 public Country updateImpl(com.liferay.portal.model.Country country) {
1553 country = toUnwrappedModel(country);
1554
1555 boolean isNew = country.isNew();
1556
1557 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1558
1559 Session session = null;
1560
1561 try {
1562 session = openSession();
1563
1564 if (country.isNew()) {
1565 session.save(country);
1566
1567 country.setNew(false);
1568 }
1569 else {
1570 session.merge(country);
1571 }
1572 }
1573 catch (Exception e) {
1574 throw processException(e);
1575 }
1576 finally {
1577 closeSession(session);
1578 }
1579
1580 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1581
1582 if (isNew || !CountryModelImpl.COLUMN_BITMASK_ENABLED) {
1583 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1584 }
1585
1586 else {
1587 if ((countryModelImpl.getColumnBitmask() &
1588 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
1589 Object[] args = new Object[] {
1590 countryModelImpl.getOriginalActive()
1591 };
1592
1593 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1594 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1595 args);
1596
1597 args = new Object[] { countryModelImpl.getActive() };
1598
1599 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1600 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1601 args);
1602 }
1603 }
1604
1605 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1606 CountryImpl.class, country.getPrimaryKey(), country, false);
1607
1608 clearUniqueFindersCache(country);
1609 cacheUniqueFindersCache(country);
1610
1611 country.resetOriginalValues();
1612
1613 return country;
1614 }
1615
1616 protected Country toUnwrappedModel(Country country) {
1617 if (country instanceof CountryImpl) {
1618 return country;
1619 }
1620
1621 CountryImpl countryImpl = new CountryImpl();
1622
1623 countryImpl.setNew(country.isNew());
1624 countryImpl.setPrimaryKey(country.getPrimaryKey());
1625
1626 countryImpl.setMvccVersion(country.getMvccVersion());
1627 countryImpl.setCountryId(country.getCountryId());
1628 countryImpl.setName(country.getName());
1629 countryImpl.setA2(country.getA2());
1630 countryImpl.setA3(country.getA3());
1631 countryImpl.setNumber(country.getNumber());
1632 countryImpl.setIdd(country.getIdd());
1633 countryImpl.setZipRequired(country.isZipRequired());
1634 countryImpl.setActive(country.isActive());
1635
1636 return countryImpl;
1637 }
1638
1639
1646 @Override
1647 public Country findByPrimaryKey(Serializable primaryKey)
1648 throws NoSuchCountryException {
1649 Country country = fetchByPrimaryKey(primaryKey);
1650
1651 if (country == null) {
1652 if (_log.isWarnEnabled()) {
1653 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1654 }
1655
1656 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1657 primaryKey);
1658 }
1659
1660 return country;
1661 }
1662
1663
1670 @Override
1671 public Country findByPrimaryKey(long countryId)
1672 throws NoSuchCountryException {
1673 return findByPrimaryKey((Serializable)countryId);
1674 }
1675
1676
1682 @Override
1683 public Country fetchByPrimaryKey(Serializable primaryKey) {
1684 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1685 CountryImpl.class, primaryKey);
1686
1687 if (country == _nullCountry) {
1688 return null;
1689 }
1690
1691 if (country == null) {
1692 Session session = null;
1693
1694 try {
1695 session = openSession();
1696
1697 country = (Country)session.get(CountryImpl.class, primaryKey);
1698
1699 if (country != null) {
1700 cacheResult(country);
1701 }
1702 else {
1703 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1704 CountryImpl.class, primaryKey, _nullCountry);
1705 }
1706 }
1707 catch (Exception e) {
1708 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1709 CountryImpl.class, primaryKey);
1710
1711 throw processException(e);
1712 }
1713 finally {
1714 closeSession(session);
1715 }
1716 }
1717
1718 return country;
1719 }
1720
1721
1727 @Override
1728 public Country fetchByPrimaryKey(long countryId) {
1729 return fetchByPrimaryKey((Serializable)countryId);
1730 }
1731
1732 @Override
1733 public Map<Serializable, Country> fetchByPrimaryKeys(
1734 Set<Serializable> primaryKeys) {
1735 if (primaryKeys.isEmpty()) {
1736 return Collections.emptyMap();
1737 }
1738
1739 Map<Serializable, Country> map = new HashMap<Serializable, Country>();
1740
1741 if (primaryKeys.size() == 1) {
1742 Iterator<Serializable> iterator = primaryKeys.iterator();
1743
1744 Serializable primaryKey = iterator.next();
1745
1746 Country country = fetchByPrimaryKey(primaryKey);
1747
1748 if (country != null) {
1749 map.put(primaryKey, country);
1750 }
1751
1752 return map;
1753 }
1754
1755 Set<Serializable> uncachedPrimaryKeys = null;
1756
1757 for (Serializable primaryKey : primaryKeys) {
1758 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1759 CountryImpl.class, primaryKey);
1760
1761 if (country == null) {
1762 if (uncachedPrimaryKeys == null) {
1763 uncachedPrimaryKeys = new HashSet<Serializable>();
1764 }
1765
1766 uncachedPrimaryKeys.add(primaryKey);
1767 }
1768 else {
1769 map.put(primaryKey, country);
1770 }
1771 }
1772
1773 if (uncachedPrimaryKeys == null) {
1774 return map;
1775 }
1776
1777 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1778 1);
1779
1780 query.append(_SQL_SELECT_COUNTRY_WHERE_PKS_IN);
1781
1782 for (Serializable primaryKey : uncachedPrimaryKeys) {
1783 query.append(String.valueOf(primaryKey));
1784
1785 query.append(StringPool.COMMA);
1786 }
1787
1788 query.setIndex(query.index() - 1);
1789
1790 query.append(StringPool.CLOSE_PARENTHESIS);
1791
1792 String sql = query.toString();
1793
1794 Session session = null;
1795
1796 try {
1797 session = openSession();
1798
1799 Query q = session.createQuery(sql);
1800
1801 for (Country country : (List<Country>)q.list()) {
1802 map.put(country.getPrimaryKeyObj(), country);
1803
1804 cacheResult(country);
1805
1806 uncachedPrimaryKeys.remove(country.getPrimaryKeyObj());
1807 }
1808
1809 for (Serializable primaryKey : uncachedPrimaryKeys) {
1810 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1811 CountryImpl.class, primaryKey, _nullCountry);
1812 }
1813 }
1814 catch (Exception e) {
1815 throw processException(e);
1816 }
1817 finally {
1818 closeSession(session);
1819 }
1820
1821 return map;
1822 }
1823
1824
1829 @Override
1830 public List<Country> findAll() {
1831 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1832 }
1833
1834
1845 @Override
1846 public List<Country> findAll(int start, int end) {
1847 return findAll(start, end, null);
1848 }
1849
1850
1862 @Override
1863 public List<Country> findAll(int start, int end,
1864 OrderByComparator<Country> orderByComparator) {
1865 boolean pagination = true;
1866 FinderPath finderPath = null;
1867 Object[] finderArgs = null;
1868
1869 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1870 (orderByComparator == null)) {
1871 pagination = false;
1872 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1873 finderArgs = FINDER_ARGS_EMPTY;
1874 }
1875 else {
1876 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1877 finderArgs = new Object[] { start, end, orderByComparator };
1878 }
1879
1880 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
1881 finderArgs, this);
1882
1883 if (list == null) {
1884 StringBundler query = null;
1885 String sql = null;
1886
1887 if (orderByComparator != null) {
1888 query = new StringBundler(2 +
1889 (orderByComparator.getOrderByFields().length * 3));
1890
1891 query.append(_SQL_SELECT_COUNTRY);
1892
1893 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1894 orderByComparator);
1895
1896 sql = query.toString();
1897 }
1898 else {
1899 sql = _SQL_SELECT_COUNTRY;
1900
1901 if (pagination) {
1902 sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
1903 }
1904 }
1905
1906 Session session = null;
1907
1908 try {
1909 session = openSession();
1910
1911 Query q = session.createQuery(sql);
1912
1913 if (!pagination) {
1914 list = (List<Country>)QueryUtil.list(q, getDialect(),
1915 start, end, false);
1916
1917 Collections.sort(list);
1918
1919 list = Collections.unmodifiableList(list);
1920 }
1921 else {
1922 list = (List<Country>)QueryUtil.list(q, getDialect(),
1923 start, end);
1924 }
1925
1926 cacheResult(list);
1927
1928 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1929 }
1930 catch (Exception e) {
1931 FinderCacheUtil.removeResult(finderPath, finderArgs);
1932
1933 throw processException(e);
1934 }
1935 finally {
1936 closeSession(session);
1937 }
1938 }
1939
1940 return list;
1941 }
1942
1943
1947 @Override
1948 public void removeAll() {
1949 for (Country country : findAll()) {
1950 remove(country);
1951 }
1952 }
1953
1954
1959 @Override
1960 public int countAll() {
1961 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1962 FINDER_ARGS_EMPTY, this);
1963
1964 if (count == null) {
1965 Session session = null;
1966
1967 try {
1968 session = openSession();
1969
1970 Query q = session.createQuery(_SQL_COUNT_COUNTRY);
1971
1972 count = (Long)q.uniqueResult();
1973
1974 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1975 FINDER_ARGS_EMPTY, count);
1976 }
1977 catch (Exception e) {
1978 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1979 FINDER_ARGS_EMPTY);
1980
1981 throw processException(e);
1982 }
1983 finally {
1984 closeSession(session);
1985 }
1986 }
1987
1988 return count.intValue();
1989 }
1990
1991 @Override
1992 protected Set<String> getBadColumnNames() {
1993 return _badColumnNames;
1994 }
1995
1996
1999 public void afterPropertiesSet() {
2000 }
2001
2002 public void destroy() {
2003 EntityCacheUtil.removeCache(CountryImpl.class.getName());
2004 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2005 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2006 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2007 }
2008
2009 private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
2010 private static final String _SQL_SELECT_COUNTRY_WHERE_PKS_IN = "SELECT country FROM Country country WHERE countryId IN (";
2011 private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
2012 private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
2013 private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
2014 private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
2015 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
2016 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
2017 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2018 private static final Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
2019 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2020 "number", "idd", "active"
2021 });
2022 private static final Country _nullCountry = new CountryImpl() {
2023 @Override
2024 public Object clone() {
2025 return this;
2026 }
2027
2028 @Override
2029 public CacheModel<Country> toCacheModel() {
2030 return _nullCountryCacheModel;
2031 }
2032 };
2033
2034 private static final CacheModel<Country> _nullCountryCacheModel = new NullCacheModel();
2035
2036 private static class NullCacheModel implements CacheModel<Country>,
2037 MVCCModel {
2038 @Override
2039 public long getMvccVersion() {
2040 return -1;
2041 }
2042
2043 @Override
2044 public void setMvccVersion(long mvccVersion) {
2045 }
2046
2047 @Override
2048 public Country toEntityModel() {
2049 return _nullCountry;
2050 }
2051 }
2052 }