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("FROM com.liferay.portal.model.Country WHERE ");
453
454 if (name == null) {
455 query.append("name IS NULL");
456 }
457 else {
458 query.append("name = ?");
459 }
460
461 query.append(" ");
462
463 query.append("ORDER BY ");
464
465 query.append("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("FROM com.liferay.portal.model.Country WHERE ");
568
569 if (a2 == null) {
570 query.append("a2 IS NULL");
571 }
572 else {
573 query.append("a2 = ?");
574 }
575
576 query.append(" ");
577
578 query.append("ORDER BY ");
579
580 query.append("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("FROM com.liferay.portal.model.Country WHERE ");
683
684 if (a3 == null) {
685 query.append("a3 IS NULL");
686 }
687 else {
688 query.append("a3 = ?");
689 }
690
691 query.append(" ");
692
693 query.append("ORDER BY ");
694
695 query.append("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("FROM com.liferay.portal.model.Country WHERE ");
766
767 query.append("active_ = ?");
768
769 query.append(" ");
770
771 query.append("ORDER BY ");
772
773 query.append("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("FROM com.liferay.portal.model.Country WHERE ");
828
829 query.append("active_ = ?");
830
831 query.append(" ");
832
833 if (obc != null) {
834 query.append("ORDER BY ");
835 query.append(obc.getOrderBy());
836 }
837
838 else {
839 query.append("ORDER BY ");
840
841 query.append("name ASC");
842 }
843
844 Query q = session.createQuery(query.toString());
845
846 QueryPos qPos = QueryPos.getInstance(q);
847
848 qPos.add(active);
849
850 list = (List<Country>)QueryUtil.list(q, getDialect(), start, end);
851 }
852 catch (Exception e) {
853 throw processException(e);
854 }
855 finally {
856 if (list == null) {
857 list = new ArrayList<Country>();
858 }
859
860 cacheResult(list);
861
862 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
863 finderArgs, list);
864
865 closeSession(session);
866 }
867 }
868
869 return list;
870 }
871
872 public Country findByActive_First(boolean active, OrderByComparator obc)
873 throws NoSuchCountryException, SystemException {
874 List<Country> list = findByActive(active, 0, 1, obc);
875
876 if (list.isEmpty()) {
877 StringBuilder msg = new StringBuilder();
878
879 msg.append("No Country exists with the key {");
880
881 msg.append("active=" + active);
882
883 msg.append(StringPool.CLOSE_CURLY_BRACE);
884
885 throw new NoSuchCountryException(msg.toString());
886 }
887 else {
888 return list.get(0);
889 }
890 }
891
892 public Country findByActive_Last(boolean active, OrderByComparator obc)
893 throws NoSuchCountryException, SystemException {
894 int count = countByActive(active);
895
896 List<Country> list = findByActive(active, count - 1, count, obc);
897
898 if (list.isEmpty()) {
899 StringBuilder msg = new StringBuilder();
900
901 msg.append("No Country exists with the key {");
902
903 msg.append("active=" + active);
904
905 msg.append(StringPool.CLOSE_CURLY_BRACE);
906
907 throw new NoSuchCountryException(msg.toString());
908 }
909 else {
910 return list.get(0);
911 }
912 }
913
914 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
915 OrderByComparator obc) throws NoSuchCountryException, SystemException {
916 Country country = findByPrimaryKey(countryId);
917
918 int count = countByActive(active);
919
920 Session session = null;
921
922 try {
923 session = openSession();
924
925 StringBuilder query = new StringBuilder();
926
927 query.append("FROM com.liferay.portal.model.Country WHERE ");
928
929 query.append("active_ = ?");
930
931 query.append(" ");
932
933 if (obc != null) {
934 query.append("ORDER BY ");
935 query.append(obc.getOrderBy());
936 }
937
938 else {
939 query.append("ORDER BY ");
940
941 query.append("name ASC");
942 }
943
944 Query q = session.createQuery(query.toString());
945
946 QueryPos qPos = QueryPos.getInstance(q);
947
948 qPos.add(active);
949
950 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, country);
951
952 Country[] array = new CountryImpl[3];
953
954 array[0] = (Country)objArray[0];
955 array[1] = (Country)objArray[1];
956 array[2] = (Country)objArray[2];
957
958 return array;
959 }
960 catch (Exception e) {
961 throw processException(e);
962 }
963 finally {
964 closeSession(session);
965 }
966 }
967
968 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
969 throws SystemException {
970 Session session = null;
971
972 try {
973 session = openSession();
974
975 dynamicQuery.compile(session);
976
977 return dynamicQuery.list();
978 }
979 catch (Exception e) {
980 throw processException(e);
981 }
982 finally {
983 closeSession(session);
984 }
985 }
986
987 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
988 int start, int end) throws SystemException {
989 Session session = null;
990
991 try {
992 session = openSession();
993
994 dynamicQuery.setLimit(start, end);
995
996 dynamicQuery.compile(session);
997
998 return dynamicQuery.list();
999 }
1000 catch (Exception e) {
1001 throw processException(e);
1002 }
1003 finally {
1004 closeSession(session);
1005 }
1006 }
1007
1008 public List<Country> findAll() throws SystemException {
1009 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1010 }
1011
1012 public List<Country> findAll(int start, int end) throws SystemException {
1013 return findAll(start, end, null);
1014 }
1015
1016 public List<Country> findAll(int start, int end, OrderByComparator obc)
1017 throws SystemException {
1018 Object[] finderArgs = new Object[] {
1019 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1020 };
1021
1022 List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1023 finderArgs, this);
1024
1025 if (list == null) {
1026 Session session = null;
1027
1028 try {
1029 session = openSession();
1030
1031 StringBuilder query = new StringBuilder();
1032
1033 query.append("FROM com.liferay.portal.model.Country ");
1034
1035 if (obc != null) {
1036 query.append("ORDER BY ");
1037 query.append(obc.getOrderBy());
1038 }
1039
1040 else {
1041 query.append("ORDER BY ");
1042
1043 query.append("name ASC");
1044 }
1045
1046 Query q = session.createQuery(query.toString());
1047
1048 if (obc == null) {
1049 list = (List<Country>)QueryUtil.list(q, getDialect(),
1050 start, end, false);
1051
1052 Collections.sort(list);
1053 }
1054 else {
1055 list = (List<Country>)QueryUtil.list(q, getDialect(),
1056 start, end);
1057 }
1058 }
1059 catch (Exception e) {
1060 throw processException(e);
1061 }
1062 finally {
1063 if (list == null) {
1064 list = new ArrayList<Country>();
1065 }
1066
1067 cacheResult(list);
1068
1069 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1070
1071 closeSession(session);
1072 }
1073 }
1074
1075 return list;
1076 }
1077
1078 public void removeByName(String name)
1079 throws NoSuchCountryException, SystemException {
1080 Country country = findByName(name);
1081
1082 remove(country);
1083 }
1084
1085 public void removeByA2(String a2)
1086 throws NoSuchCountryException, SystemException {
1087 Country country = findByA2(a2);
1088
1089 remove(country);
1090 }
1091
1092 public void removeByA3(String a3)
1093 throws NoSuchCountryException, SystemException {
1094 Country country = findByA3(a3);
1095
1096 remove(country);
1097 }
1098
1099 public void removeByActive(boolean active) throws SystemException {
1100 for (Country country : findByActive(active)) {
1101 remove(country);
1102 }
1103 }
1104
1105 public void removeAll() throws SystemException {
1106 for (Country country : findAll()) {
1107 remove(country);
1108 }
1109 }
1110
1111 public int countByName(String name) throws SystemException {
1112 Object[] finderArgs = new Object[] { name };
1113
1114 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1115 finderArgs, this);
1116
1117 if (count == null) {
1118 Session session = null;
1119
1120 try {
1121 session = openSession();
1122
1123 StringBuilder query = new StringBuilder();
1124
1125 query.append("SELECT COUNT(*) ");
1126 query.append("FROM com.liferay.portal.model.Country WHERE ");
1127
1128 if (name == null) {
1129 query.append("name IS NULL");
1130 }
1131 else {
1132 query.append("name = ?");
1133 }
1134
1135 query.append(" ");
1136
1137 Query q = session.createQuery(query.toString());
1138
1139 QueryPos qPos = QueryPos.getInstance(q);
1140
1141 if (name != null) {
1142 qPos.add(name);
1143 }
1144
1145 count = (Long)q.uniqueResult();
1146 }
1147 catch (Exception e) {
1148 throw processException(e);
1149 }
1150 finally {
1151 if (count == null) {
1152 count = Long.valueOf(0);
1153 }
1154
1155 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1156 finderArgs, count);
1157
1158 closeSession(session);
1159 }
1160 }
1161
1162 return count.intValue();
1163 }
1164
1165 public int countByA2(String a2) throws SystemException {
1166 Object[] finderArgs = new Object[] { a2 };
1167
1168 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A2,
1169 finderArgs, this);
1170
1171 if (count == null) {
1172 Session session = null;
1173
1174 try {
1175 session = openSession();
1176
1177 StringBuilder query = new StringBuilder();
1178
1179 query.append("SELECT COUNT(*) ");
1180 query.append("FROM com.liferay.portal.model.Country WHERE ");
1181
1182 if (a2 == null) {
1183 query.append("a2 IS NULL");
1184 }
1185 else {
1186 query.append("a2 = ?");
1187 }
1188
1189 query.append(" ");
1190
1191 Query q = session.createQuery(query.toString());
1192
1193 QueryPos qPos = QueryPos.getInstance(q);
1194
1195 if (a2 != null) {
1196 qPos.add(a2);
1197 }
1198
1199 count = (Long)q.uniqueResult();
1200 }
1201 catch (Exception e) {
1202 throw processException(e);
1203 }
1204 finally {
1205 if (count == null) {
1206 count = Long.valueOf(0);
1207 }
1208
1209 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, finderArgs,
1210 count);
1211
1212 closeSession(session);
1213 }
1214 }
1215
1216 return count.intValue();
1217 }
1218
1219 public int countByA3(String a3) throws SystemException {
1220 Object[] finderArgs = new Object[] { a3 };
1221
1222 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A3,
1223 finderArgs, this);
1224
1225 if (count == null) {
1226 Session session = null;
1227
1228 try {
1229 session = openSession();
1230
1231 StringBuilder query = new StringBuilder();
1232
1233 query.append("SELECT COUNT(*) ");
1234 query.append("FROM com.liferay.portal.model.Country WHERE ");
1235
1236 if (a3 == null) {
1237 query.append("a3 IS NULL");
1238 }
1239 else {
1240 query.append("a3 = ?");
1241 }
1242
1243 query.append(" ");
1244
1245 Query q = session.createQuery(query.toString());
1246
1247 QueryPos qPos = QueryPos.getInstance(q);
1248
1249 if (a3 != null) {
1250 qPos.add(a3);
1251 }
1252
1253 count = (Long)q.uniqueResult();
1254 }
1255 catch (Exception e) {
1256 throw processException(e);
1257 }
1258 finally {
1259 if (count == null) {
1260 count = Long.valueOf(0);
1261 }
1262
1263 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, finderArgs,
1264 count);
1265
1266 closeSession(session);
1267 }
1268 }
1269
1270 return count.intValue();
1271 }
1272
1273 public int countByActive(boolean active) throws SystemException {
1274 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1275
1276 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1277 finderArgs, this);
1278
1279 if (count == null) {
1280 Session session = null;
1281
1282 try {
1283 session = openSession();
1284
1285 StringBuilder query = new StringBuilder();
1286
1287 query.append("SELECT COUNT(*) ");
1288 query.append("FROM com.liferay.portal.model.Country WHERE ");
1289
1290 query.append("active_ = ?");
1291
1292 query.append(" ");
1293
1294 Query q = session.createQuery(query.toString());
1295
1296 QueryPos qPos = QueryPos.getInstance(q);
1297
1298 qPos.add(active);
1299
1300 count = (Long)q.uniqueResult();
1301 }
1302 catch (Exception e) {
1303 throw processException(e);
1304 }
1305 finally {
1306 if (count == null) {
1307 count = Long.valueOf(0);
1308 }
1309
1310 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1311 finderArgs, count);
1312
1313 closeSession(session);
1314 }
1315 }
1316
1317 return count.intValue();
1318 }
1319
1320 public int countAll() throws SystemException {
1321 Object[] finderArgs = new Object[0];
1322
1323 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1324 finderArgs, this);
1325
1326 if (count == null) {
1327 Session session = null;
1328
1329 try {
1330 session = openSession();
1331
1332 Query q = session.createQuery(
1333 "SELECT COUNT(*) FROM com.liferay.portal.model.Country");
1334
1335 count = (Long)q.uniqueResult();
1336 }
1337 catch (Exception e) {
1338 throw processException(e);
1339 }
1340 finally {
1341 if (count == null) {
1342 count = Long.valueOf(0);
1343 }
1344
1345 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1346 count);
1347
1348 closeSession(session);
1349 }
1350 }
1351
1352 return count.intValue();
1353 }
1354
1355 public void afterPropertiesSet() {
1356 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1357 com.liferay.portal.util.PropsUtil.get(
1358 "value.object.listener.com.liferay.portal.model.Country")));
1359
1360 if (listenerClassNames.length > 0) {
1361 try {
1362 List<ModelListener<Country>> listenersList = new ArrayList<ModelListener<Country>>();
1363
1364 for (String listenerClassName : listenerClassNames) {
1365 listenersList.add((ModelListener<Country>)Class.forName(
1366 listenerClassName).newInstance());
1367 }
1368
1369 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1370 }
1371 catch (Exception e) {
1372 _log.error(e);
1373 }
1374 }
1375 }
1376
1377 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1378 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1379 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1380 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1381 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1382 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1383 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1384 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1385 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1386 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1387 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1388 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1389 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1390 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1391 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1392 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1393 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1394 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1395 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1396 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1397 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1398 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1399 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1400 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1401 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1402 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1403 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1404 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1405 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1406 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1407 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1408 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1409 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1410 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1411 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1412 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1413 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1414 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1415 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1416 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1417 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1418 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1419 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1420 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1421 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1422 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1423 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1424 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1425 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1426 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1427 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1428 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1429 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1430 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1431 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1432 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1433 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1434 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1435 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1436 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1437 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1438 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1439 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1440 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1441 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1442 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1443 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1444 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1445 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1446 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1447 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1448 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1449 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1450 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1451 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1452 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1453 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1454 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1455 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1456 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1457 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1458 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1459 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1460 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1461 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1462 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1463 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1464 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1465 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1466 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1467 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1468}