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.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
28 import com.liferay.portal.kernel.exception.SystemException;
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 public Country updateImpl(com.liferay.portal.model.Country country,
246 boolean merge) throws SystemException {
247 country = toUnwrappedModel(country);
248
249 boolean isNew = country.isNew();
250
251 CountryModelImpl countryModelImpl = (CountryModelImpl)country;
252
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 BatchSessionUtil.update(session, country, merge);
259
260 country.setNew(false);
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268
269 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
270
271 EntityCacheUtil.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
272 CountryImpl.class, country.getPrimaryKey(), country);
273
274 if (!isNew &&
275 (!Validator.equals(country.getName(),
276 countryModelImpl.getOriginalName()))) {
277 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
278 new Object[] { countryModelImpl.getOriginalName() });
279 }
280
281 if (isNew ||
282 (!Validator.equals(country.getName(),
283 countryModelImpl.getOriginalName()))) {
284 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
285 new Object[] { country.getName() }, country);
286 }
287
288 if (!isNew &&
289 (!Validator.equals(country.getA2(),
290 countryModelImpl.getOriginalA2()))) {
291 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A2,
292 new Object[] { countryModelImpl.getOriginalA2() });
293 }
294
295 if (isNew ||
296 (!Validator.equals(country.getA2(),
297 countryModelImpl.getOriginalA2()))) {
298 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
299 new Object[] { country.getA2() }, country);
300 }
301
302 if (!isNew &&
303 (!Validator.equals(country.getA3(),
304 countryModelImpl.getOriginalA3()))) {
305 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A3,
306 new Object[] { countryModelImpl.getOriginalA3() });
307 }
308
309 if (isNew ||
310 (!Validator.equals(country.getA3(),
311 countryModelImpl.getOriginalA3()))) {
312 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A3,
313 new Object[] { country.getA3() }, country);
314 }
315
316 return country;
317 }
318
319 protected Country toUnwrappedModel(Country country) {
320 if (country instanceof CountryImpl) {
321 return country;
322 }
323
324 CountryImpl countryImpl = new CountryImpl();
325
326 countryImpl.setNew(country.isNew());
327 countryImpl.setPrimaryKey(country.getPrimaryKey());
328
329 countryImpl.setCountryId(country.getCountryId());
330 countryImpl.setName(country.getName());
331 countryImpl.setA2(country.getA2());
332 countryImpl.setA3(country.getA3());
333 countryImpl.setNumber(country.getNumber());
334 countryImpl.setIdd(country.getIdd());
335 countryImpl.setActive(country.isActive());
336
337 return countryImpl;
338 }
339
340 public Country findByPrimaryKey(Serializable primaryKey)
341 throws NoSuchModelException, SystemException {
342 return findByPrimaryKey(((Long)primaryKey).longValue());
343 }
344
345 public Country findByPrimaryKey(long countryId)
346 throws NoSuchCountryException, SystemException {
347 Country country = fetchByPrimaryKey(countryId);
348
349 if (country == null) {
350 if (_log.isWarnEnabled()) {
351 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + countryId);
352 }
353
354 throw new NoSuchCountryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
355 countryId);
356 }
357
358 return country;
359 }
360
361 public Country fetchByPrimaryKey(Serializable primaryKey)
362 throws SystemException {
363 return fetchByPrimaryKey(((Long)primaryKey).longValue());
364 }
365
366 public Country fetchByPrimaryKey(long countryId) throws SystemException {
367 Country country = (Country)EntityCacheUtil.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED,
368 CountryImpl.class, countryId, this);
369
370 if (country == null) {
371 Session session = null;
372
373 try {
374 session = openSession();
375
376 country = (Country)session.get(CountryImpl.class,
377 new Long(countryId));
378 }
379 catch (Exception e) {
380 throw processException(e);
381 }
382 finally {
383 if (country != null) {
384 cacheResult(country);
385 }
386
387 closeSession(session);
388 }
389 }
390
391 return country;
392 }
393
394 public Country findByName(String name)
395 throws NoSuchCountryException, SystemException {
396 Country country = fetchByName(name);
397
398 if (country == null) {
399 StringBundler msg = new StringBundler(4);
400
401 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
402
403 msg.append("name=");
404 msg.append(name);
405
406 msg.append(StringPool.CLOSE_CURLY_BRACE);
407
408 if (_log.isWarnEnabled()) {
409 _log.warn(msg.toString());
410 }
411
412 throw new NoSuchCountryException(msg.toString());
413 }
414
415 return country;
416 }
417
418 public Country fetchByName(String name) throws SystemException {
419 return fetchByName(name, true);
420 }
421
422 public Country fetchByName(String name, boolean retrieveFromCache)
423 throws SystemException {
424 Object[] finderArgs = new Object[] { name };
425
426 Object result = null;
427
428 if (retrieveFromCache) {
429 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
430 finderArgs, this);
431 }
432
433 if (result == null) {
434 Session session = null;
435
436 try {
437 session = openSession();
438
439 StringBundler query = new StringBundler(3);
440
441 query.append(_SQL_SELECT_COUNTRY_WHERE);
442
443 if (name == null) {
444 query.append(_FINDER_COLUMN_NAME_NAME_1);
445 }
446 else {
447 if (name.equals(StringPool.BLANK)) {
448 query.append(_FINDER_COLUMN_NAME_NAME_3);
449 }
450 else {
451 query.append(_FINDER_COLUMN_NAME_NAME_2);
452 }
453 }
454
455 query.append(CountryModelImpl.ORDER_BY_JPQL);
456
457 String sql = query.toString();
458
459 Query q = session.createQuery(sql);
460
461 QueryPos qPos = QueryPos.getInstance(q);
462
463 if (name != null) {
464 qPos.add(name);
465 }
466
467 List<Country> list = q.list();
468
469 result = list;
470
471 Country country = null;
472
473 if (list.isEmpty()) {
474 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
475 finderArgs, list);
476 }
477 else {
478 country = list.get(0);
479
480 cacheResult(country);
481
482 if ((country.getName() == null) ||
483 !country.getName().equals(name)) {
484 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
485 finderArgs, country);
486 }
487 }
488
489 return country;
490 }
491 catch (Exception e) {
492 throw processException(e);
493 }
494 finally {
495 if (result == null) {
496 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
497 finderArgs, new ArrayList<Country>());
498 }
499
500 closeSession(session);
501 }
502 }
503 else {
504 if (result instanceof List<?>) {
505 return null;
506 }
507 else {
508 return (Country)result;
509 }
510 }
511 }
512
513 public Country findByA2(String a2)
514 throws NoSuchCountryException, SystemException {
515 Country country = fetchByA2(a2);
516
517 if (country == null) {
518 StringBundler msg = new StringBundler(4);
519
520 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
521
522 msg.append("a2=");
523 msg.append(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 StringBundler query = new StringBundler(3);
559
560 query.append(_SQL_SELECT_COUNTRY_WHERE);
561
562 if (a2 == null) {
563 query.append(_FINDER_COLUMN_A2_A2_1);
564 }
565 else {
566 if (a2.equals(StringPool.BLANK)) {
567 query.append(_FINDER_COLUMN_A2_A2_3);
568 }
569 else {
570 query.append(_FINDER_COLUMN_A2_A2_2);
571 }
572 }
573
574 query.append(CountryModelImpl.ORDER_BY_JPQL);
575
576 String sql = query.toString();
577
578 Query q = session.createQuery(sql);
579
580 QueryPos qPos = QueryPos.getInstance(q);
581
582 if (a2 != null) {
583 qPos.add(a2);
584 }
585
586 List<Country> list = q.list();
587
588 result = list;
589
590 Country country = null;
591
592 if (list.isEmpty()) {
593 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
594 finderArgs, list);
595 }
596 else {
597 country = list.get(0);
598
599 cacheResult(country);
600
601 if ((country.getA2() == null) ||
602 !country.getA2().equals(a2)) {
603 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
604 finderArgs, country);
605 }
606 }
607
608 return country;
609 }
610 catch (Exception e) {
611 throw processException(e);
612 }
613 finally {
614 if (result == null) {
615 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A2,
616 finderArgs, new ArrayList<Country>());
617 }
618
619 closeSession(session);
620 }
621 }
622 else {
623 if (result instanceof List<?>) {
624 return null;
625 }
626 else {
627 return (Country)result;
628 }
629 }
630 }
631
632 public Country findByA3(String a3)
633 throws NoSuchCountryException, SystemException {
634 Country country = fetchByA3(a3);
635
636 if (country == null) {
637 StringBundler msg = new StringBundler(4);
638
639 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
640
641 msg.append("a3=");
642 msg.append(a3);
643
644 msg.append(StringPool.CLOSE_CURLY_BRACE);
645
646 if (_log.isWarnEnabled()) {
647 _log.warn(msg.toString());
648 }
649
650 throw new NoSuchCountryException(msg.toString());
651 }
652
653 return country;
654 }
655
656 public Country fetchByA3(String a3) throws SystemException {
657 return fetchByA3(a3, true);
658 }
659
660 public Country fetchByA3(String a3, boolean retrieveFromCache)
661 throws SystemException {
662 Object[] finderArgs = new Object[] { a3 };
663
664 Object result = null;
665
666 if (retrieveFromCache) {
667 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A3,
668 finderArgs, this);
669 }
670
671 if (result == null) {
672 Session session = null;
673
674 try {
675 session = openSession();
676
677 StringBundler query = new StringBundler(3);
678
679 query.append(_SQL_SELECT_COUNTRY_WHERE);
680
681 if (a3 == null) {
682 query.append(_FINDER_COLUMN_A3_A3_1);
683 }
684 else {
685 if (a3.equals(StringPool.BLANK)) {
686 query.append(_FINDER_COLUMN_A3_A3_3);
687 }
688 else {
689 query.append(_FINDER_COLUMN_A3_A3_2);
690 }
691 }
692
693 query.append(CountryModelImpl.ORDER_BY_JPQL);
694
695 String sql = query.toString();
696
697 Query q = session.createQuery(sql);
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 StringBundler query = new StringBundler(3);
764
765 query.append(_SQL_SELECT_COUNTRY_WHERE);
766
767 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
768
769 query.append(CountryModelImpl.ORDER_BY_JPQL);
770
771 String sql = query.toString();
772
773 Query q = session.createQuery(sql);
774
775 QueryPos qPos = QueryPos.getInstance(q);
776
777 qPos.add(active);
778
779 list = q.list();
780 }
781 catch (Exception e) {
782 throw processException(e);
783 }
784 finally {
785 if (list == null) {
786 list = new ArrayList<Country>();
787 }
788
789 cacheResult(list);
790
791 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
792 finderArgs, list);
793
794 closeSession(session);
795 }
796 }
797
798 return list;
799 }
800
801 public List<Country> findByActive(boolean active, int start, int end)
802 throws SystemException {
803 return findByActive(active, start, end, null);
804 }
805
806 public List<Country> findByActive(boolean active, int start, int end,
807 OrderByComparator orderByComparator) throws SystemException {
808 Object[] finderArgs = new Object[] {
809 Boolean.valueOf(active),
810
811 String.valueOf(start), String.valueOf(end),
812 String.valueOf(orderByComparator)
813 };
814
815 List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
816 finderArgs, this);
817
818 if (list == null) {
819 Session session = null;
820
821 try {
822 session = openSession();
823
824 StringBundler query = null;
825
826 if (orderByComparator != null) {
827 query = new StringBundler(3 +
828 (orderByComparator.getOrderByFields().length * 3));
829 }
830 else {
831 query = new StringBundler(3);
832 }
833
834 query.append(_SQL_SELECT_COUNTRY_WHERE);
835
836 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
837
838 if (orderByComparator != null) {
839 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
840 orderByComparator);
841 }
842
843 else {
844 query.append(CountryModelImpl.ORDER_BY_JPQL);
845 }
846
847 String sql = query.toString();
848
849 Query q = session.createQuery(sql);
850
851 QueryPos qPos = QueryPos.getInstance(q);
852
853 qPos.add(active);
854
855 list = (List<Country>)QueryUtil.list(q, getDialect(), start, end);
856 }
857 catch (Exception e) {
858 throw processException(e);
859 }
860 finally {
861 if (list == null) {
862 list = new ArrayList<Country>();
863 }
864
865 cacheResult(list);
866
867 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
868 finderArgs, list);
869
870 closeSession(session);
871 }
872 }
873
874 return list;
875 }
876
877 public Country findByActive_First(boolean active,
878 OrderByComparator orderByComparator)
879 throws NoSuchCountryException, SystemException {
880 List<Country> list = findByActive(active, 0, 1, orderByComparator);
881
882 if (list.isEmpty()) {
883 StringBundler msg = new StringBundler(4);
884
885 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
886
887 msg.append("active=");
888 msg.append(active);
889
890 msg.append(StringPool.CLOSE_CURLY_BRACE);
891
892 throw new NoSuchCountryException(msg.toString());
893 }
894 else {
895 return list.get(0);
896 }
897 }
898
899 public Country findByActive_Last(boolean active,
900 OrderByComparator orderByComparator)
901 throws NoSuchCountryException, SystemException {
902 int count = countByActive(active);
903
904 List<Country> list = findByActive(active, count - 1, count,
905 orderByComparator);
906
907 if (list.isEmpty()) {
908 StringBundler msg = new StringBundler(4);
909
910 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
911
912 msg.append("active=");
913 msg.append(active);
914
915 msg.append(StringPool.CLOSE_CURLY_BRACE);
916
917 throw new NoSuchCountryException(msg.toString());
918 }
919 else {
920 return list.get(0);
921 }
922 }
923
924 public Country[] findByActive_PrevAndNext(long countryId, boolean active,
925 OrderByComparator orderByComparator)
926 throws NoSuchCountryException, SystemException {
927 Country country = findByPrimaryKey(countryId);
928
929 int count = countByActive(active);
930
931 Session session = null;
932
933 try {
934 session = openSession();
935
936 StringBundler query = null;
937
938 if (orderByComparator != null) {
939 query = new StringBundler(3 +
940 (orderByComparator.getOrderByFields().length * 3));
941 }
942 else {
943 query = new StringBundler(3);
944 }
945
946 query.append(_SQL_SELECT_COUNTRY_WHERE);
947
948 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
949
950 if (orderByComparator != null) {
951 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
952 orderByComparator);
953 }
954
955 else {
956 query.append(CountryModelImpl.ORDER_BY_JPQL);
957 }
958
959 String sql = query.toString();
960
961 Query q = session.createQuery(sql);
962
963 QueryPos qPos = QueryPos.getInstance(q);
964
965 qPos.add(active);
966
967 Object[] objArray = QueryUtil.getPrevAndNext(q, count,
968 orderByComparator, country);
969
970 Country[] array = new CountryImpl[3];
971
972 array[0] = (Country)objArray[0];
973 array[1] = (Country)objArray[1];
974 array[2] = (Country)objArray[2];
975
976 return array;
977 }
978 catch (Exception e) {
979 throw processException(e);
980 }
981 finally {
982 closeSession(session);
983 }
984 }
985
986 public List<Country> findAll() throws SystemException {
987 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
988 }
989
990 public List<Country> findAll(int start, int end) throws SystemException {
991 return findAll(start, end, null);
992 }
993
994 public List<Country> findAll(int start, int end,
995 OrderByComparator orderByComparator) throws SystemException {
996 Object[] finderArgs = new Object[] {
997 String.valueOf(start), String.valueOf(end),
998 String.valueOf(orderByComparator)
999 };
1000
1001 List<Country> list = (List<Country>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1002 finderArgs, this);
1003
1004 if (list == null) {
1005 Session session = null;
1006
1007 try {
1008 session = openSession();
1009
1010 StringBundler query = null;
1011 String sql = null;
1012
1013 if (orderByComparator != null) {
1014 query = new StringBundler(2 +
1015 (orderByComparator.getOrderByFields().length * 3));
1016
1017 query.append(_SQL_SELECT_COUNTRY);
1018
1019 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1020 orderByComparator);
1021
1022 sql = query.toString();
1023 }
1024
1025 else {
1026 sql = _SQL_SELECT_COUNTRY.concat(CountryModelImpl.ORDER_BY_JPQL);
1027 }
1028
1029 Query q = session.createQuery(sql);
1030
1031 if (orderByComparator == null) {
1032 list = (List<Country>)QueryUtil.list(q, getDialect(),
1033 start, end, false);
1034
1035 Collections.sort(list);
1036 }
1037 else {
1038 list = (List<Country>)QueryUtil.list(q, getDialect(),
1039 start, end);
1040 }
1041 }
1042 catch (Exception e) {
1043 throw processException(e);
1044 }
1045 finally {
1046 if (list == null) {
1047 list = new ArrayList<Country>();
1048 }
1049
1050 cacheResult(list);
1051
1052 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1053
1054 closeSession(session);
1055 }
1056 }
1057
1058 return list;
1059 }
1060
1061 public void removeByName(String name)
1062 throws NoSuchCountryException, SystemException {
1063 Country country = findByName(name);
1064
1065 remove(country);
1066 }
1067
1068 public void removeByA2(String a2)
1069 throws NoSuchCountryException, SystemException {
1070 Country country = findByA2(a2);
1071
1072 remove(country);
1073 }
1074
1075 public void removeByA3(String a3)
1076 throws NoSuchCountryException, SystemException {
1077 Country country = findByA3(a3);
1078
1079 remove(country);
1080 }
1081
1082 public void removeByActive(boolean active) throws SystemException {
1083 for (Country country : findByActive(active)) {
1084 remove(country);
1085 }
1086 }
1087
1088 public void removeAll() throws SystemException {
1089 for (Country country : findAll()) {
1090 remove(country);
1091 }
1092 }
1093
1094 public int countByName(String name) throws SystemException {
1095 Object[] finderArgs = new Object[] { name };
1096
1097 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1098 finderArgs, this);
1099
1100 if (count == null) {
1101 Session session = null;
1102
1103 try {
1104 session = openSession();
1105
1106 StringBundler query = new StringBundler(2);
1107
1108 query.append(_SQL_COUNT_COUNTRY_WHERE);
1109
1110 if (name == null) {
1111 query.append(_FINDER_COLUMN_NAME_NAME_1);
1112 }
1113 else {
1114 if (name.equals(StringPool.BLANK)) {
1115 query.append(_FINDER_COLUMN_NAME_NAME_3);
1116 }
1117 else {
1118 query.append(_FINDER_COLUMN_NAME_NAME_2);
1119 }
1120 }
1121
1122 String sql = query.toString();
1123
1124 Query q = session.createQuery(sql);
1125
1126 QueryPos qPos = QueryPos.getInstance(q);
1127
1128 if (name != null) {
1129 qPos.add(name);
1130 }
1131
1132 count = (Long)q.uniqueResult();
1133 }
1134 catch (Exception e) {
1135 throw processException(e);
1136 }
1137 finally {
1138 if (count == null) {
1139 count = Long.valueOf(0);
1140 }
1141
1142 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1143 finderArgs, count);
1144
1145 closeSession(session);
1146 }
1147 }
1148
1149 return count.intValue();
1150 }
1151
1152 public int countByA2(String a2) throws SystemException {
1153 Object[] finderArgs = new Object[] { a2 };
1154
1155 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A2,
1156 finderArgs, this);
1157
1158 if (count == null) {
1159 Session session = null;
1160
1161 try {
1162 session = openSession();
1163
1164 StringBundler query = new StringBundler(2);
1165
1166 query.append(_SQL_COUNT_COUNTRY_WHERE);
1167
1168 if (a2 == null) {
1169 query.append(_FINDER_COLUMN_A2_A2_1);
1170 }
1171 else {
1172 if (a2.equals(StringPool.BLANK)) {
1173 query.append(_FINDER_COLUMN_A2_A2_3);
1174 }
1175 else {
1176 query.append(_FINDER_COLUMN_A2_A2_2);
1177 }
1178 }
1179
1180 String sql = query.toString();
1181
1182 Query q = session.createQuery(sql);
1183
1184 QueryPos qPos = QueryPos.getInstance(q);
1185
1186 if (a2 != null) {
1187 qPos.add(a2);
1188 }
1189
1190 count = (Long)q.uniqueResult();
1191 }
1192 catch (Exception e) {
1193 throw processException(e);
1194 }
1195 finally {
1196 if (count == null) {
1197 count = Long.valueOf(0);
1198 }
1199
1200 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A2, finderArgs,
1201 count);
1202
1203 closeSession(session);
1204 }
1205 }
1206
1207 return count.intValue();
1208 }
1209
1210 public int countByA3(String a3) throws SystemException {
1211 Object[] finderArgs = new Object[] { a3 };
1212
1213 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A3,
1214 finderArgs, this);
1215
1216 if (count == null) {
1217 Session session = null;
1218
1219 try {
1220 session = openSession();
1221
1222 StringBundler query = new StringBundler(2);
1223
1224 query.append(_SQL_COUNT_COUNTRY_WHERE);
1225
1226 if (a3 == null) {
1227 query.append(_FINDER_COLUMN_A3_A3_1);
1228 }
1229 else {
1230 if (a3.equals(StringPool.BLANK)) {
1231 query.append(_FINDER_COLUMN_A3_A3_3);
1232 }
1233 else {
1234 query.append(_FINDER_COLUMN_A3_A3_2);
1235 }
1236 }
1237
1238 String sql = query.toString();
1239
1240 Query q = session.createQuery(sql);
1241
1242 QueryPos qPos = QueryPos.getInstance(q);
1243
1244 if (a3 != null) {
1245 qPos.add(a3);
1246 }
1247
1248 count = (Long)q.uniqueResult();
1249 }
1250 catch (Exception e) {
1251 throw processException(e);
1252 }
1253 finally {
1254 if (count == null) {
1255 count = Long.valueOf(0);
1256 }
1257
1258 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A3, finderArgs,
1259 count);
1260
1261 closeSession(session);
1262 }
1263 }
1264
1265 return count.intValue();
1266 }
1267
1268 public int countByActive(boolean active) throws SystemException {
1269 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1270
1271 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1272 finderArgs, this);
1273
1274 if (count == null) {
1275 Session session = null;
1276
1277 try {
1278 session = openSession();
1279
1280 StringBundler query = new StringBundler(2);
1281
1282 query.append(_SQL_COUNT_COUNTRY_WHERE);
1283
1284 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1285
1286 String sql = query.toString();
1287
1288 Query q = session.createQuery(sql);
1289
1290 QueryPos qPos = QueryPos.getInstance(q);
1291
1292 qPos.add(active);
1293
1294 count = (Long)q.uniqueResult();
1295 }
1296 catch (Exception e) {
1297 throw processException(e);
1298 }
1299 finally {
1300 if (count == null) {
1301 count = Long.valueOf(0);
1302 }
1303
1304 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1305 finderArgs, count);
1306
1307 closeSession(session);
1308 }
1309 }
1310
1311 return count.intValue();
1312 }
1313
1314 public int countAll() throws SystemException {
1315 Object[] finderArgs = new Object[0];
1316
1317 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1318 finderArgs, this);
1319
1320 if (count == null) {
1321 Session session = null;
1322
1323 try {
1324 session = openSession();
1325
1326 Query q = session.createQuery(_SQL_COUNT_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(type = AccountPersistence.class)
1371 protected AccountPersistence accountPersistence;
1372 @BeanReference(type = AddressPersistence.class)
1373 protected AddressPersistence addressPersistence;
1374 @BeanReference(type = BrowserTrackerPersistence.class)
1375 protected BrowserTrackerPersistence browserTrackerPersistence;
1376 @BeanReference(type = ClassNamePersistence.class)
1377 protected ClassNamePersistence classNamePersistence;
1378 @BeanReference(type = CompanyPersistence.class)
1379 protected CompanyPersistence companyPersistence;
1380 @BeanReference(type = ContactPersistence.class)
1381 protected ContactPersistence contactPersistence;
1382 @BeanReference(type = CountryPersistence.class)
1383 protected CountryPersistence countryPersistence;
1384 @BeanReference(type = EmailAddressPersistence.class)
1385 protected EmailAddressPersistence emailAddressPersistence;
1386 @BeanReference(type = GroupPersistence.class)
1387 protected GroupPersistence groupPersistence;
1388 @BeanReference(type = ImagePersistence.class)
1389 protected ImagePersistence imagePersistence;
1390 @BeanReference(type = LayoutPersistence.class)
1391 protected LayoutPersistence layoutPersistence;
1392 @BeanReference(type = LayoutPrototypePersistence.class)
1393 protected LayoutPrototypePersistence layoutPrototypePersistence;
1394 @BeanReference(type = LayoutSetPersistence.class)
1395 protected LayoutSetPersistence layoutSetPersistence;
1396 @BeanReference(type = LayoutSetPrototypePersistence.class)
1397 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1398 @BeanReference(type = ListTypePersistence.class)
1399 protected ListTypePersistence listTypePersistence;
1400 @BeanReference(type = LockPersistence.class)
1401 protected LockPersistence lockPersistence;
1402 @BeanReference(type = MembershipRequestPersistence.class)
1403 protected MembershipRequestPersistence membershipRequestPersistence;
1404 @BeanReference(type = OrganizationPersistence.class)
1405 protected OrganizationPersistence organizationPersistence;
1406 @BeanReference(type = OrgGroupPermissionPersistence.class)
1407 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1408 @BeanReference(type = OrgGroupRolePersistence.class)
1409 protected OrgGroupRolePersistence orgGroupRolePersistence;
1410 @BeanReference(type = OrgLaborPersistence.class)
1411 protected OrgLaborPersistence orgLaborPersistence;
1412 @BeanReference(type = PasswordPolicyPersistence.class)
1413 protected PasswordPolicyPersistence passwordPolicyPersistence;
1414 @BeanReference(type = PasswordPolicyRelPersistence.class)
1415 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1416 @BeanReference(type = PasswordTrackerPersistence.class)
1417 protected PasswordTrackerPersistence passwordTrackerPersistence;
1418 @BeanReference(type = PermissionPersistence.class)
1419 protected PermissionPersistence permissionPersistence;
1420 @BeanReference(type = PhonePersistence.class)
1421 protected PhonePersistence phonePersistence;
1422 @BeanReference(type = PluginSettingPersistence.class)
1423 protected PluginSettingPersistence pluginSettingPersistence;
1424 @BeanReference(type = PortletPersistence.class)
1425 protected PortletPersistence portletPersistence;
1426 @BeanReference(type = PortletItemPersistence.class)
1427 protected PortletItemPersistence portletItemPersistence;
1428 @BeanReference(type = PortletPreferencesPersistence.class)
1429 protected PortletPreferencesPersistence portletPreferencesPersistence;
1430 @BeanReference(type = RegionPersistence.class)
1431 protected RegionPersistence regionPersistence;
1432 @BeanReference(type = ReleasePersistence.class)
1433 protected ReleasePersistence releasePersistence;
1434 @BeanReference(type = ResourcePersistence.class)
1435 protected ResourcePersistence resourcePersistence;
1436 @BeanReference(type = ResourceActionPersistence.class)
1437 protected ResourceActionPersistence resourceActionPersistence;
1438 @BeanReference(type = ResourceCodePersistence.class)
1439 protected ResourceCodePersistence resourceCodePersistence;
1440 @BeanReference(type = ResourcePermissionPersistence.class)
1441 protected ResourcePermissionPersistence resourcePermissionPersistence;
1442 @BeanReference(type = RolePersistence.class)
1443 protected RolePersistence rolePersistence;
1444 @BeanReference(type = ServiceComponentPersistence.class)
1445 protected ServiceComponentPersistence serviceComponentPersistence;
1446 @BeanReference(type = ShardPersistence.class)
1447 protected ShardPersistence shardPersistence;
1448 @BeanReference(type = SubscriptionPersistence.class)
1449 protected SubscriptionPersistence subscriptionPersistence;
1450 @BeanReference(type = TeamPersistence.class)
1451 protected TeamPersistence teamPersistence;
1452 @BeanReference(type = UserPersistence.class)
1453 protected UserPersistence userPersistence;
1454 @BeanReference(type = UserGroupPersistence.class)
1455 protected UserGroupPersistence userGroupPersistence;
1456 @BeanReference(type = UserGroupGroupRolePersistence.class)
1457 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1458 @BeanReference(type = UserGroupRolePersistence.class)
1459 protected UserGroupRolePersistence userGroupRolePersistence;
1460 @BeanReference(type = UserIdMapperPersistence.class)
1461 protected UserIdMapperPersistence userIdMapperPersistence;
1462 @BeanReference(type = UserTrackerPersistence.class)
1463 protected UserTrackerPersistence userTrackerPersistence;
1464 @BeanReference(type = UserTrackerPathPersistence.class)
1465 protected UserTrackerPathPersistence userTrackerPathPersistence;
1466 @BeanReference(type = WebDAVPropsPersistence.class)
1467 protected WebDAVPropsPersistence webDAVPropsPersistence;
1468 @BeanReference(type = WebsitePersistence.class)
1469 protected WebsitePersistence websitePersistence;
1470 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1471 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1472 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1473 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1474 private static final String _SQL_SELECT_COUNTRY = "SELECT country FROM Country country";
1475 private static final String _SQL_SELECT_COUNTRY_WHERE = "SELECT country FROM Country country WHERE ";
1476 private static final String _SQL_COUNT_COUNTRY = "SELECT COUNT(country) FROM Country country";
1477 private static final String _SQL_COUNT_COUNTRY_WHERE = "SELECT COUNT(country) FROM Country country WHERE ";
1478 private static final String _FINDER_COLUMN_NAME_NAME_1 = "country.name IS NULL";
1479 private static final String _FINDER_COLUMN_NAME_NAME_2 = "country.name = ?";
1480 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(country.name IS NULL OR country.name = ?)";
1481 private static final String _FINDER_COLUMN_A2_A2_1 = "country.a2 IS NULL";
1482 private static final String _FINDER_COLUMN_A2_A2_2 = "country.a2 = ?";
1483 private static final String _FINDER_COLUMN_A2_A2_3 = "(country.a2 IS NULL OR country.a2 = ?)";
1484 private static final String _FINDER_COLUMN_A3_A3_1 = "country.a3 IS NULL";
1485 private static final String _FINDER_COLUMN_A3_A3_2 = "country.a3 = ?";
1486 private static final String _FINDER_COLUMN_A3_A3_3 = "(country.a3 IS NULL OR country.a3 = ?)";
1487 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "country.active = ?";
1488 private static final String _ORDER_BY_ENTITY_ALIAS = "country.";
1489 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Country exists with the primary key ";
1490 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Country exists with the key {";
1491 private static Log _log = LogFactoryUtil.getLog(CountryPersistenceImpl.class);
1492}