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 public CountryPersistenceImpl() {
1294 setModelClass(Country.class);
1295 }
1296
1297
1302 @Override
1303 public void cacheResult(Country country) {
1304 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1305 CountryImpl.class, country.getPrimaryKey(), country);
1306
1307 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
1308 new Object[] { country.getName() }, country);
1309
1310 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
1311 new Object[] { country.getA2() }, country);
1312
1313 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
1314 new Object[] { country.getA3() }, country);
1315
1316 country.resetOriginalValues();
1317 }
1318
1319
1324 @Override
1325 public void cacheResult(List<Country> countries) {
1326 for (Country country : countries) {
1327 if (EntityCacheUtil.getResult(
1328 CountryModelImpl.ENTITY_CACHE_ENABLED,
1329 CountryImpl.class, country.getPrimaryKey()) == null) {
1330 cacheResult(country);
1331 }
1332 else {
1333 country.resetOriginalValues();
1334 }
1335 }
1336 }
1337
1338
1345 @Override
1346 public void clearCache() {
1347 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1348 CacheRegistryUtil.clear(CountryImpl.class.getName());
1349 }
1350
1351 EntityCacheUtil.clearCache(CountryImpl.class.getName());
1352
1353 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1354 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1355 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1356 }
1357
1358
1365 @Override
1366 public void clearCache(Country country) {
1367 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1368 CountryImpl.class, country.getPrimaryKey());
1369
1370 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1371 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1372
1373 clearUniqueFindersCache(country);
1374 }
1375
1376 @Override
1377 public void clearCache(List<Country> countries) {
1378 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1379 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1380
1381 for (Country country : countries) {
1382 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1383 CountryImpl.class, country.getPrimaryKey());
1384
1385 clearUniqueFindersCache(country);
1386 }
1387 }
1388
1389 protected void cacheUniqueFindersCache(Country country) {
1390 if (country.isNew()) {
1391 Object[] args = new Object[] { country.getName() };
1392
1393 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1394 Long.valueOf(1));
1395 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args, country);
1396
1397 args = new Object[] { country.getA2() };
1398
1399 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1400 Long.valueOf(1));
1401 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1402
1403 args = new Object[] { country.getA3() };
1404
1405 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1406 Long.valueOf(1));
1407 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1408 }
1409 else {
1410 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1411
1412 if ((countryModelImpl.getColumnBitmask() &
1413 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1414 Object[] args = new Object[] { country.getName() };
1415
1416 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1417 Long.valueOf(1));
1418 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1419 country);
1420 }
1421
1422 if ((countryModelImpl.getColumnBitmask() &
1423 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1424 Object[] args = new Object[] { country.getA2() };
1425
1426 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1427 Long.valueOf(1));
1428 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1429 }
1430
1431 if ((countryModelImpl.getColumnBitmask() &
1432 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1433 Object[] args = new Object[] { country.getA3() };
1434
1435 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1436 Long.valueOf(1));
1437 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1438 }
1439 }
1440 }
1441
1442 protected void clearUniqueFindersCache(Country country) {
1443 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1444
1445 Object[] args = new Object[] { country.getName() };
1446
1447 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1448 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1449
1450 if ((countryModelImpl.getColumnBitmask() &
1451 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1452 args = new Object[] { countryModelImpl.getOriginalName() };
1453
1454 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1455 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1456 }
1457
1458 args = new Object[] { country.getA2() };
1459
1460 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1461 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1462
1463 if ((countryModelImpl.getColumnBitmask() &
1464 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1465 args = new Object[] { countryModelImpl.getOriginalA2() };
1466
1467 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1468 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1469 }
1470
1471 args = new Object[] { country.getA3() };
1472
1473 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1474 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1475
1476 if ((countryModelImpl.getColumnBitmask() &
1477 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1478 args = new Object[] { countryModelImpl.getOriginalA3() };
1479
1480 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1481 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1482 }
1483 }
1484
1485
1491 @Override
1492 public Country create(long countryId) {
1493 Country country = new CountryImpl();
1494
1495 country.setNew(true);
1496 country.setPrimaryKey(countryId);
1497
1498 return country;
1499 }
1500
1501
1509 @Override
1510 public Country remove(long countryId)
1511 throws NoSuchCountryException, SystemException {
1512 return remove((Serializable)countryId);
1513 }
1514
1515
1523 @Override
1524 public Country remove(Serializable primaryKey)
1525 throws NoSuchCountryException, SystemException {
1526 Session session = null;
1527
1528 try {
1529 session = openSession();
1530
1531 Country country = (Country)session.get(CountryImpl.class, primaryKey);
1532
1533 if (country == null) {
1534 if (_log.isWarnEnabled()) {
1535 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1536 }
1537
1538 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1539 primaryKey);
1540 }
1541
1542 return remove(country);
1543 }
1544 catch (NoSuchCountryException nsee) {
1545 throw nsee;
1546 }
1547 catch (Exception e) {
1548 throw processException(e);
1549 }
1550 finally {
1551 closeSession(session);
1552 }
1553 }
1554
1555 @Override
1556 protected Country removeImpl(Country country) throws SystemException {
1557 country = toUnwrappedModel(country);
1558
1559 Session session = null;
1560
1561 try {
1562 session = openSession();
1563
1564 if (!session.contains(country)) {
1565 country = (Country)session.get(CountryImpl.class,
1566 country.getPrimaryKeyObj());
1567 }
1568
1569 if (country != null) {
1570 session.delete(country);
1571 }
1572 }
1573 catch (Exception e) {
1574 throw processException(e);
1575 }
1576 finally {
1577 closeSession(session);
1578 }
1579
1580 if (country != null) {
1581 clearCache(country);
1582 }
1583
1584 return country;
1585 }
1586
1587 @Override
1588 public Country updateImpl(com.liferay.portal.model.Country country)
1589 throws SystemException {
1590 country = toUnwrappedModel(country);
1591
1592 boolean isNew = country.isNew();
1593
1594 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1595
1596 Session session = null;
1597
1598 try {
1599 session = openSession();
1600
1601 if (country.isNew()) {
1602 session.save(country);
1603
1604 country.setNew(false);
1605 }
1606 else {
1607 session.merge(country);
1608 }
1609 }
1610 catch (Exception e) {
1611 throw processException(e);
1612 }
1613 finally {
1614 closeSession(session);
1615 }
1616
1617 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1618
1619 if (isNew || !CountryModelImpl.COLUMN_BITMASK_ENABLED) {
1620 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1621 }
1622
1623 else {
1624 if ((countryModelImpl.getColumnBitmask() &
1625 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
1626 Object[] args = new Object[] {
1627 countryModelImpl.getOriginalActive()
1628 };
1629
1630 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1631 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1632 args);
1633
1634 args = new Object[] { countryModelImpl.getActive() };
1635
1636 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1637 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1638 args);
1639 }
1640 }
1641
1642 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1643 CountryImpl.class, country.getPrimaryKey(), country);
1644
1645 clearUniqueFindersCache(country);
1646 cacheUniqueFindersCache(country);
1647
1648 return country;
1649 }
1650
1651 protected Country toUnwrappedModel(Country country) {
1652 if (country instanceof CountryImpl) {
1653 return country;
1654 }
1655
1656 CountryImpl countryImpl = new CountryImpl();
1657
1658 countryImpl.setNew(country.isNew());
1659 countryImpl.setPrimaryKey(country.getPrimaryKey());
1660
1661 countryImpl.setCountryId(country.getCountryId());
1662 countryImpl.setName(country.getName());
1663 countryImpl.setA2(country.getA2());
1664 countryImpl.setA3(country.getA3());
1665 countryImpl.setNumber(country.getNumber());
1666 countryImpl.setIdd(country.getIdd());
1667 countryImpl.setZipRequired(country.isZipRequired());
1668 countryImpl.setActive(country.isActive());
1669
1670 return countryImpl;
1671 }
1672
1673
1681 @Override
1682 public Country findByPrimaryKey(Serializable primaryKey)
1683 throws NoSuchCountryException, SystemException {
1684 Country country = fetchByPrimaryKey(primaryKey);
1685
1686 if (country == null) {
1687 if (_log.isWarnEnabled()) {
1688 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1689 }
1690
1691 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1692 primaryKey);
1693 }
1694
1695 return country;
1696 }
1697
1698
1706 @Override
1707 public Country findByPrimaryKey(long countryId)
1708 throws NoSuchCountryException, SystemException {
1709 return findByPrimaryKey((Serializable)countryId);
1710 }
1711
1712
1719 @Override
1720 public Country fetchByPrimaryKey(Serializable primaryKey)
1721 throws SystemException {
1722 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1723 CountryImpl.class, primaryKey);
1724
1725 if (country == _nullCountry) {
1726 return null;
1727 }
1728
1729 if (country == null) {
1730 Session session = null;
1731
1732 try {
1733 session = openSession();
1734
1735 country = (Country)session.get(CountryImpl.class, primaryKey);
1736
1737 if (country != null) {
1738 cacheResult(country);
1739 }
1740 else {
1741 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1742 CountryImpl.class, primaryKey, _nullCountry);
1743 }
1744 }
1745 catch (Exception e) {
1746 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1747 CountryImpl.class, primaryKey);
1748
1749 throw processException(e);
1750 }
1751 finally {
1752 closeSession(session);
1753 }
1754 }
1755
1756 return country;
1757 }
1758
1759
1766 @Override
1767 public Country fetchByPrimaryKey(long countryId) throws SystemException {
1768 return fetchByPrimaryKey((Serializable)countryId);
1769 }
1770
1771
1777 @Override
1778 public List<Country> findAll() throws SystemException {
1779 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1780 }
1781
1782
1794 @Override
1795 public List<Country> findAll(int start, int end) throws SystemException {
1796 return findAll(start, end, null);
1797 }
1798
1799
1812 @Override
1813 public List<Country> findAll(int start, int end,
1814 OrderByComparator orderByComparator) throws SystemException {
1815 boolean pagination = true;
1816 FinderPath finderPath = null;
1817 Object[] finderArgs = null;
1818
1819 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1820 (orderByComparator == null)) {
1821 pagination = false;
1822 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1823 finderArgs = FINDER_ARGS_EMPTY;
1824 }
1825 else {
1826 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1827 finderArgs = new Object[] { start, end, orderByComparator };
1828 }
1829
1830 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
1831 finderArgs, this);
1832
1833 if (list == null) {
1834 StringBundler query = null;
1835 String sql = null;
1836
1837 if (orderByComparator != null) {
1838 query = new StringBundler(2 +
1839 (orderByComparator.getOrderByFields().length * 3));
1840
1841 query.append(_SQL_SELECT_COUNTRY);
1842
1843 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1844 orderByComparator);
1845
1846 sql = query.toString();
1847 }
1848 else {
1849 sql = _SQL_SELECT_COUNTRY;
1850
1851 if (pagination) {
1852 sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
1853 }
1854 }
1855
1856 Session session = null;
1857
1858 try {
1859 session = openSession();
1860
1861 Query q = session.createQuery(sql);
1862
1863 if (!pagination) {
1864 list = (List<Country>)QueryUtil.list(q, getDialect(),
1865 start, end, false);
1866
1867 Collections.sort(list);
1868
1869 list = new UnmodifiableList<Country>(list);
1870 }
1871 else {
1872 list = (List<Country>)QueryUtil.list(q, getDialect(),
1873 start, end);
1874 }
1875
1876 cacheResult(list);
1877
1878 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1879 }
1880 catch (Exception e) {
1881 FinderCacheUtil.removeResult(finderPath, finderArgs);
1882
1883 throw processException(e);
1884 }
1885 finally {
1886 closeSession(session);
1887 }
1888 }
1889
1890 return list;
1891 }
1892
1893
1898 @Override
1899 public void removeAll() throws SystemException {
1900 for (Country country : findAll()) {
1901 remove(country);
1902 }
1903 }
1904
1905
1911 @Override
1912 public int countAll() throws SystemException {
1913 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1914 FINDER_ARGS_EMPTY, this);
1915
1916 if (count == null) {
1917 Session session = null;
1918
1919 try {
1920 session = openSession();
1921
1922 Query q = session.createQuery(_SQL_COUNT_COUNTRY);
1923
1924 count = (Long)q.uniqueResult();
1925
1926 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1927 FINDER_ARGS_EMPTY, count);
1928 }
1929 catch (Exception e) {
1930 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1931 FINDER_ARGS_EMPTY);
1932
1933 throw processException(e);
1934 }
1935 finally {
1936 closeSession(session);
1937 }
1938 }
1939
1940 return count.intValue();
1941 }
1942
1943 @Override
1944 protected Set<String> getBadColumnNames() {
1945 return _badColumnNames;
1946 }
1947
1948
1951 public void afterPropertiesSet() {
1952 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1953 com.liferay.portal.util.PropsUtil.get(
1954 "value.object.listener.com.liferay.portal.model.Country")));
1955
1956 if (listenerClassNames.length > 0) {
1957 try {
1958 List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1959
1960 for (String listenerClassName : listenerClassNames) {
1961 listenersList.add((ModelListener<Country>)InstanceFactory.newInstance(
1962 getClassLoader(), listenerClassName));
1963 }
1964
1965 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1966 }
1967 catch (Exception e) {
1968 _log.error(e);
1969 }
1970 }
1971 }
1972
1973 public void destroy() {
1974 EntityCacheUtil.removeCache(CountryImpl.class.getName());
1975 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1976 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1977 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1978 }
1979
1980 private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
1981 private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
1982 private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
1983 private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
1984 private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
1985 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
1986 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
1987 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1988 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1989 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1990 "number", "idd", "active"
1991 });
1992 private static Country _nullCountry = new CountryImpl() {
1993 @Override
1994 public Object clone() {
1995 return this;
1996 }
1997
1998 @Override
1999 public CacheModel<Country> toCacheModel() {
2000 return _nullCountryCacheModel;
2001 }
2002 };
2003
2004 private static CacheModel<Country> _nullCountryCacheModel = new CacheModel<Country>() {
2005 @Override
2006 public Country toEntityModel() {
2007 return _nullCountry;
2008 }
2009 };
2010 }