001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchUserGroupException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028 import com.liferay.portal.kernel.dao.orm.FinderPath;
029 import com.liferay.portal.kernel.dao.orm.Query;
030 import com.liferay.portal.kernel.dao.orm.QueryPos;
031 import com.liferay.portal.kernel.dao.orm.QueryUtil;
032 import com.liferay.portal.kernel.dao.orm.SQLQuery;
033 import com.liferay.portal.kernel.dao.orm.Session;
034 import com.liferay.portal.kernel.exception.SystemException;
035 import com.liferay.portal.kernel.log.Log;
036 import com.liferay.portal.kernel.log.LogFactoryUtil;
037 import com.liferay.portal.kernel.util.GetterUtil;
038 import com.liferay.portal.kernel.util.InstanceFactory;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.SetUtil;
041 import com.liferay.portal.kernel.util.StringBundler;
042 import com.liferay.portal.kernel.util.StringPool;
043 import com.liferay.portal.kernel.util.StringUtil;
044 import com.liferay.portal.kernel.util.Validator;
045 import com.liferay.portal.model.ModelListener;
046 import com.liferay.portal.model.UserGroup;
047 import com.liferay.portal.model.impl.UserGroupImpl;
048 import com.liferay.portal.model.impl.UserGroupModelImpl;
049 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050
051 import java.io.Serializable;
052
053 import java.util.ArrayList;
054 import java.util.Collections;
055 import java.util.List;
056 import java.util.Set;
057
058
074 public class UserGroupPersistenceImpl extends BasePersistenceImpl<UserGroup>
075 implements UserGroupPersistence {
076 public static final String FINDER_CLASS_NAME_ENTITY = UserGroupImpl.class.getName();
077 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
078 ".List";
079 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
080 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081 "findByCompanyId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
089 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090 "countByCompanyId", new String[] { Long.class.getName() });
091 public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
092 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093 "findByC_P",
094 new String[] {
095 Long.class.getName(), Long.class.getName(),
096
097 "java.lang.Integer", "java.lang.Integer",
098 "com.liferay.portal.kernel.util.OrderByComparator"
099 });
100 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
101 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102 "countByC_P",
103 new String[] { Long.class.getName(), Long.class.getName() });
104 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
105 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
106 "fetchByC_N",
107 new String[] { Long.class.getName(), String.class.getName() });
108 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
109 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110 "countByC_N",
111 new String[] { Long.class.getName(), String.class.getName() });
112 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
113 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "findAll", new String[0]);
115 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
116 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117 "countAll", new String[0]);
118
119
124 public void cacheResult(UserGroup userGroup) {
125 EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
126 UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
127
128 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
129 new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() },
130 userGroup);
131 }
132
133
138 public void cacheResult(List<UserGroup> userGroups) {
139 for (UserGroup userGroup : userGroups) {
140 if (EntityCacheUtil.getResult(
141 UserGroupModelImpl.ENTITY_CACHE_ENABLED,
142 UserGroupImpl.class, userGroup.getPrimaryKey(), this) == null) {
143 cacheResult(userGroup);
144 }
145 }
146 }
147
148
155 public void clearCache() {
156 CacheRegistryUtil.clear(UserGroupImpl.class.getName());
157 EntityCacheUtil.clearCache(UserGroupImpl.class.getName());
158 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
159 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
160 }
161
162
169 public void clearCache(UserGroup userGroup) {
170 EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
171 UserGroupImpl.class, userGroup.getPrimaryKey());
172
173 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
174 new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() });
175 }
176
177
183 public UserGroup create(long userGroupId) {
184 UserGroup userGroup = new UserGroupImpl();
185
186 userGroup.setNew(true);
187 userGroup.setPrimaryKey(userGroupId);
188
189 return userGroup;
190 }
191
192
200 public UserGroup remove(Serializable primaryKey)
201 throws NoSuchModelException, SystemException {
202 return remove(((Long)primaryKey).longValue());
203 }
204
205
213 public UserGroup remove(long userGroupId)
214 throws NoSuchUserGroupException, SystemException {
215 Session session = null;
216
217 try {
218 session = openSession();
219
220 UserGroup userGroup = (UserGroup)session.get(UserGroupImpl.class,
221 new Long(userGroupId));
222
223 if (userGroup == null) {
224 if (_log.isWarnEnabled()) {
225 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
226 }
227
228 throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
229 userGroupId);
230 }
231
232 return remove(userGroup);
233 }
234 catch (NoSuchUserGroupException nsee) {
235 throw nsee;
236 }
237 catch (Exception e) {
238 throw processException(e);
239 }
240 finally {
241 closeSession(session);
242 }
243 }
244
245 protected UserGroup removeImpl(UserGroup userGroup)
246 throws SystemException {
247 userGroup = toUnwrappedModel(userGroup);
248
249 try {
250 clearGroups.clear(userGroup.getPrimaryKey());
251 }
252 catch (Exception e) {
253 throw processException(e);
254 }
255 finally {
256 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
257 }
258
259 try {
260 clearUsers.clear(userGroup.getPrimaryKey());
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
267 }
268
269 Session session = null;
270
271 try {
272 session = openSession();
273
274 BatchSessionUtil.delete(session, userGroup);
275 }
276 catch (Exception e) {
277 throw processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282
283 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
284
285 UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
286
287 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
288 new Object[] {
289 new Long(userGroupModelImpl.getOriginalCompanyId()),
290
291 userGroupModelImpl.getOriginalName()
292 });
293
294 EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
295 UserGroupImpl.class, userGroup.getPrimaryKey());
296
297 return userGroup;
298 }
299
300 public UserGroup updateImpl(com.liferay.portal.model.UserGroup userGroup,
301 boolean merge) throws SystemException {
302 userGroup = toUnwrappedModel(userGroup);
303
304 boolean isNew = userGroup.isNew();
305
306 UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
307
308 Session session = null;
309
310 try {
311 session = openSession();
312
313 BatchSessionUtil.update(session, userGroup, merge);
314
315 userGroup.setNew(false);
316 }
317 catch (Exception e) {
318 throw processException(e);
319 }
320 finally {
321 closeSession(session);
322 }
323
324 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
325
326 EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
327 UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
328
329 if (!isNew &&
330 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
331 !Validator.equals(userGroup.getName(),
332 userGroupModelImpl.getOriginalName()))) {
333 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
334 new Object[] {
335 new Long(userGroupModelImpl.getOriginalCompanyId()),
336
337 userGroupModelImpl.getOriginalName()
338 });
339 }
340
341 if (isNew ||
342 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
343 !Validator.equals(userGroup.getName(),
344 userGroupModelImpl.getOriginalName()))) {
345 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
346 new Object[] {
347 new Long(userGroup.getCompanyId()),
348
349 userGroup.getName()
350 }, userGroup);
351 }
352
353 return userGroup;
354 }
355
356 protected UserGroup toUnwrappedModel(UserGroup userGroup) {
357 if (userGroup instanceof UserGroupImpl) {
358 return userGroup;
359 }
360
361 UserGroupImpl userGroupImpl = new UserGroupImpl();
362
363 userGroupImpl.setNew(userGroup.isNew());
364 userGroupImpl.setPrimaryKey(userGroup.getPrimaryKey());
365
366 userGroupImpl.setUserGroupId(userGroup.getUserGroupId());
367 userGroupImpl.setCompanyId(userGroup.getCompanyId());
368 userGroupImpl.setParentUserGroupId(userGroup.getParentUserGroupId());
369 userGroupImpl.setName(userGroup.getName());
370 userGroupImpl.setDescription(userGroup.getDescription());
371
372 return userGroupImpl;
373 }
374
375
383 public UserGroup findByPrimaryKey(Serializable primaryKey)
384 throws NoSuchModelException, SystemException {
385 return findByPrimaryKey(((Long)primaryKey).longValue());
386 }
387
388
396 public UserGroup findByPrimaryKey(long userGroupId)
397 throws NoSuchUserGroupException, SystemException {
398 UserGroup userGroup = fetchByPrimaryKey(userGroupId);
399
400 if (userGroup == null) {
401 if (_log.isWarnEnabled()) {
402 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
403 }
404
405 throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
406 userGroupId);
407 }
408
409 return userGroup;
410 }
411
412
419 public UserGroup fetchByPrimaryKey(Serializable primaryKey)
420 throws SystemException {
421 return fetchByPrimaryKey(((Long)primaryKey).longValue());
422 }
423
424
431 public UserGroup fetchByPrimaryKey(long userGroupId)
432 throws SystemException {
433 UserGroup userGroup = (UserGroup)EntityCacheUtil.getResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
434 UserGroupImpl.class, userGroupId, this);
435
436 if (userGroup == null) {
437 Session session = null;
438
439 try {
440 session = openSession();
441
442 userGroup = (UserGroup)session.get(UserGroupImpl.class,
443 new Long(userGroupId));
444 }
445 catch (Exception e) {
446 throw processException(e);
447 }
448 finally {
449 if (userGroup != null) {
450 cacheResult(userGroup);
451 }
452
453 closeSession(session);
454 }
455 }
456
457 return userGroup;
458 }
459
460
467 public List<UserGroup> findByCompanyId(long companyId)
468 throws SystemException {
469 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
470 null);
471 }
472
473
486 public List<UserGroup> findByCompanyId(long companyId, int start, int end)
487 throws SystemException {
488 return findByCompanyId(companyId, start, end, null);
489 }
490
491
505 public List<UserGroup> findByCompanyId(long companyId, int start, int end,
506 OrderByComparator orderByComparator) throws SystemException {
507 Object[] finderArgs = new Object[] {
508 companyId,
509
510 String.valueOf(start), String.valueOf(end),
511 String.valueOf(orderByComparator)
512 };
513
514 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
515 finderArgs, this);
516
517 if (list == null) {
518 Session session = null;
519
520 try {
521 session = openSession();
522
523 StringBundler query = null;
524
525 if (orderByComparator != null) {
526 query = new StringBundler(3 +
527 (orderByComparator.getOrderByFields().length * 3));
528 }
529 else {
530 query = new StringBundler(3);
531 }
532
533 query.append(_SQL_SELECT_USERGROUP_WHERE);
534
535 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
536
537 if (orderByComparator != null) {
538 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
539 orderByComparator);
540 }
541
542 else {
543 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
544 }
545
546 String sql = query.toString();
547
548 Query q = session.createQuery(sql);
549
550 QueryPos qPos = QueryPos.getInstance(q);
551
552 qPos.add(companyId);
553
554 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
555 end);
556 }
557 catch (Exception e) {
558 throw processException(e);
559 }
560 finally {
561 if (list == null) {
562 list = new ArrayList<UserGroup>();
563 }
564
565 cacheResult(list);
566
567 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
568 finderArgs, list);
569
570 closeSession(session);
571 }
572 }
573
574 return list;
575 }
576
577
590 public UserGroup findByCompanyId_First(long companyId,
591 OrderByComparator orderByComparator)
592 throws NoSuchUserGroupException, SystemException {
593 List<UserGroup> list = findByCompanyId(companyId, 0, 1,
594 orderByComparator);
595
596 if (list.isEmpty()) {
597 StringBundler msg = new StringBundler(4);
598
599 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
600
601 msg.append("companyId=");
602 msg.append(companyId);
603
604 msg.append(StringPool.CLOSE_CURLY_BRACE);
605
606 throw new NoSuchUserGroupException(msg.toString());
607 }
608 else {
609 return list.get(0);
610 }
611 }
612
613
626 public UserGroup findByCompanyId_Last(long companyId,
627 OrderByComparator orderByComparator)
628 throws NoSuchUserGroupException, SystemException {
629 int count = countByCompanyId(companyId);
630
631 List<UserGroup> list = findByCompanyId(companyId, count - 1, count,
632 orderByComparator);
633
634 if (list.isEmpty()) {
635 StringBundler msg = new StringBundler(4);
636
637 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
638
639 msg.append("companyId=");
640 msg.append(companyId);
641
642 msg.append(StringPool.CLOSE_CURLY_BRACE);
643
644 throw new NoSuchUserGroupException(msg.toString());
645 }
646 else {
647 return list.get(0);
648 }
649 }
650
651
665 public UserGroup[] findByCompanyId_PrevAndNext(long userGroupId,
666 long companyId, OrderByComparator orderByComparator)
667 throws NoSuchUserGroupException, SystemException {
668 UserGroup userGroup = findByPrimaryKey(userGroupId);
669
670 Session session = null;
671
672 try {
673 session = openSession();
674
675 UserGroup[] array = new UserGroupImpl[3];
676
677 array[0] = getByCompanyId_PrevAndNext(session, userGroup,
678 companyId, orderByComparator, true);
679
680 array[1] = userGroup;
681
682 array[2] = getByCompanyId_PrevAndNext(session, userGroup,
683 companyId, orderByComparator, false);
684
685 return array;
686 }
687 catch (Exception e) {
688 throw processException(e);
689 }
690 finally {
691 closeSession(session);
692 }
693 }
694
695 protected UserGroup getByCompanyId_PrevAndNext(Session session,
696 UserGroup userGroup, long companyId,
697 OrderByComparator orderByComparator, boolean previous) {
698 StringBundler query = null;
699
700 if (orderByComparator != null) {
701 query = new StringBundler(6 +
702 (orderByComparator.getOrderByFields().length * 6));
703 }
704 else {
705 query = new StringBundler(3);
706 }
707
708 query.append(_SQL_SELECT_USERGROUP_WHERE);
709
710 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
711
712 if (orderByComparator != null) {
713 String[] orderByFields = orderByComparator.getOrderByFields();
714
715 if (orderByFields.length > 0) {
716 query.append(WHERE_AND);
717 }
718
719 for (int i = 0; i < orderByFields.length; i++) {
720 query.append(_ORDER_BY_ENTITY_ALIAS);
721 query.append(orderByFields[i]);
722
723 if ((i + 1) < orderByFields.length) {
724 if (orderByComparator.isAscending() ^ previous) {
725 query.append(WHERE_GREATER_THAN_HAS_NEXT);
726 }
727 else {
728 query.append(WHERE_LESSER_THAN_HAS_NEXT);
729 }
730 }
731 else {
732 if (orderByComparator.isAscending() ^ previous) {
733 query.append(WHERE_GREATER_THAN);
734 }
735 else {
736 query.append(WHERE_LESSER_THAN);
737 }
738 }
739 }
740
741 query.append(ORDER_BY_CLAUSE);
742
743 for (int i = 0; i < orderByFields.length; i++) {
744 query.append(_ORDER_BY_ENTITY_ALIAS);
745 query.append(orderByFields[i]);
746
747 if ((i + 1) < orderByFields.length) {
748 if (orderByComparator.isAscending() ^ previous) {
749 query.append(ORDER_BY_ASC_HAS_NEXT);
750 }
751 else {
752 query.append(ORDER_BY_DESC_HAS_NEXT);
753 }
754 }
755 else {
756 if (orderByComparator.isAscending() ^ previous) {
757 query.append(ORDER_BY_ASC);
758 }
759 else {
760 query.append(ORDER_BY_DESC);
761 }
762 }
763 }
764 }
765
766 else {
767 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
768 }
769
770 String sql = query.toString();
771
772 Query q = session.createQuery(sql);
773
774 q.setFirstResult(0);
775 q.setMaxResults(2);
776
777 QueryPos qPos = QueryPos.getInstance(q);
778
779 qPos.add(companyId);
780
781 if (orderByComparator != null) {
782 Object[] values = orderByComparator.getOrderByValues(userGroup);
783
784 for (Object value : values) {
785 qPos.add(value);
786 }
787 }
788
789 List<UserGroup> list = q.list();
790
791 if (list.size() == 2) {
792 return list.get(1);
793 }
794 else {
795 return null;
796 }
797 }
798
799
807 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId)
808 throws SystemException {
809 return findByC_P(companyId, parentUserGroupId, QueryUtil.ALL_POS,
810 QueryUtil.ALL_POS, null);
811 }
812
813
827 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
828 int start, int end) throws SystemException {
829 return findByC_P(companyId, parentUserGroupId, start, end, null);
830 }
831
832
847 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
848 int start, int end, OrderByComparator orderByComparator)
849 throws SystemException {
850 Object[] finderArgs = new Object[] {
851 companyId, parentUserGroupId,
852
853 String.valueOf(start), String.valueOf(end),
854 String.valueOf(orderByComparator)
855 };
856
857 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
858 finderArgs, this);
859
860 if (list == null) {
861 Session session = null;
862
863 try {
864 session = openSession();
865
866 StringBundler query = null;
867
868 if (orderByComparator != null) {
869 query = new StringBundler(4 +
870 (orderByComparator.getOrderByFields().length * 3));
871 }
872 else {
873 query = new StringBundler(4);
874 }
875
876 query.append(_SQL_SELECT_USERGROUP_WHERE);
877
878 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
879
880 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
881
882 if (orderByComparator != null) {
883 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
884 orderByComparator);
885 }
886
887 else {
888 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
889 }
890
891 String sql = query.toString();
892
893 Query q = session.createQuery(sql);
894
895 QueryPos qPos = QueryPos.getInstance(q);
896
897 qPos.add(companyId);
898
899 qPos.add(parentUserGroupId);
900
901 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
902 end);
903 }
904 catch (Exception e) {
905 throw processException(e);
906 }
907 finally {
908 if (list == null) {
909 list = new ArrayList<UserGroup>();
910 }
911
912 cacheResult(list);
913
914 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
915 list);
916
917 closeSession(session);
918 }
919 }
920
921 return list;
922 }
923
924
938 public UserGroup findByC_P_First(long companyId, long parentUserGroupId,
939 OrderByComparator orderByComparator)
940 throws NoSuchUserGroupException, SystemException {
941 List<UserGroup> list = findByC_P(companyId, parentUserGroupId, 0, 1,
942 orderByComparator);
943
944 if (list.isEmpty()) {
945 StringBundler msg = new StringBundler(6);
946
947 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
948
949 msg.append("companyId=");
950 msg.append(companyId);
951
952 msg.append(", parentUserGroupId=");
953 msg.append(parentUserGroupId);
954
955 msg.append(StringPool.CLOSE_CURLY_BRACE);
956
957 throw new NoSuchUserGroupException(msg.toString());
958 }
959 else {
960 return list.get(0);
961 }
962 }
963
964
978 public UserGroup findByC_P_Last(long companyId, long parentUserGroupId,
979 OrderByComparator orderByComparator)
980 throws NoSuchUserGroupException, SystemException {
981 int count = countByC_P(companyId, parentUserGroupId);
982
983 List<UserGroup> list = findByC_P(companyId, parentUserGroupId,
984 count - 1, count, orderByComparator);
985
986 if (list.isEmpty()) {
987 StringBundler msg = new StringBundler(6);
988
989 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
990
991 msg.append("companyId=");
992 msg.append(companyId);
993
994 msg.append(", parentUserGroupId=");
995 msg.append(parentUserGroupId);
996
997 msg.append(StringPool.CLOSE_CURLY_BRACE);
998
999 throw new NoSuchUserGroupException(msg.toString());
1000 }
1001 else {
1002 return list.get(0);
1003 }
1004 }
1005
1006
1021 public UserGroup[] findByC_P_PrevAndNext(long userGroupId, long companyId,
1022 long parentUserGroupId, OrderByComparator orderByComparator)
1023 throws NoSuchUserGroupException, SystemException {
1024 UserGroup userGroup = findByPrimaryKey(userGroupId);
1025
1026 Session session = null;
1027
1028 try {
1029 session = openSession();
1030
1031 UserGroup[] array = new UserGroupImpl[3];
1032
1033 array[0] = getByC_P_PrevAndNext(session, userGroup, companyId,
1034 parentUserGroupId, orderByComparator, true);
1035
1036 array[1] = userGroup;
1037
1038 array[2] = getByC_P_PrevAndNext(session, userGroup, companyId,
1039 parentUserGroupId, orderByComparator, false);
1040
1041 return array;
1042 }
1043 catch (Exception e) {
1044 throw processException(e);
1045 }
1046 finally {
1047 closeSession(session);
1048 }
1049 }
1050
1051 protected UserGroup getByC_P_PrevAndNext(Session session,
1052 UserGroup userGroup, long companyId, long parentUserGroupId,
1053 OrderByComparator orderByComparator, boolean previous) {
1054 StringBundler query = null;
1055
1056 if (orderByComparator != null) {
1057 query = new StringBundler(6 +
1058 (orderByComparator.getOrderByFields().length * 6));
1059 }
1060 else {
1061 query = new StringBundler(3);
1062 }
1063
1064 query.append(_SQL_SELECT_USERGROUP_WHERE);
1065
1066 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1067
1068 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1069
1070 if (orderByComparator != null) {
1071 String[] orderByFields = orderByComparator.getOrderByFields();
1072
1073 if (orderByFields.length > 0) {
1074 query.append(WHERE_AND);
1075 }
1076
1077 for (int i = 0; i < orderByFields.length; i++) {
1078 query.append(_ORDER_BY_ENTITY_ALIAS);
1079 query.append(orderByFields[i]);
1080
1081 if ((i + 1) < orderByFields.length) {
1082 if (orderByComparator.isAscending() ^ previous) {
1083 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1084 }
1085 else {
1086 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1087 }
1088 }
1089 else {
1090 if (orderByComparator.isAscending() ^ previous) {
1091 query.append(WHERE_GREATER_THAN);
1092 }
1093 else {
1094 query.append(WHERE_LESSER_THAN);
1095 }
1096 }
1097 }
1098
1099 query.append(ORDER_BY_CLAUSE);
1100
1101 for (int i = 0; i < orderByFields.length; i++) {
1102 query.append(_ORDER_BY_ENTITY_ALIAS);
1103 query.append(orderByFields[i]);
1104
1105 if ((i + 1) < orderByFields.length) {
1106 if (orderByComparator.isAscending() ^ previous) {
1107 query.append(ORDER_BY_ASC_HAS_NEXT);
1108 }
1109 else {
1110 query.append(ORDER_BY_DESC_HAS_NEXT);
1111 }
1112 }
1113 else {
1114 if (orderByComparator.isAscending() ^ previous) {
1115 query.append(ORDER_BY_ASC);
1116 }
1117 else {
1118 query.append(ORDER_BY_DESC);
1119 }
1120 }
1121 }
1122 }
1123
1124 else {
1125 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1126 }
1127
1128 String sql = query.toString();
1129
1130 Query q = session.createQuery(sql);
1131
1132 q.setFirstResult(0);
1133 q.setMaxResults(2);
1134
1135 QueryPos qPos = QueryPos.getInstance(q);
1136
1137 qPos.add(companyId);
1138
1139 qPos.add(parentUserGroupId);
1140
1141 if (orderByComparator != null) {
1142 Object[] values = orderByComparator.getOrderByValues(userGroup);
1143
1144 for (Object value : values) {
1145 qPos.add(value);
1146 }
1147 }
1148
1149 List<UserGroup> list = q.list();
1150
1151 if (list.size() == 2) {
1152 return list.get(1);
1153 }
1154 else {
1155 return null;
1156 }
1157 }
1158
1159
1168 public UserGroup findByC_N(long companyId, String name)
1169 throws NoSuchUserGroupException, SystemException {
1170 UserGroup userGroup = fetchByC_N(companyId, name);
1171
1172 if (userGroup == null) {
1173 StringBundler msg = new StringBundler(6);
1174
1175 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1176
1177 msg.append("companyId=");
1178 msg.append(companyId);
1179
1180 msg.append(", name=");
1181 msg.append(name);
1182
1183 msg.append(StringPool.CLOSE_CURLY_BRACE);
1184
1185 if (_log.isWarnEnabled()) {
1186 _log.warn(msg.toString());
1187 }
1188
1189 throw new NoSuchUserGroupException(msg.toString());
1190 }
1191
1192 return userGroup;
1193 }
1194
1195
1203 public UserGroup fetchByC_N(long companyId, String name)
1204 throws SystemException {
1205 return fetchByC_N(companyId, name, true);
1206 }
1207
1208
1216 public UserGroup fetchByC_N(long companyId, String name,
1217 boolean retrieveFromCache) throws SystemException {
1218 Object[] finderArgs = new Object[] { companyId, name };
1219
1220 Object result = null;
1221
1222 if (retrieveFromCache) {
1223 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
1224 finderArgs, this);
1225 }
1226
1227 if (result == null) {
1228 Session session = null;
1229
1230 try {
1231 session = openSession();
1232
1233 StringBundler query = new StringBundler(4);
1234
1235 query.append(_SQL_SELECT_USERGROUP_WHERE);
1236
1237 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1238
1239 if (name == null) {
1240 query.append(_FINDER_COLUMN_C_N_NAME_1);
1241 }
1242 else {
1243 if (name.equals(StringPool.BLANK)) {
1244 query.append(_FINDER_COLUMN_C_N_NAME_3);
1245 }
1246 else {
1247 query.append(_FINDER_COLUMN_C_N_NAME_2);
1248 }
1249 }
1250
1251 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1252
1253 String sql = query.toString();
1254
1255 Query q = session.createQuery(sql);
1256
1257 QueryPos qPos = QueryPos.getInstance(q);
1258
1259 qPos.add(companyId);
1260
1261 if (name != null) {
1262 qPos.add(name);
1263 }
1264
1265 List<UserGroup> list = q.list();
1266
1267 result = list;
1268
1269 UserGroup userGroup = null;
1270
1271 if (list.isEmpty()) {
1272 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1273 finderArgs, list);
1274 }
1275 else {
1276 userGroup = list.get(0);
1277
1278 cacheResult(userGroup);
1279
1280 if ((userGroup.getCompanyId() != companyId) ||
1281 (userGroup.getName() == null) ||
1282 !userGroup.getName().equals(name)) {
1283 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1284 finderArgs, userGroup);
1285 }
1286 }
1287
1288 return userGroup;
1289 }
1290 catch (Exception e) {
1291 throw processException(e);
1292 }
1293 finally {
1294 if (result == null) {
1295 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1296 finderArgs, new ArrayList<UserGroup>());
1297 }
1298
1299 closeSession(session);
1300 }
1301 }
1302 else {
1303 if (result instanceof List<?>) {
1304 return null;
1305 }
1306 else {
1307 return (UserGroup)result;
1308 }
1309 }
1310 }
1311
1312
1318 public List<UserGroup> findAll() throws SystemException {
1319 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1320 }
1321
1322
1334 public List<UserGroup> findAll(int start, int end)
1335 throws SystemException {
1336 return findAll(start, end, null);
1337 }
1338
1339
1352 public List<UserGroup> findAll(int start, int end,
1353 OrderByComparator orderByComparator) throws SystemException {
1354 Object[] finderArgs = new Object[] {
1355 String.valueOf(start), String.valueOf(end),
1356 String.valueOf(orderByComparator)
1357 };
1358
1359 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1360 finderArgs, this);
1361
1362 if (list == null) {
1363 Session session = null;
1364
1365 try {
1366 session = openSession();
1367
1368 StringBundler query = null;
1369 String sql = null;
1370
1371 if (orderByComparator != null) {
1372 query = new StringBundler(2 +
1373 (orderByComparator.getOrderByFields().length * 3));
1374
1375 query.append(_SQL_SELECT_USERGROUP);
1376
1377 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1378 orderByComparator);
1379
1380 sql = query.toString();
1381 }
1382 else {
1383 sql = _SQL_SELECT_USERGROUP.concat(UserGroupModelImpl.ORDER_BY_JPQL);
1384 }
1385
1386 Query q = session.createQuery(sql);
1387
1388 if (orderByComparator == null) {
1389 list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1390 start, end, false);
1391
1392 Collections.sort(list);
1393 }
1394 else {
1395 list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1396 start, end);
1397 }
1398 }
1399 catch (Exception e) {
1400 throw processException(e);
1401 }
1402 finally {
1403 if (list == null) {
1404 list = new ArrayList<UserGroup>();
1405 }
1406
1407 cacheResult(list);
1408
1409 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1410
1411 closeSession(session);
1412 }
1413 }
1414
1415 return list;
1416 }
1417
1418
1424 public void removeByCompanyId(long companyId) throws SystemException {
1425 for (UserGroup userGroup : findByCompanyId(companyId)) {
1426 remove(userGroup);
1427 }
1428 }
1429
1430
1437 public void removeByC_P(long companyId, long parentUserGroupId)
1438 throws SystemException {
1439 for (UserGroup userGroup : findByC_P(companyId, parentUserGroupId)) {
1440 remove(userGroup);
1441 }
1442 }
1443
1444
1451 public void removeByC_N(long companyId, String name)
1452 throws NoSuchUserGroupException, SystemException {
1453 UserGroup userGroup = findByC_N(companyId, name);
1454
1455 remove(userGroup);
1456 }
1457
1458
1463 public void removeAll() throws SystemException {
1464 for (UserGroup userGroup : findAll()) {
1465 remove(userGroup);
1466 }
1467 }
1468
1469
1476 public int countByCompanyId(long companyId) throws SystemException {
1477 Object[] finderArgs = new Object[] { companyId };
1478
1479 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1480 finderArgs, this);
1481
1482 if (count == null) {
1483 Session session = null;
1484
1485 try {
1486 session = openSession();
1487
1488 StringBundler query = new StringBundler(2);
1489
1490 query.append(_SQL_COUNT_USERGROUP_WHERE);
1491
1492 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1493
1494 String sql = query.toString();
1495
1496 Query q = session.createQuery(sql);
1497
1498 QueryPos qPos = QueryPos.getInstance(q);
1499
1500 qPos.add(companyId);
1501
1502 count = (Long)q.uniqueResult();
1503 }
1504 catch (Exception e) {
1505 throw processException(e);
1506 }
1507 finally {
1508 if (count == null) {
1509 count = Long.valueOf(0);
1510 }
1511
1512 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1513 finderArgs, count);
1514
1515 closeSession(session);
1516 }
1517 }
1518
1519 return count.intValue();
1520 }
1521
1522
1530 public int countByC_P(long companyId, long parentUserGroupId)
1531 throws SystemException {
1532 Object[] finderArgs = new Object[] { companyId, parentUserGroupId };
1533
1534 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1535 finderArgs, this);
1536
1537 if (count == null) {
1538 Session session = null;
1539
1540 try {
1541 session = openSession();
1542
1543 StringBundler query = new StringBundler(3);
1544
1545 query.append(_SQL_COUNT_USERGROUP_WHERE);
1546
1547 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1548
1549 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1550
1551 String sql = query.toString();
1552
1553 Query q = session.createQuery(sql);
1554
1555 QueryPos qPos = QueryPos.getInstance(q);
1556
1557 qPos.add(companyId);
1558
1559 qPos.add(parentUserGroupId);
1560
1561 count = (Long)q.uniqueResult();
1562 }
1563 catch (Exception e) {
1564 throw processException(e);
1565 }
1566 finally {
1567 if (count == null) {
1568 count = Long.valueOf(0);
1569 }
1570
1571 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1572 count);
1573
1574 closeSession(session);
1575 }
1576 }
1577
1578 return count.intValue();
1579 }
1580
1581
1589 public int countByC_N(long companyId, String name)
1590 throws SystemException {
1591 Object[] finderArgs = new Object[] { companyId, name };
1592
1593 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1594 finderArgs, this);
1595
1596 if (count == null) {
1597 Session session = null;
1598
1599 try {
1600 session = openSession();
1601
1602 StringBundler query = new StringBundler(3);
1603
1604 query.append(_SQL_COUNT_USERGROUP_WHERE);
1605
1606 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1607
1608 if (name == null) {
1609 query.append(_FINDER_COLUMN_C_N_NAME_1);
1610 }
1611 else {
1612 if (name.equals(StringPool.BLANK)) {
1613 query.append(_FINDER_COLUMN_C_N_NAME_3);
1614 }
1615 else {
1616 query.append(_FINDER_COLUMN_C_N_NAME_2);
1617 }
1618 }
1619
1620 String sql = query.toString();
1621
1622 Query q = session.createQuery(sql);
1623
1624 QueryPos qPos = QueryPos.getInstance(q);
1625
1626 qPos.add(companyId);
1627
1628 if (name != null) {
1629 qPos.add(name);
1630 }
1631
1632 count = (Long)q.uniqueResult();
1633 }
1634 catch (Exception e) {
1635 throw processException(e);
1636 }
1637 finally {
1638 if (count == null) {
1639 count = Long.valueOf(0);
1640 }
1641
1642 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1643 count);
1644
1645 closeSession(session);
1646 }
1647 }
1648
1649 return count.intValue();
1650 }
1651
1652
1658 public int countAll() throws SystemException {
1659 Object[] finderArgs = new Object[0];
1660
1661 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1662 finderArgs, this);
1663
1664 if (count == null) {
1665 Session session = null;
1666
1667 try {
1668 session = openSession();
1669
1670 Query q = session.createQuery(_SQL_COUNT_USERGROUP);
1671
1672 count = (Long)q.uniqueResult();
1673 }
1674 catch (Exception e) {
1675 throw processException(e);
1676 }
1677 finally {
1678 if (count == null) {
1679 count = Long.valueOf(0);
1680 }
1681
1682 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1683 count);
1684
1685 closeSession(session);
1686 }
1687 }
1688
1689 return count.intValue();
1690 }
1691
1692
1699 public List<com.liferay.portal.model.Group> getGroups(long pk)
1700 throws SystemException {
1701 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1702 }
1703
1704
1717 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1718 int end) throws SystemException {
1719 return getGroups(pk, start, end, null);
1720 }
1721
1722 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1723 UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1724 UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1725 "getGroups",
1726 new String[] {
1727 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1728 "com.liferay.portal.kernel.util.OrderByComparator"
1729 });
1730
1731
1745 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1746 int end, OrderByComparator orderByComparator) throws SystemException {
1747 Object[] finderArgs = new Object[] {
1748 pk, String.valueOf(start), String.valueOf(end),
1749 String.valueOf(orderByComparator)
1750 };
1751
1752 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1753 finderArgs, this);
1754
1755 if (list == null) {
1756 Session session = null;
1757
1758 try {
1759 session = openSession();
1760
1761 String sql = null;
1762
1763 if (orderByComparator != null) {
1764 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1765 .concat(orderByComparator.getOrderBy());
1766 }
1767 else {
1768 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1769 }
1770
1771 SQLQuery q = session.createSQLQuery(sql);
1772
1773 q.addEntity("Group_",
1774 com.liferay.portal.model.impl.GroupImpl.class);
1775
1776 QueryPos qPos = QueryPos.getInstance(q);
1777
1778 qPos.add(pk);
1779
1780 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1781 getDialect(), start, end);
1782 }
1783 catch (Exception e) {
1784 throw processException(e);
1785 }
1786 finally {
1787 if (list == null) {
1788 list = new ArrayList<com.liferay.portal.model.Group>();
1789 }
1790
1791 groupPersistence.cacheResult(list);
1792
1793 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1794 list);
1795
1796 closeSession(session);
1797 }
1798 }
1799
1800 return list;
1801 }
1802
1803 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1804 UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1805 UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1806 "getGroupsSize", new String[] { Long.class.getName() });
1807
1808
1815 public int getGroupsSize(long pk) throws SystemException {
1816 Object[] finderArgs = new Object[] { pk };
1817
1818 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1819 finderArgs, this);
1820
1821 if (count == null) {
1822 Session session = null;
1823
1824 try {
1825 session = openSession();
1826
1827 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1828
1829 q.addScalar(COUNT_COLUMN_NAME,
1830 com.liferay.portal.kernel.dao.orm.Type.LONG);
1831
1832 QueryPos qPos = QueryPos.getInstance(q);
1833
1834 qPos.add(pk);
1835
1836 count = (Long)q.uniqueResult();
1837 }
1838 catch (Exception e) {
1839 throw processException(e);
1840 }
1841 finally {
1842 if (count == null) {
1843 count = Long.valueOf(0);
1844 }
1845
1846 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1847 finderArgs, count);
1848
1849 closeSession(session);
1850 }
1851 }
1852
1853 return count.intValue();
1854 }
1855
1856 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1857 UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1858 UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1859 "containsGroup",
1860 new String[] { Long.class.getName(), Long.class.getName() });
1861
1862
1870 public boolean containsGroup(long pk, long groupPK)
1871 throws SystemException {
1872 Object[] finderArgs = new Object[] { pk, groupPK };
1873
1874 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1875 finderArgs, this);
1876
1877 if (value == null) {
1878 try {
1879 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1880 }
1881 catch (Exception e) {
1882 throw processException(e);
1883 }
1884 finally {
1885 if (value == null) {
1886 value = Boolean.FALSE;
1887 }
1888
1889 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1890 finderArgs, value);
1891 }
1892 }
1893
1894 return value.booleanValue();
1895 }
1896
1897
1904 public boolean containsGroups(long pk) throws SystemException {
1905 if (getGroupsSize(pk) > 0) {
1906 return true;
1907 }
1908 else {
1909 return false;
1910 }
1911 }
1912
1913
1920 public void addGroup(long pk, long groupPK) throws SystemException {
1921 try {
1922 addGroup.add(pk, groupPK);
1923 }
1924 catch (Exception e) {
1925 throw processException(e);
1926 }
1927 finally {
1928 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1929 }
1930 }
1931
1932
1939 public void addGroup(long pk, com.liferay.portal.model.Group group)
1940 throws SystemException {
1941 try {
1942 addGroup.add(pk, group.getPrimaryKey());
1943 }
1944 catch (Exception e) {
1945 throw processException(e);
1946 }
1947 finally {
1948 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1949 }
1950 }
1951
1952
1959 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1960 try {
1961 for (long groupPK : groupPKs) {
1962 addGroup.add(pk, groupPK);
1963 }
1964 }
1965 catch (Exception e) {
1966 throw processException(e);
1967 }
1968 finally {
1969 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1970 }
1971 }
1972
1973
1980 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1981 throws SystemException {
1982 try {
1983 for (com.liferay.portal.model.Group group : groups) {
1984 addGroup.add(pk, group.getPrimaryKey());
1985 }
1986 }
1987 catch (Exception e) {
1988 throw processException(e);
1989 }
1990 finally {
1991 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1992 }
1993 }
1994
1995
2001 public void clearGroups(long pk) throws SystemException {
2002 try {
2003 clearGroups.clear(pk);
2004 }
2005 catch (Exception e) {
2006 throw processException(e);
2007 }
2008 finally {
2009 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2010 }
2011 }
2012
2013
2020 public void removeGroup(long pk, long groupPK) throws SystemException {
2021 try {
2022 removeGroup.remove(pk, groupPK);
2023 }
2024 catch (Exception e) {
2025 throw processException(e);
2026 }
2027 finally {
2028 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2029 }
2030 }
2031
2032
2039 public void removeGroup(long pk, com.liferay.portal.model.Group group)
2040 throws SystemException {
2041 try {
2042 removeGroup.remove(pk, group.getPrimaryKey());
2043 }
2044 catch (Exception e) {
2045 throw processException(e);
2046 }
2047 finally {
2048 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2049 }
2050 }
2051
2052
2059 public void removeGroups(long pk, long[] groupPKs)
2060 throws SystemException {
2061 try {
2062 for (long groupPK : groupPKs) {
2063 removeGroup.remove(pk, groupPK);
2064 }
2065 }
2066 catch (Exception e) {
2067 throw processException(e);
2068 }
2069 finally {
2070 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2071 }
2072 }
2073
2074
2081 public void removeGroups(long pk,
2082 List<com.liferay.portal.model.Group> groups) throws SystemException {
2083 try {
2084 for (com.liferay.portal.model.Group group : groups) {
2085 removeGroup.remove(pk, group.getPrimaryKey());
2086 }
2087 }
2088 catch (Exception e) {
2089 throw processException(e);
2090 }
2091 finally {
2092 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2093 }
2094 }
2095
2096
2103 public void setGroups(long pk, long[] groupPKs) throws SystemException {
2104 try {
2105 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
2106
2107 List<com.liferay.portal.model.Group> groups = getGroups(pk);
2108
2109 for (com.liferay.portal.model.Group group : groups) {
2110 if (!groupPKSet.remove(group.getPrimaryKey())) {
2111 removeGroup.remove(pk, group.getPrimaryKey());
2112 }
2113 }
2114
2115 for (Long groupPK : groupPKSet) {
2116 addGroup.add(pk, groupPK);
2117 }
2118 }
2119 catch (Exception e) {
2120 throw processException(e);
2121 }
2122 finally {
2123 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2124 }
2125 }
2126
2127
2134 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
2135 throws SystemException {
2136 try {
2137 long[] groupPKs = new long[groups.size()];
2138
2139 for (int i = 0; i < groups.size(); i++) {
2140 com.liferay.portal.model.Group group = groups.get(i);
2141
2142 groupPKs[i] = group.getPrimaryKey();
2143 }
2144
2145 setGroups(pk, groupPKs);
2146 }
2147 catch (Exception e) {
2148 throw processException(e);
2149 }
2150 finally {
2151 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2152 }
2153 }
2154
2155
2162 public List<com.liferay.portal.model.User> getUsers(long pk)
2163 throws SystemException {
2164 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2165 }
2166
2167
2180 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2181 int end) throws SystemException {
2182 return getUsers(pk, start, end, null);
2183 }
2184
2185 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2186 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
2187 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUsers",
2188 new String[] {
2189 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2190 "com.liferay.portal.kernel.util.OrderByComparator"
2191 });
2192
2193
2207 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2208 int end, OrderByComparator orderByComparator) throws SystemException {
2209 Object[] finderArgs = new Object[] {
2210 pk, String.valueOf(start), String.valueOf(end),
2211 String.valueOf(orderByComparator)
2212 };
2213
2214 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
2215 finderArgs, this);
2216
2217 if (list == null) {
2218 Session session = null;
2219
2220 try {
2221 session = openSession();
2222
2223 String sql = null;
2224
2225 if (orderByComparator != null) {
2226 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
2227 .concat(orderByComparator.getOrderBy());
2228 }
2229 else {
2230 sql = _SQL_GETUSERS;
2231 }
2232
2233 SQLQuery q = session.createSQLQuery(sql);
2234
2235 q.addEntity("User_",
2236 com.liferay.portal.model.impl.UserImpl.class);
2237
2238 QueryPos qPos = QueryPos.getInstance(q);
2239
2240 qPos.add(pk);
2241
2242 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2243 getDialect(), start, end);
2244 }
2245 catch (Exception e) {
2246 throw processException(e);
2247 }
2248 finally {
2249 if (list == null) {
2250 list = new ArrayList<com.liferay.portal.model.User>();
2251 }
2252
2253 userPersistence.cacheResult(list);
2254
2255 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
2256 list);
2257
2258 closeSession(session);
2259 }
2260 }
2261
2262 return list;
2263 }
2264
2265 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2266 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
2267 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
2268 "getUsersSize", new String[] { Long.class.getName() });
2269
2270
2277 public int getUsersSize(long pk) throws SystemException {
2278 Object[] finderArgs = new Object[] { pk };
2279
2280 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
2281 finderArgs, this);
2282
2283 if (count == null) {
2284 Session session = null;
2285
2286 try {
2287 session = openSession();
2288
2289 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2290
2291 q.addScalar(COUNT_COLUMN_NAME,
2292 com.liferay.portal.kernel.dao.orm.Type.LONG);
2293
2294 QueryPos qPos = QueryPos.getInstance(q);
2295
2296 qPos.add(pk);
2297
2298 count = (Long)q.uniqueResult();
2299 }
2300 catch (Exception e) {
2301 throw processException(e);
2302 }
2303 finally {
2304 if (count == null) {
2305 count = Long.valueOf(0);
2306 }
2307
2308 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
2309 finderArgs, count);
2310
2311 closeSession(session);
2312 }
2313 }
2314
2315 return count.intValue();
2316 }
2317
2318 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2319 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
2320 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
2321 "containsUser",
2322 new String[] { Long.class.getName(), Long.class.getName() });
2323
2324
2332 public boolean containsUser(long pk, long userPK) throws SystemException {
2333 Object[] finderArgs = new Object[] { pk, userPK };
2334
2335 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
2336 finderArgs, this);
2337
2338 if (value == null) {
2339 try {
2340 value = Boolean.valueOf(containsUser.contains(pk, userPK));
2341 }
2342 catch (Exception e) {
2343 throw processException(e);
2344 }
2345 finally {
2346 if (value == null) {
2347 value = Boolean.FALSE;
2348 }
2349
2350 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
2351 finderArgs, value);
2352 }
2353 }
2354
2355 return value.booleanValue();
2356 }
2357
2358
2365 public boolean containsUsers(long pk) throws SystemException {
2366 if (getUsersSize(pk) > 0) {
2367 return true;
2368 }
2369 else {
2370 return false;
2371 }
2372 }
2373
2374
2381 public void addUser(long pk, long userPK) throws SystemException {
2382 try {
2383 addUser.add(pk, userPK);
2384 }
2385 catch (Exception e) {
2386 throw processException(e);
2387 }
2388 finally {
2389 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2390 }
2391 }
2392
2393
2400 public void addUser(long pk, com.liferay.portal.model.User user)
2401 throws SystemException {
2402 try {
2403 addUser.add(pk, user.getPrimaryKey());
2404 }
2405 catch (Exception e) {
2406 throw processException(e);
2407 }
2408 finally {
2409 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2410 }
2411 }
2412
2413
2420 public void addUsers(long pk, long[] userPKs) throws SystemException {
2421 try {
2422 for (long userPK : userPKs) {
2423 addUser.add(pk, userPK);
2424 }
2425 }
2426 catch (Exception e) {
2427 throw processException(e);
2428 }
2429 finally {
2430 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2431 }
2432 }
2433
2434
2441 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2442 throws SystemException {
2443 try {
2444 for (com.liferay.portal.model.User user : users) {
2445 addUser.add(pk, user.getPrimaryKey());
2446 }
2447 }
2448 catch (Exception e) {
2449 throw processException(e);
2450 }
2451 finally {
2452 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2453 }
2454 }
2455
2456
2462 public void clearUsers(long pk) throws SystemException {
2463 try {
2464 clearUsers.clear(pk);
2465 }
2466 catch (Exception e) {
2467 throw processException(e);
2468 }
2469 finally {
2470 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2471 }
2472 }
2473
2474
2481 public void removeUser(long pk, long userPK) throws SystemException {
2482 try {
2483 removeUser.remove(pk, userPK);
2484 }
2485 catch (Exception e) {
2486 throw processException(e);
2487 }
2488 finally {
2489 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2490 }
2491 }
2492
2493
2500 public void removeUser(long pk, com.liferay.portal.model.User user)
2501 throws SystemException {
2502 try {
2503 removeUser.remove(pk, user.getPrimaryKey());
2504 }
2505 catch (Exception e) {
2506 throw processException(e);
2507 }
2508 finally {
2509 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2510 }
2511 }
2512
2513
2520 public void removeUsers(long pk, long[] userPKs) throws SystemException {
2521 try {
2522 for (long userPK : userPKs) {
2523 removeUser.remove(pk, userPK);
2524 }
2525 }
2526 catch (Exception e) {
2527 throw processException(e);
2528 }
2529 finally {
2530 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2531 }
2532 }
2533
2534
2541 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2542 throws SystemException {
2543 try {
2544 for (com.liferay.portal.model.User user : users) {
2545 removeUser.remove(pk, user.getPrimaryKey());
2546 }
2547 }
2548 catch (Exception e) {
2549 throw processException(e);
2550 }
2551 finally {
2552 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2553 }
2554 }
2555
2556
2563 public void setUsers(long pk, long[] userPKs) throws SystemException {
2564 try {
2565 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
2566
2567 List<com.liferay.portal.model.User> users = getUsers(pk);
2568
2569 for (com.liferay.portal.model.User user : users) {
2570 if (!userPKSet.remove(user.getPrimaryKey())) {
2571 removeUser.remove(pk, user.getPrimaryKey());
2572 }
2573 }
2574
2575 for (Long userPK : userPKSet) {
2576 addUser.add(pk, userPK);
2577 }
2578 }
2579 catch (Exception e) {
2580 throw processException(e);
2581 }
2582 finally {
2583 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2584 }
2585 }
2586
2587
2594 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2595 throws SystemException {
2596 try {
2597 long[] userPKs = new long[users.size()];
2598
2599 for (int i = 0; i < users.size(); i++) {
2600 com.liferay.portal.model.User user = users.get(i);
2601
2602 userPKs[i] = user.getPrimaryKey();
2603 }
2604
2605 setUsers(pk, userPKs);
2606 }
2607 catch (Exception e) {
2608 throw processException(e);
2609 }
2610 finally {
2611 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2612 }
2613 }
2614
2615
2618 public void afterPropertiesSet() {
2619 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2620 com.liferay.portal.util.PropsUtil.get(
2621 "value.object.listener.com.liferay.portal.model.UserGroup")));
2622
2623 if (listenerClassNames.length > 0) {
2624 try {
2625 List<ModelListener<UserGroup>> listenersList = new ArrayList<ModelListener<UserGroup>>();
2626
2627 for (String listenerClassName : listenerClassNames) {
2628 listenersList.add((ModelListener<UserGroup>)InstanceFactory.newInstance(
2629 listenerClassName));
2630 }
2631
2632 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2633 }
2634 catch (Exception e) {
2635 _log.error(e);
2636 }
2637 }
2638
2639 containsGroup = new ContainsGroup(this);
2640
2641 addGroup = new AddGroup(this);
2642 clearGroups = new ClearGroups(this);
2643 removeGroup = new RemoveGroup(this);
2644
2645 containsUser = new ContainsUser(this);
2646
2647 addUser = new AddUser(this);
2648 clearUsers = new ClearUsers(this);
2649 removeUser = new RemoveUser(this);
2650 }
2651
2652 public void destroy() {
2653 EntityCacheUtil.removeCache(UserGroupImpl.class.getName());
2654 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2655 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2656 }
2657
2658 @BeanReference(type = AccountPersistence.class)
2659 protected AccountPersistence accountPersistence;
2660 @BeanReference(type = AddressPersistence.class)
2661 protected AddressPersistence addressPersistence;
2662 @BeanReference(type = BrowserTrackerPersistence.class)
2663 protected BrowserTrackerPersistence browserTrackerPersistence;
2664 @BeanReference(type = ClassNamePersistence.class)
2665 protected ClassNamePersistence classNamePersistence;
2666 @BeanReference(type = ClusterGroupPersistence.class)
2667 protected ClusterGroupPersistence clusterGroupPersistence;
2668 @BeanReference(type = CompanyPersistence.class)
2669 protected CompanyPersistence companyPersistence;
2670 @BeanReference(type = ContactPersistence.class)
2671 protected ContactPersistence contactPersistence;
2672 @BeanReference(type = CountryPersistence.class)
2673 protected CountryPersistence countryPersistence;
2674 @BeanReference(type = EmailAddressPersistence.class)
2675 protected EmailAddressPersistence emailAddressPersistence;
2676 @BeanReference(type = GroupPersistence.class)
2677 protected GroupPersistence groupPersistence;
2678 @BeanReference(type = ImagePersistence.class)
2679 protected ImagePersistence imagePersistence;
2680 @BeanReference(type = LayoutPersistence.class)
2681 protected LayoutPersistence layoutPersistence;
2682 @BeanReference(type = LayoutPrototypePersistence.class)
2683 protected LayoutPrototypePersistence layoutPrototypePersistence;
2684 @BeanReference(type = LayoutSetPersistence.class)
2685 protected LayoutSetPersistence layoutSetPersistence;
2686 @BeanReference(type = LayoutSetPrototypePersistence.class)
2687 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2688 @BeanReference(type = ListTypePersistence.class)
2689 protected ListTypePersistence listTypePersistence;
2690 @BeanReference(type = LockPersistence.class)
2691 protected LockPersistence lockPersistence;
2692 @BeanReference(type = MembershipRequestPersistence.class)
2693 protected MembershipRequestPersistence membershipRequestPersistence;
2694 @BeanReference(type = OrganizationPersistence.class)
2695 protected OrganizationPersistence organizationPersistence;
2696 @BeanReference(type = OrgGroupPermissionPersistence.class)
2697 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2698 @BeanReference(type = OrgGroupRolePersistence.class)
2699 protected OrgGroupRolePersistence orgGroupRolePersistence;
2700 @BeanReference(type = OrgLaborPersistence.class)
2701 protected OrgLaborPersistence orgLaborPersistence;
2702 @BeanReference(type = PasswordPolicyPersistence.class)
2703 protected PasswordPolicyPersistence passwordPolicyPersistence;
2704 @BeanReference(type = PasswordPolicyRelPersistence.class)
2705 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2706 @BeanReference(type = PasswordTrackerPersistence.class)
2707 protected PasswordTrackerPersistence passwordTrackerPersistence;
2708 @BeanReference(type = PermissionPersistence.class)
2709 protected PermissionPersistence permissionPersistence;
2710 @BeanReference(type = PhonePersistence.class)
2711 protected PhonePersistence phonePersistence;
2712 @BeanReference(type = PluginSettingPersistence.class)
2713 protected PluginSettingPersistence pluginSettingPersistence;
2714 @BeanReference(type = PortletPersistence.class)
2715 protected PortletPersistence portletPersistence;
2716 @BeanReference(type = PortletItemPersistence.class)
2717 protected PortletItemPersistence portletItemPersistence;
2718 @BeanReference(type = PortletPreferencesPersistence.class)
2719 protected PortletPreferencesPersistence portletPreferencesPersistence;
2720 @BeanReference(type = RegionPersistence.class)
2721 protected RegionPersistence regionPersistence;
2722 @BeanReference(type = ReleasePersistence.class)
2723 protected ReleasePersistence releasePersistence;
2724 @BeanReference(type = ResourcePersistence.class)
2725 protected ResourcePersistence resourcePersistence;
2726 @BeanReference(type = ResourceActionPersistence.class)
2727 protected ResourceActionPersistence resourceActionPersistence;
2728 @BeanReference(type = ResourceCodePersistence.class)
2729 protected ResourceCodePersistence resourceCodePersistence;
2730 @BeanReference(type = ResourcePermissionPersistence.class)
2731 protected ResourcePermissionPersistence resourcePermissionPersistence;
2732 @BeanReference(type = RolePersistence.class)
2733 protected RolePersistence rolePersistence;
2734 @BeanReference(type = ServiceComponentPersistence.class)
2735 protected ServiceComponentPersistence serviceComponentPersistence;
2736 @BeanReference(type = ShardPersistence.class)
2737 protected ShardPersistence shardPersistence;
2738 @BeanReference(type = SubscriptionPersistence.class)
2739 protected SubscriptionPersistence subscriptionPersistence;
2740 @BeanReference(type = TicketPersistence.class)
2741 protected TicketPersistence ticketPersistence;
2742 @BeanReference(type = TeamPersistence.class)
2743 protected TeamPersistence teamPersistence;
2744 @BeanReference(type = UserPersistence.class)
2745 protected UserPersistence userPersistence;
2746 @BeanReference(type = UserGroupPersistence.class)
2747 protected UserGroupPersistence userGroupPersistence;
2748 @BeanReference(type = UserGroupGroupRolePersistence.class)
2749 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2750 @BeanReference(type = UserGroupRolePersistence.class)
2751 protected UserGroupRolePersistence userGroupRolePersistence;
2752 @BeanReference(type = UserIdMapperPersistence.class)
2753 protected UserIdMapperPersistence userIdMapperPersistence;
2754 @BeanReference(type = UserTrackerPersistence.class)
2755 protected UserTrackerPersistence userTrackerPersistence;
2756 @BeanReference(type = UserTrackerPathPersistence.class)
2757 protected UserTrackerPathPersistence userTrackerPathPersistence;
2758 @BeanReference(type = WebDAVPropsPersistence.class)
2759 protected WebDAVPropsPersistence webDAVPropsPersistence;
2760 @BeanReference(type = WebsitePersistence.class)
2761 protected WebsitePersistence websitePersistence;
2762 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2763 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2764 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2765 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2766 protected ContainsGroup containsGroup;
2767 protected AddGroup addGroup;
2768 protected ClearGroups clearGroups;
2769 protected RemoveGroup removeGroup;
2770 protected ContainsUser containsUser;
2771 protected AddUser addUser;
2772 protected ClearUsers clearUsers;
2773 protected RemoveUser removeUser;
2774
2775 protected class ContainsGroup {
2776 protected ContainsGroup(UserGroupPersistenceImpl persistenceImpl) {
2777 super();
2778
2779 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2780 _SQL_CONTAINSGROUP,
2781 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2782 RowMapper.COUNT);
2783 }
2784
2785 protected boolean contains(long userGroupId, long groupId) {
2786 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2787 new Long(userGroupId), new Long(groupId)
2788 });
2789
2790 if (results.size() > 0) {
2791 Integer count = results.get(0);
2792
2793 if (count.intValue() > 0) {
2794 return true;
2795 }
2796 }
2797
2798 return false;
2799 }
2800
2801 private MappingSqlQuery<Integer> _mappingSqlQuery;
2802 }
2803
2804 protected class AddGroup {
2805 protected AddGroup(UserGroupPersistenceImpl persistenceImpl) {
2806 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2807 "INSERT INTO Groups_UserGroups (userGroupId, groupId) VALUES (?, ?)",
2808 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2809 _persistenceImpl = persistenceImpl;
2810 }
2811
2812 protected void add(long userGroupId, long groupId)
2813 throws SystemException {
2814 if (!_persistenceImpl.containsGroup.contains(userGroupId, groupId)) {
2815 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2816
2817 for (ModelListener<UserGroup> listener : listeners) {
2818 listener.onBeforeAddAssociation(userGroupId,
2819 com.liferay.portal.model.Group.class.getName(), groupId);
2820 }
2821
2822 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2823 listener.onBeforeAddAssociation(groupId,
2824 UserGroup.class.getName(), userGroupId);
2825 }
2826
2827 _sqlUpdate.update(new Object[] {
2828 new Long(userGroupId), new Long(groupId)
2829 });
2830
2831 for (ModelListener<UserGroup> listener : listeners) {
2832 listener.onAfterAddAssociation(userGroupId,
2833 com.liferay.portal.model.Group.class.getName(), groupId);
2834 }
2835
2836 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2837 listener.onAfterAddAssociation(groupId,
2838 UserGroup.class.getName(), userGroupId);
2839 }
2840 }
2841 }
2842
2843 private SqlUpdate _sqlUpdate;
2844 private UserGroupPersistenceImpl _persistenceImpl;
2845 }
2846
2847 protected class ClearGroups {
2848 protected ClearGroups(UserGroupPersistenceImpl persistenceImpl) {
2849 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2850 "DELETE FROM Groups_UserGroups WHERE userGroupId = ?",
2851 new int[] { java.sql.Types.BIGINT });
2852 }
2853
2854 protected void clear(long userGroupId) throws SystemException {
2855 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2856
2857 List<com.liferay.portal.model.Group> groups = null;
2858
2859 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2860 groups = getGroups(userGroupId);
2861
2862 for (com.liferay.portal.model.Group group : groups) {
2863 for (ModelListener<UserGroup> listener : listeners) {
2864 listener.onBeforeRemoveAssociation(userGroupId,
2865 com.liferay.portal.model.Group.class.getName(),
2866 group.getPrimaryKey());
2867 }
2868
2869 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2870 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2871 UserGroup.class.getName(), userGroupId);
2872 }
2873 }
2874 }
2875
2876 _sqlUpdate.update(new Object[] { new Long(userGroupId) });
2877
2878 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2879 for (com.liferay.portal.model.Group group : groups) {
2880 for (ModelListener<UserGroup> listener : listeners) {
2881 listener.onAfterRemoveAssociation(userGroupId,
2882 com.liferay.portal.model.Group.class.getName(),
2883 group.getPrimaryKey());
2884 }
2885
2886 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2887 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
2888 UserGroup.class.getName(), userGroupId);
2889 }
2890 }
2891 }
2892 }
2893
2894 private SqlUpdate _sqlUpdate;
2895 }
2896
2897 protected class RemoveGroup {
2898 protected RemoveGroup(UserGroupPersistenceImpl persistenceImpl) {
2899 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2900 "DELETE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?",
2901 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2902 _persistenceImpl = persistenceImpl;
2903 }
2904
2905 protected void remove(long userGroupId, long groupId)
2906 throws SystemException {
2907 if (_persistenceImpl.containsGroup.contains(userGroupId, groupId)) {
2908 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2909
2910 for (ModelListener<UserGroup> listener : listeners) {
2911 listener.onBeforeRemoveAssociation(userGroupId,
2912 com.liferay.portal.model.Group.class.getName(), groupId);
2913 }
2914
2915 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2916 listener.onBeforeRemoveAssociation(groupId,
2917 UserGroup.class.getName(), userGroupId);
2918 }
2919
2920 _sqlUpdate.update(new Object[] {
2921 new Long(userGroupId), new Long(groupId)
2922 });
2923
2924 for (ModelListener<UserGroup> listener : listeners) {
2925 listener.onAfterRemoveAssociation(userGroupId,
2926 com.liferay.portal.model.Group.class.getName(), groupId);
2927 }
2928
2929 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2930 listener.onAfterRemoveAssociation(groupId,
2931 UserGroup.class.getName(), userGroupId);
2932 }
2933 }
2934 }
2935
2936 private SqlUpdate _sqlUpdate;
2937 private UserGroupPersistenceImpl _persistenceImpl;
2938 }
2939
2940 protected class ContainsUser {
2941 protected ContainsUser(UserGroupPersistenceImpl persistenceImpl) {
2942 super();
2943
2944 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2945 _SQL_CONTAINSUSER,
2946 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2947 RowMapper.COUNT);
2948 }
2949
2950 protected boolean contains(long userGroupId, long userId) {
2951 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2952 new Long(userGroupId), new Long(userId)
2953 });
2954
2955 if (results.size() > 0) {
2956 Integer count = results.get(0);
2957
2958 if (count.intValue() > 0) {
2959 return true;
2960 }
2961 }
2962
2963 return false;
2964 }
2965
2966 private MappingSqlQuery<Integer> _mappingSqlQuery;
2967 }
2968
2969 protected class AddUser {
2970 protected AddUser(UserGroupPersistenceImpl persistenceImpl) {
2971 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2972 "INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)",
2973 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2974 _persistenceImpl = persistenceImpl;
2975 }
2976
2977 protected void add(long userGroupId, long userId)
2978 throws SystemException {
2979 if (!_persistenceImpl.containsUser.contains(userGroupId, userId)) {
2980 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2981
2982 for (ModelListener<UserGroup> listener : listeners) {
2983 listener.onBeforeAddAssociation(userGroupId,
2984 com.liferay.portal.model.User.class.getName(), userId);
2985 }
2986
2987 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2988 listener.onBeforeAddAssociation(userId,
2989 UserGroup.class.getName(), userGroupId);
2990 }
2991
2992 _sqlUpdate.update(new Object[] {
2993 new Long(userGroupId), new Long(userId)
2994 });
2995
2996 for (ModelListener<UserGroup> listener : listeners) {
2997 listener.onAfterAddAssociation(userGroupId,
2998 com.liferay.portal.model.User.class.getName(), userId);
2999 }
3000
3001 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3002 listener.onAfterAddAssociation(userId,
3003 UserGroup.class.getName(), userGroupId);
3004 }
3005 }
3006 }
3007
3008 private SqlUpdate _sqlUpdate;
3009 private UserGroupPersistenceImpl _persistenceImpl;
3010 }
3011
3012 protected class ClearUsers {
3013 protected ClearUsers(UserGroupPersistenceImpl persistenceImpl) {
3014 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3015 "DELETE FROM Users_UserGroups WHERE userGroupId = ?",
3016 new int[] { java.sql.Types.BIGINT });
3017 }
3018
3019 protected void clear(long userGroupId) throws SystemException {
3020 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3021
3022 List<com.liferay.portal.model.User> users = null;
3023
3024 if ((listeners.length > 0) || (userListeners.length > 0)) {
3025 users = getUsers(userGroupId);
3026
3027 for (com.liferay.portal.model.User user : users) {
3028 for (ModelListener<UserGroup> listener : listeners) {
3029 listener.onBeforeRemoveAssociation(userGroupId,
3030 com.liferay.portal.model.User.class.getName(),
3031 user.getPrimaryKey());
3032 }
3033
3034 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3035 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
3036 UserGroup.class.getName(), userGroupId);
3037 }
3038 }
3039 }
3040
3041 _sqlUpdate.update(new Object[] { new Long(userGroupId) });
3042
3043 if ((listeners.length > 0) || (userListeners.length > 0)) {
3044 for (com.liferay.portal.model.User user : users) {
3045 for (ModelListener<UserGroup> listener : listeners) {
3046 listener.onAfterRemoveAssociation(userGroupId,
3047 com.liferay.portal.model.User.class.getName(),
3048 user.getPrimaryKey());
3049 }
3050
3051 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3052 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
3053 UserGroup.class.getName(), userGroupId);
3054 }
3055 }
3056 }
3057 }
3058
3059 private SqlUpdate _sqlUpdate;
3060 }
3061
3062 protected class RemoveUser {
3063 protected RemoveUser(UserGroupPersistenceImpl persistenceImpl) {
3064 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3065 "DELETE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
3066 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3067 _persistenceImpl = persistenceImpl;
3068 }
3069
3070 protected void remove(long userGroupId, long userId)
3071 throws SystemException {
3072 if (_persistenceImpl.containsUser.contains(userGroupId, userId)) {
3073 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3074
3075 for (ModelListener<UserGroup> listener : listeners) {
3076 listener.onBeforeRemoveAssociation(userGroupId,
3077 com.liferay.portal.model.User.class.getName(), userId);
3078 }
3079
3080 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3081 listener.onBeforeRemoveAssociation(userId,
3082 UserGroup.class.getName(), userGroupId);
3083 }
3084
3085 _sqlUpdate.update(new Object[] {
3086 new Long(userGroupId), new Long(userId)
3087 });
3088
3089 for (ModelListener<UserGroup> listener : listeners) {
3090 listener.onAfterRemoveAssociation(userGroupId,
3091 com.liferay.portal.model.User.class.getName(), userId);
3092 }
3093
3094 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3095 listener.onAfterRemoveAssociation(userId,
3096 UserGroup.class.getName(), userGroupId);
3097 }
3098 }
3099 }
3100
3101 private SqlUpdate _sqlUpdate;
3102 private UserGroupPersistenceImpl _persistenceImpl;
3103 }
3104
3105 private static final String _SQL_SELECT_USERGROUP = "SELECT userGroup FROM UserGroup userGroup";
3106 private static final String _SQL_SELECT_USERGROUP_WHERE = "SELECT userGroup FROM UserGroup userGroup WHERE ";
3107 private static final String _SQL_COUNT_USERGROUP = "SELECT COUNT(userGroup) FROM UserGroup userGroup";
3108 private static final String _SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(userGroup) FROM UserGroup userGroup WHERE ";
3109 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_UserGroups ON (Groups_UserGroups.groupId = Group_.groupId) WHERE (Groups_UserGroups.userGroupId = ?)";
3110 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ?";
3111 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?";
3112 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_UserGroups ON (Users_UserGroups.userId = User_.userId) WHERE (Users_UserGroups.userGroupId = ?)";
3113 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ?";
3114 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?";
3115 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userGroup.companyId = ?";
3116 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "userGroup.companyId = ? AND ";
3117 private static final String _FINDER_COLUMN_C_P_PARENTUSERGROUPID_2 = "userGroup.parentUserGroupId = ?";
3118 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "userGroup.companyId = ? AND ";
3119 private static final String _FINDER_COLUMN_C_N_NAME_1 = "userGroup.name IS NULL";
3120 private static final String _FINDER_COLUMN_C_N_NAME_2 = "userGroup.name = ?";
3121 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(userGroup.name IS NULL OR userGroup.name = ?)";
3122 private static final String _ORDER_BY_ENTITY_ALIAS = "userGroup.";
3123 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroup exists with the primary key ";
3124 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroup exists with the key {";
3125 private static Log _log = LogFactoryUtil.getLog(UserGroupPersistenceImpl.class);
3126 }