001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchCountryException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.Country;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.model.impl.CountryImpl;
042 import com.liferay.portal.model.impl.CountryModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050 import java.util.Set;
051
052
064 public class CountryPersistenceImpl extends BasePersistenceImpl<Country>
065 implements CountryPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = CountryImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
077 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
080 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
083 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
086 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
087 FINDER_CLASS_NAME_ENTITY, "fetchByName",
088 new String[] { String.class.getName() },
089 CountryModelImpl.NAME_COLUMN_BITMASK);
090 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
091 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
093 new String[] { String.class.getName() });
094
095
103 @Override
104 public Country findByName(String name)
105 throws NoSuchCountryException, SystemException {
106 Country country = fetchByName(name);
107
108 if (country == null) {
109 StringBundler msg = new StringBundler(4);
110
111 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
112
113 msg.append("name=");
114 msg.append(name);
115
116 msg.append(StringPool.CLOSE_CURLY_BRACE);
117
118 if (_log.isWarnEnabled()) {
119 _log.warn(msg.toString());
120 }
121
122 throw new NoSuchCountryException(msg.toString());
123 }
124
125 return country;
126 }
127
128
135 @Override
136 public Country fetchByName(String name) throws SystemException {
137 return fetchByName(name, true);
138 }
139
140
148 @Override
149 public Country fetchByName(String name, boolean retrieveFromCache)
150 throws SystemException {
151 Object[] finderArgs = new Object[] { name };
152
153 Object result = null;
154
155 if (retrieveFromCache) {
156 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
157 finderArgs, this);
158 }
159
160 if (result instanceof Country) {
161 Country country = (Country)result;
162
163 if (!Validator.equals(name, country.getName())) {
164 result = null;
165 }
166 }
167
168 if (result == null) {
169 StringBundler query = new StringBundler(3);
170
171 query.append(_SQL_SELECT_COUNTRY_WHERE);
172
173 boolean bindName = false;
174
175 if (name == null) {
176 query.append(_FINDER_COLUMN_NAME_NAME_1);
177 }
178 else if (name.equals(StringPool.BLANK)) {
179 query.append(_FINDER_COLUMN_NAME_NAME_3);
180 }
181 else {
182 bindName = true;
183
184 query.append(_FINDER_COLUMN_NAME_NAME_2);
185 }
186
187 String sql = query.toString();
188
189 Session session = null;
190
191 try {
192 session = openSession();
193
194 Query q = session.createQuery(sql);
195
196 QueryPos qPos = QueryPos.getInstance(q);
197
198 if (bindName) {
199 qPos.add(name);
200 }
201
202 List<Country> list = q.list();
203
204 if (list.isEmpty()) {
205 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
206 finderArgs, list);
207 }
208 else {
209 Country country = list.get(0);
210
211 result = country;
212
213 cacheResult(country);
214
215 if ((country.getName() == null) ||
216 !country.getName().equals(name)) {
217 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
218 finderArgs, country);
219 }
220 }
221 }
222 catch (Exception e) {
223 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
224 finderArgs);
225
226 throw processException(e);
227 }
228 finally {
229 closeSession(session);
230 }
231 }
232
233 if (result instanceof List<?>) {
234 return null;
235 }
236 else {
237 return (Country)result;
238 }
239 }
240
241
248 @Override
249 public Country removeByName(String name)
250 throws NoSuchCountryException, SystemException {
251 Country country = findByName(name);
252
253 return remove(country);
254 }
255
256
263 @Override
264 public int countByName(String name) throws SystemException {
265 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
266
267 Object[] finderArgs = new Object[] { name };
268
269 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
270 this);
271
272 if (count == null) {
273 StringBundler query = new StringBundler(2);
274
275 query.append(_SQL_COUNT_COUNTRY_WHERE);
276
277 boolean bindName = false;
278
279 if (name == null) {
280 query.append(_FINDER_COLUMN_NAME_NAME_1);
281 }
282 else if (name.equals(StringPool.BLANK)) {
283 query.append(_FINDER_COLUMN_NAME_NAME_3);
284 }
285 else {
286 bindName = true;
287
288 query.append(_FINDER_COLUMN_NAME_NAME_2);
289 }
290
291 String sql = query.toString();
292
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 Query q = session.createQuery(sql);
299
300 QueryPos qPos = QueryPos.getInstance(q);
301
302 if (bindName) {
303 qPos.add(name);
304 }
305
306 count = (Long)q.uniqueResult();
307
308 FinderCacheUtil.putResult(finderPath, finderArgs, count);
309 }
310 catch (Exception e) {
311 FinderCacheUtil.removeResult(finderPath, finderArgs);
312
313 throw processException(e);
314 }
315 finally {
316 closeSession(session);
317 }
318 }
319
320 return count.intValue();
321 }
322
323 private static final String _FINDER_COLUMN_NAME_NAME_1 = "country.name IS NULL";
324 private static final String _FINDER_COLUMN_NAME_NAME_2 = "country.name = ?";
325 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(country.name IS NULL OR country.name = '')";
326 public static final FinderPath FINDER_PATH_FETCH_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
327 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
328 FINDER_CLASS_NAME_ENTITY, "fetchByA2",
329 new String[] { String.class.getName() },
330 CountryModelImpl.A2_COLUMN_BITMASK);
331 public static final FinderPath FINDER_PATH_COUNT_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
332 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
333 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA2",
334 new String[] { String.class.getName() });
335
336
344 @Override
345 public Country findByA2(String a2)
346 throws NoSuchCountryException, SystemException {
347 Country country = fetchByA2(a2);
348
349 if (country == null) {
350 StringBundler msg = new StringBundler(4);
351
352 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
353
354 msg.append("a2=");
355 msg.append(a2);
356
357 msg.append(StringPool.CLOSE_CURLY_BRACE);
358
359 if (_log.isWarnEnabled()) {
360 _log.warn(msg.toString());
361 }
362
363 throw new NoSuchCountryException(msg.toString());
364 }
365
366 return country;
367 }
368
369
376 @Override
377 public Country fetchByA2(String a2) throws SystemException {
378 return fetchByA2(a2, true);
379 }
380
381
389 @Override
390 public Country fetchByA2(String a2, boolean retrieveFromCache)
391 throws SystemException {
392 Object[] finderArgs = new Object[] { a2 };
393
394 Object result = null;
395
396 if (retrieveFromCache) {
397 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A2,
398 finderArgs, this);
399 }
400
401 if (result instanceof Country) {
402 Country country = (Country)result;
403
404 if (!Validator.equals(a2, country.getA2())) {
405 result = null;
406 }
407 }
408
409 if (result == null) {
410 StringBundler query = new StringBundler(3);
411
412 query.append(_SQL_SELECT_COUNTRY_WHERE);
413
414 boolean bindA2 = false;
415
416 if (a2 == null) {
417 query.append(_FINDER_COLUMN_A2_A2_1);
418 }
419 else if (a2.equals(StringPool.BLANK)) {
420 query.append(_FINDER_COLUMN_A2_A2_3);
421 }
422 else {
423 bindA2 = true;
424
425 query.append(_FINDER_COLUMN_A2_A2_2);
426 }
427
428 String sql = query.toString();
429
430 Session session = null;
431
432 try {
433 session = openSession();
434
435 Query q = session.createQuery(sql);
436
437 QueryPos qPos = QueryPos.getInstance(q);
438
439 if (bindA2) {
440 qPos.add(a2);
441 }
442
443 List<Country> list = q.list();
444
445 if (list.isEmpty()) {
446 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
447 finderArgs, list);
448 }
449 else {
450 Country country = list.get(0);
451
452 result = country;
453
454 cacheResult(country);
455
456 if ((country.getA2() == null) ||
457 !country.getA2().equals(a2)) {
458 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
459 finderArgs, country);
460 }
461 }
462 }
463 catch (Exception e) {
464 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, finderArgs);
465
466 throw processException(e);
467 }
468 finally {
469 closeSession(session);
470 }
471 }
472
473 if (result instanceof List<?>) {
474 return null;
475 }
476 else {
477 return (Country)result;
478 }
479 }
480
481
488 @Override
489 public Country removeByA2(String a2)
490 throws NoSuchCountryException, SystemException {
491 Country country = findByA2(a2);
492
493 return remove(country);
494 }
495
496
503 @Override
504 public int countByA2(String a2) throws SystemException {
505 FinderPath finderPath = FINDER_PATH_COUNT_BY_A2;
506
507 Object[] finderArgs = new Object[] { a2 };
508
509 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
510 this);
511
512 if (count == null) {
513 StringBundler query = new StringBundler(2);
514
515 query.append(_SQL_COUNT_COUNTRY_WHERE);
516
517 boolean bindA2 = false;
518
519 if (a2 == null) {
520 query.append(_FINDER_COLUMN_A2_A2_1);
521 }
522 else if (a2.equals(StringPool.BLANK)) {
523 query.append(_FINDER_COLUMN_A2_A2_3);
524 }
525 else {
526 bindA2 = true;
527
528 query.append(_FINDER_COLUMN_A2_A2_2);
529 }
530
531 String sql = query.toString();
532
533 Session session = null;
534
535 try {
536 session = openSession();
537
538 Query q = session.createQuery(sql);
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 if (bindA2) {
543 qPos.add(a2);
544 }
545
546 count = (Long)q.uniqueResult();
547
548 FinderCacheUtil.putResult(finderPath, finderArgs, count);
549 }
550 catch (Exception e) {
551 FinderCacheUtil.removeResult(finderPath, finderArgs);
552
553 throw processException(e);
554 }
555 finally {
556 closeSession(session);
557 }
558 }
559
560 return count.intValue();
561 }
562
563 private static final String _FINDER_COLUMN_A2_A2_1 = "country.a2 IS NULL";
564 private static final String _FINDER_COLUMN_A2_A2_2 = "country.a2 = ?";
565 private static final String _FINDER_COLUMN_A2_A2_3 = "(country.a2 IS NULL OR country.a2 = '')";
566 public static final FinderPath FINDER_PATH_FETCH_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
567 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
568 FINDER_CLASS_NAME_ENTITY, "fetchByA3",
569 new String[] { String.class.getName() },
570 CountryModelImpl.A3_COLUMN_BITMASK);
571 public static final FinderPath FINDER_PATH_COUNT_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
572 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
573 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA3",
574 new String[] { String.class.getName() });
575
576
584 @Override
585 public Country findByA3(String a3)
586 throws NoSuchCountryException, SystemException {
587 Country country = fetchByA3(a3);
588
589 if (country == null) {
590 StringBundler msg = new StringBundler(4);
591
592 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
593
594 msg.append("a3=");
595 msg.append(a3);
596
597 msg.append(StringPool.CLOSE_CURLY_BRACE);
598
599 if (_log.isWarnEnabled()) {
600 _log.warn(msg.toString());
601 }
602
603 throw new NoSuchCountryException(msg.toString());
604 }
605
606 return country;
607 }
608
609
616 @Override
617 public Country fetchByA3(String a3) throws SystemException {
618 return fetchByA3(a3, true);
619 }
620
621
629 @Override
630 public Country fetchByA3(String a3, boolean retrieveFromCache)
631 throws SystemException {
632 Object[] finderArgs = new Object[] { a3 };
633
634 Object result = null;
635
636 if (retrieveFromCache) {
637 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
638 finderArgs, this);
639 }
640
641 if (result instanceof Country) {
642 Country country = (Country)result;
643
644 if (!Validator.equals(a3, country.getA3())) {
645 result = null;
646 }
647 }
648
649 if (result == null) {
650 StringBundler query = new StringBundler(3);
651
652 query.append(_SQL_SELECT_COUNTRY_WHERE);
653
654 boolean bindA3 = false;
655
656 if (a3 == null) {
657 query.append(_FINDER_COLUMN_A3_A3_1);
658 }
659 else if (a3.equals(StringPool.BLANK)) {
660 query.append(_FINDER_COLUMN_A3_A3_3);
661 }
662 else {
663 bindA3 = true;
664
665 query.append(_FINDER_COLUMN_A3_A3_2);
666 }
667
668 String sql = query.toString();
669
670 Session session = null;
671
672 try {
673 session = openSession();
674
675 Query q = session.createQuery(sql);
676
677 QueryPos qPos = QueryPos.getInstance(q);
678
679 if (bindA3) {
680 qPos.add(a3);
681 }
682
683 List<Country> list = q.list();
684
685 if (list.isEmpty()) {
686 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
687 finderArgs, list);
688 }
689 else {
690 Country country = list.get(0);
691
692 result = country;
693
694 cacheResult(country);
695
696 if ((country.getA3() == null) ||
697 !country.getA3().equals(a3)) {
698 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
699 finderArgs, country);
700 }
701 }
702 }
703 catch (Exception e) {
704 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, finderArgs);
705
706 throw processException(e);
707 }
708 finally {
709 closeSession(session);
710 }
711 }
712
713 if (result instanceof List<?>) {
714 return null;
715 }
716 else {
717 return (Country)result;
718 }
719 }
720
721
728 @Override
729 public Country removeByA3(String a3)
730 throws NoSuchCountryException, SystemException {
731 Country country = findByA3(a3);
732
733 return remove(country);
734 }
735
736
743 @Override
744 public int countByA3(String a3) throws SystemException {
745 FinderPath finderPath = FINDER_PATH_COUNT_BY_A3;
746
747 Object[] finderArgs = new Object[] { a3 };
748
749 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
750 this);
751
752 if (count == null) {
753 StringBundler query = new StringBundler(2);
754
755 query.append(_SQL_COUNT_COUNTRY_WHERE);
756
757 boolean bindA3 = false;
758
759 if (a3 == null) {
760 query.append(_FINDER_COLUMN_A3_A3_1);
761 }
762 else if (a3.equals(StringPool.BLANK)) {
763 query.append(_FINDER_COLUMN_A3_A3_3);
764 }
765 else {
766 bindA3 = true;
767
768 query.append(_FINDER_COLUMN_A3_A3_2);
769 }
770
771 String sql = query.toString();
772
773 Session session = null;
774
775 try {
776 session = openSession();
777
778 Query q = session.createQuery(sql);
779
780 QueryPos qPos = QueryPos.getInstance(q);
781
782 if (bindA3) {
783 qPos.add(a3);
784 }
785
786 count = (Long)q.uniqueResult();
787
788 FinderCacheUtil.putResult(finderPath, finderArgs, count);
789 }
790 catch (Exception e) {
791 FinderCacheUtil.removeResult(finderPath, finderArgs);
792
793 throw processException(e);
794 }
795 finally {
796 closeSession(session);
797 }
798 }
799
800 return count.intValue();
801 }
802
803 private static final String _FINDER_COLUMN_A3_A3_1 = "country.a3 IS NULL";
804 private static final String _FINDER_COLUMN_A3_A3_2 = "country.a3 = ?";
805 private static final String _FINDER_COLUMN_A3_A3_3 = "(country.a3 IS NULL OR country.a3 = '')";
806 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
807 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
808 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
809 new String[] {
810 Boolean.class.getName(),
811
812 Integer.class.getName(), Integer.class.getName(),
813 OrderByComparator.class.getName()
814 });
815 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
816 new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
817 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
818 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
819 new String[] { Boolean.class.getName() },
820 CountryModelImpl.ACTIVE_COLUMN_BITMASK |
821 CountryModelImpl.NAME_COLUMN_BITMASK);
822 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
823 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
824 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
825 new String[] { Boolean.class.getName() });
826
827
834 @Override
835 public List<Country> findByActive(boolean active) throws SystemException {
836 return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
837 }
838
839
852 @Override
853 public List<Country> findByActive(boolean active, int start, int end)
854 throws SystemException {
855 return findByActive(active, start, end, null);
856 }
857
858
872 @Override
873 public List<Country> findByActive(boolean active, int start, int end,
874 OrderByComparator orderByComparator) throws SystemException {
875 boolean pagination = true;
876 FinderPath finderPath = null;
877 Object[] finderArgs = null;
878
879 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
880 (orderByComparator == null)) {
881 pagination = false;
882 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
883 finderArgs = new Object[] { active };
884 }
885 else {
886 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
887 finderArgs = new Object[] { active, start, end, orderByComparator };
888 }
889
890 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
891 finderArgs, this);
892
893 if ((list != null) && !list.isEmpty()) {
894 for (Country country : list) {
895 if ((active != country.getActive())) {
896 list = null;
897
898 break;
899 }
900 }
901 }
902
903 if (list == null) {
904 StringBundler query = null;
905
906 if (orderByComparator != null) {
907 query = new StringBundler(3 +
908 (orderByComparator.getOrderByFields().length * 3));
909 }
910 else {
911 query = new StringBundler(3);
912 }
913
914 query.append(_SQL_SELECT_COUNTRY_WHERE);
915
916 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
917
918 if (orderByComparator != null) {
919 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
920 orderByComparator);
921 }
922 else
923 if (pagination) {
924 query.append(CountryModelImpl.ORDER_BY_JPQL);
925 }
926
927 String sql = query.toString();
928
929 Session session = null;
930
931 try {
932 session = openSession();
933
934 Query q = session.createQuery(sql);
935
936 QueryPos qPos = QueryPos.getInstance(q);
937
938 qPos.add(active);
939
940 if (!pagination) {
941 list = (List<Country>)QueryUtil.list(q, getDialect(),
942 start, end, false);
943
944 Collections.sort(list);
945
946 list = new UnmodifiableList<Country>(list);
947 }
948 else {
949 list = (List<Country>)QueryUtil.list(q, getDialect(),
950 start, end);
951 }
952
953 cacheResult(list);
954
955 FinderCacheUtil.putResult(finderPath, finderArgs, list);
956 }
957 catch (Exception e) {
958 FinderCacheUtil.removeResult(finderPath, finderArgs);
959
960 throw processException(e);
961 }
962 finally {
963 closeSession(session);
964 }
965 }
966
967 return list;
968 }
969
970
979 @Override
980 public Country findByActive_First(boolean active,
981 OrderByComparator orderByComparator)
982 throws NoSuchCountryException, SystemException {
983 Country country = fetchByActive_First(active, orderByComparator);
984
985 if (country != null) {
986 return country;
987 }
988
989 StringBundler msg = new StringBundler(4);
990
991 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
992
993 msg.append("active=");
994 msg.append(active);
995
996 msg.append(StringPool.CLOSE_CURLY_BRACE);
997
998 throw new NoSuchCountryException(msg.toString());
999 }
1000
1001
1009 @Override
1010 public Country fetchByActive_First(boolean active,
1011 OrderByComparator orderByComparator) throws SystemException {
1012 List<Country> list = findByActive(active, 0, 1, orderByComparator);
1013
1014 if (!list.isEmpty()) {
1015 return list.get(0);
1016 }
1017
1018 return null;
1019 }
1020
1021
1030 @Override
1031 public Country findByActive_Last(boolean active,
1032 OrderByComparator orderByComparator)
1033 throws NoSuchCountryException, SystemException {
1034 Country country = fetchByActive_Last(active, orderByComparator);
1035
1036 if (country != null) {
1037 return country;
1038 }
1039
1040 StringBundler msg = new StringBundler(4);
1041
1042 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1043
1044 msg.append("active=");
1045 msg.append(active);
1046
1047 msg.append(StringPool.CLOSE_CURLY_BRACE);
1048
1049 throw new NoSuchCountryException(msg.toString());
1050 }
1051
1052
1060 @Override
1061 public Country fetchByActive_Last(boolean active,
1062 OrderByComparator orderByComparator) throws SystemException {
1063 int count = countByActive(active);
1064
1065 if (count == 0) {
1066 return null;
1067 }
1068
1069 List<Country> list = findByActive(active, count - 1, count,
1070 orderByComparator);
1071
1072 if (!list.isEmpty()) {
1073 return list.get(0);
1074 }
1075
1076 return null;
1077 }
1078
1079
1089 @Override
1090 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
1091 OrderByComparator orderByComparator)
1092 throws NoSuchCountryException, SystemException {
1093 Country country = findByPrimaryKey(countryId);
1094
1095 Session session = null;
1096
1097 try {
1098 session = openSession();
1099
1100 Country[] array = new CountryImpl[3];
1101
1102 array[0] = getByActive_PrevAndNext(session, country, active,
1103 orderByComparator, true);
1104
1105 array[1] = country;
1106
1107 array[2] = getByActive_PrevAndNext(session, country, active,
1108 orderByComparator, false);
1109
1110 return array;
1111 }
1112 catch (Exception e) {
1113 throw processException(e);
1114 }
1115 finally {
1116 closeSession(session);
1117 }
1118 }
1119
1120 protected Country getByActive_PrevAndNext(Session session, Country country,
1121 boolean active, OrderByComparator orderByComparator, boolean previous) {
1122 StringBundler query = null;
1123
1124 if (orderByComparator != null) {
1125 query = new StringBundler(6 +
1126 (orderByComparator.getOrderByFields().length * 6));
1127 }
1128 else {
1129 query = new StringBundler(3);
1130 }
1131
1132 query.append(_SQL_SELECT_COUNTRY_WHERE);
1133
1134 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1135
1136 if (orderByComparator != null) {
1137 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1138
1139 if (orderByConditionFields.length > 0) {
1140 query.append(WHERE_AND);
1141 }
1142
1143 for (int i = 0; i < orderByConditionFields.length; i++) {
1144 query.append(_ORDER_BY_ENTITY_ALIAS);
1145 query.append(orderByConditionFields[i]);
1146
1147 if ((i + 1) < orderByConditionFields.length) {
1148 if (orderByComparator.isAscending() ^ previous) {
1149 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1150 }
1151 else {
1152 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1153 }
1154 }
1155 else {
1156 if (orderByComparator.isAscending() ^ previous) {
1157 query.append(WHERE_GREATER_THAN);
1158 }
1159 else {
1160 query.append(WHERE_LESSER_THAN);
1161 }
1162 }
1163 }
1164
1165 query.append(ORDER_BY_CLAUSE);
1166
1167 String[] orderByFields = orderByComparator.getOrderByFields();
1168
1169 for (int i = 0; i < orderByFields.length; i++) {
1170 query.append(_ORDER_BY_ENTITY_ALIAS);
1171 query.append(orderByFields[i]);
1172
1173 if ((i + 1) < orderByFields.length) {
1174 if (orderByComparator.isAscending() ^ previous) {
1175 query.append(ORDER_BY_ASC_HAS_NEXT);
1176 }
1177 else {
1178 query.append(ORDER_BY_DESC_HAS_NEXT);
1179 }
1180 }
1181 else {
1182 if (orderByComparator.isAscending() ^ previous) {
1183 query.append(ORDER_BY_ASC);
1184 }
1185 else {
1186 query.append(ORDER_BY_DESC);
1187 }
1188 }
1189 }
1190 }
1191 else {
1192 query.append(CountryModelImpl.ORDER_BY_JPQL);
1193 }
1194
1195 String sql = query.toString();
1196
1197 Query q = session.createQuery(sql);
1198
1199 q.setFirstResult(0);
1200 q.setMaxResults(2);
1201
1202 QueryPos qPos = QueryPos.getInstance(q);
1203
1204 qPos.add(active);
1205
1206 if (orderByComparator != null) {
1207 Object[] values = orderByComparator.getOrderByConditionValues(country);
1208
1209 for (Object value : values) {
1210 qPos.add(value);
1211 }
1212 }
1213
1214 List<Country> list = q.list();
1215
1216 if (list.size() == 2) {
1217 return list.get(1);
1218 }
1219 else {
1220 return null;
1221 }
1222 }
1223
1224
1230 @Override
1231 public void removeByActive(boolean active) throws SystemException {
1232 for (Country country : findByActive(active, QueryUtil.ALL_POS,
1233 QueryUtil.ALL_POS, null)) {
1234 remove(country);
1235 }
1236 }
1237
1238
1245 @Override
1246 public int countByActive(boolean active) throws SystemException {
1247 FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1248
1249 Object[] finderArgs = new Object[] { active };
1250
1251 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1252 this);
1253
1254 if (count == null) {
1255 StringBundler query = new StringBundler(2);
1256
1257 query.append(_SQL_COUNT_COUNTRY_WHERE);
1258
1259 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1260
1261 String sql = query.toString();
1262
1263 Session session = null;
1264
1265 try {
1266 session = openSession();
1267
1268 Query q = session.createQuery(sql);
1269
1270 QueryPos qPos = QueryPos.getInstance(q);
1271
1272 qPos.add(active);
1273
1274 count = (Long)q.uniqueResult();
1275
1276 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1277 }
1278 catch (Exception e) {
1279 FinderCacheUtil.removeResult(finderPath, finderArgs);
1280
1281 throw processException(e);
1282 }
1283 finally {
1284 closeSession(session);
1285 }
1286 }
1287
1288 return count.intValue();
1289 }
1290
1291 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "country.active = ?";
1292
1293
1298 @Override
1299 public void cacheResult(Country country) {
1300 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1301 CountryImpl.class, country.getPrimaryKey(), country);
1302
1303 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
1304 new Object[] { country.getName() }, country);
1305
1306 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
1307 new Object[] { country.getA2() }, country);
1308
1309 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
1310 new Object[] { country.getA3() }, country);
1311
1312 country.resetOriginalValues();
1313 }
1314
1315
1320 @Override
1321 public void cacheResult(List<Country> countries) {
1322 for (Country country : countries) {
1323 if (EntityCacheUtil.getResult(
1324 CountryModelImpl.ENTITY_CACHE_ENABLED,
1325 CountryImpl.class, country.getPrimaryKey()) == null) {
1326 cacheResult(country);
1327 }
1328 else {
1329 country.resetOriginalValues();
1330 }
1331 }
1332 }
1333
1334
1341 @Override
1342 public void clearCache() {
1343 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1344 CacheRegistryUtil.clear(CountryImpl.class.getName());
1345 }
1346
1347 EntityCacheUtil.clearCache(CountryImpl.class.getName());
1348
1349 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1350 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1351 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1352 }
1353
1354
1361 @Override
1362 public void clearCache(Country country) {
1363 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1364 CountryImpl.class, country.getPrimaryKey());
1365
1366 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1367 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1368
1369 clearUniqueFindersCache(country);
1370 }
1371
1372 @Override
1373 public void clearCache(List<Country> countries) {
1374 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1375 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1376
1377 for (Country country : countries) {
1378 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1379 CountryImpl.class, country.getPrimaryKey());
1380
1381 clearUniqueFindersCache(country);
1382 }
1383 }
1384
1385 protected void cacheUniqueFindersCache(Country country) {
1386 if (country.isNew()) {
1387 Object[] args = new Object[] { country.getName() };
1388
1389 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1390 Long.valueOf(1));
1391 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args, country);
1392
1393 args = new Object[] { country.getA2() };
1394
1395 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1396 Long.valueOf(1));
1397 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1398
1399 args = new Object[] { country.getA3() };
1400
1401 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1402 Long.valueOf(1));
1403 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1404 }
1405 else {
1406 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1407
1408 if ((countryModelImpl.getColumnBitmask() &
1409 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1410 Object[] args = new Object[] { country.getName() };
1411
1412 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1413 Long.valueOf(1));
1414 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1415 country);
1416 }
1417
1418 if ((countryModelImpl.getColumnBitmask() &
1419 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1420 Object[] args = new Object[] { country.getA2() };
1421
1422 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1423 Long.valueOf(1));
1424 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1425 }
1426
1427 if ((countryModelImpl.getColumnBitmask() &
1428 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1429 Object[] args = new Object[] { country.getA3() };
1430
1431 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1432 Long.valueOf(1));
1433 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1434 }
1435 }
1436 }
1437
1438 protected void clearUniqueFindersCache(Country country) {
1439 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1440
1441 Object[] args = new Object[] { country.getName() };
1442
1443 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1444 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1445
1446 if ((countryModelImpl.getColumnBitmask() &
1447 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1448 args = new Object[] { countryModelImpl.getOriginalName() };
1449
1450 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1451 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1452 }
1453
1454 args = new Object[] { country.getA2() };
1455
1456 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1457 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1458
1459 if ((countryModelImpl.getColumnBitmask() &
1460 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1461 args = new Object[] { countryModelImpl.getOriginalA2() };
1462
1463 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1464 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1465 }
1466
1467 args = new Object[] { country.getA3() };
1468
1469 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1470 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1471
1472 if ((countryModelImpl.getColumnBitmask() &
1473 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1474 args = new Object[] { countryModelImpl.getOriginalA3() };
1475
1476 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1477 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1478 }
1479 }
1480
1481
1487 @Override
1488 public Country create(long countryId) {
1489 Country country = new CountryImpl();
1490
1491 country.setNew(true);
1492 country.setPrimaryKey(countryId);
1493
1494 return country;
1495 }
1496
1497
1505 @Override
1506 public Country remove(long countryId)
1507 throws NoSuchCountryException, SystemException {
1508 return remove((Serializable)countryId);
1509 }
1510
1511
1519 @Override
1520 public Country remove(Serializable primaryKey)
1521 throws NoSuchCountryException, SystemException {
1522 Session session = null;
1523
1524 try {
1525 session = openSession();
1526
1527 Country country = (Country)session.get(CountryImpl.class, primaryKey);
1528
1529 if (country == null) {
1530 if (_log.isWarnEnabled()) {
1531 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1532 }
1533
1534 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1535 primaryKey);
1536 }
1537
1538 return remove(country);
1539 }
1540 catch (NoSuchCountryException nsee) {
1541 throw nsee;
1542 }
1543 catch (Exception e) {
1544 throw processException(e);
1545 }
1546 finally {
1547 closeSession(session);
1548 }
1549 }
1550
1551 @Override
1552 protected Country removeImpl(Country country) throws SystemException {
1553 country = toUnwrappedModel(country);
1554
1555 Session session = null;
1556
1557 try {
1558 session = openSession();
1559
1560 if (!session.contains(country)) {
1561 country = (Country)session.get(CountryImpl.class,
1562 country.getPrimaryKeyObj());
1563 }
1564
1565 if (country != null) {
1566 session.delete(country);
1567 }
1568 }
1569 catch (Exception e) {
1570 throw processException(e);
1571 }
1572 finally {
1573 closeSession(session);
1574 }
1575
1576 if (country != null) {
1577 clearCache(country);
1578 }
1579
1580 return country;
1581 }
1582
1583 @Override
1584 public Country updateImpl(com.liferay.portal.model.Country country)
1585 throws SystemException {
1586 country = toUnwrappedModel(country);
1587
1588 boolean isNew = country.isNew();
1589
1590 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1591
1592 Session session = null;
1593
1594 try {
1595 session = openSession();
1596
1597 if (country.isNew()) {
1598 session.save(country);
1599
1600 country.setNew(false);
1601 }
1602 else {
1603 session.merge(country);
1604 }
1605 }
1606 catch (Exception e) {
1607 throw processException(e);
1608 }
1609 finally {
1610 closeSession(session);
1611 }
1612
1613 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1614
1615 if (isNew || !CountryModelImpl.COLUMN_BITMASK_ENABLED) {
1616 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1617 }
1618
1619 else {
1620 if ((countryModelImpl.getColumnBitmask() &
1621 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
1622 Object[] args = new Object[] {
1623 countryModelImpl.getOriginalActive()
1624 };
1625
1626 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1627 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1628 args);
1629
1630 args = new Object[] { countryModelImpl.getActive() };
1631
1632 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1633 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1634 args);
1635 }
1636 }
1637
1638 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1639 CountryImpl.class, country.getPrimaryKey(), country);
1640
1641 clearUniqueFindersCache(country);
1642 cacheUniqueFindersCache(country);
1643
1644 return country;
1645 }
1646
1647 protected Country toUnwrappedModel(Country country) {
1648 if (country instanceof CountryImpl) {
1649 return country;
1650 }
1651
1652 CountryImpl countryImpl = new CountryImpl();
1653
1654 countryImpl.setNew(country.isNew());
1655 countryImpl.setPrimaryKey(country.getPrimaryKey());
1656
1657 countryImpl.setCountryId(country.getCountryId());
1658 countryImpl.setName(country.getName());
1659 countryImpl.setA2(country.getA2());
1660 countryImpl.setA3(country.getA3());
1661 countryImpl.setNumber(country.getNumber());
1662 countryImpl.setIdd(country.getIdd());
1663 countryImpl.setZipRequired(country.isZipRequired());
1664 countryImpl.setActive(country.isActive());
1665
1666 return countryImpl;
1667 }
1668
1669
1677 @Override
1678 public Country findByPrimaryKey(Serializable primaryKey)
1679 throws NoSuchCountryException, SystemException {
1680 Country country = fetchByPrimaryKey(primaryKey);
1681
1682 if (country == null) {
1683 if (_log.isWarnEnabled()) {
1684 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1685 }
1686
1687 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1688 primaryKey);
1689 }
1690
1691 return country;
1692 }
1693
1694
1702 @Override
1703 public Country findByPrimaryKey(long countryId)
1704 throws NoSuchCountryException, SystemException {
1705 return findByPrimaryKey((Serializable)countryId);
1706 }
1707
1708
1715 @Override
1716 public Country fetchByPrimaryKey(Serializable primaryKey)
1717 throws SystemException {
1718 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1719 CountryImpl.class, primaryKey);
1720
1721 if (country == _nullCountry) {
1722 return null;
1723 }
1724
1725 if (country == null) {
1726 Session session = null;
1727
1728 try {
1729 session = openSession();
1730
1731 country = (Country)session.get(CountryImpl.class, primaryKey);
1732
1733 if (country != null) {
1734 cacheResult(country);
1735 }
1736 else {
1737 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1738 CountryImpl.class, primaryKey, _nullCountry);
1739 }
1740 }
1741 catch (Exception e) {
1742 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1743 CountryImpl.class, primaryKey);
1744
1745 throw processException(e);
1746 }
1747 finally {
1748 closeSession(session);
1749 }
1750 }
1751
1752 return country;
1753 }
1754
1755
1762 @Override
1763 public Country fetchByPrimaryKey(long countryId) throws SystemException {
1764 return fetchByPrimaryKey((Serializable)countryId);
1765 }
1766
1767
1773 @Override
1774 public List<Country> findAll() throws SystemException {
1775 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1776 }
1777
1778
1790 @Override
1791 public List<Country> findAll(int start, int end) throws SystemException {
1792 return findAll(start, end, null);
1793 }
1794
1795
1808 @Override
1809 public List<Country> findAll(int start, int end,
1810 OrderByComparator orderByComparator) throws SystemException {
1811 boolean pagination = true;
1812 FinderPath finderPath = null;
1813 Object[] finderArgs = null;
1814
1815 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1816 (orderByComparator == null)) {
1817 pagination = false;
1818 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1819 finderArgs = FINDER_ARGS_EMPTY;
1820 }
1821 else {
1822 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1823 finderArgs = new Object[] { start, end, orderByComparator };
1824 }
1825
1826 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
1827 finderArgs, this);
1828
1829 if (list == null) {
1830 StringBundler query = null;
1831 String sql = null;
1832
1833 if (orderByComparator != null) {
1834 query = new StringBundler(2 +
1835 (orderByComparator.getOrderByFields().length * 3));
1836
1837 query.append(_SQL_SELECT_COUNTRY);
1838
1839 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1840 orderByComparator);
1841
1842 sql = query.toString();
1843 }
1844 else {
1845 sql = _SQL_SELECT_COUNTRY;
1846
1847 if (pagination) {
1848 sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
1849 }
1850 }
1851
1852 Session session = null;
1853
1854 try {
1855 session = openSession();
1856
1857 Query q = session.createQuery(sql);
1858
1859 if (!pagination) {
1860 list = (List<Country>)QueryUtil.list(q, getDialect(),
1861 start, end, false);
1862
1863 Collections.sort(list);
1864
1865 list = new UnmodifiableList<Country>(list);
1866 }
1867 else {
1868 list = (List<Country>)QueryUtil.list(q, getDialect(),
1869 start, end);
1870 }
1871
1872 cacheResult(list);
1873
1874 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1875 }
1876 catch (Exception e) {
1877 FinderCacheUtil.removeResult(finderPath, finderArgs);
1878
1879 throw processException(e);
1880 }
1881 finally {
1882 closeSession(session);
1883 }
1884 }
1885
1886 return list;
1887 }
1888
1889
1894 @Override
1895 public void removeAll() throws SystemException {
1896 for (Country country : findAll()) {
1897 remove(country);
1898 }
1899 }
1900
1901
1907 @Override
1908 public int countAll() throws SystemException {
1909 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1910 FINDER_ARGS_EMPTY, this);
1911
1912 if (count == null) {
1913 Session session = null;
1914
1915 try {
1916 session = openSession();
1917
1918 Query q = session.createQuery(_SQL_COUNT_COUNTRY);
1919
1920 count = (Long)q.uniqueResult();
1921
1922 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1923 FINDER_ARGS_EMPTY, count);
1924 }
1925 catch (Exception e) {
1926 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1927 FINDER_ARGS_EMPTY);
1928
1929 throw processException(e);
1930 }
1931 finally {
1932 closeSession(session);
1933 }
1934 }
1935
1936 return count.intValue();
1937 }
1938
1939 @Override
1940 protected Set<String> getBadColumnNames() {
1941 return _badColumnNames;
1942 }
1943
1944
1947 public void afterPropertiesSet() {
1948 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1949 com.liferay.portal.util.PropsUtil.get(
1950 "value.object.listener.com.liferay.portal.model.Country")));
1951
1952 if (listenerClassNames.length > 0) {
1953 try {
1954 List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1955
1956 for (String listenerClassName : listenerClassNames) {
1957 listenersList.add((ModelListener<Country>)InstanceFactory.newInstance(
1958 getClassLoader(), listenerClassName));
1959 }
1960
1961 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1962 }
1963 catch (Exception e) {
1964 _log.error(e);
1965 }
1966 }
1967 }
1968
1969 public void destroy() {
1970 EntityCacheUtil.removeCache(CountryImpl.class.getName());
1971 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1972 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1973 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1974 }
1975
1976 private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
1977 private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
1978 private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
1979 private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
1980 private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
1981 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
1982 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
1983 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1984 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1985 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1986 "number", "idd", "active"
1987 });
1988 private static Country _nullCountry = new CountryImpl() {
1989 @Override
1990 public Object clone() {
1991 return this;
1992 }
1993
1994 @Override
1995 public CacheModel<Country> toCacheModel() {
1996 return _nullCountryCacheModel;
1997 }
1998 };
1999
2000 private static CacheModel<Country> _nullCountryCacheModel = new CacheModel<Country>() {
2001 @Override
2002 public Country toEntityModel() {
2003 return _nullCountry;
2004 }
2005 };
2006 }