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.annotation.BeanReference;
28 import com.liferay.portal.kernel.cache.CacheRegistry;
29 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32 import com.liferay.portal.kernel.dao.orm.FinderPath;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryPos;
35 import com.liferay.portal.kernel.dao.orm.QueryUtil;
36 import com.liferay.portal.kernel.dao.orm.Session;
37 import com.liferay.portal.kernel.log.Log;
38 import com.liferay.portal.kernel.log.LogFactoryUtil;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.OrderByComparator;
41 import com.liferay.portal.kernel.util.StringPool;
42 import com.liferay.portal.kernel.util.StringUtil;
43 import com.liferay.portal.model.ModelListener;
44 import com.liferay.portal.model.OrgGroupRole;
45 import com.liferay.portal.model.impl.OrgGroupRoleImpl;
46 import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
47 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.List;
52
53
66 public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl
67 implements OrgGroupRolePersistence {
68 public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
69 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70 ".List";
71 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
72 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73 "findByGroupId", new String[] { Long.class.getName() });
74 public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
75 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
76 "findByGroupId",
77 new String[] {
78 Long.class.getName(),
79
80 "java.lang.Integer", "java.lang.Integer",
81 "com.liferay.portal.kernel.util.OrderByComparator"
82 });
83 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
84 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
85 "countByGroupId", new String[] { Long.class.getName() });
86 public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
87 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88 "findByRoleId", new String[] { Long.class.getName() });
89 public static final FinderPath FINDER_PATH_FIND_BY_OBC_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
90 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
91 "findByRoleId",
92 new String[] {
93 Long.class.getName(),
94
95 "java.lang.Integer", "java.lang.Integer",
96 "com.liferay.portal.kernel.util.OrderByComparator"
97 });
98 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
99 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100 "countByRoleId", new String[] { Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
102 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103 "findAll", new String[0]);
104 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
105 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106 "countAll", new String[0]);
107
108 public void cacheResult(OrgGroupRole orgGroupRole) {
109 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
110 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
111 }
112
113 public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
114 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
115 if (EntityCacheUtil.getResult(
116 OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
117 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(),
118 this) == null) {
119 cacheResult(orgGroupRole);
120 }
121 }
122 }
123
124 public void clearCache() {
125 CacheRegistry.clear(OrgGroupRoleImpl.class.getName());
126 EntityCacheUtil.clearCache(OrgGroupRoleImpl.class.getName());
127 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
128 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
129 }
130
131 public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
132 OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
133
134 orgGroupRole.setNew(true);
135 orgGroupRole.setPrimaryKey(orgGroupRolePK);
136
137 return orgGroupRole;
138 }
139
140 public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
141 throws NoSuchOrgGroupRoleException, SystemException {
142 Session session = null;
143
144 try {
145 session = openSession();
146
147 OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
148 orgGroupRolePK);
149
150 if (orgGroupRole == null) {
151 if (_log.isWarnEnabled()) {
152 _log.warn("No OrgGroupRole exists with the primary key " +
153 orgGroupRolePK);
154 }
155
156 throw new NoSuchOrgGroupRoleException(
157 "No OrgGroupRole exists with the primary key " +
158 orgGroupRolePK);
159 }
160
161 return remove(orgGroupRole);
162 }
163 catch (NoSuchOrgGroupRoleException nsee) {
164 throw nsee;
165 }
166 catch (Exception e) {
167 throw processException(e);
168 }
169 finally {
170 closeSession(session);
171 }
172 }
173
174 public OrgGroupRole remove(OrgGroupRole orgGroupRole)
175 throws SystemException {
176 for (ModelListener<OrgGroupRole> listener : listeners) {
177 listener.onBeforeRemove(orgGroupRole);
178 }
179
180 orgGroupRole = removeImpl(orgGroupRole);
181
182 for (ModelListener<OrgGroupRole> listener : listeners) {
183 listener.onAfterRemove(orgGroupRole);
184 }
185
186 return orgGroupRole;
187 }
188
189 protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole)
190 throws SystemException {
191 orgGroupRole = toUnwrappedModel(orgGroupRole);
192
193 Session session = null;
194
195 try {
196 session = openSession();
197
198 if (orgGroupRole.isCachedModel() || BatchSessionUtil.isEnabled()) {
199 Object staleObject = session.get(OrgGroupRoleImpl.class,
200 orgGroupRole.getPrimaryKeyObj());
201
202 if (staleObject != null) {
203 session.evict(staleObject);
204 }
205 }
206
207 session.delete(orgGroupRole);
208
209 session.flush();
210 }
211 catch (Exception e) {
212 throw processException(e);
213 }
214 finally {
215 closeSession(session);
216 }
217
218 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
219
220 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
221 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
222
223 return orgGroupRole;
224 }
225
226
229 public OrgGroupRole update(OrgGroupRole orgGroupRole)
230 throws SystemException {
231 if (_log.isWarnEnabled()) {
232 _log.warn(
233 "Using the deprecated update(OrgGroupRole orgGroupRole) method. Use update(OrgGroupRole orgGroupRole, boolean merge) instead.");
234 }
235
236 return update(orgGroupRole, false);
237 }
238
239
251 public OrgGroupRole update(OrgGroupRole orgGroupRole, boolean merge)
252 throws SystemException {
253 boolean isNew = orgGroupRole.isNew();
254
255 for (ModelListener<OrgGroupRole> listener : listeners) {
256 if (isNew) {
257 listener.onBeforeCreate(orgGroupRole);
258 }
259 else {
260 listener.onBeforeUpdate(orgGroupRole);
261 }
262 }
263
264 orgGroupRole = updateImpl(orgGroupRole, merge);
265
266 for (ModelListener<OrgGroupRole> listener : listeners) {
267 if (isNew) {
268 listener.onAfterCreate(orgGroupRole);
269 }
270 else {
271 listener.onAfterUpdate(orgGroupRole);
272 }
273 }
274
275 return orgGroupRole;
276 }
277
278 public OrgGroupRole updateImpl(
279 com.liferay.portal.model.OrgGroupRole orgGroupRole, boolean merge)
280 throws SystemException {
281 orgGroupRole = toUnwrappedModel(orgGroupRole);
282
283 Session session = null;
284
285 try {
286 session = openSession();
287
288 BatchSessionUtil.update(session, orgGroupRole, merge);
289
290 orgGroupRole.setNew(false);
291 }
292 catch (Exception e) {
293 throw processException(e);
294 }
295 finally {
296 closeSession(session);
297 }
298
299 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
300
301 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
302 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
303
304 return orgGroupRole;
305 }
306
307 protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
308 if (orgGroupRole instanceof OrgGroupRoleImpl) {
309 return orgGroupRole;
310 }
311
312 OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
313
314 orgGroupRoleImpl.setNew(orgGroupRole.isNew());
315 orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
316
317 orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
318 orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
319 orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
320
321 return orgGroupRoleImpl;
322 }
323
324 public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
325 throws NoSuchOrgGroupRoleException, SystemException {
326 OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
327
328 if (orgGroupRole == null) {
329 if (_log.isWarnEnabled()) {
330 _log.warn("No OrgGroupRole exists with the primary key " +
331 orgGroupRolePK);
332 }
333
334 throw new NoSuchOrgGroupRoleException(
335 "No OrgGroupRole exists with the primary key " +
336 orgGroupRolePK);
337 }
338
339 return orgGroupRole;
340 }
341
342 public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
343 throws SystemException {
344 OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
345 OrgGroupRoleImpl.class, orgGroupRolePK, this);
346
347 if (orgGroupRole == null) {
348 Session session = null;
349
350 try {
351 session = openSession();
352
353 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
354 orgGroupRolePK);
355 }
356 catch (Exception e) {
357 throw processException(e);
358 }
359 finally {
360 if (orgGroupRole != null) {
361 cacheResult(orgGroupRole);
362 }
363
364 closeSession(session);
365 }
366 }
367
368 return orgGroupRole;
369 }
370
371 public List<OrgGroupRole> findByGroupId(long groupId)
372 throws SystemException {
373 Object[] finderArgs = new Object[] { new Long(groupId) };
374
375 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
376 finderArgs, this);
377
378 if (list == null) {
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 StringBuilder query = new StringBuilder();
385
386 query.append(
387 "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ");
388
389 query.append("orgGroupRole.id.groupId = ?");
390
391 query.append(" ");
392
393 Query q = session.createQuery(query.toString());
394
395 QueryPos qPos = QueryPos.getInstance(q);
396
397 qPos.add(groupId);
398
399 list = q.list();
400 }
401 catch (Exception e) {
402 throw processException(e);
403 }
404 finally {
405 if (list == null) {
406 list = new ArrayList<OrgGroupRole>();
407 }
408
409 cacheResult(list);
410
411 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
412 finderArgs, list);
413
414 closeSession(session);
415 }
416 }
417
418 return list;
419 }
420
421 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
422 throws SystemException {
423 return findByGroupId(groupId, start, end, null);
424 }
425
426 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
427 OrderByComparator obc) throws SystemException {
428 Object[] finderArgs = new Object[] {
429 new Long(groupId),
430
431 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
432 };
433
434 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
435 finderArgs, this);
436
437 if (list == null) {
438 Session session = null;
439
440 try {
441 session = openSession();
442
443 StringBuilder query = new StringBuilder();
444
445 query.append(
446 "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ");
447
448 query.append("orgGroupRole.id.groupId = ?");
449
450 query.append(" ");
451
452 if (obc != null) {
453 query.append("ORDER BY ");
454
455 String[] orderByFields = obc.getOrderByFields();
456
457 for (int i = 0; i < orderByFields.length; i++) {
458 query.append("orgGroupRole.");
459 query.append(orderByFields[i]);
460
461 if (obc.isAscending()) {
462 query.append(" ASC");
463 }
464 else {
465 query.append(" DESC");
466 }
467
468 if ((i + 1) < orderByFields.length) {
469 query.append(", ");
470 }
471 }
472 }
473
474 Query q = session.createQuery(query.toString());
475
476 QueryPos qPos = QueryPos.getInstance(q);
477
478 qPos.add(groupId);
479
480 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
481 start, end);
482 }
483 catch (Exception e) {
484 throw processException(e);
485 }
486 finally {
487 if (list == null) {
488 list = new ArrayList<OrgGroupRole>();
489 }
490
491 cacheResult(list);
492
493 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
494 finderArgs, list);
495
496 closeSession(session);
497 }
498 }
499
500 return list;
501 }
502
503 public OrgGroupRole findByGroupId_First(long groupId, OrderByComparator obc)
504 throws NoSuchOrgGroupRoleException, SystemException {
505 List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, obc);
506
507 if (list.isEmpty()) {
508 StringBuilder msg = new StringBuilder();
509
510 msg.append("No OrgGroupRole exists with the key {");
511
512 msg.append("groupId=" + groupId);
513
514 msg.append(StringPool.CLOSE_CURLY_BRACE);
515
516 throw new NoSuchOrgGroupRoleException(msg.toString());
517 }
518 else {
519 return list.get(0);
520 }
521 }
522
523 public OrgGroupRole findByGroupId_Last(long groupId, OrderByComparator obc)
524 throws NoSuchOrgGroupRoleException, SystemException {
525 int count = countByGroupId(groupId);
526
527 List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count, obc);
528
529 if (list.isEmpty()) {
530 StringBuilder msg = new StringBuilder();
531
532 msg.append("No OrgGroupRole exists with the key {");
533
534 msg.append("groupId=" + groupId);
535
536 msg.append(StringPool.CLOSE_CURLY_BRACE);
537
538 throw new NoSuchOrgGroupRoleException(msg.toString());
539 }
540 else {
541 return list.get(0);
542 }
543 }
544
545 public OrgGroupRole[] findByGroupId_PrevAndNext(
546 OrgGroupRolePK orgGroupRolePK, long groupId, OrderByComparator obc)
547 throws NoSuchOrgGroupRoleException, SystemException {
548 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
549
550 int count = countByGroupId(groupId);
551
552 Session session = null;
553
554 try {
555 session = openSession();
556
557 StringBuilder query = new StringBuilder();
558
559 query.append(
560 "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ");
561
562 query.append("orgGroupRole.id.groupId = ?");
563
564 query.append(" ");
565
566 if (obc != null) {
567 query.append("ORDER BY ");
568
569 String[] orderByFields = obc.getOrderByFields();
570
571 for (int i = 0; i < orderByFields.length; i++) {
572 query.append("orgGroupRole.");
573 query.append(orderByFields[i]);
574
575 if (obc.isAscending()) {
576 query.append(" ASC");
577 }
578 else {
579 query.append(" DESC");
580 }
581
582 if ((i + 1) < orderByFields.length) {
583 query.append(", ");
584 }
585 }
586 }
587
588 Query q = session.createQuery(query.toString());
589
590 QueryPos qPos = QueryPos.getInstance(q);
591
592 qPos.add(groupId);
593
594 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
595 orgGroupRole);
596
597 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
598
599 array[0] = (OrgGroupRole)objArray[0];
600 array[1] = (OrgGroupRole)objArray[1];
601 array[2] = (OrgGroupRole)objArray[2];
602
603 return array;
604 }
605 catch (Exception e) {
606 throw processException(e);
607 }
608 finally {
609 closeSession(session);
610 }
611 }
612
613 public List<OrgGroupRole> findByRoleId(long roleId)
614 throws SystemException {
615 Object[] finderArgs = new Object[] { new Long(roleId) };
616
617 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
618 finderArgs, this);
619
620 if (list == null) {
621 Session session = null;
622
623 try {
624 session = openSession();
625
626 StringBuilder query = new StringBuilder();
627
628 query.append(
629 "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ");
630
631 query.append("orgGroupRole.id.roleId = ?");
632
633 query.append(" ");
634
635 Query q = session.createQuery(query.toString());
636
637 QueryPos qPos = QueryPos.getInstance(q);
638
639 qPos.add(roleId);
640
641 list = q.list();
642 }
643 catch (Exception e) {
644 throw processException(e);
645 }
646 finally {
647 if (list == null) {
648 list = new ArrayList<OrgGroupRole>();
649 }
650
651 cacheResult(list);
652
653 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
654 finderArgs, list);
655
656 closeSession(session);
657 }
658 }
659
660 return list;
661 }
662
663 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
664 throws SystemException {
665 return findByRoleId(roleId, start, end, null);
666 }
667
668 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
669 OrderByComparator obc) throws SystemException {
670 Object[] finderArgs = new Object[] {
671 new Long(roleId),
672
673 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
674 };
675
676 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ROLEID,
677 finderArgs, this);
678
679 if (list == null) {
680 Session session = null;
681
682 try {
683 session = openSession();
684
685 StringBuilder query = new StringBuilder();
686
687 query.append(
688 "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ");
689
690 query.append("orgGroupRole.id.roleId = ?");
691
692 query.append(" ");
693
694 if (obc != null) {
695 query.append("ORDER BY ");
696
697 String[] orderByFields = obc.getOrderByFields();
698
699 for (int i = 0; i < orderByFields.length; i++) {
700 query.append("orgGroupRole.");
701 query.append(orderByFields[i]);
702
703 if (obc.isAscending()) {
704 query.append(" ASC");
705 }
706 else {
707 query.append(" DESC");
708 }
709
710 if ((i + 1) < orderByFields.length) {
711 query.append(", ");
712 }
713 }
714 }
715
716 Query q = session.createQuery(query.toString());
717
718 QueryPos qPos = QueryPos.getInstance(q);
719
720 qPos.add(roleId);
721
722 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
723 start, end);
724 }
725 catch (Exception e) {
726 throw processException(e);
727 }
728 finally {
729 if (list == null) {
730 list = new ArrayList<OrgGroupRole>();
731 }
732
733 cacheResult(list);
734
735 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ROLEID,
736 finderArgs, list);
737
738 closeSession(session);
739 }
740 }
741
742 return list;
743 }
744
745 public OrgGroupRole findByRoleId_First(long roleId, OrderByComparator obc)
746 throws NoSuchOrgGroupRoleException, SystemException {
747 List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, obc);
748
749 if (list.isEmpty()) {
750 StringBuilder msg = new StringBuilder();
751
752 msg.append("No OrgGroupRole exists with the key {");
753
754 msg.append("roleId=" + roleId);
755
756 msg.append(StringPool.CLOSE_CURLY_BRACE);
757
758 throw new NoSuchOrgGroupRoleException(msg.toString());
759 }
760 else {
761 return list.get(0);
762 }
763 }
764
765 public OrgGroupRole findByRoleId_Last(long roleId, OrderByComparator obc)
766 throws NoSuchOrgGroupRoleException, SystemException {
767 int count = countByRoleId(roleId);
768
769 List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count, obc);
770
771 if (list.isEmpty()) {
772 StringBuilder msg = new StringBuilder();
773
774 msg.append("No OrgGroupRole exists with the key {");
775
776 msg.append("roleId=" + roleId);
777
778 msg.append(StringPool.CLOSE_CURLY_BRACE);
779
780 throw new NoSuchOrgGroupRoleException(msg.toString());
781 }
782 else {
783 return list.get(0);
784 }
785 }
786
787 public OrgGroupRole[] findByRoleId_PrevAndNext(
788 OrgGroupRolePK orgGroupRolePK, long roleId, OrderByComparator obc)
789 throws NoSuchOrgGroupRoleException, SystemException {
790 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
791
792 int count = countByRoleId(roleId);
793
794 Session session = null;
795
796 try {
797 session = openSession();
798
799 StringBuilder query = new StringBuilder();
800
801 query.append(
802 "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ");
803
804 query.append("orgGroupRole.id.roleId = ?");
805
806 query.append(" ");
807
808 if (obc != null) {
809 query.append("ORDER BY ");
810
811 String[] orderByFields = obc.getOrderByFields();
812
813 for (int i = 0; i < orderByFields.length; i++) {
814 query.append("orgGroupRole.");
815 query.append(orderByFields[i]);
816
817 if (obc.isAscending()) {
818 query.append(" ASC");
819 }
820 else {
821 query.append(" DESC");
822 }
823
824 if ((i + 1) < orderByFields.length) {
825 query.append(", ");
826 }
827 }
828 }
829
830 Query q = session.createQuery(query.toString());
831
832 QueryPos qPos = QueryPos.getInstance(q);
833
834 qPos.add(roleId);
835
836 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
837 orgGroupRole);
838
839 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
840
841 array[0] = (OrgGroupRole)objArray[0];
842 array[1] = (OrgGroupRole)objArray[1];
843 array[2] = (OrgGroupRole)objArray[2];
844
845 return array;
846 }
847 catch (Exception e) {
848 throw processException(e);
849 }
850 finally {
851 closeSession(session);
852 }
853 }
854
855 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
856 throws SystemException {
857 Session session = null;
858
859 try {
860 session = openSession();
861
862 dynamicQuery.compile(session);
863
864 return dynamicQuery.list();
865 }
866 catch (Exception e) {
867 throw processException(e);
868 }
869 finally {
870 closeSession(session);
871 }
872 }
873
874 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
875 int start, int end) throws SystemException {
876 Session session = null;
877
878 try {
879 session = openSession();
880
881 dynamicQuery.setLimit(start, end);
882
883 dynamicQuery.compile(session);
884
885 return dynamicQuery.list();
886 }
887 catch (Exception e) {
888 throw processException(e);
889 }
890 finally {
891 closeSession(session);
892 }
893 }
894
895 public List<OrgGroupRole> findAll() throws SystemException {
896 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
897 }
898
899 public List<OrgGroupRole> findAll(int start, int end)
900 throws SystemException {
901 return findAll(start, end, null);
902 }
903
904 public List<OrgGroupRole> findAll(int start, int end, OrderByComparator obc)
905 throws SystemException {
906 Object[] finderArgs = new Object[] {
907 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
908 };
909
910 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
911 finderArgs, this);
912
913 if (list == null) {
914 Session session = null;
915
916 try {
917 session = openSession();
918
919 StringBuilder query = new StringBuilder();
920
921 query.append(
922 "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole ");
923
924 if (obc != null) {
925 query.append("ORDER BY ");
926
927 String[] orderByFields = obc.getOrderByFields();
928
929 for (int i = 0; i < orderByFields.length; i++) {
930 query.append("orgGroupRole.");
931 query.append(orderByFields[i]);
932
933 if (obc.isAscending()) {
934 query.append(" ASC");
935 }
936 else {
937 query.append(" DESC");
938 }
939
940 if ((i + 1) < orderByFields.length) {
941 query.append(", ");
942 }
943 }
944 }
945
946 Query q = session.createQuery(query.toString());
947
948 if (obc == null) {
949 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
950 start, end, false);
951
952 Collections.sort(list);
953 }
954 else {
955 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
956 start, end);
957 }
958 }
959 catch (Exception e) {
960 throw processException(e);
961 }
962 finally {
963 if (list == null) {
964 list = new ArrayList<OrgGroupRole>();
965 }
966
967 cacheResult(list);
968
969 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
970
971 closeSession(session);
972 }
973 }
974
975 return list;
976 }
977
978 public void removeByGroupId(long groupId) throws SystemException {
979 for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
980 remove(orgGroupRole);
981 }
982 }
983
984 public void removeByRoleId(long roleId) throws SystemException {
985 for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
986 remove(orgGroupRole);
987 }
988 }
989
990 public void removeAll() throws SystemException {
991 for (OrgGroupRole orgGroupRole : findAll()) {
992 remove(orgGroupRole);
993 }
994 }
995
996 public int countByGroupId(long groupId) throws SystemException {
997 Object[] finderArgs = new Object[] { new Long(groupId) };
998
999 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1000 finderArgs, this);
1001
1002 if (count == null) {
1003 Session session = null;
1004
1005 try {
1006 session = openSession();
1007
1008 StringBuilder query = new StringBuilder();
1009
1010 query.append("SELECT COUNT(orgGroupRole) ");
1011 query.append("FROM OrgGroupRole orgGroupRole WHERE ");
1012
1013 query.append("orgGroupRole.id.groupId = ?");
1014
1015 query.append(" ");
1016
1017 Query q = session.createQuery(query.toString());
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 qPos.add(groupId);
1022
1023 count = (Long)q.uniqueResult();
1024 }
1025 catch (Exception e) {
1026 throw processException(e);
1027 }
1028 finally {
1029 if (count == null) {
1030 count = Long.valueOf(0);
1031 }
1032
1033 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1034 finderArgs, count);
1035
1036 closeSession(session);
1037 }
1038 }
1039
1040 return count.intValue();
1041 }
1042
1043 public int countByRoleId(long roleId) throws SystemException {
1044 Object[] finderArgs = new Object[] { new Long(roleId) };
1045
1046 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1047 finderArgs, this);
1048
1049 if (count == null) {
1050 Session session = null;
1051
1052 try {
1053 session = openSession();
1054
1055 StringBuilder query = new StringBuilder();
1056
1057 query.append("SELECT COUNT(orgGroupRole) ");
1058 query.append("FROM OrgGroupRole orgGroupRole WHERE ");
1059
1060 query.append("orgGroupRole.id.roleId = ?");
1061
1062 query.append(" ");
1063
1064 Query q = session.createQuery(query.toString());
1065
1066 QueryPos qPos = QueryPos.getInstance(q);
1067
1068 qPos.add(roleId);
1069
1070 count = (Long)q.uniqueResult();
1071 }
1072 catch (Exception e) {
1073 throw processException(e);
1074 }
1075 finally {
1076 if (count == null) {
1077 count = Long.valueOf(0);
1078 }
1079
1080 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1081 finderArgs, count);
1082
1083 closeSession(session);
1084 }
1085 }
1086
1087 return count.intValue();
1088 }
1089
1090 public int countAll() throws SystemException {
1091 Object[] finderArgs = new Object[0];
1092
1093 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1094 finderArgs, this);
1095
1096 if (count == null) {
1097 Session session = null;
1098
1099 try {
1100 session = openSession();
1101
1102 Query q = session.createQuery(
1103 "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole");
1104
1105 count = (Long)q.uniqueResult();
1106 }
1107 catch (Exception e) {
1108 throw processException(e);
1109 }
1110 finally {
1111 if (count == null) {
1112 count = Long.valueOf(0);
1113 }
1114
1115 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1116 count);
1117
1118 closeSession(session);
1119 }
1120 }
1121
1122 return count.intValue();
1123 }
1124
1125 public void afterPropertiesSet() {
1126 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1127 com.liferay.portal.util.PropsUtil.get(
1128 "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1129
1130 if (listenerClassNames.length > 0) {
1131 try {
1132 List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1133
1134 for (String listenerClassName : listenerClassNames) {
1135 listenersList.add((ModelListener<OrgGroupRole>)Class.forName(
1136 listenerClassName).newInstance());
1137 }
1138
1139 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1140 }
1141 catch (Exception e) {
1142 _log.error(e);
1143 }
1144 }
1145 }
1146
1147 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1148 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1149 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1150 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1151 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1152 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1153 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1154 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1155 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1156 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1157 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1158 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1159 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1160 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1161 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1162 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1163 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1164 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1165 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1166 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1167 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1168 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1169 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1170 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1171 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1172 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1173 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
1174 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1175 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1176 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1177 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1178 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1179 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1180 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1181 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1182 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1183 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1184 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1185 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1186 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1187 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1188 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1189 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1190 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1191 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1192 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1193 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1194 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1195 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1196 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1197 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1198 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1199 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1200 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1201 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1202 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1203 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1204 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1205 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1206 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1207 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1208 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1209 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1210 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1211 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1212 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1213 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1214 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1215 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1216 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1217 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1218 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1219 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1220 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1221 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1222 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1223 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1224 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1225 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1226 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1227 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence.impl")
1228 protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1229 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1230 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1231 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1232 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1233 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1234 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1235 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1236 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1237 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1238 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1239 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1240 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1241 private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1242}