1
19
20 package com.liferay.portal.service.persistence;
21
22 import com.liferay.portal.NoSuchCompanyException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
25 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
26 import com.liferay.portal.kernel.dao.orm.Query;
27 import com.liferay.portal.kernel.dao.orm.QueryPos;
28 import com.liferay.portal.kernel.dao.orm.QueryUtil;
29 import com.liferay.portal.kernel.dao.orm.Session;
30 import com.liferay.portal.kernel.log.Log;
31 import com.liferay.portal.kernel.log.LogFactoryUtil;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.OrderByComparator;
34 import com.liferay.portal.kernel.util.StringPool;
35 import com.liferay.portal.kernel.util.StringUtil;
36 import com.liferay.portal.model.Company;
37 import com.liferay.portal.model.ModelListener;
38 import com.liferay.portal.model.impl.CompanyImpl;
39 import com.liferay.portal.model.impl.CompanyModelImpl;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.Iterator;
45 import java.util.List;
46
47
53 public class CompanyPersistenceImpl extends BasePersistenceImpl
54 implements CompanyPersistence {
55 public Company create(long companyId) {
56 Company company = new CompanyImpl();
57
58 company.setNew(true);
59 company.setPrimaryKey(companyId);
60
61 return company;
62 }
63
64 public Company remove(long companyId)
65 throws NoSuchCompanyException, SystemException {
66 Session session = null;
67
68 try {
69 session = openSession();
70
71 Company company = (Company)session.get(CompanyImpl.class,
72 new Long(companyId));
73
74 if (company == null) {
75 if (_log.isWarnEnabled()) {
76 _log.warn("No Company exists with the primary key " +
77 companyId);
78 }
79
80 throw new NoSuchCompanyException(
81 "No Company exists with the primary key " + companyId);
82 }
83
84 return remove(company);
85 }
86 catch (NoSuchCompanyException nsee) {
87 throw nsee;
88 }
89 catch (Exception e) {
90 throw processException(e);
91 }
92 finally {
93 closeSession(session);
94 }
95 }
96
97 public Company remove(Company company) throws SystemException {
98 for (ModelListener listener : listeners) {
99 listener.onBeforeRemove(company);
100 }
101
102 company = removeImpl(company);
103
104 for (ModelListener listener : listeners) {
105 listener.onAfterRemove(company);
106 }
107
108 return company;
109 }
110
111 protected Company removeImpl(Company company) throws SystemException {
112 Session session = null;
113
114 try {
115 session = openSession();
116
117 if (BatchSessionUtil.isEnabled()) {
118 Object staleObject = session.get(CompanyImpl.class,
119 company.getPrimaryKeyObj());
120
121 if (staleObject != null) {
122 session.evict(staleObject);
123 }
124 }
125
126 session.delete(company);
127
128 session.flush();
129
130 return company;
131 }
132 catch (Exception e) {
133 throw processException(e);
134 }
135 finally {
136 closeSession(session);
137
138 FinderCacheUtil.clearCache(Company.class.getName());
139 }
140 }
141
142
145 public Company update(Company company) throws SystemException {
146 if (_log.isWarnEnabled()) {
147 _log.warn(
148 "Using the deprecated update(Company company) method. Use update(Company company, boolean merge) instead.");
149 }
150
151 return update(company, false);
152 }
153
154
167 public Company update(Company company, boolean merge)
168 throws SystemException {
169 boolean isNew = company.isNew();
170
171 for (ModelListener listener : listeners) {
172 if (isNew) {
173 listener.onBeforeCreate(company);
174 }
175 else {
176 listener.onBeforeUpdate(company);
177 }
178 }
179
180 company = updateImpl(company, merge);
181
182 for (ModelListener listener : listeners) {
183 if (isNew) {
184 listener.onAfterCreate(company);
185 }
186 else {
187 listener.onAfterUpdate(company);
188 }
189 }
190
191 return company;
192 }
193
194 public Company updateImpl(com.liferay.portal.model.Company company,
195 boolean merge) throws SystemException {
196 Session session = null;
197
198 try {
199 session = openSession();
200
201 BatchSessionUtil.update(session, company, merge);
202
203 company.setNew(false);
204
205 return company;
206 }
207 catch (Exception e) {
208 throw processException(e);
209 }
210 finally {
211 closeSession(session);
212
213 FinderCacheUtil.clearCache(Company.class.getName());
214 }
215 }
216
217 public Company findByPrimaryKey(long companyId)
218 throws NoSuchCompanyException, SystemException {
219 Company company = fetchByPrimaryKey(companyId);
220
221 if (company == null) {
222 if (_log.isWarnEnabled()) {
223 _log.warn("No Company exists with the primary key " +
224 companyId);
225 }
226
227 throw new NoSuchCompanyException(
228 "No Company exists with the primary key " + companyId);
229 }
230
231 return company;
232 }
233
234 public Company fetchByPrimaryKey(long companyId) throws SystemException {
235 Session session = null;
236
237 try {
238 session = openSession();
239
240 return (Company)session.get(CompanyImpl.class, new Long(companyId));
241 }
242 catch (Exception e) {
243 throw processException(e);
244 }
245 finally {
246 closeSession(session);
247 }
248 }
249
250 public Company findByWebId(String webId)
251 throws NoSuchCompanyException, SystemException {
252 Company company = fetchByWebId(webId);
253
254 if (company == null) {
255 StringBuilder msg = new StringBuilder();
256
257 msg.append("No Company exists with the key {");
258
259 msg.append("webId=" + webId);
260
261 msg.append(StringPool.CLOSE_CURLY_BRACE);
262
263 if (_log.isWarnEnabled()) {
264 _log.warn(msg.toString());
265 }
266
267 throw new NoSuchCompanyException(msg.toString());
268 }
269
270 return company;
271 }
272
273 public Company fetchByWebId(String webId) throws SystemException {
274 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
275 String finderClassName = Company.class.getName();
276 String finderMethodName = "fetchByWebId";
277 String[] finderParams = new String[] { String.class.getName() };
278 Object[] finderArgs = new Object[] { webId };
279
280 Object result = null;
281
282 if (finderClassNameCacheEnabled) {
283 result = FinderCacheUtil.getResult(finderClassName,
284 finderMethodName, finderParams, finderArgs, this);
285 }
286
287 if (result == null) {
288 Session session = null;
289
290 try {
291 session = openSession();
292
293 StringBuilder query = new StringBuilder();
294
295 query.append("FROM com.liferay.portal.model.Company WHERE ");
296
297 if (webId == null) {
298 query.append("webId IS NULL");
299 }
300 else {
301 query.append("webId = ?");
302 }
303
304 query.append(" ");
305
306 Query q = session.createQuery(query.toString());
307
308 QueryPos qPos = QueryPos.getInstance(q);
309
310 if (webId != null) {
311 qPos.add(webId);
312 }
313
314 List<Company> list = q.list();
315
316 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
317 finderClassName, finderMethodName, finderParams,
318 finderArgs, list);
319
320 if (list.size() == 0) {
321 return null;
322 }
323 else {
324 return list.get(0);
325 }
326 }
327 catch (Exception e) {
328 throw processException(e);
329 }
330 finally {
331 closeSession(session);
332 }
333 }
334 else {
335 List<Company> list = (List<Company>)result;
336
337 if (list.size() == 0) {
338 return null;
339 }
340 else {
341 return list.get(0);
342 }
343 }
344 }
345
346 public Company findByVirtualHost(String virtualHost)
347 throws NoSuchCompanyException, SystemException {
348 Company company = fetchByVirtualHost(virtualHost);
349
350 if (company == null) {
351 StringBuilder msg = new StringBuilder();
352
353 msg.append("No Company exists with the key {");
354
355 msg.append("virtualHost=" + virtualHost);
356
357 msg.append(StringPool.CLOSE_CURLY_BRACE);
358
359 if (_log.isWarnEnabled()) {
360 _log.warn(msg.toString());
361 }
362
363 throw new NoSuchCompanyException(msg.toString());
364 }
365
366 return company;
367 }
368
369 public Company fetchByVirtualHost(String virtualHost)
370 throws SystemException {
371 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
372 String finderClassName = Company.class.getName();
373 String finderMethodName = "fetchByVirtualHost";
374 String[] finderParams = new String[] { String.class.getName() };
375 Object[] finderArgs = new Object[] { virtualHost };
376
377 Object result = null;
378
379 if (finderClassNameCacheEnabled) {
380 result = FinderCacheUtil.getResult(finderClassName,
381 finderMethodName, finderParams, finderArgs, this);
382 }
383
384 if (result == null) {
385 Session session = null;
386
387 try {
388 session = openSession();
389
390 StringBuilder query = new StringBuilder();
391
392 query.append("FROM com.liferay.portal.model.Company WHERE ");
393
394 if (virtualHost == null) {
395 query.append("virtualHost IS NULL");
396 }
397 else {
398 query.append("virtualHost = ?");
399 }
400
401 query.append(" ");
402
403 Query q = session.createQuery(query.toString());
404
405 QueryPos qPos = QueryPos.getInstance(q);
406
407 if (virtualHost != null) {
408 qPos.add(virtualHost);
409 }
410
411 List<Company> list = q.list();
412
413 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
414 finderClassName, finderMethodName, finderParams,
415 finderArgs, list);
416
417 if (list.size() == 0) {
418 return null;
419 }
420 else {
421 return list.get(0);
422 }
423 }
424 catch (Exception e) {
425 throw processException(e);
426 }
427 finally {
428 closeSession(session);
429 }
430 }
431 else {
432 List<Company> list = (List<Company>)result;
433
434 if (list.size() == 0) {
435 return null;
436 }
437 else {
438 return list.get(0);
439 }
440 }
441 }
442
443 public Company findByMx(String mx)
444 throws NoSuchCompanyException, SystemException {
445 Company company = fetchByMx(mx);
446
447 if (company == null) {
448 StringBuilder msg = new StringBuilder();
449
450 msg.append("No Company exists with the key {");
451
452 msg.append("mx=" + mx);
453
454 msg.append(StringPool.CLOSE_CURLY_BRACE);
455
456 if (_log.isWarnEnabled()) {
457 _log.warn(msg.toString());
458 }
459
460 throw new NoSuchCompanyException(msg.toString());
461 }
462
463 return company;
464 }
465
466 public Company fetchByMx(String mx) throws SystemException {
467 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
468 String finderClassName = Company.class.getName();
469 String finderMethodName = "fetchByMx";
470 String[] finderParams = new String[] { String.class.getName() };
471 Object[] finderArgs = new Object[] { mx };
472
473 Object result = null;
474
475 if (finderClassNameCacheEnabled) {
476 result = FinderCacheUtil.getResult(finderClassName,
477 finderMethodName, finderParams, finderArgs, this);
478 }
479
480 if (result == null) {
481 Session session = null;
482
483 try {
484 session = openSession();
485
486 StringBuilder query = new StringBuilder();
487
488 query.append("FROM com.liferay.portal.model.Company WHERE ");
489
490 if (mx == null) {
491 query.append("mx IS NULL");
492 }
493 else {
494 query.append("mx = ?");
495 }
496
497 query.append(" ");
498
499 Query q = session.createQuery(query.toString());
500
501 QueryPos qPos = QueryPos.getInstance(q);
502
503 if (mx != null) {
504 qPos.add(mx);
505 }
506
507 List<Company> list = q.list();
508
509 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
510 finderClassName, finderMethodName, finderParams,
511 finderArgs, list);
512
513 if (list.size() == 0) {
514 return null;
515 }
516 else {
517 return list.get(0);
518 }
519 }
520 catch (Exception e) {
521 throw processException(e);
522 }
523 finally {
524 closeSession(session);
525 }
526 }
527 else {
528 List<Company> list = (List<Company>)result;
529
530 if (list.size() == 0) {
531 return null;
532 }
533 else {
534 return list.get(0);
535 }
536 }
537 }
538
539 public Company findByLogoId(long logoId)
540 throws NoSuchCompanyException, SystemException {
541 Company company = fetchByLogoId(logoId);
542
543 if (company == null) {
544 StringBuilder msg = new StringBuilder();
545
546 msg.append("No Company exists with the key {");
547
548 msg.append("logoId=" + logoId);
549
550 msg.append(StringPool.CLOSE_CURLY_BRACE);
551
552 if (_log.isWarnEnabled()) {
553 _log.warn(msg.toString());
554 }
555
556 throw new NoSuchCompanyException(msg.toString());
557 }
558
559 return company;
560 }
561
562 public Company fetchByLogoId(long logoId) throws SystemException {
563 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
564 String finderClassName = Company.class.getName();
565 String finderMethodName = "fetchByLogoId";
566 String[] finderParams = new String[] { Long.class.getName() };
567 Object[] finderArgs = new Object[] { new Long(logoId) };
568
569 Object result = null;
570
571 if (finderClassNameCacheEnabled) {
572 result = FinderCacheUtil.getResult(finderClassName,
573 finderMethodName, finderParams, finderArgs, this);
574 }
575
576 if (result == null) {
577 Session session = null;
578
579 try {
580 session = openSession();
581
582 StringBuilder query = new StringBuilder();
583
584 query.append("FROM com.liferay.portal.model.Company WHERE ");
585
586 query.append("logoId = ?");
587
588 query.append(" ");
589
590 Query q = session.createQuery(query.toString());
591
592 QueryPos qPos = QueryPos.getInstance(q);
593
594 qPos.add(logoId);
595
596 List<Company> list = q.list();
597
598 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
599 finderClassName, finderMethodName, finderParams,
600 finderArgs, list);
601
602 if (list.size() == 0) {
603 return null;
604 }
605 else {
606 return list.get(0);
607 }
608 }
609 catch (Exception e) {
610 throw processException(e);
611 }
612 finally {
613 closeSession(session);
614 }
615 }
616 else {
617 List<Company> list = (List<Company>)result;
618
619 if (list.size() == 0) {
620 return null;
621 }
622 else {
623 return list.get(0);
624 }
625 }
626 }
627
628 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
629 throws SystemException {
630 Session session = null;
631
632 try {
633 session = openSession();
634
635 dynamicQuery.compile(session);
636
637 return dynamicQuery.list();
638 }
639 catch (Exception e) {
640 throw processException(e);
641 }
642 finally {
643 closeSession(session);
644 }
645 }
646
647 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
648 int start, int end) throws SystemException {
649 Session session = null;
650
651 try {
652 session = openSession();
653
654 dynamicQuery.setLimit(start, end);
655
656 dynamicQuery.compile(session);
657
658 return dynamicQuery.list();
659 }
660 catch (Exception e) {
661 throw processException(e);
662 }
663 finally {
664 closeSession(session);
665 }
666 }
667
668 public List<Company> findAll() throws SystemException {
669 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
670 }
671
672 public List<Company> findAll(int start, int end) throws SystemException {
673 return findAll(start, end, null);
674 }
675
676 public List<Company> findAll(int start, int end, OrderByComparator obc)
677 throws SystemException {
678 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
679 String finderClassName = Company.class.getName();
680 String finderMethodName = "findAll";
681 String[] finderParams = new String[] {
682 "java.lang.Integer", "java.lang.Integer",
683 "com.liferay.portal.kernel.util.OrderByComparator"
684 };
685 Object[] finderArgs = new Object[] {
686 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
687 };
688
689 Object result = null;
690
691 if (finderClassNameCacheEnabled) {
692 result = FinderCacheUtil.getResult(finderClassName,
693 finderMethodName, finderParams, finderArgs, this);
694 }
695
696 if (result == null) {
697 Session session = null;
698
699 try {
700 session = openSession();
701
702 StringBuilder query = new StringBuilder();
703
704 query.append("FROM com.liferay.portal.model.Company ");
705
706 if (obc != null) {
707 query.append("ORDER BY ");
708 query.append(obc.getOrderBy());
709 }
710
711 Query q = session.createQuery(query.toString());
712
713 List<Company> list = null;
714
715 if (obc == null) {
716 list = (List<Company>)QueryUtil.list(q, getDialect(),
717 start, end, false);
718
719 Collections.sort(list);
720 }
721 else {
722 list = (List<Company>)QueryUtil.list(q, getDialect(),
723 start, end);
724 }
725
726 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
727 finderClassName, finderMethodName, finderParams,
728 finderArgs, list);
729
730 return list;
731 }
732 catch (Exception e) {
733 throw processException(e);
734 }
735 finally {
736 closeSession(session);
737 }
738 }
739 else {
740 return (List<Company>)result;
741 }
742 }
743
744 public void removeByWebId(String webId)
745 throws NoSuchCompanyException, SystemException {
746 Company company = findByWebId(webId);
747
748 remove(company);
749 }
750
751 public void removeByVirtualHost(String virtualHost)
752 throws NoSuchCompanyException, SystemException {
753 Company company = findByVirtualHost(virtualHost);
754
755 remove(company);
756 }
757
758 public void removeByMx(String mx)
759 throws NoSuchCompanyException, SystemException {
760 Company company = findByMx(mx);
761
762 remove(company);
763 }
764
765 public void removeByLogoId(long logoId)
766 throws NoSuchCompanyException, SystemException {
767 Company company = findByLogoId(logoId);
768
769 remove(company);
770 }
771
772 public void removeAll() throws SystemException {
773 for (Company company : findAll()) {
774 remove(company);
775 }
776 }
777
778 public int countByWebId(String webId) throws SystemException {
779 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
780 String finderClassName = Company.class.getName();
781 String finderMethodName = "countByWebId";
782 String[] finderParams = new String[] { String.class.getName() };
783 Object[] finderArgs = new Object[] { webId };
784
785 Object result = null;
786
787 if (finderClassNameCacheEnabled) {
788 result = FinderCacheUtil.getResult(finderClassName,
789 finderMethodName, finderParams, finderArgs, this);
790 }
791
792 if (result == null) {
793 Session session = null;
794
795 try {
796 session = openSession();
797
798 StringBuilder query = new StringBuilder();
799
800 query.append("SELECT COUNT(*) ");
801 query.append("FROM com.liferay.portal.model.Company WHERE ");
802
803 if (webId == null) {
804 query.append("webId IS NULL");
805 }
806 else {
807 query.append("webId = ?");
808 }
809
810 query.append(" ");
811
812 Query q = session.createQuery(query.toString());
813
814 QueryPos qPos = QueryPos.getInstance(q);
815
816 if (webId != null) {
817 qPos.add(webId);
818 }
819
820 Long count = null;
821
822 Iterator<Long> itr = q.list().iterator();
823
824 if (itr.hasNext()) {
825 count = itr.next();
826 }
827
828 if (count == null) {
829 count = new Long(0);
830 }
831
832 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
833 finderClassName, finderMethodName, finderParams,
834 finderArgs, count);
835
836 return count.intValue();
837 }
838 catch (Exception e) {
839 throw processException(e);
840 }
841 finally {
842 closeSession(session);
843 }
844 }
845 else {
846 return ((Long)result).intValue();
847 }
848 }
849
850 public int countByVirtualHost(String virtualHost) throws SystemException {
851 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
852 String finderClassName = Company.class.getName();
853 String finderMethodName = "countByVirtualHost";
854 String[] finderParams = new String[] { String.class.getName() };
855 Object[] finderArgs = new Object[] { virtualHost };
856
857 Object result = null;
858
859 if (finderClassNameCacheEnabled) {
860 result = FinderCacheUtil.getResult(finderClassName,
861 finderMethodName, finderParams, finderArgs, this);
862 }
863
864 if (result == null) {
865 Session session = null;
866
867 try {
868 session = openSession();
869
870 StringBuilder query = new StringBuilder();
871
872 query.append("SELECT COUNT(*) ");
873 query.append("FROM com.liferay.portal.model.Company WHERE ");
874
875 if (virtualHost == null) {
876 query.append("virtualHost IS NULL");
877 }
878 else {
879 query.append("virtualHost = ?");
880 }
881
882 query.append(" ");
883
884 Query q = session.createQuery(query.toString());
885
886 QueryPos qPos = QueryPos.getInstance(q);
887
888 if (virtualHost != null) {
889 qPos.add(virtualHost);
890 }
891
892 Long count = null;
893
894 Iterator<Long> itr = q.list().iterator();
895
896 if (itr.hasNext()) {
897 count = itr.next();
898 }
899
900 if (count == null) {
901 count = new Long(0);
902 }
903
904 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
905 finderClassName, finderMethodName, finderParams,
906 finderArgs, count);
907
908 return count.intValue();
909 }
910 catch (Exception e) {
911 throw processException(e);
912 }
913 finally {
914 closeSession(session);
915 }
916 }
917 else {
918 return ((Long)result).intValue();
919 }
920 }
921
922 public int countByMx(String mx) throws SystemException {
923 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
924 String finderClassName = Company.class.getName();
925 String finderMethodName = "countByMx";
926 String[] finderParams = new String[] { String.class.getName() };
927 Object[] finderArgs = new Object[] { mx };
928
929 Object result = null;
930
931 if (finderClassNameCacheEnabled) {
932 result = FinderCacheUtil.getResult(finderClassName,
933 finderMethodName, finderParams, finderArgs, this);
934 }
935
936 if (result == null) {
937 Session session = null;
938
939 try {
940 session = openSession();
941
942 StringBuilder query = new StringBuilder();
943
944 query.append("SELECT COUNT(*) ");
945 query.append("FROM com.liferay.portal.model.Company WHERE ");
946
947 if (mx == null) {
948 query.append("mx IS NULL");
949 }
950 else {
951 query.append("mx = ?");
952 }
953
954 query.append(" ");
955
956 Query q = session.createQuery(query.toString());
957
958 QueryPos qPos = QueryPos.getInstance(q);
959
960 if (mx != null) {
961 qPos.add(mx);
962 }
963
964 Long count = null;
965
966 Iterator<Long> itr = q.list().iterator();
967
968 if (itr.hasNext()) {
969 count = itr.next();
970 }
971
972 if (count == null) {
973 count = new Long(0);
974 }
975
976 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
977 finderClassName, finderMethodName, finderParams,
978 finderArgs, count);
979
980 return count.intValue();
981 }
982 catch (Exception e) {
983 throw processException(e);
984 }
985 finally {
986 closeSession(session);
987 }
988 }
989 else {
990 return ((Long)result).intValue();
991 }
992 }
993
994 public int countByLogoId(long logoId) throws SystemException {
995 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
996 String finderClassName = Company.class.getName();
997 String finderMethodName = "countByLogoId";
998 String[] finderParams = new String[] { Long.class.getName() };
999 Object[] finderArgs = new Object[] { new Long(logoId) };
1000
1001 Object result = null;
1002
1003 if (finderClassNameCacheEnabled) {
1004 result = FinderCacheUtil.getResult(finderClassName,
1005 finderMethodName, finderParams, finderArgs, this);
1006 }
1007
1008 if (result == null) {
1009 Session session = null;
1010
1011 try {
1012 session = openSession();
1013
1014 StringBuilder query = new StringBuilder();
1015
1016 query.append("SELECT COUNT(*) ");
1017 query.append("FROM com.liferay.portal.model.Company WHERE ");
1018
1019 query.append("logoId = ?");
1020
1021 query.append(" ");
1022
1023 Query q = session.createQuery(query.toString());
1024
1025 QueryPos qPos = QueryPos.getInstance(q);
1026
1027 qPos.add(logoId);
1028
1029 Long count = null;
1030
1031 Iterator<Long> itr = q.list().iterator();
1032
1033 if (itr.hasNext()) {
1034 count = itr.next();
1035 }
1036
1037 if (count == null) {
1038 count = new Long(0);
1039 }
1040
1041 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1042 finderClassName, finderMethodName, finderParams,
1043 finderArgs, count);
1044
1045 return count.intValue();
1046 }
1047 catch (Exception e) {
1048 throw processException(e);
1049 }
1050 finally {
1051 closeSession(session);
1052 }
1053 }
1054 else {
1055 return ((Long)result).intValue();
1056 }
1057 }
1058
1059 public int countAll() throws SystemException {
1060 boolean finderClassNameCacheEnabled = CompanyModelImpl.CACHE_ENABLED;
1061 String finderClassName = Company.class.getName();
1062 String finderMethodName = "countAll";
1063 String[] finderParams = new String[] { };
1064 Object[] finderArgs = new Object[] { };
1065
1066 Object result = null;
1067
1068 if (finderClassNameCacheEnabled) {
1069 result = FinderCacheUtil.getResult(finderClassName,
1070 finderMethodName, finderParams, finderArgs, this);
1071 }
1072
1073 if (result == null) {
1074 Session session = null;
1075
1076 try {
1077 session = openSession();
1078
1079 Query q = session.createQuery(
1080 "SELECT COUNT(*) FROM com.liferay.portal.model.Company");
1081
1082 Long count = null;
1083
1084 Iterator<Long> itr = q.list().iterator();
1085
1086 if (itr.hasNext()) {
1087 count = itr.next();
1088 }
1089
1090 if (count == null) {
1091 count = new Long(0);
1092 }
1093
1094 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1095 finderClassName, finderMethodName, finderParams,
1096 finderArgs, count);
1097
1098 return count.intValue();
1099 }
1100 catch (Exception e) {
1101 throw processException(e);
1102 }
1103 finally {
1104 closeSession(session);
1105 }
1106 }
1107 else {
1108 return ((Long)result).intValue();
1109 }
1110 }
1111
1112 public void afterPropertiesSet() {
1113 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1114 com.liferay.portal.util.PropsUtil.get(
1115 "value.object.listener.com.liferay.portal.model.Company")));
1116
1117 if (listenerClassNames.length > 0) {
1118 try {
1119 List<ModelListener> listenersList = new ArrayList<ModelListener>();
1120
1121 for (String listenerClassName : listenerClassNames) {
1122 listenersList.add((ModelListener)Class.forName(
1123 listenerClassName).newInstance());
1124 }
1125
1126 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1127 }
1128 catch (Exception e) {
1129 _log.error(e);
1130 }
1131 }
1132 }
1133
1134 private static Log _log = LogFactoryUtil.getLog(CompanyPersistenceImpl.class);
1135}