1
14
15 package com.liferay.portal.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.NoSuchUserGroupException;
19 import com.liferay.portal.SystemException;
20 import com.liferay.portal.kernel.annotation.BeanReference;
21 import com.liferay.portal.kernel.cache.CacheRegistry;
22 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
23 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
24 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
25 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
26 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
27 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
28 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29 import com.liferay.portal.kernel.dao.orm.FinderPath;
30 import com.liferay.portal.kernel.dao.orm.Query;
31 import com.liferay.portal.kernel.dao.orm.QueryPos;
32 import com.liferay.portal.kernel.dao.orm.QueryUtil;
33 import com.liferay.portal.kernel.dao.orm.SQLQuery;
34 import com.liferay.portal.kernel.dao.orm.Session;
35 import com.liferay.portal.kernel.log.Log;
36 import com.liferay.portal.kernel.log.LogFactoryUtil;
37 import com.liferay.portal.kernel.util.GetterUtil;
38 import com.liferay.portal.kernel.util.InstanceFactory;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.SetUtil;
41 import com.liferay.portal.kernel.util.StringBundler;
42 import com.liferay.portal.kernel.util.StringPool;
43 import com.liferay.portal.kernel.util.StringUtil;
44 import com.liferay.portal.kernel.util.Validator;
45 import com.liferay.portal.model.ModelListener;
46 import com.liferay.portal.model.UserGroup;
47 import com.liferay.portal.model.impl.UserGroupImpl;
48 import com.liferay.portal.model.impl.UserGroupModelImpl;
49 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
50
51 import java.io.Serializable;
52
53 import java.util.ArrayList;
54 import java.util.Collections;
55 import java.util.List;
56 import java.util.Set;
57
58
71 public class UserGroupPersistenceImpl extends BasePersistenceImpl<UserGroup>
72 implements UserGroupPersistence {
73 public static final String FINDER_CLASS_NAME_ENTITY = UserGroupImpl.class.getName();
74 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
75 ".List";
76 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
77 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
78 "findByCompanyId",
79 new String[] {
80 Long.class.getName(),
81
82 "java.lang.Integer", "java.lang.Integer",
83 "com.liferay.portal.kernel.util.OrderByComparator"
84 });
85 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
86 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
87 "countByCompanyId", new String[] { Long.class.getName() });
88 public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
89 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
90 "findByC_P",
91 new String[] {
92 Long.class.getName(), Long.class.getName(),
93
94 "java.lang.Integer", "java.lang.Integer",
95 "com.liferay.portal.kernel.util.OrderByComparator"
96 });
97 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
98 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
99 "countByC_P",
100 new String[] { Long.class.getName(), Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
102 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
103 "fetchByC_N",
104 new String[] { Long.class.getName(), String.class.getName() });
105 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
106 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "countByC_N",
108 new String[] { Long.class.getName(), String.class.getName() });
109 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
110 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111 "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
113 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "countAll", new String[0]);
115
116 public void cacheResult(UserGroup userGroup) {
117 EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
118 UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
119
120 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
121 new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() },
122 userGroup);
123 }
124
125 public void cacheResult(List<UserGroup> userGroups) {
126 for (UserGroup userGroup : userGroups) {
127 if (EntityCacheUtil.getResult(
128 UserGroupModelImpl.ENTITY_CACHE_ENABLED,
129 UserGroupImpl.class, userGroup.getPrimaryKey(), this) == null) {
130 cacheResult(userGroup);
131 }
132 }
133 }
134
135 public void clearCache() {
136 CacheRegistry.clear(UserGroupImpl.class.getName());
137 EntityCacheUtil.clearCache(UserGroupImpl.class.getName());
138 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
139 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
140 }
141
142 public void clearCache(UserGroup userGroup) {
143 EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
144 UserGroupImpl.class, userGroup.getPrimaryKey());
145
146 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
147 new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() });
148 }
149
150 public UserGroup create(long userGroupId) {
151 UserGroup userGroup = new UserGroupImpl();
152
153 userGroup.setNew(true);
154 userGroup.setPrimaryKey(userGroupId);
155
156 return userGroup;
157 }
158
159 public UserGroup remove(Serializable primaryKey)
160 throws NoSuchModelException, SystemException {
161 return remove(((Long)primaryKey).longValue());
162 }
163
164 public UserGroup remove(long userGroupId)
165 throws NoSuchUserGroupException, SystemException {
166 Session session = null;
167
168 try {
169 session = openSession();
170
171 UserGroup userGroup = (UserGroup)session.get(UserGroupImpl.class,
172 new Long(userGroupId));
173
174 if (userGroup == null) {
175 if (_log.isWarnEnabled()) {
176 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
177 }
178
179 throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
180 userGroupId);
181 }
182
183 return remove(userGroup);
184 }
185 catch (NoSuchUserGroupException nsee) {
186 throw nsee;
187 }
188 catch (Exception e) {
189 throw processException(e);
190 }
191 finally {
192 closeSession(session);
193 }
194 }
195
196 protected UserGroup removeImpl(UserGroup userGroup)
197 throws SystemException {
198 userGroup = toUnwrappedModel(userGroup);
199
200 try {
201 clearGroups.clear(userGroup.getPrimaryKey());
202 }
203 catch (Exception e) {
204 throw processException(e);
205 }
206 finally {
207 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
208 }
209
210 try {
211 clearUsers.clear(userGroup.getPrimaryKey());
212 }
213 catch (Exception e) {
214 throw processException(e);
215 }
216 finally {
217 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
218 }
219
220 Session session = null;
221
222 try {
223 session = openSession();
224
225 BatchSessionUtil.delete(session, userGroup);
226 }
227 catch (Exception e) {
228 throw processException(e);
229 }
230 finally {
231 closeSession(session);
232 }
233
234 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
235
236 UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
237
238 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
239 new Object[] {
240 new Long(userGroupModelImpl.getOriginalCompanyId()),
241
242 userGroupModelImpl.getOriginalName()
243 });
244
245 EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
246 UserGroupImpl.class, userGroup.getPrimaryKey());
247
248 return userGroup;
249 }
250
251
254 public UserGroup update(UserGroup userGroup) throws SystemException {
255 if (_log.isWarnEnabled()) {
256 _log.warn(
257 "Using the deprecated update(UserGroup userGroup) method. Use update(UserGroup userGroup, boolean merge) instead.");
258 }
259
260 return update(userGroup, false);
261 }
262
263 public UserGroup updateImpl(com.liferay.portal.model.UserGroup userGroup,
264 boolean merge) throws SystemException {
265 userGroup = toUnwrappedModel(userGroup);
266
267 boolean isNew = userGroup.isNew();
268
269 UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
270
271 Session session = null;
272
273 try {
274 session = openSession();
275
276 BatchSessionUtil.update(session, userGroup, merge);
277
278 userGroup.setNew(false);
279 }
280 catch (Exception e) {
281 throw processException(e);
282 }
283 finally {
284 closeSession(session);
285 }
286
287 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
288
289 EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
290 UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
291
292 if (!isNew &&
293 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
294 !Validator.equals(userGroup.getName(),
295 userGroupModelImpl.getOriginalName()))) {
296 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
297 new Object[] {
298 new Long(userGroupModelImpl.getOriginalCompanyId()),
299
300 userGroupModelImpl.getOriginalName()
301 });
302 }
303
304 if (isNew ||
305 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
306 !Validator.equals(userGroup.getName(),
307 userGroupModelImpl.getOriginalName()))) {
308 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
309 new Object[] {
310 new Long(userGroup.getCompanyId()),
311
312 userGroup.getName()
313 }, userGroup);
314 }
315
316 return userGroup;
317 }
318
319 protected UserGroup toUnwrappedModel(UserGroup userGroup) {
320 if (userGroup instanceof UserGroupImpl) {
321 return userGroup;
322 }
323
324 UserGroupImpl userGroupImpl = new UserGroupImpl();
325
326 userGroupImpl.setNew(userGroup.isNew());
327 userGroupImpl.setPrimaryKey(userGroup.getPrimaryKey());
328
329 userGroupImpl.setUserGroupId(userGroup.getUserGroupId());
330 userGroupImpl.setCompanyId(userGroup.getCompanyId());
331 userGroupImpl.setParentUserGroupId(userGroup.getParentUserGroupId());
332 userGroupImpl.setName(userGroup.getName());
333 userGroupImpl.setDescription(userGroup.getDescription());
334
335 return userGroupImpl;
336 }
337
338 public UserGroup findByPrimaryKey(Serializable primaryKey)
339 throws NoSuchModelException, SystemException {
340 return findByPrimaryKey(((Long)primaryKey).longValue());
341 }
342
343 public UserGroup findByPrimaryKey(long userGroupId)
344 throws NoSuchUserGroupException, SystemException {
345 UserGroup userGroup = fetchByPrimaryKey(userGroupId);
346
347 if (userGroup == null) {
348 if (_log.isWarnEnabled()) {
349 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
350 }
351
352 throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
353 userGroupId);
354 }
355
356 return userGroup;
357 }
358
359 public UserGroup fetchByPrimaryKey(Serializable primaryKey)
360 throws SystemException {
361 return fetchByPrimaryKey(((Long)primaryKey).longValue());
362 }
363
364 public UserGroup fetchByPrimaryKey(long userGroupId)
365 throws SystemException {
366 UserGroup userGroup = (UserGroup)EntityCacheUtil.getResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
367 UserGroupImpl.class, userGroupId, this);
368
369 if (userGroup == null) {
370 Session session = null;
371
372 try {
373 session = openSession();
374
375 userGroup = (UserGroup)session.get(UserGroupImpl.class,
376 new Long(userGroupId));
377 }
378 catch (Exception e) {
379 throw processException(e);
380 }
381 finally {
382 if (userGroup != null) {
383 cacheResult(userGroup);
384 }
385
386 closeSession(session);
387 }
388 }
389
390 return userGroup;
391 }
392
393 public List<UserGroup> findByCompanyId(long companyId)
394 throws SystemException {
395 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
396 null);
397 }
398
399 public List<UserGroup> findByCompanyId(long companyId, int start, int end)
400 throws SystemException {
401 return findByCompanyId(companyId, start, end, null);
402 }
403
404 public List<UserGroup> findByCompanyId(long companyId, int start, int end,
405 OrderByComparator orderByComparator) throws SystemException {
406 Object[] finderArgs = new Object[] {
407 companyId,
408
409 String.valueOf(start), String.valueOf(end),
410 String.valueOf(orderByComparator)
411 };
412
413 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
414 finderArgs, this);
415
416 if (list == null) {
417 StringBundler query = null;
418
419 if (orderByComparator != null) {
420 query = new StringBundler(3 +
421 (orderByComparator.getOrderByFields().length * 3));
422 }
423 else {
424 query = new StringBundler(3);
425 }
426
427 query.append(_SQL_SELECT_USERGROUP_WHERE);
428
429 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
430
431 if (orderByComparator != null) {
432 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
433 orderByComparator);
434 }
435
436 else {
437 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
438 }
439
440 String sql = query.toString();
441
442 Session session = null;
443
444 try {
445 session = openSession();
446
447 Query q = session.createQuery(sql);
448
449 QueryPos qPos = QueryPos.getInstance(q);
450
451 qPos.add(companyId);
452
453 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
454 end);
455 }
456 catch (Exception e) {
457 throw processException(e);
458 }
459 finally {
460 if (list == null) {
461 list = new ArrayList<UserGroup>();
462 }
463
464 cacheResult(list);
465
466 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
467 finderArgs, list);
468
469 closeSession(session);
470 }
471 }
472
473 return list;
474 }
475
476 public UserGroup findByCompanyId_First(long companyId,
477 OrderByComparator orderByComparator)
478 throws NoSuchUserGroupException, SystemException {
479 List<UserGroup> list = findByCompanyId(companyId, 0, 1,
480 orderByComparator);
481
482 if (list.isEmpty()) {
483 StringBundler msg = new StringBundler(4);
484
485 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
486
487 msg.append("companyId=");
488 msg.append(companyId);
489
490 msg.append(StringPool.CLOSE_CURLY_BRACE);
491
492 throw new NoSuchUserGroupException(msg.toString());
493 }
494 else {
495 return list.get(0);
496 }
497 }
498
499 public UserGroup findByCompanyId_Last(long companyId,
500 OrderByComparator orderByComparator)
501 throws NoSuchUserGroupException, SystemException {
502 int count = countByCompanyId(companyId);
503
504 List<UserGroup> list = findByCompanyId(companyId, count - 1, count,
505 orderByComparator);
506
507 if (list.isEmpty()) {
508 StringBundler msg = new StringBundler(4);
509
510 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
511
512 msg.append("companyId=");
513 msg.append(companyId);
514
515 msg.append(StringPool.CLOSE_CURLY_BRACE);
516
517 throw new NoSuchUserGroupException(msg.toString());
518 }
519 else {
520 return list.get(0);
521 }
522 }
523
524 public UserGroup[] findByCompanyId_PrevAndNext(long userGroupId,
525 long companyId, OrderByComparator orderByComparator)
526 throws NoSuchUserGroupException, SystemException {
527 UserGroup userGroup = findByPrimaryKey(userGroupId);
528
529 Session session = null;
530
531 try {
532 session = openSession();
533
534 UserGroup[] array = new UserGroupImpl[3];
535
536 array[0] = getByCompanyId_PrevAndNext(session, userGroup,
537 companyId, orderByComparator, true);
538
539 array[1] = userGroup;
540
541 array[2] = getByCompanyId_PrevAndNext(session, userGroup,
542 companyId, orderByComparator, false);
543
544 return array;
545 }
546 catch (Exception e) {
547 throw processException(e);
548 }
549 finally {
550 closeSession(session);
551 }
552 }
553
554 protected UserGroup getByCompanyId_PrevAndNext(Session session,
555 UserGroup userGroup, long companyId,
556 OrderByComparator orderByComparator, boolean previous) {
557 StringBundler query = null;
558
559 if (orderByComparator != null) {
560 query = new StringBundler(6 +
561 (orderByComparator.getOrderByFields().length * 6));
562 }
563 else {
564 query = new StringBundler(3);
565 }
566
567 query.append(_SQL_SELECT_USERGROUP_WHERE);
568
569 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
570
571 if (orderByComparator != null) {
572 String[] orderByFields = orderByComparator.getOrderByFields();
573
574 if (orderByFields.length > 0) {
575 query.append(WHERE_AND);
576 }
577
578 for (int i = 0; i < orderByFields.length; i++) {
579 query.append(_ORDER_BY_ENTITY_ALIAS);
580 query.append(orderByFields[i]);
581
582 if ((i + 1) < orderByFields.length) {
583 if (orderByComparator.isAscending() ^ previous) {
584 query.append(WHERE_GREATER_THAN_HAS_NEXT);
585 }
586 else {
587 query.append(WHERE_LESSER_THAN_HAS_NEXT);
588 }
589 }
590 else {
591 if (orderByComparator.isAscending() ^ previous) {
592 query.append(WHERE_GREATER_THAN);
593 }
594 else {
595 query.append(WHERE_LESSER_THAN);
596 }
597 }
598 }
599
600 query.append(ORDER_BY_CLAUSE);
601
602 for (int i = 0; i < orderByFields.length; i++) {
603 query.append(_ORDER_BY_ENTITY_ALIAS);
604 query.append(orderByFields[i]);
605
606 if ((i + 1) < orderByFields.length) {
607 if (orderByComparator.isAscending() ^ previous) {
608 query.append(ORDER_BY_ASC_HAS_NEXT);
609 }
610 else {
611 query.append(ORDER_BY_DESC_HAS_NEXT);
612 }
613 }
614 else {
615 if (orderByComparator.isAscending() ^ previous) {
616 query.append(ORDER_BY_ASC);
617 }
618 else {
619 query.append(ORDER_BY_DESC);
620 }
621 }
622 }
623 }
624
625 else {
626 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
627 }
628
629 String sql = query.toString();
630
631 Query q = session.createQuery(sql);
632
633 q.setFirstResult(0);
634 q.setMaxResults(2);
635
636 QueryPos qPos = QueryPos.getInstance(q);
637
638 qPos.add(companyId);
639
640 if (orderByComparator != null) {
641 Object[] values = orderByComparator.getOrderByValues(userGroup);
642
643 for (Object value : values) {
644 qPos.add(value);
645 }
646 }
647
648 List<UserGroup> list = q.list();
649
650 if (list.size() == 2) {
651 return list.get(1);
652 }
653 else {
654 return null;
655 }
656 }
657
658 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId)
659 throws SystemException {
660 return findByC_P(companyId, parentUserGroupId, QueryUtil.ALL_POS,
661 QueryUtil.ALL_POS, null);
662 }
663
664 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
665 int start, int end) throws SystemException {
666 return findByC_P(companyId, parentUserGroupId, start, end, null);
667 }
668
669 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
670 int start, int end, OrderByComparator orderByComparator)
671 throws SystemException {
672 Object[] finderArgs = new Object[] {
673 companyId, parentUserGroupId,
674
675 String.valueOf(start), String.valueOf(end),
676 String.valueOf(orderByComparator)
677 };
678
679 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
680 finderArgs, this);
681
682 if (list == null) {
683 StringBundler query = null;
684
685 if (orderByComparator != null) {
686 query = new StringBundler(4 +
687 (orderByComparator.getOrderByFields().length * 3));
688 }
689 else {
690 query = new StringBundler(4);
691 }
692
693 query.append(_SQL_SELECT_USERGROUP_WHERE);
694
695 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
696
697 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
698
699 if (orderByComparator != null) {
700 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
701 orderByComparator);
702 }
703
704 else {
705 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
706 }
707
708 String sql = query.toString();
709
710 Session session = null;
711
712 try {
713 session = openSession();
714
715 Query q = session.createQuery(sql);
716
717 QueryPos qPos = QueryPos.getInstance(q);
718
719 qPos.add(companyId);
720
721 qPos.add(parentUserGroupId);
722
723 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
724 end);
725 }
726 catch (Exception e) {
727 throw processException(e);
728 }
729 finally {
730 if (list == null) {
731 list = new ArrayList<UserGroup>();
732 }
733
734 cacheResult(list);
735
736 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
737 list);
738
739 closeSession(session);
740 }
741 }
742
743 return list;
744 }
745
746 public UserGroup findByC_P_First(long companyId, long parentUserGroupId,
747 OrderByComparator orderByComparator)
748 throws NoSuchUserGroupException, SystemException {
749 List<UserGroup> list = findByC_P(companyId, parentUserGroupId, 0, 1,
750 orderByComparator);
751
752 if (list.isEmpty()) {
753 StringBundler msg = new StringBundler(6);
754
755 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
756
757 msg.append("companyId=");
758 msg.append(companyId);
759
760 msg.append(", parentUserGroupId=");
761 msg.append(parentUserGroupId);
762
763 msg.append(StringPool.CLOSE_CURLY_BRACE);
764
765 throw new NoSuchUserGroupException(msg.toString());
766 }
767 else {
768 return list.get(0);
769 }
770 }
771
772 public UserGroup findByC_P_Last(long companyId, long parentUserGroupId,
773 OrderByComparator orderByComparator)
774 throws NoSuchUserGroupException, SystemException {
775 int count = countByC_P(companyId, parentUserGroupId);
776
777 List<UserGroup> list = findByC_P(companyId, parentUserGroupId,
778 count - 1, count, orderByComparator);
779
780 if (list.isEmpty()) {
781 StringBundler msg = new StringBundler(6);
782
783 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
784
785 msg.append("companyId=");
786 msg.append(companyId);
787
788 msg.append(", parentUserGroupId=");
789 msg.append(parentUserGroupId);
790
791 msg.append(StringPool.CLOSE_CURLY_BRACE);
792
793 throw new NoSuchUserGroupException(msg.toString());
794 }
795 else {
796 return list.get(0);
797 }
798 }
799
800 public UserGroup[] findByC_P_PrevAndNext(long userGroupId, long companyId,
801 long parentUserGroupId, OrderByComparator orderByComparator)
802 throws NoSuchUserGroupException, SystemException {
803 UserGroup userGroup = findByPrimaryKey(userGroupId);
804
805 Session session = null;
806
807 try {
808 session = openSession();
809
810 UserGroup[] array = new UserGroupImpl[3];
811
812 array[0] = getByC_P_PrevAndNext(session, userGroup, companyId,
813 parentUserGroupId, orderByComparator, true);
814
815 array[1] = userGroup;
816
817 array[2] = getByC_P_PrevAndNext(session, userGroup, companyId,
818 parentUserGroupId, orderByComparator, false);
819
820 return array;
821 }
822 catch (Exception e) {
823 throw processException(e);
824 }
825 finally {
826 closeSession(session);
827 }
828 }
829
830 protected UserGroup getByC_P_PrevAndNext(Session session,
831 UserGroup userGroup, long companyId, long parentUserGroupId,
832 OrderByComparator orderByComparator, boolean previous) {
833 StringBundler query = null;
834
835 if (orderByComparator != null) {
836 query = new StringBundler(6 +
837 (orderByComparator.getOrderByFields().length * 6));
838 }
839 else {
840 query = new StringBundler(3);
841 }
842
843 query.append(_SQL_SELECT_USERGROUP_WHERE);
844
845 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
846
847 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
848
849 if (orderByComparator != null) {
850 String[] orderByFields = orderByComparator.getOrderByFields();
851
852 if (orderByFields.length > 0) {
853 query.append(WHERE_AND);
854 }
855
856 for (int i = 0; i < orderByFields.length; i++) {
857 query.append(_ORDER_BY_ENTITY_ALIAS);
858 query.append(orderByFields[i]);
859
860 if ((i + 1) < orderByFields.length) {
861 if (orderByComparator.isAscending() ^ previous) {
862 query.append(WHERE_GREATER_THAN_HAS_NEXT);
863 }
864 else {
865 query.append(WHERE_LESSER_THAN_HAS_NEXT);
866 }
867 }
868 else {
869 if (orderByComparator.isAscending() ^ previous) {
870 query.append(WHERE_GREATER_THAN);
871 }
872 else {
873 query.append(WHERE_LESSER_THAN);
874 }
875 }
876 }
877
878 query.append(ORDER_BY_CLAUSE);
879
880 for (int i = 0; i < orderByFields.length; i++) {
881 query.append(_ORDER_BY_ENTITY_ALIAS);
882 query.append(orderByFields[i]);
883
884 if ((i + 1) < orderByFields.length) {
885 if (orderByComparator.isAscending() ^ previous) {
886 query.append(ORDER_BY_ASC_HAS_NEXT);
887 }
888 else {
889 query.append(ORDER_BY_DESC_HAS_NEXT);
890 }
891 }
892 else {
893 if (orderByComparator.isAscending() ^ previous) {
894 query.append(ORDER_BY_ASC);
895 }
896 else {
897 query.append(ORDER_BY_DESC);
898 }
899 }
900 }
901 }
902
903 else {
904 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
905 }
906
907 String sql = query.toString();
908
909 Query q = session.createQuery(sql);
910
911 q.setFirstResult(0);
912 q.setMaxResults(2);
913
914 QueryPos qPos = QueryPos.getInstance(q);
915
916 qPos.add(companyId);
917
918 qPos.add(parentUserGroupId);
919
920 if (orderByComparator != null) {
921 Object[] values = orderByComparator.getOrderByValues(userGroup);
922
923 for (Object value : values) {
924 qPos.add(value);
925 }
926 }
927
928 List<UserGroup> list = q.list();
929
930 if (list.size() == 2) {
931 return list.get(1);
932 }
933 else {
934 return null;
935 }
936 }
937
938 public UserGroup findByC_N(long companyId, String name)
939 throws NoSuchUserGroupException, SystemException {
940 UserGroup userGroup = fetchByC_N(companyId, name);
941
942 if (userGroup == null) {
943 StringBundler msg = new StringBundler(6);
944
945 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
946
947 msg.append("companyId=");
948 msg.append(companyId);
949
950 msg.append(", name=");
951 msg.append(name);
952
953 msg.append(StringPool.CLOSE_CURLY_BRACE);
954
955 if (_log.isWarnEnabled()) {
956 _log.warn(msg.toString());
957 }
958
959 throw new NoSuchUserGroupException(msg.toString());
960 }
961
962 return userGroup;
963 }
964
965 public UserGroup fetchByC_N(long companyId, String name)
966 throws SystemException {
967 return fetchByC_N(companyId, name, true);
968 }
969
970 public UserGroup fetchByC_N(long companyId, String name,
971 boolean retrieveFromCache) throws SystemException {
972 Object[] finderArgs = new Object[] { companyId, name };
973
974 Object result = null;
975
976 if (retrieveFromCache) {
977 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
978 finderArgs, this);
979 }
980
981 if (result == null) {
982 StringBundler query = new StringBundler(4);
983
984 query.append(_SQL_SELECT_USERGROUP_WHERE);
985
986 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
987
988 if (name == null) {
989 query.append(_FINDER_COLUMN_C_N_NAME_1);
990 }
991 else {
992 if (name.equals(StringPool.BLANK)) {
993 query.append(_FINDER_COLUMN_C_N_NAME_3);
994 }
995 else {
996 query.append(_FINDER_COLUMN_C_N_NAME_2);
997 }
998 }
999
1000 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1001
1002 String sql = query.toString();
1003
1004 Session session = null;
1005
1006 try {
1007 session = openSession();
1008
1009 Query q = session.createQuery(sql);
1010
1011 QueryPos qPos = QueryPos.getInstance(q);
1012
1013 qPos.add(companyId);
1014
1015 if (name != null) {
1016 qPos.add(name);
1017 }
1018
1019 List<UserGroup> list = q.list();
1020
1021 result = list;
1022
1023 UserGroup userGroup = null;
1024
1025 if (list.isEmpty()) {
1026 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1027 finderArgs, list);
1028 }
1029 else {
1030 userGroup = list.get(0);
1031
1032 cacheResult(userGroup);
1033
1034 if ((userGroup.getCompanyId() != companyId) ||
1035 (userGroup.getName() == null) ||
1036 !userGroup.getName().equals(name)) {
1037 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1038 finderArgs, userGroup);
1039 }
1040 }
1041
1042 return userGroup;
1043 }
1044 catch (Exception e) {
1045 throw processException(e);
1046 }
1047 finally {
1048 if (result == null) {
1049 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1050 finderArgs, new ArrayList<UserGroup>());
1051 }
1052
1053 closeSession(session);
1054 }
1055 }
1056 else {
1057 if (result instanceof List<?>) {
1058 return null;
1059 }
1060 else {
1061 return (UserGroup)result;
1062 }
1063 }
1064 }
1065
1066 public List<UserGroup> findAll() throws SystemException {
1067 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1068 }
1069
1070 public List<UserGroup> findAll(int start, int end)
1071 throws SystemException {
1072 return findAll(start, end, null);
1073 }
1074
1075 public List<UserGroup> findAll(int start, int end,
1076 OrderByComparator orderByComparator) throws SystemException {
1077 Object[] finderArgs = new Object[] {
1078 String.valueOf(start), String.valueOf(end),
1079 String.valueOf(orderByComparator)
1080 };
1081
1082 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1083 finderArgs, this);
1084
1085 if (list == null) {
1086 StringBundler query = null;
1087 String sql = null;
1088
1089 if (orderByComparator != null) {
1090 query = new StringBundler(2 +
1091 (orderByComparator.getOrderByFields().length * 3));
1092
1093 query.append(_SQL_SELECT_USERGROUP);
1094
1095 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1096 orderByComparator);
1097
1098 sql = query.toString();
1099 }
1100 else {
1101 sql = _SQL_SELECT_USERGROUP.concat(UserGroupModelImpl.ORDER_BY_JPQL);
1102 }
1103
1104 Session session = null;
1105
1106 try {
1107 session = openSession();
1108
1109 Query q = session.createQuery(sql);
1110
1111 if (orderByComparator == null) {
1112 list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1113 start, end, false);
1114
1115 Collections.sort(list);
1116 }
1117 else {
1118 list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1119 start, end);
1120 }
1121 }
1122 catch (Exception e) {
1123 throw processException(e);
1124 }
1125 finally {
1126 if (list == null) {
1127 list = new ArrayList<UserGroup>();
1128 }
1129
1130 cacheResult(list);
1131
1132 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1133
1134 closeSession(session);
1135 }
1136 }
1137
1138 return list;
1139 }
1140
1141 public void removeByCompanyId(long companyId) throws SystemException {
1142 for (UserGroup userGroup : findByCompanyId(companyId)) {
1143 remove(userGroup);
1144 }
1145 }
1146
1147 public void removeByC_P(long companyId, long parentUserGroupId)
1148 throws SystemException {
1149 for (UserGroup userGroup : findByC_P(companyId, parentUserGroupId)) {
1150 remove(userGroup);
1151 }
1152 }
1153
1154 public void removeByC_N(long companyId, String name)
1155 throws NoSuchUserGroupException, SystemException {
1156 UserGroup userGroup = findByC_N(companyId, name);
1157
1158 remove(userGroup);
1159 }
1160
1161 public void removeAll() throws SystemException {
1162 for (UserGroup userGroup : findAll()) {
1163 remove(userGroup);
1164 }
1165 }
1166
1167 public int countByCompanyId(long companyId) throws SystemException {
1168 Object[] finderArgs = new Object[] { companyId };
1169
1170 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1171 finderArgs, this);
1172
1173 if (count == null) {
1174 StringBundler query = new StringBundler(2);
1175
1176 query.append(_SQL_COUNT_USERGROUP_WHERE);
1177
1178 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1179
1180 String sql = query.toString();
1181
1182 Session session = null;
1183
1184 try {
1185 session = openSession();
1186
1187 Query q = session.createQuery(sql);
1188
1189 QueryPos qPos = QueryPos.getInstance(q);
1190
1191 qPos.add(companyId);
1192
1193 count = (Long)q.uniqueResult();
1194 }
1195 catch (Exception e) {
1196 throw processException(e);
1197 }
1198 finally {
1199 if (count == null) {
1200 count = Long.valueOf(0);
1201 }
1202
1203 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1204 finderArgs, count);
1205
1206 closeSession(session);
1207 }
1208 }
1209
1210 return count.intValue();
1211 }
1212
1213 public int countByC_P(long companyId, long parentUserGroupId)
1214 throws SystemException {
1215 Object[] finderArgs = new Object[] { companyId, parentUserGroupId };
1216
1217 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1218 finderArgs, this);
1219
1220 if (count == null) {
1221 StringBundler query = new StringBundler(3);
1222
1223 query.append(_SQL_COUNT_USERGROUP_WHERE);
1224
1225 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1226
1227 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1228
1229 String sql = query.toString();
1230
1231 Session session = null;
1232
1233 try {
1234 session = openSession();
1235
1236 Query q = session.createQuery(sql);
1237
1238 QueryPos qPos = QueryPos.getInstance(q);
1239
1240 qPos.add(companyId);
1241
1242 qPos.add(parentUserGroupId);
1243
1244 count = (Long)q.uniqueResult();
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 if (count == null) {
1251 count = Long.valueOf(0);
1252 }
1253
1254 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1255 count);
1256
1257 closeSession(session);
1258 }
1259 }
1260
1261 return count.intValue();
1262 }
1263
1264 public int countByC_N(long companyId, String name)
1265 throws SystemException {
1266 Object[] finderArgs = new Object[] { companyId, name };
1267
1268 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1269 finderArgs, this);
1270
1271 if (count == null) {
1272 StringBundler query = new StringBundler(3);
1273
1274 query.append(_SQL_COUNT_USERGROUP_WHERE);
1275
1276 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1277
1278 if (name == null) {
1279 query.append(_FINDER_COLUMN_C_N_NAME_1);
1280 }
1281 else {
1282 if (name.equals(StringPool.BLANK)) {
1283 query.append(_FINDER_COLUMN_C_N_NAME_3);
1284 }
1285 else {
1286 query.append(_FINDER_COLUMN_C_N_NAME_2);
1287 }
1288 }
1289
1290 String sql = query.toString();
1291
1292 Session session = null;
1293
1294 try {
1295 session = openSession();
1296
1297 Query q = session.createQuery(sql);
1298
1299 QueryPos qPos = QueryPos.getInstance(q);
1300
1301 qPos.add(companyId);
1302
1303 if (name != null) {
1304 qPos.add(name);
1305 }
1306
1307 count = (Long)q.uniqueResult();
1308 }
1309 catch (Exception e) {
1310 throw processException(e);
1311 }
1312 finally {
1313 if (count == null) {
1314 count = Long.valueOf(0);
1315 }
1316
1317 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1318 count);
1319
1320 closeSession(session);
1321 }
1322 }
1323
1324 return count.intValue();
1325 }
1326
1327 public int countAll() throws SystemException {
1328 Object[] finderArgs = new Object[0];
1329
1330 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1331 finderArgs, this);
1332
1333 if (count == null) {
1334 Session session = null;
1335
1336 try {
1337 session = openSession();
1338
1339 Query q = session.createQuery(_SQL_COUNT_USERGROUP);
1340
1341 count = (Long)q.uniqueResult();
1342 }
1343 catch (Exception e) {
1344 throw processException(e);
1345 }
1346 finally {
1347 if (count == null) {
1348 count = Long.valueOf(0);
1349 }
1350
1351 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1352 count);
1353
1354 closeSession(session);
1355 }
1356 }
1357
1358 return count.intValue();
1359 }
1360
1361 public List<com.liferay.portal.model.Group> getGroups(long pk)
1362 throws SystemException {
1363 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1364 }
1365
1366 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1367 int end) throws SystemException {
1368 return getGroups(pk, start, end, null);
1369 }
1370
1371 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1372 UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1373 UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1374 "getGroups",
1375 new String[] {
1376 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1377 "com.liferay.portal.kernel.util.OrderByComparator"
1378 });
1379
1380 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1381 int end, OrderByComparator orderByComparator) throws SystemException {
1382 Object[] finderArgs = new Object[] {
1383 pk, String.valueOf(start), String.valueOf(end),
1384 String.valueOf(orderByComparator)
1385 };
1386
1387 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1388 finderArgs, this);
1389
1390 if (list == null) {
1391 Session session = null;
1392
1393 try {
1394 session = openSession();
1395
1396 String sql = null;
1397
1398 if (orderByComparator != null) {
1399 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1400 .concat(orderByComparator.getOrderBy());
1401 }
1402 else {
1403 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1404 }
1405
1406 SQLQuery q = session.createSQLQuery(sql);
1407
1408 q.addEntity("Group_",
1409 com.liferay.portal.model.impl.GroupImpl.class);
1410
1411 QueryPos qPos = QueryPos.getInstance(q);
1412
1413 qPos.add(pk);
1414
1415 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1416 getDialect(), start, end);
1417 }
1418 catch (Exception e) {
1419 throw processException(e);
1420 }
1421 finally {
1422 if (list == null) {
1423 list = new ArrayList<com.liferay.portal.model.Group>();
1424 }
1425
1426 groupPersistence.cacheResult(list);
1427
1428 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1429 list);
1430
1431 closeSession(session);
1432 }
1433 }
1434
1435 return list;
1436 }
1437
1438 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1439 UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1440 UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1441 "getGroupsSize", new String[] { Long.class.getName() });
1442
1443 public int getGroupsSize(long pk) throws SystemException {
1444 Object[] finderArgs = new Object[] { pk };
1445
1446 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1447 finderArgs, this);
1448
1449 if (count == null) {
1450 Session session = null;
1451
1452 try {
1453 session = openSession();
1454
1455 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1456
1457 q.addScalar(COUNT_COLUMN_NAME,
1458 com.liferay.portal.kernel.dao.orm.Type.LONG);
1459
1460 QueryPos qPos = QueryPos.getInstance(q);
1461
1462 qPos.add(pk);
1463
1464 count = (Long)q.uniqueResult();
1465 }
1466 catch (Exception e) {
1467 throw processException(e);
1468 }
1469 finally {
1470 if (count == null) {
1471 count = Long.valueOf(0);
1472 }
1473
1474 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1475 finderArgs, count);
1476
1477 closeSession(session);
1478 }
1479 }
1480
1481 return count.intValue();
1482 }
1483
1484 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1485 UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1486 UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1487 "containsGroup",
1488 new String[] { Long.class.getName(), Long.class.getName() });
1489
1490 public boolean containsGroup(long pk, long groupPK)
1491 throws SystemException {
1492 Object[] finderArgs = new Object[] { pk, groupPK };
1493
1494 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1495 finderArgs, this);
1496
1497 if (value == null) {
1498 try {
1499 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1500 }
1501 catch (Exception e) {
1502 throw processException(e);
1503 }
1504 finally {
1505 if (value == null) {
1506 value = Boolean.FALSE;
1507 }
1508
1509 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1510 finderArgs, value);
1511 }
1512 }
1513
1514 return value.booleanValue();
1515 }
1516
1517 public boolean containsGroups(long pk) throws SystemException {
1518 if (getGroupsSize(pk) > 0) {
1519 return true;
1520 }
1521 else {
1522 return false;
1523 }
1524 }
1525
1526 public void addGroup(long pk, long groupPK) throws SystemException {
1527 try {
1528 addGroup.add(pk, groupPK);
1529 }
1530 catch (Exception e) {
1531 throw processException(e);
1532 }
1533 finally {
1534 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1535 }
1536 }
1537
1538 public void addGroup(long pk, com.liferay.portal.model.Group group)
1539 throws SystemException {
1540 try {
1541 addGroup.add(pk, group.getPrimaryKey());
1542 }
1543 catch (Exception e) {
1544 throw processException(e);
1545 }
1546 finally {
1547 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1548 }
1549 }
1550
1551 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1552 try {
1553 for (long groupPK : groupPKs) {
1554 addGroup.add(pk, groupPK);
1555 }
1556 }
1557 catch (Exception e) {
1558 throw processException(e);
1559 }
1560 finally {
1561 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1562 }
1563 }
1564
1565 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1566 throws SystemException {
1567 try {
1568 for (com.liferay.portal.model.Group group : groups) {
1569 addGroup.add(pk, group.getPrimaryKey());
1570 }
1571 }
1572 catch (Exception e) {
1573 throw processException(e);
1574 }
1575 finally {
1576 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1577 }
1578 }
1579
1580 public void clearGroups(long pk) throws SystemException {
1581 try {
1582 clearGroups.clear(pk);
1583 }
1584 catch (Exception e) {
1585 throw processException(e);
1586 }
1587 finally {
1588 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1589 }
1590 }
1591
1592 public void removeGroup(long pk, long groupPK) throws SystemException {
1593 try {
1594 removeGroup.remove(pk, groupPK);
1595 }
1596 catch (Exception e) {
1597 throw processException(e);
1598 }
1599 finally {
1600 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1601 }
1602 }
1603
1604 public void removeGroup(long pk, com.liferay.portal.model.Group group)
1605 throws SystemException {
1606 try {
1607 removeGroup.remove(pk, group.getPrimaryKey());
1608 }
1609 catch (Exception e) {
1610 throw processException(e);
1611 }
1612 finally {
1613 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1614 }
1615 }
1616
1617 public void removeGroups(long pk, long[] groupPKs)
1618 throws SystemException {
1619 try {
1620 for (long groupPK : groupPKs) {
1621 removeGroup.remove(pk, groupPK);
1622 }
1623 }
1624 catch (Exception e) {
1625 throw processException(e);
1626 }
1627 finally {
1628 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1629 }
1630 }
1631
1632 public void removeGroups(long pk,
1633 List<com.liferay.portal.model.Group> groups) throws SystemException {
1634 try {
1635 for (com.liferay.portal.model.Group group : groups) {
1636 removeGroup.remove(pk, group.getPrimaryKey());
1637 }
1638 }
1639 catch (Exception e) {
1640 throw processException(e);
1641 }
1642 finally {
1643 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1644 }
1645 }
1646
1647 public void setGroups(long pk, long[] groupPKs) throws SystemException {
1648 try {
1649 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
1650
1651 List<com.liferay.portal.model.Group> groups = getGroups(pk);
1652
1653 for (com.liferay.portal.model.Group group : groups) {
1654 if (!groupPKSet.remove(group.getPrimaryKey())) {
1655 removeGroup.remove(pk, group.getPrimaryKey());
1656 }
1657 }
1658
1659 for (Long groupPK : groupPKSet) {
1660 addGroup.add(pk, groupPK);
1661 }
1662 }
1663 catch (Exception e) {
1664 throw processException(e);
1665 }
1666 finally {
1667 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1668 }
1669 }
1670
1671 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1672 throws SystemException {
1673 try {
1674 long[] groupPKs = new long[groups.size()];
1675
1676 for (int i = 0; i < groups.size(); i++) {
1677 com.liferay.portal.model.Group group = groups.get(i);
1678
1679 groupPKs[i] = group.getPrimaryKey();
1680 }
1681
1682 setGroups(pk, groupPKs);
1683 }
1684 catch (Exception e) {
1685 throw processException(e);
1686 }
1687 finally {
1688 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1689 }
1690 }
1691
1692 public List<com.liferay.portal.model.User> getUsers(long pk)
1693 throws SystemException {
1694 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1695 }
1696
1697 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1698 int end) throws SystemException {
1699 return getUsers(pk, start, end, null);
1700 }
1701
1702 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1703 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1704 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUsers",
1705 new String[] {
1706 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1707 "com.liferay.portal.kernel.util.OrderByComparator"
1708 });
1709
1710 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1711 int end, OrderByComparator orderByComparator) throws SystemException {
1712 Object[] finderArgs = new Object[] {
1713 pk, String.valueOf(start), String.valueOf(end),
1714 String.valueOf(orderByComparator)
1715 };
1716
1717 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1718 finderArgs, this);
1719
1720 if (list == null) {
1721 Session session = null;
1722
1723 try {
1724 session = openSession();
1725
1726 String sql = null;
1727
1728 if (orderByComparator != null) {
1729 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1730 .concat(orderByComparator.getOrderBy());
1731 }
1732 else {
1733 sql = _SQL_GETUSERS;
1734 }
1735
1736 SQLQuery q = session.createSQLQuery(sql);
1737
1738 q.addEntity("User_",
1739 com.liferay.portal.model.impl.UserImpl.class);
1740
1741 QueryPos qPos = QueryPos.getInstance(q);
1742
1743 qPos.add(pk);
1744
1745 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1746 getDialect(), start, end);
1747 }
1748 catch (Exception e) {
1749 throw processException(e);
1750 }
1751 finally {
1752 if (list == null) {
1753 list = new ArrayList<com.liferay.portal.model.User>();
1754 }
1755
1756 userPersistence.cacheResult(list);
1757
1758 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1759 list);
1760
1761 closeSession(session);
1762 }
1763 }
1764
1765 return list;
1766 }
1767
1768 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1769 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1770 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1771 "getUsersSize", new String[] { Long.class.getName() });
1772
1773 public int getUsersSize(long pk) throws SystemException {
1774 Object[] finderArgs = new Object[] { pk };
1775
1776 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1777 finderArgs, this);
1778
1779 if (count == null) {
1780 Session session = null;
1781
1782 try {
1783 session = openSession();
1784
1785 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1786
1787 q.addScalar(COUNT_COLUMN_NAME,
1788 com.liferay.portal.kernel.dao.orm.Type.LONG);
1789
1790 QueryPos qPos = QueryPos.getInstance(q);
1791
1792 qPos.add(pk);
1793
1794 count = (Long)q.uniqueResult();
1795 }
1796 catch (Exception e) {
1797 throw processException(e);
1798 }
1799 finally {
1800 if (count == null) {
1801 count = Long.valueOf(0);
1802 }
1803
1804 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1805 finderArgs, count);
1806
1807 closeSession(session);
1808 }
1809 }
1810
1811 return count.intValue();
1812 }
1813
1814 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1815 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1816 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1817 "containsUser",
1818 new String[] { Long.class.getName(), Long.class.getName() });
1819
1820 public boolean containsUser(long pk, long userPK) throws SystemException {
1821 Object[] finderArgs = new Object[] { pk, userPK };
1822
1823 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1824 finderArgs, this);
1825
1826 if (value == null) {
1827 try {
1828 value = Boolean.valueOf(containsUser.contains(pk, userPK));
1829 }
1830 catch (Exception e) {
1831 throw processException(e);
1832 }
1833 finally {
1834 if (value == null) {
1835 value = Boolean.FALSE;
1836 }
1837
1838 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1839 finderArgs, value);
1840 }
1841 }
1842
1843 return value.booleanValue();
1844 }
1845
1846 public boolean containsUsers(long pk) throws SystemException {
1847 if (getUsersSize(pk) > 0) {
1848 return true;
1849 }
1850 else {
1851 return false;
1852 }
1853 }
1854
1855 public void addUser(long pk, long userPK) throws SystemException {
1856 try {
1857 addUser.add(pk, userPK);
1858 }
1859 catch (Exception e) {
1860 throw processException(e);
1861 }
1862 finally {
1863 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1864 }
1865 }
1866
1867 public void addUser(long pk, com.liferay.portal.model.User user)
1868 throws SystemException {
1869 try {
1870 addUser.add(pk, user.getPrimaryKey());
1871 }
1872 catch (Exception e) {
1873 throw processException(e);
1874 }
1875 finally {
1876 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1877 }
1878 }
1879
1880 public void addUsers(long pk, long[] userPKs) throws SystemException {
1881 try {
1882 for (long userPK : userPKs) {
1883 addUser.add(pk, userPK);
1884 }
1885 }
1886 catch (Exception e) {
1887 throw processException(e);
1888 }
1889 finally {
1890 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1891 }
1892 }
1893
1894 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1895 throws SystemException {
1896 try {
1897 for (com.liferay.portal.model.User user : users) {
1898 addUser.add(pk, user.getPrimaryKey());
1899 }
1900 }
1901 catch (Exception e) {
1902 throw processException(e);
1903 }
1904 finally {
1905 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1906 }
1907 }
1908
1909 public void clearUsers(long pk) throws SystemException {
1910 try {
1911 clearUsers.clear(pk);
1912 }
1913 catch (Exception e) {
1914 throw processException(e);
1915 }
1916 finally {
1917 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1918 }
1919 }
1920
1921 public void removeUser(long pk, long userPK) throws SystemException {
1922 try {
1923 removeUser.remove(pk, userPK);
1924 }
1925 catch (Exception e) {
1926 throw processException(e);
1927 }
1928 finally {
1929 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1930 }
1931 }
1932
1933 public void removeUser(long pk, com.liferay.portal.model.User user)
1934 throws SystemException {
1935 try {
1936 removeUser.remove(pk, user.getPrimaryKey());
1937 }
1938 catch (Exception e) {
1939 throw processException(e);
1940 }
1941 finally {
1942 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1943 }
1944 }
1945
1946 public void removeUsers(long pk, long[] userPKs) throws SystemException {
1947 try {
1948 for (long userPK : userPKs) {
1949 removeUser.remove(pk, userPK);
1950 }
1951 }
1952 catch (Exception e) {
1953 throw processException(e);
1954 }
1955 finally {
1956 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1957 }
1958 }
1959
1960 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1961 throws SystemException {
1962 try {
1963 for (com.liferay.portal.model.User user : users) {
1964 removeUser.remove(pk, user.getPrimaryKey());
1965 }
1966 }
1967 catch (Exception e) {
1968 throw processException(e);
1969 }
1970 finally {
1971 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1972 }
1973 }
1974
1975 public void setUsers(long pk, long[] userPKs) throws SystemException {
1976 try {
1977 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1978
1979 List<com.liferay.portal.model.User> users = getUsers(pk);
1980
1981 for (com.liferay.portal.model.User user : users) {
1982 if (!userPKSet.remove(user.getPrimaryKey())) {
1983 removeUser.remove(pk, user.getPrimaryKey());
1984 }
1985 }
1986
1987 for (Long userPK : userPKSet) {
1988 addUser.add(pk, userPK);
1989 }
1990 }
1991 catch (Exception e) {
1992 throw processException(e);
1993 }
1994 finally {
1995 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1996 }
1997 }
1998
1999 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2000 throws SystemException {
2001 try {
2002 long[] userPKs = new long[users.size()];
2003
2004 for (int i = 0; i < users.size(); i++) {
2005 com.liferay.portal.model.User user = users.get(i);
2006
2007 userPKs[i] = user.getPrimaryKey();
2008 }
2009
2010 setUsers(pk, userPKs);
2011 }
2012 catch (Exception e) {
2013 throw processException(e);
2014 }
2015 finally {
2016 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2017 }
2018 }
2019
2020 public void afterPropertiesSet() {
2021 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2022 com.liferay.portal.util.PropsUtil.get(
2023 "value.object.listener.com.liferay.portal.model.UserGroup")));
2024
2025 if (listenerClassNames.length > 0) {
2026 try {
2027 List<ModelListener<UserGroup>> listenersList = new ArrayList<ModelListener<UserGroup>>();
2028
2029 for (String listenerClassName : listenerClassNames) {
2030 listenersList.add((ModelListener<UserGroup>)InstanceFactory.newInstance(
2031 listenerClassName));
2032 }
2033
2034 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2035 }
2036 catch (Exception e) {
2037 _log.error(e);
2038 }
2039 }
2040
2041 containsGroup = new ContainsGroup(this);
2042
2043 addGroup = new AddGroup(this);
2044 clearGroups = new ClearGroups(this);
2045 removeGroup = new RemoveGroup(this);
2046
2047 containsUser = new ContainsUser(this);
2048
2049 addUser = new AddUser(this);
2050 clearUsers = new ClearUsers(this);
2051 removeUser = new RemoveUser(this);
2052 }
2053
2054 public void destroy() {
2055 EntityCacheUtil.removeCache(UserGroupImpl.class.getName());
2056 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2057 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2058 }
2059
2060 @BeanReference(type = AccountPersistence.class)
2061 protected AccountPersistence accountPersistence;
2062 @BeanReference(type = AddressPersistence.class)
2063 protected AddressPersistence addressPersistence;
2064 @BeanReference(type = BrowserTrackerPersistence.class)
2065 protected BrowserTrackerPersistence browserTrackerPersistence;
2066 @BeanReference(type = ClassNamePersistence.class)
2067 protected ClassNamePersistence classNamePersistence;
2068 @BeanReference(type = CompanyPersistence.class)
2069 protected CompanyPersistence companyPersistence;
2070 @BeanReference(type = ContactPersistence.class)
2071 protected ContactPersistence contactPersistence;
2072 @BeanReference(type = CountryPersistence.class)
2073 protected CountryPersistence countryPersistence;
2074 @BeanReference(type = EmailAddressPersistence.class)
2075 protected EmailAddressPersistence emailAddressPersistence;
2076 @BeanReference(type = GroupPersistence.class)
2077 protected GroupPersistence groupPersistence;
2078 @BeanReference(type = ImagePersistence.class)
2079 protected ImagePersistence imagePersistence;
2080 @BeanReference(type = LayoutPersistence.class)
2081 protected LayoutPersistence layoutPersistence;
2082 @BeanReference(type = LayoutSetPersistence.class)
2083 protected LayoutSetPersistence layoutSetPersistence;
2084 @BeanReference(type = ListTypePersistence.class)
2085 protected ListTypePersistence listTypePersistence;
2086 @BeanReference(type = LockPersistence.class)
2087 protected LockPersistence lockPersistence;
2088 @BeanReference(type = MembershipRequestPersistence.class)
2089 protected MembershipRequestPersistence membershipRequestPersistence;
2090 @BeanReference(type = OrganizationPersistence.class)
2091 protected OrganizationPersistence organizationPersistence;
2092 @BeanReference(type = OrgGroupPermissionPersistence.class)
2093 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2094 @BeanReference(type = OrgGroupRolePersistence.class)
2095 protected OrgGroupRolePersistence orgGroupRolePersistence;
2096 @BeanReference(type = OrgLaborPersistence.class)
2097 protected OrgLaborPersistence orgLaborPersistence;
2098 @BeanReference(type = PasswordPolicyPersistence.class)
2099 protected PasswordPolicyPersistence passwordPolicyPersistence;
2100 @BeanReference(type = PasswordPolicyRelPersistence.class)
2101 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2102 @BeanReference(type = PasswordTrackerPersistence.class)
2103 protected PasswordTrackerPersistence passwordTrackerPersistence;
2104 @BeanReference(type = PermissionPersistence.class)
2105 protected PermissionPersistence permissionPersistence;
2106 @BeanReference(type = PhonePersistence.class)
2107 protected PhonePersistence phonePersistence;
2108 @BeanReference(type = PluginSettingPersistence.class)
2109 protected PluginSettingPersistence pluginSettingPersistence;
2110 @BeanReference(type = PortletPersistence.class)
2111 protected PortletPersistence portletPersistence;
2112 @BeanReference(type = PortletItemPersistence.class)
2113 protected PortletItemPersistence portletItemPersistence;
2114 @BeanReference(type = PortletPreferencesPersistence.class)
2115 protected PortletPreferencesPersistence portletPreferencesPersistence;
2116 @BeanReference(type = RegionPersistence.class)
2117 protected RegionPersistence regionPersistence;
2118 @BeanReference(type = ReleasePersistence.class)
2119 protected ReleasePersistence releasePersistence;
2120 @BeanReference(type = ResourcePersistence.class)
2121 protected ResourcePersistence resourcePersistence;
2122 @BeanReference(type = ResourceActionPersistence.class)
2123 protected ResourceActionPersistence resourceActionPersistence;
2124 @BeanReference(type = ResourceCodePersistence.class)
2125 protected ResourceCodePersistence resourceCodePersistence;
2126 @BeanReference(type = ResourcePermissionPersistence.class)
2127 protected ResourcePermissionPersistence resourcePermissionPersistence;
2128 @BeanReference(type = RolePersistence.class)
2129 protected RolePersistence rolePersistence;
2130 @BeanReference(type = ServiceComponentPersistence.class)
2131 protected ServiceComponentPersistence serviceComponentPersistence;
2132 @BeanReference(type = ShardPersistence.class)
2133 protected ShardPersistence shardPersistence;
2134 @BeanReference(type = SubscriptionPersistence.class)
2135 protected SubscriptionPersistence subscriptionPersistence;
2136 @BeanReference(type = UserPersistence.class)
2137 protected UserPersistence userPersistence;
2138 @BeanReference(type = UserGroupPersistence.class)
2139 protected UserGroupPersistence userGroupPersistence;
2140 @BeanReference(type = UserGroupGroupRolePersistence.class)
2141 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2142 @BeanReference(type = UserGroupRolePersistence.class)
2143 protected UserGroupRolePersistence userGroupRolePersistence;
2144 @BeanReference(type = UserIdMapperPersistence.class)
2145 protected UserIdMapperPersistence userIdMapperPersistence;
2146 @BeanReference(type = UserTrackerPersistence.class)
2147 protected UserTrackerPersistence userTrackerPersistence;
2148 @BeanReference(type = UserTrackerPathPersistence.class)
2149 protected UserTrackerPathPersistence userTrackerPathPersistence;
2150 @BeanReference(type = WebDAVPropsPersistence.class)
2151 protected WebDAVPropsPersistence webDAVPropsPersistence;
2152 @BeanReference(type = WebsitePersistence.class)
2153 protected WebsitePersistence websitePersistence;
2154 protected ContainsGroup containsGroup;
2155 protected AddGroup addGroup;
2156 protected ClearGroups clearGroups;
2157 protected RemoveGroup removeGroup;
2158 protected ContainsUser containsUser;
2159 protected AddUser addUser;
2160 protected ClearUsers clearUsers;
2161 protected RemoveUser removeUser;
2162
2163 protected class ContainsGroup {
2164 protected ContainsGroup(UserGroupPersistenceImpl persistenceImpl) {
2165 super();
2166
2167 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2168 _SQL_CONTAINSGROUP,
2169 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2170 RowMapper.COUNT);
2171 }
2172
2173 protected boolean contains(long userGroupId, long groupId) {
2174 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2175 new Long(userGroupId), new Long(groupId)
2176 });
2177
2178 if (results.size() > 0) {
2179 Integer count = results.get(0);
2180
2181 if (count.intValue() > 0) {
2182 return true;
2183 }
2184 }
2185
2186 return false;
2187 }
2188
2189 private MappingSqlQuery _mappingSqlQuery;
2190 }
2191
2192 protected class AddGroup {
2193 protected AddGroup(UserGroupPersistenceImpl persistenceImpl) {
2194 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2195 "INSERT INTO Groups_UserGroups (userGroupId, groupId) VALUES (?, ?)",
2196 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2197 _persistenceImpl = persistenceImpl;
2198 }
2199
2200 protected void add(long userGroupId, long groupId)
2201 throws SystemException {
2202 if (!_persistenceImpl.containsGroup.contains(userGroupId, groupId)) {
2203 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2204
2205 for (ModelListener<UserGroup> listener : listeners) {
2206 listener.onBeforeAddAssociation(userGroupId,
2207 com.liferay.portal.model.Group.class.getName(), groupId);
2208 }
2209
2210 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2211 listener.onBeforeAddAssociation(groupId,
2212 UserGroup.class.getName(), userGroupId);
2213 }
2214
2215 _sqlUpdate.update(new Object[] {
2216 new Long(userGroupId), new Long(groupId)
2217 });
2218
2219 for (ModelListener<UserGroup> listener : listeners) {
2220 listener.onAfterAddAssociation(userGroupId,
2221 com.liferay.portal.model.Group.class.getName(), groupId);
2222 }
2223
2224 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2225 listener.onAfterAddAssociation(groupId,
2226 UserGroup.class.getName(), userGroupId);
2227 }
2228 }
2229 }
2230
2231 private SqlUpdate _sqlUpdate;
2232 private UserGroupPersistenceImpl _persistenceImpl;
2233 }
2234
2235 protected class ClearGroups {
2236 protected ClearGroups(UserGroupPersistenceImpl persistenceImpl) {
2237 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2238 "DELETE FROM Groups_UserGroups WHERE userGroupId = ?",
2239 new int[] { java.sql.Types.BIGINT });
2240 }
2241
2242 protected void clear(long userGroupId) throws SystemException {
2243 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2244
2245 List<com.liferay.portal.model.Group> groups = null;
2246
2247 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2248 groups = getGroups(userGroupId);
2249
2250 for (com.liferay.portal.model.Group group : groups) {
2251 for (ModelListener<UserGroup> listener : listeners) {
2252 listener.onBeforeRemoveAssociation(userGroupId,
2253 com.liferay.portal.model.Group.class.getName(),
2254 group.getPrimaryKey());
2255 }
2256
2257 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2258 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2259 UserGroup.class.getName(), userGroupId);
2260 }
2261 }
2262 }
2263
2264 _sqlUpdate.update(new Object[] { new Long(userGroupId) });
2265
2266 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2267 for (com.liferay.portal.model.Group group : groups) {
2268 for (ModelListener<UserGroup> listener : listeners) {
2269 listener.onAfterRemoveAssociation(userGroupId,
2270 com.liferay.portal.model.Group.class.getName(),
2271 group.getPrimaryKey());
2272 }
2273
2274 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2275 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
2276 UserGroup.class.getName(), userGroupId);
2277 }
2278 }
2279 }
2280 }
2281
2282 private SqlUpdate _sqlUpdate;
2283 }
2284
2285 protected class RemoveGroup {
2286 protected RemoveGroup(UserGroupPersistenceImpl persistenceImpl) {
2287 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2288 "DELETE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?",
2289 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2290 _persistenceImpl = persistenceImpl;
2291 }
2292
2293 protected void remove(long userGroupId, long groupId)
2294 throws SystemException {
2295 if (_persistenceImpl.containsGroup.contains(userGroupId, groupId)) {
2296 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2297
2298 for (ModelListener<UserGroup> listener : listeners) {
2299 listener.onBeforeRemoveAssociation(userGroupId,
2300 com.liferay.portal.model.Group.class.getName(), groupId);
2301 }
2302
2303 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2304 listener.onBeforeRemoveAssociation(groupId,
2305 UserGroup.class.getName(), userGroupId);
2306 }
2307
2308 _sqlUpdate.update(new Object[] {
2309 new Long(userGroupId), new Long(groupId)
2310 });
2311
2312 for (ModelListener<UserGroup> listener : listeners) {
2313 listener.onAfterRemoveAssociation(userGroupId,
2314 com.liferay.portal.model.Group.class.getName(), groupId);
2315 }
2316
2317 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2318 listener.onAfterRemoveAssociation(groupId,
2319 UserGroup.class.getName(), userGroupId);
2320 }
2321 }
2322 }
2323
2324 private SqlUpdate _sqlUpdate;
2325 private UserGroupPersistenceImpl _persistenceImpl;
2326 }
2327
2328 protected class ContainsUser {
2329 protected ContainsUser(UserGroupPersistenceImpl persistenceImpl) {
2330 super();
2331
2332 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2333 _SQL_CONTAINSUSER,
2334 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2335 RowMapper.COUNT);
2336 }
2337
2338 protected boolean contains(long userGroupId, long userId) {
2339 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2340 new Long(userGroupId), new Long(userId)
2341 });
2342
2343 if (results.size() > 0) {
2344 Integer count = results.get(0);
2345
2346 if (count.intValue() > 0) {
2347 return true;
2348 }
2349 }
2350
2351 return false;
2352 }
2353
2354 private MappingSqlQuery _mappingSqlQuery;
2355 }
2356
2357 protected class AddUser {
2358 protected AddUser(UserGroupPersistenceImpl persistenceImpl) {
2359 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2360 "INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)",
2361 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2362 _persistenceImpl = persistenceImpl;
2363 }
2364
2365 protected void add(long userGroupId, long userId)
2366 throws SystemException {
2367 if (!_persistenceImpl.containsUser.contains(userGroupId, userId)) {
2368 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2369
2370 for (ModelListener<UserGroup> listener : listeners) {
2371 listener.onBeforeAddAssociation(userGroupId,
2372 com.liferay.portal.model.User.class.getName(), userId);
2373 }
2374
2375 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2376 listener.onBeforeAddAssociation(userId,
2377 UserGroup.class.getName(), userGroupId);
2378 }
2379
2380 _sqlUpdate.update(new Object[] {
2381 new Long(userGroupId), new Long(userId)
2382 });
2383
2384 for (ModelListener<UserGroup> listener : listeners) {
2385 listener.onAfterAddAssociation(userGroupId,
2386 com.liferay.portal.model.User.class.getName(), userId);
2387 }
2388
2389 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2390 listener.onAfterAddAssociation(userId,
2391 UserGroup.class.getName(), userGroupId);
2392 }
2393 }
2394 }
2395
2396 private SqlUpdate _sqlUpdate;
2397 private UserGroupPersistenceImpl _persistenceImpl;
2398 }
2399
2400 protected class ClearUsers {
2401 protected ClearUsers(UserGroupPersistenceImpl persistenceImpl) {
2402 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2403 "DELETE FROM Users_UserGroups WHERE userGroupId = ?",
2404 new int[] { java.sql.Types.BIGINT });
2405 }
2406
2407 protected void clear(long userGroupId) throws SystemException {
2408 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2409
2410 List<com.liferay.portal.model.User> users = null;
2411
2412 if ((listeners.length > 0) || (userListeners.length > 0)) {
2413 users = getUsers(userGroupId);
2414
2415 for (com.liferay.portal.model.User user : users) {
2416 for (ModelListener<UserGroup> listener : listeners) {
2417 listener.onBeforeRemoveAssociation(userGroupId,
2418 com.liferay.portal.model.User.class.getName(),
2419 user.getPrimaryKey());
2420 }
2421
2422 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2423 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2424 UserGroup.class.getName(), userGroupId);
2425 }
2426 }
2427 }
2428
2429 _sqlUpdate.update(new Object[] { new Long(userGroupId) });
2430
2431 if ((listeners.length > 0) || (userListeners.length > 0)) {
2432 for (com.liferay.portal.model.User user : users) {
2433 for (ModelListener<UserGroup> listener : listeners) {
2434 listener.onAfterRemoveAssociation(userGroupId,
2435 com.liferay.portal.model.User.class.getName(),
2436 user.getPrimaryKey());
2437 }
2438
2439 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2440 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2441 UserGroup.class.getName(), userGroupId);
2442 }
2443 }
2444 }
2445 }
2446
2447 private SqlUpdate _sqlUpdate;
2448 }
2449
2450 protected class RemoveUser {
2451 protected RemoveUser(UserGroupPersistenceImpl persistenceImpl) {
2452 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2453 "DELETE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
2454 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2455 _persistenceImpl = persistenceImpl;
2456 }
2457
2458 protected void remove(long userGroupId, long userId)
2459 throws SystemException {
2460 if (_persistenceImpl.containsUser.contains(userGroupId, userId)) {
2461 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2462
2463 for (ModelListener<UserGroup> listener : listeners) {
2464 listener.onBeforeRemoveAssociation(userGroupId,
2465 com.liferay.portal.model.User.class.getName(), userId);
2466 }
2467
2468 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2469 listener.onBeforeRemoveAssociation(userId,
2470 UserGroup.class.getName(), userGroupId);
2471 }
2472
2473 _sqlUpdate.update(new Object[] {
2474 new Long(userGroupId), new Long(userId)
2475 });
2476
2477 for (ModelListener<UserGroup> listener : listeners) {
2478 listener.onAfterRemoveAssociation(userGroupId,
2479 com.liferay.portal.model.User.class.getName(), userId);
2480 }
2481
2482 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2483 listener.onAfterRemoveAssociation(userId,
2484 UserGroup.class.getName(), userGroupId);
2485 }
2486 }
2487 }
2488
2489 private SqlUpdate _sqlUpdate;
2490 private UserGroupPersistenceImpl _persistenceImpl;
2491 }
2492
2493 private static final String _SQL_SELECT_USERGROUP = "SELECT userGroup FROM UserGroup userGroup";
2494 private static final String _SQL_SELECT_USERGROUP_WHERE = "SELECT userGroup FROM UserGroup userGroup WHERE ";
2495 private static final String _SQL_COUNT_USERGROUP = "SELECT COUNT(userGroup) FROM UserGroup userGroup";
2496 private static final String _SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(userGroup) FROM UserGroup userGroup WHERE ";
2497 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_UserGroups ON (Groups_UserGroups.groupId = Group_.groupId) WHERE (Groups_UserGroups.userGroupId = ?)";
2498 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ?";
2499 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?";
2500 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_UserGroups ON (Users_UserGroups.userId = User_.userId) WHERE (Users_UserGroups.userGroupId = ?)";
2501 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ?";
2502 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?";
2503 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userGroup.companyId = ?";
2504 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "userGroup.companyId = ? AND ";
2505 private static final String _FINDER_COLUMN_C_P_PARENTUSERGROUPID_2 = "userGroup.parentUserGroupId = ?";
2506 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "userGroup.companyId = ? AND ";
2507 private static final String _FINDER_COLUMN_C_N_NAME_1 = "userGroup.name IS NULL";
2508 private static final String _FINDER_COLUMN_C_N_NAME_2 = "userGroup.name = ?";
2509 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(userGroup.name IS NULL OR userGroup.name = ?)";
2510 private static final String _ORDER_BY_ENTITY_ALIAS = "userGroup.";
2511 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroup exists with the primary key ";
2512 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroup exists with the key {";
2513 private static Log _log = LogFactoryUtil.getLog(UserGroupPersistenceImpl.class);
2514}