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