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