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