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