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