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