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