1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchCountryException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.annotation.BeanReference;
28 import com.liferay.portal.kernel.cache.CacheRegistry;
29 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32 import com.liferay.portal.kernel.dao.orm.FinderPath;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryPos;
35 import com.liferay.portal.kernel.dao.orm.QueryUtil;
36 import com.liferay.portal.kernel.dao.orm.Session;
37 import com.liferay.portal.kernel.log.Log;
38 import com.liferay.portal.kernel.log.LogFactoryUtil;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.OrderByComparator;
41 import com.liferay.portal.kernel.util.StringPool;
42 import com.liferay.portal.kernel.util.StringUtil;
43 import com.liferay.portal.kernel.util.Validator;
44 import com.liferay.portal.model.Country;
45 import com.liferay.portal.model.ModelListener;
46 import com.liferay.portal.model.impl.CountryImpl;
47 import com.liferay.portal.model.impl.CountryModelImpl;
48 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.List;
53
54
67 public class CountryPersistenceImpl extends BasePersistenceImpl
68 implements CountryPersistence {
69 public static final String FINDER_CLASS_NAME_ENTITY = CountryImpl.class.getName();
70 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
71 ".List";
72 public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
73 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
74 "fetchByName", new String[] { String.class.getName() });
75 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
76 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
77 "countByName", new String[] { String.class.getName() });
78 public static final FinderPath FINDER_PATH_FETCH_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
79 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
80 "fetchByA2", new String[] { String.class.getName() });
81 public static final FinderPath FINDER_PATH_COUNT_BY_A2 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
82 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
83 "countByA2", new String[] { String.class.getName() });
84 public static final FinderPath FINDER_PATH_FETCH_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
85 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
86 "fetchByA3", new String[] { String.class.getName() });
87 public static final FinderPath FINDER_PATH_COUNT_BY_A3 = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
88 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89 "countByA3", new String[] { String.class.getName() });
90 public static final FinderPath FINDER_PATH_FIND_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
91 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92 "findByActive", new String[] { Boolean.class.getName() });
93 public static final FinderPath FINDER_PATH_FIND_BY_OBC_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
94 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95 "findByActive",
96 new String[] {
97 Boolean.class.getName(),
98
99 "java.lang.Integer", "java.lang.Integer",
100 "com.liferay.portal.kernel.util.OrderByComparator"
101 });
102 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
103 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "countByActive", new String[] { Boolean.class.getName() });
105 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
106 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "findAll", new String[0]);
108 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CountryModelImpl.ENTITY_CACHE_ENABLED,
109 CountryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110 "countAll", new String[0]);
111
112 public void cacheResult(Country country) {
113 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
114 CountryImpl.class, country.getPrimaryKey(), country);
115
116 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
117 new Object[] { country.getName() }, country);
118
119 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
120 new Object[] { country.getA2() }, country);
121
122 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
123 new Object[] { country.getA3() }, country);
124 }
125
126 public void cacheResult(List<Country> countries) {
127 for (Country country : countries) {
128 if (EntityCacheUtil.getResult(
129 CountryModelImpl.ENTITY_CACHE_ENABLED,
130 CountryImpl.class, country.getPrimaryKey(), this) == null) {
131 cacheResult(country);
132 }
133 }
134 }
135
136 public void clearCache() {
137 CacheRegistry.clear(CountryImpl.class.getName());
138 EntityCacheUtil.clearCache(CountryImpl.class.getName());
139 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
141 }
142
143 public Country create(long countryId) {
144 Country country = new CountryImpl();
145
146 country.setNew(true);
147 country.setPrimaryKey(countryId);
148
149 return country;
150 }
151
152 public Country remove(long countryId)
153 throws NoSuchCountryException, SystemException {
154 Session session = null;
155
156 try {
157 session = openSession();
158
159 Country country = (Country)session.get(CountryImpl.class,
160 new Long(countryId));
161
162 if (country == null) {
163 if (_log.isWarnEnabled()) {
164 _log.warn("No Country exists with the primary key " +
165 countryId);
166 }
167
168 throw new NoSuchCountryException(
169 "No Country exists with the primary key " + countryId);
170 }
171
172 return remove(country);
173 }
174 catch (NoSuchCountryException nsee) {
175 throw nsee;
176 }
177 catch (Exception e) {
178 throw processException(e);
179 }
180 finally {
181 closeSession(session);
182 }
183 }
184
185 public Country remove(Country country) throws SystemException {
186 for (ModelListener<Country> listener : listeners) {
187 listener.onBeforeRemove(country);
188 }
189
190 country = removeImpl(country);
191
192 for (ModelListener<Country> listener : listeners) {
193 listener.onAfterRemove(country);
194 }
195
196 return country;
197 }
198
199 protected Country removeImpl(Country country) throws SystemException {
200 Session session = null;
201
202 try {
203 session = openSession();
204
205 if (country.isCachedModel() || BatchSessionUtil.isEnabled()) {
206 Object staleObject = session.get(CountryImpl.class,
207 country.getPrimaryKeyObj());
208
209 if (staleObject != null) {
210 session.evict(staleObject);
211 }
212 }
213
214 session.delete(country);
215
216 session.flush();
217 }
218 catch (Exception e) {
219 throw processException(e);
220 }
221 finally {
222 closeSession(session);
223 }
224
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
226
227 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
228
229 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
230 new Object[] { countryModelImpl.getOriginalName() });
231
232 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2,
233 new Object[] { countryModelImpl.getOriginalA2() });
234
235 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3,
236 new Object[] { countryModelImpl.getOriginalA3() });
237
238 EntityCacheUtil.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
239 CountryImpl.class, country.getPrimaryKey());
240
241 return country;
242 }
243
244
247 public Country update(Country country) throws SystemException {
248 if (_log.isWarnEnabled()) {
249 _log.warn(
250 "Using the deprecated update(Country country) method. Use update(Country country, boolean merge) instead.");
251 }
252
253 return update(country, false);
254 }
255
256
268 public Country update(Country country, boolean merge)
269 throws SystemException {
270 boolean isNew = country.isNew();
271
272 for (ModelListener<Country> listener : listeners) {
273 if (isNew) {
274 listener.onBeforeCreate(country);
275 }
276 else {
277 listener.onBeforeUpdate(country);
278 }
279 }
280
281 country = updateImpl(country, merge);
282
283 for (ModelListener<Country> listener : listeners) {
284 if (isNew) {
285 listener.onAfterCreate(country);
286 }
287 else {
288 listener.onAfterUpdate(country);
289 }
290 }
291
292 return country;
293 }
294
295 public Country updateImpl(com.liferay.portal.model.Country country,
296 boolean merge) throws SystemException {
297 boolean isNew = country.isNew();
298
299 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
300
301 Session session = null;
302
303 try {
304 session = openSession();
305
306 BatchSessionUtil.update(session, country, merge);
307
308 country.setNew(false);
309 }
310 catch (Exception e) {
311 throw processException(e);
312 }
313 finally {
314 closeSession(session);
315 }
316
317 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
318
319 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
320 CountryImpl.class, country.getPrimaryKey(), country);
321
322 if (!isNew &&
323 (!Validator.equals(country.getName(),
324 countryModelImpl.getOriginalName()))) {
325 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
326 new Object[] { countryModelImpl.getOriginalName() });
327 }
328
329 if (isNew ||
330 (!Validator.equals(country.getName(),
331 countryModelImpl.getOriginalName()))) {
332 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
333 new Object[] { country.getName() }, country);
334 }
335
336 if (!isNew &&
337 (!Validator.equals(country.getA2(),
338 countryModelImpl.getOriginalA2()))) {
339 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2,
340 new Object[] { countryModelImpl.getOriginalA2() });
341 }
342
343 if (isNew ||
344 (!Validator.equals(country.getA2(),
345 countryModelImpl.getOriginalA2()))) {
346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
347 new Object[] { country.getA2() }, country);
348 }
349
350 if (!isNew &&
351 (!Validator.equals(country.getA3(),
352 countryModelImpl.getOriginalA3()))) {
353 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3,
354 new Object[] { countryModelImpl.getOriginalA3() });
355 }
356
357 if (isNew ||
358 (!Validator.equals(country.getA3(),
359 countryModelImpl.getOriginalA3()))) {
360 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
361 new Object[] { country.getA3() }, country);
362 }
363
364 return country;
365 }
366
367 public Country findByPrimaryKey(long countryId)
368 throws NoSuchCountryException, SystemException {
369 Country country = fetchByPrimaryKey(countryId);
370
371 if (country == null) {
372 if (_log.isWarnEnabled()) {
373 _log.warn("No Country exists with the primary key " +
374 countryId);
375 }
376
377 throw new NoSuchCountryException(
378 "No Country exists with the primary key " + countryId);
379 }
380
381 return country;
382 }
383
384 public Country fetchByPrimaryKey(long countryId) throws SystemException {
385 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
386 CountryImpl.class, countryId, this);
387
388 if (country == null) {
389 Session session = null;
390
391 try {
392 session = openSession();
393
394 country = (Country)session.get(CountryImpl.class,
395 new Long(countryId));
396 }
397 catch (Exception e) {
398 throw processException(e);
399 }
400 finally {
401 if (country != null) {
402 cacheResult(country);
403 }
404
405 closeSession(session);
406 }
407 }
408
409 return country;
410 }
411
412 public Country findByName(String name)
413 throws NoSuchCountryException, SystemException {
414 Country country = fetchByName(name);
415
416 if (country == null) {
417 StringBuilder msg = new StringBuilder();
418
419 msg.append("No Country exists with the key {");
420
421 msg.append("name=" + name);
422
423 msg.append(StringPool.CLOSE_CURLY_BRACE);
424
425 if (_log.isWarnEnabled()) {
426 _log.warn(msg.toString());
427 }
428
429 throw new NoSuchCountryException(msg.toString());
430 }
431
432 return country;
433 }
434
435 public Country fetchByName(String name) throws SystemException {
436 return fetchByName(name, true);
437 }
438
439 public Country fetchByName(String name, boolean retrieveFromCache)
440 throws SystemException {
441 Object[] finderArgs = new Object[] { name };
442
443 Object result = null;
444
445 if (retrieveFromCache) {
446 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
447 finderArgs, this);
448 }
449
450 if (result == null) {
451 Session session = null;
452
453 try {
454 session = openSession();
455
456 StringBuilder query = new StringBuilder();
457
458 query.append("SELECT country FROM Country country WHERE ");
459
460 if (name == null) {
461 query.append("country.name IS NULL");
462 }
463 else {
464 query.append("country.name = ?");
465 }
466
467 query.append(" ");
468
469 query.append("ORDER BY ");
470
471 query.append("country.name ASC");
472
473 Query q = session.createQuery(query.toString());
474
475 QueryPos qPos = QueryPos.getInstance(q);
476
477 if (name != null) {
478 qPos.add(name);
479 }
480
481 List<Country> list = q.list();
482
483 result = list;
484
485 Country country = null;
486
487 if (list.isEmpty()) {
488 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
489 finderArgs, list);
490 }
491 else {
492 country = list.get(0);
493
494 cacheResult(country);
495
496 if ((country.getName() == null) ||
497 !country.getName().equals(name)) {
498 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
499 finderArgs, country);
500 }
501 }
502
503 return country;
504 }
505 catch (Exception e) {
506 throw processException(e);
507 }
508 finally {
509 if (result == null) {
510 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
511 finderArgs, new ArrayList<Country>());
512 }
513
514 closeSession(session);
515 }
516 }
517 else {
518 if (result instanceof List<?>) {
519 return null;
520 }
521 else {
522 return (Country)result;
523 }
524 }
525 }
526
527 public Country findByA2(String a2)
528 throws NoSuchCountryException, SystemException {
529 Country country = fetchByA2(a2);
530
531 if (country == null) {
532 StringBuilder msg = new StringBuilder();
533
534 msg.append("No Country exists with the key {");
535
536 msg.append("a2=" + a2);
537
538 msg.append(StringPool.CLOSE_CURLY_BRACE);
539
540 if (_log.isWarnEnabled()) {
541 _log.warn(msg.toString());
542 }
543
544 throw new NoSuchCountryException(msg.toString());
545 }
546
547 return country;
548 }
549
550 public Country fetchByA2(String a2) throws SystemException {
551 return fetchByA2(a2, true);
552 }
553
554 public Country fetchByA2(String a2, boolean retrieveFromCache)
555 throws SystemException {
556 Object[] finderArgs = new Object[] { a2 };
557
558 Object result = null;
559
560 if (retrieveFromCache) {
561 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A2,
562 finderArgs, this);
563 }
564
565 if (result == null) {
566 Session session = null;
567
568 try {
569 session = openSession();
570
571 StringBuilder query = new StringBuilder();
572
573 query.append("SELECT country FROM Country country WHERE ");
574
575 if (a2 == null) {
576 query.append("country.a2 IS NULL");
577 }
578 else {
579 query.append("country.a2 = ?");
580 }
581
582 query.append(" ");
583
584 query.append("ORDER BY ");
585
586 query.append("country.name ASC");
587
588 Query q = session.createQuery(query.toString());
589
590 QueryPos qPos = QueryPos.getInstance(q);
591
592 if (a2 != null) {
593 qPos.add(a2);
594 }
595
596 List<Country> list = q.list();
597
598 result = list;
599
600 Country country = null;
601
602 if (list.isEmpty()) {
603 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
604 finderArgs, list);
605 }
606 else {
607 country = list.get(0);
608
609 cacheResult(country);
610
611 if ((country.getA2() == null) ||
612 !country.getA2().equals(a2)) {
613 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
614 finderArgs, country);
615 }
616 }
617
618 return country;
619 }
620 catch (Exception e) {
621 throw processException(e);
622 }
623 finally {
624 if (result == null) {
625 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
626 finderArgs, new ArrayList<Country>());
627 }
628
629 closeSession(session);
630 }
631 }
632 else {
633 if (result instanceof List<?>) {
634 return null;
635 }
636 else {
637 return (Country)result;
638 }
639 }
640 }
641
642 public Country findByA3(String a3)
643 throws NoSuchCountryException, SystemException {
644 Country country = fetchByA3(a3);
645
646 if (country == null) {
647 StringBuilder msg = new StringBuilder();
648
649 msg.append("No Country exists with the key {");
650
651 msg.append("a3=" + a3);
652
653 msg.append(StringPool.CLOSE_CURLY_BRACE);
654
655 if (_log.isWarnEnabled()) {
656 _log.warn(msg.toString());
657 }
658
659 throw new NoSuchCountryException(msg.toString());
660 }
661
662 return country;
663 }
664
665 public Country fetchByA3(String a3) throws SystemException {
666 return fetchByA3(a3, true);
667 }
668
669 public Country fetchByA3(String a3, boolean retrieveFromCache)
670 throws SystemException {
671 Object[] finderArgs = new Object[] { a3 };
672
673 Object result = null;
674
675 if (retrieveFromCache) {
676 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
677 finderArgs, this);
678 }
679
680 if (result == null) {
681 Session session = null;
682
683 try {
684 session = openSession();
685
686 StringBuilder query = new StringBuilder();
687
688 query.append("SELECT country FROM Country country WHERE ");
689
690 if (a3 == null) {
691 query.append("country.a3 IS NULL");
692 }
693 else {
694 query.append("country.a3 = ?");
695 }
696
697 query.append(" ");
698
699 query.append("ORDER BY ");
700
701 query.append("country.name ASC");
702
703 Query q = session.createQuery(query.toString());
704
705 QueryPos qPos = QueryPos.getInstance(q);
706
707 if (a3 != null) {
708 qPos.add(a3);
709 }
710
711 List<Country> list = q.list();
712
713 result = list;
714
715 Country country = null;
716
717 if (list.isEmpty()) {
718 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
719 finderArgs, list);
720 }
721 else {
722 country = list.get(0);
723
724 cacheResult(country);
725
726 if ((country.getA3() == null) ||
727 !country.getA3().equals(a3)) {
728 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
729 finderArgs, country);
730 }
731 }
732
733 return country;
734 }
735 catch (Exception e) {
736 throw processException(e);
737 }
738 finally {
739 if (result == null) {
740 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
741 finderArgs, new ArrayList<Country>());
742 }
743
744 closeSession(session);
745 }
746 }
747 else {
748 if (result instanceof List<?>) {
749 return null;
750 }
751 else {
752 return (Country)result;
753 }
754 }
755 }
756
757 public List<Country> findByActive(boolean active) throws SystemException {
758 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
759
760 List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
761 finderArgs, this);
762
763 if (list == null) {
764 Session session = null;
765
766 try {
767 session = openSession();
768
769 StringBuilder query = new StringBuilder();
770
771 query.append("SELECT country FROM Country country WHERE ");
772
773 query.append("country.active = ?");
774
775 query.append(" ");
776
777 query.append("ORDER BY ");
778
779 query.append("country.name ASC");
780
781 Query q = session.createQuery(query.toString());
782
783 QueryPos qPos = QueryPos.getInstance(q);
784
785 qPos.add(active);
786
787 list = q.list();
788 }
789 catch (Exception e) {
790 throw processException(e);
791 }
792 finally {
793 if (list == null) {
794 list = new ArrayList<Country>();
795 }
796
797 cacheResult(list);
798
799 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
800 finderArgs, list);
801
802 closeSession(session);
803 }
804 }
805
806 return list;
807 }
808
809 public List<Country> findByActive(boolean active, int start, int end)
810 throws SystemException {
811 return findByActive(active, start, end, null);
812 }
813
814 public List<Country> findByActive(boolean active, int start, int end,
815 OrderByComparator obc) throws SystemException {
816 Object[] finderArgs = new Object[] {
817 Boolean.valueOf(active),
818
819 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
820 };
821
822 List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
823 finderArgs, this);
824
825 if (list == null) {
826 Session session = null;
827
828 try {
829 session = openSession();
830
831 StringBuilder query = new StringBuilder();
832
833 query.append("SELECT country FROM Country country WHERE ");
834
835 query.append("country.active = ?");
836
837 query.append(" ");
838
839 if (obc != null) {
840 query.append("ORDER BY ");
841
842 String[] orderByFields = obc.getOrderByFields();
843
844 for (int i = 0; i < orderByFields.length; i++) {
845 query.append("country.");
846 query.append(orderByFields[i]);
847
848 if (obc.isAscending()) {
849 query.append(" ASC");
850 }
851 else {
852 query.append(" DESC");
853 }
854
855 if ((i + 1) < orderByFields.length) {
856 query.append(", ");
857 }
858 }
859 }
860
861 else {
862 query.append("ORDER BY ");
863
864 query.append("country.name ASC");
865 }
866
867 Query q = session.createQuery(query.toString());
868
869 QueryPos qPos = QueryPos.getInstance(q);
870
871 qPos.add(active);
872
873 list = (List<Country>)QueryUtil.list(q, getDialect(), start, end);
874 }
875 catch (Exception e) {
876 throw processException(e);
877 }
878 finally {
879 if (list == null) {
880 list = new ArrayList<Country>();
881 }
882
883 cacheResult(list);
884
885 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
886 finderArgs, list);
887
888 closeSession(session);
889 }
890 }
891
892 return list;
893 }
894
895 public Country findByActive_First(boolean active, OrderByComparator obc)
896 throws NoSuchCountryException, SystemException {
897 List<Country> list = findByActive(active, 0, 1, obc);
898
899 if (list.isEmpty()) {
900 StringBuilder msg = new StringBuilder();
901
902 msg.append("No Country exists with the key {");
903
904 msg.append("active=" + active);
905
906 msg.append(StringPool.CLOSE_CURLY_BRACE);
907
908 throw new NoSuchCountryException(msg.toString());
909 }
910 else {
911 return list.get(0);
912 }
913 }
914
915 public Country findByActive_Last(boolean active, OrderByComparator obc)
916 throws NoSuchCountryException, SystemException {
917 int count = countByActive(active);
918
919 List<Country> list = findByActive(active, count - 1, count, obc);
920
921 if (list.isEmpty()) {
922 StringBuilder msg = new StringBuilder();
923
924 msg.append("No Country exists with the key {");
925
926 msg.append("active=" + active);
927
928 msg.append(StringPool.CLOSE_CURLY_BRACE);
929
930 throw new NoSuchCountryException(msg.toString());
931 }
932 else {
933 return list.get(0);
934 }
935 }
936
937 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
938 OrderByComparator obc) throws NoSuchCountryException, SystemException {
939 Country country = findByPrimaryKey(countryId);
940
941 int count = countByActive(active);
942
943 Session session = null;
944
945 try {
946 session = openSession();
947
948 StringBuilder query = new StringBuilder();
949
950 query.append("SELECT country FROM Country country WHERE ");
951
952 query.append("country.active = ?");
953
954 query.append(" ");
955
956 if (obc != null) {
957 query.append("ORDER BY ");
958
959 String[] orderByFields = obc.getOrderByFields();
960
961 for (int i = 0; i < orderByFields.length; i++) {
962 query.append("country.");
963 query.append(orderByFields[i]);
964
965 if (obc.isAscending()) {
966 query.append(" ASC");
967 }
968 else {
969 query.append(" DESC");
970 }
971
972 if ((i + 1) < orderByFields.length) {
973 query.append(", ");
974 }
975 }
976 }
977
978 else {
979 query.append("ORDER BY ");
980
981 query.append("country.name ASC");
982 }
983
984 Query q = session.createQuery(query.toString());
985
986 QueryPos qPos = QueryPos.getInstance(q);
987
988 qPos.add(active);
989
990 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, country);
991
992 Country[] array = new CountryImpl[3];
993
994 array[0] = (Country)objArray[0];
995 array[1] = (Country)objArray[1];
996 array[2] = (Country)objArray[2];
997
998 return array;
999 }
1000 catch (Exception e) {
1001 throw processException(e);
1002 }
1003 finally {
1004 closeSession(session);
1005 }
1006 }
1007
1008 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1009 throws SystemException {
1010 Session session = null;
1011
1012 try {
1013 session = openSession();
1014
1015 dynamicQuery.compile(session);
1016
1017 return dynamicQuery.list();
1018 }
1019 catch (Exception e) {
1020 throw processException(e);
1021 }
1022 finally {
1023 closeSession(session);
1024 }
1025 }
1026
1027 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1028 int start, int end) throws SystemException {
1029 Session session = null;
1030
1031 try {
1032 session = openSession();
1033
1034 dynamicQuery.setLimit(start, end);
1035
1036 dynamicQuery.compile(session);
1037
1038 return dynamicQuery.list();
1039 }
1040 catch (Exception e) {
1041 throw processException(e);
1042 }
1043 finally {
1044 closeSession(session);
1045 }
1046 }
1047
1048 public List<Country> findAll() throws SystemException {
1049 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1050 }
1051
1052 public List<Country> findAll(int start, int end) throws SystemException {
1053 return findAll(start, end, null);
1054 }
1055
1056 public List<Country> findAll(int start, int end, OrderByComparator obc)
1057 throws SystemException {
1058 Object[] finderArgs = new Object[] {
1059 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1060 };
1061
1062 List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1063 finderArgs, this);
1064
1065 if (list == null) {
1066 Session session = null;
1067
1068 try {
1069 session = openSession();
1070
1071 StringBuilder query = new StringBuilder();
1072
1073 query.append("SELECT country FROM Country country ");
1074
1075 if (obc != null) {
1076 query.append("ORDER BY ");
1077
1078 String[] orderByFields = obc.getOrderByFields();
1079
1080 for (int i = 0; i < orderByFields.length; i++) {
1081 query.append("country.");
1082 query.append(orderByFields[i]);
1083
1084 if (obc.isAscending()) {
1085 query.append(" ASC");
1086 }
1087 else {
1088 query.append(" DESC");
1089 }
1090
1091 if ((i + 1) < orderByFields.length) {
1092 query.append(", ");
1093 }
1094 }
1095 }
1096
1097 else {
1098 query.append("ORDER BY ");
1099
1100 query.append("country.name ASC");
1101 }
1102
1103 Query q = session.createQuery(query.toString());
1104
1105 if (obc == null) {
1106 list = (List<Country>)QueryUtil.list(q, getDialect(),
1107 start, end, false);
1108
1109 Collections.sort(list);
1110 }
1111 else {
1112 list = (List<Country>)QueryUtil.list(q, getDialect(),
1113 start, end);
1114 }
1115 }
1116 catch (Exception e) {
1117 throw processException(e);
1118 }
1119 finally {
1120 if (list == null) {
1121 list = new ArrayList<Country>();
1122 }
1123
1124 cacheResult(list);
1125
1126 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1127
1128 closeSession(session);
1129 }
1130 }
1131
1132 return list;
1133 }
1134
1135 public void removeByName(String name)
1136 throws NoSuchCountryException, SystemException {
1137 Country country = findByName(name);
1138
1139 remove(country);
1140 }
1141
1142 public void removeByA2(String a2)
1143 throws NoSuchCountryException, SystemException {
1144 Country country = findByA2(a2);
1145
1146 remove(country);
1147 }
1148
1149 public void removeByA3(String a3)
1150 throws NoSuchCountryException, SystemException {
1151 Country country = findByA3(a3);
1152
1153 remove(country);
1154 }
1155
1156 public void removeByActive(boolean active) throws SystemException {
1157 for (Country country : findByActive(active)) {
1158 remove(country);
1159 }
1160 }
1161
1162 public void removeAll() throws SystemException {
1163 for (Country country : findAll()) {
1164 remove(country);
1165 }
1166 }
1167
1168 public int countByName(String name) throws SystemException {
1169 Object[] finderArgs = new Object[] { name };
1170
1171 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1172 finderArgs, this);
1173
1174 if (count == null) {
1175 Session session = null;
1176
1177 try {
1178 session = openSession();
1179
1180 StringBuilder query = new StringBuilder();
1181
1182 query.append("SELECT COUNT(country) ");
1183 query.append("FROM Country country WHERE ");
1184
1185 if (name == null) {
1186 query.append("country.name IS NULL");
1187 }
1188 else {
1189 query.append("country.name = ?");
1190 }
1191
1192 query.append(" ");
1193
1194 Query q = session.createQuery(query.toString());
1195
1196 QueryPos qPos = QueryPos.getInstance(q);
1197
1198 if (name != null) {
1199 qPos.add(name);
1200 }
1201
1202 count = (Long)q.uniqueResult();
1203 }
1204 catch (Exception e) {
1205 throw processException(e);
1206 }
1207 finally {
1208 if (count == null) {
1209 count = Long.valueOf(0);
1210 }
1211
1212 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1213 finderArgs, count);
1214
1215 closeSession(session);
1216 }
1217 }
1218
1219 return count.intValue();
1220 }
1221
1222 public int countByA2(String a2) throws SystemException {
1223 Object[] finderArgs = new Object[] { a2 };
1224
1225 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A2,
1226 finderArgs, this);
1227
1228 if (count == null) {
1229 Session session = null;
1230
1231 try {
1232 session = openSession();
1233
1234 StringBuilder query = new StringBuilder();
1235
1236 query.append("SELECT COUNT(country) ");
1237 query.append("FROM Country country WHERE ");
1238
1239 if (a2 == null) {
1240 query.append("country.a2 IS NULL");
1241 }
1242 else {
1243 query.append("country.a2 = ?");
1244 }
1245
1246 query.append(" ");
1247
1248 Query q = session.createQuery(query.toString());
1249
1250 QueryPos qPos = QueryPos.getInstance(q);
1251
1252 if (a2 != null) {
1253 qPos.add(a2);
1254 }
1255
1256 count = (Long)q.uniqueResult();
1257 }
1258 catch (Exception e) {
1259 throw processException(e);
1260 }
1261 finally {
1262 if (count == null) {
1263 count = Long.valueOf(0);
1264 }
1265
1266 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, finderArgs,
1267 count);
1268
1269 closeSession(session);
1270 }
1271 }
1272
1273 return count.intValue();
1274 }
1275
1276 public int countByA3(String a3) throws SystemException {
1277 Object[] finderArgs = new Object[] { a3 };
1278
1279 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A3,
1280 finderArgs, this);
1281
1282 if (count == null) {
1283 Session session = null;
1284
1285 try {
1286 session = openSession();
1287
1288 StringBuilder query = new StringBuilder();
1289
1290 query.append("SELECT COUNT(country) ");
1291 query.append("FROM Country country WHERE ");
1292
1293 if (a3 == null) {
1294 query.append("country.a3 IS NULL");
1295 }
1296 else {
1297 query.append("country.a3 = ?");
1298 }
1299
1300 query.append(" ");
1301
1302 Query q = session.createQuery(query.toString());
1303
1304 QueryPos qPos = QueryPos.getInstance(q);
1305
1306 if (a3 != null) {
1307 qPos.add(a3);
1308 }
1309
1310 count = (Long)q.uniqueResult();
1311 }
1312 catch (Exception e) {
1313 throw processException(e);
1314 }
1315 finally {
1316 if (count == null) {
1317 count = Long.valueOf(0);
1318 }
1319
1320 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, finderArgs,
1321 count);
1322
1323 closeSession(session);
1324 }
1325 }
1326
1327 return count.intValue();
1328 }
1329
1330 public int countByActive(boolean active) throws SystemException {
1331 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1332
1333 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1334 finderArgs, this);
1335
1336 if (count == null) {
1337 Session session = null;
1338
1339 try {
1340 session = openSession();
1341
1342 StringBuilder query = new StringBuilder();
1343
1344 query.append("SELECT COUNT(country) ");
1345 query.append("FROM Country country WHERE ");
1346
1347 query.append("country.active = ?");
1348
1349 query.append(" ");
1350
1351 Query q = session.createQuery(query.toString());
1352
1353 QueryPos qPos = QueryPos.getInstance(q);
1354
1355 qPos.add(active);
1356
1357 count = (Long)q.uniqueResult();
1358 }
1359 catch (Exception e) {
1360 throw processException(e);
1361 }
1362 finally {
1363 if (count == null) {
1364 count = Long.valueOf(0);
1365 }
1366
1367 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1368 finderArgs, count);
1369
1370 closeSession(session);
1371 }
1372 }
1373
1374 return count.intValue();
1375 }
1376
1377 public int countAll() throws SystemException {
1378 Object[] finderArgs = new Object[0];
1379
1380 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1381 finderArgs, this);
1382
1383 if (count == null) {
1384 Session session = null;
1385
1386 try {
1387 session = openSession();
1388
1389 Query q = session.createQuery(
1390 "SELECT COUNT(country) FROM Country country");
1391
1392 count = (Long)q.uniqueResult();
1393 }
1394 catch (Exception e) {
1395 throw processException(e);
1396 }
1397 finally {
1398 if (count == null) {
1399 count = Long.valueOf(0);
1400 }
1401
1402 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1403 count);
1404
1405 closeSession(session);
1406 }
1407 }
1408
1409 return count.intValue();
1410 }
1411
1412 public void afterPropertiesSet() {
1413 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1414 com.liferay.portal.util.PropsUtil.get(
1415 "value.object.listener.com.liferay.portal.model.Country")));
1416
1417 if (listenerClassNames.length > 0) {
1418 try {
1419 List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1420
1421 for (String listenerClassName : listenerClassNames) {
1422 listenersList.add((ModelListener<Country>)Class.forName(
1423 listenerClassName).newInstance());
1424 }
1425
1426 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1427 }
1428 catch (Exception e) {
1429 _log.error(e);
1430 }
1431 }
1432 }
1433
1434 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1435 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1436 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1437 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1438 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1439 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1440 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1441 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1442 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1443 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1444 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1445 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1446 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1447 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1448 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1449 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1450 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1451 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1452 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1453 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1454 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1455 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1456 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1457 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1458 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1459 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1460 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
1461 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1462 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1463 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1464 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1465 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1466 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1467 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1468 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1469 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1470 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1471 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1472 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1473 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1474 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1475 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1476 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1477 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1478 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1479 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1480 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1481 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1482 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1483 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1484 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1485 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1486 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1487 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1488 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1489 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1490 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1491 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1492 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1493 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1494 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1495 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1496 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1497 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1498 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1499 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1500 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1501 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1502 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1503 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1504 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1505 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1506 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1507 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1508 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1509 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1510 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1511 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1512 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1513 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1514 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1515 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1516 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1517 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1518 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1519 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1520 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1521 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1522 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1523 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1524 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1525 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1526 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1527}