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