001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchUserGroupRoleException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.model.UserGroupRole;
039 import com.liferay.portal.model.impl.UserGroupRoleImpl;
040 import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.List;
048
049
061 public class UserGroupRolePersistenceImpl extends BasePersistenceImpl<UserGroupRole>
062 implements UserGroupRolePersistence {
063
068 public static final String FINDER_CLASS_NAME_ENTITY = UserGroupRoleImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List1";
071 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List2";
073 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
074 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
075 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
076 "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
078 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
079 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
080 "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
082 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
085 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
086 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
087 "findByUserId",
088 new String[] {
089 Long.class.getName(),
090
091 Integer.class.getName(), Integer.class.getName(),
092 OrderByComparator.class.getName()
093 });
094 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
095 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
096 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
097 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
098 "findByUserId", new String[] { Long.class.getName() },
099 UserGroupRoleModelImpl.USERID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
101 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
103 new String[] { Long.class.getName() });
104
105
112 public List<UserGroupRole> findByUserId(long userId)
113 throws SystemException {
114 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
130 public List<UserGroupRole> findByUserId(long userId, int start, int end)
131 throws SystemException {
132 return findByUserId(userId, start, end, null);
133 }
134
135
149 public List<UserGroupRole> findByUserId(long userId, int start, int end,
150 OrderByComparator orderByComparator) throws SystemException {
151 boolean pagination = true;
152 FinderPath finderPath = null;
153 Object[] finderArgs = null;
154
155 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156 (orderByComparator == null)) {
157 pagination = false;
158 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
159 finderArgs = new Object[] { userId };
160 }
161 else {
162 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
163 finderArgs = new Object[] { userId, start, end, orderByComparator };
164 }
165
166 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
167 finderArgs, this);
168
169 if ((list != null) && !list.isEmpty()) {
170 for (UserGroupRole userGroupRole : list) {
171 if ((userId != userGroupRole.getUserId())) {
172 list = null;
173
174 break;
175 }
176 }
177 }
178
179 if (list == null) {
180 StringBundler query = null;
181
182 if (orderByComparator != null) {
183 query = new StringBundler(3 +
184 (orderByComparator.getOrderByFields().length * 3));
185 }
186 else {
187 query = new StringBundler(3);
188 }
189
190 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
191
192 query.append(_FINDER_COLUMN_USERID_USERID_2);
193
194 if (orderByComparator != null) {
195 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
196 orderByComparator);
197 }
198 else
199 if (pagination) {
200 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
201 }
202
203 String sql = query.toString();
204
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 Query q = session.createQuery(sql);
211
212 QueryPos qPos = QueryPos.getInstance(q);
213
214 qPos.add(userId);
215
216 if (!pagination) {
217 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
218 start, end, false);
219
220 Collections.sort(list);
221
222 list = new UnmodifiableList<UserGroupRole>(list);
223 }
224 else {
225 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
226 start, end);
227 }
228
229 cacheResult(list);
230
231 FinderCacheUtil.putResult(finderPath, finderArgs, list);
232 }
233 catch (Exception e) {
234 FinderCacheUtil.removeResult(finderPath, finderArgs);
235
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240 }
241 }
242
243 return list;
244 }
245
246
255 public UserGroupRole findByUserId_First(long userId,
256 OrderByComparator orderByComparator)
257 throws NoSuchUserGroupRoleException, SystemException {
258 UserGroupRole userGroupRole = fetchByUserId_First(userId,
259 orderByComparator);
260
261 if (userGroupRole != null) {
262 return userGroupRole;
263 }
264
265 StringBundler msg = new StringBundler(4);
266
267 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
268
269 msg.append("userId=");
270 msg.append(userId);
271
272 msg.append(StringPool.CLOSE_CURLY_BRACE);
273
274 throw new NoSuchUserGroupRoleException(msg.toString());
275 }
276
277
285 public UserGroupRole fetchByUserId_First(long userId,
286 OrderByComparator orderByComparator) throws SystemException {
287 List<UserGroupRole> list = findByUserId(userId, 0, 1, orderByComparator);
288
289 if (!list.isEmpty()) {
290 return list.get(0);
291 }
292
293 return null;
294 }
295
296
305 public UserGroupRole findByUserId_Last(long userId,
306 OrderByComparator orderByComparator)
307 throws NoSuchUserGroupRoleException, SystemException {
308 UserGroupRole userGroupRole = fetchByUserId_Last(userId,
309 orderByComparator);
310
311 if (userGroupRole != null) {
312 return userGroupRole;
313 }
314
315 StringBundler msg = new StringBundler(4);
316
317 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318
319 msg.append("userId=");
320 msg.append(userId);
321
322 msg.append(StringPool.CLOSE_CURLY_BRACE);
323
324 throw new NoSuchUserGroupRoleException(msg.toString());
325 }
326
327
335 public UserGroupRole fetchByUserId_Last(long userId,
336 OrderByComparator orderByComparator) throws SystemException {
337 int count = countByUserId(userId);
338
339 List<UserGroupRole> list = findByUserId(userId, count - 1, count,
340 orderByComparator);
341
342 if (!list.isEmpty()) {
343 return list.get(0);
344 }
345
346 return null;
347 }
348
349
359 public UserGroupRole[] findByUserId_PrevAndNext(
360 UserGroupRolePK userGroupRolePK, long userId,
361 OrderByComparator orderByComparator)
362 throws NoSuchUserGroupRoleException, SystemException {
363 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
364
365 Session session = null;
366
367 try {
368 session = openSession();
369
370 UserGroupRole[] array = new UserGroupRoleImpl[3];
371
372 array[0] = getByUserId_PrevAndNext(session, userGroupRole, userId,
373 orderByComparator, true);
374
375 array[1] = userGroupRole;
376
377 array[2] = getByUserId_PrevAndNext(session, userGroupRole, userId,
378 orderByComparator, false);
379
380 return array;
381 }
382 catch (Exception e) {
383 throw processException(e);
384 }
385 finally {
386 closeSession(session);
387 }
388 }
389
390 protected UserGroupRole getByUserId_PrevAndNext(Session session,
391 UserGroupRole userGroupRole, long userId,
392 OrderByComparator orderByComparator, boolean previous) {
393 StringBundler query = null;
394
395 if (orderByComparator != null) {
396 query = new StringBundler(6 +
397 (orderByComparator.getOrderByFields().length * 6));
398 }
399 else {
400 query = new StringBundler(3);
401 }
402
403 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
404
405 query.append(_FINDER_COLUMN_USERID_USERID_2);
406
407 if (orderByComparator != null) {
408 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
409
410 if (orderByConditionFields.length > 0) {
411 query.append(WHERE_AND);
412 }
413
414 for (int i = 0; i < orderByConditionFields.length; i++) {
415 query.append(_ORDER_BY_ENTITY_ALIAS);
416 query.append(orderByConditionFields[i]);
417
418 if ((i + 1) < orderByConditionFields.length) {
419 if (orderByComparator.isAscending() ^ previous) {
420 query.append(WHERE_GREATER_THAN_HAS_NEXT);
421 }
422 else {
423 query.append(WHERE_LESSER_THAN_HAS_NEXT);
424 }
425 }
426 else {
427 if (orderByComparator.isAscending() ^ previous) {
428 query.append(WHERE_GREATER_THAN);
429 }
430 else {
431 query.append(WHERE_LESSER_THAN);
432 }
433 }
434 }
435
436 query.append(ORDER_BY_CLAUSE);
437
438 String[] orderByFields = orderByComparator.getOrderByFields();
439
440 for (int i = 0; i < orderByFields.length; i++) {
441 query.append(_ORDER_BY_ENTITY_ALIAS);
442 query.append(orderByFields[i]);
443
444 if ((i + 1) < orderByFields.length) {
445 if (orderByComparator.isAscending() ^ previous) {
446 query.append(ORDER_BY_ASC_HAS_NEXT);
447 }
448 else {
449 query.append(ORDER_BY_DESC_HAS_NEXT);
450 }
451 }
452 else {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(ORDER_BY_ASC);
455 }
456 else {
457 query.append(ORDER_BY_DESC);
458 }
459 }
460 }
461 }
462 else {
463 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
464 }
465
466 String sql = query.toString();
467
468 Query q = session.createQuery(sql);
469
470 q.setFirstResult(0);
471 q.setMaxResults(2);
472
473 QueryPos qPos = QueryPos.getInstance(q);
474
475 qPos.add(userId);
476
477 if (orderByComparator != null) {
478 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
479
480 for (Object value : values) {
481 qPos.add(value);
482 }
483 }
484
485 List<UserGroupRole> list = q.list();
486
487 if (list.size() == 2) {
488 return list.get(1);
489 }
490 else {
491 return null;
492 }
493 }
494
495
501 public void removeByUserId(long userId) throws SystemException {
502 for (UserGroupRole userGroupRole : findByUserId(userId,
503 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
504 remove(userGroupRole);
505 }
506 }
507
508
515 public int countByUserId(long userId) throws SystemException {
516 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
517
518 Object[] finderArgs = new Object[] { userId };
519
520 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
521 this);
522
523 if (count == null) {
524 StringBundler query = new StringBundler(2);
525
526 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
527
528 query.append(_FINDER_COLUMN_USERID_USERID_2);
529
530 String sql = query.toString();
531
532 Session session = null;
533
534 try {
535 session = openSession();
536
537 Query q = session.createQuery(sql);
538
539 QueryPos qPos = QueryPos.getInstance(q);
540
541 qPos.add(userId);
542
543 count = (Long)q.uniqueResult();
544
545 FinderCacheUtil.putResult(finderPath, finderArgs, count);
546 }
547 catch (Exception e) {
548 FinderCacheUtil.removeResult(finderPath, finderArgs);
549
550 throw processException(e);
551 }
552 finally {
553 closeSession(session);
554 }
555 }
556
557 return count.intValue();
558 }
559
560 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userGroupRole.id.userId = ?";
561 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
562 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
563 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
564 "findByGroupId",
565 new String[] {
566 Long.class.getName(),
567
568 Integer.class.getName(), Integer.class.getName(),
569 OrderByComparator.class.getName()
570 });
571 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
572 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
573 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
574 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
575 "findByGroupId", new String[] { Long.class.getName() },
576 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
577 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
578 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
579 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
580 new String[] { Long.class.getName() });
581
582
589 public List<UserGroupRole> findByGroupId(long groupId)
590 throws SystemException {
591 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
592 }
593
594
607 public List<UserGroupRole> findByGroupId(long groupId, int start, int end)
608 throws SystemException {
609 return findByGroupId(groupId, start, end, null);
610 }
611
612
626 public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
627 OrderByComparator orderByComparator) throws SystemException {
628 boolean pagination = true;
629 FinderPath finderPath = null;
630 Object[] finderArgs = null;
631
632 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
633 (orderByComparator == null)) {
634 pagination = false;
635 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
636 finderArgs = new Object[] { groupId };
637 }
638 else {
639 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
640 finderArgs = new Object[] { groupId, start, end, orderByComparator };
641 }
642
643 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
644 finderArgs, this);
645
646 if ((list != null) && !list.isEmpty()) {
647 for (UserGroupRole userGroupRole : list) {
648 if ((groupId != userGroupRole.getGroupId())) {
649 list = null;
650
651 break;
652 }
653 }
654 }
655
656 if (list == null) {
657 StringBundler query = null;
658
659 if (orderByComparator != null) {
660 query = new StringBundler(3 +
661 (orderByComparator.getOrderByFields().length * 3));
662 }
663 else {
664 query = new StringBundler(3);
665 }
666
667 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
668
669 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
670
671 if (orderByComparator != null) {
672 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
673 orderByComparator);
674 }
675 else
676 if (pagination) {
677 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
678 }
679
680 String sql = query.toString();
681
682 Session session = null;
683
684 try {
685 session = openSession();
686
687 Query q = session.createQuery(sql);
688
689 QueryPos qPos = QueryPos.getInstance(q);
690
691 qPos.add(groupId);
692
693 if (!pagination) {
694 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
695 start, end, false);
696
697 Collections.sort(list);
698
699 list = new UnmodifiableList<UserGroupRole>(list);
700 }
701 else {
702 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
703 start, end);
704 }
705
706 cacheResult(list);
707
708 FinderCacheUtil.putResult(finderPath, finderArgs, list);
709 }
710 catch (Exception e) {
711 FinderCacheUtil.removeResult(finderPath, finderArgs);
712
713 throw processException(e);
714 }
715 finally {
716 closeSession(session);
717 }
718 }
719
720 return list;
721 }
722
723
732 public UserGroupRole findByGroupId_First(long groupId,
733 OrderByComparator orderByComparator)
734 throws NoSuchUserGroupRoleException, SystemException {
735 UserGroupRole userGroupRole = fetchByGroupId_First(groupId,
736 orderByComparator);
737
738 if (userGroupRole != null) {
739 return userGroupRole;
740 }
741
742 StringBundler msg = new StringBundler(4);
743
744 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
745
746 msg.append("groupId=");
747 msg.append(groupId);
748
749 msg.append(StringPool.CLOSE_CURLY_BRACE);
750
751 throw new NoSuchUserGroupRoleException(msg.toString());
752 }
753
754
762 public UserGroupRole fetchByGroupId_First(long groupId,
763 OrderByComparator orderByComparator) throws SystemException {
764 List<UserGroupRole> list = findByGroupId(groupId, 0, 1,
765 orderByComparator);
766
767 if (!list.isEmpty()) {
768 return list.get(0);
769 }
770
771 return null;
772 }
773
774
783 public UserGroupRole findByGroupId_Last(long groupId,
784 OrderByComparator orderByComparator)
785 throws NoSuchUserGroupRoleException, SystemException {
786 UserGroupRole userGroupRole = fetchByGroupId_Last(groupId,
787 orderByComparator);
788
789 if (userGroupRole != null) {
790 return userGroupRole;
791 }
792
793 StringBundler msg = new StringBundler(4);
794
795 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
796
797 msg.append("groupId=");
798 msg.append(groupId);
799
800 msg.append(StringPool.CLOSE_CURLY_BRACE);
801
802 throw new NoSuchUserGroupRoleException(msg.toString());
803 }
804
805
813 public UserGroupRole fetchByGroupId_Last(long groupId,
814 OrderByComparator orderByComparator) throws SystemException {
815 int count = countByGroupId(groupId);
816
817 List<UserGroupRole> list = findByGroupId(groupId, count - 1, count,
818 orderByComparator);
819
820 if (!list.isEmpty()) {
821 return list.get(0);
822 }
823
824 return null;
825 }
826
827
837 public UserGroupRole[] findByGroupId_PrevAndNext(
838 UserGroupRolePK userGroupRolePK, long groupId,
839 OrderByComparator orderByComparator)
840 throws NoSuchUserGroupRoleException, SystemException {
841 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
842
843 Session session = null;
844
845 try {
846 session = openSession();
847
848 UserGroupRole[] array = new UserGroupRoleImpl[3];
849
850 array[0] = getByGroupId_PrevAndNext(session, userGroupRole,
851 groupId, orderByComparator, true);
852
853 array[1] = userGroupRole;
854
855 array[2] = getByGroupId_PrevAndNext(session, userGroupRole,
856 groupId, orderByComparator, false);
857
858 return array;
859 }
860 catch (Exception e) {
861 throw processException(e);
862 }
863 finally {
864 closeSession(session);
865 }
866 }
867
868 protected UserGroupRole getByGroupId_PrevAndNext(Session session,
869 UserGroupRole userGroupRole, long groupId,
870 OrderByComparator orderByComparator, boolean previous) {
871 StringBundler query = null;
872
873 if (orderByComparator != null) {
874 query = new StringBundler(6 +
875 (orderByComparator.getOrderByFields().length * 6));
876 }
877 else {
878 query = new StringBundler(3);
879 }
880
881 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
882
883 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
884
885 if (orderByComparator != null) {
886 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
887
888 if (orderByConditionFields.length > 0) {
889 query.append(WHERE_AND);
890 }
891
892 for (int i = 0; i < orderByConditionFields.length; i++) {
893 query.append(_ORDER_BY_ENTITY_ALIAS);
894 query.append(orderByConditionFields[i]);
895
896 if ((i + 1) < orderByConditionFields.length) {
897 if (orderByComparator.isAscending() ^ previous) {
898 query.append(WHERE_GREATER_THAN_HAS_NEXT);
899 }
900 else {
901 query.append(WHERE_LESSER_THAN_HAS_NEXT);
902 }
903 }
904 else {
905 if (orderByComparator.isAscending() ^ previous) {
906 query.append(WHERE_GREATER_THAN);
907 }
908 else {
909 query.append(WHERE_LESSER_THAN);
910 }
911 }
912 }
913
914 query.append(ORDER_BY_CLAUSE);
915
916 String[] orderByFields = orderByComparator.getOrderByFields();
917
918 for (int i = 0; i < orderByFields.length; i++) {
919 query.append(_ORDER_BY_ENTITY_ALIAS);
920 query.append(orderByFields[i]);
921
922 if ((i + 1) < orderByFields.length) {
923 if (orderByComparator.isAscending() ^ previous) {
924 query.append(ORDER_BY_ASC_HAS_NEXT);
925 }
926 else {
927 query.append(ORDER_BY_DESC_HAS_NEXT);
928 }
929 }
930 else {
931 if (orderByComparator.isAscending() ^ previous) {
932 query.append(ORDER_BY_ASC);
933 }
934 else {
935 query.append(ORDER_BY_DESC);
936 }
937 }
938 }
939 }
940 else {
941 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
942 }
943
944 String sql = query.toString();
945
946 Query q = session.createQuery(sql);
947
948 q.setFirstResult(0);
949 q.setMaxResults(2);
950
951 QueryPos qPos = QueryPos.getInstance(q);
952
953 qPos.add(groupId);
954
955 if (orderByComparator != null) {
956 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
957
958 for (Object value : values) {
959 qPos.add(value);
960 }
961 }
962
963 List<UserGroupRole> list = q.list();
964
965 if (list.size() == 2) {
966 return list.get(1);
967 }
968 else {
969 return null;
970 }
971 }
972
973
979 public void removeByGroupId(long groupId) throws SystemException {
980 for (UserGroupRole userGroupRole : findByGroupId(groupId,
981 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
982 remove(userGroupRole);
983 }
984 }
985
986
993 public int countByGroupId(long groupId) throws SystemException {
994 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
995
996 Object[] finderArgs = new Object[] { groupId };
997
998 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
999 this);
1000
1001 if (count == null) {
1002 StringBundler query = new StringBundler(2);
1003
1004 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1005
1006 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1007
1008 String sql = query.toString();
1009
1010 Session session = null;
1011
1012 try {
1013 session = openSession();
1014
1015 Query q = session.createQuery(sql);
1016
1017 QueryPos qPos = QueryPos.getInstance(q);
1018
1019 qPos.add(groupId);
1020
1021 count = (Long)q.uniqueResult();
1022
1023 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1024 }
1025 catch (Exception e) {
1026 FinderCacheUtil.removeResult(finderPath, finderArgs);
1027
1028 throw processException(e);
1029 }
1030 finally {
1031 closeSession(session);
1032 }
1033 }
1034
1035 return count.intValue();
1036 }
1037
1038 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "userGroupRole.id.groupId = ?";
1039 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1040 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1041 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1042 "findByRoleId",
1043 new String[] {
1044 Long.class.getName(),
1045
1046 Integer.class.getName(), Integer.class.getName(),
1047 OrderByComparator.class.getName()
1048 });
1049 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
1050 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1051 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1052 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1053 "findByRoleId", new String[] { Long.class.getName() },
1054 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
1055 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1056 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1057 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
1058 new String[] { Long.class.getName() });
1059
1060
1067 public List<UserGroupRole> findByRoleId(long roleId)
1068 throws SystemException {
1069 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1070 }
1071
1072
1085 public List<UserGroupRole> findByRoleId(long roleId, int start, int end)
1086 throws SystemException {
1087 return findByRoleId(roleId, start, end, null);
1088 }
1089
1090
1104 public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
1105 OrderByComparator orderByComparator) throws SystemException {
1106 boolean pagination = true;
1107 FinderPath finderPath = null;
1108 Object[] finderArgs = null;
1109
1110 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1111 (orderByComparator == null)) {
1112 pagination = false;
1113 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
1114 finderArgs = new Object[] { roleId };
1115 }
1116 else {
1117 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
1118 finderArgs = new Object[] { roleId, start, end, orderByComparator };
1119 }
1120
1121 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
1122 finderArgs, this);
1123
1124 if ((list != null) && !list.isEmpty()) {
1125 for (UserGroupRole userGroupRole : list) {
1126 if ((roleId != userGroupRole.getRoleId())) {
1127 list = null;
1128
1129 break;
1130 }
1131 }
1132 }
1133
1134 if (list == null) {
1135 StringBundler query = null;
1136
1137 if (orderByComparator != null) {
1138 query = new StringBundler(3 +
1139 (orderByComparator.getOrderByFields().length * 3));
1140 }
1141 else {
1142 query = new StringBundler(3);
1143 }
1144
1145 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1146
1147 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1148
1149 if (orderByComparator != null) {
1150 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1151 orderByComparator);
1152 }
1153 else
1154 if (pagination) {
1155 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1156 }
1157
1158 String sql = query.toString();
1159
1160 Session session = null;
1161
1162 try {
1163 session = openSession();
1164
1165 Query q = session.createQuery(sql);
1166
1167 QueryPos qPos = QueryPos.getInstance(q);
1168
1169 qPos.add(roleId);
1170
1171 if (!pagination) {
1172 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1173 start, end, false);
1174
1175 Collections.sort(list);
1176
1177 list = new UnmodifiableList<UserGroupRole>(list);
1178 }
1179 else {
1180 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1181 start, end);
1182 }
1183
1184 cacheResult(list);
1185
1186 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1187 }
1188 catch (Exception e) {
1189 FinderCacheUtil.removeResult(finderPath, finderArgs);
1190
1191 throw processException(e);
1192 }
1193 finally {
1194 closeSession(session);
1195 }
1196 }
1197
1198 return list;
1199 }
1200
1201
1210 public UserGroupRole findByRoleId_First(long roleId,
1211 OrderByComparator orderByComparator)
1212 throws NoSuchUserGroupRoleException, SystemException {
1213 UserGroupRole userGroupRole = fetchByRoleId_First(roleId,
1214 orderByComparator);
1215
1216 if (userGroupRole != null) {
1217 return userGroupRole;
1218 }
1219
1220 StringBundler msg = new StringBundler(4);
1221
1222 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1223
1224 msg.append("roleId=");
1225 msg.append(roleId);
1226
1227 msg.append(StringPool.CLOSE_CURLY_BRACE);
1228
1229 throw new NoSuchUserGroupRoleException(msg.toString());
1230 }
1231
1232
1240 public UserGroupRole fetchByRoleId_First(long roleId,
1241 OrderByComparator orderByComparator) throws SystemException {
1242 List<UserGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
1243
1244 if (!list.isEmpty()) {
1245 return list.get(0);
1246 }
1247
1248 return null;
1249 }
1250
1251
1260 public UserGroupRole findByRoleId_Last(long roleId,
1261 OrderByComparator orderByComparator)
1262 throws NoSuchUserGroupRoleException, SystemException {
1263 UserGroupRole userGroupRole = fetchByRoleId_Last(roleId,
1264 orderByComparator);
1265
1266 if (userGroupRole != null) {
1267 return userGroupRole;
1268 }
1269
1270 StringBundler msg = new StringBundler(4);
1271
1272 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1273
1274 msg.append("roleId=");
1275 msg.append(roleId);
1276
1277 msg.append(StringPool.CLOSE_CURLY_BRACE);
1278
1279 throw new NoSuchUserGroupRoleException(msg.toString());
1280 }
1281
1282
1290 public UserGroupRole fetchByRoleId_Last(long roleId,
1291 OrderByComparator orderByComparator) throws SystemException {
1292 int count = countByRoleId(roleId);
1293
1294 List<UserGroupRole> list = findByRoleId(roleId, count - 1, count,
1295 orderByComparator);
1296
1297 if (!list.isEmpty()) {
1298 return list.get(0);
1299 }
1300
1301 return null;
1302 }
1303
1304
1314 public UserGroupRole[] findByRoleId_PrevAndNext(
1315 UserGroupRolePK userGroupRolePK, long roleId,
1316 OrderByComparator orderByComparator)
1317 throws NoSuchUserGroupRoleException, SystemException {
1318 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1319
1320 Session session = null;
1321
1322 try {
1323 session = openSession();
1324
1325 UserGroupRole[] array = new UserGroupRoleImpl[3];
1326
1327 array[0] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1328 orderByComparator, true);
1329
1330 array[1] = userGroupRole;
1331
1332 array[2] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1333 orderByComparator, false);
1334
1335 return array;
1336 }
1337 catch (Exception e) {
1338 throw processException(e);
1339 }
1340 finally {
1341 closeSession(session);
1342 }
1343 }
1344
1345 protected UserGroupRole getByRoleId_PrevAndNext(Session session,
1346 UserGroupRole userGroupRole, long roleId,
1347 OrderByComparator orderByComparator, boolean previous) {
1348 StringBundler query = null;
1349
1350 if (orderByComparator != null) {
1351 query = new StringBundler(6 +
1352 (orderByComparator.getOrderByFields().length * 6));
1353 }
1354 else {
1355 query = new StringBundler(3);
1356 }
1357
1358 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1359
1360 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1361
1362 if (orderByComparator != null) {
1363 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1364
1365 if (orderByConditionFields.length > 0) {
1366 query.append(WHERE_AND);
1367 }
1368
1369 for (int i = 0; i < orderByConditionFields.length; i++) {
1370 query.append(_ORDER_BY_ENTITY_ALIAS);
1371 query.append(orderByConditionFields[i]);
1372
1373 if ((i + 1) < orderByConditionFields.length) {
1374 if (orderByComparator.isAscending() ^ previous) {
1375 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1376 }
1377 else {
1378 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1379 }
1380 }
1381 else {
1382 if (orderByComparator.isAscending() ^ previous) {
1383 query.append(WHERE_GREATER_THAN);
1384 }
1385 else {
1386 query.append(WHERE_LESSER_THAN);
1387 }
1388 }
1389 }
1390
1391 query.append(ORDER_BY_CLAUSE);
1392
1393 String[] orderByFields = orderByComparator.getOrderByFields();
1394
1395 for (int i = 0; i < orderByFields.length; i++) {
1396 query.append(_ORDER_BY_ENTITY_ALIAS);
1397 query.append(orderByFields[i]);
1398
1399 if ((i + 1) < orderByFields.length) {
1400 if (orderByComparator.isAscending() ^ previous) {
1401 query.append(ORDER_BY_ASC_HAS_NEXT);
1402 }
1403 else {
1404 query.append(ORDER_BY_DESC_HAS_NEXT);
1405 }
1406 }
1407 else {
1408 if (orderByComparator.isAscending() ^ previous) {
1409 query.append(ORDER_BY_ASC);
1410 }
1411 else {
1412 query.append(ORDER_BY_DESC);
1413 }
1414 }
1415 }
1416 }
1417 else {
1418 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1419 }
1420
1421 String sql = query.toString();
1422
1423 Query q = session.createQuery(sql);
1424
1425 q.setFirstResult(0);
1426 q.setMaxResults(2);
1427
1428 QueryPos qPos = QueryPos.getInstance(q);
1429
1430 qPos.add(roleId);
1431
1432 if (orderByComparator != null) {
1433 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1434
1435 for (Object value : values) {
1436 qPos.add(value);
1437 }
1438 }
1439
1440 List<UserGroupRole> list = q.list();
1441
1442 if (list.size() == 2) {
1443 return list.get(1);
1444 }
1445 else {
1446 return null;
1447 }
1448 }
1449
1450
1456 public void removeByRoleId(long roleId) throws SystemException {
1457 for (UserGroupRole userGroupRole : findByRoleId(roleId,
1458 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1459 remove(userGroupRole);
1460 }
1461 }
1462
1463
1470 public int countByRoleId(long roleId) throws SystemException {
1471 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1472
1473 Object[] finderArgs = new Object[] { roleId };
1474
1475 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1476 this);
1477
1478 if (count == null) {
1479 StringBundler query = new StringBundler(2);
1480
1481 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1482
1483 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1484
1485 String sql = query.toString();
1486
1487 Session session = null;
1488
1489 try {
1490 session = openSession();
1491
1492 Query q = session.createQuery(sql);
1493
1494 QueryPos qPos = QueryPos.getInstance(q);
1495
1496 qPos.add(roleId);
1497
1498 count = (Long)q.uniqueResult();
1499
1500 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1501 }
1502 catch (Exception e) {
1503 FinderCacheUtil.removeResult(finderPath, finderArgs);
1504
1505 throw processException(e);
1506 }
1507 finally {
1508 closeSession(session);
1509 }
1510 }
1511
1512 return count.intValue();
1513 }
1514
1515 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "userGroupRole.id.roleId = ?";
1516 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1517 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1518 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1519 "findByU_G",
1520 new String[] {
1521 Long.class.getName(), Long.class.getName(),
1522
1523 Integer.class.getName(), Integer.class.getName(),
1524 OrderByComparator.class.getName()
1525 });
1526 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1527 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1528 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1529 "findByU_G",
1530 new String[] { Long.class.getName(), Long.class.getName() },
1531 UserGroupRoleModelImpl.USERID_COLUMN_BITMASK |
1532 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
1533 public static final FinderPath FINDER_PATH_COUNT_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1534 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1535 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_G",
1536 new String[] { Long.class.getName(), Long.class.getName() });
1537
1538
1546 public List<UserGroupRole> findByU_G(long userId, long groupId)
1547 throws SystemException {
1548 return findByU_G(userId, groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1549 null);
1550 }
1551
1552
1566 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1567 int end) throws SystemException {
1568 return findByU_G(userId, groupId, start, end, null);
1569 }
1570
1571
1586 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1587 int end, OrderByComparator orderByComparator) throws SystemException {
1588 boolean pagination = true;
1589 FinderPath finderPath = null;
1590 Object[] finderArgs = null;
1591
1592 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1593 (orderByComparator == null)) {
1594 pagination = false;
1595 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G;
1596 finderArgs = new Object[] { userId, groupId };
1597 }
1598 else {
1599 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G;
1600 finderArgs = new Object[] {
1601 userId, groupId,
1602
1603 start, end, orderByComparator
1604 };
1605 }
1606
1607 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
1608 finderArgs, this);
1609
1610 if ((list != null) && !list.isEmpty()) {
1611 for (UserGroupRole userGroupRole : list) {
1612 if ((userId != userGroupRole.getUserId()) ||
1613 (groupId != userGroupRole.getGroupId())) {
1614 list = null;
1615
1616 break;
1617 }
1618 }
1619 }
1620
1621 if (list == null) {
1622 StringBundler query = null;
1623
1624 if (orderByComparator != null) {
1625 query = new StringBundler(4 +
1626 (orderByComparator.getOrderByFields().length * 3));
1627 }
1628 else {
1629 query = new StringBundler(4);
1630 }
1631
1632 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1633
1634 query.append(_FINDER_COLUMN_U_G_USERID_2);
1635
1636 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1637
1638 if (orderByComparator != null) {
1639 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1640 orderByComparator);
1641 }
1642 else
1643 if (pagination) {
1644 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1645 }
1646
1647 String sql = query.toString();
1648
1649 Session session = null;
1650
1651 try {
1652 session = openSession();
1653
1654 Query q = session.createQuery(sql);
1655
1656 QueryPos qPos = QueryPos.getInstance(q);
1657
1658 qPos.add(userId);
1659
1660 qPos.add(groupId);
1661
1662 if (!pagination) {
1663 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1664 start, end, false);
1665
1666 Collections.sort(list);
1667
1668 list = new UnmodifiableList<UserGroupRole>(list);
1669 }
1670 else {
1671 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1672 start, end);
1673 }
1674
1675 cacheResult(list);
1676
1677 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1678 }
1679 catch (Exception e) {
1680 FinderCacheUtil.removeResult(finderPath, finderArgs);
1681
1682 throw processException(e);
1683 }
1684 finally {
1685 closeSession(session);
1686 }
1687 }
1688
1689 return list;
1690 }
1691
1692
1702 public UserGroupRole findByU_G_First(long userId, long groupId,
1703 OrderByComparator orderByComparator)
1704 throws NoSuchUserGroupRoleException, SystemException {
1705 UserGroupRole userGroupRole = fetchByU_G_First(userId, groupId,
1706 orderByComparator);
1707
1708 if (userGroupRole != null) {
1709 return userGroupRole;
1710 }
1711
1712 StringBundler msg = new StringBundler(6);
1713
1714 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1715
1716 msg.append("userId=");
1717 msg.append(userId);
1718
1719 msg.append(", groupId=");
1720 msg.append(groupId);
1721
1722 msg.append(StringPool.CLOSE_CURLY_BRACE);
1723
1724 throw new NoSuchUserGroupRoleException(msg.toString());
1725 }
1726
1727
1736 public UserGroupRole fetchByU_G_First(long userId, long groupId,
1737 OrderByComparator orderByComparator) throws SystemException {
1738 List<UserGroupRole> list = findByU_G(userId, groupId, 0, 1,
1739 orderByComparator);
1740
1741 if (!list.isEmpty()) {
1742 return list.get(0);
1743 }
1744
1745 return null;
1746 }
1747
1748
1758 public UserGroupRole findByU_G_Last(long userId, long groupId,
1759 OrderByComparator orderByComparator)
1760 throws NoSuchUserGroupRoleException, SystemException {
1761 UserGroupRole userGroupRole = fetchByU_G_Last(userId, groupId,
1762 orderByComparator);
1763
1764 if (userGroupRole != null) {
1765 return userGroupRole;
1766 }
1767
1768 StringBundler msg = new StringBundler(6);
1769
1770 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1771
1772 msg.append("userId=");
1773 msg.append(userId);
1774
1775 msg.append(", groupId=");
1776 msg.append(groupId);
1777
1778 msg.append(StringPool.CLOSE_CURLY_BRACE);
1779
1780 throw new NoSuchUserGroupRoleException(msg.toString());
1781 }
1782
1783
1792 public UserGroupRole fetchByU_G_Last(long userId, long groupId,
1793 OrderByComparator orderByComparator) throws SystemException {
1794 int count = countByU_G(userId, groupId);
1795
1796 List<UserGroupRole> list = findByU_G(userId, groupId, count - 1, count,
1797 orderByComparator);
1798
1799 if (!list.isEmpty()) {
1800 return list.get(0);
1801 }
1802
1803 return null;
1804 }
1805
1806
1817 public UserGroupRole[] findByU_G_PrevAndNext(
1818 UserGroupRolePK userGroupRolePK, long userId, long groupId,
1819 OrderByComparator orderByComparator)
1820 throws NoSuchUserGroupRoleException, SystemException {
1821 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1822
1823 Session session = null;
1824
1825 try {
1826 session = openSession();
1827
1828 UserGroupRole[] array = new UserGroupRoleImpl[3];
1829
1830 array[0] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1831 groupId, orderByComparator, true);
1832
1833 array[1] = userGroupRole;
1834
1835 array[2] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1836 groupId, orderByComparator, false);
1837
1838 return array;
1839 }
1840 catch (Exception e) {
1841 throw processException(e);
1842 }
1843 finally {
1844 closeSession(session);
1845 }
1846 }
1847
1848 protected UserGroupRole getByU_G_PrevAndNext(Session session,
1849 UserGroupRole userGroupRole, long userId, long groupId,
1850 OrderByComparator orderByComparator, boolean previous) {
1851 StringBundler query = null;
1852
1853 if (orderByComparator != null) {
1854 query = new StringBundler(6 +
1855 (orderByComparator.getOrderByFields().length * 6));
1856 }
1857 else {
1858 query = new StringBundler(3);
1859 }
1860
1861 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1862
1863 query.append(_FINDER_COLUMN_U_G_USERID_2);
1864
1865 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1866
1867 if (orderByComparator != null) {
1868 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1869
1870 if (orderByConditionFields.length > 0) {
1871 query.append(WHERE_AND);
1872 }
1873
1874 for (int i = 0; i < orderByConditionFields.length; i++) {
1875 query.append(_ORDER_BY_ENTITY_ALIAS);
1876 query.append(orderByConditionFields[i]);
1877
1878 if ((i + 1) < orderByConditionFields.length) {
1879 if (orderByComparator.isAscending() ^ previous) {
1880 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1881 }
1882 else {
1883 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1884 }
1885 }
1886 else {
1887 if (orderByComparator.isAscending() ^ previous) {
1888 query.append(WHERE_GREATER_THAN);
1889 }
1890 else {
1891 query.append(WHERE_LESSER_THAN);
1892 }
1893 }
1894 }
1895
1896 query.append(ORDER_BY_CLAUSE);
1897
1898 String[] orderByFields = orderByComparator.getOrderByFields();
1899
1900 for (int i = 0; i < orderByFields.length; i++) {
1901 query.append(_ORDER_BY_ENTITY_ALIAS);
1902 query.append(orderByFields[i]);
1903
1904 if ((i + 1) < orderByFields.length) {
1905 if (orderByComparator.isAscending() ^ previous) {
1906 query.append(ORDER_BY_ASC_HAS_NEXT);
1907 }
1908 else {
1909 query.append(ORDER_BY_DESC_HAS_NEXT);
1910 }
1911 }
1912 else {
1913 if (orderByComparator.isAscending() ^ previous) {
1914 query.append(ORDER_BY_ASC);
1915 }
1916 else {
1917 query.append(ORDER_BY_DESC);
1918 }
1919 }
1920 }
1921 }
1922 else {
1923 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1924 }
1925
1926 String sql = query.toString();
1927
1928 Query q = session.createQuery(sql);
1929
1930 q.setFirstResult(0);
1931 q.setMaxResults(2);
1932
1933 QueryPos qPos = QueryPos.getInstance(q);
1934
1935 qPos.add(userId);
1936
1937 qPos.add(groupId);
1938
1939 if (orderByComparator != null) {
1940 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1941
1942 for (Object value : values) {
1943 qPos.add(value);
1944 }
1945 }
1946
1947 List<UserGroupRole> list = q.list();
1948
1949 if (list.size() == 2) {
1950 return list.get(1);
1951 }
1952 else {
1953 return null;
1954 }
1955 }
1956
1957
1964 public void removeByU_G(long userId, long groupId)
1965 throws SystemException {
1966 for (UserGroupRole userGroupRole : findByU_G(userId, groupId,
1967 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1968 remove(userGroupRole);
1969 }
1970 }
1971
1972
1980 public int countByU_G(long userId, long groupId) throws SystemException {
1981 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_G;
1982
1983 Object[] finderArgs = new Object[] { userId, groupId };
1984
1985 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1986 this);
1987
1988 if (count == null) {
1989 StringBundler query = new StringBundler(3);
1990
1991 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1992
1993 query.append(_FINDER_COLUMN_U_G_USERID_2);
1994
1995 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1996
1997 String sql = query.toString();
1998
1999 Session session = null;
2000
2001 try {
2002 session = openSession();
2003
2004 Query q = session.createQuery(sql);
2005
2006 QueryPos qPos = QueryPos.getInstance(q);
2007
2008 qPos.add(userId);
2009
2010 qPos.add(groupId);
2011
2012 count = (Long)q.uniqueResult();
2013
2014 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2015 }
2016 catch (Exception e) {
2017 FinderCacheUtil.removeResult(finderPath, finderArgs);
2018
2019 throw processException(e);
2020 }
2021 finally {
2022 closeSession(session);
2023 }
2024 }
2025
2026 return count.intValue();
2027 }
2028
2029 private static final String _FINDER_COLUMN_U_G_USERID_2 = "userGroupRole.id.userId = ? AND ";
2030 private static final String _FINDER_COLUMN_U_G_GROUPID_2 = "userGroupRole.id.groupId = ?";
2031 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2032 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2033 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2034 "findByG_R",
2035 new String[] {
2036 Long.class.getName(), Long.class.getName(),
2037
2038 Integer.class.getName(), Integer.class.getName(),
2039 OrderByComparator.class.getName()
2040 });
2041 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2042 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2043 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2044 "findByG_R",
2045 new String[] { Long.class.getName(), Long.class.getName() },
2046 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK |
2047 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
2048 public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2049 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2050 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_R",
2051 new String[] { Long.class.getName(), Long.class.getName() });
2052
2053
2061 public List<UserGroupRole> findByG_R(long groupId, long roleId)
2062 throws SystemException {
2063 return findByG_R(groupId, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2064 null);
2065 }
2066
2067
2081 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2082 int end) throws SystemException {
2083 return findByG_R(groupId, roleId, start, end, null);
2084 }
2085
2086
2101 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2102 int end, OrderByComparator orderByComparator) throws SystemException {
2103 boolean pagination = true;
2104 FinderPath finderPath = null;
2105 Object[] finderArgs = null;
2106
2107 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2108 (orderByComparator == null)) {
2109 pagination = false;
2110 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R;
2111 finderArgs = new Object[] { groupId, roleId };
2112 }
2113 else {
2114 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R;
2115 finderArgs = new Object[] {
2116 groupId, roleId,
2117
2118 start, end, orderByComparator
2119 };
2120 }
2121
2122 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
2123 finderArgs, this);
2124
2125 if ((list != null) && !list.isEmpty()) {
2126 for (UserGroupRole userGroupRole : list) {
2127 if ((groupId != userGroupRole.getGroupId()) ||
2128 (roleId != userGroupRole.getRoleId())) {
2129 list = null;
2130
2131 break;
2132 }
2133 }
2134 }
2135
2136 if (list == null) {
2137 StringBundler query = null;
2138
2139 if (orderByComparator != null) {
2140 query = new StringBundler(4 +
2141 (orderByComparator.getOrderByFields().length * 3));
2142 }
2143 else {
2144 query = new StringBundler(4);
2145 }
2146
2147 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2148
2149 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2150
2151 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2152
2153 if (orderByComparator != null) {
2154 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2155 orderByComparator);
2156 }
2157 else
2158 if (pagination) {
2159 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2160 }
2161
2162 String sql = query.toString();
2163
2164 Session session = null;
2165
2166 try {
2167 session = openSession();
2168
2169 Query q = session.createQuery(sql);
2170
2171 QueryPos qPos = QueryPos.getInstance(q);
2172
2173 qPos.add(groupId);
2174
2175 qPos.add(roleId);
2176
2177 if (!pagination) {
2178 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2179 start, end, false);
2180
2181 Collections.sort(list);
2182
2183 list = new UnmodifiableList<UserGroupRole>(list);
2184 }
2185 else {
2186 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2187 start, end);
2188 }
2189
2190 cacheResult(list);
2191
2192 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2193 }
2194 catch (Exception e) {
2195 FinderCacheUtil.removeResult(finderPath, finderArgs);
2196
2197 throw processException(e);
2198 }
2199 finally {
2200 closeSession(session);
2201 }
2202 }
2203
2204 return list;
2205 }
2206
2207
2217 public UserGroupRole findByG_R_First(long groupId, long roleId,
2218 OrderByComparator orderByComparator)
2219 throws NoSuchUserGroupRoleException, SystemException {
2220 UserGroupRole userGroupRole = fetchByG_R_First(groupId, roleId,
2221 orderByComparator);
2222
2223 if (userGroupRole != null) {
2224 return userGroupRole;
2225 }
2226
2227 StringBundler msg = new StringBundler(6);
2228
2229 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2230
2231 msg.append("groupId=");
2232 msg.append(groupId);
2233
2234 msg.append(", roleId=");
2235 msg.append(roleId);
2236
2237 msg.append(StringPool.CLOSE_CURLY_BRACE);
2238
2239 throw new NoSuchUserGroupRoleException(msg.toString());
2240 }
2241
2242
2251 public UserGroupRole fetchByG_R_First(long groupId, long roleId,
2252 OrderByComparator orderByComparator) throws SystemException {
2253 List<UserGroupRole> list = findByG_R(groupId, roleId, 0, 1,
2254 orderByComparator);
2255
2256 if (!list.isEmpty()) {
2257 return list.get(0);
2258 }
2259
2260 return null;
2261 }
2262
2263
2273 public UserGroupRole findByG_R_Last(long groupId, long roleId,
2274 OrderByComparator orderByComparator)
2275 throws NoSuchUserGroupRoleException, SystemException {
2276 UserGroupRole userGroupRole = fetchByG_R_Last(groupId, roleId,
2277 orderByComparator);
2278
2279 if (userGroupRole != null) {
2280 return userGroupRole;
2281 }
2282
2283 StringBundler msg = new StringBundler(6);
2284
2285 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2286
2287 msg.append("groupId=");
2288 msg.append(groupId);
2289
2290 msg.append(", roleId=");
2291 msg.append(roleId);
2292
2293 msg.append(StringPool.CLOSE_CURLY_BRACE);
2294
2295 throw new NoSuchUserGroupRoleException(msg.toString());
2296 }
2297
2298
2307 public UserGroupRole fetchByG_R_Last(long groupId, long roleId,
2308 OrderByComparator orderByComparator) throws SystemException {
2309 int count = countByG_R(groupId, roleId);
2310
2311 List<UserGroupRole> list = findByG_R(groupId, roleId, count - 1, count,
2312 orderByComparator);
2313
2314 if (!list.isEmpty()) {
2315 return list.get(0);
2316 }
2317
2318 return null;
2319 }
2320
2321
2332 public UserGroupRole[] findByG_R_PrevAndNext(
2333 UserGroupRolePK userGroupRolePK, long groupId, long roleId,
2334 OrderByComparator orderByComparator)
2335 throws NoSuchUserGroupRoleException, SystemException {
2336 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
2337
2338 Session session = null;
2339
2340 try {
2341 session = openSession();
2342
2343 UserGroupRole[] array = new UserGroupRoleImpl[3];
2344
2345 array[0] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2346 roleId, orderByComparator, true);
2347
2348 array[1] = userGroupRole;
2349
2350 array[2] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2351 roleId, orderByComparator, false);
2352
2353 return array;
2354 }
2355 catch (Exception e) {
2356 throw processException(e);
2357 }
2358 finally {
2359 closeSession(session);
2360 }
2361 }
2362
2363 protected UserGroupRole getByG_R_PrevAndNext(Session session,
2364 UserGroupRole userGroupRole, long groupId, long roleId,
2365 OrderByComparator orderByComparator, boolean previous) {
2366 StringBundler query = null;
2367
2368 if (orderByComparator != null) {
2369 query = new StringBundler(6 +
2370 (orderByComparator.getOrderByFields().length * 6));
2371 }
2372 else {
2373 query = new StringBundler(3);
2374 }
2375
2376 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2377
2378 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2379
2380 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2381
2382 if (orderByComparator != null) {
2383 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2384
2385 if (orderByConditionFields.length > 0) {
2386 query.append(WHERE_AND);
2387 }
2388
2389 for (int i = 0; i < orderByConditionFields.length; i++) {
2390 query.append(_ORDER_BY_ENTITY_ALIAS);
2391 query.append(orderByConditionFields[i]);
2392
2393 if ((i + 1) < orderByConditionFields.length) {
2394 if (orderByComparator.isAscending() ^ previous) {
2395 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2396 }
2397 else {
2398 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2399 }
2400 }
2401 else {
2402 if (orderByComparator.isAscending() ^ previous) {
2403 query.append(WHERE_GREATER_THAN);
2404 }
2405 else {
2406 query.append(WHERE_LESSER_THAN);
2407 }
2408 }
2409 }
2410
2411 query.append(ORDER_BY_CLAUSE);
2412
2413 String[] orderByFields = orderByComparator.getOrderByFields();
2414
2415 for (int i = 0; i < orderByFields.length; i++) {
2416 query.append(_ORDER_BY_ENTITY_ALIAS);
2417 query.append(orderByFields[i]);
2418
2419 if ((i + 1) < orderByFields.length) {
2420 if (orderByComparator.isAscending() ^ previous) {
2421 query.append(ORDER_BY_ASC_HAS_NEXT);
2422 }
2423 else {
2424 query.append(ORDER_BY_DESC_HAS_NEXT);
2425 }
2426 }
2427 else {
2428 if (orderByComparator.isAscending() ^ previous) {
2429 query.append(ORDER_BY_ASC);
2430 }
2431 else {
2432 query.append(ORDER_BY_DESC);
2433 }
2434 }
2435 }
2436 }
2437 else {
2438 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2439 }
2440
2441 String sql = query.toString();
2442
2443 Query q = session.createQuery(sql);
2444
2445 q.setFirstResult(0);
2446 q.setMaxResults(2);
2447
2448 QueryPos qPos = QueryPos.getInstance(q);
2449
2450 qPos.add(groupId);
2451
2452 qPos.add(roleId);
2453
2454 if (orderByComparator != null) {
2455 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
2456
2457 for (Object value : values) {
2458 qPos.add(value);
2459 }
2460 }
2461
2462 List<UserGroupRole> list = q.list();
2463
2464 if (list.size() == 2) {
2465 return list.get(1);
2466 }
2467 else {
2468 return null;
2469 }
2470 }
2471
2472
2479 public void removeByG_R(long groupId, long roleId)
2480 throws SystemException {
2481 for (UserGroupRole userGroupRole : findByG_R(groupId, roleId,
2482 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2483 remove(userGroupRole);
2484 }
2485 }
2486
2487
2495 public int countByG_R(long groupId, long roleId) throws SystemException {
2496 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_R;
2497
2498 Object[] finderArgs = new Object[] { groupId, roleId };
2499
2500 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2501 this);
2502
2503 if (count == null) {
2504 StringBundler query = new StringBundler(3);
2505
2506 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2507
2508 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2509
2510 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2511
2512 String sql = query.toString();
2513
2514 Session session = null;
2515
2516 try {
2517 session = openSession();
2518
2519 Query q = session.createQuery(sql);
2520
2521 QueryPos qPos = QueryPos.getInstance(q);
2522
2523 qPos.add(groupId);
2524
2525 qPos.add(roleId);
2526
2527 count = (Long)q.uniqueResult();
2528
2529 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2530 }
2531 catch (Exception e) {
2532 FinderCacheUtil.removeResult(finderPath, finderArgs);
2533
2534 throw processException(e);
2535 }
2536 finally {
2537 closeSession(session);
2538 }
2539 }
2540
2541 return count.intValue();
2542 }
2543
2544 private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "userGroupRole.id.groupId = ? AND ";
2545 private static final String _FINDER_COLUMN_G_R_ROLEID_2 = "userGroupRole.id.roleId = ?";
2546
2547
2552 public void cacheResult(UserGroupRole userGroupRole) {
2553 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2554 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2555 userGroupRole);
2556
2557 userGroupRole.resetOriginalValues();
2558 }
2559
2560
2565 public void cacheResult(List<UserGroupRole> userGroupRoles) {
2566 for (UserGroupRole userGroupRole : userGroupRoles) {
2567 if (EntityCacheUtil.getResult(
2568 UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2569 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey()) == null) {
2570 cacheResult(userGroupRole);
2571 }
2572 else {
2573 userGroupRole.resetOriginalValues();
2574 }
2575 }
2576 }
2577
2578
2585 @Override
2586 public void clearCache() {
2587 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2588 CacheRegistryUtil.clear(UserGroupRoleImpl.class.getName());
2589 }
2590
2591 EntityCacheUtil.clearCache(UserGroupRoleImpl.class.getName());
2592
2593 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2594 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2595 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2596 }
2597
2598
2605 @Override
2606 public void clearCache(UserGroupRole userGroupRole) {
2607 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2608 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2609
2610 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2611 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2612 }
2613
2614 @Override
2615 public void clearCache(List<UserGroupRole> userGroupRoles) {
2616 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2617 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2618
2619 for (UserGroupRole userGroupRole : userGroupRoles) {
2620 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2621 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2622 }
2623 }
2624
2625
2631 public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
2632 UserGroupRole userGroupRole = new UserGroupRoleImpl();
2633
2634 userGroupRole.setNew(true);
2635 userGroupRole.setPrimaryKey(userGroupRolePK);
2636
2637 return userGroupRole;
2638 }
2639
2640
2648 public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
2649 throws NoSuchUserGroupRoleException, SystemException {
2650 return remove((Serializable)userGroupRolePK);
2651 }
2652
2653
2661 @Override
2662 public UserGroupRole remove(Serializable primaryKey)
2663 throws NoSuchUserGroupRoleException, SystemException {
2664 Session session = null;
2665
2666 try {
2667 session = openSession();
2668
2669 UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2670 primaryKey);
2671
2672 if (userGroupRole == null) {
2673 if (_log.isWarnEnabled()) {
2674 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2675 }
2676
2677 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2678 primaryKey);
2679 }
2680
2681 return remove(userGroupRole);
2682 }
2683 catch (NoSuchUserGroupRoleException nsee) {
2684 throw nsee;
2685 }
2686 catch (Exception e) {
2687 throw processException(e);
2688 }
2689 finally {
2690 closeSession(session);
2691 }
2692 }
2693
2694 @Override
2695 protected UserGroupRole removeImpl(UserGroupRole userGroupRole)
2696 throws SystemException {
2697 userGroupRole = toUnwrappedModel(userGroupRole);
2698
2699 Session session = null;
2700
2701 try {
2702 session = openSession();
2703
2704 if (!session.contains(userGroupRole)) {
2705 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2706 userGroupRole.getPrimaryKeyObj());
2707 }
2708
2709 if (userGroupRole != null) {
2710 session.delete(userGroupRole);
2711 }
2712 }
2713 catch (Exception e) {
2714 throw processException(e);
2715 }
2716 finally {
2717 closeSession(session);
2718 }
2719
2720 if (userGroupRole != null) {
2721 clearCache(userGroupRole);
2722 }
2723
2724 return userGroupRole;
2725 }
2726
2727 @Override
2728 public UserGroupRole updateImpl(
2729 com.liferay.portal.model.UserGroupRole userGroupRole)
2730 throws SystemException {
2731 userGroupRole = toUnwrappedModel(userGroupRole);
2732
2733 boolean isNew = userGroupRole.isNew();
2734
2735 UserGroupRoleModelImpl userGroupRoleModelImpl = (UserGroupRoleModelImpl)userGroupRole;
2736
2737 Session session = null;
2738
2739 try {
2740 session = openSession();
2741
2742 if (userGroupRole.isNew()) {
2743 session.save(userGroupRole);
2744
2745 userGroupRole.setNew(false);
2746 }
2747 else {
2748 session.merge(userGroupRole);
2749 }
2750 }
2751 catch (Exception e) {
2752 throw processException(e);
2753 }
2754 finally {
2755 closeSession(session);
2756 }
2757
2758 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2759
2760 if (isNew || !UserGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
2761 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2762 }
2763
2764 else {
2765 if ((userGroupRoleModelImpl.getColumnBitmask() &
2766 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2767 Object[] args = new Object[] {
2768 userGroupRoleModelImpl.getOriginalUserId()
2769 };
2770
2771 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2772 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2773 args);
2774
2775 args = new Object[] { userGroupRoleModelImpl.getUserId() };
2776
2777 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2778 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2779 args);
2780 }
2781
2782 if ((userGroupRoleModelImpl.getColumnBitmask() &
2783 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2784 Object[] args = new Object[] {
2785 userGroupRoleModelImpl.getOriginalGroupId()
2786 };
2787
2788 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2789 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2790 args);
2791
2792 args = new Object[] { userGroupRoleModelImpl.getGroupId() };
2793
2794 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2795 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2796 args);
2797 }
2798
2799 if ((userGroupRoleModelImpl.getColumnBitmask() &
2800 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
2801 Object[] args = new Object[] {
2802 userGroupRoleModelImpl.getOriginalRoleId()
2803 };
2804
2805 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2806 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2807 args);
2808
2809 args = new Object[] { userGroupRoleModelImpl.getRoleId() };
2810
2811 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2812 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2813 args);
2814 }
2815
2816 if ((userGroupRoleModelImpl.getColumnBitmask() &
2817 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G.getColumnBitmask()) != 0) {
2818 Object[] args = new Object[] {
2819 userGroupRoleModelImpl.getOriginalUserId(),
2820 userGroupRoleModelImpl.getOriginalGroupId()
2821 };
2822
2823 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2824 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2825 args);
2826
2827 args = new Object[] {
2828 userGroupRoleModelImpl.getUserId(),
2829 userGroupRoleModelImpl.getGroupId()
2830 };
2831
2832 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2833 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2834 args);
2835 }
2836
2837 if ((userGroupRoleModelImpl.getColumnBitmask() &
2838 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R.getColumnBitmask()) != 0) {
2839 Object[] args = new Object[] {
2840 userGroupRoleModelImpl.getOriginalGroupId(),
2841 userGroupRoleModelImpl.getOriginalRoleId()
2842 };
2843
2844 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2845 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2846 args);
2847
2848 args = new Object[] {
2849 userGroupRoleModelImpl.getGroupId(),
2850 userGroupRoleModelImpl.getRoleId()
2851 };
2852
2853 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2854 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2855 args);
2856 }
2857 }
2858
2859 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2860 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2861 userGroupRole);
2862
2863 return userGroupRole;
2864 }
2865
2866 protected UserGroupRole toUnwrappedModel(UserGroupRole userGroupRole) {
2867 if (userGroupRole instanceof UserGroupRoleImpl) {
2868 return userGroupRole;
2869 }
2870
2871 UserGroupRoleImpl userGroupRoleImpl = new UserGroupRoleImpl();
2872
2873 userGroupRoleImpl.setNew(userGroupRole.isNew());
2874 userGroupRoleImpl.setPrimaryKey(userGroupRole.getPrimaryKey());
2875
2876 userGroupRoleImpl.setUserId(userGroupRole.getUserId());
2877 userGroupRoleImpl.setGroupId(userGroupRole.getGroupId());
2878 userGroupRoleImpl.setRoleId(userGroupRole.getRoleId());
2879
2880 return userGroupRoleImpl;
2881 }
2882
2883
2891 @Override
2892 public UserGroupRole findByPrimaryKey(Serializable primaryKey)
2893 throws NoSuchUserGroupRoleException, SystemException {
2894 UserGroupRole userGroupRole = fetchByPrimaryKey(primaryKey);
2895
2896 if (userGroupRole == null) {
2897 if (_log.isWarnEnabled()) {
2898 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2899 }
2900
2901 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2902 primaryKey);
2903 }
2904
2905 return userGroupRole;
2906 }
2907
2908
2916 public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
2917 throws NoSuchUserGroupRoleException, SystemException {
2918 return findByPrimaryKey((Serializable)userGroupRolePK);
2919 }
2920
2921
2928 @Override
2929 public UserGroupRole fetchByPrimaryKey(Serializable primaryKey)
2930 throws SystemException {
2931 UserGroupRole userGroupRole = (UserGroupRole)EntityCacheUtil.getResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2932 UserGroupRoleImpl.class, primaryKey);
2933
2934 if (userGroupRole == _nullUserGroupRole) {
2935 return null;
2936 }
2937
2938 if (userGroupRole == null) {
2939 Session session = null;
2940
2941 try {
2942 session = openSession();
2943
2944 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2945 primaryKey);
2946
2947 if (userGroupRole != null) {
2948 cacheResult(userGroupRole);
2949 }
2950 else {
2951 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2952 UserGroupRoleImpl.class, primaryKey, _nullUserGroupRole);
2953 }
2954 }
2955 catch (Exception e) {
2956 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2957 UserGroupRoleImpl.class, primaryKey);
2958
2959 throw processException(e);
2960 }
2961 finally {
2962 closeSession(session);
2963 }
2964 }
2965
2966 return userGroupRole;
2967 }
2968
2969
2976 public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK)
2977 throws SystemException {
2978 return fetchByPrimaryKey((Serializable)userGroupRolePK);
2979 }
2980
2981
2987 public List<UserGroupRole> findAll() throws SystemException {
2988 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2989 }
2990
2991
3003 public List<UserGroupRole> findAll(int start, int end)
3004 throws SystemException {
3005 return findAll(start, end, null);
3006 }
3007
3008
3021 public List<UserGroupRole> findAll(int start, int end,
3022 OrderByComparator orderByComparator) throws SystemException {
3023 boolean pagination = true;
3024 FinderPath finderPath = null;
3025 Object[] finderArgs = null;
3026
3027 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3028 (orderByComparator == null)) {
3029 pagination = false;
3030 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3031 finderArgs = FINDER_ARGS_EMPTY;
3032 }
3033 else {
3034 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3035 finderArgs = new Object[] { start, end, orderByComparator };
3036 }
3037
3038 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
3039 finderArgs, this);
3040
3041 if (list == null) {
3042 StringBundler query = null;
3043 String sql = null;
3044
3045 if (orderByComparator != null) {
3046 query = new StringBundler(2 +
3047 (orderByComparator.getOrderByFields().length * 3));
3048
3049 query.append(_SQL_SELECT_USERGROUPROLE);
3050
3051 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3052 orderByComparator);
3053
3054 sql = query.toString();
3055 }
3056 else {
3057 sql = _SQL_SELECT_USERGROUPROLE;
3058
3059 if (pagination) {
3060 sql = sql.concat(UserGroupRoleModelImpl.ORDER_BY_JPQL);
3061 }
3062 }
3063
3064 Session session = null;
3065
3066 try {
3067 session = openSession();
3068
3069 Query q = session.createQuery(sql);
3070
3071 if (!pagination) {
3072 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3073 start, end, false);
3074
3075 Collections.sort(list);
3076
3077 list = new UnmodifiableList<UserGroupRole>(list);
3078 }
3079 else {
3080 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3081 start, end);
3082 }
3083
3084 cacheResult(list);
3085
3086 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3087 }
3088 catch (Exception e) {
3089 FinderCacheUtil.removeResult(finderPath, finderArgs);
3090
3091 throw processException(e);
3092 }
3093 finally {
3094 closeSession(session);
3095 }
3096 }
3097
3098 return list;
3099 }
3100
3101
3106 public void removeAll() throws SystemException {
3107 for (UserGroupRole userGroupRole : findAll()) {
3108 remove(userGroupRole);
3109 }
3110 }
3111
3112
3118 public int countAll() throws SystemException {
3119 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3120 FINDER_ARGS_EMPTY, this);
3121
3122 if (count == null) {
3123 Session session = null;
3124
3125 try {
3126 session = openSession();
3127
3128 Query q = session.createQuery(_SQL_COUNT_USERGROUPROLE);
3129
3130 count = (Long)q.uniqueResult();
3131
3132 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3133 FINDER_ARGS_EMPTY, count);
3134 }
3135 catch (Exception e) {
3136 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3137 FINDER_ARGS_EMPTY);
3138
3139 throw processException(e);
3140 }
3141 finally {
3142 closeSession(session);
3143 }
3144 }
3145
3146 return count.intValue();
3147 }
3148
3149
3152 public void afterPropertiesSet() {
3153 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3154 com.liferay.portal.util.PropsUtil.get(
3155 "value.object.listener.com.liferay.portal.model.UserGroupRole")));
3156
3157 if (listenerClassNames.length > 0) {
3158 try {
3159 List<ModelListener<UserGroupRole>> listenersList = new ArrayList<ModelListener<UserGroupRole>>();
3160
3161 for (String listenerClassName : listenerClassNames) {
3162 listenersList.add((ModelListener<UserGroupRole>)InstanceFactory.newInstance(
3163 getClassLoader(), listenerClassName));
3164 }
3165
3166 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3167 }
3168 catch (Exception e) {
3169 _log.error(e);
3170 }
3171 }
3172 }
3173
3174 public void destroy() {
3175 EntityCacheUtil.removeCache(UserGroupRoleImpl.class.getName());
3176 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3177 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3178 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3179 }
3180
3181 private static final String _SQL_SELECT_USERGROUPROLE = "SELECT userGroupRole FROM UserGroupRole userGroupRole";
3182 private static final String _SQL_SELECT_USERGROUPROLE_WHERE = "SELECT userGroupRole FROM UserGroupRole userGroupRole WHERE ";
3183 private static final String _SQL_COUNT_USERGROUPROLE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole";
3184 private static final String _SQL_COUNT_USERGROUPROLE_WHERE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole WHERE ";
3185 private static final String _ORDER_BY_ENTITY_ALIAS = "userGroupRole.";
3186 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroupRole exists with the primary key ";
3187 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroupRole exists with the key {";
3188 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3189 private static Log _log = LogFactoryUtil.getLog(UserGroupRolePersistenceImpl.class);
3190 private static UserGroupRole _nullUserGroupRole = new UserGroupRoleImpl() {
3191 @Override
3192 public Object clone() {
3193 return this;
3194 }
3195
3196 @Override
3197 public CacheModel<UserGroupRole> toCacheModel() {
3198 return _nullUserGroupRoleCacheModel;
3199 }
3200 };
3201
3202 private static CacheModel<UserGroupRole> _nullUserGroupRoleCacheModel = new CacheModel<UserGroupRole>() {
3203 public UserGroupRole toEntityModel() {
3204 return _nullUserGroupRole;
3205 }
3206 };
3207 }