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