001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchCountryException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
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
051
063 public class CountryPersistenceImpl extends BasePersistenceImpl<Country>
064 implements CountryPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = CountryImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
076 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
079 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
082 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084 public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
085 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
086 FINDER_CLASS_NAME_ENTITY, "fetchByName",
087 new String[] { String.class.getName() },
088 CountryModelImpl.NAME_COLUMN_BITMASK);
089 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
090 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
092 new String[] { String.class.getName() });
093
094
102 public Country findByName(String name)
103 throws NoSuchCountryException, SystemException {
104 Country country = fetchByName(name);
105
106 if (country == null) {
107 StringBundler msg = new StringBundler(4);
108
109 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
110
111 msg.append("name=");
112 msg.append(name);
113
114 msg.append(StringPool.CLOSE_CURLY_BRACE);
115
116 if (_log.isWarnEnabled()) {
117 _log.warn(msg.toString());
118 }
119
120 throw new NoSuchCountryException(msg.toString());
121 }
122
123 return country;
124 }
125
126
133 public Country fetchByName(String name) throws SystemException {
134 return fetchByName(name, true);
135 }
136
137
145 public Country fetchByName(String name, boolean retrieveFromCache)
146 throws SystemException {
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 if (name == null) {
170 query.append(_FINDER_COLUMN_NAME_NAME_1);
171 }
172 else {
173 if (name.equals(StringPool.BLANK)) {
174 query.append(_FINDER_COLUMN_NAME_NAME_3);
175 }
176 else {
177 query.append(_FINDER_COLUMN_NAME_NAME_2);
178 }
179 }
180
181 String sql = query.toString();
182
183 Session session = null;
184
185 try {
186 session = openSession();
187
188 Query q = session.createQuery(sql);
189
190 QueryPos qPos = QueryPos.getInstance(q);
191
192 if (name != null) {
193 qPos.add(name);
194 }
195
196 List<Country> list = q.list();
197
198 if (list.isEmpty()) {
199 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
200 finderArgs, list);
201 }
202 else {
203 Country country = list.get(0);
204
205 result = country;
206
207 cacheResult(country);
208
209 if ((country.getName() == null) ||
210 !country.getName().equals(name)) {
211 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
212 finderArgs, country);
213 }
214 }
215 }
216 catch (Exception e) {
217 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
218 finderArgs);
219
220 throw processException(e);
221 }
222 finally {
223 closeSession(session);
224 }
225 }
226
227 if (result instanceof List<?>) {
228 return null;
229 }
230 else {
231 return (Country)result;
232 }
233 }
234
235
242 public Country removeByName(String name)
243 throws NoSuchCountryException, SystemException {
244 Country country = findByName(name);
245
246 return remove(country);
247 }
248
249
256 public int countByName(String name) throws SystemException {
257 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
258
259 Object[] finderArgs = new Object[] { name };
260
261 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
262 this);
263
264 if (count == null) {
265 StringBundler query = new StringBundler(2);
266
267 query.append(_SQL_COUNT_COUNTRY_WHERE);
268
269 if (name == null) {
270 query.append(_FINDER_COLUMN_NAME_NAME_1);
271 }
272 else {
273 if (name.equals(StringPool.BLANK)) {
274 query.append(_FINDER_COLUMN_NAME_NAME_3);
275 }
276 else {
277 query.append(_FINDER_COLUMN_NAME_NAME_2);
278 }
279 }
280
281 String sql = query.toString();
282
283 Session session = null;
284
285 try {
286 session = openSession();
287
288 Query q = session.createQuery(sql);
289
290 QueryPos qPos = QueryPos.getInstance(q);
291
292 if (name != null) {
293 qPos.add(name);
294 }
295
296 count = (Long)q.uniqueResult();
297
298 FinderCacheUtil.putResult(finderPath, finderArgs, count);
299 }
300 catch (Exception e) {
301 FinderCacheUtil.removeResult(finderPath, finderArgs);
302
303 throw processException(e);
304 }
305 finally {
306 closeSession(session);
307 }
308 }
309
310 return count.intValue();
311 }
312
313 private static final String _FINDER_COLUMN_NAME_NAME_1 = "country.name IS NULL";
314 private static final String _FINDER_COLUMN_NAME_NAME_2 = "country.name = ?";
315 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(country.name IS NULL OR country.name = ?)";
316 public static final FinderPath FINDER_PATH_FETCH_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
317 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
318 FINDER_CLASS_NAME_ENTITY, "fetchByA2",
319 new String[] { String.class.getName() },
320 CountryModelImpl.A2_COLUMN_BITMASK);
321 public static final FinderPath FINDER_PATH_COUNT_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
322 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
323 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA2",
324 new String[] { String.class.getName() });
325
326
334 public Country findByA2(String a2)
335 throws NoSuchCountryException, SystemException {
336 Country country = fetchByA2(a2);
337
338 if (country == null) {
339 StringBundler msg = new StringBundler(4);
340
341 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
342
343 msg.append("a2=");
344 msg.append(a2);
345
346 msg.append(StringPool.CLOSE_CURLY_BRACE);
347
348 if (_log.isWarnEnabled()) {
349 _log.warn(msg.toString());
350 }
351
352 throw new NoSuchCountryException(msg.toString());
353 }
354
355 return country;
356 }
357
358
365 public Country fetchByA2(String a2) throws SystemException {
366 return fetchByA2(a2, true);
367 }
368
369
377 public Country fetchByA2(String a2, boolean retrieveFromCache)
378 throws SystemException {
379 Object[] finderArgs = new Object[] { a2 };
380
381 Object result = null;
382
383 if (retrieveFromCache) {
384 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A2,
385 finderArgs, this);
386 }
387
388 if (result instanceof Country) {
389 Country country = (Country)result;
390
391 if (!Validator.equals(a2, country.getA2())) {
392 result = null;
393 }
394 }
395
396 if (result == null) {
397 StringBundler query = new StringBundler(3);
398
399 query.append(_SQL_SELECT_COUNTRY_WHERE);
400
401 if (a2 == null) {
402 query.append(_FINDER_COLUMN_A2_A2_1);
403 }
404 else {
405 if (a2.equals(StringPool.BLANK)) {
406 query.append(_FINDER_COLUMN_A2_A2_3);
407 }
408 else {
409 query.append(_FINDER_COLUMN_A2_A2_2);
410 }
411 }
412
413 String sql = query.toString();
414
415 Session session = null;
416
417 try {
418 session = openSession();
419
420 Query q = session.createQuery(sql);
421
422 QueryPos qPos = QueryPos.getInstance(q);
423
424 if (a2 != null) {
425 qPos.add(a2);
426 }
427
428 List<Country> list = q.list();
429
430 if (list.isEmpty()) {
431 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
432 finderArgs, list);
433 }
434 else {
435 Country country = list.get(0);
436
437 result = country;
438
439 cacheResult(country);
440
441 if ((country.getA2() == null) ||
442 !country.getA2().equals(a2)) {
443 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
444 finderArgs, country);
445 }
446 }
447 }
448 catch (Exception e) {
449 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, finderArgs);
450
451 throw processException(e);
452 }
453 finally {
454 closeSession(session);
455 }
456 }
457
458 if (result instanceof List<?>) {
459 return null;
460 }
461 else {
462 return (Country)result;
463 }
464 }
465
466
473 public Country removeByA2(String a2)
474 throws NoSuchCountryException, SystemException {
475 Country country = findByA2(a2);
476
477 return remove(country);
478 }
479
480
487 public int countByA2(String a2) throws SystemException {
488 FinderPath finderPath = FINDER_PATH_COUNT_BY_A2;
489
490 Object[] finderArgs = new Object[] { a2 };
491
492 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
493 this);
494
495 if (count == null) {
496 StringBundler query = new StringBundler(2);
497
498 query.append(_SQL_COUNT_COUNTRY_WHERE);
499
500 if (a2 == null) {
501 query.append(_FINDER_COLUMN_A2_A2_1);
502 }
503 else {
504 if (a2.equals(StringPool.BLANK)) {
505 query.append(_FINDER_COLUMN_A2_A2_3);
506 }
507 else {
508 query.append(_FINDER_COLUMN_A2_A2_2);
509 }
510 }
511
512 String sql = query.toString();
513
514 Session session = null;
515
516 try {
517 session = openSession();
518
519 Query q = session.createQuery(sql);
520
521 QueryPos qPos = QueryPos.getInstance(q);
522
523 if (a2 != null) {
524 qPos.add(a2);
525 }
526
527 count = (Long)q.uniqueResult();
528
529 FinderCacheUtil.putResult(finderPath, finderArgs, count);
530 }
531 catch (Exception e) {
532 FinderCacheUtil.removeResult(finderPath, finderArgs);
533
534 throw processException(e);
535 }
536 finally {
537 closeSession(session);
538 }
539 }
540
541 return count.intValue();
542 }
543
544 private static final String _FINDER_COLUMN_A2_A2_1 = "country.a2 IS NULL";
545 private static final String _FINDER_COLUMN_A2_A2_2 = "country.a2 = ?";
546 private static final String _FINDER_COLUMN_A2_A2_3 = "(country.a2 IS NULL OR country.a2 = ?)";
547 public static final FinderPath FINDER_PATH_FETCH_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
548 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
549 FINDER_CLASS_NAME_ENTITY, "fetchByA3",
550 new String[] { String.class.getName() },
551 CountryModelImpl.A3_COLUMN_BITMASK);
552 public static final FinderPath FINDER_PATH_COUNT_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
553 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
554 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA3",
555 new String[] { String.class.getName() });
556
557
565 public Country findByA3(String a3)
566 throws NoSuchCountryException, SystemException {
567 Country country = fetchByA3(a3);
568
569 if (country == null) {
570 StringBundler msg = new StringBundler(4);
571
572 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
573
574 msg.append("a3=");
575 msg.append(a3);
576
577 msg.append(StringPool.CLOSE_CURLY_BRACE);
578
579 if (_log.isWarnEnabled()) {
580 _log.warn(msg.toString());
581 }
582
583 throw new NoSuchCountryException(msg.toString());
584 }
585
586 return country;
587 }
588
589
596 public Country fetchByA3(String a3) throws SystemException {
597 return fetchByA3(a3, true);
598 }
599
600
608 public Country fetchByA3(String a3, boolean retrieveFromCache)
609 throws SystemException {
610 Object[] finderArgs = new Object[] { a3 };
611
612 Object result = null;
613
614 if (retrieveFromCache) {
615 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
616 finderArgs, this);
617 }
618
619 if (result instanceof Country) {
620 Country country = (Country)result;
621
622 if (!Validator.equals(a3, country.getA3())) {
623 result = null;
624 }
625 }
626
627 if (result == null) {
628 StringBundler query = new StringBundler(3);
629
630 query.append(_SQL_SELECT_COUNTRY_WHERE);
631
632 if (a3 == null) {
633 query.append(_FINDER_COLUMN_A3_A3_1);
634 }
635 else {
636 if (a3.equals(StringPool.BLANK)) {
637 query.append(_FINDER_COLUMN_A3_A3_3);
638 }
639 else {
640 query.append(_FINDER_COLUMN_A3_A3_2);
641 }
642 }
643
644 String sql = query.toString();
645
646 Session session = null;
647
648 try {
649 session = openSession();
650
651 Query q = session.createQuery(sql);
652
653 QueryPos qPos = QueryPos.getInstance(q);
654
655 if (a3 != null) {
656 qPos.add(a3);
657 }
658
659 List<Country> list = q.list();
660
661 if (list.isEmpty()) {
662 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
663 finderArgs, list);
664 }
665 else {
666 Country country = list.get(0);
667
668 result = country;
669
670 cacheResult(country);
671
672 if ((country.getA3() == null) ||
673 !country.getA3().equals(a3)) {
674 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
675 finderArgs, country);
676 }
677 }
678 }
679 catch (Exception e) {
680 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, finderArgs);
681
682 throw processException(e);
683 }
684 finally {
685 closeSession(session);
686 }
687 }
688
689 if (result instanceof List<?>) {
690 return null;
691 }
692 else {
693 return (Country)result;
694 }
695 }
696
697
704 public Country removeByA3(String a3)
705 throws NoSuchCountryException, SystemException {
706 Country country = findByA3(a3);
707
708 return remove(country);
709 }
710
711
718 public int countByA3(String a3) throws SystemException {
719 FinderPath finderPath = FINDER_PATH_COUNT_BY_A3;
720
721 Object[] finderArgs = new Object[] { a3 };
722
723 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
724 this);
725
726 if (count == null) {
727 StringBundler query = new StringBundler(2);
728
729 query.append(_SQL_COUNT_COUNTRY_WHERE);
730
731 if (a3 == null) {
732 query.append(_FINDER_COLUMN_A3_A3_1);
733 }
734 else {
735 if (a3.equals(StringPool.BLANK)) {
736 query.append(_FINDER_COLUMN_A3_A3_3);
737 }
738 else {
739 query.append(_FINDER_COLUMN_A3_A3_2);
740 }
741 }
742
743 String sql = query.toString();
744
745 Session session = null;
746
747 try {
748 session = openSession();
749
750 Query q = session.createQuery(sql);
751
752 QueryPos qPos = QueryPos.getInstance(q);
753
754 if (a3 != null) {
755 qPos.add(a3);
756 }
757
758 count = (Long)q.uniqueResult();
759
760 FinderCacheUtil.putResult(finderPath, finderArgs, count);
761 }
762 catch (Exception e) {
763 FinderCacheUtil.removeResult(finderPath, finderArgs);
764
765 throw processException(e);
766 }
767 finally {
768 closeSession(session);
769 }
770 }
771
772 return count.intValue();
773 }
774
775 private static final String _FINDER_COLUMN_A3_A3_1 = "country.a3 IS NULL";
776 private static final String _FINDER_COLUMN_A3_A3_2 = "country.a3 = ?";
777 private static final String _FINDER_COLUMN_A3_A3_3 = "(country.a3 IS NULL OR country.a3 = ?)";
778 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
779 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
780 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByActive",
781 new String[] {
782 Boolean.class.getName(),
783
784 Integer.class.getName(), Integer.class.getName(),
785 OrderByComparator.class.getName()
786 });
787 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
788 new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
789 CountryModelImpl.FINDER_CACHE_ENABLED, CountryImpl.class,
790 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActive",
791 new String[] { Boolean.class.getName() },
792 CountryModelImpl.ACTIVE_COLUMN_BITMASK |
793 CountryModelImpl.NAME_COLUMN_BITMASK);
794 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
795 CountryModelImpl.FINDER_CACHE_ENABLED, Long.class,
796 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
797 new String[] { Boolean.class.getName() });
798
799
806 public List<Country> findByActive(boolean active) throws SystemException {
807 return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
808 }
809
810
823 public List<Country> findByActive(boolean active, int start, int end)
824 throws SystemException {
825 return findByActive(active, start, end, null);
826 }
827
828
842 public List<Country> findByActive(boolean active, int start, int end,
843 OrderByComparator orderByComparator) throws SystemException {
844 boolean pagination = true;
845 FinderPath finderPath = null;
846 Object[] finderArgs = null;
847
848 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
849 (orderByComparator == null)) {
850 pagination = false;
851 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
852 finderArgs = new Object[] { active };
853 }
854 else {
855 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
856 finderArgs = new Object[] { active, start, end, orderByComparator };
857 }
858
859 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
860 finderArgs, this);
861
862 if ((list != null) && !list.isEmpty()) {
863 for (Country country : list) {
864 if ((active != country.getActive())) {
865 list = null;
866
867 break;
868 }
869 }
870 }
871
872 if (list == null) {
873 StringBundler query = null;
874
875 if (orderByComparator != null) {
876 query = new StringBundler(3 +
877 (orderByComparator.getOrderByFields().length * 3));
878 }
879 else {
880 query = new StringBundler(3);
881 }
882
883 query.append(_SQL_SELECT_COUNTRY_WHERE);
884
885 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
886
887 if (orderByComparator != null) {
888 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
889 orderByComparator);
890 }
891 else
892 if (pagination) {
893 query.append(CountryModelImpl.ORDER_BY_JPQL);
894 }
895
896 String sql = query.toString();
897
898 Session session = null;
899
900 try {
901 session = openSession();
902
903 Query q = session.createQuery(sql);
904
905 QueryPos qPos = QueryPos.getInstance(q);
906
907 qPos.add(active);
908
909 if (!pagination) {
910 list = (List<Country>)QueryUtil.list(q, getDialect(),
911 start, end, false);
912
913 Collections.sort(list);
914
915 list = new UnmodifiableList<Country>(list);
916 }
917 else {
918 list = (List<Country>)QueryUtil.list(q, getDialect(),
919 start, end);
920 }
921
922 cacheResult(list);
923
924 FinderCacheUtil.putResult(finderPath, finderArgs, list);
925 }
926 catch (Exception e) {
927 FinderCacheUtil.removeResult(finderPath, finderArgs);
928
929 throw processException(e);
930 }
931 finally {
932 closeSession(session);
933 }
934 }
935
936 return list;
937 }
938
939
948 public Country findByActive_First(boolean active,
949 OrderByComparator orderByComparator)
950 throws NoSuchCountryException, SystemException {
951 Country country = fetchByActive_First(active, orderByComparator);
952
953 if (country != null) {
954 return country;
955 }
956
957 StringBundler msg = new StringBundler(4);
958
959 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
960
961 msg.append("active=");
962 msg.append(active);
963
964 msg.append(StringPool.CLOSE_CURLY_BRACE);
965
966 throw new NoSuchCountryException(msg.toString());
967 }
968
969
977 public Country fetchByActive_First(boolean active,
978 OrderByComparator orderByComparator) throws SystemException {
979 List<Country> list = findByActive(active, 0, 1, orderByComparator);
980
981 if (!list.isEmpty()) {
982 return list.get(0);
983 }
984
985 return null;
986 }
987
988
997 public Country findByActive_Last(boolean active,
998 OrderByComparator orderByComparator)
999 throws NoSuchCountryException, SystemException {
1000 Country country = fetchByActive_Last(active, orderByComparator);
1001
1002 if (country != null) {
1003 return country;
1004 }
1005
1006 StringBundler msg = new StringBundler(4);
1007
1008 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1009
1010 msg.append("active=");
1011 msg.append(active);
1012
1013 msg.append(StringPool.CLOSE_CURLY_BRACE);
1014
1015 throw new NoSuchCountryException(msg.toString());
1016 }
1017
1018
1026 public Country fetchByActive_Last(boolean active,
1027 OrderByComparator orderByComparator) throws SystemException {
1028 int count = countByActive(active);
1029
1030 List<Country> list = findByActive(active, count - 1, count,
1031 orderByComparator);
1032
1033 if (!list.isEmpty()) {
1034 return list.get(0);
1035 }
1036
1037 return null;
1038 }
1039
1040
1050 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
1051 OrderByComparator orderByComparator)
1052 throws NoSuchCountryException, SystemException {
1053 Country country = findByPrimaryKey(countryId);
1054
1055 Session session = null;
1056
1057 try {
1058 session = openSession();
1059
1060 Country[] array = new CountryImpl[3];
1061
1062 array[0] = getByActive_PrevAndNext(session, country, active,
1063 orderByComparator, true);
1064
1065 array[1] = country;
1066
1067 array[2] = getByActive_PrevAndNext(session, country, active,
1068 orderByComparator, false);
1069
1070 return array;
1071 }
1072 catch (Exception e) {
1073 throw processException(e);
1074 }
1075 finally {
1076 closeSession(session);
1077 }
1078 }
1079
1080 protected Country getByActive_PrevAndNext(Session session, Country country,
1081 boolean active, OrderByComparator orderByComparator, boolean previous) {
1082 StringBundler query = null;
1083
1084 if (orderByComparator != null) {
1085 query = new StringBundler(6 +
1086 (orderByComparator.getOrderByFields().length * 6));
1087 }
1088 else {
1089 query = new StringBundler(3);
1090 }
1091
1092 query.append(_SQL_SELECT_COUNTRY_WHERE);
1093
1094 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1095
1096 if (orderByComparator != null) {
1097 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1098
1099 if (orderByConditionFields.length > 0) {
1100 query.append(WHERE_AND);
1101 }
1102
1103 for (int i = 0; i < orderByConditionFields.length; i++) {
1104 query.append(_ORDER_BY_ENTITY_ALIAS);
1105 query.append(orderByConditionFields[i]);
1106
1107 if ((i + 1) < orderByConditionFields.length) {
1108 if (orderByComparator.isAscending() ^ previous) {
1109 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1110 }
1111 else {
1112 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1113 }
1114 }
1115 else {
1116 if (orderByComparator.isAscending() ^ previous) {
1117 query.append(WHERE_GREATER_THAN);
1118 }
1119 else {
1120 query.append(WHERE_LESSER_THAN);
1121 }
1122 }
1123 }
1124
1125 query.append(ORDER_BY_CLAUSE);
1126
1127 String[] orderByFields = orderByComparator.getOrderByFields();
1128
1129 for (int i = 0; i < orderByFields.length; i++) {
1130 query.append(_ORDER_BY_ENTITY_ALIAS);
1131 query.append(orderByFields[i]);
1132
1133 if ((i + 1) < orderByFields.length) {
1134 if (orderByComparator.isAscending() ^ previous) {
1135 query.append(ORDER_BY_ASC_HAS_NEXT);
1136 }
1137 else {
1138 query.append(ORDER_BY_DESC_HAS_NEXT);
1139 }
1140 }
1141 else {
1142 if (orderByComparator.isAscending() ^ previous) {
1143 query.append(ORDER_BY_ASC);
1144 }
1145 else {
1146 query.append(ORDER_BY_DESC);
1147 }
1148 }
1149 }
1150 }
1151 else {
1152 query.append(CountryModelImpl.ORDER_BY_JPQL);
1153 }
1154
1155 String sql = query.toString();
1156
1157 Query q = session.createQuery(sql);
1158
1159 q.setFirstResult(0);
1160 q.setMaxResults(2);
1161
1162 QueryPos qPos = QueryPos.getInstance(q);
1163
1164 qPos.add(active);
1165
1166 if (orderByComparator != null) {
1167 Object[] values = orderByComparator.getOrderByConditionValues(country);
1168
1169 for (Object value : values) {
1170 qPos.add(value);
1171 }
1172 }
1173
1174 List<Country> list = q.list();
1175
1176 if (list.size() == 2) {
1177 return list.get(1);
1178 }
1179 else {
1180 return null;
1181 }
1182 }
1183
1184
1190 public void removeByActive(boolean active) throws SystemException {
1191 for (Country country : findByActive(active, QueryUtil.ALL_POS,
1192 QueryUtil.ALL_POS, null)) {
1193 remove(country);
1194 }
1195 }
1196
1197
1204 public int countByActive(boolean active) throws SystemException {
1205 FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1206
1207 Object[] finderArgs = new Object[] { active };
1208
1209 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1210 this);
1211
1212 if (count == null) {
1213 StringBundler query = new StringBundler(2);
1214
1215 query.append(_SQL_COUNT_COUNTRY_WHERE);
1216
1217 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1218
1219 String sql = query.toString();
1220
1221 Session session = null;
1222
1223 try {
1224 session = openSession();
1225
1226 Query q = session.createQuery(sql);
1227
1228 QueryPos qPos = QueryPos.getInstance(q);
1229
1230 qPos.add(active);
1231
1232 count = (Long)q.uniqueResult();
1233
1234 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1235 }
1236 catch (Exception e) {
1237 FinderCacheUtil.removeResult(finderPath, finderArgs);
1238
1239 throw processException(e);
1240 }
1241 finally {
1242 closeSession(session);
1243 }
1244 }
1245
1246 return count.intValue();
1247 }
1248
1249 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "country.active = ?";
1250
1251
1256 public void cacheResult(Country country) {
1257 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1258 CountryImpl.class, country.getPrimaryKey(), country);
1259
1260 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
1261 new Object[] { country.getName() }, country);
1262
1263 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
1264 new Object[] { country.getA2() }, country);
1265
1266 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
1267 new Object[] { country.getA3() }, country);
1268
1269 country.resetOriginalValues();
1270 }
1271
1272
1277 public void cacheResult(List<Country> countries) {
1278 for (Country country : countries) {
1279 if (EntityCacheUtil.getResult(
1280 CountryModelImpl.ENTITY_CACHE_ENABLED,
1281 CountryImpl.class, country.getPrimaryKey()) == null) {
1282 cacheResult(country);
1283 }
1284 else {
1285 country.resetOriginalValues();
1286 }
1287 }
1288 }
1289
1290
1297 @Override
1298 public void clearCache() {
1299 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1300 CacheRegistryUtil.clear(CountryImpl.class.getName());
1301 }
1302
1303 EntityCacheUtil.clearCache(CountryImpl.class.getName());
1304
1305 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1307 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1308 }
1309
1310
1317 @Override
1318 public void clearCache(Country country) {
1319 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1320 CountryImpl.class, country.getPrimaryKey());
1321
1322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1323 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1324
1325 clearUniqueFindersCache(country);
1326 }
1327
1328 @Override
1329 public void clearCache(List<Country> countries) {
1330 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1331 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1332
1333 for (Country country : countries) {
1334 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1335 CountryImpl.class, country.getPrimaryKey());
1336
1337 clearUniqueFindersCache(country);
1338 }
1339 }
1340
1341 protected void cacheUniqueFindersCache(Country country) {
1342 if (country.isNew()) {
1343 Object[] args = new Object[] { country.getName() };
1344
1345 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1346 Long.valueOf(1));
1347 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args, country);
1348
1349 args = new Object[] { country.getA2() };
1350
1351 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1352 Long.valueOf(1));
1353 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1354
1355 args = new Object[] { country.getA3() };
1356
1357 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1358 Long.valueOf(1));
1359 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1360 }
1361 else {
1362 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1363
1364 if ((countryModelImpl.getColumnBitmask() &
1365 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1366 Object[] args = new Object[] { country.getName() };
1367
1368 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME, args,
1369 Long.valueOf(1));
1370 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME, args,
1371 country);
1372 }
1373
1374 if ((countryModelImpl.getColumnBitmask() &
1375 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1376 Object[] args = new Object[] { country.getA2() };
1377
1378 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, args,
1379 Long.valueOf(1));
1380 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2, args, country);
1381 }
1382
1383 if ((countryModelImpl.getColumnBitmask() &
1384 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1385 Object[] args = new Object[] { country.getA3() };
1386
1387 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, args,
1388 Long.valueOf(1));
1389 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3, args, country);
1390 }
1391 }
1392 }
1393
1394 protected void clearUniqueFindersCache(Country country) {
1395 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1396
1397 Object[] args = new Object[] { country.getName() };
1398
1399 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1400 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1401
1402 if ((countryModelImpl.getColumnBitmask() &
1403 FINDER_PATH_FETCH_BY_NAME.getColumnBitmask()) != 0) {
1404 args = new Object[] { countryModelImpl.getOriginalName() };
1405
1406 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1407 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME, args);
1408 }
1409
1410 args = new Object[] { country.getA2() };
1411
1412 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1413 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1414
1415 if ((countryModelImpl.getColumnBitmask() &
1416 FINDER_PATH_FETCH_BY_A2.getColumnBitmask()) != 0) {
1417 args = new Object[] { countryModelImpl.getOriginalA2() };
1418
1419 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A2, args);
1420 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2, args);
1421 }
1422
1423 args = new Object[] { country.getA3() };
1424
1425 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1426 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1427
1428 if ((countryModelImpl.getColumnBitmask() &
1429 FINDER_PATH_FETCH_BY_A3.getColumnBitmask()) != 0) {
1430 args = new Object[] { countryModelImpl.getOriginalA3() };
1431
1432 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A3, args);
1433 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3, args);
1434 }
1435 }
1436
1437
1443 public Country create(long countryId) {
1444 Country country = new CountryImpl();
1445
1446 country.setNew(true);
1447 country.setPrimaryKey(countryId);
1448
1449 return country;
1450 }
1451
1452
1460 public Country remove(long countryId)
1461 throws NoSuchCountryException, SystemException {
1462 return remove(Long.valueOf(countryId));
1463 }
1464
1465
1473 @Override
1474 public Country remove(Serializable primaryKey)
1475 throws NoSuchCountryException, SystemException {
1476 Session session = null;
1477
1478 try {
1479 session = openSession();
1480
1481 Country country = (Country)session.get(CountryImpl.class, primaryKey);
1482
1483 if (country == null) {
1484 if (_log.isWarnEnabled()) {
1485 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1486 }
1487
1488 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1489 primaryKey);
1490 }
1491
1492 return remove(country);
1493 }
1494 catch (NoSuchCountryException nsee) {
1495 throw nsee;
1496 }
1497 catch (Exception e) {
1498 throw processException(e);
1499 }
1500 finally {
1501 closeSession(session);
1502 }
1503 }
1504
1505 @Override
1506 protected Country removeImpl(Country country) throws SystemException {
1507 country = toUnwrappedModel(country);
1508
1509 Session session = null;
1510
1511 try {
1512 session = openSession();
1513
1514 if (!session.contains(country)) {
1515 country = (Country)session.get(CountryImpl.class,
1516 country.getPrimaryKeyObj());
1517 }
1518
1519 if (country != null) {
1520 session.delete(country);
1521 }
1522 }
1523 catch (Exception e) {
1524 throw processException(e);
1525 }
1526 finally {
1527 closeSession(session);
1528 }
1529
1530 if (country != null) {
1531 clearCache(country);
1532 }
1533
1534 return country;
1535 }
1536
1537 @Override
1538 public Country updateImpl(com.liferay.portal.model.Country country)
1539 throws SystemException {
1540 country = toUnwrappedModel(country);
1541
1542 boolean isNew = country.isNew();
1543
1544 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
1545
1546 Session session = null;
1547
1548 try {
1549 session = openSession();
1550
1551 if (country.isNew()) {
1552 session.save(country);
1553
1554 country.setNew(false);
1555 }
1556 else {
1557 session.merge(country);
1558 }
1559 }
1560 catch (Exception e) {
1561 throw processException(e);
1562 }
1563 finally {
1564 closeSession(session);
1565 }
1566
1567 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1568
1569 if (isNew || !CountryModelImpl.COLUMN_BITMASK_ENABLED) {
1570 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1571 }
1572
1573 else {
1574 if ((countryModelImpl.getColumnBitmask() &
1575 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
1576 Object[] args = new Object[] {
1577 Boolean.valueOf(countryModelImpl.getOriginalActive())
1578 };
1579
1580 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1581 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1582 args);
1583
1584 args = new Object[] {
1585 Boolean.valueOf(countryModelImpl.getActive())
1586 };
1587
1588 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
1589 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
1590 args);
1591 }
1592 }
1593
1594 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1595 CountryImpl.class, country.getPrimaryKey(), country);
1596
1597 clearUniqueFindersCache(country);
1598 cacheUniqueFindersCache(country);
1599
1600 return country;
1601 }
1602
1603 protected Country toUnwrappedModel(Country country) {
1604 if (country instanceof CountryImpl) {
1605 return country;
1606 }
1607
1608 CountryImpl countryImpl = new CountryImpl();
1609
1610 countryImpl.setNew(country.isNew());
1611 countryImpl.setPrimaryKey(country.getPrimaryKey());
1612
1613 countryImpl.setCountryId(country.getCountryId());
1614 countryImpl.setName(country.getName());
1615 countryImpl.setA2(country.getA2());
1616 countryImpl.setA3(country.getA3());
1617 countryImpl.setNumber(country.getNumber());
1618 countryImpl.setIdd(country.getIdd());
1619 countryImpl.setZipRequired(country.isZipRequired());
1620 countryImpl.setActive(country.isActive());
1621
1622 return countryImpl;
1623 }
1624
1625
1633 @Override
1634 public Country findByPrimaryKey(Serializable primaryKey)
1635 throws NoSuchModelException, SystemException {
1636 return findByPrimaryKey(((Long)primaryKey).longValue());
1637 }
1638
1639
1647 public Country findByPrimaryKey(long countryId)
1648 throws NoSuchCountryException, SystemException {
1649 Country country = fetchByPrimaryKey(countryId);
1650
1651 if (country == null) {
1652 if (_log.isWarnEnabled()) {
1653 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + countryId);
1654 }
1655
1656 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1657 countryId);
1658 }
1659
1660 return country;
1661 }
1662
1663
1670 @Override
1671 public Country fetchByPrimaryKey(Serializable primaryKey)
1672 throws SystemException {
1673 return fetchByPrimaryKey(((Long)primaryKey).longValue());
1674 }
1675
1676
1683 public Country fetchByPrimaryKey(long countryId) throws SystemException {
1684 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1685 CountryImpl.class, countryId);
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,
1698 Long.valueOf(countryId));
1699
1700 if (country != null) {
1701 cacheResult(country);
1702 }
1703 else {
1704 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1705 CountryImpl.class, countryId, _nullCountry);
1706 }
1707 }
1708 catch (Exception e) {
1709 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
1710 CountryImpl.class, countryId);
1711
1712 throw processException(e);
1713 }
1714 finally {
1715 closeSession(session);
1716 }
1717 }
1718
1719 return country;
1720 }
1721
1722
1728 public List<Country> findAll() throws SystemException {
1729 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1730 }
1731
1732
1744 public List<Country> findAll(int start, int end) throws SystemException {
1745 return findAll(start, end, null);
1746 }
1747
1748
1761 public List<Country> findAll(int start, int end,
1762 OrderByComparator orderByComparator) throws SystemException {
1763 boolean pagination = true;
1764 FinderPath finderPath = null;
1765 Object[] finderArgs = null;
1766
1767 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1768 (orderByComparator == null)) {
1769 pagination = false;
1770 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1771 finderArgs = FINDER_ARGS_EMPTY;
1772 }
1773 else {
1774 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1775 finderArgs = new Object[] { start, end, orderByComparator };
1776 }
1777
1778 List<Country> list = (List<Country>)FinderCacheUtil.getResult(finderPath,
1779 finderArgs, this);
1780
1781 if (list == null) {
1782 StringBundler query = null;
1783 String sql = null;
1784
1785 if (orderByComparator != null) {
1786 query = new StringBundler(2 +
1787 (orderByComparator.getOrderByFields().length * 3));
1788
1789 query.append(_SQL_SELECT_COUNTRY);
1790
1791 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1792 orderByComparator);
1793
1794 sql = query.toString();
1795 }
1796 else {
1797 sql = _SQL_SELECT_COUNTRY;
1798
1799 if (pagination) {
1800 sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
1801 }
1802 }
1803
1804 Session session = null;
1805
1806 try {
1807 session = openSession();
1808
1809 Query q = session.createQuery(sql);
1810
1811 if (!pagination) {
1812 list = (List<Country>)QueryUtil.list(q, getDialect(),
1813 start, end, false);
1814
1815 Collections.sort(list);
1816
1817 list = new UnmodifiableList<Country>(list);
1818 }
1819 else {
1820 list = (List<Country>)QueryUtil.list(q, getDialect(),
1821 start, end);
1822 }
1823
1824 cacheResult(list);
1825
1826 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1827 }
1828 catch (Exception e) {
1829 FinderCacheUtil.removeResult(finderPath, finderArgs);
1830
1831 throw processException(e);
1832 }
1833 finally {
1834 closeSession(session);
1835 }
1836 }
1837
1838 return list;
1839 }
1840
1841
1846 public void removeAll() throws SystemException {
1847 for (Country country : findAll()) {
1848 remove(country);
1849 }
1850 }
1851
1852
1858 public int countAll() throws SystemException {
1859 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1860 FINDER_ARGS_EMPTY, this);
1861
1862 if (count == null) {
1863 Session session = null;
1864
1865 try {
1866 session = openSession();
1867
1868 Query q = session.createQuery(_SQL_COUNT_COUNTRY);
1869
1870 count = (Long)q.uniqueResult();
1871
1872 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1873 FINDER_ARGS_EMPTY, count);
1874 }
1875 catch (Exception e) {
1876 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1877 FINDER_ARGS_EMPTY);
1878
1879 throw processException(e);
1880 }
1881 finally {
1882 closeSession(session);
1883 }
1884 }
1885
1886 return count.intValue();
1887 }
1888
1889
1892 public void afterPropertiesSet() {
1893 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1894 com.liferay.portal.util.PropsUtil.get(
1895 "value.object.listener.com.liferay.portal.model.Country")));
1896
1897 if (listenerClassNames.length > 0) {
1898 try {
1899 List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1900
1901 for (String listenerClassName : listenerClassNames) {
1902 listenersList.add((ModelListener<Country>)InstanceFactory.newInstance(
1903 listenerClassName));
1904 }
1905
1906 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1907 }
1908 catch (Exception e) {
1909 _log.error(e);
1910 }
1911 }
1912 }
1913
1914 public void destroy() {
1915 EntityCacheUtil.removeCache(CountryImpl.class.getName());
1916 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1917 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1918 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1919 }
1920
1921 private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
1922 private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
1923 private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
1924 private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
1925 private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
1926 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
1927 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
1928 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1929 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1930 private static Country _nullCountry = new CountryImpl() {
1931 @Override
1932 public Object clone() {
1933 return this;
1934 }
1935
1936 @Override
1937 public CacheModel<Country> toCacheModel() {
1938 return _nullCountryCacheModel;
1939 }
1940 };
1941
1942 private static CacheModel<Country> _nullCountryCacheModel = new CacheModel<Country>() {
1943 public Country toEntityModel() {
1944 return _nullCountry;
1945 }
1946 };
1947 }