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 if (BatchSessionUtil.isEnabled()) {
130 Object staleObject = session.get(OrgGroupRoleImpl.class,
131 orgGroupRole.getPrimaryKeyObj());
132
133 if (staleObject != null) {
134 session.evict(staleObject);
135 }
136 }
137
138 session.delete(orgGroupRole);
139
140 session.flush();
141
142 return orgGroupRole;
143 }
144 catch (Exception e) {
145 throw processException(e);
146 }
147 finally {
148 closeSession(session);
149
150 FinderCacheUtil.clearCache(OrgGroupRole.class.getName());
151 }
152 }
153
154
157 public OrgGroupRole update(OrgGroupRole orgGroupRole)
158 throws SystemException {
159 if (_log.isWarnEnabled()) {
160 _log.warn(
161 "Using the deprecated update(OrgGroupRole orgGroupRole) method. Use update(OrgGroupRole orgGroupRole, boolean merge) instead.");
162 }
163
164 return update(orgGroupRole, false);
165 }
166
167
180 public OrgGroupRole update(OrgGroupRole orgGroupRole, boolean merge)
181 throws SystemException {
182 boolean isNew = orgGroupRole.isNew();
183
184 if (_listeners.length > 0) {
185 for (ModelListener listener : _listeners) {
186 if (isNew) {
187 listener.onBeforeCreate(orgGroupRole);
188 }
189 else {
190 listener.onBeforeUpdate(orgGroupRole);
191 }
192 }
193 }
194
195 orgGroupRole = updateImpl(orgGroupRole, merge);
196
197 if (_listeners.length > 0) {
198 for (ModelListener listener : _listeners) {
199 if (isNew) {
200 listener.onAfterCreate(orgGroupRole);
201 }
202 else {
203 listener.onAfterUpdate(orgGroupRole);
204 }
205 }
206 }
207
208 return orgGroupRole;
209 }
210
211 public OrgGroupRole updateImpl(
212 com.liferay.portal.model.OrgGroupRole orgGroupRole, boolean merge)
213 throws SystemException {
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 BatchSessionUtil.update(session, orgGroupRole, merge);
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 = null;
806
807 if (obc == null) {
808 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
809 start, end, false);
810
811 Collections.sort(list);
812 }
813 else {
814 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
815 start, end);
816 }
817
818 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
819 finderClassName, finderMethodName, finderParams,
820 finderArgs, list);
821
822 return list;
823 }
824 catch (Exception e) {
825 throw processException(e);
826 }
827 finally {
828 closeSession(session);
829 }
830 }
831 else {
832 return (List<OrgGroupRole>)result;
833 }
834 }
835
836 public void removeByGroupId(long groupId) throws SystemException {
837 for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
838 remove(orgGroupRole);
839 }
840 }
841
842 public void removeByRoleId(long roleId) throws SystemException {
843 for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
844 remove(orgGroupRole);
845 }
846 }
847
848 public void removeAll() throws SystemException {
849 for (OrgGroupRole orgGroupRole : findAll()) {
850 remove(orgGroupRole);
851 }
852 }
853
854 public int countByGroupId(long groupId) throws SystemException {
855 boolean finderClassNameCacheEnabled = OrgGroupRoleModelImpl.CACHE_ENABLED;
856 String finderClassName = OrgGroupRole.class.getName();
857 String finderMethodName = "countByGroupId";
858 String[] finderParams = new String[] { Long.class.getName() };
859 Object[] finderArgs = new Object[] { new Long(groupId) };
860
861 Object result = null;
862
863 if (finderClassNameCacheEnabled) {
864 result = FinderCacheUtil.getResult(finderClassName,
865 finderMethodName, finderParams, finderArgs, this);
866 }
867
868 if (result == null) {
869 Session session = null;
870
871 try {
872 session = openSession();
873
874 StringBuilder query = new StringBuilder();
875
876 query.append("SELECT COUNT(*) ");
877 query.append(
878 "FROM com.liferay.portal.model.OrgGroupRole WHERE ");
879
880 query.append("groupId = ?");
881
882 query.append(" ");
883
884 Query q = session.createQuery(query.toString());
885
886 QueryPos qPos = QueryPos.getInstance(q);
887
888 qPos.add(groupId);
889
890 Long count = null;
891
892 Iterator<Long> itr = q.list().iterator();
893
894 if (itr.hasNext()) {
895 count = itr.next();
896 }
897
898 if (count == null) {
899 count = new Long(0);
900 }
901
902 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
903 finderClassName, finderMethodName, finderParams,
904 finderArgs, count);
905
906 return count.intValue();
907 }
908 catch (Exception e) {
909 throw processException(e);
910 }
911 finally {
912 closeSession(session);
913 }
914 }
915 else {
916 return ((Long)result).intValue();
917 }
918 }
919
920 public int countByRoleId(long roleId) throws SystemException {
921 boolean finderClassNameCacheEnabled = OrgGroupRoleModelImpl.CACHE_ENABLED;
922 String finderClassName = OrgGroupRole.class.getName();
923 String finderMethodName = "countByRoleId";
924 String[] finderParams = new String[] { Long.class.getName() };
925 Object[] finderArgs = new Object[] { new Long(roleId) };
926
927 Object result = null;
928
929 if (finderClassNameCacheEnabled) {
930 result = FinderCacheUtil.getResult(finderClassName,
931 finderMethodName, finderParams, finderArgs, this);
932 }
933
934 if (result == null) {
935 Session session = null;
936
937 try {
938 session = openSession();
939
940 StringBuilder query = new StringBuilder();
941
942 query.append("SELECT COUNT(*) ");
943 query.append(
944 "FROM com.liferay.portal.model.OrgGroupRole WHERE ");
945
946 query.append("roleId = ?");
947
948 query.append(" ");
949
950 Query q = session.createQuery(query.toString());
951
952 QueryPos qPos = QueryPos.getInstance(q);
953
954 qPos.add(roleId);
955
956 Long count = null;
957
958 Iterator<Long> itr = q.list().iterator();
959
960 if (itr.hasNext()) {
961 count = itr.next();
962 }
963
964 if (count == null) {
965 count = new Long(0);
966 }
967
968 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
969 finderClassName, finderMethodName, finderParams,
970 finderArgs, count);
971
972 return count.intValue();
973 }
974 catch (Exception e) {
975 throw processException(e);
976 }
977 finally {
978 closeSession(session);
979 }
980 }
981 else {
982 return ((Long)result).intValue();
983 }
984 }
985
986 public int countAll() throws SystemException {
987 boolean finderClassNameCacheEnabled = OrgGroupRoleModelImpl.CACHE_ENABLED;
988 String finderClassName = OrgGroupRole.class.getName();
989 String finderMethodName = "countAll";
990 String[] finderParams = new String[] { };
991 Object[] finderArgs = new Object[] { };
992
993 Object result = null;
994
995 if (finderClassNameCacheEnabled) {
996 result = FinderCacheUtil.getResult(finderClassName,
997 finderMethodName, finderParams, finderArgs, this);
998 }
999
1000 if (result == null) {
1001 Session session = null;
1002
1003 try {
1004 session = openSession();
1005
1006 Query q = session.createQuery(
1007 "SELECT COUNT(*) FROM com.liferay.portal.model.OrgGroupRole");
1008
1009 Long count = null;
1010
1011 Iterator<Long> itr = q.list().iterator();
1012
1013 if (itr.hasNext()) {
1014 count = itr.next();
1015 }
1016
1017 if (count == null) {
1018 count = new Long(0);
1019 }
1020
1021 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1022 finderClassName, finderMethodName, finderParams,
1023 finderArgs, count);
1024
1025 return count.intValue();
1026 }
1027 catch (Exception e) {
1028 throw processException(e);
1029 }
1030 finally {
1031 closeSession(session);
1032 }
1033 }
1034 else {
1035 return ((Long)result).intValue();
1036 }
1037 }
1038
1039 public void registerListener(ModelListener listener) {
1040 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1041
1042 listeners.add(listener);
1043
1044 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1045 }
1046
1047 public void unregisterListener(ModelListener listener) {
1048 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1049
1050 listeners.remove(listener);
1051
1052 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1053 }
1054
1055 public void afterPropertiesSet() {
1056 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1057 com.liferay.portal.util.PropsUtil.get(
1058 "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1059
1060 if (listenerClassNames.length > 0) {
1061 try {
1062 List<ModelListener> listeners = new ArrayList<ModelListener>();
1063
1064 for (String listenerClassName : listenerClassNames) {
1065 listeners.add((ModelListener)Class.forName(
1066 listenerClassName).newInstance());
1067 }
1068
1069 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1070 }
1071 catch (Exception e) {
1072 _log.error(e);
1073 }
1074 }
1075 }
1076
1077 private static Log _log = LogFactory.getLog(OrgGroupRolePersistenceImpl.class);
1078 private ModelListener[] _listeners = new ModelListener[0];
1079}