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