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