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