001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchTeamException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028 import com.liferay.portal.kernel.dao.orm.FinderPath;
029 import com.liferay.portal.kernel.dao.orm.Query;
030 import com.liferay.portal.kernel.dao.orm.QueryPos;
031 import com.liferay.portal.kernel.dao.orm.QueryUtil;
032 import com.liferay.portal.kernel.dao.orm.SQLQuery;
033 import com.liferay.portal.kernel.dao.orm.Session;
034 import com.liferay.portal.kernel.exception.SystemException;
035 import com.liferay.portal.kernel.log.Log;
036 import com.liferay.portal.kernel.log.LogFactoryUtil;
037 import com.liferay.portal.kernel.util.GetterUtil;
038 import com.liferay.portal.kernel.util.InstanceFactory;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.SetUtil;
041 import com.liferay.portal.kernel.util.StringBundler;
042 import com.liferay.portal.kernel.util.StringPool;
043 import com.liferay.portal.kernel.util.StringUtil;
044 import com.liferay.portal.kernel.util.UnmodifiableList;
045 import com.liferay.portal.kernel.util.Validator;
046 import com.liferay.portal.model.CacheModel;
047 import com.liferay.portal.model.ModelListener;
048 import com.liferay.portal.model.Team;
049 import com.liferay.portal.model.impl.TeamImpl;
050 import com.liferay.portal.model.impl.TeamModelImpl;
051 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
052 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
053
054 import java.io.Serializable;
055
056 import java.util.ArrayList;
057 import java.util.Collections;
058 import java.util.List;
059 import java.util.Set;
060
061
073 public class TeamPersistenceImpl extends BasePersistenceImpl<Team>
074 implements TeamPersistence {
075
080 public static final String FINDER_CLASS_NAME_ENTITY = TeamImpl.class.getName();
081 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List1";
083 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List2";
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
086 TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
089 TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
092 TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
095 TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
097 new String[] {
098 Long.class.getName(),
099
100 Integer.class.getName(), Integer.class.getName(),
101 OrderByComparator.class.getName()
102 });
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
104 new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
105 TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
107 new String[] { Long.class.getName() },
108 TeamModelImpl.GROUPID_COLUMN_BITMASK |
109 TeamModelImpl.NAME_COLUMN_BITMASK);
110 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
111 TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
113 new String[] { Long.class.getName() });
114
115
122 public List<Team> findByGroupId(long groupId) throws SystemException {
123 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124 }
125
126
139 public List<Team> findByGroupId(long groupId, int start, int end)
140 throws SystemException {
141 return findByGroupId(groupId, start, end, null);
142 }
143
144
158 public List<Team> findByGroupId(long groupId, int start, int end,
159 OrderByComparator orderByComparator) throws SystemException {
160 boolean pagination = true;
161 FinderPath finderPath = null;
162 Object[] finderArgs = null;
163
164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165 (orderByComparator == null)) {
166 pagination = false;
167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
168 finderArgs = new Object[] { groupId };
169 }
170 else {
171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
172 finderArgs = new Object[] { groupId, start, end, orderByComparator };
173 }
174
175 List<Team> list = (List<Team>)FinderCacheUtil.getResult(finderPath,
176 finderArgs, this);
177
178 if ((list != null) && !list.isEmpty()) {
179 for (Team team : list) {
180 if ((groupId != team.getGroupId())) {
181 list = null;
182
183 break;
184 }
185 }
186 }
187
188 if (list == null) {
189 StringBundler query = null;
190
191 if (orderByComparator != null) {
192 query = new StringBundler(3 +
193 (orderByComparator.getOrderByFields().length * 3));
194 }
195 else {
196 query = new StringBundler(3);
197 }
198
199 query.append(_SQL_SELECT_TEAM_WHERE);
200
201 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
202
203 if (orderByComparator != null) {
204 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
205 orderByComparator);
206 }
207 else
208 if (pagination) {
209 query.append(TeamModelImpl.ORDER_BY_JPQL);
210 }
211
212 String sql = query.toString();
213
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 Query q = session.createQuery(sql);
220
221 QueryPos qPos = QueryPos.getInstance(q);
222
223 qPos.add(groupId);
224
225 if (!pagination) {
226 list = (List<Team>)QueryUtil.list(q, getDialect(), start,
227 end, false);
228
229 Collections.sort(list);
230
231 list = new UnmodifiableList<Team>(list);
232 }
233 else {
234 list = (List<Team>)QueryUtil.list(q, getDialect(), start,
235 end);
236 }
237
238 cacheResult(list);
239
240 FinderCacheUtil.putResult(finderPath, finderArgs, list);
241 }
242 catch (Exception e) {
243 FinderCacheUtil.removeResult(finderPath, finderArgs);
244
245 throw processException(e);
246 }
247 finally {
248 closeSession(session);
249 }
250 }
251
252 return list;
253 }
254
255
264 public Team findByGroupId_First(long groupId,
265 OrderByComparator orderByComparator)
266 throws NoSuchTeamException, SystemException {
267 Team team = fetchByGroupId_First(groupId, orderByComparator);
268
269 if (team != null) {
270 return team;
271 }
272
273 StringBundler msg = new StringBundler(4);
274
275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
276
277 msg.append("groupId=");
278 msg.append(groupId);
279
280 msg.append(StringPool.CLOSE_CURLY_BRACE);
281
282 throw new NoSuchTeamException(msg.toString());
283 }
284
285
293 public Team fetchByGroupId_First(long groupId,
294 OrderByComparator orderByComparator) throws SystemException {
295 List<Team> list = findByGroupId(groupId, 0, 1, orderByComparator);
296
297 if (!list.isEmpty()) {
298 return list.get(0);
299 }
300
301 return null;
302 }
303
304
313 public Team findByGroupId_Last(long groupId,
314 OrderByComparator orderByComparator)
315 throws NoSuchTeamException, SystemException {
316 Team team = fetchByGroupId_Last(groupId, orderByComparator);
317
318 if (team != null) {
319 return team;
320 }
321
322 StringBundler msg = new StringBundler(4);
323
324 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
325
326 msg.append("groupId=");
327 msg.append(groupId);
328
329 msg.append(StringPool.CLOSE_CURLY_BRACE);
330
331 throw new NoSuchTeamException(msg.toString());
332 }
333
334
342 public Team fetchByGroupId_Last(long groupId,
343 OrderByComparator orderByComparator) throws SystemException {
344 int count = countByGroupId(groupId);
345
346 List<Team> list = findByGroupId(groupId, count - 1, count,
347 orderByComparator);
348
349 if (!list.isEmpty()) {
350 return list.get(0);
351 }
352
353 return null;
354 }
355
356
366 public Team[] findByGroupId_PrevAndNext(long teamId, long groupId,
367 OrderByComparator orderByComparator)
368 throws NoSuchTeamException, SystemException {
369 Team team = findByPrimaryKey(teamId);
370
371 Session session = null;
372
373 try {
374 session = openSession();
375
376 Team[] array = new TeamImpl[3];
377
378 array[0] = getByGroupId_PrevAndNext(session, team, groupId,
379 orderByComparator, true);
380
381 array[1] = team;
382
383 array[2] = getByGroupId_PrevAndNext(session, team, groupId,
384 orderByComparator, false);
385
386 return array;
387 }
388 catch (Exception e) {
389 throw processException(e);
390 }
391 finally {
392 closeSession(session);
393 }
394 }
395
396 protected Team getByGroupId_PrevAndNext(Session session, Team team,
397 long groupId, OrderByComparator orderByComparator, boolean previous) {
398 StringBundler query = null;
399
400 if (orderByComparator != null) {
401 query = new StringBundler(6 +
402 (orderByComparator.getOrderByFields().length * 6));
403 }
404 else {
405 query = new StringBundler(3);
406 }
407
408 query.append(_SQL_SELECT_TEAM_WHERE);
409
410 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
411
412 if (orderByComparator != null) {
413 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
414
415 if (orderByConditionFields.length > 0) {
416 query.append(WHERE_AND);
417 }
418
419 for (int i = 0; i < orderByConditionFields.length; i++) {
420 query.append(_ORDER_BY_ENTITY_ALIAS);
421 query.append(orderByConditionFields[i]);
422
423 if ((i + 1) < orderByConditionFields.length) {
424 if (orderByComparator.isAscending() ^ previous) {
425 query.append(WHERE_GREATER_THAN_HAS_NEXT);
426 }
427 else {
428 query.append(WHERE_LESSER_THAN_HAS_NEXT);
429 }
430 }
431 else {
432 if (orderByComparator.isAscending() ^ previous) {
433 query.append(WHERE_GREATER_THAN);
434 }
435 else {
436 query.append(WHERE_LESSER_THAN);
437 }
438 }
439 }
440
441 query.append(ORDER_BY_CLAUSE);
442
443 String[] orderByFields = orderByComparator.getOrderByFields();
444
445 for (int i = 0; i < orderByFields.length; i++) {
446 query.append(_ORDER_BY_ENTITY_ALIAS);
447 query.append(orderByFields[i]);
448
449 if ((i + 1) < orderByFields.length) {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(ORDER_BY_ASC_HAS_NEXT);
452 }
453 else {
454 query.append(ORDER_BY_DESC_HAS_NEXT);
455 }
456 }
457 else {
458 if (orderByComparator.isAscending() ^ previous) {
459 query.append(ORDER_BY_ASC);
460 }
461 else {
462 query.append(ORDER_BY_DESC);
463 }
464 }
465 }
466 }
467 else {
468 query.append(TeamModelImpl.ORDER_BY_JPQL);
469 }
470
471 String sql = query.toString();
472
473 Query q = session.createQuery(sql);
474
475 q.setFirstResult(0);
476 q.setMaxResults(2);
477
478 QueryPos qPos = QueryPos.getInstance(q);
479
480 qPos.add(groupId);
481
482 if (orderByComparator != null) {
483 Object[] values = orderByComparator.getOrderByConditionValues(team);
484
485 for (Object value : values) {
486 qPos.add(value);
487 }
488 }
489
490 List<Team> list = q.list();
491
492 if (list.size() == 2) {
493 return list.get(1);
494 }
495 else {
496 return null;
497 }
498 }
499
500
507 public List<Team> filterFindByGroupId(long groupId)
508 throws SystemException {
509 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
510 QueryUtil.ALL_POS, null);
511 }
512
513
526 public List<Team> filterFindByGroupId(long groupId, int start, int end)
527 throws SystemException {
528 return filterFindByGroupId(groupId, start, end, null);
529 }
530
531
545 public List<Team> filterFindByGroupId(long groupId, int start, int end,
546 OrderByComparator orderByComparator) throws SystemException {
547 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
548 return findByGroupId(groupId, start, end, orderByComparator);
549 }
550
551 StringBundler query = null;
552
553 if (orderByComparator != null) {
554 query = new StringBundler(3 +
555 (orderByComparator.getOrderByFields().length * 3));
556 }
557 else {
558 query = new StringBundler(3);
559 }
560
561 if (getDB().isSupportsInlineDistinct()) {
562 query.append(_FILTER_SQL_SELECT_TEAM_WHERE);
563 }
564 else {
565 query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1);
566 }
567
568 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
569
570 if (!getDB().isSupportsInlineDistinct()) {
571 query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2);
572 }
573
574 if (orderByComparator != null) {
575 if (getDB().isSupportsInlineDistinct()) {
576 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
577 orderByComparator);
578 }
579 else {
580 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
581 orderByComparator);
582 }
583 }
584 else {
585 if (getDB().isSupportsInlineDistinct()) {
586 query.append(TeamModelImpl.ORDER_BY_JPQL);
587 }
588 else {
589 query.append(TeamModelImpl.ORDER_BY_SQL);
590 }
591 }
592
593 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
594 Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
595 groupId);
596
597 Session session = null;
598
599 try {
600 session = openSession();
601
602 SQLQuery q = session.createSQLQuery(sql);
603
604 if (getDB().isSupportsInlineDistinct()) {
605 q.addEntity(_FILTER_ENTITY_ALIAS, TeamImpl.class);
606 }
607 else {
608 q.addEntity(_FILTER_ENTITY_TABLE, TeamImpl.class);
609 }
610
611 QueryPos qPos = QueryPos.getInstance(q);
612
613 qPos.add(groupId);
614
615 return (List<Team>)QueryUtil.list(q, getDialect(), start, end);
616 }
617 catch (Exception e) {
618 throw processException(e);
619 }
620 finally {
621 closeSession(session);
622 }
623 }
624
625
635 public Team[] filterFindByGroupId_PrevAndNext(long teamId, long groupId,
636 OrderByComparator orderByComparator)
637 throws NoSuchTeamException, SystemException {
638 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
639 return findByGroupId_PrevAndNext(teamId, groupId, orderByComparator);
640 }
641
642 Team team = findByPrimaryKey(teamId);
643
644 Session session = null;
645
646 try {
647 session = openSession();
648
649 Team[] array = new TeamImpl[3];
650
651 array[0] = filterGetByGroupId_PrevAndNext(session, team, groupId,
652 orderByComparator, true);
653
654 array[1] = team;
655
656 array[2] = filterGetByGroupId_PrevAndNext(session, team, groupId,
657 orderByComparator, false);
658
659 return array;
660 }
661 catch (Exception e) {
662 throw processException(e);
663 }
664 finally {
665 closeSession(session);
666 }
667 }
668
669 protected Team filterGetByGroupId_PrevAndNext(Session session, Team team,
670 long groupId, OrderByComparator orderByComparator, boolean previous) {
671 StringBundler query = null;
672
673 if (orderByComparator != null) {
674 query = new StringBundler(6 +
675 (orderByComparator.getOrderByFields().length * 6));
676 }
677 else {
678 query = new StringBundler(3);
679 }
680
681 if (getDB().isSupportsInlineDistinct()) {
682 query.append(_FILTER_SQL_SELECT_TEAM_WHERE);
683 }
684 else {
685 query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1);
686 }
687
688 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
689
690 if (!getDB().isSupportsInlineDistinct()) {
691 query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2);
692 }
693
694 if (orderByComparator != null) {
695 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
696
697 if (orderByConditionFields.length > 0) {
698 query.append(WHERE_AND);
699 }
700
701 for (int i = 0; i < orderByConditionFields.length; i++) {
702 if (getDB().isSupportsInlineDistinct()) {
703 query.append(_ORDER_BY_ENTITY_ALIAS);
704 }
705 else {
706 query.append(_ORDER_BY_ENTITY_TABLE);
707 }
708
709 query.append(orderByConditionFields[i]);
710
711 if ((i + 1) < orderByConditionFields.length) {
712 if (orderByComparator.isAscending() ^ previous) {
713 query.append(WHERE_GREATER_THAN_HAS_NEXT);
714 }
715 else {
716 query.append(WHERE_LESSER_THAN_HAS_NEXT);
717 }
718 }
719 else {
720 if (orderByComparator.isAscending() ^ previous) {
721 query.append(WHERE_GREATER_THAN);
722 }
723 else {
724 query.append(WHERE_LESSER_THAN);
725 }
726 }
727 }
728
729 query.append(ORDER_BY_CLAUSE);
730
731 String[] orderByFields = orderByComparator.getOrderByFields();
732
733 for (int i = 0; i < orderByFields.length; i++) {
734 if (getDB().isSupportsInlineDistinct()) {
735 query.append(_ORDER_BY_ENTITY_ALIAS);
736 }
737 else {
738 query.append(_ORDER_BY_ENTITY_TABLE);
739 }
740
741 query.append(orderByFields[i]);
742
743 if ((i + 1) < orderByFields.length) {
744 if (orderByComparator.isAscending() ^ previous) {
745 query.append(ORDER_BY_ASC_HAS_NEXT);
746 }
747 else {
748 query.append(ORDER_BY_DESC_HAS_NEXT);
749 }
750 }
751 else {
752 if (orderByComparator.isAscending() ^ previous) {
753 query.append(ORDER_BY_ASC);
754 }
755 else {
756 query.append(ORDER_BY_DESC);
757 }
758 }
759 }
760 }
761 else {
762 if (getDB().isSupportsInlineDistinct()) {
763 query.append(TeamModelImpl.ORDER_BY_JPQL);
764 }
765 else {
766 query.append(TeamModelImpl.ORDER_BY_SQL);
767 }
768 }
769
770 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
771 Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
772 groupId);
773
774 SQLQuery q = session.createSQLQuery(sql);
775
776 q.setFirstResult(0);
777 q.setMaxResults(2);
778
779 if (getDB().isSupportsInlineDistinct()) {
780 q.addEntity(_FILTER_ENTITY_ALIAS, TeamImpl.class);
781 }
782 else {
783 q.addEntity(_FILTER_ENTITY_TABLE, TeamImpl.class);
784 }
785
786 QueryPos qPos = QueryPos.getInstance(q);
787
788 qPos.add(groupId);
789
790 if (orderByComparator != null) {
791 Object[] values = orderByComparator.getOrderByConditionValues(team);
792
793 for (Object value : values) {
794 qPos.add(value);
795 }
796 }
797
798 List<Team> list = q.list();
799
800 if (list.size() == 2) {
801 return list.get(1);
802 }
803 else {
804 return null;
805 }
806 }
807
808
814 public void removeByGroupId(long groupId) throws SystemException {
815 for (Team team : findByGroupId(groupId, QueryUtil.ALL_POS,
816 QueryUtil.ALL_POS, null)) {
817 remove(team);
818 }
819 }
820
821
828 public int countByGroupId(long groupId) throws SystemException {
829 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
830
831 Object[] finderArgs = new Object[] { groupId };
832
833 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
834 this);
835
836 if (count == null) {
837 StringBundler query = new StringBundler(2);
838
839 query.append(_SQL_COUNT_TEAM_WHERE);
840
841 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
842
843 String sql = query.toString();
844
845 Session session = null;
846
847 try {
848 session = openSession();
849
850 Query q = session.createQuery(sql);
851
852 QueryPos qPos = QueryPos.getInstance(q);
853
854 qPos.add(groupId);
855
856 count = (Long)q.uniqueResult();
857
858 FinderCacheUtil.putResult(finderPath, finderArgs, count);
859 }
860 catch (Exception e) {
861 FinderCacheUtil.removeResult(finderPath, finderArgs);
862
863 throw processException(e);
864 }
865 finally {
866 closeSession(session);
867 }
868 }
869
870 return count.intValue();
871 }
872
873
880 public int filterCountByGroupId(long groupId) throws SystemException {
881 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
882 return countByGroupId(groupId);
883 }
884
885 StringBundler query = new StringBundler(2);
886
887 query.append(_FILTER_SQL_COUNT_TEAM_WHERE);
888
889 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
890
891 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
892 Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
893 groupId);
894
895 Session session = null;
896
897 try {
898 session = openSession();
899
900 SQLQuery q = session.createSQLQuery(sql);
901
902 q.addScalar(COUNT_COLUMN_NAME,
903 com.liferay.portal.kernel.dao.orm.Type.LONG);
904
905 QueryPos qPos = QueryPos.getInstance(q);
906
907 qPos.add(groupId);
908
909 Long count = (Long)q.uniqueResult();
910
911 return count.intValue();
912 }
913 catch (Exception e) {
914 throw processException(e);
915 }
916 finally {
917 closeSession(session);
918 }
919 }
920
921 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "team.groupId = ?";
922 public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
923 TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
924 FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
925 new String[] { Long.class.getName(), String.class.getName() },
926 TeamModelImpl.GROUPID_COLUMN_BITMASK |
927 TeamModelImpl.NAME_COLUMN_BITMASK);
928 public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
929 TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
930 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
931 new String[] { Long.class.getName(), String.class.getName() });
932
933
942 public Team findByG_N(long groupId, String name)
943 throws NoSuchTeamException, SystemException {
944 Team team = fetchByG_N(groupId, name);
945
946 if (team == null) {
947 StringBundler msg = new StringBundler(6);
948
949 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
950
951 msg.append("groupId=");
952 msg.append(groupId);
953
954 msg.append(", name=");
955 msg.append(name);
956
957 msg.append(StringPool.CLOSE_CURLY_BRACE);
958
959 if (_log.isWarnEnabled()) {
960 _log.warn(msg.toString());
961 }
962
963 throw new NoSuchTeamException(msg.toString());
964 }
965
966 return team;
967 }
968
969
977 public Team fetchByG_N(long groupId, String name) throws SystemException {
978 return fetchByG_N(groupId, name, true);
979 }
980
981
990 public Team fetchByG_N(long groupId, String name, boolean retrieveFromCache)
991 throws SystemException {
992 Object[] finderArgs = new Object[] { groupId, name };
993
994 Object result = null;
995
996 if (retrieveFromCache) {
997 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
998 finderArgs, this);
999 }
1000
1001 if (result instanceof Team) {
1002 Team team = (Team)result;
1003
1004 if ((groupId != team.getGroupId()) ||
1005 !Validator.equals(name, team.getName())) {
1006 result = null;
1007 }
1008 }
1009
1010 if (result == null) {
1011 StringBundler query = new StringBundler(4);
1012
1013 query.append(_SQL_SELECT_TEAM_WHERE);
1014
1015 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1016
1017 if (name == null) {
1018 query.append(_FINDER_COLUMN_G_N_NAME_1);
1019 }
1020 else {
1021 if (name.equals(StringPool.BLANK)) {
1022 query.append(_FINDER_COLUMN_G_N_NAME_3);
1023 }
1024 else {
1025 query.append(_FINDER_COLUMN_G_N_NAME_2);
1026 }
1027 }
1028
1029 String sql = query.toString();
1030
1031 Session session = null;
1032
1033 try {
1034 session = openSession();
1035
1036 Query q = session.createQuery(sql);
1037
1038 QueryPos qPos = QueryPos.getInstance(q);
1039
1040 qPos.add(groupId);
1041
1042 if (name != null) {
1043 qPos.add(name);
1044 }
1045
1046 List<Team> list = q.list();
1047
1048 if (list.isEmpty()) {
1049 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1050 finderArgs, list);
1051 }
1052 else {
1053 Team team = list.get(0);
1054
1055 result = team;
1056
1057 cacheResult(team);
1058
1059 if ((team.getGroupId() != groupId) ||
1060 (team.getName() == null) ||
1061 !team.getName().equals(name)) {
1062 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1063 finderArgs, team);
1064 }
1065 }
1066 }
1067 catch (Exception e) {
1068 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
1069 finderArgs);
1070
1071 throw processException(e);
1072 }
1073 finally {
1074 closeSession(session);
1075 }
1076 }
1077
1078 if (result instanceof List<?>) {
1079 return null;
1080 }
1081 else {
1082 return (Team)result;
1083 }
1084 }
1085
1086
1094 public Team removeByG_N(long groupId, String name)
1095 throws NoSuchTeamException, SystemException {
1096 Team team = findByG_N(groupId, name);
1097
1098 return remove(team);
1099 }
1100
1101
1109 public int countByG_N(long groupId, String name) throws SystemException {
1110 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
1111
1112 Object[] finderArgs = new Object[] { groupId, name };
1113
1114 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1115 this);
1116
1117 if (count == null) {
1118 StringBundler query = new StringBundler(3);
1119
1120 query.append(_SQL_COUNT_TEAM_WHERE);
1121
1122 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1123
1124 if (name == null) {
1125 query.append(_FINDER_COLUMN_G_N_NAME_1);
1126 }
1127 else {
1128 if (name.equals(StringPool.BLANK)) {
1129 query.append(_FINDER_COLUMN_G_N_NAME_3);
1130 }
1131 else {
1132 query.append(_FINDER_COLUMN_G_N_NAME_2);
1133 }
1134 }
1135
1136 String sql = query.toString();
1137
1138 Session session = null;
1139
1140 try {
1141 session = openSession();
1142
1143 Query q = session.createQuery(sql);
1144
1145 QueryPos qPos = QueryPos.getInstance(q);
1146
1147 qPos.add(groupId);
1148
1149 if (name != null) {
1150 qPos.add(name);
1151 }
1152
1153 count = (Long)q.uniqueResult();
1154
1155 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1156 }
1157 catch (Exception e) {
1158 FinderCacheUtil.removeResult(finderPath, finderArgs);
1159
1160 throw processException(e);
1161 }
1162 finally {
1163 closeSession(session);
1164 }
1165 }
1166
1167 return count.intValue();
1168 }
1169
1170 private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "team.groupId = ? AND ";
1171 private static final String _FINDER_COLUMN_G_N_NAME_1 = "team.name IS NULL";
1172 private static final String _FINDER_COLUMN_G_N_NAME_2 = "team.name = ?";
1173 private static final String _FINDER_COLUMN_G_N_NAME_3 = "(team.name IS NULL OR team.name = ?)";
1174
1175
1180 public void cacheResult(Team team) {
1181 EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1182 TeamImpl.class, team.getPrimaryKey(), team);
1183
1184 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1185 new Object[] { Long.valueOf(team.getGroupId()), team.getName() },
1186 team);
1187
1188 team.resetOriginalValues();
1189 }
1190
1191
1196 public void cacheResult(List<Team> teams) {
1197 for (Team team : teams) {
1198 if (EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1199 TeamImpl.class, team.getPrimaryKey()) == null) {
1200 cacheResult(team);
1201 }
1202 else {
1203 team.resetOriginalValues();
1204 }
1205 }
1206 }
1207
1208
1215 @Override
1216 public void clearCache() {
1217 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1218 CacheRegistryUtil.clear(TeamImpl.class.getName());
1219 }
1220
1221 EntityCacheUtil.clearCache(TeamImpl.class.getName());
1222
1223 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1226 }
1227
1228
1235 @Override
1236 public void clearCache(Team team) {
1237 EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1238 TeamImpl.class, team.getPrimaryKey());
1239
1240 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1241 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1242
1243 clearUniqueFindersCache(team);
1244 }
1245
1246 @Override
1247 public void clearCache(List<Team> teams) {
1248 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1249 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1250
1251 for (Team team : teams) {
1252 EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1253 TeamImpl.class, team.getPrimaryKey());
1254
1255 clearUniqueFindersCache(team);
1256 }
1257 }
1258
1259 protected void cacheUniqueFindersCache(Team team) {
1260 if (team.isNew()) {
1261 Object[] args = new Object[] {
1262 Long.valueOf(team.getGroupId()),
1263
1264 team.getName()
1265 };
1266
1267 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
1268 Long.valueOf(1));
1269 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args, team);
1270 }
1271 else {
1272 TeamModelImpl teamModelImpl = (TeamModelImpl)team;
1273
1274 if ((teamModelImpl.getColumnBitmask() &
1275 FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
1276 Object[] args = new Object[] {
1277 Long.valueOf(team.getGroupId()),
1278
1279 team.getName()
1280 };
1281
1282 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, args,
1283 Long.valueOf(1));
1284 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N, args, team);
1285 }
1286 }
1287 }
1288
1289 protected void clearUniqueFindersCache(Team team) {
1290 TeamModelImpl teamModelImpl = (TeamModelImpl)team;
1291
1292 Object[] args = new Object[] {
1293 Long.valueOf(team.getGroupId()),
1294
1295 team.getName()
1296 };
1297
1298 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
1299 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
1300
1301 if ((teamModelImpl.getColumnBitmask() &
1302 FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
1303 args = new Object[] {
1304 Long.valueOf(teamModelImpl.getOriginalGroupId()),
1305
1306 teamModelImpl.getOriginalName()
1307 };
1308
1309 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
1310 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
1311 }
1312 }
1313
1314
1320 public Team create(long teamId) {
1321 Team team = new TeamImpl();
1322
1323 team.setNew(true);
1324 team.setPrimaryKey(teamId);
1325
1326 return team;
1327 }
1328
1329
1337 public Team remove(long teamId) throws NoSuchTeamException, SystemException {
1338 return remove(Long.valueOf(teamId));
1339 }
1340
1341
1349 @Override
1350 public Team remove(Serializable primaryKey)
1351 throws NoSuchTeamException, SystemException {
1352 Session session = null;
1353
1354 try {
1355 session = openSession();
1356
1357 Team team = (Team)session.get(TeamImpl.class, primaryKey);
1358
1359 if (team == null) {
1360 if (_log.isWarnEnabled()) {
1361 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1362 }
1363
1364 throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1365 primaryKey);
1366 }
1367
1368 return remove(team);
1369 }
1370 catch (NoSuchTeamException nsee) {
1371 throw nsee;
1372 }
1373 catch (Exception e) {
1374 throw processException(e);
1375 }
1376 finally {
1377 closeSession(session);
1378 }
1379 }
1380
1381 @Override
1382 protected Team removeImpl(Team team) throws SystemException {
1383 team = toUnwrappedModel(team);
1384
1385 try {
1386 clearUsers.clear(team.getPrimaryKey());
1387 }
1388 catch (Exception e) {
1389 throw processException(e);
1390 }
1391 finally {
1392 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1393 }
1394
1395 try {
1396 clearUserGroups.clear(team.getPrimaryKey());
1397 }
1398 catch (Exception e) {
1399 throw processException(e);
1400 }
1401 finally {
1402 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
1403 }
1404
1405 Session session = null;
1406
1407 try {
1408 session = openSession();
1409
1410 if (!session.contains(team)) {
1411 team = (Team)session.get(TeamImpl.class, team.getPrimaryKeyObj());
1412 }
1413
1414 if (team != null) {
1415 session.delete(team);
1416 }
1417 }
1418 catch (Exception e) {
1419 throw processException(e);
1420 }
1421 finally {
1422 closeSession(session);
1423 }
1424
1425 if (team != null) {
1426 clearCache(team);
1427 }
1428
1429 return team;
1430 }
1431
1432 @Override
1433 public Team updateImpl(com.liferay.portal.model.Team team)
1434 throws SystemException {
1435 team = toUnwrappedModel(team);
1436
1437 boolean isNew = team.isNew();
1438
1439 TeamModelImpl teamModelImpl = (TeamModelImpl)team;
1440
1441 Session session = null;
1442
1443 try {
1444 session = openSession();
1445
1446 if (team.isNew()) {
1447 session.save(team);
1448
1449 team.setNew(false);
1450 }
1451 else {
1452 session.merge(team);
1453 }
1454 }
1455 catch (Exception e) {
1456 throw processException(e);
1457 }
1458 finally {
1459 closeSession(session);
1460 }
1461
1462 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1463
1464 if (isNew || !TeamModelImpl.COLUMN_BITMASK_ENABLED) {
1465 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1466 }
1467
1468 else {
1469 if ((teamModelImpl.getColumnBitmask() &
1470 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1471 Object[] args = new Object[] {
1472 Long.valueOf(teamModelImpl.getOriginalGroupId())
1473 };
1474
1475 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1476 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1477 args);
1478
1479 args = new Object[] { Long.valueOf(teamModelImpl.getGroupId()) };
1480
1481 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1482 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1483 args);
1484 }
1485 }
1486
1487 EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1488 TeamImpl.class, team.getPrimaryKey(), team);
1489
1490 clearUniqueFindersCache(team);
1491 cacheUniqueFindersCache(team);
1492
1493 return team;
1494 }
1495
1496 protected Team toUnwrappedModel(Team team) {
1497 if (team instanceof TeamImpl) {
1498 return team;
1499 }
1500
1501 TeamImpl teamImpl = new TeamImpl();
1502
1503 teamImpl.setNew(team.isNew());
1504 teamImpl.setPrimaryKey(team.getPrimaryKey());
1505
1506 teamImpl.setTeamId(team.getTeamId());
1507 teamImpl.setCompanyId(team.getCompanyId());
1508 teamImpl.setUserId(team.getUserId());
1509 teamImpl.setUserName(team.getUserName());
1510 teamImpl.setCreateDate(team.getCreateDate());
1511 teamImpl.setModifiedDate(team.getModifiedDate());
1512 teamImpl.setGroupId(team.getGroupId());
1513 teamImpl.setName(team.getName());
1514 teamImpl.setDescription(team.getDescription());
1515
1516 return teamImpl;
1517 }
1518
1519
1527 @Override
1528 public Team findByPrimaryKey(Serializable primaryKey)
1529 throws NoSuchModelException, SystemException {
1530 return findByPrimaryKey(((Long)primaryKey).longValue());
1531 }
1532
1533
1541 public Team findByPrimaryKey(long teamId)
1542 throws NoSuchTeamException, SystemException {
1543 Team team = fetchByPrimaryKey(teamId);
1544
1545 if (team == null) {
1546 if (_log.isWarnEnabled()) {
1547 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + teamId);
1548 }
1549
1550 throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1551 teamId);
1552 }
1553
1554 return team;
1555 }
1556
1557
1564 @Override
1565 public Team fetchByPrimaryKey(Serializable primaryKey)
1566 throws SystemException {
1567 return fetchByPrimaryKey(((Long)primaryKey).longValue());
1568 }
1569
1570
1577 public Team fetchByPrimaryKey(long teamId) throws SystemException {
1578 Team team = (Team)EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1579 TeamImpl.class, teamId);
1580
1581 if (team == _nullTeam) {
1582 return null;
1583 }
1584
1585 if (team == null) {
1586 Session session = null;
1587
1588 try {
1589 session = openSession();
1590
1591 team = (Team)session.get(TeamImpl.class, Long.valueOf(teamId));
1592
1593 if (team != null) {
1594 cacheResult(team);
1595 }
1596 else {
1597 EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1598 TeamImpl.class, teamId, _nullTeam);
1599 }
1600 }
1601 catch (Exception e) {
1602 EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
1603 TeamImpl.class, teamId);
1604
1605 throw processException(e);
1606 }
1607 finally {
1608 closeSession(session);
1609 }
1610 }
1611
1612 return team;
1613 }
1614
1615
1621 public List<Team> findAll() throws SystemException {
1622 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1623 }
1624
1625
1637 public List<Team> findAll(int start, int end) throws SystemException {
1638 return findAll(start, end, null);
1639 }
1640
1641
1654 public List<Team> findAll(int start, int end,
1655 OrderByComparator orderByComparator) throws SystemException {
1656 boolean pagination = true;
1657 FinderPath finderPath = null;
1658 Object[] finderArgs = null;
1659
1660 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1661 (orderByComparator == null)) {
1662 pagination = false;
1663 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1664 finderArgs = FINDER_ARGS_EMPTY;
1665 }
1666 else {
1667 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1668 finderArgs = new Object[] { start, end, orderByComparator };
1669 }
1670
1671 List<Team> list = (List<Team>)FinderCacheUtil.getResult(finderPath,
1672 finderArgs, this);
1673
1674 if (list == null) {
1675 StringBundler query = null;
1676 String sql = null;
1677
1678 if (orderByComparator != null) {
1679 query = new StringBundler(2 +
1680 (orderByComparator.getOrderByFields().length * 3));
1681
1682 query.append(_SQL_SELECT_TEAM);
1683
1684 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1685 orderByComparator);
1686
1687 sql = query.toString();
1688 }
1689 else {
1690 sql = _SQL_SELECT_TEAM;
1691
1692 if (pagination) {
1693 sql = sql.concat(TeamModelImpl.ORDER_BY_JPQL);
1694 }
1695 }
1696
1697 Session session = null;
1698
1699 try {
1700 session = openSession();
1701
1702 Query q = session.createQuery(sql);
1703
1704 if (!pagination) {
1705 list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1706 end, false);
1707
1708 Collections.sort(list);
1709
1710 list = new UnmodifiableList<Team>(list);
1711 }
1712 else {
1713 list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1714 end);
1715 }
1716
1717 cacheResult(list);
1718
1719 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1720 }
1721 catch (Exception e) {
1722 FinderCacheUtil.removeResult(finderPath, finderArgs);
1723
1724 throw processException(e);
1725 }
1726 finally {
1727 closeSession(session);
1728 }
1729 }
1730
1731 return list;
1732 }
1733
1734
1739 public void removeAll() throws SystemException {
1740 for (Team team : findAll()) {
1741 remove(team);
1742 }
1743 }
1744
1745
1751 public int countAll() throws SystemException {
1752 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1753 FINDER_ARGS_EMPTY, this);
1754
1755 if (count == null) {
1756 Session session = null;
1757
1758 try {
1759 session = openSession();
1760
1761 Query q = session.createQuery(_SQL_COUNT_TEAM);
1762
1763 count = (Long)q.uniqueResult();
1764
1765 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1766 FINDER_ARGS_EMPTY, count);
1767 }
1768 catch (Exception e) {
1769 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1770 FINDER_ARGS_EMPTY);
1771
1772 throw processException(e);
1773 }
1774 finally {
1775 closeSession(session);
1776 }
1777 }
1778
1779 return count.intValue();
1780 }
1781
1782
1789 public List<com.liferay.portal.model.User> getUsers(long pk)
1790 throws SystemException {
1791 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1792 }
1793
1794
1807 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1808 int end) throws SystemException {
1809 return getUsers(pk, start, end, null);
1810 }
1811
1812 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1813 TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
1814 com.liferay.portal.model.impl.UserImpl.class,
1815 TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsers",
1816 new String[] {
1817 Long.class.getName(), Integer.class.getName(),
1818 Integer.class.getName(), OrderByComparator.class.getName()
1819 });
1820
1821 static {
1822 FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
1823 }
1824
1825
1839 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1840 int end, OrderByComparator orderByComparator) throws SystemException {
1841 boolean pagination = true;
1842 Object[] finderArgs = null;
1843
1844 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1845 (orderByComparator == null)) {
1846 pagination = false;
1847 finderArgs = new Object[] { pk };
1848 }
1849 else {
1850 finderArgs = new Object[] { pk, start, end, orderByComparator };
1851 }
1852
1853 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1854 finderArgs, this);
1855
1856 if (list == null) {
1857 Session session = null;
1858
1859 try {
1860 session = openSession();
1861
1862 String sql = null;
1863
1864 if (orderByComparator != null) {
1865 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1866 .concat(orderByComparator.getOrderBy());
1867 }
1868 else {
1869 sql = _SQL_GETUSERS;
1870
1871 if (pagination) {
1872 sql = sql.concat(com.liferay.portal.model.impl.UserModelImpl.ORDER_BY_SQL);
1873 }
1874 }
1875
1876 SQLQuery q = session.createSQLQuery(sql);
1877
1878 q.addEntity("User_",
1879 com.liferay.portal.model.impl.UserImpl.class);
1880
1881 QueryPos qPos = QueryPos.getInstance(q);
1882
1883 qPos.add(pk);
1884
1885 if (!pagination) {
1886 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1887 getDialect(), start, end, false);
1888
1889 Collections.sort(list);
1890
1891 list = new UnmodifiableList<com.liferay.portal.model.User>(list);
1892 }
1893 else {
1894 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1895 getDialect(), start, end);
1896 }
1897
1898 userPersistence.cacheResult(list);
1899
1900 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1901 list);
1902 }
1903 catch (Exception e) {
1904 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS, finderArgs);
1905
1906 throw processException(e);
1907 }
1908 finally {
1909 closeSession(session);
1910 }
1911 }
1912
1913 return list;
1914 }
1915
1916 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1917 TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS, Long.class,
1918 TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsersSize",
1919 new String[] { Long.class.getName() });
1920
1921 static {
1922 FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
1923 }
1924
1925
1932 public int getUsersSize(long pk) throws SystemException {
1933 Object[] finderArgs = new Object[] { pk };
1934
1935 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1936 finderArgs, this);
1937
1938 if (count == null) {
1939 Session session = null;
1940
1941 try {
1942 session = openSession();
1943
1944 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1945
1946 q.addScalar(COUNT_COLUMN_NAME,
1947 com.liferay.portal.kernel.dao.orm.Type.LONG);
1948
1949 QueryPos qPos = QueryPos.getInstance(q);
1950
1951 qPos.add(pk);
1952
1953 count = (Long)q.uniqueResult();
1954
1955 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1956 finderArgs, count);
1957 }
1958 catch (Exception e) {
1959 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS_SIZE,
1960 finderArgs);
1961
1962 throw processException(e);
1963 }
1964 finally {
1965 closeSession(session);
1966 }
1967 }
1968
1969 return count.intValue();
1970 }
1971
1972 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1973 TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS, Boolean.class,
1974 TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "containsUser",
1975 new String[] { Long.class.getName(), Long.class.getName() });
1976
1977
1985 public boolean containsUser(long pk, long userPK) throws SystemException {
1986 Object[] finderArgs = new Object[] { pk, userPK };
1987
1988 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1989 finderArgs, this);
1990
1991 if (value == null) {
1992 try {
1993 value = Boolean.valueOf(containsUser.contains(pk, userPK));
1994
1995 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1996 finderArgs, value);
1997 }
1998 catch (Exception e) {
1999 FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_USER,
2000 finderArgs);
2001
2002 throw processException(e);
2003 }
2004 }
2005
2006 return value.booleanValue();
2007 }
2008
2009
2016 public boolean containsUsers(long pk) throws SystemException {
2017 if (getUsersSize(pk) > 0) {
2018 return true;
2019 }
2020 else {
2021 return false;
2022 }
2023 }
2024
2025
2032 public void addUser(long pk, long userPK) throws SystemException {
2033 try {
2034 addUser.add(pk, userPK);
2035 }
2036 catch (Exception e) {
2037 throw processException(e);
2038 }
2039 finally {
2040 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2041 }
2042 }
2043
2044
2051 public void addUser(long pk, com.liferay.portal.model.User user)
2052 throws SystemException {
2053 try {
2054 addUser.add(pk, user.getPrimaryKey());
2055 }
2056 catch (Exception e) {
2057 throw processException(e);
2058 }
2059 finally {
2060 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2061 }
2062 }
2063
2064
2071 public void addUsers(long pk, long[] userPKs) throws SystemException {
2072 try {
2073 for (long userPK : userPKs) {
2074 addUser.add(pk, userPK);
2075 }
2076 }
2077 catch (Exception e) {
2078 throw processException(e);
2079 }
2080 finally {
2081 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2082 }
2083 }
2084
2085
2092 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2093 throws SystemException {
2094 try {
2095 for (com.liferay.portal.model.User user : users) {
2096 addUser.add(pk, user.getPrimaryKey());
2097 }
2098 }
2099 catch (Exception e) {
2100 throw processException(e);
2101 }
2102 finally {
2103 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2104 }
2105 }
2106
2107
2113 public void clearUsers(long pk) throws SystemException {
2114 try {
2115 clearUsers.clear(pk);
2116 }
2117 catch (Exception e) {
2118 throw processException(e);
2119 }
2120 finally {
2121 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2122 }
2123 }
2124
2125
2132 public void removeUser(long pk, long userPK) throws SystemException {
2133 try {
2134 removeUser.remove(pk, userPK);
2135 }
2136 catch (Exception e) {
2137 throw processException(e);
2138 }
2139 finally {
2140 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2141 }
2142 }
2143
2144
2151 public void removeUser(long pk, com.liferay.portal.model.User user)
2152 throws SystemException {
2153 try {
2154 removeUser.remove(pk, user.getPrimaryKey());
2155 }
2156 catch (Exception e) {
2157 throw processException(e);
2158 }
2159 finally {
2160 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2161 }
2162 }
2163
2164
2171 public void removeUsers(long pk, long[] userPKs) throws SystemException {
2172 try {
2173 for (long userPK : userPKs) {
2174 removeUser.remove(pk, userPK);
2175 }
2176 }
2177 catch (Exception e) {
2178 throw processException(e);
2179 }
2180 finally {
2181 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2182 }
2183 }
2184
2185
2192 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2193 throws SystemException {
2194 try {
2195 for (com.liferay.portal.model.User user : users) {
2196 removeUser.remove(pk, user.getPrimaryKey());
2197 }
2198 }
2199 catch (Exception e) {
2200 throw processException(e);
2201 }
2202 finally {
2203 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2204 }
2205 }
2206
2207
2214 public void setUsers(long pk, long[] userPKs) throws SystemException {
2215 try {
2216 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
2217
2218 List<com.liferay.portal.model.User> users = getUsers(pk);
2219
2220 for (com.liferay.portal.model.User user : users) {
2221 if (!userPKSet.remove(user.getPrimaryKey())) {
2222 removeUser.remove(pk, user.getPrimaryKey());
2223 }
2224 }
2225
2226 for (Long userPK : userPKSet) {
2227 addUser.add(pk, userPK);
2228 }
2229 }
2230 catch (Exception e) {
2231 throw processException(e);
2232 }
2233 finally {
2234 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2235 }
2236 }
2237
2238
2245 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2246 throws SystemException {
2247 try {
2248 long[] userPKs = new long[users.size()];
2249
2250 for (int i = 0; i < users.size(); i++) {
2251 com.liferay.portal.model.User user = users.get(i);
2252
2253 userPKs[i] = user.getPrimaryKey();
2254 }
2255
2256 setUsers(pk, userPKs);
2257 }
2258 catch (Exception e) {
2259 throw processException(e);
2260 }
2261 finally {
2262 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2263 }
2264 }
2265
2266
2273 public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
2274 throws SystemException {
2275 return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2276 }
2277
2278
2291 public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
2292 int start, int end) throws SystemException {
2293 return getUserGroups(pk, start, end, null);
2294 }
2295
2296 public static final FinderPath FINDER_PATH_GET_USERGROUPS = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2297 TeamModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
2298 com.liferay.portal.model.impl.UserGroupImpl.class,
2299 TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME, "getUserGroups",
2300 new String[] {
2301 Long.class.getName(), Integer.class.getName(),
2302 Integer.class.getName(), OrderByComparator.class.getName()
2303 });
2304
2305 static {
2306 FINDER_PATH_GET_USERGROUPS.setCacheKeyGeneratorCacheName(null);
2307 }
2308
2309
2323 public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
2324 int start, int end, OrderByComparator orderByComparator)
2325 throws SystemException {
2326 boolean pagination = true;
2327 Object[] finderArgs = null;
2328
2329 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2330 (orderByComparator == null)) {
2331 pagination = false;
2332 finderArgs = new Object[] { pk };
2333 }
2334 else {
2335 finderArgs = new Object[] { pk, start, end, orderByComparator };
2336 }
2337
2338 List<com.liferay.portal.model.UserGroup> list = (List<com.liferay.portal.model.UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS,
2339 finderArgs, this);
2340
2341 if (list == null) {
2342 Session session = null;
2343
2344 try {
2345 session = openSession();
2346
2347 String sql = null;
2348
2349 if (orderByComparator != null) {
2350 sql = _SQL_GETUSERGROUPS.concat(ORDER_BY_CLAUSE)
2351 .concat(orderByComparator.getOrderBy());
2352 }
2353 else {
2354 sql = _SQL_GETUSERGROUPS;
2355
2356 if (pagination) {
2357 sql = sql.concat(com.liferay.portal.model.impl.UserGroupModelImpl.ORDER_BY_SQL);
2358 }
2359 }
2360
2361 SQLQuery q = session.createSQLQuery(sql);
2362
2363 q.addEntity("UserGroup",
2364 com.liferay.portal.model.impl.UserGroupImpl.class);
2365
2366 QueryPos qPos = QueryPos.getInstance(q);
2367
2368 qPos.add(pk);
2369
2370 if (!pagination) {
2371 list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
2372 getDialect(), start, end, false);
2373
2374 Collections.sort(list);
2375
2376 list = new UnmodifiableList<com.liferay.portal.model.UserGroup>(list);
2377 }
2378 else {
2379 list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
2380 getDialect(), start, end);
2381 }
2382
2383 userGroupPersistence.cacheResult(list);
2384
2385 FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS,
2386 finderArgs, list);
2387 }
2388 catch (Exception e) {
2389 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERGROUPS,
2390 finderArgs);
2391
2392 throw processException(e);
2393 }
2394 finally {
2395 closeSession(session);
2396 }
2397 }
2398
2399 return list;
2400 }
2401
2402 public static final FinderPath FINDER_PATH_GET_USERGROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2403 TeamModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS, Long.class,
2404 TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
2405 "getUserGroupsSize", new String[] { Long.class.getName() });
2406
2407 static {
2408 FINDER_PATH_GET_USERGROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
2409 }
2410
2411
2418 public int getUserGroupsSize(long pk) throws SystemException {
2419 Object[] finderArgs = new Object[] { pk };
2420
2421 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS_SIZE,
2422 finderArgs, this);
2423
2424 if (count == null) {
2425 Session session = null;
2426
2427 try {
2428 session = openSession();
2429
2430 SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
2431
2432 q.addScalar(COUNT_COLUMN_NAME,
2433 com.liferay.portal.kernel.dao.orm.Type.LONG);
2434
2435 QueryPos qPos = QueryPos.getInstance(q);
2436
2437 qPos.add(pk);
2438
2439 count = (Long)q.uniqueResult();
2440
2441 FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS_SIZE,
2442 finderArgs, count);
2443 }
2444 catch (Exception e) {
2445 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERGROUPS_SIZE,
2446 finderArgs);
2447
2448 throw processException(e);
2449 }
2450 finally {
2451 closeSession(session);
2452 }
2453 }
2454
2455 return count.intValue();
2456 }
2457
2458 public static final FinderPath FINDER_PATH_CONTAINS_USERGROUP = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2459 TeamModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS, Boolean.class,
2460 TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
2461 "containsUserGroup",
2462 new String[] { Long.class.getName(), Long.class.getName() });
2463
2464
2472 public boolean containsUserGroup(long pk, long userGroupPK)
2473 throws SystemException {
2474 Object[] finderArgs = new Object[] { pk, userGroupPK };
2475
2476 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USERGROUP,
2477 finderArgs, this);
2478
2479 if (value == null) {
2480 try {
2481 value = Boolean.valueOf(containsUserGroup.contains(pk,
2482 userGroupPK));
2483
2484 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USERGROUP,
2485 finderArgs, value);
2486 }
2487 catch (Exception e) {
2488 FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_USERGROUP,
2489 finderArgs);
2490
2491 throw processException(e);
2492 }
2493 }
2494
2495 return value.booleanValue();
2496 }
2497
2498
2505 public boolean containsUserGroups(long pk) throws SystemException {
2506 if (getUserGroupsSize(pk) > 0) {
2507 return true;
2508 }
2509 else {
2510 return false;
2511 }
2512 }
2513
2514
2521 public void addUserGroup(long pk, long userGroupPK)
2522 throws SystemException {
2523 try {
2524 addUserGroup.add(pk, userGroupPK);
2525 }
2526 catch (Exception e) {
2527 throw processException(e);
2528 }
2529 finally {
2530 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2531 }
2532 }
2533
2534
2541 public void addUserGroup(long pk,
2542 com.liferay.portal.model.UserGroup userGroup) throws SystemException {
2543 try {
2544 addUserGroup.add(pk, userGroup.getPrimaryKey());
2545 }
2546 catch (Exception e) {
2547 throw processException(e);
2548 }
2549 finally {
2550 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2551 }
2552 }
2553
2554
2561 public void addUserGroups(long pk, long[] userGroupPKs)
2562 throws SystemException {
2563 try {
2564 for (long userGroupPK : userGroupPKs) {
2565 addUserGroup.add(pk, userGroupPK);
2566 }
2567 }
2568 catch (Exception e) {
2569 throw processException(e);
2570 }
2571 finally {
2572 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2573 }
2574 }
2575
2576
2583 public void addUserGroups(long pk,
2584 List<com.liferay.portal.model.UserGroup> userGroups)
2585 throws SystemException {
2586 try {
2587 for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2588 addUserGroup.add(pk, userGroup.getPrimaryKey());
2589 }
2590 }
2591 catch (Exception e) {
2592 throw processException(e);
2593 }
2594 finally {
2595 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2596 }
2597 }
2598
2599
2605 public void clearUserGroups(long pk) throws SystemException {
2606 try {
2607 clearUserGroups.clear(pk);
2608 }
2609 catch (Exception e) {
2610 throw processException(e);
2611 }
2612 finally {
2613 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2614 }
2615 }
2616
2617
2624 public void removeUserGroup(long pk, long userGroupPK)
2625 throws SystemException {
2626 try {
2627 removeUserGroup.remove(pk, userGroupPK);
2628 }
2629 catch (Exception e) {
2630 throw processException(e);
2631 }
2632 finally {
2633 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2634 }
2635 }
2636
2637
2644 public void removeUserGroup(long pk,
2645 com.liferay.portal.model.UserGroup userGroup) throws SystemException {
2646 try {
2647 removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2648 }
2649 catch (Exception e) {
2650 throw processException(e);
2651 }
2652 finally {
2653 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2654 }
2655 }
2656
2657
2664 public void removeUserGroups(long pk, long[] userGroupPKs)
2665 throws SystemException {
2666 try {
2667 for (long userGroupPK : userGroupPKs) {
2668 removeUserGroup.remove(pk, userGroupPK);
2669 }
2670 }
2671 catch (Exception e) {
2672 throw processException(e);
2673 }
2674 finally {
2675 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2676 }
2677 }
2678
2679
2686 public void removeUserGroups(long pk,
2687 List<com.liferay.portal.model.UserGroup> userGroups)
2688 throws SystemException {
2689 try {
2690 for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2691 removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2692 }
2693 }
2694 catch (Exception e) {
2695 throw processException(e);
2696 }
2697 finally {
2698 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2699 }
2700 }
2701
2702
2709 public void setUserGroups(long pk, long[] userGroupPKs)
2710 throws SystemException {
2711 try {
2712 Set<Long> userGroupPKSet = SetUtil.fromArray(userGroupPKs);
2713
2714 List<com.liferay.portal.model.UserGroup> userGroups = getUserGroups(pk);
2715
2716 for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2717 if (!userGroupPKSet.remove(userGroup.getPrimaryKey())) {
2718 removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2719 }
2720 }
2721
2722 for (Long userGroupPK : userGroupPKSet) {
2723 addUserGroup.add(pk, userGroupPK);
2724 }
2725 }
2726 catch (Exception e) {
2727 throw processException(e);
2728 }
2729 finally {
2730 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2731 }
2732 }
2733
2734
2741 public void setUserGroups(long pk,
2742 List<com.liferay.portal.model.UserGroup> userGroups)
2743 throws SystemException {
2744 try {
2745 long[] userGroupPKs = new long[userGroups.size()];
2746
2747 for (int i = 0; i < userGroups.size(); i++) {
2748 com.liferay.portal.model.UserGroup userGroup = userGroups.get(i);
2749
2750 userGroupPKs[i] = userGroup.getPrimaryKey();
2751 }
2752
2753 setUserGroups(pk, userGroupPKs);
2754 }
2755 catch (Exception e) {
2756 throw processException(e);
2757 }
2758 finally {
2759 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2760 }
2761 }
2762
2763
2766 public void afterPropertiesSet() {
2767 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2768 com.liferay.portal.util.PropsUtil.get(
2769 "value.object.listener.com.liferay.portal.model.Team")));
2770
2771 if (listenerClassNames.length > 0) {
2772 try {
2773 List<ModelListener<Team>> listenersList = new ArrayList<ModelListener<Team>>();
2774
2775 for (String listenerClassName : listenerClassNames) {
2776 listenersList.add((ModelListener<Team>)InstanceFactory.newInstance(
2777 listenerClassName));
2778 }
2779
2780 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2781 }
2782 catch (Exception e) {
2783 _log.error(e);
2784 }
2785 }
2786
2787 containsUser = new ContainsUser();
2788
2789 addUser = new AddUser();
2790 clearUsers = new ClearUsers();
2791 removeUser = new RemoveUser();
2792
2793 containsUserGroup = new ContainsUserGroup();
2794
2795 addUserGroup = new AddUserGroup();
2796 clearUserGroups = new ClearUserGroups();
2797 removeUserGroup = new RemoveUserGroup();
2798 }
2799
2800 public void destroy() {
2801 EntityCacheUtil.removeCache(TeamImpl.class.getName());
2802 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2803 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2804 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2805 }
2806
2807 @BeanReference(type = UserPersistence.class)
2808 protected UserPersistence userPersistence;
2809 protected ContainsUser containsUser;
2810 protected AddUser addUser;
2811 protected ClearUsers clearUsers;
2812 protected RemoveUser removeUser;
2813 @BeanReference(type = UserGroupPersistence.class)
2814 protected UserGroupPersistence userGroupPersistence;
2815 protected ContainsUserGroup containsUserGroup;
2816 protected AddUserGroup addUserGroup;
2817 protected ClearUserGroups clearUserGroups;
2818 protected RemoveUserGroup removeUserGroup;
2819
2820 protected class ContainsUser {
2821 protected ContainsUser() {
2822 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2823 _SQL_CONTAINSUSER,
2824 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2825 RowMapper.COUNT);
2826 }
2827
2828 protected boolean contains(long teamId, long userId) {
2829 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2830 new Long(teamId), new Long(userId)
2831 });
2832
2833 if (results.size() > 0) {
2834 Integer count = results.get(0);
2835
2836 if (count.intValue() > 0) {
2837 return true;
2838 }
2839 }
2840
2841 return false;
2842 }
2843
2844 private MappingSqlQuery<Integer> _mappingSqlQuery;
2845 }
2846
2847 protected class AddUser {
2848 protected AddUser() {
2849 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2850 "INSERT INTO Users_Teams (teamId, userId) VALUES (?, ?)",
2851 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2852 }
2853
2854 protected void add(long teamId, long userId) throws SystemException {
2855 if (!containsUser.contains(teamId, userId)) {
2856 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2857
2858 for (ModelListener<Team> listener : listeners) {
2859 listener.onBeforeAddAssociation(teamId,
2860 com.liferay.portal.model.User.class.getName(), userId);
2861 }
2862
2863 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2864 listener.onBeforeAddAssociation(userId,
2865 Team.class.getName(), teamId);
2866 }
2867
2868 _sqlUpdate.update(new Object[] {
2869 new Long(teamId), new Long(userId)
2870 });
2871
2872 for (ModelListener<Team> listener : listeners) {
2873 listener.onAfterAddAssociation(teamId,
2874 com.liferay.portal.model.User.class.getName(), userId);
2875 }
2876
2877 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2878 listener.onAfterAddAssociation(userId,
2879 Team.class.getName(), teamId);
2880 }
2881 }
2882 }
2883
2884 private SqlUpdate _sqlUpdate;
2885 }
2886
2887 protected class ClearUsers {
2888 protected ClearUsers() {
2889 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2890 "DELETE FROM Users_Teams WHERE teamId = ?",
2891 new int[] { java.sql.Types.BIGINT });
2892 }
2893
2894 protected void clear(long teamId) throws SystemException {
2895 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2896
2897 List<com.liferay.portal.model.User> users = null;
2898
2899 if ((listeners.length > 0) || (userListeners.length > 0)) {
2900 users = getUsers(teamId);
2901
2902 for (com.liferay.portal.model.User user : users) {
2903 for (ModelListener<Team> listener : listeners) {
2904 listener.onBeforeRemoveAssociation(teamId,
2905 com.liferay.portal.model.User.class.getName(),
2906 user.getPrimaryKey());
2907 }
2908
2909 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2910 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2911 Team.class.getName(), teamId);
2912 }
2913 }
2914 }
2915
2916 _sqlUpdate.update(new Object[] { new Long(teamId) });
2917
2918 if ((listeners.length > 0) || (userListeners.length > 0)) {
2919 for (com.liferay.portal.model.User user : users) {
2920 for (ModelListener<Team> listener : listeners) {
2921 listener.onAfterRemoveAssociation(teamId,
2922 com.liferay.portal.model.User.class.getName(),
2923 user.getPrimaryKey());
2924 }
2925
2926 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2927 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2928 Team.class.getName(), teamId);
2929 }
2930 }
2931 }
2932 }
2933
2934 private SqlUpdate _sqlUpdate;
2935 }
2936
2937 protected class RemoveUser {
2938 protected RemoveUser() {
2939 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2940 "DELETE FROM Users_Teams WHERE teamId = ? AND userId = ?",
2941 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2942 }
2943
2944 protected void remove(long teamId, long userId)
2945 throws SystemException {
2946 if (containsUser.contains(teamId, userId)) {
2947 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2948
2949 for (ModelListener<Team> listener : listeners) {
2950 listener.onBeforeRemoveAssociation(teamId,
2951 com.liferay.portal.model.User.class.getName(), userId);
2952 }
2953
2954 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2955 listener.onBeforeRemoveAssociation(userId,
2956 Team.class.getName(), teamId);
2957 }
2958
2959 _sqlUpdate.update(new Object[] {
2960 new Long(teamId), new Long(userId)
2961 });
2962
2963 for (ModelListener<Team> listener : listeners) {
2964 listener.onAfterRemoveAssociation(teamId,
2965 com.liferay.portal.model.User.class.getName(), userId);
2966 }
2967
2968 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2969 listener.onAfterRemoveAssociation(userId,
2970 Team.class.getName(), teamId);
2971 }
2972 }
2973 }
2974
2975 private SqlUpdate _sqlUpdate;
2976 }
2977
2978 protected class ContainsUserGroup {
2979 protected ContainsUserGroup() {
2980 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2981 _SQL_CONTAINSUSERGROUP,
2982 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2983 RowMapper.COUNT);
2984 }
2985
2986 protected boolean contains(long teamId, long userGroupId) {
2987 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2988 new Long(teamId), new Long(userGroupId)
2989 });
2990
2991 if (results.size() > 0) {
2992 Integer count = results.get(0);
2993
2994 if (count.intValue() > 0) {
2995 return true;
2996 }
2997 }
2998
2999 return false;
3000 }
3001
3002 private MappingSqlQuery<Integer> _mappingSqlQuery;
3003 }
3004
3005 protected class AddUserGroup {
3006 protected AddUserGroup() {
3007 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3008 "INSERT INTO UserGroups_Teams (teamId, userGroupId) VALUES (?, ?)",
3009 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3010 }
3011
3012 protected void add(long teamId, long userGroupId)
3013 throws SystemException {
3014 if (!containsUserGroup.contains(teamId, userGroupId)) {
3015 ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
3016 userGroupPersistence.getListeners();
3017
3018 for (ModelListener<Team> listener : listeners) {
3019 listener.onBeforeAddAssociation(teamId,
3020 com.liferay.portal.model.UserGroup.class.getName(),
3021 userGroupId);
3022 }
3023
3024 for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3025 listener.onBeforeAddAssociation(userGroupId,
3026 Team.class.getName(), teamId);
3027 }
3028
3029 _sqlUpdate.update(new Object[] {
3030 new Long(teamId), new Long(userGroupId)
3031 });
3032
3033 for (ModelListener<Team> listener : listeners) {
3034 listener.onAfterAddAssociation(teamId,
3035 com.liferay.portal.model.UserGroup.class.getName(),
3036 userGroupId);
3037 }
3038
3039 for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3040 listener.onAfterAddAssociation(userGroupId,
3041 Team.class.getName(), teamId);
3042 }
3043 }
3044 }
3045
3046 private SqlUpdate _sqlUpdate;
3047 }
3048
3049 protected class ClearUserGroups {
3050 protected ClearUserGroups() {
3051 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3052 "DELETE FROM UserGroups_Teams WHERE teamId = ?",
3053 new int[] { java.sql.Types.BIGINT });
3054 }
3055
3056 protected void clear(long teamId) throws SystemException {
3057 ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
3058 userGroupPersistence.getListeners();
3059
3060 List<com.liferay.portal.model.UserGroup> userGroups = null;
3061
3062 if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
3063 userGroups = getUserGroups(teamId);
3064
3065 for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3066 for (ModelListener<Team> listener : listeners) {
3067 listener.onBeforeRemoveAssociation(teamId,
3068 com.liferay.portal.model.UserGroup.class.getName(),
3069 userGroup.getPrimaryKey());
3070 }
3071
3072 for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3073 listener.onBeforeRemoveAssociation(userGroup.getPrimaryKey(),
3074 Team.class.getName(), teamId);
3075 }
3076 }
3077 }
3078
3079 _sqlUpdate.update(new Object[] { new Long(teamId) });
3080
3081 if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
3082 for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3083 for (ModelListener<Team> listener : listeners) {
3084 listener.onAfterRemoveAssociation(teamId,
3085 com.liferay.portal.model.UserGroup.class.getName(),
3086 userGroup.getPrimaryKey());
3087 }
3088
3089 for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3090 listener.onAfterRemoveAssociation(userGroup.getPrimaryKey(),
3091 Team.class.getName(), teamId);
3092 }
3093 }
3094 }
3095 }
3096
3097 private SqlUpdate _sqlUpdate;
3098 }
3099
3100 protected class RemoveUserGroup {
3101 protected RemoveUserGroup() {
3102 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3103 "DELETE FROM UserGroups_Teams WHERE teamId = ? AND userGroupId = ?",
3104 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3105 }
3106
3107 protected void remove(long teamId, long userGroupId)
3108 throws SystemException {
3109 if (containsUserGroup.contains(teamId, userGroupId)) {
3110 ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
3111 userGroupPersistence.getListeners();
3112
3113 for (ModelListener<Team> listener : listeners) {
3114 listener.onBeforeRemoveAssociation(teamId,
3115 com.liferay.portal.model.UserGroup.class.getName(),
3116 userGroupId);
3117 }
3118
3119 for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3120 listener.onBeforeRemoveAssociation(userGroupId,
3121 Team.class.getName(), teamId);
3122 }
3123
3124 _sqlUpdate.update(new Object[] {
3125 new Long(teamId), new Long(userGroupId)
3126 });
3127
3128 for (ModelListener<Team> listener : listeners) {
3129 listener.onAfterRemoveAssociation(teamId,
3130 com.liferay.portal.model.UserGroup.class.getName(),
3131 userGroupId);
3132 }
3133
3134 for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3135 listener.onAfterRemoveAssociation(userGroupId,
3136 Team.class.getName(), teamId);
3137 }
3138 }
3139 }
3140
3141 private SqlUpdate _sqlUpdate;
3142 }
3143
3144 private static final String _SQL_SELECT_TEAM = "SELECT team FROM Team team";
3145 private static final String _SQL_SELECT_TEAM_WHERE = "SELECT team FROM Team team WHERE ";
3146 private static final String _SQL_COUNT_TEAM = "SELECT COUNT(team) FROM Team team";
3147 private static final String _SQL_COUNT_TEAM_WHERE = "SELECT COUNT(team) FROM Team team WHERE ";
3148 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Teams ON (Users_Teams.userId = User_.userId) WHERE (Users_Teams.teamId = ?)";
3149 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ?";
3150 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ? AND userId = ?";
3151 private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN UserGroups_Teams ON (UserGroups_Teams.userGroupId = UserGroup.userGroupId) WHERE (UserGroups_Teams.teamId = ?)";
3152 private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM UserGroups_Teams WHERE teamId = ?";
3153 private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM UserGroups_Teams WHERE teamId = ? AND userGroupId = ?";
3154 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "team.teamId";
3155 private static final String _FILTER_SQL_SELECT_TEAM_WHERE = "SELECT DISTINCT {team.*} FROM Team team WHERE ";
3156 private static final String _FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1 =
3157 "SELECT {Team.*} FROM (SELECT DISTINCT team.teamId FROM Team team WHERE ";
3158 private static final String _FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2 =
3159 ") TEMP_TABLE INNER JOIN Team ON TEMP_TABLE.teamId = Team.teamId";
3160 private static final String _FILTER_SQL_COUNT_TEAM_WHERE = "SELECT COUNT(DISTINCT team.teamId) AS COUNT_VALUE FROM Team team WHERE ";
3161 private static final String _FILTER_ENTITY_ALIAS = "team";
3162 private static final String _FILTER_ENTITY_TABLE = "Team";
3163 private static final String _ORDER_BY_ENTITY_ALIAS = "team.";
3164 private static final String _ORDER_BY_ENTITY_TABLE = "Team.";
3165 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Team exists with the primary key ";
3166 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Team exists with the key {";
3167 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3168 private static Log _log = LogFactoryUtil.getLog(TeamPersistenceImpl.class);
3169 private static Team _nullTeam = new TeamImpl() {
3170 @Override
3171 public Object clone() {
3172 return this;
3173 }
3174
3175 @Override
3176 public CacheModel<Team> toCacheModel() {
3177 return _nullTeamCacheModel;
3178 }
3179 };
3180
3181 private static CacheModel<Team> _nullTeamCacheModel = new CacheModel<Team>() {
3182 public Team toEntityModel() {
3183 return _nullTeam;
3184 }
3185 };
3186 }