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.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
22 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
23 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
24 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
25 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
26 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
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.dao.orm.Type;
36 import com.liferay.portal.kernel.exception.SystemException;
37 import com.liferay.portal.kernel.log.Log;
38 import com.liferay.portal.kernel.log.LogFactoryUtil;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.OrderByComparator;
41 import com.liferay.portal.kernel.util.SetUtil;
42 import com.liferay.portal.kernel.util.StringBundler;
43 import com.liferay.portal.kernel.util.StringPool;
44 import com.liferay.portal.kernel.util.StringUtil;
45 import com.liferay.portal.kernel.util.Validator;
46 import com.liferay.portal.model.ModelListener;
47 import com.liferay.portal.model.UserGroup;
48 import com.liferay.portal.model.impl.UserGroupImpl;
49 import com.liferay.portal.model.impl.UserGroupModelImpl;
50 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
51
52 import java.io.Serializable;
53
54 import java.sql.Types;
55
56 import java.util.ArrayList;
57 import java.util.Collections;
58 import java.util.List;
59 import java.util.Set;
60
61
74 public class UserGroupPersistenceImpl extends BasePersistenceImpl<UserGroup>
75 implements UserGroupPersistence {
76 public static final String FINDER_CLASS_NAME_ENTITY = UserGroupImpl.class.getName();
77 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
78 ".List";
79 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
80 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
81 "findByCompanyId", new String[] { Long.class.getName() });
82 public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
83 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
84 "findByCompanyId",
85 new String[] {
86 Long.class.getName(),
87
88 "java.lang.Integer", "java.lang.Integer",
89 "com.liferay.portal.kernel.util.OrderByComparator"
90 });
91 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
92 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93 "countByCompanyId", new String[] { Long.class.getName() });
94 public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
95 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96 "findByC_P",
97 new String[] { Long.class.getName(), Long.class.getName() });
98 public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
99 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100 "findByC_P",
101 new String[] {
102 Long.class.getName(), Long.class.getName(),
103
104 "java.lang.Integer", "java.lang.Integer",
105 "com.liferay.portal.kernel.util.OrderByComparator"
106 });
107 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
108 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109 "countByC_P",
110 new String[] { Long.class.getName(), Long.class.getName() });
111 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
112 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
113 "fetchByC_N",
114 new String[] { Long.class.getName(), String.class.getName() });
115 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
116 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117 "countByC_N",
118 new String[] { Long.class.getName(), String.class.getName() });
119 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
120 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121 "findAll", new String[0]);
122 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
123 UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124 "countAll", new String[0]);
125
126 public void cacheResult(UserGroup userGroup) {
127 EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
128 UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
129
130 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
131 new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() },
132 userGroup);
133 }
134
135 public void cacheResult(List<UserGroup> userGroups) {
136 for (UserGroup userGroup : userGroups) {
137 if (EntityCacheUtil.getResult(
138 UserGroupModelImpl.ENTITY_CACHE_ENABLED,
139 UserGroupImpl.class, userGroup.getPrimaryKey(), this) == null) {
140 cacheResult(userGroup);
141 }
142 }
143 }
144
145 public void clearCache() {
146 CacheRegistry.clear(UserGroupImpl.class.getName());
147 EntityCacheUtil.clearCache(UserGroupImpl.class.getName());
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
150 }
151
152 public UserGroup create(long userGroupId) {
153 UserGroup userGroup = new UserGroupImpl();
154
155 userGroup.setNew(true);
156 userGroup.setPrimaryKey(userGroupId);
157
158 return userGroup;
159 }
160
161 public UserGroup remove(Serializable primaryKey)
162 throws NoSuchModelException, SystemException {
163 return remove(((Long)primaryKey).longValue());
164 }
165
166 public UserGroup remove(long userGroupId)
167 throws NoSuchUserGroupException, SystemException {
168 Session session = null;
169
170 try {
171 session = openSession();
172
173 UserGroup userGroup = (UserGroup)session.get(UserGroupImpl.class,
174 new Long(userGroupId));
175
176 if (userGroup == null) {
177 if (_log.isWarnEnabled()) {
178 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
179 }
180
181 throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
182 userGroupId);
183 }
184
185 return remove(userGroup);
186 }
187 catch (NoSuchUserGroupException nsee) {
188 throw nsee;
189 }
190 catch (Exception e) {
191 throw processException(e);
192 }
193 finally {
194 closeSession(session);
195 }
196 }
197
198 public UserGroup remove(UserGroup userGroup) throws SystemException {
199 for (ModelListener<UserGroup> listener : listeners) {
200 listener.onBeforeRemove(userGroup);
201 }
202
203 userGroup = removeImpl(userGroup);
204
205 for (ModelListener<UserGroup> listener : listeners) {
206 listener.onAfterRemove(userGroup);
207 }
208
209 return userGroup;
210 }
211
212 protected UserGroup removeImpl(UserGroup userGroup)
213 throws SystemException {
214 userGroup = toUnwrappedModel(userGroup);
215
216 try {
217 clearUsers.clear(userGroup.getPrimaryKey());
218 }
219 catch (Exception e) {
220 throw processException(e);
221 }
222 finally {
223 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
224 }
225
226 Session session = null;
227
228 try {
229 session = openSession();
230
231 if (userGroup.isCachedModel() || BatchSessionUtil.isEnabled()) {
232 Object staleObject = session.get(UserGroupImpl.class,
233 userGroup.getPrimaryKeyObj());
234
235 if (staleObject != null) {
236 session.evict(staleObject);
237 }
238 }
239
240 session.delete(userGroup);
241
242 session.flush();
243 }
244 catch (Exception e) {
245 throw processException(e);
246 }
247 finally {
248 closeSession(session);
249 }
250
251 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
252
253 UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
254
255 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
256 new Object[] {
257 new Long(userGroupModelImpl.getOriginalCompanyId()),
258
259 userGroupModelImpl.getOriginalName()
260 });
261
262 EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
263 UserGroupImpl.class, userGroup.getPrimaryKey());
264
265 return userGroup;
266 }
267
268 public UserGroup updateImpl(com.liferay.portal.model.UserGroup userGroup,
269 boolean merge) throws SystemException {
270 userGroup = toUnwrappedModel(userGroup);
271
272 boolean isNew = userGroup.isNew();
273
274 UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
275
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 BatchSessionUtil.update(session, userGroup, merge);
282
283 userGroup.setNew(false);
284 }
285 catch (Exception e) {
286 throw processException(e);
287 }
288 finally {
289 closeSession(session);
290 }
291
292 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
293
294 EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
295 UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
296
297 if (!isNew &&
298 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
299 !Validator.equals(userGroup.getName(),
300 userGroupModelImpl.getOriginalName()))) {
301 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
302 new Object[] {
303 new Long(userGroupModelImpl.getOriginalCompanyId()),
304
305 userGroupModelImpl.getOriginalName()
306 });
307 }
308
309 if (isNew ||
310 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
311 !Validator.equals(userGroup.getName(),
312 userGroupModelImpl.getOriginalName()))) {
313 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
314 new Object[] {
315 new Long(userGroup.getCompanyId()),
316
317 userGroup.getName()
318 }, userGroup);
319 }
320
321 return userGroup;
322 }
323
324 protected UserGroup toUnwrappedModel(UserGroup userGroup) {
325 if (userGroup instanceof UserGroupImpl) {
326 return userGroup;
327 }
328
329 UserGroupImpl userGroupImpl = new UserGroupImpl();
330
331 userGroupImpl.setNew(userGroup.isNew());
332 userGroupImpl.setPrimaryKey(userGroup.getPrimaryKey());
333
334 userGroupImpl.setUserGroupId(userGroup.getUserGroupId());
335 userGroupImpl.setCompanyId(userGroup.getCompanyId());
336 userGroupImpl.setParentUserGroupId(userGroup.getParentUserGroupId());
337 userGroupImpl.setName(userGroup.getName());
338 userGroupImpl.setDescription(userGroup.getDescription());
339
340 return userGroupImpl;
341 }
342
343 public UserGroup findByPrimaryKey(Serializable primaryKey)
344 throws NoSuchModelException, SystemException {
345 return findByPrimaryKey(((Long)primaryKey).longValue());
346 }
347
348 public UserGroup findByPrimaryKey(long userGroupId)
349 throws NoSuchUserGroupException, SystemException {
350 UserGroup userGroup = fetchByPrimaryKey(userGroupId);
351
352 if (userGroup == null) {
353 if (_log.isWarnEnabled()) {
354 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
355 }
356
357 throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
358 userGroupId);
359 }
360
361 return userGroup;
362 }
363
364 public UserGroup fetchByPrimaryKey(Serializable primaryKey)
365 throws SystemException {
366 return fetchByPrimaryKey(((Long)primaryKey).longValue());
367 }
368
369 public UserGroup fetchByPrimaryKey(long userGroupId)
370 throws SystemException {
371 UserGroup userGroup = (UserGroup)EntityCacheUtil.getResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
372 UserGroupImpl.class, userGroupId, this);
373
374 if (userGroup == null) {
375 Session session = null;
376
377 try {
378 session = openSession();
379
380 userGroup = (UserGroup)session.get(UserGroupImpl.class,
381 new Long(userGroupId));
382 }
383 catch (Exception e) {
384 throw processException(e);
385 }
386 finally {
387 if (userGroup != null) {
388 cacheResult(userGroup);
389 }
390
391 closeSession(session);
392 }
393 }
394
395 return userGroup;
396 }
397
398 public List<UserGroup> findByCompanyId(long companyId)
399 throws SystemException {
400 Object[] finderArgs = new Object[] { new Long(companyId) };
401
402 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
403 finderArgs, this);
404
405 if (list == null) {
406 Session session = null;
407
408 try {
409 session = openSession();
410
411 StringBundler query = new StringBundler(3);
412
413 query.append(_SQL_SELECT_USERGROUP_WHERE);
414
415 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
416
417 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
418
419 String sql = query.toString();
420
421 Query q = session.createQuery(sql);
422
423 QueryPos qPos = QueryPos.getInstance(q);
424
425 qPos.add(companyId);
426
427 list = q.list();
428 }
429 catch (Exception e) {
430 throw processException(e);
431 }
432 finally {
433 if (list == null) {
434 list = new ArrayList<UserGroup>();
435 }
436
437 cacheResult(list);
438
439 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
440 finderArgs, list);
441
442 closeSession(session);
443 }
444 }
445
446 return list;
447 }
448
449 public List<UserGroup> findByCompanyId(long companyId, int start, int end)
450 throws SystemException {
451 return findByCompanyId(companyId, start, end, null);
452 }
453
454 public List<UserGroup> findByCompanyId(long companyId, int start, int end,
455 OrderByComparator obc) throws SystemException {
456 Object[] finderArgs = new Object[] {
457 new Long(companyId),
458
459 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
460 };
461
462 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
463 finderArgs, this);
464
465 if (list == null) {
466 Session session = null;
467
468 try {
469 session = openSession();
470
471 StringBundler query = null;
472
473 if (obc != null) {
474 query = new StringBundler(3 +
475 (obc.getOrderByFields().length * 3));
476 }
477 else {
478 query = new StringBundler(3);
479 }
480
481 query.append(_SQL_SELECT_USERGROUP_WHERE);
482
483 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
484
485 if (obc != null) {
486 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
487 }
488
489 else {
490 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
491 }
492
493 String sql = query.toString();
494
495 Query q = session.createQuery(sql);
496
497 QueryPos qPos = QueryPos.getInstance(q);
498
499 qPos.add(companyId);
500
501 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
502 end);
503 }
504 catch (Exception e) {
505 throw processException(e);
506 }
507 finally {
508 if (list == null) {
509 list = new ArrayList<UserGroup>();
510 }
511
512 cacheResult(list);
513
514 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
515 finderArgs, list);
516
517 closeSession(session);
518 }
519 }
520
521 return list;
522 }
523
524 public UserGroup findByCompanyId_First(long companyId, OrderByComparator obc)
525 throws NoSuchUserGroupException, SystemException {
526 List<UserGroup> list = findByCompanyId(companyId, 0, 1, obc);
527
528 if (list.isEmpty()) {
529 StringBundler msg = new StringBundler(4);
530
531 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
532
533 msg.append("companyId=");
534 msg.append(companyId);
535
536 msg.append(StringPool.CLOSE_CURLY_BRACE);
537
538 throw new NoSuchUserGroupException(msg.toString());
539 }
540 else {
541 return list.get(0);
542 }
543 }
544
545 public UserGroup findByCompanyId_Last(long companyId, OrderByComparator obc)
546 throws NoSuchUserGroupException, SystemException {
547 int count = countByCompanyId(companyId);
548
549 List<UserGroup> list = findByCompanyId(companyId, count - 1, count, obc);
550
551 if (list.isEmpty()) {
552 StringBundler msg = new StringBundler(4);
553
554 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
555
556 msg.append("companyId=");
557 msg.append(companyId);
558
559 msg.append(StringPool.CLOSE_CURLY_BRACE);
560
561 throw new NoSuchUserGroupException(msg.toString());
562 }
563 else {
564 return list.get(0);
565 }
566 }
567
568 public UserGroup[] findByCompanyId_PrevAndNext(long userGroupId,
569 long companyId, OrderByComparator obc)
570 throws NoSuchUserGroupException, SystemException {
571 UserGroup userGroup = findByPrimaryKey(userGroupId);
572
573 int count = countByCompanyId(companyId);
574
575 Session session = null;
576
577 try {
578 session = openSession();
579
580 StringBundler query = null;
581
582 if (obc != null) {
583 query = new StringBundler(3 +
584 (obc.getOrderByFields().length * 3));
585 }
586 else {
587 query = new StringBundler(3);
588 }
589
590 query.append(_SQL_SELECT_USERGROUP_WHERE);
591
592 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
593
594 if (obc != null) {
595 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
596 }
597
598 else {
599 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
600 }
601
602 String sql = query.toString();
603
604 Query q = session.createQuery(sql);
605
606 QueryPos qPos = QueryPos.getInstance(q);
607
608 qPos.add(companyId);
609
610 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
611 userGroup);
612
613 UserGroup[] array = new UserGroupImpl[3];
614
615 array[0] = (UserGroup)objArray[0];
616 array[1] = (UserGroup)objArray[1];
617 array[2] = (UserGroup)objArray[2];
618
619 return array;
620 }
621 catch (Exception e) {
622 throw processException(e);
623 }
624 finally {
625 closeSession(session);
626 }
627 }
628
629 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId)
630 throws SystemException {
631 Object[] finderArgs = new Object[] {
632 new Long(companyId), new Long(parentUserGroupId)
633 };
634
635 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
636 finderArgs, this);
637
638 if (list == null) {
639 Session session = null;
640
641 try {
642 session = openSession();
643
644 StringBundler query = new StringBundler(4);
645
646 query.append(_SQL_SELECT_USERGROUP_WHERE);
647
648 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
649
650 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
651
652 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
653
654 String sql = query.toString();
655
656 Query q = session.createQuery(sql);
657
658 QueryPos qPos = QueryPos.getInstance(q);
659
660 qPos.add(companyId);
661
662 qPos.add(parentUserGroupId);
663
664 list = q.list();
665 }
666 catch (Exception e) {
667 throw processException(e);
668 }
669 finally {
670 if (list == null) {
671 list = new ArrayList<UserGroup>();
672 }
673
674 cacheResult(list);
675
676 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
677 list);
678
679 closeSession(session);
680 }
681 }
682
683 return list;
684 }
685
686 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
687 int start, int end) throws SystemException {
688 return findByC_P(companyId, parentUserGroupId, start, end, null);
689 }
690
691 public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
692 int start, int end, OrderByComparator obc) throws SystemException {
693 Object[] finderArgs = new Object[] {
694 new Long(companyId), new Long(parentUserGroupId),
695
696 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
697 };
698
699 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_P,
700 finderArgs, this);
701
702 if (list == null) {
703 Session session = null;
704
705 try {
706 session = openSession();
707
708 StringBundler query = null;
709
710 if (obc != null) {
711 query = new StringBundler(4 +
712 (obc.getOrderByFields().length * 3));
713 }
714 else {
715 query = new StringBundler(4);
716 }
717
718 query.append(_SQL_SELECT_USERGROUP_WHERE);
719
720 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
721
722 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
723
724 if (obc != null) {
725 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
726 }
727
728 else {
729 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
730 }
731
732 String sql = query.toString();
733
734 Query q = session.createQuery(sql);
735
736 QueryPos qPos = QueryPos.getInstance(q);
737
738 qPos.add(companyId);
739
740 qPos.add(parentUserGroupId);
741
742 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
743 end);
744 }
745 catch (Exception e) {
746 throw processException(e);
747 }
748 finally {
749 if (list == null) {
750 list = new ArrayList<UserGroup>();
751 }
752
753 cacheResult(list);
754
755 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_P,
756 finderArgs, list);
757
758 closeSession(session);
759 }
760 }
761
762 return list;
763 }
764
765 public UserGroup findByC_P_First(long companyId, long parentUserGroupId,
766 OrderByComparator obc) throws NoSuchUserGroupException, SystemException {
767 List<UserGroup> list = findByC_P(companyId, parentUserGroupId, 0, 1, obc);
768
769 if (list.isEmpty()) {
770 StringBundler msg = new StringBundler(6);
771
772 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
773
774 msg.append("companyId=");
775 msg.append(companyId);
776
777 msg.append(", parentUserGroupId=");
778 msg.append(parentUserGroupId);
779
780 msg.append(StringPool.CLOSE_CURLY_BRACE);
781
782 throw new NoSuchUserGroupException(msg.toString());
783 }
784 else {
785 return list.get(0);
786 }
787 }
788
789 public UserGroup findByC_P_Last(long companyId, long parentUserGroupId,
790 OrderByComparator obc) throws NoSuchUserGroupException, SystemException {
791 int count = countByC_P(companyId, parentUserGroupId);
792
793 List<UserGroup> list = findByC_P(companyId, parentUserGroupId,
794 count - 1, count, obc);
795
796 if (list.isEmpty()) {
797 StringBundler msg = new StringBundler(6);
798
799 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
800
801 msg.append("companyId=");
802 msg.append(companyId);
803
804 msg.append(", parentUserGroupId=");
805 msg.append(parentUserGroupId);
806
807 msg.append(StringPool.CLOSE_CURLY_BRACE);
808
809 throw new NoSuchUserGroupException(msg.toString());
810 }
811 else {
812 return list.get(0);
813 }
814 }
815
816 public UserGroup[] findByC_P_PrevAndNext(long userGroupId, long companyId,
817 long parentUserGroupId, OrderByComparator obc)
818 throws NoSuchUserGroupException, SystemException {
819 UserGroup userGroup = findByPrimaryKey(userGroupId);
820
821 int count = countByC_P(companyId, parentUserGroupId);
822
823 Session session = null;
824
825 try {
826 session = openSession();
827
828 StringBundler query = null;
829
830 if (obc != null) {
831 query = new StringBundler(4 +
832 (obc.getOrderByFields().length * 3));
833 }
834 else {
835 query = new StringBundler(4);
836 }
837
838 query.append(_SQL_SELECT_USERGROUP_WHERE);
839
840 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
841
842 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
843
844 if (obc != null) {
845 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
846 }
847
848 else {
849 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
850 }
851
852 String sql = query.toString();
853
854 Query q = session.createQuery(sql);
855
856 QueryPos qPos = QueryPos.getInstance(q);
857
858 qPos.add(companyId);
859
860 qPos.add(parentUserGroupId);
861
862 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
863 userGroup);
864
865 UserGroup[] array = new UserGroupImpl[3];
866
867 array[0] = (UserGroup)objArray[0];
868 array[1] = (UserGroup)objArray[1];
869 array[2] = (UserGroup)objArray[2];
870
871 return array;
872 }
873 catch (Exception e) {
874 throw processException(e);
875 }
876 finally {
877 closeSession(session);
878 }
879 }
880
881 public UserGroup findByC_N(long companyId, String name)
882 throws NoSuchUserGroupException, SystemException {
883 UserGroup userGroup = fetchByC_N(companyId, name);
884
885 if (userGroup == null) {
886 StringBundler msg = new StringBundler(6);
887
888 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
889
890 msg.append("companyId=");
891 msg.append(companyId);
892
893 msg.append(", name=");
894 msg.append(name);
895
896 msg.append(StringPool.CLOSE_CURLY_BRACE);
897
898 if (_log.isWarnEnabled()) {
899 _log.warn(msg.toString());
900 }
901
902 throw new NoSuchUserGroupException(msg.toString());
903 }
904
905 return userGroup;
906 }
907
908 public UserGroup fetchByC_N(long companyId, String name)
909 throws SystemException {
910 return fetchByC_N(companyId, name, true);
911 }
912
913 public UserGroup fetchByC_N(long companyId, String name,
914 boolean retrieveFromCache) throws SystemException {
915 Object[] finderArgs = new Object[] { new Long(companyId), name };
916
917 Object result = null;
918
919 if (retrieveFromCache) {
920 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
921 finderArgs, this);
922 }
923
924 if (result == null) {
925 Session session = null;
926
927 try {
928 session = openSession();
929
930 StringBundler query = new StringBundler(4);
931
932 query.append(_SQL_SELECT_USERGROUP_WHERE);
933
934 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
935
936 if (name == null) {
937 query.append(_FINDER_COLUMN_C_N_NAME_1);
938 }
939 else {
940 if (name.equals(StringPool.BLANK)) {
941 query.append(_FINDER_COLUMN_C_N_NAME_3);
942 }
943 else {
944 query.append(_FINDER_COLUMN_C_N_NAME_2);
945 }
946 }
947
948 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
949
950 String sql = query.toString();
951
952 Query q = session.createQuery(sql);
953
954 QueryPos qPos = QueryPos.getInstance(q);
955
956 qPos.add(companyId);
957
958 if (name != null) {
959 qPos.add(name);
960 }
961
962 List<UserGroup> list = q.list();
963
964 result = list;
965
966 UserGroup userGroup = null;
967
968 if (list.isEmpty()) {
969 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
970 finderArgs, list);
971 }
972 else {
973 userGroup = list.get(0);
974
975 cacheResult(userGroup);
976
977 if ((userGroup.getCompanyId() != companyId) ||
978 (userGroup.getName() == null) ||
979 !userGroup.getName().equals(name)) {
980 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
981 finderArgs, userGroup);
982 }
983 }
984
985 return userGroup;
986 }
987 catch (Exception e) {
988 throw processException(e);
989 }
990 finally {
991 if (result == null) {
992 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
993 finderArgs, new ArrayList<UserGroup>());
994 }
995
996 closeSession(session);
997 }
998 }
999 else {
1000 if (result instanceof List<?>) {
1001 return null;
1002 }
1003 else {
1004 return (UserGroup)result;
1005 }
1006 }
1007 }
1008
1009 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1010 throws SystemException {
1011 Session session = null;
1012
1013 try {
1014 session = openSession();
1015
1016 dynamicQuery.compile(session);
1017
1018 return dynamicQuery.list();
1019 }
1020 catch (Exception e) {
1021 throw processException(e);
1022 }
1023 finally {
1024 closeSession(session);
1025 }
1026 }
1027
1028 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1029 int start, int end) throws SystemException {
1030 Session session = null;
1031
1032 try {
1033 session = openSession();
1034
1035 dynamicQuery.setLimit(start, end);
1036
1037 dynamicQuery.compile(session);
1038
1039 return dynamicQuery.list();
1040 }
1041 catch (Exception e) {
1042 throw processException(e);
1043 }
1044 finally {
1045 closeSession(session);
1046 }
1047 }
1048
1049 public List<UserGroup> findAll() throws SystemException {
1050 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1051 }
1052
1053 public List<UserGroup> findAll(int start, int end)
1054 throws SystemException {
1055 return findAll(start, end, null);
1056 }
1057
1058 public List<UserGroup> findAll(int start, int end, OrderByComparator obc)
1059 throws SystemException {
1060 Object[] finderArgs = new Object[] {
1061 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1062 };
1063
1064 List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1065 finderArgs, this);
1066
1067 if (list == null) {
1068 Session session = null;
1069
1070 try {
1071 session = openSession();
1072
1073 StringBundler query = null;
1074 String sql = null;
1075
1076 if (obc != null) {
1077 query = new StringBundler(2 +
1078 (obc.getOrderByFields().length * 3));
1079
1080 query.append(_SQL_SELECT_USERGROUP);
1081
1082 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1083
1084 sql = query.toString();
1085 }
1086
1087 else {
1088 sql = _SQL_SELECT_USERGROUP.concat(UserGroupModelImpl.ORDER_BY_JPQL);
1089 }
1090
1091 Query q = session.createQuery(sql);
1092
1093 if (obc == null) {
1094 list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1095 start, end, false);
1096
1097 Collections.sort(list);
1098 }
1099 else {
1100 list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1101 start, end);
1102 }
1103 }
1104 catch (Exception e) {
1105 throw processException(e);
1106 }
1107 finally {
1108 if (list == null) {
1109 list = new ArrayList<UserGroup>();
1110 }
1111
1112 cacheResult(list);
1113
1114 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1115
1116 closeSession(session);
1117 }
1118 }
1119
1120 return list;
1121 }
1122
1123 public void removeByCompanyId(long companyId) throws SystemException {
1124 for (UserGroup userGroup : findByCompanyId(companyId)) {
1125 remove(userGroup);
1126 }
1127 }
1128
1129 public void removeByC_P(long companyId, long parentUserGroupId)
1130 throws SystemException {
1131 for (UserGroup userGroup : findByC_P(companyId, parentUserGroupId)) {
1132 remove(userGroup);
1133 }
1134 }
1135
1136 public void removeByC_N(long companyId, String name)
1137 throws NoSuchUserGroupException, SystemException {
1138 UserGroup userGroup = findByC_N(companyId, name);
1139
1140 remove(userGroup);
1141 }
1142
1143 public void removeAll() throws SystemException {
1144 for (UserGroup userGroup : findAll()) {
1145 remove(userGroup);
1146 }
1147 }
1148
1149 public int countByCompanyId(long companyId) throws SystemException {
1150 Object[] finderArgs = new Object[] { new Long(companyId) };
1151
1152 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1153 finderArgs, this);
1154
1155 if (count == null) {
1156 Session session = null;
1157
1158 try {
1159 session = openSession();
1160
1161 StringBundler query = new StringBundler(2);
1162
1163 query.append(_SQL_COUNT_USERGROUP_WHERE);
1164
1165 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1166
1167 String sql = query.toString();
1168
1169 Query q = session.createQuery(sql);
1170
1171 QueryPos qPos = QueryPos.getInstance(q);
1172
1173 qPos.add(companyId);
1174
1175 count = (Long)q.uniqueResult();
1176 }
1177 catch (Exception e) {
1178 throw processException(e);
1179 }
1180 finally {
1181 if (count == null) {
1182 count = Long.valueOf(0);
1183 }
1184
1185 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1186 finderArgs, count);
1187
1188 closeSession(session);
1189 }
1190 }
1191
1192 return count.intValue();
1193 }
1194
1195 public int countByC_P(long companyId, long parentUserGroupId)
1196 throws SystemException {
1197 Object[] finderArgs = new Object[] {
1198 new Long(companyId), new Long(parentUserGroupId)
1199 };
1200
1201 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1202 finderArgs, this);
1203
1204 if (count == null) {
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 StringBundler query = new StringBundler(3);
1211
1212 query.append(_SQL_COUNT_USERGROUP_WHERE);
1213
1214 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1215
1216 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1217
1218 String sql = query.toString();
1219
1220 Query q = session.createQuery(sql);
1221
1222 QueryPos qPos = QueryPos.getInstance(q);
1223
1224 qPos.add(companyId);
1225
1226 qPos.add(parentUserGroupId);
1227
1228 count = (Long)q.uniqueResult();
1229 }
1230 catch (Exception e) {
1231 throw processException(e);
1232 }
1233 finally {
1234 if (count == null) {
1235 count = Long.valueOf(0);
1236 }
1237
1238 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1239 count);
1240
1241 closeSession(session);
1242 }
1243 }
1244
1245 return count.intValue();
1246 }
1247
1248 public int countByC_N(long companyId, String name)
1249 throws SystemException {
1250 Object[] finderArgs = new Object[] { new Long(companyId), name };
1251
1252 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1253 finderArgs, this);
1254
1255 if (count == null) {
1256 Session session = null;
1257
1258 try {
1259 session = openSession();
1260
1261 StringBundler query = new StringBundler(3);
1262
1263 query.append(_SQL_COUNT_USERGROUP_WHERE);
1264
1265 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1266
1267 if (name == null) {
1268 query.append(_FINDER_COLUMN_C_N_NAME_1);
1269 }
1270 else {
1271 if (name.equals(StringPool.BLANK)) {
1272 query.append(_FINDER_COLUMN_C_N_NAME_3);
1273 }
1274 else {
1275 query.append(_FINDER_COLUMN_C_N_NAME_2);
1276 }
1277 }
1278
1279 String sql = query.toString();
1280
1281 Query q = session.createQuery(sql);
1282
1283 QueryPos qPos = QueryPos.getInstance(q);
1284
1285 qPos.add(companyId);
1286
1287 if (name != null) {
1288 qPos.add(name);
1289 }
1290
1291 count = (Long)q.uniqueResult();
1292 }
1293 catch (Exception e) {
1294 throw processException(e);
1295 }
1296 finally {
1297 if (count == null) {
1298 count = Long.valueOf(0);
1299 }
1300
1301 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1302 count);
1303
1304 closeSession(session);
1305 }
1306 }
1307
1308 return count.intValue();
1309 }
1310
1311 public int countAll() throws SystemException {
1312 Object[] finderArgs = new Object[0];
1313
1314 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1315 finderArgs, this);
1316
1317 if (count == null) {
1318 Session session = null;
1319
1320 try {
1321 session = openSession();
1322
1323 Query q = session.createQuery(_SQL_COUNT_USERGROUP);
1324
1325 count = (Long)q.uniqueResult();
1326 }
1327 catch (Exception e) {
1328 throw processException(e);
1329 }
1330 finally {
1331 if (count == null) {
1332 count = Long.valueOf(0);
1333 }
1334
1335 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1336 count);
1337
1338 closeSession(session);
1339 }
1340 }
1341
1342 return count.intValue();
1343 }
1344
1345 public List<com.liferay.portal.model.User> getUsers(long pk)
1346 throws SystemException {
1347 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1348 }
1349
1350 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1351 int end) throws SystemException {
1352 return getUsers(pk, start, end, null);
1353 }
1354
1355 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1356 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1357 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUsers",
1358 new String[] {
1359 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1360 "com.liferay.portal.kernel.util.OrderByComparator"
1361 });
1362
1363 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1364 int end, OrderByComparator obc) throws SystemException {
1365 Object[] finderArgs = new Object[] {
1366 new Long(pk), String.valueOf(start), String.valueOf(end),
1367 String.valueOf(obc)
1368 };
1369
1370 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1371 finderArgs, this);
1372
1373 if (list == null) {
1374 Session session = null;
1375
1376 try {
1377 session = openSession();
1378
1379 String sql = null;
1380
1381 if (obc != null) {
1382 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1383 .concat(obc.getOrderBy());
1384 }
1385
1386 sql = _SQL_GETUSERS;
1387
1388 SQLQuery q = session.createSQLQuery(sql);
1389
1390 q.addEntity("User_",
1391 com.liferay.portal.model.impl.UserImpl.class);
1392
1393 QueryPos qPos = QueryPos.getInstance(q);
1394
1395 qPos.add(pk);
1396
1397 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1398 getDialect(), start, end);
1399 }
1400 catch (Exception e) {
1401 throw processException(e);
1402 }
1403 finally {
1404 if (list == null) {
1405 list = new ArrayList<com.liferay.portal.model.User>();
1406 }
1407
1408 userPersistence.cacheResult(list);
1409
1410 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1411 list);
1412
1413 closeSession(session);
1414 }
1415 }
1416
1417 return list;
1418 }
1419
1420 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1421 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1422 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1423 "getUsersSize", new String[] { Long.class.getName() });
1424
1425 public int getUsersSize(long pk) throws SystemException {
1426 Object[] finderArgs = new Object[] { new Long(pk) };
1427
1428 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1429 finderArgs, this);
1430
1431 if (count == null) {
1432 Session session = null;
1433
1434 try {
1435 session = openSession();
1436
1437 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1438
1439 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1440
1441 QueryPos qPos = QueryPos.getInstance(q);
1442
1443 qPos.add(pk);
1444
1445 count = (Long)q.uniqueResult();
1446 }
1447 catch (Exception e) {
1448 throw processException(e);
1449 }
1450 finally {
1451 if (count == null) {
1452 count = Long.valueOf(0);
1453 }
1454
1455 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1456 finderArgs, count);
1457
1458 closeSession(session);
1459 }
1460 }
1461
1462 return count.intValue();
1463 }
1464
1465 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1466 UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1467 UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1468 "containsUser",
1469 new String[] { Long.class.getName(), Long.class.getName() });
1470
1471 public boolean containsUser(long pk, long userPK) throws SystemException {
1472 Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
1473
1474 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1475 finderArgs, this);
1476
1477 if (value == null) {
1478 try {
1479 value = Boolean.valueOf(containsUser.contains(pk, userPK));
1480 }
1481 catch (Exception e) {
1482 throw processException(e);
1483 }
1484 finally {
1485 if (value == null) {
1486 value = Boolean.FALSE;
1487 }
1488
1489 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1490 finderArgs, value);
1491 }
1492 }
1493
1494 return value.booleanValue();
1495 }
1496
1497 public boolean containsUsers(long pk) throws SystemException {
1498 if (getUsersSize(pk) > 0) {
1499 return true;
1500 }
1501 else {
1502 return false;
1503 }
1504 }
1505
1506 public void addUser(long pk, long userPK) throws SystemException {
1507 try {
1508 addUser.add(pk, userPK);
1509 }
1510 catch (Exception e) {
1511 throw processException(e);
1512 }
1513 finally {
1514 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1515 }
1516 }
1517
1518 public void addUser(long pk, com.liferay.portal.model.User user)
1519 throws SystemException {
1520 try {
1521 addUser.add(pk, user.getPrimaryKey());
1522 }
1523 catch (Exception e) {
1524 throw processException(e);
1525 }
1526 finally {
1527 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1528 }
1529 }
1530
1531 public void addUsers(long pk, long[] userPKs) throws SystemException {
1532 try {
1533 for (long userPK : userPKs) {
1534 addUser.add(pk, userPK);
1535 }
1536 }
1537 catch (Exception e) {
1538 throw processException(e);
1539 }
1540 finally {
1541 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1542 }
1543 }
1544
1545 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1546 throws SystemException {
1547 try {
1548 for (com.liferay.portal.model.User user : users) {
1549 addUser.add(pk, user.getPrimaryKey());
1550 }
1551 }
1552 catch (Exception e) {
1553 throw processException(e);
1554 }
1555 finally {
1556 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1557 }
1558 }
1559
1560 public void clearUsers(long pk) throws SystemException {
1561 try {
1562 clearUsers.clear(pk);
1563 }
1564 catch (Exception e) {
1565 throw processException(e);
1566 }
1567 finally {
1568 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1569 }
1570 }
1571
1572 public void removeUser(long pk, long userPK) throws SystemException {
1573 try {
1574 removeUser.remove(pk, userPK);
1575 }
1576 catch (Exception e) {
1577 throw processException(e);
1578 }
1579 finally {
1580 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1581 }
1582 }
1583
1584 public void removeUser(long pk, com.liferay.portal.model.User user)
1585 throws SystemException {
1586 try {
1587 removeUser.remove(pk, user.getPrimaryKey());
1588 }
1589 catch (Exception e) {
1590 throw processException(e);
1591 }
1592 finally {
1593 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1594 }
1595 }
1596
1597 public void removeUsers(long pk, long[] userPKs) throws SystemException {
1598 try {
1599 for (long userPK : userPKs) {
1600 removeUser.remove(pk, userPK);
1601 }
1602 }
1603 catch (Exception e) {
1604 throw processException(e);
1605 }
1606 finally {
1607 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1608 }
1609 }
1610
1611 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1612 throws SystemException {
1613 try {
1614 for (com.liferay.portal.model.User user : users) {
1615 removeUser.remove(pk, user.getPrimaryKey());
1616 }
1617 }
1618 catch (Exception e) {
1619 throw processException(e);
1620 }
1621 finally {
1622 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1623 }
1624 }
1625
1626 public void setUsers(long pk, long[] userPKs) throws SystemException {
1627 try {
1628 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1629
1630 List<com.liferay.portal.model.User> users = getUsers(pk);
1631
1632 for (com.liferay.portal.model.User user : users) {
1633 if (!userPKSet.contains(user.getPrimaryKey())) {
1634 removeUser.remove(pk, user.getPrimaryKey());
1635 }
1636 else {
1637 userPKSet.remove(user.getPrimaryKey());
1638 }
1639 }
1640
1641 for (Long userPK : userPKSet) {
1642 addUser.add(pk, userPK);
1643 }
1644 }
1645 catch (Exception e) {
1646 throw processException(e);
1647 }
1648 finally {
1649 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1650 }
1651 }
1652
1653 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
1654 throws SystemException {
1655 try {
1656 long[] userPKs = new long[users.size()];
1657
1658 for (int i = 0; i < users.size(); i++) {
1659 com.liferay.portal.model.User user = users.get(i);
1660
1661 userPKs[i] = user.getPrimaryKey();
1662 }
1663
1664 setUsers(pk, userPKs);
1665 }
1666 catch (Exception e) {
1667 throw processException(e);
1668 }
1669 finally {
1670 FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1671 }
1672 }
1673
1674 public void afterPropertiesSet() {
1675 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1676 com.liferay.portal.util.PropsUtil.get(
1677 "value.object.listener.com.liferay.portal.model.UserGroup")));
1678
1679 if (listenerClassNames.length > 0) {
1680 try {
1681 List<ModelListener<UserGroup>> listenersList = new ArrayList<ModelListener<UserGroup>>();
1682
1683 for (String listenerClassName : listenerClassNames) {
1684 listenersList.add((ModelListener<UserGroup>)Class.forName(
1685 listenerClassName).newInstance());
1686 }
1687
1688 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1689 }
1690 catch (Exception e) {
1691 _log.error(e);
1692 }
1693 }
1694
1695 containsUser = new ContainsUser(this);
1696
1697 addUser = new AddUser(this);
1698 clearUsers = new ClearUsers(this);
1699 removeUser = new RemoveUser(this);
1700 }
1701
1702 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
1703 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1704 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
1705 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1706 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
1707 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1708 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
1709 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1710 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
1711 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1712 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
1713 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1714 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
1715 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1716 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
1717 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1718 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
1719 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1720 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
1721 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1722 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
1723 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1724 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPrototypePersistence")
1725 protected com.liferay.portal.service.persistence.LayoutPrototypePersistence layoutPrototypePersistence;
1726 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
1727 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1728 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPrototypePersistence")
1729 protected com.liferay.portal.service.persistence.LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1730 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
1731 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1732 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
1733 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1734 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
1735 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1736 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
1737 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1738 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
1739 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1740 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
1741 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1742 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
1743 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1744 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
1745 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1746 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
1747 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1748 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
1749 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1750 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
1751 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1752 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
1753 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1754 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
1755 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1756 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
1757 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1758 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
1759 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1760 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
1761 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1762 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
1763 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1764 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
1765 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1766 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1767 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1768 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
1769 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1770 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
1771 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1772 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
1773 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1774 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
1775 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1776 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
1777 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1778 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
1779 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1780 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
1781 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1782 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1783 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1784 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
1785 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1786 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
1787 protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1788 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
1789 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1790 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
1791 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1792 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
1793 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1794 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
1795 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1796 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
1797 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1798 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
1799 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1800 @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence")
1801 protected com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1802 @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence")
1803 protected com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1804 protected ContainsUser containsUser;
1805 protected AddUser addUser;
1806 protected ClearUsers clearUsers;
1807 protected RemoveUser removeUser;
1808
1809 protected class ContainsUser {
1810 protected ContainsUser(UserGroupPersistenceImpl persistenceImpl) {
1811 super();
1812
1813 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1814 _SQL_CONTAINSUSER,
1815 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1816 }
1817
1818 protected boolean contains(long userGroupId, long userId) {
1819 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1820 new Long(userGroupId), new Long(userId)
1821 });
1822
1823 if (results.size() > 0) {
1824 Integer count = results.get(0);
1825
1826 if (count.intValue() > 0) {
1827 return true;
1828 }
1829 }
1830
1831 return false;
1832 }
1833
1834 private MappingSqlQuery<Integer> _mappingSqlQuery;
1835 }
1836
1837 protected class AddUser {
1838 protected AddUser(UserGroupPersistenceImpl persistenceImpl) {
1839 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1840 "INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)",
1841 new int[] { Types.BIGINT, Types.BIGINT });
1842 _persistenceImpl = persistenceImpl;
1843 }
1844
1845 protected void add(long userGroupId, long userId)
1846 throws SystemException {
1847 if (!_persistenceImpl.containsUser.contains(userGroupId, userId)) {
1848 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1849
1850 for (ModelListener<UserGroup> listener : listeners) {
1851 listener.onBeforeAddAssociation(userGroupId,
1852 com.liferay.portal.model.User.class.getName(), userId);
1853 }
1854
1855 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1856 listener.onBeforeAddAssociation(userId,
1857 UserGroup.class.getName(), userGroupId);
1858 }
1859
1860 _sqlUpdate.update(new Object[] {
1861 new Long(userGroupId), new Long(userId)
1862 });
1863
1864 for (ModelListener<UserGroup> listener : listeners) {
1865 listener.onAfterAddAssociation(userGroupId,
1866 com.liferay.portal.model.User.class.getName(), userId);
1867 }
1868
1869 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1870 listener.onAfterAddAssociation(userId,
1871 UserGroup.class.getName(), userGroupId);
1872 }
1873 }
1874 }
1875
1876 private SqlUpdate _sqlUpdate;
1877 private UserGroupPersistenceImpl _persistenceImpl;
1878 }
1879
1880 protected class ClearUsers {
1881 protected ClearUsers(UserGroupPersistenceImpl persistenceImpl) {
1882 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1883 "DELETE FROM Users_UserGroups WHERE userGroupId = ?",
1884 new int[] { Types.BIGINT });
1885 }
1886
1887 protected void clear(long userGroupId) throws SystemException {
1888 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1889
1890 List<com.liferay.portal.model.User> users = null;
1891
1892 if ((listeners.length > 0) || (userListeners.length > 0)) {
1893 users = getUsers(userGroupId);
1894
1895 for (com.liferay.portal.model.User user : users) {
1896 for (ModelListener<UserGroup> listener : listeners) {
1897 listener.onBeforeRemoveAssociation(userGroupId,
1898 com.liferay.portal.model.User.class.getName(),
1899 user.getPrimaryKey());
1900 }
1901
1902 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1903 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
1904 UserGroup.class.getName(), userGroupId);
1905 }
1906 }
1907 }
1908
1909 _sqlUpdate.update(new Object[] { new Long(userGroupId) });
1910
1911 if ((listeners.length > 0) || (userListeners.length > 0)) {
1912 for (com.liferay.portal.model.User user : users) {
1913 for (ModelListener<UserGroup> listener : listeners) {
1914 listener.onAfterRemoveAssociation(userGroupId,
1915 com.liferay.portal.model.User.class.getName(),
1916 user.getPrimaryKey());
1917 }
1918
1919 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1920 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
1921 UserGroup.class.getName(), userGroupId);
1922 }
1923 }
1924 }
1925 }
1926
1927 private SqlUpdate _sqlUpdate;
1928 }
1929
1930 protected class RemoveUser {
1931 protected RemoveUser(UserGroupPersistenceImpl persistenceImpl) {
1932 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1933 "DELETE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
1934 new int[] { Types.BIGINT, Types.BIGINT });
1935 _persistenceImpl = persistenceImpl;
1936 }
1937
1938 protected void remove(long userGroupId, long userId)
1939 throws SystemException {
1940 if (_persistenceImpl.containsUser.contains(userGroupId, userId)) {
1941 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1942
1943 for (ModelListener<UserGroup> listener : listeners) {
1944 listener.onBeforeRemoveAssociation(userGroupId,
1945 com.liferay.portal.model.User.class.getName(), userId);
1946 }
1947
1948 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1949 listener.onBeforeRemoveAssociation(userId,
1950 UserGroup.class.getName(), userGroupId);
1951 }
1952
1953 _sqlUpdate.update(new Object[] {
1954 new Long(userGroupId), new Long(userId)
1955 });
1956
1957 for (ModelListener<UserGroup> listener : listeners) {
1958 listener.onAfterRemoveAssociation(userGroupId,
1959 com.liferay.portal.model.User.class.getName(), userId);
1960 }
1961
1962 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1963 listener.onAfterRemoveAssociation(userId,
1964 UserGroup.class.getName(), userGroupId);
1965 }
1966 }
1967 }
1968
1969 private SqlUpdate _sqlUpdate;
1970 private UserGroupPersistenceImpl _persistenceImpl;
1971 }
1972
1973 private static final String _SQL_SELECT_USERGROUP = "SELECT userGroup FROM UserGroup userGroup";
1974 private static final String _SQL_SELECT_USERGROUP_WHERE = "SELECT userGroup FROM UserGroup userGroup WHERE ";
1975 private static final String _SQL_COUNT_USERGROUP = "SELECT COUNT(userGroup) FROM UserGroup userGroup";
1976 private static final String _SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(userGroup) FROM UserGroup userGroup WHERE ";
1977 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_UserGroups ON (Users_UserGroups.userId = User_.userId) WHERE (Users_UserGroups.userGroupId = ?)";
1978 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ?";
1979 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?";
1980 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userGroup.companyId = ?";
1981 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "userGroup.companyId = ? AND ";
1982 private static final String _FINDER_COLUMN_C_P_PARENTUSERGROUPID_2 = "userGroup.parentUserGroupId = ?";
1983 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "userGroup.companyId = ? AND ";
1984 private static final String _FINDER_COLUMN_C_N_NAME_1 = "userGroup.name IS NULL";
1985 private static final String _FINDER_COLUMN_C_N_NAME_2 = "userGroup.name = ?";
1986 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(userGroup.name IS NULL OR userGroup.name = ?)";
1987 private static final String _ORDER_BY_ENTITY_ALIAS = "userGroup.";
1988 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroup exists with the primary key ";
1989 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroup exists with the key {";
1990 private static Log _log = LogFactoryUtil.getLog(UserGroupPersistenceImpl.class);
1991}