1
14
15 package com.liferay.portal.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.NoSuchTeamException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
22 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
23 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
24 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
25 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
26 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
27 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28 import com.liferay.portal.kernel.dao.orm.FinderPath;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.SQLQuery;
33 import com.liferay.portal.kernel.dao.orm.Session;
34 import com.liferay.portal.kernel.dao.orm.Type;
35 import com.liferay.portal.kernel.exception.SystemException;
36 import com.liferay.portal.kernel.log.Log;
37 import com.liferay.portal.kernel.log.LogFactoryUtil;
38 import com.liferay.portal.kernel.util.GetterUtil;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.SetUtil;
41 import com.liferay.portal.kernel.util.StringBundler;
42 import com.liferay.portal.kernel.util.StringPool;
43 import com.liferay.portal.kernel.util.StringUtil;
44 import com.liferay.portal.kernel.util.Validator;
45 import com.liferay.portal.model.ModelListener;
46 import com.liferay.portal.model.Team;
47 import com.liferay.portal.model.impl.TeamImpl;
48 import com.liferay.portal.model.impl.TeamModelImpl;
49 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
50
51 import java.io.Serializable;
52
53 import java.sql.Types;
54
55 import java.util.ArrayList;
56 import java.util.Collections;
57 import java.util.List;
58 import java.util.Set;
59
60
73 public class TeamPersistenceImpl extends BasePersistenceImpl<Team>
74 implements TeamPersistence {
75 public static final String FINDER_CLASS_NAME_ENTITY = TeamImpl.class.getName();
76 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
77 ".List";
78 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
79 TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
80 "findByGroupId", new String[] { Long.class.getName() });
81 public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
82 TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
83 "findByGroupId",
84 new String[] {
85 Long.class.getName(),
86
87 "java.lang.Integer", "java.lang.Integer",
88 "com.liferay.portal.kernel.util.OrderByComparator"
89 });
90 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
91 TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92 "countByGroupId", new String[] { Long.class.getName() });
93 public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
94 TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
95 "fetchByG_N",
96 new String[] { Long.class.getName(), String.class.getName() });
97 public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
98 TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
99 "countByG_N",
100 new String[] { Long.class.getName(), String.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
102 TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103 "findAll", new String[0]);
104 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
105 TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106 "countAll", new String[0]);
107
108 public void cacheResult(Team team) {
109 EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
110 TeamImpl.class, team.getPrimaryKey(), team);
111
112 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
113 new Object[] { new Long(team.getGroupId()), team.getName() }, team);
114 }
115
116 public void cacheResult(List<Team> teams) {
117 for (Team team : teams) {
118 if (EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
119 TeamImpl.class, team.getPrimaryKey(), this) == null) {
120 cacheResult(team);
121 }
122 }
123 }
124
125 public void clearCache() {
126 CacheRegistry.clear(TeamImpl.class.getName());
127 EntityCacheUtil.clearCache(TeamImpl.class.getName());
128 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
129 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
130 }
131
132 public Team create(long teamId) {
133 Team team = new TeamImpl();
134
135 team.setNew(true);
136 team.setPrimaryKey(teamId);
137
138 return team;
139 }
140
141 public Team remove(Serializable primaryKey)
142 throws NoSuchModelException, SystemException {
143 return remove(((Long)primaryKey).longValue());
144 }
145
146 public Team remove(long teamId) throws NoSuchTeamException, SystemException {
147 Session session = null;
148
149 try {
150 session = openSession();
151
152 Team team = (Team)session.get(TeamImpl.class, new Long(teamId));
153
154 if (team == null) {
155 if (_log.isWarnEnabled()) {
156 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + teamId);
157 }
158
159 throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
160 teamId);
161 }
162
163 return remove(team);
164 }
165 catch (NoSuchTeamException nsee) {
166 throw nsee;
167 }
168 catch (Exception e) {
169 throw processException(e);
170 }
171 finally {
172 closeSession(session);
173 }
174 }
175
176 public Team remove(Team team) throws SystemException {
177 for (ModelListener<Team> listener : listeners) {
178 listener.onBeforeRemove(team);
179 }
180
181 team = removeImpl(team);
182
183 for (ModelListener<Team> listener : listeners) {
184 listener.onAfterRemove(team);
185 }
186
187 return team;
188 }
189
190 protected Team removeImpl(Team team) throws SystemException {
191 team = toUnwrappedModel(team);
192
193 try {
194 clearUsers.clear(team.getPrimaryKey());
195 }
196 catch (Exception e) {
197 throw processException(e);
198 }
199 finally {
200 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
201 }
202
203 Session session = null;
204
205 try {
206 session = openSession();
207
208 if (team.isCachedModel() || BatchSessionUtil.isEnabled()) {
209 Object staleObject = session.get(TeamImpl.class,
210 team.getPrimaryKeyObj());
211
212 if (staleObject != null) {
213 session.evict(staleObject);
214 }
215 }
216
217 session.delete(team);
218
219 session.flush();
220 }
221 catch (Exception e) {
222 throw processException(e);
223 }
224 finally {
225 closeSession(session);
226 }
227
228 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
229
230 TeamModelImpl teamModelImpl = (TeamModelImpl)team;
231
232 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
233 new Object[] {
234 new Long(teamModelImpl.getOriginalGroupId()),
235
236 teamModelImpl.getOriginalName()
237 });
238
239 EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
240 TeamImpl.class, team.getPrimaryKey());
241
242 return team;
243 }
244
245 public Team updateImpl(com.liferay.portal.model.Team team, boolean merge)
246 throws SystemException {
247 team = toUnwrappedModel(team);
248
249 boolean isNew = team.isNew();
250
251 TeamModelImpl teamModelImpl = (TeamModelImpl)team;
252
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 BatchSessionUtil.update(session, team, merge);
259
260 team.setNew(false);
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268
269 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
270
271 EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
272 TeamImpl.class, team.getPrimaryKey(), team);
273
274 if (!isNew &&
275 ((team.getGroupId() != teamModelImpl.getOriginalGroupId()) ||
276 !Validator.equals(team.getName(),
277 teamModelImpl.getOriginalName()))) {
278 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
279 new Object[] {
280 new Long(teamModelImpl.getOriginalGroupId()),
281
282 teamModelImpl.getOriginalName()
283 });
284 }
285
286 if (isNew ||
287 ((team.getGroupId() != teamModelImpl.getOriginalGroupId()) ||
288 !Validator.equals(team.getName(),
289 teamModelImpl.getOriginalName()))) {
290 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
291 new Object[] { new Long(team.getGroupId()), team.getName() },
292 team);
293 }
294
295 return team;
296 }
297
298 protected Team toUnwrappedModel(Team team) {
299 if (team instanceof TeamImpl) {
300 return team;
301 }
302
303 TeamImpl teamImpl = new TeamImpl();
304
305 teamImpl.setNew(team.isNew());
306 teamImpl.setPrimaryKey(team.getPrimaryKey());
307
308 teamImpl.setTeamId(team.getTeamId());
309 teamImpl.setCompanyId(team.getCompanyId());
310 teamImpl.setUserId(team.getUserId());
311 teamImpl.setUserName(team.getUserName());
312 teamImpl.setCreateDate(team.getCreateDate());
313 teamImpl.setModifiedDate(team.getModifiedDate());
314 teamImpl.setGroupId(team.getGroupId());
315 teamImpl.setName(team.getName());
316 teamImpl.setDescription(team.getDescription());
317
318 return teamImpl;
319 }
320
321 public Team findByPrimaryKey(Serializable primaryKey)
322 throws NoSuchModelException, SystemException {
323 return findByPrimaryKey(((Long)primaryKey).longValue());
324 }
325
326 public Team findByPrimaryKey(long teamId)
327 throws NoSuchTeamException, SystemException {
328 Team team = fetchByPrimaryKey(teamId);
329
330 if (team == null) {
331 if (_log.isWarnEnabled()) {
332 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + teamId);
333 }
334
335 throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
336 teamId);
337 }
338
339 return team;
340 }
341
342 public Team fetchByPrimaryKey(Serializable primaryKey)
343 throws SystemException {
344 return fetchByPrimaryKey(((Long)primaryKey).longValue());
345 }
346
347 public Team fetchByPrimaryKey(long teamId) throws SystemException {
348 Team team = (Team)EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
349 TeamImpl.class, teamId, this);
350
351 if (team == null) {
352 Session session = null;
353
354 try {
355 session = openSession();
356
357 team = (Team)session.get(TeamImpl.class, new Long(teamId));
358 }
359 catch (Exception e) {
360 throw processException(e);
361 }
362 finally {
363 if (team != null) {
364 cacheResult(team);
365 }
366
367 closeSession(session);
368 }
369 }
370
371 return team;
372 }
373
374 public List<Team> findByGroupId(long groupId) throws SystemException {
375 Object[] finderArgs = new Object[] { new Long(groupId) };
376
377 List<Team> list = (List<Team>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
378 finderArgs, this);
379
380 if (list == null) {
381 Session session = null;
382
383 try {
384 session = openSession();
385
386 StringBundler query = new StringBundler(3);
387
388 query.append(_SQL_SELECT_TEAM_WHERE);
389
390 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
391
392 query.append(TeamModelImpl.ORDER_BY_JPQL);
393
394 String sql = query.toString();
395
396 Query q = session.createQuery(sql);
397
398 QueryPos qPos = QueryPos.getInstance(q);
399
400 qPos.add(groupId);
401
402 list = q.list();
403 }
404 catch (Exception e) {
405 throw processException(e);
406 }
407 finally {
408 if (list == null) {
409 list = new ArrayList<Team>();
410 }
411
412 cacheResult(list);
413
414 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
415 finderArgs, list);
416
417 closeSession(session);
418 }
419 }
420
421 return list;
422 }
423
424 public List<Team> findByGroupId(long groupId, int start, int end)
425 throws SystemException {
426 return findByGroupId(groupId, start, end, null);
427 }
428
429 public List<Team> findByGroupId(long groupId, int start, int end,
430 OrderByComparator orderByComparator) throws SystemException {
431 Object[] finderArgs = new Object[] {
432 new Long(groupId),
433
434 String.valueOf(start), String.valueOf(end),
435 String.valueOf(orderByComparator)
436 };
437
438 List<Team> list = (List<Team>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
439 finderArgs, this);
440
441 if (list == null) {
442 Session session = null;
443
444 try {
445 session = openSession();
446
447 StringBundler query = null;
448
449 if (orderByComparator != null) {
450 query = new StringBundler(3 +
451 (orderByComparator.getOrderByFields().length * 3));
452 }
453 else {
454 query = new StringBundler(3);
455 }
456
457 query.append(_SQL_SELECT_TEAM_WHERE);
458
459 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
460
461 if (orderByComparator != null) {
462 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
463 orderByComparator);
464 }
465
466 else {
467 query.append(TeamModelImpl.ORDER_BY_JPQL);
468 }
469
470 String sql = query.toString();
471
472 Query q = session.createQuery(sql);
473
474 QueryPos qPos = QueryPos.getInstance(q);
475
476 qPos.add(groupId);
477
478 list = (List<Team>)QueryUtil.list(q, getDialect(), start, end);
479 }
480 catch (Exception e) {
481 throw processException(e);
482 }
483 finally {
484 if (list == null) {
485 list = new ArrayList<Team>();
486 }
487
488 cacheResult(list);
489
490 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
491 finderArgs, list);
492
493 closeSession(session);
494 }
495 }
496
497 return list;
498 }
499
500 public Team findByGroupId_First(long groupId,
501 OrderByComparator orderByComparator)
502 throws NoSuchTeamException, SystemException {
503 List<Team> list = findByGroupId(groupId, 0, 1, orderByComparator);
504
505 if (list.isEmpty()) {
506 StringBundler msg = new StringBundler(4);
507
508 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
509
510 msg.append("groupId=");
511 msg.append(groupId);
512
513 msg.append(StringPool.CLOSE_CURLY_BRACE);
514
515 throw new NoSuchTeamException(msg.toString());
516 }
517 else {
518 return list.get(0);
519 }
520 }
521
522 public Team findByGroupId_Last(long groupId,
523 OrderByComparator orderByComparator)
524 throws NoSuchTeamException, SystemException {
525 int count = countByGroupId(groupId);
526
527 List<Team> list = findByGroupId(groupId, count - 1, count,
528 orderByComparator);
529
530 if (list.isEmpty()) {
531 StringBundler msg = new StringBundler(4);
532
533 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
534
535 msg.append("groupId=");
536 msg.append(groupId);
537
538 msg.append(StringPool.CLOSE_CURLY_BRACE);
539
540 throw new NoSuchTeamException(msg.toString());
541 }
542 else {
543 return list.get(0);
544 }
545 }
546
547 public Team[] findByGroupId_PrevAndNext(long teamId, long groupId,
548 OrderByComparator orderByComparator)
549 throws NoSuchTeamException, SystemException {
550 Team team = findByPrimaryKey(teamId);
551
552 int count = countByGroupId(groupId);
553
554 Session session = null;
555
556 try {
557 session = openSession();
558
559 StringBundler query = null;
560
561 if (orderByComparator != null) {
562 query = new StringBundler(3 +
563 (orderByComparator.getOrderByFields().length * 3));
564 }
565 else {
566 query = new StringBundler(3);
567 }
568
569 query.append(_SQL_SELECT_TEAM_WHERE);
570
571 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
572
573 if (orderByComparator != null) {
574 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
575 orderByComparator);
576 }
577
578 else {
579 query.append(TeamModelImpl.ORDER_BY_JPQL);
580 }
581
582 String sql = query.toString();
583
584 Query q = session.createQuery(sql);
585
586 QueryPos qPos = QueryPos.getInstance(q);
587
588 qPos.add(groupId);
589
590 Object[] objArray = QueryUtil.getPrevAndNext(q, count,
591 orderByComparator, team);
592
593 Team[] array = new TeamImpl[3];
594
595 array[0] = (Team)objArray[0];
596 array[1] = (Team)objArray[1];
597 array[2] = (Team)objArray[2];
598
599 return array;
600 }
601 catch (Exception e) {
602 throw processException(e);
603 }
604 finally {
605 closeSession(session);
606 }
607 }
608
609 public Team findByG_N(long groupId, String name)
610 throws NoSuchTeamException, SystemException {
611 Team team = fetchByG_N(groupId, name);
612
613 if (team == null) {
614 StringBundler msg = new StringBundler(6);
615
616 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
617
618 msg.append("groupId=");
619 msg.append(groupId);
620
621 msg.append(", name=");
622 msg.append(name);
623
624 msg.append(StringPool.CLOSE_CURLY_BRACE);
625
626 if (_log.isWarnEnabled()) {
627 _log.warn(msg.toString());
628 }
629
630 throw new NoSuchTeamException(msg.toString());
631 }
632
633 return team;
634 }
635
636 public Team fetchByG_N(long groupId, String name) throws SystemException {
637 return fetchByG_N(groupId, name, true);
638 }
639
640 public Team fetchByG_N(long groupId, String name, boolean retrieveFromCache)
641 throws SystemException {
642 Object[] finderArgs = new Object[] { new Long(groupId), name };
643
644 Object result = null;
645
646 if (retrieveFromCache) {
647 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
648 finderArgs, this);
649 }
650
651 if (result == null) {
652 Session session = null;
653
654 try {
655 session = openSession();
656
657 StringBundler query = new StringBundler(4);
658
659 query.append(_SQL_SELECT_TEAM_WHERE);
660
661 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
662
663 if (name == null) {
664 query.append(_FINDER_COLUMN_G_N_NAME_1);
665 }
666 else {
667 if (name.equals(StringPool.BLANK)) {
668 query.append(_FINDER_COLUMN_G_N_NAME_3);
669 }
670 else {
671 query.append(_FINDER_COLUMN_G_N_NAME_2);
672 }
673 }
674
675 query.append(TeamModelImpl.ORDER_BY_JPQL);
676
677 String sql = query.toString();
678
679 Query q = session.createQuery(sql);
680
681 QueryPos qPos = QueryPos.getInstance(q);
682
683 qPos.add(groupId);
684
685 if (name != null) {
686 qPos.add(name);
687 }
688
689 List<Team> list = q.list();
690
691 result = list;
692
693 Team team = null;
694
695 if (list.isEmpty()) {
696 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
697 finderArgs, list);
698 }
699 else {
700 team = list.get(0);
701
702 cacheResult(team);
703
704 if ((team.getGroupId() != groupId) ||
705 (team.getName() == null) ||
706 !team.getName().equals(name)) {
707 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
708 finderArgs, team);
709 }
710 }
711
712 return team;
713 }
714 catch (Exception e) {
715 throw processException(e);
716 }
717 finally {
718 if (result == null) {
719 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
720 finderArgs, new ArrayList<Team>());
721 }
722
723 closeSession(session);
724 }
725 }
726 else {
727 if (result instanceof List<?>) {
728 return null;
729 }
730 else {
731 return (Team)result;
732 }
733 }
734 }
735
736 public List<Team> findAll() throws SystemException {
737 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
738 }
739
740 public List<Team> findAll(int start, int end) throws SystemException {
741 return findAll(start, end, null);
742 }
743
744 public List<Team> findAll(int start, int end,
745 OrderByComparator orderByComparator) throws SystemException {
746 Object[] finderArgs = new Object[] {
747 String.valueOf(start), String.valueOf(end),
748 String.valueOf(orderByComparator)
749 };
750
751 List<Team> list = (List<Team>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
752 finderArgs, this);
753
754 if (list == null) {
755 Session session = null;
756
757 try {
758 session = openSession();
759
760 StringBundler query = null;
761 String sql = null;
762
763 if (orderByComparator != null) {
764 query = new StringBundler(2 +
765 (orderByComparator.getOrderByFields().length * 3));
766
767 query.append(_SQL_SELECT_TEAM);
768
769 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
770 orderByComparator);
771
772 sql = query.toString();
773 }
774
775 else {
776 sql = _SQL_SELECT_TEAM.concat(TeamModelImpl.ORDER_BY_JPQL);
777 }
778
779 Query q = session.createQuery(sql);
780
781 if (orderByComparator == null) {
782 list = (List<Team>)QueryUtil.list(q, getDialect(), start,
783 end, false);
784
785 Collections.sort(list);
786 }
787 else {
788 list = (List<Team>)QueryUtil.list(q, getDialect(), start,
789 end);
790 }
791 }
792 catch (Exception e) {
793 throw processException(e);
794 }
795 finally {
796 if (list == null) {
797 list = new ArrayList<Team>();
798 }
799
800 cacheResult(list);
801
802 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
803
804 closeSession(session);
805 }
806 }
807
808 return list;
809 }
810
811 public void removeByGroupId(long groupId) throws SystemException {
812 for (Team team : findByGroupId(groupId)) {
813 remove(team);
814 }
815 }
816
817 public void removeByG_N(long groupId, String name)
818 throws NoSuchTeamException, SystemException {
819 Team team = findByG_N(groupId, name);
820
821 remove(team);
822 }
823
824 public void removeAll() throws SystemException {
825 for (Team team : findAll()) {
826 remove(team);
827 }
828 }
829
830 public int countByGroupId(long groupId) throws SystemException {
831 Object[] finderArgs = new Object[] { new Long(groupId) };
832
833 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
834 finderArgs, this);
835
836 if (count == null) {
837 Session session = null;
838
839 try {
840 session = openSession();
841
842 StringBundler query = new StringBundler(2);
843
844 query.append(_SQL_COUNT_TEAM_WHERE);
845
846 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
847
848 String sql = query.toString();
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 catch (Exception e) {
859 throw processException(e);
860 }
861 finally {
862 if (count == null) {
863 count = Long.valueOf(0);
864 }
865
866 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
867 finderArgs, count);
868
869 closeSession(session);
870 }
871 }
872
873 return count.intValue();
874 }
875
876 public int countByG_N(long groupId, String name) throws SystemException {
877 Object[] finderArgs = new Object[] { new Long(groupId), name };
878
879 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
880 finderArgs, this);
881
882 if (count == null) {
883 Session session = null;
884
885 try {
886 session = openSession();
887
888 StringBundler query = new StringBundler(3);
889
890 query.append(_SQL_COUNT_TEAM_WHERE);
891
892 query.append(_FINDER_COLUMN_G_N_GROUPID_2);
893
894 if (name == null) {
895 query.append(_FINDER_COLUMN_G_N_NAME_1);
896 }
897 else {
898 if (name.equals(StringPool.BLANK)) {
899 query.append(_FINDER_COLUMN_G_N_NAME_3);
900 }
901 else {
902 query.append(_FINDER_COLUMN_G_N_NAME_2);
903 }
904 }
905
906 String sql = query.toString();
907
908 Query q = session.createQuery(sql);
909
910 QueryPos qPos = QueryPos.getInstance(q);
911
912 qPos.add(groupId);
913
914 if (name != null) {
915 qPos.add(name);
916 }
917
918 count = (Long)q.uniqueResult();
919 }
920 catch (Exception e) {
921 throw processException(e);
922 }
923 finally {
924 if (count == null) {
925 count = Long.valueOf(0);
926 }
927
928 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
929 count);
930
931 closeSession(session);
932 }
933 }
934
935 return count.intValue();
936 }
937
938 public int countAll() throws SystemException {
939 Object[] finderArgs = new Object[0];
940
941 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
942 finderArgs, this);
943
944 if (count == null) {
945 Session session = null;
946
947 try {
948 session = openSession();
949
950 Query q = session.createQuery(_SQL_COUNT_TEAM);
951
952 count = (Long)q.uniqueResult();
953 }
954 catch (Exception e) {
955 throw processException(e);
956 }
957 finally {
958 if (count == null) {
959 count = Long.valueOf(0);
960 }
961
962 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
963 count);
964
965 closeSession(session);
966 }
967 }
968
969 return count.intValue();
970 }
971
972 public List<com.liferay.portal.model.User> getUsers(long pk)
973 throws SystemException {
974 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
975 }
976
977 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
978 int end) throws SystemException {
979 return getUsers(pk, start, end, null);
980 }
981
982 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
983 TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
984 TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsers",
985 new String[] {
986 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
987 "com.liferay.portal.kernel.util.OrderByComparator"
988 });
989
990 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
991 int end, OrderByComparator orderByComparator) throws SystemException {
992 Object[] finderArgs = new Object[] {
993 new Long(pk), String.valueOf(start), String.valueOf(end),
994 String.valueOf(orderByComparator)
995 };
996
997 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
998 finderArgs, this);
999
1000 if (list == null) {
1001 Session session = null;
1002
1003 try {
1004 session = openSession();
1005
1006 String sql = null;
1007
1008 if (orderByComparator != null) {
1009 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1010 .concat(orderByComparator.getOrderBy());
1011 }
1012
1013 sql = _SQL_GETUSERS;
1014
1015 SQLQuery q = session.createSQLQuery(sql);
1016
1017 q.addEntity("User_",
1018 com.liferay.portal.model.impl.UserImpl.class);
1019
1020 QueryPos qPos = QueryPos.getInstance(q);
1021
1022 qPos.add(pk);
1023
1024 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1025 getDialect(), start, end);
1026 }
1027 catch (Exception e) {
1028 throw processException(e);
1029 }
1030 finally {
1031 if (list == null) {
1032 list = new ArrayList<com.liferay.portal.model.User>();
1033 }
1034
1035 userPersistence.cacheResult(list);
1036
1037 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1038 list);
1039
1040 closeSession(session);
1041 }
1042 }
1043
1044 return list;
1045 }
1046
1047 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1048 TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
1049 TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsersSize",
1050 new String[] { Long.class.getName() });
1051
1052 public int getUsersSize(long pk) throws SystemException {
1053 Object[] finderArgs = new Object[] { new Long(pk) };
1054
1055 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1056 finderArgs, this);
1057
1058 if (count == null) {
1059 Session session = null;
1060
1061 try {
1062 session = openSession();
1063
1064 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1065
1066 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1067
1068 QueryPos qPos = QueryPos.getInstance(q);
1069
1070 qPos.add(pk);
1071
1072 count = (Long)q.uniqueResult();
1073 }
1074 catch (Exception e) {
1075 throw processException(e);
1076 }
1077 finally {
1078 if (count == null) {
1079 count = Long.valueOf(0);
1080 }
1081
1082 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1083 finderArgs, count);
1084
1085 closeSession(session);
1086 }
1087 }
1088
1089 return count.intValue();
1090 }
1091
1092 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1093 TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
1094 TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "containsUser",
1095 new String[] { Long.class.getName(), Long.class.getName() });
1096
1097 public boolean containsUser(long pk, long userPK) throws SystemException {
1098 Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
1099
1100 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1101 finderArgs, this);
1102
1103 if (value == null) {
1104 try {
1105 value = Boolean.valueOf(containsUser.contains(pk, userPK));
1106 }
1107 catch (Exception e) {
1108 throw processException(e);
1109 }
1110 finally {
1111 if (value == null) {
1112 value = Boolean.FALSE;
1113 }
1114
1115 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1116 finderArgs, value);
1117 }
1118 }
1119
1120 return value.booleanValue();
1121 }
1122
1123 public boolean containsUsers(long pk) throws SystemException {
1124 if (getUsersSize(pk) > 0) {
1125 return true;
1126 }
1127 else {
1128 return false;
1129 }
1130 }
1131
1132 public void addUser(long pk, long userPK) throws SystemException {
1133 try {
1134 addUser.add(pk, userPK);
1135 }
1136 catch (Exception e) {
1137 throw processException(e);
1138 }
1139 finally {
1140 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1141 }
1142 }
1143
1144 public void addUser(long pk, com.liferay.portal.model.User user)
1145 throws SystemException {
1146 try {
1147 addUser.add(pk, user.getPrimaryKey());
1148 }
1149 catch (Exception e) {
1150 throw processException(e);
1151 }
1152 finally {
1153 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1154 }
1155 }
1156
1157 public void addUsers(long pk, long[] userPKs) throws SystemException {
1158 try {
1159 for (long userPK : userPKs) {
1160 addUser.add(pk, userPK);
1161 }
1162 }
1163 catch (Exception e) {
1164 throw processException(e);
1165 }
1166 finally {
1167 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1168 }
1169 }
1170
1171 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1172 throws SystemException {
1173 try {
1174 for (com.liferay.portal.model.User user : users) {
1175 addUser.add(pk, user.getPrimaryKey());
1176 }
1177 }
1178 catch (Exception e) {
1179 throw processException(e);
1180 }
1181 finally {
1182 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1183 }
1184 }
1185
1186 public void clearUsers(long pk) throws SystemException {
1187 try {
1188 clearUsers.clear(pk);
1189 }
1190 catch (Exception e) {
1191 throw processException(e);
1192 }
1193 finally {
1194 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1195 }
1196 }
1197
1198 public void removeUser(long pk, long userPK) throws SystemException {
1199 try {
1200 removeUser.remove(pk, userPK);
1201 }
1202 catch (Exception e) {
1203 throw processException(e);
1204 }
1205 finally {
1206 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1207 }
1208 }
1209
1210 public void removeUser(long pk, com.liferay.portal.model.User user)
1211 throws SystemException {
1212 try {
1213 removeUser.remove(pk, user.getPrimaryKey());
1214 }
1215 catch (Exception e) {
1216 throw processException(e);
1217 }
1218 finally {
1219 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1220 }
1221 }
1222
1223 public void removeUsers(long pk, long[] userPKs) throws SystemException {
1224 try {
1225 for (long userPK : userPKs) {
1226 removeUser.remove(pk, userPK);
1227 }
1228 }
1229 catch (Exception e) {
1230 throw processException(e);
1231 }
1232 finally {
1233 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1234 }
1235 }
1236
1237 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1238 throws SystemException {
1239 try {
1240 for (com.liferay.portal.model.User user : users) {
1241 removeUser.remove(pk, user.getPrimaryKey());
1242 }
1243 }
1244 catch (Exception e) {
1245 throw processException(e);
1246 }
1247 finally {
1248 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1249 }
1250 }
1251
1252 public void setUsers(long pk, long[] userPKs) throws SystemException {
1253 try {
1254 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1255
1256 List<com.liferay.portal.model.User> users = getUsers(pk);
1257
1258 for (com.liferay.portal.model.User user : users) {
1259 if (!userPKSet.contains(user.getPrimaryKey())) {
1260 removeUser.remove(pk, user.getPrimaryKey());
1261 }
1262 else {
1263 userPKSet.remove(user.getPrimaryKey());
1264 }
1265 }
1266
1267 for (Long userPK : userPKSet) {
1268 addUser.add(pk, userPK);
1269 }
1270 }
1271 catch (Exception e) {
1272 throw processException(e);
1273 }
1274 finally {
1275 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1276 }
1277 }
1278
1279 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
1280 throws SystemException {
1281 try {
1282 long[] userPKs = new long[users.size()];
1283
1284 for (int i = 0; i < users.size(); i++) {
1285 com.liferay.portal.model.User user = users.get(i);
1286
1287 userPKs[i] = user.getPrimaryKey();
1288 }
1289
1290 setUsers(pk, userPKs);
1291 }
1292 catch (Exception e) {
1293 throw processException(e);
1294 }
1295 finally {
1296 FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1297 }
1298 }
1299
1300 public void afterPropertiesSet() {
1301 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1302 com.liferay.portal.util.PropsUtil.get(
1303 "value.object.listener.com.liferay.portal.model.Team")));
1304
1305 if (listenerClassNames.length > 0) {
1306 try {
1307 List<ModelListener<Team>> listenersList = new ArrayList<ModelListener<Team>>();
1308
1309 for (String listenerClassName : listenerClassNames) {
1310 listenersList.add((ModelListener<Team>)Class.forName(
1311 listenerClassName).newInstance());
1312 }
1313
1314 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1315 }
1316 catch (Exception e) {
1317 _log.error(e);
1318 }
1319 }
1320
1321 containsUser = new ContainsUser(this);
1322
1323 addUser = new AddUser(this);
1324 clearUsers = new ClearUsers(this);
1325 removeUser = new RemoveUser(this);
1326 }
1327
1328 @BeanReference(type = AccountPersistence.class)
1329 protected AccountPersistence accountPersistence;
1330 @BeanReference(type = AddressPersistence.class)
1331 protected AddressPersistence addressPersistence;
1332 @BeanReference(type = BrowserTrackerPersistence.class)
1333 protected BrowserTrackerPersistence browserTrackerPersistence;
1334 @BeanReference(type = ClassNamePersistence.class)
1335 protected ClassNamePersistence classNamePersistence;
1336 @BeanReference(type = CompanyPersistence.class)
1337 protected CompanyPersistence companyPersistence;
1338 @BeanReference(type = ContactPersistence.class)
1339 protected ContactPersistence contactPersistence;
1340 @BeanReference(type = CountryPersistence.class)
1341 protected CountryPersistence countryPersistence;
1342 @BeanReference(type = EmailAddressPersistence.class)
1343 protected EmailAddressPersistence emailAddressPersistence;
1344 @BeanReference(type = GroupPersistence.class)
1345 protected GroupPersistence groupPersistence;
1346 @BeanReference(type = ImagePersistence.class)
1347 protected ImagePersistence imagePersistence;
1348 @BeanReference(type = LayoutPersistence.class)
1349 protected LayoutPersistence layoutPersistence;
1350 @BeanReference(type = LayoutPrototypePersistence.class)
1351 protected LayoutPrototypePersistence layoutPrototypePersistence;
1352 @BeanReference(type = LayoutSetPersistence.class)
1353 protected LayoutSetPersistence layoutSetPersistence;
1354 @BeanReference(type = LayoutSetPrototypePersistence.class)
1355 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1356 @BeanReference(type = ListTypePersistence.class)
1357 protected ListTypePersistence listTypePersistence;
1358 @BeanReference(type = LockPersistence.class)
1359 protected LockPersistence lockPersistence;
1360 @BeanReference(type = MembershipRequestPersistence.class)
1361 protected MembershipRequestPersistence membershipRequestPersistence;
1362 @BeanReference(type = OrganizationPersistence.class)
1363 protected OrganizationPersistence organizationPersistence;
1364 @BeanReference(type = OrgGroupPermissionPersistence.class)
1365 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1366 @BeanReference(type = OrgGroupRolePersistence.class)
1367 protected OrgGroupRolePersistence orgGroupRolePersistence;
1368 @BeanReference(type = OrgLaborPersistence.class)
1369 protected OrgLaborPersistence orgLaborPersistence;
1370 @BeanReference(type = PasswordPolicyPersistence.class)
1371 protected PasswordPolicyPersistence passwordPolicyPersistence;
1372 @BeanReference(type = PasswordPolicyRelPersistence.class)
1373 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1374 @BeanReference(type = PasswordTrackerPersistence.class)
1375 protected PasswordTrackerPersistence passwordTrackerPersistence;
1376 @BeanReference(type = PermissionPersistence.class)
1377 protected PermissionPersistence permissionPersistence;
1378 @BeanReference(type = PhonePersistence.class)
1379 protected PhonePersistence phonePersistence;
1380 @BeanReference(type = PluginSettingPersistence.class)
1381 protected PluginSettingPersistence pluginSettingPersistence;
1382 @BeanReference(type = PortletPersistence.class)
1383 protected PortletPersistence portletPersistence;
1384 @BeanReference(type = PortletItemPersistence.class)
1385 protected PortletItemPersistence portletItemPersistence;
1386 @BeanReference(type = PortletPreferencesPersistence.class)
1387 protected PortletPreferencesPersistence portletPreferencesPersistence;
1388 @BeanReference(type = RegionPersistence.class)
1389 protected RegionPersistence regionPersistence;
1390 @BeanReference(type = ReleasePersistence.class)
1391 protected ReleasePersistence releasePersistence;
1392 @BeanReference(type = ResourcePersistence.class)
1393 protected ResourcePersistence resourcePersistence;
1394 @BeanReference(type = ResourceActionPersistence.class)
1395 protected ResourceActionPersistence resourceActionPersistence;
1396 @BeanReference(type = ResourceCodePersistence.class)
1397 protected ResourceCodePersistence resourceCodePersistence;
1398 @BeanReference(type = ResourcePermissionPersistence.class)
1399 protected ResourcePermissionPersistence resourcePermissionPersistence;
1400 @BeanReference(type = RolePersistence.class)
1401 protected RolePersistence rolePersistence;
1402 @BeanReference(type = ServiceComponentPersistence.class)
1403 protected ServiceComponentPersistence serviceComponentPersistence;
1404 @BeanReference(type = ShardPersistence.class)
1405 protected ShardPersistence shardPersistence;
1406 @BeanReference(type = SubscriptionPersistence.class)
1407 protected SubscriptionPersistence subscriptionPersistence;
1408 @BeanReference(type = TeamPersistence.class)
1409 protected TeamPersistence teamPersistence;
1410 @BeanReference(type = UserPersistence.class)
1411 protected UserPersistence userPersistence;
1412 @BeanReference(type = UserGroupPersistence.class)
1413 protected UserGroupPersistence userGroupPersistence;
1414 @BeanReference(type = UserGroupGroupRolePersistence.class)
1415 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1416 @BeanReference(type = UserGroupRolePersistence.class)
1417 protected UserGroupRolePersistence userGroupRolePersistence;
1418 @BeanReference(type = UserIdMapperPersistence.class)
1419 protected UserIdMapperPersistence userIdMapperPersistence;
1420 @BeanReference(type = UserTrackerPersistence.class)
1421 protected UserTrackerPersistence userTrackerPersistence;
1422 @BeanReference(type = UserTrackerPathPersistence.class)
1423 protected UserTrackerPathPersistence userTrackerPathPersistence;
1424 @BeanReference(type = WebDAVPropsPersistence.class)
1425 protected WebDAVPropsPersistence webDAVPropsPersistence;
1426 @BeanReference(type = WebsitePersistence.class)
1427 protected WebsitePersistence websitePersistence;
1428 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1429 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1430 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1431 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1432 protected ContainsUser containsUser;
1433 protected AddUser addUser;
1434 protected ClearUsers clearUsers;
1435 protected RemoveUser removeUser;
1436
1437 protected class ContainsUser {
1438 protected ContainsUser(TeamPersistenceImpl persistenceImpl) {
1439 super();
1440
1441 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1442 _SQL_CONTAINSUSER,
1443 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1444 }
1445
1446 protected boolean contains(long teamId, long userId) {
1447 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1448 new Long(teamId), new Long(userId)
1449 });
1450
1451 if (results.size() > 0) {
1452 Integer count = results.get(0);
1453
1454 if (count.intValue() > 0) {
1455 return true;
1456 }
1457 }
1458
1459 return false;
1460 }
1461
1462 private MappingSqlQuery<Integer> _mappingSqlQuery;
1463 }
1464
1465 protected class AddUser {
1466 protected AddUser(TeamPersistenceImpl persistenceImpl) {
1467 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1468 "INSERT INTO Users_Teams (teamId, userId) VALUES (?, ?)",
1469 new int[] { Types.BIGINT, Types.BIGINT });
1470 _persistenceImpl = persistenceImpl;
1471 }
1472
1473 protected void add(long teamId, long userId) throws SystemException {
1474 if (!_persistenceImpl.containsUser.contains(teamId, userId)) {
1475 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1476
1477 for (ModelListener<Team> listener : listeners) {
1478 listener.onBeforeAddAssociation(teamId,
1479 com.liferay.portal.model.User.class.getName(), userId);
1480 }
1481
1482 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1483 listener.onBeforeAddAssociation(userId,
1484 Team.class.getName(), teamId);
1485 }
1486
1487 _sqlUpdate.update(new Object[] {
1488 new Long(teamId), new Long(userId)
1489 });
1490
1491 for (ModelListener<Team> listener : listeners) {
1492 listener.onAfterAddAssociation(teamId,
1493 com.liferay.portal.model.User.class.getName(), userId);
1494 }
1495
1496 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1497 listener.onAfterAddAssociation(userId,
1498 Team.class.getName(), teamId);
1499 }
1500 }
1501 }
1502
1503 private SqlUpdate _sqlUpdate;
1504 private TeamPersistenceImpl _persistenceImpl;
1505 }
1506
1507 protected class ClearUsers {
1508 protected ClearUsers(TeamPersistenceImpl persistenceImpl) {
1509 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1510 "DELETE FROM Users_Teams WHERE teamId = ?",
1511 new int[] { Types.BIGINT });
1512 }
1513
1514 protected void clear(long teamId) throws SystemException {
1515 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1516
1517 List<com.liferay.portal.model.User> users = null;
1518
1519 if ((listeners.length > 0) || (userListeners.length > 0)) {
1520 users = getUsers(teamId);
1521
1522 for (com.liferay.portal.model.User user : users) {
1523 for (ModelListener<Team> listener : listeners) {
1524 listener.onBeforeRemoveAssociation(teamId,
1525 com.liferay.portal.model.User.class.getName(),
1526 user.getPrimaryKey());
1527 }
1528
1529 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1530 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
1531 Team.class.getName(), teamId);
1532 }
1533 }
1534 }
1535
1536 _sqlUpdate.update(new Object[] { new Long(teamId) });
1537
1538 if ((listeners.length > 0) || (userListeners.length > 0)) {
1539 for (com.liferay.portal.model.User user : users) {
1540 for (ModelListener<Team> listener : listeners) {
1541 listener.onAfterRemoveAssociation(teamId,
1542 com.liferay.portal.model.User.class.getName(),
1543 user.getPrimaryKey());
1544 }
1545
1546 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1547 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
1548 Team.class.getName(), teamId);
1549 }
1550 }
1551 }
1552 }
1553
1554 private SqlUpdate _sqlUpdate;
1555 }
1556
1557 protected class RemoveUser {
1558 protected RemoveUser(TeamPersistenceImpl persistenceImpl) {
1559 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1560 "DELETE FROM Users_Teams WHERE teamId = ? AND userId = ?",
1561 new int[] { Types.BIGINT, Types.BIGINT });
1562 _persistenceImpl = persistenceImpl;
1563 }
1564
1565 protected void remove(long teamId, long userId)
1566 throws SystemException {
1567 if (_persistenceImpl.containsUser.contains(teamId, userId)) {
1568 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1569
1570 for (ModelListener<Team> listener : listeners) {
1571 listener.onBeforeRemoveAssociation(teamId,
1572 com.liferay.portal.model.User.class.getName(), userId);
1573 }
1574
1575 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1576 listener.onBeforeRemoveAssociation(userId,
1577 Team.class.getName(), teamId);
1578 }
1579
1580 _sqlUpdate.update(new Object[] {
1581 new Long(teamId), new Long(userId)
1582 });
1583
1584 for (ModelListener<Team> listener : listeners) {
1585 listener.onAfterRemoveAssociation(teamId,
1586 com.liferay.portal.model.User.class.getName(), userId);
1587 }
1588
1589 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1590 listener.onAfterRemoveAssociation(userId,
1591 Team.class.getName(), teamId);
1592 }
1593 }
1594 }
1595
1596 private SqlUpdate _sqlUpdate;
1597 private TeamPersistenceImpl _persistenceImpl;
1598 }
1599
1600 private static final String _SQL_SELECT_TEAM = "SELECT team FROM Team team";
1601 private static final String _SQL_SELECT_TEAM_WHERE = "SELECT team FROM Team team WHERE ";
1602 private static final String _SQL_COUNT_TEAM = "SELECT COUNT(team) FROM Team team";
1603 private static final String _SQL_COUNT_TEAM_WHERE = "SELECT COUNT(team) FROM Team team WHERE ";
1604 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Teams ON (Users_Teams.userId = User_.userId) WHERE (Users_Teams.teamId = ?)";
1605 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ?";
1606 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ? AND userId = ?";
1607 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "team.groupId = ?";
1608 private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "team.groupId = ? AND ";
1609 private static final String _FINDER_COLUMN_G_N_NAME_1 = "team.name IS NULL";
1610 private static final String _FINDER_COLUMN_G_N_NAME_2 = "team.name = ?";
1611 private static final String _FINDER_COLUMN_G_N_NAME_3 = "(team.name IS NULL OR team.name = ?)";
1612 private static final String _ORDER_BY_ENTITY_ALIAS = "team.";
1613 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Team exists with the primary key ";
1614 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Team exists with the key {";
1615 private static Log _log = LogFactoryUtil.getLog(TeamPersistenceImpl.class);
1616}