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